Finalisation; working FRs from secondary;

pull/1138/head
Vincent 5 years ago
parent 19cf4fa54b
commit 34ecc5a751

@ -1045,6 +1045,45 @@ 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') || {};

@ -97,7 +97,7 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
if (conversationList !== undefined) { if (conversationList !== undefined) {
conversationList = conversationList.filter( conversationList = conversationList.filter(
conversation => conversation =>
!conversation.isPendingFriendRequest !conversation.isPendingFriendRequest && !conversation.isSecondary
); );
} }

@ -129,7 +129,11 @@ export const _getLeftPaneLists = (
} }
if (conversation.hasReceivedFriendRequest) { if (conversation.hasReceivedFriendRequest) {
allReceivedFriendsRequest.push(conversation); // Friend requests should always appear as coming from primary
const primaryConversation = conversations.find(c => c.id === conversation.primaryDevice) || conversation;
primaryConversation.hasReceivedFriendRequest = conversation.hasReceivedFriendRequest;
primaryConversation.isPendingFriendRequest = conversation.isPendingFriendRequest;
allReceivedFriendsRequest.push(primaryConversation);
} else if ( } else if (
unreadCount < 9 && unreadCount < 9 &&
conversation.isFriend && conversation.isFriend &&
@ -160,28 +164,28 @@ export const _getLeftPaneLists = (
group: Array<ConversationType | ConversationListItemPropsType> group: Array<ConversationType | ConversationListItemPropsType>
): T => { ): T => {
const secondariesToRemove: Array<string> = []; const secondariesToRemove: Array<string> = [];
group.forEach(device => { group.forEach(device => {
if (!device.isSecondary) { if (!device.isSecondary) {
return; return;
} }
const devicePrimary = group.find(c => c.id === device.primaryDevice); const devicePrimary = group.find(c => c.id === device.primaryDevice);
// Remove secondary where primary already exists in group // Remove secondary where primary already exists in group
if (group.some(c => c === devicePrimary)) { if (group.some(c => c === devicePrimary)) {
secondariesToRemove.push(device.id); secondariesToRemove.push(device.id);
} }
}); });
// tslint:disable-next-line: no-unnecessary-local-variable const filteredGroup = [...new Set(group.filter(
const filteredGroup = group.filter(
c => !secondariesToRemove.find(s => s === c.id) c => !secondariesToRemove.find(s => s === c.id)
); ))];
return filteredGroup as T; return filteredGroup as T;
}; };
const friends: Array<ConversationType> = filterToPrimary(allFriends); const friends: Array<ConversationType> = filterToPrimary(allFriends);
const receivedFriendsRequest: Array< const receivedFriendsRequest: Array<
ConversationListItemPropsType ConversationListItemPropsType
@ -200,7 +204,6 @@ export const _getLeftPaneLists = (
return { return {
conversations, conversations,
archivedConversations, archivedConversations,

Loading…
Cancel
Save