Trigger friend request received update for the correct device conversation, throttle the sending of automated friend requests and don't send them to devices which sent *us* a friend request

pull/604/head
Beaudan Brown 6 years ago
parent 30b26807e8
commit accd16cae1

@ -931,6 +931,13 @@
} }
await this.setFriendRequestStatus(FriendRequestStatusEnum.requestSent); await this.setFriendRequestStatus(FriendRequestStatusEnum.requestSent);
}, },
friendRequestTimerIsExpired() {
const unlockTimestamp = this.get('unlockTimestamp');
if (unlockTimestamp && unlockTimestamp > Date.now()) {
return false;
}
return true;
},
setFriendRequestExpiryTimeout() { setFriendRequestExpiryTimeout() {
if (this.isFriend()) { if (this.isFriend()) {
return; return;

@ -361,7 +361,7 @@
if (this.get('friendStatus') !== 'pending') { if (this.get('friendStatus') !== 'pending') {
return; return;
} }
const conversation = this.getConversation(); const conversation = await this.getSourceDeviceConversation();
this.set({ friendStatus: 'accepted' }); this.set({ friendStatus: 'accepted' });
await window.Signal.Data.saveMessage(this.attributes, { await window.Signal.Data.saveMessage(this.attributes, {
@ -1119,6 +1119,14 @@
// the database. // the database.
return ConversationController.getUnsafe(this.get('conversationId')); return ConversationController.getUnsafe(this.get('conversationId'));
}, },
getSourceDeviceConversation() {
// This gets the conversation of the device that sent this message
// while getConversation will return the primary device conversation
return ConversationController.getOrCreateAndWait(
this.get('source'),
'private'
);
},
getIncomingContact() { getIncomingContact() {
if (!this.isIncoming()) { if (!this.isIncoming()) {
return null; return null;

@ -355,10 +355,23 @@ OutgoingMessage.prototype = {
} catch (e) { } catch (e) {
// do nothing // do nothing
} }
// TODO: Make sure we retry sending friend request messages to all our friends if (
if (conversation && !conversation.isFriend()) { conversation &&
!conversation.isFriend() &&
!conversation.hasReceivedFriendRequest()
) {
// We want to send an automated friend request if:
// - We aren't already friends
// - We haven't received a friend request from this device
// - We haven't sent a friend request recently
if (conversation.friendRequestTimerIsExpired()) {
isMultiDeviceRequest = true; isMultiDeviceRequest = true;
thisDeviceMessageType = 'friend-request'; thisDeviceMessageType = 'friend-request';
} else {
// Throttle automated friend requests
this.successfulNumbers.push(devicePubKey);
return null;
}
} }
} }
@ -456,6 +469,9 @@ OutgoingMessage.prototype = {
.then(async outgoingObjects => { .then(async outgoingObjects => {
// TODO: handle multiple devices/messages per transmit // TODO: handle multiple devices/messages per transmit
const promises = outgoingObjects.map(async outgoingObject => { const promises = outgoingObjects.map(async outgoingObject => {
if (!outgoingObject) {
return;
}
const destination = outgoingObject.pubKey; const destination = outgoingObject.pubKey;
try { try {
const socketMessage = await this.wrapInWebsocketMessage( const socketMessage = await this.wrapInWebsocketMessage(

Loading…
Cancel
Save