diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index b6aae9df7..88636d647 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -25,6 +25,7 @@ export type PropsData = { isPublic?: boolean; isRss?: boolean; isClosable?: boolean; + primaryDevice?: string; lastUpdated: number; unreadCount: number; diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 9221e9415..75f5423f1 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -325,8 +325,7 @@ export class LeftPaneContactSection extends React.Component { const friends = window.getFriendsFromContacts(this.props.friends); const length = Number(sentFriendsRequest.length) + Number(friends.length); - // Prevent where friends and send FR showing two entries - const combined = [...new Set([...sentFriendsRequest, ...friends])]; + const combined = [...sentFriendsRequest, ...friends]; const list = (
diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index f11d53982..4cc66343d 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -138,7 +138,9 @@ export const _getLeftPaneLists = ( unreadCount += conversation.unreadCount; } if (conversation.hasSentFriendRequest) { - allSentFriendsRequest.push(conversation); + if (!conversation.isFriend) { + allSentFriendsRequest.push(conversation); + } } if (!conversation.activeAt) { @@ -152,31 +154,39 @@ export const _getLeftPaneLists = ( } } - const filterToPrimary = ( + const filterToPrimary = < + T extends Array + >( group: Array - ) => { - // Used to ensure that only the primary device gets added to LeftPane filtered groups + ): T => { + const secondariesToRemove: Array = []; + group.forEach(device => { + if (!device.isSecondary) { + return; + } + + const devicePrimary = group.find(c => c.id === device.primaryDevice); + // Remove secondary where primary already exists in group + if (group.some(c => c === devicePrimary)) { + secondariesToRemove.push(device.id); + } + }); - 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 - ) - ) + const filteredGroup = group.filter( + c => !secondariesToRemove.find(s => s === c.id) ); - return filteredGroup; + return filteredGroup as T; }; - const friends = filterToPrimary(allFriends); - const receivedFriendsRequest = filterToPrimary(allReceivedFriendsRequest); - const sentFriendsRequest = filterToPrimary(allSentFriendsRequest); + const friends: Array = filterToPrimary(allFriends); + const receivedFriendsRequest: Array< + ConversationListItemPropsType + > = filterToPrimary(allReceivedFriendsRequest); + const sentFriendsRequest: Array< + ConversationListItemPropsType + > = filterToPrimary(allSentFriendsRequest); return { conversations,