From 5cee35b3f5398ff00719c057d6b88181ab3882da Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 27 Feb 2025 14:44:23 +1100 Subject: [PATCH] fix: rekey on any type of member invite to group --- ts/state/ducks/metaGroups.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ts/state/ducks/metaGroups.ts b/ts/state/ducks/metaGroups.ts index 08dde7c92..5d3caed91 100644 --- a/ts/state/ducks/metaGroups.ts +++ b/ts/state/ducks/metaGroups.ts @@ -559,12 +559,13 @@ async function handleWithHistoryMembers({ const encryptedSupplementKeys = withHistory.length ? await MetaGroupWrapperActions.generateSupplementKeys(groupPk, withHistory) : null; + return encryptedSupplementKeys; } /** * Update the GROUP_MEMBER wrapper state to have those members. - * Calls rekey() if at least one was present in the list. + * Does not call `rekey()` so you need to call it from the caller. */ async function handleWithoutHistoryMembers({ groupPk, @@ -587,10 +588,6 @@ async function handleWithoutHistoryMembers({ // a group invite job will be added to the queue await MetaGroupWrapperActions.memberSetInviteNotSent(groupPk, member); } - - if (!isEmpty(withoutHistory)) { - await MetaGroupWrapperActions.keyRekey(groupPk); - } } async function handleMemberAddedFromUI({ @@ -635,6 +632,13 @@ async function handleMemberAddedFromUI({ // then handle the addition without history of messages (full rotation of keys). // this adds them to the members wrapper etc await handleWithoutHistoryMembers({ groupPk, withoutHistory }); + + if (withHistory.length || withoutHistory.length) { + // We now always want to call rekey(), even if only a supplemental key was needed. + // This is to take care of an edge case where a user is reinvited but considers himself kicked. + // See SES3299 + await MetaGroupWrapperActions.keyRekey(groupPk); + } const createAtNetworkTimestamp = NetworkTime.now(); await LibSessionUtil.saveDumpsToDb(groupPk);