Prompt user when an incoming friend request is received

pull/20/head
sachaaaaa 7 years ago
parent 143b1e883d
commit e1ffe582c3

@ -152,6 +152,9 @@
</script>
<script type='text/x-tmpl-mustache' id='confirmation-dialog'>
<div class="content">
{{ #title }}
<h4>{{ title }}</h4>
{{ /title }}
<div class='message'>{{ message }}</div>
<div class='buttons'>
{{ #showCancel }}

@ -595,6 +595,12 @@
});
}
});
Whisper.events.on('showFriendRequest', friendRequest => {
if (appView) {
appView.showFriendRequest(friendRequest);
}
});
}
window.getSyncRequest = () =>

@ -178,5 +178,16 @@
});
}
},
showFriendRequest({ pubKey, message, accept, decline }) {
const dialog = new Whisper.ConfirmationDialogView({
title: `${pubKey} sent you a friend request:`,
message: message,
okText: 'Accept',
cancelText: 'Decline',
resolve: accept,
reject: decline,
});
this.el.append(dialog.el);
},
});
})();

@ -19,6 +19,8 @@
this.reject = options.reject;
this.cancelText = options.cancelText || i18n('cancel');
this.title = options.title;
this.render();
},
events: {
@ -32,6 +34,7 @@
showCancel: !this.hideCancel,
cancel: this.cancelText,
ok: this.okText,
title: this.title,
};
},
ok() {

@ -836,9 +836,41 @@ MessageReceiver.prototype.extend({
}
});
},
async promptUserToAcceptFriendRequest(pubKey, message) {
pubKey = pubKey.slice(0,30)+"...";
let p = new Promise(resolve => {
window.Whisper.events.trigger('showFriendRequest', {
pubKey,
message,
accept: () => {
resolve(true);
},
decline: () => {
resolve(false);
}
});
});
return await p;
},
async innerHandleContentMessage(envelope, plaintext) {
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) {
}
if (!conversation) {
const accepted = await this.promptUserToAcceptFriendRequest(envelope.source, content.dataMessage.body);
if (!accepted) {
console.log('friend request declined!');
return;
}
}
}
if (content.preKeyBundleMessage) {
await this.handlePreKeyBundleMessage(envelope, content.preKeyBundleMessage);
}

Loading…
Cancel
Save