Fix FR logic

pull/1137/head
Mikunj 5 years ago
parent 2cd07285d9
commit df44e5afca

@ -1059,6 +1059,9 @@
}, },
// We have accepted an incoming friend request // We have accepted an incoming friend request
async onAcceptFriendRequest(options = {}) { async onAcceptFriendRequest(options = {}) {
if (this.get('type') !== Message.PRIVATE) {
return;
}
if (this.unlockTimer) { if (this.unlockTimer) {
clearTimeout(this.unlockTimer); clearTimeout(this.unlockTimer);
} }
@ -1075,14 +1078,12 @@
window.textsecure.OutgoingMessage.DebugMessageType window.textsecure.OutgoingMessage.DebugMessageType
.INCOMING_FR_ACCEPTED .INCOMING_FR_ACCEPTED
); );
} else if (this.isFriendRequestStatusNoneOrExpired()) {
// send an AFR to other device of that user (or none) // send AFR if we haven't sent a message before
const primaryPubKey = await libloki.api.getPrimaryDevicePubkey(this.id);
const autoFrMessage = textsecure.OutgoingMessage.buildAutoFriendRequestMessage( const autoFrMessage = textsecure.OutgoingMessage.buildAutoFriendRequestMessage(
primaryPubKey this.id
); );
await autoFrMessage.sendToNumber(primaryPubKey, true, this.id); await autoFrMessage.sendToNumber(this.id, false);
} }
}, },
// Our outgoing friend request has been accepted // Our outgoing friend request has been accepted

@ -415,21 +415,19 @@
}, },
async acceptFriendRequest() { async acceptFriendRequest() {
const primaryDevicePubKey = this.attributes.conversationId;
if (this.get('friendStatus') !== 'pending') { if (this.get('friendStatus') !== 'pending') {
return; return;
} }
const allDevices = await libloki.storage.getAllDevicePubKeysForPrimaryPubKey( const devicePubKey = this.get('conversationId');
primaryDevicePubKey const otherDevices = await libloki.storage.getPairedDevicesFor(devicePubKey);
); const allDevices = [devicePubKey, ...otherDevices];
// Set profile name to primary conversation // Set profile name to primary conversation
let profileName; let profileName;
const allConversationsWithUser = allDevices.map(d => const allConversationsWithUser = allDevices.map(d =>
ConversationController.get(d) ConversationController.get(d)
); ).filter(c => Boolean(c));
allConversationsWithUser.forEach(conversation => { allConversationsWithUser.forEach(conversation => {
// If we somehow received an old friend request (e.g. after having restored // If we somehow received an old friend request (e.g. after having restored
// from seed, we won't be able to accept it, we should initiate our own // from seed, we won't be able to accept it, we should initiate our own
@ -447,6 +445,7 @@
// If you don't have a profile name for this device, and profileName is set, // If you don't have a profile name for this device, and profileName is set,
// add profileName to conversation. // add profileName to conversation.
const primaryDevicePubKey = (await libloki.storage.getPrimaryDeviceFor(devicePubKey)) || devicePubKey;
const primaryConversation = allConversationsWithUser.find( const primaryConversation = allConversationsWithUser.find(
c => c.id === primaryDevicePubKey c => c.id === primaryDevicePubKey
); );
@ -471,13 +470,21 @@
if (this.get('friendStatus') !== 'pending') { if (this.get('friendStatus') !== 'pending') {
return; return;
} }
const conversation = this.getConversation();
this.set({ friendStatus: 'declined' }); this.set({ friendStatus: 'declined' });
await window.Signal.Data.saveMessage(this.attributes, { await window.Signal.Data.saveMessage(this.attributes, {
Message: Whisper.Message, Message: Whisper.Message,
}); });
conversation.onDeclineFriendRequest();
const devicePubKey = this.attributes.conversationId;
const otherDevices = await libloki.storage.getPairedDevicesFor(devicePubKey);
const allDevices = [devicePubKey, ...otherDevices];
const allConversationsWithUser = allDevices.map(d =>
ConversationController.get(d)
).filter(c => Boolean(c));
allConversationsWithUser.forEach(conversation => {
conversation.onDeclineFriendRequest();
});
}, },
getPropsForFriendRequest() { getPropsForFriendRequest() {
const friendStatus = this.get('friendStatus') || 'pending'; const friendStatus = this.get('friendStatus') || 'pending';
@ -2571,7 +2578,7 @@
} }
// We need to map the original message source to the primary device // We need to map the original message source to the primary device
if (source !== ourNumber && !message.isFriendRequest()) { if (source !== ourNumber) {
message.set({ source: primarySource }); message.set({ source: primarySource });
} }

Loading…
Cancel
Save