Filtering groups fromstate

pull/1118/head
Vincent 5 years ago
parent a429771b92
commit 2b7df8e40b

@ -595,6 +595,7 @@
isRss: this.isRss(),
isClosable: this.isClosable(),
isTyping: typingKeys.length > 0,
lastUpdated: this.get('timestamp'),
name: this.getName(),
profileName: this.getProfileName(),

@ -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",

@ -247,6 +247,8 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
const hasReceivedFriendRequest =
this.props.receivedFriendsRequest.length > 0;
console.log('[vince] this.props:', this.props);
return (
<div className="left-pane-contact-content">
{this.renderList()}
@ -322,14 +324,15 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
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 = (
<div className="module-left-pane__list" key={0}>

@ -203,6 +203,10 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
}
public render(): JSX.Element {
const conversations = this.getCurrentConversations();
console.log('[vince] conversations:', conversations);
return (
<div className="session-left-pane-section-content">
{this.renderHeader()}

@ -53,6 +53,7 @@ export type ConversationType = {
isSelected: boolean;
isTyping: boolean;
isFriend?: boolean;
isSecondary?: boolean;
hasReceivedFriendRequest?: boolean;
hasSentFriendRequest?: boolean;
};

@ -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<ConversationListItemPropsType>;
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<ConversationType | ConversationListItemPropsType>) => {
// 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) {

@ -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,

Loading…
Cancel
Save