From 7cc4400572c14c56716647b083c081951b6fc676 Mon Sep 17 00:00:00 2001 From: Alex Jin <57976479+Silver-IT@users.noreply.github.com> Date: Wed, 18 Oct 2023 10:48:45 -0700 Subject: [PATCH] Make sure we sync any identity contracts we haven't synced upon login (#1763) * feat: sync missing identity contracts after joining group * chore: remove IIFE * chore: resolved feedback --- frontend/controller/actions/group.js | 10 ++++++++++ frontend/controller/actions/identity.js | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/frontend/controller/actions/group.js b/frontend/controller/actions/group.js index bde4403eee..c1a88a5325 100644 --- a/frontend/controller/actions/group.js +++ b/frontend/controller/actions/group.js @@ -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. diff --git a/frontend/controller/actions/identity.js b/frontend/controller/actions/identity.js index 37b3b28026..1879fb0faa 100644 --- a/frontend/controller/actions/identity.js +++ b/frontend/controller/actions/identity.js @@ -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) {