Merge pull request #1129 from vincentbavitz/fr-fixes

FR Duplication Fixes | Patch for #1118
pull/1130/head
Mikunj Varsani 5 years ago committed by GitHub
commit e9fea782b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,6 +25,7 @@ export type PropsData = {
isPublic?: boolean; isPublic?: boolean;
isRss?: boolean; isRss?: boolean;
isClosable?: boolean; isClosable?: boolean;
primaryDevice?: string;
lastUpdated: number; lastUpdated: number;
unreadCount: number; unreadCount: number;

@ -325,8 +325,7 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
const friends = window.getFriendsFromContacts(this.props.friends); const friends = window.getFriendsFromContacts(this.props.friends);
const length = Number(sentFriendsRequest.length) + Number(friends.length); const length = Number(sentFriendsRequest.length) + Number(friends.length);
// Prevent where friends and send FR showing two entries const combined = [...sentFriendsRequest, ...friends];
const combined = [...new Set([...sentFriendsRequest, ...friends])];
const list = ( const list = (
<div className="module-left-pane__list" key={0}> <div className="module-left-pane__list" key={0}>

@ -138,8 +138,10 @@ export const _getLeftPaneLists = (
unreadCount += conversation.unreadCount; unreadCount += conversation.unreadCount;
} }
if (conversation.hasSentFriendRequest) { if (conversation.hasSentFriendRequest) {
if (!conversation.isFriend) {
allSentFriendsRequest.push(conversation); allSentFriendsRequest.push(conversation);
} }
}
if (!conversation.activeAt) { if (!conversation.activeAt) {
continue; continue;
@ -152,31 +154,39 @@ export const _getLeftPaneLists = (
} }
} }
const filterToPrimary = ( const filterToPrimary = <
T extends Array<ConversationType | ConversationListItemPropsType>
>(
group: Array<ConversationType | ConversationListItemPropsType> group: Array<ConversationType | ConversationListItemPropsType>
) => { ): T => {
// Used to ensure that only the primary device gets added to LeftPane filtered groups const secondariesToRemove: Array<string> = [];
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 // tslint:disable-next-line: no-unnecessary-local-variable
const filteredGroup = constructedGroup.filter( const filteredGroup = group.filter(
(c, idx) => c => !secondariesToRemove.find(s => s === c.id)
!(
c.isSecondary &&
constructedGroup.some(
g => !g.isSecondary && g.id === constructedGroup[idx].primaryDevice
)
)
); );
return filteredGroup; return filteredGroup as T;
}; };
const friends = filterToPrimary(allFriends); const friends: Array<ConversationType> = filterToPrimary(allFriends);
const receivedFriendsRequest = filterToPrimary(allReceivedFriendsRequest); const receivedFriendsRequest: Array<
const sentFriendsRequest = filterToPrimary(allSentFriendsRequest); ConversationListItemPropsType
> = filterToPrimary(allReceivedFriendsRequest);
const sentFriendsRequest: Array<
ConversationListItemPropsType
> = filterToPrimary(allSentFriendsRequest);
return { return {
conversations, conversations,

Loading…
Cancel
Save