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);
},
friendRequestTimerIsExpired() {
const unlockTimestamp = this.get('unlockTimestamp');
if (unlockTimestamp && unlockTimestamp > Date.now()) {
return false;
}
return true;
},
setFriendRequestExpiryTimeout() {
if (this.isFriend()) {
return;

@ -361,7 +361,7 @@
if (this.get('friendStatus') !== 'pending') {
return;
}
const conversation = this.getConversation();
const conversation = await this.getSourceDeviceConversation();
this.set({ friendStatus: 'accepted' });
await window.Signal.Data.saveMessage(this.attributes, {
@ -1119,6 +1119,14 @@
// the database.
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() {
if (!this.isIncoming()) {
return null;

@ -355,10 +355,23 @@ OutgoingMessage.prototype = {
} catch (e) {
// do nothing
}
// TODO: Make sure we retry sending friend request messages to all our friends
if (conversation && !conversation.isFriend()) {
isMultiDeviceRequest = true;
thisDeviceMessageType = 'friend-request';
if (
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;
thisDeviceMessageType = 'friend-request';
} else {
// Throttle automated friend requests
this.successfulNumbers.push(devicePubKey);
return null;
}
}
}
@ -456,6 +469,9 @@ OutgoingMessage.prototype = {
.then(async outgoingObjects => {
// TODO: handle multiple devices/messages per transmit
const promises = outgoingObjects.map(async outgoingObject => {
if (!outgoingObject) {
return;
}
const destination = outgoingObject.pubKey;
try {
const socketMessage = await this.wrapInWebsocketMessage(

Loading…
Cancel
Save