Fix linked device sending automatic friend request when it already has keys for a device

pull/834/head
Mikunj Varsani 6 years ago
parent 8cca388eec
commit 054a523738

@ -202,6 +202,12 @@
isMe() { isMe() {
return this.id === window.storage.get('primaryDevicePubKey'); return this.id === window.storage.get('primaryDevicePubKey');
}, },
async isOurDevice() {
const ourDevices = await window.libloki.storage.getPairedDevicesFor(
this.ourNumber
);
return this.id === this.ourNumber || ourDevices.includes(this.id);
},
isPublic() { isPublic() {
return !!(this.id && this.id.match(/^publicChat:/)); return !!(this.id && this.id.match(/^publicChat:/));
}, },

@ -240,6 +240,10 @@
return secondaryPubKeys.concat(primaryDevicePubKey); return secondaryPubKeys.concat(primaryDevicePubKey);
} }
function getPairedDevicesFor(pubkey) {
return window.Signal.Data.getPairedDevicesFor(pubkey);
}
window.libloki.storage = { window.libloki.storage = {
getPreKeyBundleForContact, getPreKeyBundleForContact,
saveContactPreKeyBundle, saveContactPreKeyBundle,
@ -250,6 +254,7 @@
removePairingAuthorisationForSecondaryPubKey, removePairingAuthorisationForSecondaryPubKey,
getGrantAuthorisationForSecondaryPubKey, getGrantAuthorisationForSecondaryPubKey,
getAuthorisationForSecondaryPubKey, getAuthorisationForSecondaryPubKey,
getPairedDevicesFor,
getAllDevicePubKeysForPrimaryPubKey, getAllDevicePubKeysForPrimaryPubKey,
getSecondaryDevicesFor, getSecondaryDevicesFor,
getPrimaryDeviceMapping, getPrimaryDeviceMapping,

@ -350,12 +350,14 @@ OutgoingMessage.prototype = {
} catch (e) { } catch (e) {
// do nothing // do nothing
} }
if ( if (conversation && !this.isGroup) {
conversation && const isOurDevice = await conversation.isOurDevice();
!conversation.isFriend() && const isFriends =
!conversation.hasReceivedFriendRequest() && conversation.isFriend() ||
!this.isGroup conversation.hasReceivedFriendRequest();
) { // We should only send a friend request to our device if we don't have keys
const shouldSendAutomatedFR = isOurDevice ? !keysFound : !isFriends;
if (shouldSendAutomatedFR) {
// We want to send an automated friend request if: // We want to send an automated friend request if:
// - We aren't already friends // - We aren't already friends
// - We haven't received a friend request from this device // - We haven't received a friend request from this device
@ -369,6 +371,14 @@ OutgoingMessage.prototype = {
return null; return null;
} }
} }
// If we're not friends with our own device then we should become friends
if (isOurDevice && keysFound && !isFriends) {
conversation.setFriendRequestStatus(
window.friends.friendRequestStatusEnum.friends
);
}
}
} }
// Check if we need to attach the preKeys // Check if we need to attach the preKeys

Loading…
Cancel
Save