Don't send contact sync message with pairing authorisation.

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

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

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

@ -229,7 +229,7 @@ class LokiAppDotNetServerAPI {
window.storage.get('primaryDevicePubKey') ||
textsecure.storage.user.getNumber();
const profileConvo = ConversationController.get(ourNumber);
const profile = profileConvo.getLokiProfile();
const profile = profileConvo && profileConvo.getLokiProfile();
const profileName = profile && profile.displayName;
// if doesn't match, write it to the network
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
(function() {
@ -109,7 +109,14 @@
}
async function createContactSyncProtoMessage(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(
sessionContacts.map(async conversation => {
const profile = conversation.getLokiProfile();
@ -152,21 +159,25 @@
});
return syncMessage;
}
async function createGroupSyncProtoMessage(conversations) {
function createGroupSyncProtoMessage(conversations) {
// We only want to sync across closed groups that we haven't left
const sessionGroups = conversations.filter(
c => c.isClosedGroup() && !c.get('left') && c.isFriend()
);
const rawGroups = await Promise.all(
sessionGroups.map(async conversation => ({
id: conversation.id,
name: conversation.get('name'),
members: conversation.get('members') || [],
blocked: conversation.isBlocked(),
expireTimer: conversation.get('expireTimer'),
admins: conversation.get('groupAdmins') || [],
}))
);
if (sessionGroups.length === 0) {
return null;
}
const rawGroups = sessionGroups.map(conversation => ({
id: window.Signal.Crypto.bytesFromString(conversation.id),
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
const groupDetails = rawGroups
.map(x => new textsecure.protobuf.GroupDetails(x))
@ -210,13 +221,6 @@
profile,
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;
}
// Send

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

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

Loading…
Cancel
Save