From 56ccd02232667f06bf5e5e35dc0588f627836edb Mon Sep 17 00:00:00 2001 From: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:08:33 -0700 Subject: [PATCH] Only set last group fetch for server updates --- ts/groups.ts | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/ts/groups.ts b/ts/groups.ts index fa6e71357d..24a7dfd4c0 100644 --- a/ts/groups.ts +++ b/ts/groups.ts @@ -2783,6 +2783,7 @@ export async function respondToGroupV2Migration({ let groupSendEndorsementResponse: Uint8Array | null | undefined; try { + const fetchedAt = Date.now(); const response: GroupLogResponseType = await makeRequestWithCredentials({ logId: `getGroupLog/${logId}`, publicParams, @@ -2799,6 +2800,7 @@ export async function respondToGroupV2Migration({ options ), }); + setLastSuccessfulGroupFetch(conversation.id, fetchedAt); // Attempt to start with the first group state, only later processing future updates firstGroupState = response?.changes?.groupChanges?.[0]?.groupState; @@ -2809,12 +2811,14 @@ export async function respondToGroupV2Migration({ `respondToGroupV2Migration/${logId}: Failed to access log endpoint; fetching full group state` ); try { + const fetchedAt = Date.now(); const groupResponse = await makeRequestWithCredentials({ logId: `getGroup/${logId}`, publicParams, secretParams, request: (sender, options) => sender.getGroup(options), }); + setLastSuccessfulGroupFetch(conversation.id, fetchedAt); firstGroupState = groupResponse.group; groupSendEndorsementResponse = @@ -3051,9 +3055,8 @@ export async function waitThenMaybeUpdateGroup( try { // And finally try to update the group await maybeUpdateGroup(options, { viaFirstStorageSync }); - - conversation.lastSuccessfulGroupFetch = Date.now(); } catch (error) { + setLastSuccessfulGroupFetch(conversation.id, undefined); log.error( `${logId}: maybeUpdateGroup failure:`, Errors.toLogFormat(error) @@ -3767,24 +3770,20 @@ async function updateGroupViaState({ dropInitialJoinMessage?: boolean; group: ConversationAttributesType; }): Promise { - const logId = idForLogging(group.groupId); - const { publicParams, secretParams } = group; + const { id, publicParams, secretParams } = group; + const logId = `updateGroupViaState/${idForLogging(group.groupId)}`; - strictAssert( - secretParams, - 'updateGroupViaState: group was missing secretParams!' - ); - strictAssert( - publicParams, - 'updateGroupViaState: group was missing publicParams!' - ); + strictAssert(secretParams, `${logId}: Missing secretParams`); + strictAssert(publicParams, `${logId}: Missing publicParams`); + const fetchedAt = Date.now(); const groupResponse = await makeRequestWithCredentials({ logId: `getGroup/${logId}`, publicParams, secretParams, request: (sender, requestOptions) => sender.getGroup(requestOptions), }); + setLastSuccessfulGroupFetch(id, fetchedAt); const { group: groupState, groupSendEndorsementResponse } = groupResponse; strictAssert(groupState, 'updateGroupViaState: Group state must be present'); @@ -3853,6 +3852,9 @@ async function updateGroupViaSingleChange({ const previouslyKnewAboutThisGroup = isNumber(group.revision) && group.membersV2?.length; const wasInGroup = !group.left; + + setLastSuccessfulGroupFetch(group.id, undefined); + const singleChangeResult: UpdatesResultType = await integrateGroupChange({ group, groupChange, @@ -4005,6 +4007,7 @@ async function updateGroupViaLogs({ let groupSendEndorsementResponse: Uint8Array | null = null; const changes: Array = []; do { + const fetchedAt = Date.now(); // eslint-disable-next-line no-await-in-loop response = await makeRequestWithCredentials({ logId: `getGroupLog/${logId}`, @@ -4024,6 +4027,7 @@ async function updateGroupViaLogs({ requestOptions ), }); + setLastSuccessfulGroupFetch(group.id, fetchedAt); // When the log is long enough that it needs to be paginated, the server is // not stateful enough to only give us endorsements when we need them. @@ -7238,3 +7242,15 @@ export function getMembershipList( return { aci, uuidCiphertext }; }); } + +function setLastSuccessfulGroupFetch( + conversationId: string, + timestamp: number | undefined +): void { + const conversation = window.ConversationController.get(conversationId); + strictAssert( + conversation, + `setLastSuccessfulGroupFetch/${idForLogging(conversationId)}: Conversation must exist` + ); + conversation.lastSuccessfulGroupFetch = timestamp; +}