Handle sync messages properly for some edge cases, ensure we always have a primaryDevicePubKey, send contact sync message

pull/601/head
Beaudan Brown 6 years ago
parent 722c10dd70
commit f16b032056

@ -192,7 +192,10 @@
}, },
isMe() { isMe() {
return this.id === this.ourNumber; return (
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:/);

@ -1261,7 +1261,9 @@
}); });
this.trigger('sent', this); this.trigger('sent', this);
this.sendSyncMessage(); if (this.get('type') !== 'friend-request') {
this.sendSyncMessage();
}
}) })
.catch(result => { .catch(result => {
this.trigger('done'); this.trigger('done');
@ -1702,6 +1704,7 @@
// 2. on a sent message sync'd from another device // 2. on a sent message sync'd from another device
// 3. in rare cases, an incoming message can be retried, though it will // 3. in rare cases, an incoming message can be retried, though it will
// still go through one of the previous two codepaths // still go through one of the previous two codepaths
const ourNumber = textsecure.storage.user.getNumber();
const message = this; const message = this;
const source = message.get('source'); const source = message.get('source');
const type = message.get('type'); const type = message.get('type');
@ -1711,7 +1714,8 @@
); );
if (initialMessage.group) { if (initialMessage.group) {
conversationId = initialMessage.group.id; conversationId = initialMessage.group.id;
} else if (authorisation) { } else if (source !== ourNumber && authorisation) {
// Ignore auth from our devices
conversationId = authorisation.primaryDevicePubKey; conversationId = authorisation.primaryDevicePubKey;
} }
@ -1908,8 +1912,6 @@
c.onReadMessage(message); c.onReadMessage(message);
} }
} else { } else {
const ourNumber = textsecure.storage.user.getNumber();
if ( if (
message.attributes.body && message.attributes.body &&
message.attributes.body.indexOf(`@${ourNumber}`) !== -1 message.attributes.body.indexOf(`@${ourNumber}`) !== -1
@ -1999,12 +2001,12 @@
autoAccept = true; autoAccept = true;
message.set({ friendStatus: 'accepted' }); message.set({ friendStatus: 'accepted' });
await sendingDeviceConversation.onFriendRequestAccepted(); await sendingDeviceConversation.onFriendRequestAccepted();
window.libloki.api.sendBackgroundMessage(message.get('source'));
} else { } else {
await sendingDeviceConversation.onFriendRequestReceived(); await sendingDeviceConversation.onFriendRequestReceived();
} }
} else { } else if (message.get('type') !== 'outgoing') {
await conversation.onFriendRequestAccepted(); // Ignore 'outgoing' messages because they are sync messages
await sendingDeviceConversation.onFriendRequestAccepted();
// We need to return for these types of messages because android struggles // We need to return for these types of messages because android struggles
if ( if (
!message.get('body') && !message.get('body') &&

@ -164,13 +164,21 @@
const pairingAuthorisation = createPairingAuthorisationProtoMessage( const pairingAuthorisation = createPairingAuthorisationProtoMessage(
authorisation authorisation
); );
// Send profile name to secondary device
const ourNumber = textsecure.storage.user.getNumber(); const ourNumber = textsecure.storage.user.getNumber();
const conversation = await ConversationController.getOrCreateAndWait( const ourConversation = await ConversationController.getOrCreateAndWait(
ourNumber, ourNumber,
'private' 'private'
); );
const lokiProfile = conversation.getLokiProfile(); const secondaryConversation = await ConversationController.getOrCreateAndWait(
recipientPubKey,
'private'
);
// Always be friends with secondary devices
secondaryConversation.setFriendRequestStatus(
window.friends.friendRequestStatusEnum.friends
);
// Send profile name to secondary device
const lokiProfile = ourConversation.getLokiProfile();
const profile = new textsecure.protobuf.DataMessage.LokiProfile( const profile = new textsecure.protobuf.DataMessage.LokiProfile(
lokiProfile lokiProfile
); );
@ -178,12 +186,11 @@
profile, profile,
}); });
// Attach contact list // Attach contact list
// TODO: Reenable sending of the syncmessage for pairing requests const syncMessage = await createContactSyncProtoMessage();
// const syncMessage = await createContactSyncProtoMessage();
const content = new textsecure.protobuf.Content({ const content = new textsecure.protobuf.Content({
pairingAuthorisation, pairingAuthorisation,
dataMessage, dataMessage,
// syncMessage, syncMessage,
}); });
// Send // Send
const options = { messageType: 'pairing-request' }; const options = { messageType: 'pairing-request' };

@ -239,6 +239,7 @@
getAuthorisationForSecondaryPubKey, getAuthorisationForSecondaryPubKey,
getAllDevicePubKeysForPrimaryPubKey, getAllDevicePubKeysForPrimaryPubKey,
getSecondaryDevicesFor, getSecondaryDevicesFor,
getPrimaryDeviceMapping,
}; };
// Libloki protocol store // Libloki protocol store

@ -546,6 +546,10 @@
async registrationDone(number, displayName) { async registrationDone(number, displayName) {
window.log.info('registration done'); window.log.info('registration done');
if (!textsecure.storage.get('secondaryDeviceStatus')) {
// We have registered as a primary device
textsecure.storage.put('primaryDevicePubKey', number);
}
// Ensure that we always have a conversation for ourself // Ensure that we always have a conversation for ourself
const conversation = await ConversationController.getOrCreateAndWait( const conversation = await ConversationController.getOrCreateAndWait(
number, number,

Loading…
Cancel
Save