mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-02 08:13:37 +01:00
Avoid race when downloading group avatars post-import
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user