Sync secondary devices again but handle the receiving of them properly

This commit is contained in:
Beaudan Brown 2019-11-06 16:07:15 +11:00
parent 41fdcef695
commit 15c07ea7df
3 changed files with 21 additions and 17 deletions

View file

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

View file

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

View file

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