From 7ae0c65e873e645f182e9c9b374055488f90174d Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 30 Dec 2019 17:41:13 +1100 Subject: [PATCH] show current friends and pending friend request in contact lists --- ts/components/LeftPane.tsx | 12 +++- ts/components/session/ActionsPanel.tsx | 3 + .../session/LeftPaneContactSection.tsx | 64 +++++++++++++------ 3 files changed, 55 insertions(+), 24 deletions(-) diff --git a/ts/components/LeftPane.tsx b/ts/components/LeftPane.tsx index 3a4c50bbd..775377954 100644 --- a/ts/components/LeftPane.tsx +++ b/ts/components/LeftPane.tsx @@ -7,7 +7,6 @@ import { PropsData as ConversationListItemPropsType } from './ConversationListIt import { PropsData as SearchResultsProps } from './SearchResults'; import { SearchOptions } from '../types/Search'; import { LeftPaneSectionHeader } from './session/LeftPaneSectionHeader'; -import { LeftPaneContactSection } from './session/LeftPaneContactSection'; import { SessionIconButton, SessionIconSize, @@ -20,6 +19,8 @@ import { SessionButtonColor, SessionButtonType, } from './session/SessionButton'; +import { ConversationType } from '../state/ducks/conversations'; +import { LeftPaneContactSection } from './session/LeftPaneContactSection'; // from https://github.com/bvaughn/react-virtualized/blob/fb3484ed5dcc41bffae8eab029126c0fb8f7abc0/source/List/types.js#L5 export type RowRendererParamsType = { @@ -36,11 +37,12 @@ interface State { } interface Props { - conversations?: Array; + conversations: Array; + friends: Array; searchResults?: SearchResultsProps; searchTerm: string; isSecondaryDevice: boolean; - + openConversationInternal: (id: string, messageId?: string) => void; updateSearchTerm: (searchTerm: string) => void; search: (query: string, options: SearchOptions) => void; @@ -111,9 +113,12 @@ export class LeftPane extends React.Component { ); } + + private renderContactSection() { const { openConversationInternal, + friends, conversations, searchResults, searchTerm, @@ -127,6 +132,7 @@ export class LeftPane extends React.Component { { let unreadCount = 0; if (conversations !== undefined) { conversations.some(function (conversation) { + if (conversation.showFriendRequestIndicator) { + return false; + } unreadCount += conversation.unreadCount; if (unreadCount > 9) { return true; diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 4c7abb4d5..bbd9af1e9 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -17,12 +17,14 @@ import { import { AutoSizer, List } from 'react-virtualized'; import { validateNumber } from '../../types/PhoneNumber'; import { ActionsPanel } from './ActionsPanel'; +import { ConversationType } from '../../state/ducks/conversations'; export interface Props { searchTerm: string; isSecondaryDevice: boolean; - conversations?: Array; + conversations: Array; + friends: Array; searchResults?: SearchResultsProps; @@ -64,7 +66,7 @@ export class LeftPaneContactSection extends React.Component { public renderHeader(): JSX.Element | undefined { const labels = [window.i18n('contactsHeader'), window.i18n('lists')]; const friendRequestCount = ActionsPanel.getFriendRequestsCount(this.props.conversations); - + return LeftPane.renderHeader( labels, this.handleTabSelected, @@ -160,30 +162,47 @@ export class LeftPaneContactSection extends React.Component { ); } - public getCurrentConversations(): - | Array - | undefined { + public getCurrentFriends(): + | Array { + const { friends } = this.props; + + let friendList = friends; + console.log('friends:', friendList); + if (friendList !== undefined) { + friendList = friendList.filter( + friend => + friend.type ==='direct' && !friend.isMe + ); + } + + return friendList; + } + + + public getFriendRequests(): Array { const { conversations } = this.props; - let conversationList = conversations; - if (conversationList !== undefined) { - conversationList = conversationList.filter( - conversation => - !conversation.isSecondary && conversation.showFriendRequestIndicator + let conversationsList = conversations; + console.log('conversations:', conversationsList); + if (conversationsList !== undefined) { + conversationsList = conversationsList.filter( + conversation => conversation.showFriendRequestIndicator ); } - return conversationList; + return conversationsList; } private renderList() { - const conversations = this.getCurrentConversations(); + const friends = this.getCurrentFriends(); + const friendsRequest = this.getFriendRequests(); - if (!conversations) { + if (!friends) { throw new Error( - 'render: must provided conversations if no search results are provided' + 'render: must provided friends if no search results are provided' ); } + const length = friends.length + (friendsRequest?friendsRequest.length:0); // Note: conversations is not a known prop for List, but it is required to ensure that // it re-renders when our conversation data changes. Otherwise it would just render @@ -195,7 +214,7 @@ export class LeftPaneContactSection extends React.Component { { }: RowRendererParamsType): JSX.Element | undefined => { const { openConversationInternal } = this.props; - const conversations = this.getCurrentConversations(); + const friends = this.getCurrentFriends(); + const friendRequest = this.getFriendRequests(); - if (!conversations) { - throw new Error('renderRow: Tried to render without conversations'); + let item; + if(index