Auto accept friend request if we have both incoming and outgoing friend requests.

pull/50/head
Mikunj 7 years ago
parent 8a0b8e1f00
commit fb8b0e1d40

@ -554,7 +554,8 @@
); );
// Update the UI // Update the UI
this.updateFriendRequestUI(); await this.updatePendingFriendRequests();
await this.updateFriendRequestUI();
}, },
async onFriendRequestSent() { async onFriendRequestSent() {
// Check if we need to set the friend request expiry // Check if we need to set the friend request expiry
@ -1285,20 +1286,17 @@
.map(request => this._removeMessage(request.id)) .map(request => this._removeMessage(request.id))
); );
// We also need to update any outgoing pending requests and set them to denied. // If we have an outgoing friend request then
// when we get an incoming friend request. // we auto accept the incoming friend request
const outgoing = await this.getPendingFriendRequests('outgoing'); const outgoing = await this.getPendingFriendRequests('outgoing');
await Promise.all( if (outgoing.length > 0) {
outgoing.map(async request => { const current = this.messageCollection.find(i => i.id === message.id);
if (request.hasErrors()) return; if (current) {
await current.acceptFriendRequest();
request.set({ friendStatus: 'declined' }); } else {
await window.Signal.Data.saveMessage(request.attributes, { window.log.debug('onNewMessage: Failed to find incoming friend request');
Message: Whisper.Message, }
}); }
this.trigger('updateMessage', request);
})
);
// Trigger an update if we removed or updated messages // Trigger an update if we removed or updated messages
if (outgoing.length > 0 || incoming.length > 0) if (outgoing.length > 0 || incoming.length > 0)

@ -297,34 +297,42 @@
// It doesn't need anything right now! // It doesn't need anything right now!
return {}; return {};
}, },
getPropsForFriendRequest() {
const friendStatus = this.get('friendStatus') || 'pending'; async acceptFriendRequest() {
const direction = this.get('direction') || 'incoming'; if (this.get('friendStatus') !== 'pending') return;
const conversation = this.getConversation(); const conversation = this.getConversation();
const onAccept = async () => { this.set({ friendStatus: 'accepted' });
this.set({ friendStatus: 'accepted' }); await window.Signal.Data.saveMessage(this.attributes, {
await window.Signal.Data.saveMessage(this.attributes, { Message: Whisper.Message,
Message: Whisper.Message, });
});
window.Whisper.events.trigger('friendRequestUpdated', { window.Whisper.events.trigger('friendRequestUpdated', {
pubKey: conversation.id, pubKey: conversation.id,
...this.attributes, ...this.attributes,
}); });
}; },
async declineFriendRequest() {
if (this.get('friendStatus') !== 'pending') return;
const conversation = this.getConversation();
const onDecline = async () => { this.set({ friendStatus: 'declined' });
this.set({ friendStatus: 'declined' }); await window.Signal.Data.saveMessage(this.attributes, {
await window.Signal.Data.saveMessage(this.attributes, { Message: Whisper.Message,
Message: Whisper.Message, });
});
window.Whisper.events.trigger('friendRequestUpdated', { window.Whisper.events.trigger('friendRequestUpdated', {
pubKey: conversation.id, pubKey: conversation.id,
...this.attributes, ...this.attributes,
}); });
}; },
getPropsForFriendRequest() {
const friendStatus = this.get('friendStatus') || 'pending';
const direction = this.get('direction') || 'incoming';
const conversation = this.getConversation();
const onAccept = () => this.acceptFriendRequest();
const onDecline = () => this.declineFriendRequest()
const onDeleteConversation = async () => { const onDeleteConversation = async () => {
// Delete the whole conversation // Delete the whole conversation

Loading…
Cancel
Save