diff --git a/js/background.js b/js/background.js index e9f43c901..0b811f59d 100644 --- a/js/background.js +++ b/js/background.js @@ -1365,6 +1365,11 @@ }); Whisper.events.on('deviceUnpairingRequested', async (pubKey, callback) => { + const isSecondaryDevice = !!textsecure.storage.get('isSecondaryDevice'); + if (isSecondaryDevice) { + return; + } + await libloki.storage.removePairingAuthorisationForSecondaryPubKey( pubKey ); diff --git a/js/models/conversations.js b/js/models/conversations.js index 48c6781df..822600f19 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -607,6 +607,7 @@ hasSentFriendRequest: this.hasSentFriendRequest(), isBlocked: this.isBlocked(), isSecondary: !!this.get('secondaryStatus'), + primaryDevice: this.getPrimaryDevicePubKey(), phoneNumber: format(this.id, { ourRegionCode: regionCode, }), diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index dd2ae21df..9221e9415 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -321,9 +321,12 @@ export class LeftPaneContactSection extends React.Component { private renderList() { const { sentFriendsRequest } = this.props; + const friends = window.getFriendsFromContacts(this.props.friends); const length = Number(sentFriendsRequest.length) + Number(friends.length); - const combined = [...sentFriendsRequest, ...friends]; + + // Prevent where friends and send FR showing two entries + const combined = [...new Set([...sentFriendsRequest, ...friends])]; const list = (
diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 06ff8f458..219c66377 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -53,6 +53,8 @@ export type ConversationType = { isSelected: boolean; isTyping: boolean; isFriend?: boolean; + isSecondary?: boolean; + primaryDevice: string; hasReceivedFriendRequest?: boolean; hasSentFriendRequest?: boolean; }; diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 90e175192..f11d53982 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -107,9 +107,9 @@ export const _getLeftPaneLists = ( const conversations: Array = []; const archivedConversations: Array = []; - const friends: Array = []; - const receivedFriendsRequest: Array = []; - const sentFriendsRequest: Array = []; + const allFriends: Array = []; + const allReceivedFriendsRequest: Array = []; + const allSentFriendsRequest: Array = []; const max = sorted.length; let unreadCount = 0; @@ -125,11 +125,11 @@ export const _getLeftPaneLists = ( } if (conversation.isFriend && conversation.activeAt !== undefined) { - friends.push(conversation); + allFriends.push(conversation); } if (conversation.hasReceivedFriendRequest) { - receivedFriendsRequest.push(conversation); + allReceivedFriendsRequest.push(conversation); } else if ( unreadCount < 9 && conversation.isFriend && @@ -138,7 +138,7 @@ export const _getLeftPaneLists = ( unreadCount += conversation.unreadCount; } if (conversation.hasSentFriendRequest) { - sentFriendsRequest.push(conversation); + allSentFriendsRequest.push(conversation); } if (!conversation.activeAt) { @@ -152,6 +152,32 @@ export const _getLeftPaneLists = ( } } + const filterToPrimary = ( + group: Array + ) => { + // Used to ensure that only the primary device gets added to LeftPane filtered groups + + const constructedGroup = conversations.filter(c => + group.some(g => c.id === g.id) + ); + // tslint:disable-next-line: no-unnecessary-local-variable + const filteredGroup = constructedGroup.filter( + (c, idx) => + !( + c.isSecondary && + constructedGroup.some( + g => !g.isSecondary && g.id === constructedGroup[idx].primaryDevice + ) + ) + ); + + return filteredGroup; + }; + + const friends = filterToPrimary(allFriends); + const receivedFriendsRequest = filterToPrimary(allReceivedFriendsRequest); + const sentFriendsRequest = filterToPrimary(allSentFriendsRequest); + return { conversations, archivedConversations, diff --git a/ts/test/state/selectors/conversations_test.ts b/ts/test/state/selectors/conversations_test.ts index 63b6cd9e9..6bc3f65ec 100644 --- a/ts/test/state/selectors/conversations_test.ts +++ b/ts/test/state/selectors/conversations_test.ts @@ -19,6 +19,8 @@ describe('state/selectors/conversations', () => { timestamp: 0, phoneNumber: 'notused', isArchived: false, + isSecondary: false, + primaryDevice: 'id1', type: 'direct', isMe: false, @@ -35,6 +37,8 @@ describe('state/selectors/conversations', () => { timestamp: 20, phoneNumber: 'notused', isArchived: false, + isSecondary: false, + primaryDevice: 'id2', type: 'direct', isMe: false, @@ -51,6 +55,8 @@ describe('state/selectors/conversations', () => { timestamp: 20, phoneNumber: 'notused', isArchived: false, + isSecondary: false, + primaryDevice: 'id3', type: 'direct', isMe: false, @@ -67,6 +73,8 @@ describe('state/selectors/conversations', () => { timestamp: 20, phoneNumber: 'notused', isArchived: false, + isSecondary: false, + primaryDevice: 'id4', type: 'direct', isMe: false, @@ -83,6 +91,8 @@ describe('state/selectors/conversations', () => { timestamp: 30, phoneNumber: 'notused', isArchived: false, + isSecondary: false, + primaryDevice: 'id5', type: 'direct', isMe: false,