Rename blockSync, only send contacts and profile if sending a GRANT request, do *not* always be friends with secondary devices because we still need to complete a friend request exchange

pull/606/head
Beaudan Brown 5 years ago
parent 332cd30052
commit c31535edb4

@ -1244,7 +1244,7 @@
libloki.api.sendBackgroundMessage(conversation.id); libloki.api.sendBackgroundMessage(conversation.id);
} else { } else {
// Accept any pending friend requests if there are any // Accept any pending friend requests if there are any
conversation.onAcceptFriendRequest({ fromContactSync: true }); conversation.onAcceptFriendRequest({ blockSync: true });
} }
if (details.profileKey) { if (details.profileKey) {

@ -775,7 +775,7 @@
} }
}, },
async setFriendRequestStatus(newStatus, options = {}) { async setFriendRequestStatus(newStatus, options = {}) {
const { fromContactSync } = options; const { blockSync } = options;
// Ensure that the new status is a valid FriendStatusEnum value // Ensure that the new status is a valid FriendStatusEnum value
if (!(newStatus in Object.values(FriendRequestStatusEnum))) { if (!(newStatus in Object.values(FriendRequestStatusEnum))) {
return; return;
@ -792,7 +792,7 @@
Conversation: Whisper.Conversation, Conversation: Whisper.Conversation,
}); });
await this.updateTextInputState(); await this.updateTextInputState();
if (!fromContactSync && newStatus === FriendRequestStatusEnum.friends) { if (!blockSync && newStatus === FriendRequestStatusEnum.friends) {
// Sync contact // Sync contact
this.wrapSend(textsecure.messaging.sendContactSyncMessage(this)); this.wrapSend(textsecure.messaging.sendContactSyncMessage(this));
} }

@ -165,33 +165,28 @@
ourNumber, ourNumber,
'private' 'private'
); );
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(
lokiProfile
);
const dataMessage = new textsecure.protobuf.DataMessage({
profile,
});
// Attach contact list
const conversations = await window.Signal.Data.getConversationsWithFriendStatus(
window.friends.friendRequestStatusEnum.friends,
{ ConversationCollection: Whisper.ConversationCollection }
);
const syncMessage = await createContactSyncProtoMessage(conversations);
const content = new textsecure.protobuf.Content({ const content = new textsecure.protobuf.Content({
pairingAuthorisation, pairingAuthorisation,
dataMessage,
syncMessage,
}); });
const isGrant = authorisation.primaryDevicePubKey === ourNumber;
if (isGrant) {
// Send profile name to secondary device
const lokiProfile = ourConversation.getLokiProfile();
const profile = new textsecure.protobuf.DataMessage.LokiProfile(
lokiProfile
);
const dataMessage = new textsecure.protobuf.DataMessage({
profile,
});
// 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 // Send
const options = { messageType: 'pairing-request' }; const options = { messageType: 'pairing-request' };
const p = new Promise((resolve, reject) => { const p = new Promise((resolve, reject) => {

@ -1232,8 +1232,6 @@ MessageReceiver.prototype.extend({
return false; return false;
} }
await libloki.storage.savePairingAuthorisation(authorisation); await libloki.storage.savePairingAuthorisation(authorisation);
// sending a message back = accepting friend request
window.libloki.api.sendBackgroundMessage(pubKey);
return true; return true;
}, },
@ -1293,7 +1291,12 @@ MessageReceiver.prototype.extend({
deviceMapping deviceMapping
); );
if (autoAccepted) { if (autoAccepted) {
await conversation.onFriendRequestAccepted(); // sending a message back = accepting friend request
// Directly setting friend request status to skip the pending state
await conversation.setFriendRequestStatus(
window.friends.friendRequestStatusEnum.friends
);
window.libloki.api.sendBackgroundMessage(envelope.source);
return this.removeFromCache(envelope); return this.removeFromCache(envelope);
} }
} }

Loading…
Cancel
Save