From 9f0ea1cbf7406f28024053ce59137d588572f7a0 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Fri, 21 Jan 2022 14:34:32 -0800 Subject: [PATCH] Use message.groupV2.revision during first fetch --- ts/groups.ts | 52 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/ts/groups.ts b/ts/groups.ts index 48a5897cf8..0c07114eca 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -2946,24 +2946,63 @@ async function getGroupUpdates({ group, serverPublicParamsBase64, newRevision, + + // If we just linked and this is a group where we have been a member + // from the beggining - applying all changes since the start is the best + // case scenario. + fallbackRevision: 0, }); return result; } catch (error) { + const nextStep = isFirstFetch + ? `fetching logs since ${newRevision}` + : 'fetching full state'; + if (error.code === TEMPORAL_AUTH_REJECTED_CODE) { // We will fail over to the updateGroupViaState call below log.info( - `getGroupUpdates/${logId}: Temporal credential failure, now fetching full group state` + `getGroupUpdates/${logId}: Temporal credential failure, now ${nextStep}` ); } else if (error.code === GROUP_ACCESS_DENIED_CODE) { // We will fail over to the updateGroupViaState call below log.info( - `getGroupUpdates/${logId}: Log access denied, now fetching full group state` + `getGroupUpdates/${logId}: Log access denied, now ${nextStep}` ); } else { throw error; } } + + // Fetch of logs starting from the revision 0 failed, so we probably were + // just invited to the group. Try fetching logs from the same revision as in + // this message. + if (isFirstFetch) { + try { + const result = await updateGroupViaLogs({ + group, + serverPublicParamsBase64, + newRevision, + fallbackRevision: newRevision, + }); + + return result; + } catch (error) { + if (error.code === TEMPORAL_AUTH_REJECTED_CODE) { + // We will fail over to the updateGroupViaState call below + log.info( + `getGroupUpdates/${logId}: Temporal credential failure, now fetching full state` + ); + } else if (error.code === GROUP_ACCESS_DENIED_CODE) { + // We will fail over to the updateGroupViaState call below + log.info( + `getGroupUpdates/${logId}: Log access denied, now fetching full state` + ); + } else { + throw error; + } + } + } } if (window.GV2_ENABLE_STATE_PROCESSING) { @@ -3081,9 +3120,11 @@ async function updateGroupViaSingleChange({ async function updateGroupViaLogs({ group, serverPublicParamsBase64, + fallbackRevision, newRevision, }: { group: ConversationAttributesType; + fallbackRevision: number; newRevision: number; serverPublicParamsBase64: string; }): Promise { @@ -3096,6 +3137,7 @@ async function updateGroupViaLogs({ const groupCredentials = getCredentialsForToday(data); const deltaOptions = { group, + fallbackRevision, newRevision, serverPublicParamsBase64, authCredentialBase64: groupCredentials.today.credential, @@ -3219,11 +3261,13 @@ function getGroupCredentials({ async function getGroupDelta({ group, newRevision, + fallbackRevision, serverPublicParamsBase64, authCredentialBase64, }: { group: ConversationAttributesType; newRevision: number; + fallbackRevision: number; serverPublicParamsBase64: string; authCredentialBase64: string; }): Promise { @@ -3246,7 +3290,9 @@ async function getGroupDelta({ }); const currentRevision = group.revision; - let revisionToFetch = isNumber(currentRevision) ? currentRevision + 1 : 0; + let revisionToFetch = isNumber(currentRevision) + ? currentRevision + 1 + : fallbackRevision; let response; const changes: Array = [];