Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2133 #2134

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions frontend/controller/actions/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export default (sbp('sbp/selectors/register', {
// secret keys to be shared with us, (b) ready to call the inviteAccept
// action if we haven't done so yet (because we were previously waiting for
// the keys), or (c) already a member and ready to interact with the group.
'gi.actions/group/join': async function (params: $Exact<ChelKeyRequestParams>) {
'gi.actions/group/_private/join': async function (params: $Exact<ChelKeyRequestParams>) {
// We want to process any current events first, so that we process leave
// actions and don't interfere with the leaving process (otherwise, the
// side-effects could prevent us from fully leaving).
Expand Down Expand Up @@ -432,21 +432,25 @@ export default (sbp('sbp/selectors/register', {
keyIds: [PEKid]
})

await sbp('chelonia/out/keyAdd', {
contractID: params.contractID,
contractName: 'gi.contracts/group',
data: [encryptedOutgoingData(params.contractID, CEKid, {
foreignKey: `sp:${encodeURIComponent(userID)}?keyName=${encodeURIComponent('csk')}`,
id: userCSKid,
data: userCSKdata,
permissions: [GIMessage.OP_ACTION_ENCRYPTED + '#inner'],
allowedActions: '*',
purpose: ['sig'],
ringLevel: Number.MAX_SAFE_INTEGER,
name: `${userID}/${userCSKid}`
})],
signingKeyId: CSKid
})
const existingForeignKeys = await sbp('chelonia/contract/foreignKeysByContractID', params.contractID, userID)
// Check to avoid adding existing keys to the contract
if (!existingForeignKeys?.includes(userCSKid)) {
await sbp('chelonia/out/keyAdd', {
contractID: params.contractID,
contractName: 'gi.contracts/group',
data: [encryptedOutgoingData(params.contractID, CEKid, {
foreignKey: `sp:${encodeURIComponent(userID)}?keyName=${encodeURIComponent('csk')}`,
id: userCSKid,
data: userCSKdata,
permissions: [GIMessage.OP_ACTION_ENCRYPTED + '#inner'],
allowedActions: '*',
purpose: ['sig'],
ringLevel: Number.MAX_SAFE_INTEGER,
name: `${userID}/${userCSKid}`
})],
signingKeyId: CSKid
})
}

// Send inviteAccept action to the group to add ourselves to the members list
await sbp('chelonia/contract/wait', params.contractID)
Expand All @@ -462,7 +466,7 @@ export default (sbp('sbp/selectors/register', {
contractID: params.contractID
}).catch((e) => console.error('[gi.actions/group/join] Error sending updateLastLoggedIn', e))
} catch (e) {
console.error(`[gi.actions/group/join] Error while sending key request for ${params.contractID}:`, e)
console.error(`[gi.actions/group/join] Error while accepting invite ${params.contractID}:`, e)
throw e
}
}
Expand Down Expand Up @@ -495,6 +499,13 @@ export default (sbp('sbp/selectors/register', {
await sbp('chelonia/contract/release', params.contractID, { ephemeral: true })
}
},
// This wrapper ensures that all join actions for the same contract happen in
// order. Because join is complex and there are many async steps involved,
// multiple calls to join for the same contract can result in conflicting with
// each other
'gi.actions/group/join': function (params: $Exact<ChelKeyRequestParams>) {
return sbp('okTurtles.eventQueue/queueEvent', `JOIN_GROUP-${params.contractID}`, ['gi.actions/group/_private/join', params])
},
'gi.actions/group/joinAndSwitch': async function (params: $Exact<ChelKeyRequestParams>) {
await sbp('gi.actions/group/join', params)
// after joining, we can set the current group
Expand Down
Loading