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

@ -52,6 +52,14 @@
// Make sure poppers are positioned properly
window.dispatchEvent(new Event('resize'));
},
unload() {
const { lastConversation } = this;
if (!lastConversation) {
return;
}
lastConversation.trigger('unload', 'force unload requested');
},
onUnload(conversation) {
if (this.lastConversation === conversation) {
this.stopListening(this.lastConversation);
@ -93,6 +101,12 @@
}
});
// Close current opened conversation to reload the group information once
// linked.
Whisper.events.on('setupAsNewDevice', () => {
this.conversation_stack.unload();
});
if (!options.initialLoadComplete) {
this.appLoadingScreen = new Whisper.AppLoadingScreen();
this.appLoadingScreen.render();

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:`,

View file

@ -150,6 +150,8 @@ export class ConversationModel extends window.Backbone
intlCollator = new Intl.Collator(undefined, { sensitivity: 'base' });
lastSuccessfulGroupFetch?: number;
private cachedLatestGroupCallEraId?: string;
private cachedIdenticon?: CachedIdenticon;

View file

@ -391,12 +391,6 @@ Whisper.ConversationView = Whisper.View.extend({
this.model.updateSharedGroups.bind(this.model),
FIVE_MINUTES
);
this.model.throttledFetchLatestGroupV2Data =
this.model.throttledFetchLatestGroupV2Data ||
window._.throttle(
this.model.fetchLatestGroupV2Data.bind(this.model),
FIVE_MINUTES
);
this.model.throttledMaybeMigrateV1Group =
this.model.throttledMaybeMigrateV1Group ||
window._.throttle(
@ -2181,7 +2175,7 @@ Whisper.ConversationView = Whisper.View.extend({
this.setQuoteMessage(quotedMessageId);
}
this.model.throttledFetchLatestGroupV2Data();
this.model.fetchLatestGroupV2Data();
this.model.throttledMaybeMigrateV1Group();
const statusPromise = this.model.throttledGetProfiles();