From 0f5a01f2b26fd6dd30908361f45170e731800ae4 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Thu, 24 Mar 2022 10:06:39 -0700 Subject: [PATCH] Fetch full group state if last epoch is stale --- ts/groups.ts | 25 ++++++++++++++++++++++++- ts/model-types.d.ts | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ts/groups.ts b/ts/groups.ts index af0ba3f85d..c7aefacdc6 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -3622,6 +3622,7 @@ async function getGroupDelta({ changes, group, newRevision: latestRevision, + serverPublicParamsBase64, }); } @@ -3629,15 +3630,17 @@ async function integrateGroupChanges({ group, newRevision, changes, + serverPublicParamsBase64, }: { group: ConversationAttributesType; newRevision: number | undefined; changes: Array; + serverPublicParamsBase64: string; }): Promise { const logId = idForLogging(group.groupId); let attributes = group; const finalMessages: Array> = []; - const finalMembers: Array> = []; + let finalMembers: Array> = []; const imax = changes.length; for (let i = 0; i < imax; i += 1) { @@ -3721,6 +3724,24 @@ async function integrateGroupChanges({ Errors.toLogFormat(error) ); } + } else if (attributes.lastFetchedEpoch !== SUPPORTED_CHANGE_EPOCH) { + log.info( + `integrateGroupChanges(${logId}): last fetched epoch ` + + `${group.lastFetchedEpoch ?? '?'} is stale. ` + + 'Refreshing group state' + ); + const { + newAttributes: updatedAttributes, + groupChangeMessages: extraChanges, + members: updatedMembers, + } = await updateGroupViaState({ + group: attributes, + serverPublicParamsBase64, + }); + + attributes = updatedAttributes; + finalMessages.push(extraChanges); + finalMembers = [updatedMembers]; } // If this is our first fetch, we will collapse this down to one set of messages @@ -3839,6 +3860,7 @@ async function integrateGroupChange({ !groupChange || !isChangeSupported || isFirstFetch || + (groupState && group.lastFetchedEpoch !== SUPPORTED_CHANGE_EPOCH) || (isMoreThanOneVersionUp && !weAreAwaitingApproval) ) { if (!groupState) { @@ -4993,6 +5015,7 @@ async function applyGroupState({ // version result.revision = version; + result.lastFetchedEpoch = SUPPORTED_CHANGE_EPOCH; // title // Note: During decryption, title becomes a GroupAttributeBlob diff --git a/ts/model-types.d.ts b/ts/model-types.d.ts index 0f4f6f41e9..812c8c47b0 100644 --- a/ts/model-types.d.ts +++ b/ts/model-types.d.ts @@ -331,6 +331,7 @@ export type ConversationAttributesType = { secretParams?: string; publicParams?: string; revision?: number; + lastFetchedEpoch?: number; senderKeyInfo?: SenderKeyInfoType; // GroupV2 other fields