pass in source, sourceDevice, timestamp and receivedAt when adding a friend request.

pull/38/head
Mikunj 7 years ago
parent cb46dd3adb
commit 688f275262

@ -685,6 +685,10 @@
friendStatus: 'pending', friendStatus: 'pending',
direction: 'incoming', direction: 'incoming',
preKeyBundle: null, preKeyBundle: null,
timestamp: null,
source: null,
sourceDevice: null,
received_at: null,
...options, ...options,
}; };
@ -695,13 +699,13 @@
return; return;
} }
const lastMessage = this.get('timestamp') || Date.now(); const timestamp = _options.timestamp || this.get('timestamp') || Date.now();
window.log.info( window.log.info(
'adding friend request for', 'adding friend request for',
this.ourNumber, this.ourNumber,
this.idForLogging(), this.idForLogging(),
lastMessage timestamp
); );
this.lastMessageStatus = 'sending'; this.lastMessageStatus = 'sending';
@ -731,12 +735,12 @@
} }
// Add the new message // Add the new message
const timestamp = Date.now(); const received_at = _options.received_at || Date.now();
const message = { const message = {
conversationId: this.id, conversationId: this.id,
type: 'friend-request', type: 'friend-request',
sent_at: lastMessage, sent_at: timestamp,
received_at: timestamp, received_at,
unread: 1, unread: 1,
from: this.id, from: this.id,
to: this.ourNumber, to: this.ourNumber,
@ -744,6 +748,8 @@
direction: _options.direction, direction: _options.direction,
body, body,
preKeyBundle: _options.preKeyBundle, preKeyBundle: _options.preKeyBundle,
source: _options.source,
sourceDevice: _options.sourceDevice,
}; };
const id = await window.Signal.Data.saveMessage(message, { const id = await window.Signal.Data.saveMessage(message, {

@ -178,12 +178,13 @@
}); });
} }
}, },
async showFriendRequest({ pubKey, message, preKeyBundle }) { async showFriendRequest({ pubKey, message, preKeyBundle, options }) {
const controller = window.ConversationController; const controller = window.ConversationController;
const conversation = await controller.getOrCreateAndWait(pubKey, 'private'); const conversation = await controller.getOrCreateAndWait(pubKey, 'private');
if (conversation) { if (conversation) {
conversation.addFriendRequest(message, { conversation.addFriendRequest(message, {
preKeyBundle: preKeyBundle || null, preKeyBundle: preKeyBundle || null,
...options,
}); });
} }
}, },

@ -934,11 +934,17 @@ MessageReceiver.prototype.extend({
return this.innerHandleContentMessage(envelope, plaintext); return this.innerHandleContentMessage(envelope, plaintext);
}); });
}, },
promptUserToAcceptFriendRequest(pubKey, message, preKeyBundle) { promptUserToAcceptFriendRequest(envelope, message, preKeyBundle) {
window.Whisper.events.trigger('showFriendRequest', { window.Whisper.events.trigger('showFriendRequest', {
pubKey, pubKey: envelope.source,
message, message,
preKeyBundle, 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 // 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); const content = textsecure.protobuf.Content.decode(plaintext);
if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) { if (envelope.type === textsecure.protobuf.Envelope.Type.FRIEND_REQUEST) {
// only prompt friend request if there is no conversation yet
let conversation; let conversation;
try { try {
conversation = ConversationController.get(envelope.source); conversation = ConversationController.get(envelope.source);
} catch (e) { } } catch (e) { }
// only prompt friend request if there is no conversation yet
if (!conversation) { if (!conversation) {
this.promptUserToAcceptFriendRequest( this.promptUserToAcceptFriendRequest(
envelope.source, envelope,
content.dataMessage.body, content.dataMessage.body,
content.preKeyBundle, content.preKeyBundle,
); );
return;
} }
// Exit early since the friend request reply will be a regular empty message
return;
} }
// Check if our friend request got accepted // Check if our friend request got accepted

Loading…
Cancel
Save