diff --git a/js/models/conversations.js b/js/models/conversations.js index 134ff543f..34384145a 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -685,6 +685,10 @@ friendStatus: 'pending', direction: 'incoming', preKeyBundle: null, + timestamp: null, + source: null, + sourceDevice: null, + received_at: null, ...options, }; @@ -695,13 +699,13 @@ return; } - const lastMessage = this.get('timestamp') || Date.now(); + const timestamp = _options.timestamp || this.get('timestamp') || Date.now(); window.log.info( 'adding friend request for', this.ourNumber, this.idForLogging(), - lastMessage + timestamp ); this.lastMessageStatus = 'sending'; @@ -731,12 +735,12 @@ } // Add the new message - const timestamp = Date.now(); + const received_at = _options.received_at || Date.now(); const message = { conversationId: this.id, type: 'friend-request', - sent_at: lastMessage, - received_at: timestamp, + sent_at: timestamp, + received_at, unread: 1, from: this.id, to: this.ourNumber, @@ -744,6 +748,8 @@ direction: _options.direction, body, preKeyBundle: _options.preKeyBundle, + source: _options.source, + sourceDevice: _options.sourceDevice, }; const id = await window.Signal.Data.saveMessage(message, { diff --git a/js/views/app_view.js b/js/views/app_view.js index d1dd803c2..bcf325768 100644 --- a/js/views/app_view.js +++ b/js/views/app_view.js @@ -178,12 +178,13 @@ }); } }, - async showFriendRequest({ pubKey, message, preKeyBundle }) { + async showFriendRequest({ pubKey, message, preKeyBundle, options }) { const controller = window.ConversationController; const conversation = await controller.getOrCreateAndWait(pubKey, 'private'); if (conversation) { conversation.addFriendRequest(message, { preKeyBundle: preKeyBundle || null, + ...options, }); } }, diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index e70ba299c..d721bc22e 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -934,11 +934,17 @@ MessageReceiver.prototype.extend({ return this.innerHandleContentMessage(envelope, plaintext); }); }, - promptUserToAcceptFriendRequest(pubKey, message, preKeyBundle) { + promptUserToAcceptFriendRequest(envelope, message, preKeyBundle) { window.Whisper.events.trigger('showFriendRequest', { - pubKey, + pubKey: envelope.source, message, preKeyBundle, + options: { + source: envelope.source, + sourceDevice: envelope.sourceDevice, + timestamp: envelope.timestamp.toNumber(), + receivedAt: envelope.receivedAt, + }, }); }, // A handler function for when a friend request is accepted or declined @@ -973,19 +979,22 @@ MessageReceiver.prototype.extend({ const content = textsecure.protobuf.Content.decode(plaintext); if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { - // only prompt friend request if there is no conversation yet let conversation; try { conversation = ConversationController.get(envelope.source); } catch (e) { } + + // only prompt friend request if there is no conversation yet if (!conversation) { this.promptUserToAcceptFriendRequest( - envelope.source, + envelope, content.dataMessage.body, content.preKeyBundle, ); - return; } + + // Exit early since the friend request reply will be a regular empty message + return; } // Check if our friend request got accepted