From 2b0ea5bcc58d68e905e8727a7d0c27b6e4b9fbef Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 14 May 2020 15:13:06 +1000 Subject: [PATCH 1/4] simplificaiton --- package.json | 1 + ts/components/ConversationListItem.tsx | 1 + .../session/LeftPaneContactSection.tsx | 2 +- ts/state/selectors/conversations.ts | 59 ++++++++++++------- 4 files changed, 41 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 3472e45d7..5b14250d6 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "start-multi2": "cross-env NODE_APP_INSTANCE=2 electron .", "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod electron .", "start-prod-multi": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod1 electron .", + "start-prod-multi1": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod2 electron .", "start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=1 electron .", "start-swarm-test-2": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=2 electron .", "grunt": "grunt", 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..8e720488d 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -326,7 +326,7 @@ export class LeftPaneContactSection extends React.Component { 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..cda522aed 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -102,6 +102,7 @@ export const _getLeftPaneLists = ( sentFriendsRequest: Array; unreadCount: number; } => { + const _ = window.Lodash; const values = Object.values(lookup); const sorted = values.sort(comparator); @@ -138,7 +139,9 @@ export const _getLeftPaneLists = ( unreadCount += conversation.unreadCount; } if (conversation.hasSentFriendRequest) { - allSentFriendsRequest.push(conversation); + if (!conversation.isFriend) { + allSentFriendsRequest.push(conversation); + } } if (!conversation.activeAt) { @@ -152,31 +155,45 @@ export const _getLeftPaneLists = ( } } - const filterToPrimary = ( + const filterToPrimary = >( 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 (_.includes(group, 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 - ) - ) - ); - - return filteredGroup; + const filteredGroup = group.filter(c => !(secondariesToRemove.find(s => s === c.id))); + + return (filteredGroup as T); }; - const friends = filterToPrimary(allFriends); - const receivedFriendsRequest = filterToPrimary(allReceivedFriendsRequest); - const sentFriendsRequest = filterToPrimary(allSentFriendsRequest); + const friends: Array = + filterToPrimary(allFriends); + const receivedFriendsRequest: Array = + filterToPrimary(allReceivedFriendsRequest); + const sentFriendsRequest: Array = + filterToPrimary(allSentFriendsRequest); + + console.log('[vince] allFriends:', allFriends); + console.log('[vince] friends:', friends); + + console.log('[vince] allReceivedFriendsRequest:', allReceivedFriendsRequest); + console.log('[vince] receivedFriendsRequest:', receivedFriendsRequest); + + console.log('[vince] allSentFriendsRequest:', allSentFriendsRequest); + console.log('[vince] sentFriendsRequest:', sentFriendsRequest); + + console.log('[vince] conversations:', conversations); return { conversations, From 08e223e96e9716f49a7a04b326e5812128671d4d Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 14 May 2020 15:36:07 +1000 Subject: [PATCH 2/4] final w comments --- ts/state/selectors/conversations.ts | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index cda522aed..4878b5464 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -155,9 +155,11 @@ export const _getLeftPaneLists = ( } } - const filterToPrimary = >( + const filterToPrimary = < + T extends Array + >( group: Array - ) : T => { + ): T => { const secondariesToRemove: Array = []; group.forEach(device => { if (!device.isSecondary) { @@ -172,17 +174,20 @@ export const _getLeftPaneLists = ( }); // tslint:disable-next-line: no-unnecessary-local-variable - const filteredGroup = group.filter(c => !(secondariesToRemove.find(s => s === c.id))); + const filteredGroup = group.filter( + c => !secondariesToRemove.find(s => s === c.id) + ); - return (filteredGroup as T); + return filteredGroup as T; }; - const friends: Array = - filterToPrimary(allFriends); - const receivedFriendsRequest: Array = - filterToPrimary(allReceivedFriendsRequest); - const sentFriendsRequest: Array = - filterToPrimary(allSentFriendsRequest); + const friends: Array = filterToPrimary(allFriends); + const receivedFriendsRequest: Array< + ConversationListItemPropsType + > = filterToPrimary(allReceivedFriendsRequest); + const sentFriendsRequest: Array< + ConversationListItemPropsType + > = filterToPrimary(allSentFriendsRequest); console.log('[vince] allFriends:', allFriends); console.log('[vince] friends:', friends); From ca910be1ef501179d29faae0dd10d5cc3226a84e Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 14 May 2020 15:36:26 +1000 Subject: [PATCH 3/4] removed comments --- package.json | 1 - ts/components/session/LeftPaneContactSection.tsx | 1 - ts/state/selectors/conversations.ts | 11 ----------- 3 files changed, 13 deletions(-) diff --git a/package.json b/package.json index 5b14250d6..3472e45d7 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "start-multi2": "cross-env NODE_APP_INSTANCE=2 electron .", "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod electron .", "start-prod-multi": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod1 electron .", - "start-prod-multi1": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod2 electron .", "start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=1 electron .", "start-swarm-test-2": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=2 electron .", "grunt": "grunt", diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 8e720488d..75f5423f1 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -325,7 +325,6 @@ 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 = [...sentFriendsRequest, ...friends]; const list = ( diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 4878b5464..5b85ed009 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -189,17 +189,6 @@ export const _getLeftPaneLists = ( ConversationListItemPropsType > = filterToPrimary(allSentFriendsRequest); - console.log('[vince] allFriends:', allFriends); - console.log('[vince] friends:', friends); - - console.log('[vince] allReceivedFriendsRequest:', allReceivedFriendsRequest); - console.log('[vince] receivedFriendsRequest:', receivedFriendsRequest); - - console.log('[vince] allSentFriendsRequest:', allSentFriendsRequest); - console.log('[vince] sentFriendsRequest:', sentFriendsRequest); - - console.log('[vince] conversations:', conversations); - return { conversations, archivedConversations, From a668be33d7a2c9d5b1158030f6035f3631c55cac Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 14 May 2020 15:58:44 +1000 Subject: [PATCH 4/4] remove lodash --- ts/state/selectors/conversations.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 5b85ed009..4cc66343d 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -102,7 +102,6 @@ export const _getLeftPaneLists = ( sentFriendsRequest: Array; unreadCount: number; } => { - const _ = window.Lodash; const values = Object.values(lookup); const sorted = values.sort(comparator); @@ -168,7 +167,7 @@ export const _getLeftPaneLists = ( const devicePrimary = group.find(c => c.id === device.primaryDevice); // Remove secondary where primary already exists in group - if (_.includes(group, devicePrimary)) { + if (group.some(c => c === devicePrimary)) { secondariesToRemove.push(device.id); } });