Let group update happen on relink

This commit is contained in:
Fedor Indutny 2021-05-07 13:07:24 -07:00 committed by GitHub
parent 97fe907483
commit 98894ab121
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 7 deletions

View file

@ -22,6 +22,7 @@ import { isStorageWriteFeatureEnabled } from './storage/isFeatureEnabled';
import dataInterface from './sql/Client';
import { toWebSafeBase64, fromWebSafeBase64 } from './util/webSafeBase64';
import { assert } from './util/assert';
import { isMoreRecentThan } from './util/timestamp';
import {
ConversationAttributesType,
GroupV2MemberType,
@ -2597,6 +2598,8 @@ type MaybeUpdatePropsType = {
dropInitialJoinMessage?: boolean;
};
const FIVE_MINUTES = 1000 * 60 * 5;
export async function waitThenMaybeUpdateGroup(
options: MaybeUpdatePropsType,
{ viaSync = false } = {}
@ -2607,10 +2610,23 @@ export async function waitThenMaybeUpdateGroup(
// Then wait to process all outstanding messages for this conversation
const { conversation } = options;
const { lastSuccessfulGroupFetch = 0 } = conversation;
if (isMoreRecentThan(lastSuccessfulGroupFetch, FIVE_MINUTES)) {
const waitTime = lastSuccessfulGroupFetch + FIVE_MINUTES - Date.now();
window.log.info(
`waitThenMaybeUpdateGroup/${conversation.idForLogging()}: group update ` +
`was fetched recently, skipping for ${waitTime}ms`
);
return;
}
await conversation.queueJob(async () => {
try {
// And finally try to update the group
await maybeUpdateGroup(options, { viaSync });
conversation.lastSuccessfulGroupFetch = Date.now();
} catch (error) {
window.log.error(
`waitThenMaybeUpdateGroup/${conversation.idForLogging()}: maybeUpdateGroup failure:`,