From 2b7df8e40bf96a5d69f30b87ac8612fd6c8fc5bb Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 12 May 2020 09:29:10 +1000 Subject: [PATCH] Filtering groups fromstate --- js/models/conversations.js | 1 + package.json | 3 +- .../session/LeftPaneContactSection.tsx | 13 ++++--- .../session/LeftPaneMessageSection.tsx | 4 +++ ts/state/ducks/conversations.ts | 1 + ts/state/selectors/conversations.ts | 36 +++++++++++++++++-- ts/test/state/selectors/conversations_test.ts | 5 +++ 7 files changed, 54 insertions(+), 9 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 48c6781df..a4410b279 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -595,6 +595,7 @@ isRss: this.isRss(), isClosable: this.isClosable(), isTyping: typingKeys.length > 0, + lastUpdated: this.get('timestamp'), name: this.getName(), profileName: this.getProfileName(), diff --git a/package.json b/package.json index 3472e45d7..2237adb42 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,12 @@ "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-multi2": "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", "icon-gen": "electron-icon-maker --input=images/icon_1024.png --output=./build", - "generate": "yarn icon-gen && yarn grunt", + "generate": "yarn icon-gen && yarn grunt", "build-release": "cross-env SIGNAL_ENV=production npm run build -- --config.directories.output=release", "build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "clean-module-protobuf": "rm -f ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 6a8cce476..d29cd38cb 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -247,6 +247,8 @@ export class LeftPaneContactSection extends React.Component { const hasReceivedFriendRequest = this.props.receivedFriendsRequest.length > 0; + console.log('[vince] this.props:', this.props); + return (
{this.renderList()} @@ -322,14 +324,15 @@ export class LeftPaneContactSection extends React.Component { private renderList() { const { sentFriendsRequest } = this.props; - const visibleFriendRequests = sentFriendsRequest.filter( - device => !device.isSecondary - ); + console.log('[vince] this.props.friends:', this.props.friends); + console.log('[vince] sentFriendsRequest:', sentFriendsRequest); const friends = window.getFriendsFromContacts(this.props.friends); const length = - Number(visibleFriendRequests.length) + Number(friends.length); - const combined = [...visibleFriendRequests, ...friends]; + Number(sentFriendsRequest.length) + Number(friends.length); + + // prevent where friends and send FR showing two entries + const combined = [...new Set ([...sentFriendsRequest, ...friends])]; const list = (
diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index e29b942b1..3a55767b0 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -203,6 +203,10 @@ export class LeftPaneMessageSection extends React.Component { } public render(): JSX.Element { + const conversations = this.getCurrentConversations(); + console.log('[vince] conversations:', conversations); + + return (
{this.renderHeader()} diff --git a/ts/state/ducks/conversations.ts b/ts/state/ducks/conversations.ts index 06ff8f458..e7ea0e406 100644 --- a/ts/state/ducks/conversations.ts +++ b/ts/state/ducks/conversations.ts @@ -53,6 +53,7 @@ export type ConversationType = { isSelected: boolean; isTyping: boolean; isFriend?: boolean; + isSecondary?: boolean; hasReceivedFriendRequest?: boolean; hasSentFriendRequest?: boolean; }; diff --git a/ts/state/selectors/conversations.ts b/ts/state/selectors/conversations.ts index 90e175192..eb9d8289c 100644 --- a/ts/state/selectors/conversations.ts +++ b/ts/state/selectors/conversations.ts @@ -9,6 +9,10 @@ import { ConversationType, } from '../ducks/conversations'; +import { + getPrimaryDeviceFor +} from '../../../js/modules/data'; + import { getIntl, getRegionCode, getUserNumber } from './user'; import { PropsData as ConversationListItemPropsType } from '../../components/ConversationListItem'; @@ -102,6 +106,8 @@ export const _getLeftPaneLists = ( sentFriendsRequest: Array; unreadCount: number; } => { + const _ = window.Lodash; + const values = Object.values(lookup); const sorted = values.sort(comparator); @@ -114,6 +120,30 @@ export const _getLeftPaneLists = ( const max = sorted.length; let unreadCount = 0; + // Map pubkeys to their primary pubkey so you don't need to call getPrimaryDeviceFor + // every time. + + const filterToPrimary = async (conversation: ConversationType, filerGroup: Array) => { + // Used to ensure that only the primary device gets added to LeftPane filtered groups + // Get one result per user. Dont just ignore secondaries, in case + // a user hasn't synced with primary but FR or contact is duplicated. + + const primaryPubkey = conversation.isSecondary + ? await getPrimaryDeviceFor(conversation.id) + : conversation.id; + + const primaryConversation = conversation.isSecondary + ? conversations.find(c => c.id === primaryPubkey) + : conversation; + + if (!_.includes(filerGroup, primaryConversation)) { + // Push secondary to array only if private pubkey not found + filerGroup.push(primaryConversation || conversation); + } + + return primaryConversation; + }; + for (let i = 0; i < max; i += 1) { let conversation = sorted[i]; @@ -125,11 +155,11 @@ export const _getLeftPaneLists = ( } if (conversation.isFriend && conversation.activeAt !== undefined) { - friends.push(conversation); + void filterToPrimary(conversation, friends); } if (conversation.hasReceivedFriendRequest) { - receivedFriendsRequest.push(conversation); + void filterToPrimary(conversation, receivedFriendsRequest); } else if ( unreadCount < 9 && conversation.isFriend && @@ -138,7 +168,7 @@ export const _getLeftPaneLists = ( unreadCount += conversation.unreadCount; } if (conversation.hasSentFriendRequest) { - sentFriendsRequest.push(conversation); + void filterToPrimary(conversation, sentFriendsRequest); } if (!conversation.activeAt) { diff --git a/ts/test/state/selectors/conversations_test.ts b/ts/test/state/selectors/conversations_test.ts index 63b6cd9e9..ce3681a7e 100644 --- a/ts/test/state/selectors/conversations_test.ts +++ b/ts/test/state/selectors/conversations_test.ts @@ -19,6 +19,7 @@ describe('state/selectors/conversations', () => { timestamp: 0, phoneNumber: 'notused', isArchived: false, + isSecondary: false, type: 'direct', isMe: false, @@ -35,6 +36,7 @@ describe('state/selectors/conversations', () => { timestamp: 20, phoneNumber: 'notused', isArchived: false, + isSecondary: false, type: 'direct', isMe: false, @@ -51,6 +53,7 @@ describe('state/selectors/conversations', () => { timestamp: 20, phoneNumber: 'notused', isArchived: false, + isSecondary: false, type: 'direct', isMe: false, @@ -67,6 +70,7 @@ describe('state/selectors/conversations', () => { timestamp: 20, phoneNumber: 'notused', isArchived: false, + isSecondary: false, type: 'direct', isMe: false, @@ -83,6 +87,7 @@ describe('state/selectors/conversations', () => { timestamp: 30, phoneNumber: 'notused', isArchived: false, + isSecondary: false, type: 'direct', isMe: false,