Groups: Force a fetch right now if our update runs into a conflict

This commit is contained in:
Scott Nonnenberg 2021-08-06 14:25:15 -07:00 committed by GitHub
parent 7ce89414bf
commit 35625f4200
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View file

@ -1368,13 +1368,13 @@ export async function modifyGroupV2({
);
// eslint-disable-next-line no-await-in-loop
await conversation.fetchLatestGroupV2Data();
await conversation.fetchLatestGroupV2Data({ force: true });
} else if (error.code === 409) {
window.log.error(
`modifyGroupV2/${idLog}: Conflict while updating. Timed out; not retrying.`
);
// We don't wait here because we're breaking out of the loop immediately.
conversation.fetchLatestGroupV2Data();
conversation.fetchLatestGroupV2Data({ force: true });
throw error;
} else {
const errorString = error && error.stack ? error.stack : error;
@ -2720,6 +2720,7 @@ type MaybeUpdatePropsType = {
receivedAt?: number;
sentAt?: number;
dropInitialJoinMessage?: boolean;
force?: boolean;
};
const FIVE_MINUTES = 1000 * 60 * 5;
@ -2742,7 +2743,10 @@ export async function waitThenMaybeUpdateGroup(
// Then make sure we haven't fetched this group too recently
const { lastSuccessfulGroupFetch = 0 } = conversation;
if (isMoreRecentThan(lastSuccessfulGroupFetch, FIVE_MINUTES)) {
if (
!options.force &&
isMoreRecentThan(lastSuccessfulGroupFetch, FIVE_MINUTES)
) {
const waitTime = lastSuccessfulGroupFetch + FIVE_MINUTES - Date.now();
window.log.info(
`waitThenMaybeUpdateGroup/${conversation.idForLogging()}: group update ` +

View file

@ -1008,12 +1008,15 @@ export class ConversationModel extends window.Backbone
}
}
async fetchLatestGroupV2Data(): Promise<void> {
async fetchLatestGroupV2Data(
options: { force?: boolean } = {}
): Promise<void> {
if (!isGroupV2(this.attributes)) {
return;
}
await window.Signal.Groups.waitThenMaybeUpdateGroup({
force: options.force,
conversation: this,
});
}