From 7bfcfd5c3f570d5e6940cc151323acebd09bebb6 Mon Sep 17 00:00:00 2001 From: silver-it Date: Thu, 12 Oct 2023 09:09:52 +0800 Subject: [PATCH 1/3] feat: sync missing identity contracts after joining group --- frontend/controller/actions/group.js | 13 ++++++++++++- frontend/controller/actions/identity.js | 5 +---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/frontend/controller/actions/group.js b/frontend/controller/actions/group.js index bde4403eee..ce80b3ad3e 100644 --- a/frontend/controller/actions/group.js +++ b/frontend/controller/actions/group.js @@ -316,7 +316,9 @@ export default (sbp('sbp/selectors/register', { // 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 & { options?: { skipUsableKeysCheck?: boolean; skipInviteAccept?: boolean } }) { - sbp('okTurtles.data/set', 'JOINING_GROUP-' + params.contractID, true) + if (!params.options?.skipInviteAccept) { + sbp('okTurtles.data/set', 'JOINING_GROUP-' + params.contractID, true) + } try { const rootState = sbp('state/vuex/state') const username = rootState.loggedIn.username @@ -512,6 +514,15 @@ export default (sbp('sbp/selectors/register', { }) } + (async () => { + // 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)) + 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 1e4c506a4d..471d202620 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) { From f2bbe66447de363b5b24fe9a5f2d596b5e6d489c Mon Sep 17 00:00:00 2001 From: silver-it Date: Thu, 12 Oct 2023 09:11:47 +0800 Subject: [PATCH 2/3] chore: remove IIFE --- frontend/controller/actions/group.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/frontend/controller/actions/group.js b/frontend/controller/actions/group.js index ce80b3ad3e..ae0ca4b5c4 100644 --- a/frontend/controller/actions/group.js +++ b/frontend/controller/actions/group.js @@ -514,14 +514,12 @@ export default (sbp('sbp/selectors/register', { }) } - (async () => { - // 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)) - await sbp('chelonia/contract/sync', missingIDs) - })() + // 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)) + 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 From bb7f5ad8c9f116ffaeb5dd1564c24543fa46b60b Mon Sep 17 00:00:00 2001 From: silver-it Date: Wed, 18 Oct 2023 07:58:55 +0800 Subject: [PATCH 3/3] chore: resolved feedback --- frontend/controller/actions/group.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/controller/actions/group.js b/frontend/controller/actions/group.js index ae0ca4b5c4..c1a88a5325 100644 --- a/frontend/controller/actions/group.js +++ b/frontend/controller/actions/group.js @@ -316,9 +316,7 @@ export default (sbp('sbp/selectors/register', { // 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 & { options?: { skipUsableKeysCheck?: boolean; skipInviteAccept?: boolean } }) { - if (!params.options?.skipInviteAccept) { - sbp('okTurtles.data/set', 'JOINING_GROUP-' + params.contractID, true) - } + sbp('okTurtles.data/set', 'JOINING_GROUP-' + params.contractID, true) try { const rootState = sbp('state/vuex/state') const username = rootState.loggedIn.username @@ -519,7 +517,10 @@ export default (sbp('sbp/selectors/register', { Object.keys(state.profiles) .map(username => sbp('namespace/lookup', username)) )).filter(id => !rootState[id] && !sbp('chelonia/contract/isSyncing', id)) - await sbp('chelonia/contract/sync', missingIDs) + 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