Merge pull request #499 from sachaaaaa/auto_friend_secondary

[multi-device] Auto friend request to sync contacts
pull/509/head
sachaaaaa 6 years ago committed by GitHub
commit 7ff32258f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1147,6 +1147,7 @@ MessageReceiver.prototype.extend({
// This call already removes the envelope from the cache
await this.handleContacts(envelope, syncMessage.contacts);
removedFromCache = true;
await this.sendFriendRequestsToSyncContacts(syncMessage.contacts);
}
} else {
window.log.warn('Unimplemented pairing authorisation message type');
@ -1156,6 +1157,31 @@ MessageReceiver.prototype.extend({
await this.removeFromCache(envelope);
}
},
async sendFriendRequestsToSyncContacts(contacts) {
const attachmentPointer = await this.handleAttachment(contacts);
const contactBuffer = new ContactBuffer(attachmentPointer.data);
let contactDetails = contactBuffer.next();
// Extract just the pubkeys
const friendPubKeys = []
while (contactDetails !== undefined) {
friendPubKeys.push(contactDetails.number);
contactDetails = contactBuffer.next();
}
return Promise.all(
friendPubKeys.map(async pubKey => {
const c = await window.ConversationController.getOrCreateAndWait(pubKey, 'private');
if (!c) {
return null;
}
const attachments = [];
const quote = null;
const linkPreview = null;
// Send an empty message, the underlying logic will know
// it should send a friend request
return c.sendMessage('', attachments, quote, linkPreview);
})
);
},
async handleAuthorisationForContact(envelope, pairingAuthorisation) {
const valid = await this.validateAuthorisation(pairingAuthorisation);
if (!valid) {

Loading…
Cancel
Save