Don't send contact sync message with pairing authorisation.

Don't send secondary devices in contact sync messages.
pull/877/head
Mikunj 6 years ago
parent f35493ce9f
commit 0eaebcbcac

@ -1371,6 +1371,8 @@
await window.lokiFileServerAPI.updateOurDeviceMapping(); await window.lokiFileServerAPI.updateOurDeviceMapping();
// TODO: we should ensure the message was sent and retry automatically if not // TODO: we should ensure the message was sent and retry automatically if not
await libloki.api.sendUnpairingMessageToSecondary(pubKey); await libloki.api.sendUnpairingMessageToSecondary(pubKey);
// Remove all traces of the device
ConversationController.deleteContact(pubKey);
Whisper.events.trigger('refreshLinkedDeviceList'); Whisper.events.trigger('refreshLinkedDeviceList');
}); });
} }

@ -935,7 +935,7 @@
if (newStatus === FriendRequestStatusEnum.friends) { if (newStatus === FriendRequestStatusEnum.friends) {
if (!blockSync) { if (!blockSync) {
// Sync contact // Sync contact
this.wrapSend(textsecure.messaging.sendContactSyncMessage(this)); this.wrapSend(textsecure.messaging.sendContactSyncMessage([this]));
} }
// Only enable sending profileKey after becoming friends // Only enable sending profileKey after becoming friends
this.set({ profileSharing: true }); this.set({ profileSharing: true });

@ -229,7 +229,7 @@ class LokiAppDotNetServerAPI {
window.storage.get('primaryDevicePubKey') || window.storage.get('primaryDevicePubKey') ||
textsecure.storage.user.getNumber(); textsecure.storage.user.getNumber();
const profileConvo = ConversationController.get(ourNumber); const profileConvo = ConversationController.get(ourNumber);
const profile = profileConvo.getLokiProfile(); const profile = profileConvo && profileConvo.getLokiProfile();
const profileName = profile && profile.displayName; const profileName = profile && profile.displayName;
// if doesn't match, write it to the network // if doesn't match, write it to the network
if (tokenRes.response.data.user.name !== profileName) { if (tokenRes.response.data.user.name !== profileName) {

@ -1,4 +1,4 @@
/* global window, textsecure, Whisper, dcodeIO, StringView, ConversationController */ /* global window, textsecure, dcodeIO, StringView, ConversationController */
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function() { (function() {
@ -109,7 +109,14 @@
} }
async function createContactSyncProtoMessage(conversations) { async function createContactSyncProtoMessage(conversations) {
// Extract required contacts information out of conversations // Extract required contacts information out of conversations
const sessionContacts = conversations.filter(c => c.isPrivate()); const sessionContacts = conversations.filter(
c => c.isPrivate() && !c.isSecondaryDevice()
);
if (sessionContacts.length === 0) {
return null;
}
const rawContacts = await Promise.all( const rawContacts = await Promise.all(
sessionContacts.map(async conversation => { sessionContacts.map(async conversation => {
const profile = conversation.getLokiProfile(); const profile = conversation.getLokiProfile();
@ -152,21 +159,25 @@
}); });
return syncMessage; return syncMessage;
} }
async function createGroupSyncProtoMessage(conversations) { function createGroupSyncProtoMessage(conversations) {
// We only want to sync across closed groups that we haven't left // We only want to sync across closed groups that we haven't left
const sessionGroups = conversations.filter( const sessionGroups = conversations.filter(
c => c.isClosedGroup() && !c.get('left') && c.isFriend() c => c.isClosedGroup() && !c.get('left') && c.isFriend()
); );
const rawGroups = await Promise.all(
sessionGroups.map(async conversation => ({ if (sessionGroups.length === 0) {
id: conversation.id, return null;
name: conversation.get('name'), }
members: conversation.get('members') || [],
blocked: conversation.isBlocked(), const rawGroups = sessionGroups.map(conversation => ({
expireTimer: conversation.get('expireTimer'), id: window.Signal.Crypto.bytesFromString(conversation.id),
admins: conversation.get('groupAdmins') || [], name: conversation.get('name'),
})) members: conversation.get('members') || [],
); blocked: conversation.isBlocked(),
expireTimer: conversation.get('expireTimer'),
admins: conversation.get('groupAdmins') || [],
}));
// Convert raw groups to an array of buffers // Convert raw groups to an array of buffers
const groupDetails = rawGroups const groupDetails = rawGroups
.map(x => new textsecure.protobuf.GroupDetails(x)) .map(x => new textsecure.protobuf.GroupDetails(x))
@ -210,13 +221,6 @@
profile, profile,
profileKey, profileKey,
}); });
// Attach contact list
const conversations = await window.Signal.Data.getConversationsWithFriendStatus(
window.friends.friendRequestStatusEnum.friends,
{ ConversationCollection: Whisper.ConversationCollection }
);
const syncMessage = await createContactSyncProtoMessage(conversations);
content.syncMessage = syncMessage;
content.dataMessage = dataMessage; content.dataMessage = dataMessage;
} }
// Send // Send

@ -634,10 +634,10 @@
blockSync: true, blockSync: true,
} }
); );
// Send group sync message // Send sync messages
await textsecure.messaging.sendGroupSyncMessage( const conversations = window.getConversations().models;
window.getConversations() textsecure.messaging.sendContactSyncMessage(conversations);
); textsecure.messaging.sendGroupSyncMessage(conversations);
}, },
validatePubKeyHex(pubKey) { validatePubKeyHex(pubKey) {
const c = new Whisper.Conversation({ const c = new Whisper.Conversation({

@ -664,58 +664,67 @@ MessageSender.prototype = {
return Promise.resolve(); return Promise.resolve();
}, },
async sendContactSyncMessage(contactConversation) { async sendContactSyncMessage(conversations) {
if (!contactConversation.isPrivate()) { // If we havn't got a primaryDeviceKey then we are in the middle of pairing
return Promise.resolve(); // primaryDevicePubKey is set to our own number if we are the master device
}
const primaryDeviceKey = window.storage.get('primaryDevicePubKey'); const primaryDeviceKey = window.storage.get('primaryDevicePubKey');
const allOurDevices = (await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( if (!primaryDeviceKey) {
primaryDeviceKey
))
// Don't send to ourselves
.filter(pubKey => pubKey !== textsecure.storage.user.getNumber());
if (
allOurDevices.includes(contactConversation.id) ||
!primaryDeviceKey ||
allOurDevices.length === 0
) {
// If we havn't got a primaryDeviceKey then we are in the middle of pairing
return Promise.resolve(); return Promise.resolve();
} }
const syncMessage = await libloki.api.createContactSyncProtoMessage([ // We need to sync across 3 contacts at a time
contactConversation, // This is to avoid hitting storage server limit
]); const chunked = _.chunk(conversations, 3);
const contentMessage = new textsecure.protobuf.Content(); const syncMessages = await Promise.all(
contentMessage.syncMessage = syncMessage; chunked.map(c => libloki.api.createContactSyncProtoMessage(c))
const silent = true;
return this.sendIndividualProto(
primaryDeviceKey,
contentMessage,
Date.now(),
silent,
{} // options
); );
const syncPromises = syncMessages
.filter(message => message != null)
.map(syncMessage => {
const contentMessage = new textsecure.protobuf.Content();
contentMessage.syncMessage = syncMessage;
const silent = true;
return this.sendIndividualProto(
primaryDeviceKey,
contentMessage,
Date.now(),
silent,
{} // options
);
});
return Promise.all(syncPromises);
}, },
async sendGroupSyncMessage(conversations) { sendGroupSyncMessage(conversations) {
const ourNumber = textsecure.storage.user.getNumber(); // If we havn't got a primaryDeviceKey then we are in the middle of pairing
const syncMessage = await libloki.api.createGroupSyncProtoMessage( // primaryDevicePubKey is set to our own number if we are the master device
conversations const primaryDeviceKey = window.storage.get('primaryDevicePubKey');
); if (!primaryDeviceKey) {
const contentMessage = new textsecure.protobuf.Content(); return Promise.resolve();
contentMessage.syncMessage = syncMessage; }
const silent = true; // We need to sync across 1 group at a time
return this.sendIndividualProto( // This is because we could hit the storage server limit with one group
ourNumber, const syncPromises = conversations
contentMessage, .map(c => libloki.api.createGroupSyncProtoMessage([c]))
Date.now(), .filter(message => message != null)
silent, .map(syncMessage => {
{} // options const contentMessage = new textsecure.protobuf.Content();
); contentMessage.syncMessage = syncMessage;
const silent = true;
return this.sendIndividualProto(
primaryDeviceKey,
contentMessage,
Date.now(),
silent,
{} // options
);
});
return Promise.all(syncPromises);
}, },
sendRequestContactSyncMessage(options) { sendRequestContactSyncMessage(options) {
@ -1277,6 +1286,7 @@ textsecure.MessageSender = function MessageSenderWrapper(username, password) {
sender sender
); );
this.sendContactSyncMessage = sender.sendContactSyncMessage.bind(sender); this.sendContactSyncMessage = sender.sendContactSyncMessage.bind(sender);
this.sendGroupSyncMessage = sender.sendGroupSyncMessage.bind(sender);
this.sendRequestConfigurationSyncMessage = sender.sendRequestConfigurationSyncMessage.bind( this.sendRequestConfigurationSyncMessage = sender.sendRequestConfigurationSyncMessage.bind(
sender sender
); );

Loading…
Cancel
Save