mark secondary devices as secondary from the right primary key

pull/1252/head
Audric Ackermann 5 years ago
parent 9a5c73af3c
commit b04a64da8c
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -338,33 +338,29 @@ async function onContactReceived(details: any) {
activeAt = activeAt || Date.now(); activeAt = activeAt || Date.now();
conversation.set('active_at', activeAt); conversation.set('active_at', activeAt);
} }
const ourPrimaryKey = window.storage.get('primaryDevicePubKey');
if (ourPrimaryKey) {
const ourSecondaryDevices = await MultiDeviceProtocol.getSecondaryDevices(
ourPrimaryKey
);
if (ourSecondaryDevices.some(device => device.key === id)) {
await conversation.setSecondaryStatus(true, ourPrimaryKey);
}
}
const devices = await MultiDeviceProtocol.getAllDevices(id); const primaryDevice = await MultiDeviceProtocol.getPrimaryDevice(id);
const deviceConversations = await Promise.all(
devices.map(d =>
ConversationController.getOrCreateAndWait(d.key, 'private')
)
);
const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices(id); const secondaryDevices = await MultiDeviceProtocol.getSecondaryDevices(id);
await Promise.all( const primaryConversation = await ConversationController.getOrCreateAndWait(
primaryDevice.key,
'private'
);
const secondaryConversations = await Promise.all(
secondaryDevices.map(async d => { secondaryDevices.map(async d => {
const secondaryConv = await ConversationController.getOrCreateAndWait( const secondaryConv = await ConversationController.getOrCreateAndWait(
d.key, d.key,
'private' 'private'
); );
await secondaryConv.setSecondaryStatus(true, id); await secondaryConv.setSecondaryStatus(true, primaryDevice.key);
return conversation;
}) })
); );
const deviceConversations = [
primaryConversation,
...secondaryConversations,
];
// triger session request with every devices of that user // triger session request with every devices of that user
// when we do not have a session with it already // when we do not have a session with it already
deviceConversations.forEach(device => { deviceConversations.forEach(device => {

Loading…
Cancel
Save