Create contacts during processing of group updates
This commit is contained in:
parent
6578679166
commit
53a27d022f
2 changed files with 60 additions and 15 deletions
44
ts/groups.ts
44
ts/groups.ts
|
@ -12,6 +12,7 @@ import {
|
||||||
import type { ClientZkGroupCipher } from '@signalapp/signal-client/zkgroup';
|
import type { ClientZkGroupCipher } from '@signalapp/signal-client/zkgroup';
|
||||||
import { v4 as getGuid } from 'uuid';
|
import { v4 as getGuid } from 'uuid';
|
||||||
import LRU from 'lru-cache';
|
import LRU from 'lru-cache';
|
||||||
|
import PQueue from 'p-queue';
|
||||||
import * as log from './logging/log';
|
import * as log from './logging/log';
|
||||||
import {
|
import {
|
||||||
getCredentialsForToday,
|
getCredentialsForToday,
|
||||||
|
@ -2794,6 +2795,8 @@ async function updateGroup(
|
||||||
},
|
},
|
||||||
{ viaSync = false } = {}
|
{ viaSync = false } = {}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const logId = conversation.idForLogging();
|
||||||
|
|
||||||
const { newAttributes, groupChangeMessages, members } = updates;
|
const { newAttributes, groupChangeMessages, members } = updates;
|
||||||
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
|
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
|
||||||
|
|
||||||
|
@ -2859,6 +2862,38 @@ async function updateGroup(
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const contactsWithoutProfileKey = new Array<ConversationModel>();
|
||||||
|
|
||||||
|
// Capture profile key for each member in the group, if we don't have it yet
|
||||||
|
members.forEach(member => {
|
||||||
|
const contact = window.ConversationController.getOrCreate(
|
||||||
|
member.uuid,
|
||||||
|
'private'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (member.profileKey && !contact.get('profileKey')) {
|
||||||
|
contactsWithoutProfileKey.push(contact);
|
||||||
|
contact.setProfileKey(member.profileKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (contactsWithoutProfileKey.length !== 0) {
|
||||||
|
log.info(
|
||||||
|
`updateGroup/${logId}: fetching ` +
|
||||||
|
`${contactsWithoutProfileKey.length} missing profiles`
|
||||||
|
);
|
||||||
|
|
||||||
|
const profileFetchQueue = new PQueue({
|
||||||
|
concurrency: 3,
|
||||||
|
});
|
||||||
|
await profileFetchQueue.addAll(
|
||||||
|
contactsWithoutProfileKey.map(contact => () => {
|
||||||
|
const active = contact.getActiveProfileFetch();
|
||||||
|
return active || contact.getProfiles();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (changeMessagesToSave.length > 0) {
|
if (changeMessagesToSave.length > 0) {
|
||||||
await window.Signal.Data.saveMessages(changeMessagesToSave, {
|
await window.Signal.Data.saveMessages(changeMessagesToSave, {
|
||||||
forceSave: true,
|
forceSave: true,
|
||||||
|
@ -2871,15 +2906,6 @@ async function updateGroup(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Capture profile key for each member in the group, if we don't have it yet
|
|
||||||
members.forEach(member => {
|
|
||||||
const contact = window.ConversationController.get(member.uuid);
|
|
||||||
|
|
||||||
if (member.profileKey && contact && !contact.get('profileKey')) {
|
|
||||||
contact.setProfileKey(member.profileKey);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// No need for convo.updateLastMessage(), 'newmessage' handler does that
|
// No need for convo.updateLastMessage(), 'newmessage' handler does that
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,6 +216,8 @@ export class ConversationModel extends window.Backbone
|
||||||
// This number is recorded as an optimization and may be out of date.
|
// This number is recorded as an optimization and may be out of date.
|
||||||
private newestReceivedAtMarkedRead?: number;
|
private newestReceivedAtMarkedRead?: number;
|
||||||
|
|
||||||
|
private _activeProfileFetch?: Promise<void>;
|
||||||
|
|
||||||
override defaults(): Partial<ConversationAttributesType> {
|
override defaults(): Partial<ConversationAttributesType> {
|
||||||
return {
|
return {
|
||||||
unreadCount: 0,
|
unreadCount: 0,
|
||||||
|
@ -4648,12 +4650,29 @@ export class ConversationModel extends window.Backbone
|
||||||
const queue = new PQueue({
|
const queue = new PQueue({
|
||||||
concurrency: 3,
|
concurrency: 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Convert Promise<void[]> that is returned by addAll() to Promise<void>
|
||||||
|
const promise = (async () => {
|
||||||
await queue.addAll(
|
await queue.addAll(
|
||||||
conversations.map(
|
conversations.map(
|
||||||
conversation => () =>
|
conversation => () =>
|
||||||
getProfile(conversation.get('uuid'), conversation.get('e164'))
|
getProfile(conversation.get('uuid'), conversation.get('e164'))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
})();
|
||||||
|
|
||||||
|
this._activeProfileFetch = promise;
|
||||||
|
try {
|
||||||
|
await promise;
|
||||||
|
} finally {
|
||||||
|
if (this._activeProfileFetch === promise) {
|
||||||
|
this._activeProfileFetch = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getActiveProfileFetch(): Promise<void> | undefined {
|
||||||
|
return this._activeProfileFetch;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setEncryptedProfileName(encryptedName: string): Promise<void> {
|
async setEncryptedProfileName(encryptedName: string): Promise<void> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue