trigger sync with primary when we are friend with their secondary

pull/1137/head
Audric Ackermann 5 years ago
parent a8a4c4995a
commit 182635e267
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -664,22 +664,43 @@ MessageSender.prototype = {
if (!primaryDeviceKey) { if (!primaryDeviceKey) {
return Promise.resolve(); return Promise.resolve();
} }
// Extract required contacts information out of conversations // first get all friends with primary devices
const sessionContacts = conversations.filter( const sessionContactsPrimary = conversations.filter(
c => c =>
c.isPrivate() && c.isPrivate() &&
!c.isSecondaryDevice() && !c.isOurLocalDevice() &&
c.isFriend() && c.isFriend() &&
!c.isOurLocalDevice() !c.get('secondaryStatus')
) || [];
// then get all friends with secondary devices
let sessionContactsSecondary = conversations.filter(
c =>
c.isPrivate() &&
!c.isOurLocalDevice() &&
c.isFriend() &&
c.get('secondaryStatus')
); );
if (sessionContacts.length === 0) {
// then morph all secondary conversation to their primary
sessionContactsSecondary = await Promise.all(sessionContactsSecondary.map(async c => {
return window.ConversationController.getOrCreateAndWait(
c.getPrimaryDevicePubKey(),
'private'
);
})) || [];
const contactsSet = new Set([...sessionContactsPrimary, ...sessionContactsSecondary]);
const contacts = [...contactsSet];
if (contacts.length === 0) {
window.console.info('No contacts to sync.'); window.console.info('No contacts to sync.');
return Promise.resolve(); return Promise.resolve();
} }
// We need to sync across 3 contacts at a time // We need to sync across 3 contacts at a time
// This is to avoid hitting storage server limit // This is to avoid hitting storage server limit
const chunked = _.chunk(sessionContacts, 3); const chunked = _.chunk(contacts, 3);
const syncMessages = await Promise.all( const syncMessages = await Promise.all(
chunked.map(c => libloki.api.createContactSyncProtoMessage(c)) chunked.map(c => libloki.api.createContactSyncProtoMessage(c))
); );

Loading…
Cancel
Save