Only set last group fetch for server updates
This commit is contained in:
parent
28c3bf8017
commit
56ccd02232
1 changed files with 28 additions and 12 deletions
40
ts/groups.ts
40
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<UpdatesResultType> {
|
||||
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<Proto.IGroupChanges> = [];
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue