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

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

@ -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, {

@ -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,
});
}
},

@ -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

Loading…
Cancel
Save