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

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

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

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

Loading…
Cancel
Save