From 60ddaa14bef0473668ac34881884a47ee08383f1 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 19 May 2020 11:12:05 +1000 Subject: [PATCH] Prevent multiple FR conversations --- js/conversation_controller.js | 9 +++++++++ js/models/conversations.js | 9 ++++++++- js/models/messages.js | 19 ++++++++++++++++++- package.json | 2 +- .../session/LeftPaneContactSection.tsx | 2 ++ .../session/LeftPaneMessageSection.tsx | 2 +- ts/state/ducks/conversations.ts | 1 + 7 files changed, 40 insertions(+), 4 deletions(-) diff --git a/js/conversation_controller.js b/js/conversation_controller.js index 171703716..ea93a3437 100644 --- a/js/conversation_controller.js +++ b/js/conversation_controller.js @@ -87,6 +87,9 @@ ); } + console.log('[vince] Creating conversation with id:', id); + + if (!this._initialFetchComplete) { throw new Error( 'ConversationController.get() needs complete initial fetch' @@ -194,6 +197,12 @@ conversations.remove(conversation); }, getOrCreateAndWait(id, type) { + const ourNumber = textsecure.storage.user.getNumber(); + + if (id !== ourNumber) { + console.log('[vince][core] getOrCreateAndWaiting.. with source:', id); + } + return this._initialPromise.then(() => { const conversation = this.getOrCreate(id, type); diff --git a/js/models/conversations.js b/js/models/conversations.js index 3a84663dd..6be3aef1b 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -584,7 +584,6 @@ const result = { id: this.id, - isArchived: this.get('isArchived'), activeAt: this.get('active_at'), avatarPath: this.getAvatarPath(), @@ -1620,6 +1619,8 @@ FriendRequestStatusEnum.pendingSend ); + + // Always share our profileKey in the friend request // This will get added automatically after the FR // is accepted, via the profileSharing flag @@ -1637,6 +1638,9 @@ direction: 'outgoing', friendStatus: 'pending', }); + + console.log(`[vince][core] Sending FR message from conversations.js`, messageWithSchema); + } if (this.isPrivate()) { @@ -1658,6 +1662,9 @@ const model = this.addSingleMessage(attributes); const message = MessageController.register(model.id, model); + + console.log('[vince][core] Sending message:', message); + await window.Signal.Data.saveMessage(message.attributes, { forceSave: true, Message: Whisper.Message, diff --git a/js/models/messages.js b/js/models/messages.js index bb81814d0..516d8f1f8 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -429,6 +429,10 @@ return; } this.set({ friendStatus: 'accepted' }); + + console.log('[vince][core] this.attributes:', this.attributes); + console.log('[vince][core] This is the conversation youre accepting!! :', conversation); + await window.Signal.Data.saveMessage(this.attributes, { Message: Whisper.Message, }); @@ -2219,6 +2223,7 @@ let attributes = { ...conversation.attributes, }; + if (dataMessage.group) { let groupUpdate = null; attributes = { @@ -2508,6 +2513,7 @@ - We are friends with the user, and that user just sent us a friend request. */ + const isFriend = sendingDeviceConversation.isFriend(); const hasSentFriendRequest = sendingDeviceConversation.hasSentFriendRequest(); autoAccept = isFriend || hasSentFriendRequest; @@ -2515,6 +2521,12 @@ if (autoAccept) { message.set({ friendStatus: 'accepted' }); } + + + console.log('[vince][core] source:', source); + console.log('[vince][core] ourNumber:', ourNumber); + console.log('[vince][core] Friend request in messaages.js:2391', message); + libloki.api.debug.logNormalFriendRequest( `Received a NORMAL_FRIEND_REQUEST from source: ${source}, primarySource: ${primarySource}, isAlreadyFriend: ${isFriend}, didWeAlreadySentFR: ${hasSentFriendRequest}` @@ -2534,8 +2546,13 @@ } // We need to map the original message source to the primary device + // only map to primary device if this is NOT a friend request. + // Otherwise you can enter a stalemate. + const conditionalSource = message.get('type') === 'friend-request' + ? source + : primarySource; if (source !== ourNumber) { - message.set({ source: primarySource }); + message.set({ source: conditionalSource }); } const id = await window.Signal.Data.saveMessage(message.attributes, { diff --git a/package.json b/package.json index 4603dedd2..a75ced0ce 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "start-multi2": "cross-env NODE_APP_INSTANCE=2 electron .", "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod electron .", "start-prod-multi": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod1 electron .", - "start-prod-multi-2": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod2 electron .", + "start-prod-multi1": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod2 electron .", "start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=1 electron .", "start-swarm-test-2": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=2 electron .", "start-swarm-test-3": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=3 electron .", diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 75f5423f1..54dba48e6 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -123,6 +123,8 @@ export class LeftPaneContactSection extends React.Component { const item = receivedFriendsRequest[index]; const onClick = this.props.openConversationInternal; + console.log('[vince] renderRowFriendRequest: receivedFriendsRequest:', receivedFriendsRequest); + return ( { if (conversationList !== undefined) { conversationList = conversationList.filter( conversation => - !conversation.isSecondary && !conversation.isPendingFriendRequest + !conversation.isPendingFriendRequest ); } diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 219c66377..2305cae6d 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -55,6 +55,7 @@ export type ConversationType = { isFriend?: boolean; isSecondary?: boolean; primaryDevice: string; + isPendingFriendRequest?: boolean; hasReceivedFriendRequest?: boolean; hasSentFriendRequest?: boolean; };