Skip to content

Commit

Permalink
Chat bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Oct 14, 2024
1 parent 22a0f6e commit 8167a3f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
21 changes: 18 additions & 3 deletions frontend/controller/actions/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import { SETTING_CHELONIA_STATE } from '@model/database.js'
import sbp from '@sbp/sbp'
import { imageUpload, objectURLtoBlob } from '@utils/image.js'
import { SETTING_CURRENT_USER } from '~/frontend/model/database.js'
import { KV_QUEUE, LOGIN, LOGOUT } from '~/frontend/utils/events.js'
import { JOINED_CHATROOM, KV_QUEUE, LOGIN, LOGOUT } from '~/frontend/utils/events.js'
import { GIMessage } from '~/shared/domains/chelonia/GIMessage.js'
import { Secret } from '~/shared/domains/chelonia/Secret.js'
import { encryptedOutgoingData, encryptedOutgoingDataWithRawKey } from '~/shared/domains/chelonia/encryptedData.js'
import { EVENT_HANDLED } from '~/shared/domains/chelonia/events.js'
// Using relative path to crypto.js instead of ~-path to workaround some esbuild bug
import type { Key } from '../../../shared/domains/chelonia/crypto.js'
import { CURVE25519XSALSA20POLY1305, EDWARDS25519SHA512BATCH, deserializeKey, keyId, keygen, serializeKey } from '../../../shared/domains/chelonia/crypto.js'
Expand Down Expand Up @@ -498,6 +499,7 @@ export default (sbp('sbp/selectors/register', {
.filter(memberID => memberID !== rootGetters.ourIdentityContractId)
.map(memberID => rootGetters.ourContactProfilesById[memberID].contractID)
const currentGroupId = params.data.currentGroupId
const identityContractID = rootState.loggedIn.identityContractID

const message = await sbp('gi.actions/chatroom/create', {
data: {
Expand All @@ -512,11 +514,11 @@ export default (sbp('sbp/selectors/register', {
prepublish: params.hooks?.prepublish,
postpublish: null
}
}, rootState.loggedIn.identityContractID)
}, identityContractID)

// Share the keys to the newly created chatroom with ourselves
await sbp('gi.actions/out/shareVolatileKeys', {
contractID: rootState.loggedIn.identityContractID,
contractID: identityContractID,
contractName: 'gi.contracts/identity',
subjectContractID: message.contractID(),
keyIds: '*'
Expand All @@ -525,9 +527,20 @@ export default (sbp('sbp/selectors/register', {
await sbp('gi.actions/chatroom/join', {
...omit(params, ['options', 'contractID', 'data', 'hooks']),
contractID: message.contractID(),
// 'undefined' is for ourselves
data: { memberID: [undefined, ...partnerIDs] }
})

const switchChannelAfterJoined = (contractID: string) => {
if (contractID === message.contractID()) {
if (rootState[message.contractID()]?.members?.[identityContractID]) {
sbp('okTurtles.events/emit', JOINED_CHATROOM, { identityContractID, groupContractID: currentGroupId, chatRoomID: message.contractID() })
sbp('okTurtles.events/off', EVENT_HANDLED, switchChannelAfterJoined)
}
}
}
sbp('okTurtles.events/on', EVENT_HANDLED, switchChannelAfterJoined)

await sendMessage({
...omit(params, ['options', 'data', 'action', 'hooks']),
data: {
Expand Down Expand Up @@ -566,6 +579,8 @@ export default (sbp('sbp/selectors/register', {
hooks
})
}

return message.contractID()
}),
...encryptedAction('gi.actions/identity/joinDirectMessage', L('Failed to join a direct message.')),
...encryptedAction('gi.actions/identity/joinGroup', L('Failed to join a group.')),
Expand Down
2 changes: 1 addition & 1 deletion frontend/controller/app/chatroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sbp('okTurtles.events/on', JOINED_CHATROOM, ({ identityContractID, groupContract
console.warn('[JOINED_CHATROOM] Given up on setCurrentChatRoomId after 5 attempts', { identityContractID, groupContractID, chatRoomID })
return
}
setTimeout(setCurrentChatRoomId, 5 + 5 * attemptCount)
setTimeout(setCurrentChatRoomId, 5 * Math.pow(1.75, attemptCount))
} else {
sbp('state/vuex/commit', 'setCurrentChatRoomId', { groupID: groupContractID, chatRoomID })
}
Expand Down
1 change: 1 addition & 0 deletions frontend/views/containers/chatroom/ChatMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ export default ({
}
if (toChatRoomId !== fromChatRoomId) {
this.ephemeral.onChatScroll?.flush()
this.initializeState(true)
this.ephemeral.messagesInitiated = false
this.ephemeral.scrolledDistance = 0
Expand Down
11 changes: 9 additions & 2 deletions frontend/views/containers/chatroom/DMMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ const DMMixin: Object = {
}
try {
const identityContractID = this.ourIdentityContractId
const currentGroupId = this.currentGroupId
await sbp('gi.actions/identity/createDirectMessage', {
contractID: identityContractID,
data: { currentGroupId: this.currentGroupId, memberIDs },
data: { currentGroupId, memberIDs },
hooks: {
prepublish (message) {
console.error('@@@XX pp', 'setPendingChatRoomId', message.contractID())
sbp('state/vuex/commit', 'setPendingChatRoomId', { chatRoomID: message.contractID(), groupID: currentGroupId })
}
}
/* hooks: {
onprocessed: (message) => {
const dmID = message.decryptedValue().data.contractID
// The logic for updating paths will not work until the DM chatroom
Expand Down Expand Up @@ -56,7 +63,7 @@ const DMMixin: Object = {
setCurrentChatRoomId()
}
}
} */
})
} catch (err) {
console.error('[DMMixin.js] Failed to create a new chatroom', err)
Expand Down

0 comments on commit 8167a3f

Please sign in to comment.