Simplification

pull/1138/head
Vincent 5 years ago
parent 1f9b3ce5ea
commit 1b345bce42

@ -994,21 +994,15 @@
ConversationController.get(d) ConversationController.get(d)
); );
const pendingRequests = await allConversationsWithUser.reduce( const pendingRequestPromises = allConversationsWithUser.map(c =>
async (requestsP, conversation) => { c.getFriendRequests(direction, status)
const requests = await requestsP; )[0];
const request = (await conversation.getFriendRequests(
direction, let pendingRequests = await Promise.all(pendingRequestPromises);
status pendingRequests = pendingRequests.filter(p => Boolean(p.length));
))[0];
return request
? requests.concat({ conversation, request })
: requests;
},
[]
);
// We set all friend request messages from all devices
// from a user here to accepted where possible
await Promise.all( await Promise.all(
pendingRequests.map(async friendRequest => { pendingRequests.map(async friendRequest => {
const { conversation, request } = friendRequest; const { conversation, request } = friendRequest;

@ -425,6 +425,7 @@
primaryDevicePubKey primaryDevicePubKey
); );
// Set profile name to primary conversation
let profileName; let profileName;
const allConversationsWithUser = allDevices.map(d => const allConversationsWithUser = allDevices.map(d =>
ConversationController.get(d) ConversationController.get(d)
@ -458,6 +459,13 @@
}); });
this.set({ friendStatus: 'accepted' }); this.set({ friendStatus: 'accepted' });
// Update redux store
window.Signal.Data.updateConversation(
primaryConversation.id,
primaryConversation.attributes,
{ Conversation: Whisper.Conversation }
);
}, },
async declineFriendRequest() { async declineFriendRequest() {
if (this.get('friendStatus') !== 'pending') { if (this.get('friendStatus') !== 'pending') {

@ -1045,45 +1045,6 @@ MessageReceiver.prototype.extend({
return this.handlePairingRequest(envelope, pairingAuthorisation); return this.handlePairingRequest(envelope, pairingAuthorisation);
}, },
async handleSecondaryDeviceFriendRequest(pubKey, deviceMapping) {
if (!deviceMapping) {
return false;
}
// Only handle secondary pubkeys
if (deviceMapping.isPrimary === '1' || !deviceMapping.authorisations) {
return false;
}
const { authorisations } = deviceMapping;
// Secondary devices should only have 1 authorisation from a primary device
if (authorisations.length !== 1) {
return false;
}
const authorisation = authorisations[0];
if (!authorisation) {
return false;
}
if (!authorisation.grantSignature) {
return false;
}
const isValid = await libloki.crypto.validateAuthorisation(authorisation);
if (!isValid) {
return false;
}
const correctSender = pubKey === authorisation.secondaryDevicePubKey;
if (!correctSender) {
return false;
}
const { primaryDevicePubKey } = authorisation;
// ensure the primary device is a friend
const c = window.ConversationController.get(primaryDevicePubKey);
if (!c || (await !c.isFriendWithAnyDevice())) {
return false;
}
await libloki.storage.savePairingAuthorisation(authorisation);
return true;
},
async updateProfile(conversation, profile, profileKey) { async updateProfile(conversation, profile, profileKey) {
// Retain old values unless changed: // Retain old values unless changed:
const newProfile = conversation.get('profile') || {}; const newProfile = conversation.get('profile') || {};

Loading…
Cancel
Save