Sync secondary devices again but handle the receiving of them properly

pull/601/head
Beaudan Brown 6 years ago
parent 41fdcef695
commit 15c07ea7df

@ -8,6 +8,7 @@
storage, storage,
textsecure, textsecure,
Whisper, Whisper,
libloki,
BlockedNumberController BlockedNumberController
*/ */
@ -252,7 +253,7 @@
window.lokiP2pAPI = new window.LokiP2pAPI(ourKey); window.lokiP2pAPI = new window.LokiP2pAPI(ourKey);
window.lokiP2pAPI.on('pingContact', pubKey => { window.lokiP2pAPI.on('pingContact', pubKey => {
const isPing = true; const isPing = true;
window.libloki.api.sendOnlineBroadcastMessage(pubKey, isPing); libloki.api.sendOnlineBroadcastMessage(pubKey, isPing);
}); });
window.lokiP2pAPI.on('online', ConversationController._handleOnline); window.lokiP2pAPI.on('online', ConversationController._handleOnline);
window.lokiP2pAPI.on('offline', ConversationController._handleOffline); window.lokiP2pAPI.on('offline', ConversationController._handleOffline);
@ -845,8 +846,8 @@
}); });
Whisper.events.on('devicePairingRequestRejected', async pubKey => { Whisper.events.on('devicePairingRequestRejected', async pubKey => {
await window.libloki.storage.removeContactPreKeyBundle(pubKey); await libloki.storage.removeContactPreKeyBundle(pubKey);
await window.libloki.storage.removePairingAuthorisationForSecondaryPubKey( await libloki.storage.removePairingAuthorisationForSecondaryPubKey(
pubKey pubKey
); );
}); });
@ -1164,7 +1165,7 @@
} }
let primaryDevice = null; let primaryDevice = null;
const authorisation = await window.libloki.storage.getGrantAuthorisationForSecondaryPubKey( const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey(
sender sender
); );
if (authorisation) { if (authorisation) {
@ -1221,6 +1222,16 @@
if (activeAt !== null) { if (activeAt !== null) {
activeAt = activeAt || Date.now(); activeAt = activeAt || Date.now();
} }
const ourAuthorisations = await libloki.storage.getPrimaryDeviceMapping(
window.storage.get('primaryDevicePubKey')
);
const isSecondaryDevice =
ourAuthorisations &&
ourAuthorisations.some(auth => auth.secondaryDevicePubKey === id);
if (isSecondaryDevice) {
await conversation.setSecondaryStatus(true);
}
if (details.profileKey) { if (details.profileKey) {
const profileKey = window.Signal.Crypto.arrayBufferToBase64( const profileKey = window.Signal.Crypto.arrayBufferToBase64(
@ -1395,7 +1406,7 @@
const messageDescriptor = getMessageDescriptor(data); const messageDescriptor = getMessageDescriptor(data);
// Funnel messages to primary device conversation if multi-device // Funnel messages to primary device conversation if multi-device
const authorisation = await window.libloki.storage.getGrantAuthorisationForSecondaryPubKey( const authorisation = await libloki.storage.getGrantAuthorisationForSecondaryPubKey(
messageDescriptor.id messageDescriptor.id
); );
if (authorisation) { if (authorisation) {

@ -192,10 +192,7 @@
}, },
isMe() { isMe() {
return ( return this.id === window.storage.get('primaryDevicePubKey');
this.id === this.ourNumber ||
this.id === window.storage.get('primaryDevicePubKey')
);
}, },
isPublic() { isPublic() {
return this.id && this.id.match(/^publicChat:/); return this.id && this.id.match(/^publicChat:/);

@ -120,11 +120,7 @@
{ ConversationCollection: Whisper.ConversationCollection } { ConversationCollection: Whisper.ConversationCollection }
); );
// Extract required contacts information out of conversations // Extract required contacts information out of conversations
const rawContacts = conversations.reduce((acc, conversation) => { const rawContacts = conversations.map(conversation => {
if (conversation.isSecondaryDevice()) {
// Don't bother syncing secondary devices
return acc;
}
const profile = conversation.getLokiProfile(); const profile = conversation.getLokiProfile();
const number = conversation.getNumber(); const number = conversation.getNumber();
const name = profile const name = profile
@ -139,15 +135,15 @@
destination: number, destination: number,
identityKey: StringView.hexToArrayBuffer(number), identityKey: StringView.hexToArrayBuffer(number),
}); });
return acc.concat({ return {
name, name,
verified, verified,
number, number,
nickname: conversation.getNickname(), nickname: conversation.getNickname(),
blocked: conversation.isBlocked(), blocked: conversation.isBlocked(),
expireTimer: conversation.get('expireTimer'), expireTimer: conversation.get('expireTimer'),
}); };
}, []); });
// Convert raw contacts to an array of buffers // Convert raw contacts to an array of buffers
const contactDetails = rawContacts const contactDetails = rawContacts
.filter(x => x.number !== textsecure.storage.user.getNumber()) .filter(x => x.number !== textsecure.storage.user.getNumber())

Loading…
Cancel
Save