Simplification

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

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

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

@ -1045,45 +1045,6 @@ MessageReceiver.prototype.extend({
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) {
// Retain old values unless changed:
const newProfile = conversation.get('profile') || {};

Loading…
Cancel
Save