Avoid race when downloading group avatars post-import

This commit is contained in:
trevor-signal
2026-02-11 08:55:26 -05:00
committed by GitHub
parent ff9d247cb2
commit 291000f297
2 changed files with 46 additions and 17 deletions

View File

@@ -279,7 +279,6 @@ export class BackupImportStream extends Writable {
#customColorById = new Map<number, CustomColorDataType>();
#releaseNotesRecipientId: Long | undefined;
#releaseNotesChatId: Long | undefined;
#pendingGroupAvatars = new Map<string, string>();
#pinnedMessages: Array<PinnedMessageParams> = [];
#frameErrorCount: number = 0;
#backupTier: BackupLevel | undefined;
@@ -422,7 +421,19 @@ export class BackupImportStream extends Writable {
// conversation's last message, which uses redux selectors)
await loadAllAndReinitializeRedux();
const allConversations = window.ConversationController.getAll();
const allConversations = window.ConversationController.getAll().sort(
(convoA, convoB) => {
if (convoA.get('isPinned')) {
return -1;
}
if (convoB.get('isPinned')) {
return 1;
}
return (
(convoB.get('active_at') ?? 0) - (convoA.get('active_at') ?? 0)
);
}
);
// Update last message in every active conversation now that we have
// them loaded into memory.
@@ -445,12 +456,21 @@ export class BackupImportStream extends Writable {
// Schedule group avatar download.
await pMap(
[...this.#pendingGroupAvatars.entries()],
async ([conversationId, newAvatarUrl]) => {
allConversations,
async conversation => {
if (this.options.type === 'cross-client-integration-test') {
return;
}
await groupAvatarJobQueue.add({ conversationId, newAvatarUrl });
if (
!isGroup(conversation.attributes) ||
!conversation.get('remoteAvatarUrl')
) {
return;
}
await groupAvatarJobQueue.add({
conversationId: conversation.get('id'),
newAvatarUrl: conversation.get('remoteAvatarUrl'),
});
},
{ concurrency: MAX_CONCURRENCY }
);
@@ -1218,6 +1238,7 @@ export class BackupImportStream extends Writable {
url: avatarUrl,
}
: undefined,
remoteAvatarUrl: dropNull(avatarUrl),
color: fromAvatarColor(group.avatarColor),
colorFromPrimary: dropNull(group.avatarColor),
@@ -1319,9 +1340,7 @@ export class BackupImportStream extends Writable {
: undefined,
announcementsOnly: dropNull(announcementsOnly),
};
if (avatarUrl) {
this.#pendingGroupAvatars.set(attrs.id, avatarUrl);
}
if (group.blocked) {
await itemStorage.blocked.addBlockedGroup(groupId);
}