Skip to content

Commit

Permalink
Make sure we sync any identity contracts we haven't synced upon login (
Browse files Browse the repository at this point in the history
…#1763)

* feat: sync missing identity contracts after joining group

* chore: remove IIFE

* chore: resolved feedback
  • Loading branch information
Silver-IT authored Oct 18, 2023
1 parent 0a1cd00 commit 7cc4400
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 10 additions & 0 deletions frontend/controller/actions/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,16 @@ export default (sbp('sbp/selectors/register', {
})
}

// NOTE: sync identity contracts which are out of sync after joining group
const missingIDs = (await Promise.all(
Object.keys(state.profiles)
.map(username => sbp('namespace/lookup', username))
)).filter(id => !rootState[id] && !sbp('chelonia/contract/isSyncing', id))
if (missingIDs.length > 0) {
console.info('found unsynced identity contracts to sync:', missingIDs)
await sbp('chelonia/contract/sync', missingIDs)
}

sbp('okTurtles.data/set', 'JOINING_GROUP-' + params.contractID, false)
// We have already sent a key request that hasn't been answered. We cannot
// do much at this point, so we do nothing.
Expand Down
5 changes: 1 addition & 4 deletions frontend/controller/actions/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,7 @@ export default (sbp('sbp/selectors/register', {
const additionalIdentityContractIDs = await Promise.all(chatRoomUsers.filter(username => {
return getters.ourUsername !== username && !getters.ourContacts.includes(username)
}).map(username => sbp('namespace/lookup', username)))

for (const identityContractID of additionalIdentityContractIDs) {
await sbp('chelonia/contract/sync', identityContractID)
}
await sbp('chelonia/contract/sync', additionalIdentityContractIDs)

// NOTE: users could notice that they leave the group by someone else when they log in
if (!state.currentGroupId) {
Expand Down

0 comments on commit 7cc4400

Please sign in to comment.