show current friends and pending friend request in contact lists

pull/712/head
Audric Ackermann 5 years ago
parent a0949d49ea
commit 7ae0c65e87

@ -7,7 +7,6 @@ import { PropsData as ConversationListItemPropsType } from './ConversationListIt
import { PropsData as SearchResultsProps } from './SearchResults'; import { PropsData as SearchResultsProps } from './SearchResults';
import { SearchOptions } from '../types/Search'; import { SearchOptions } from '../types/Search';
import { LeftPaneSectionHeader } from './session/LeftPaneSectionHeader'; import { LeftPaneSectionHeader } from './session/LeftPaneSectionHeader';
import { LeftPaneContactSection } from './session/LeftPaneContactSection';
import { import {
SessionIconButton, SessionIconButton,
SessionIconSize, SessionIconSize,
@ -20,6 +19,8 @@ import {
SessionButtonColor, SessionButtonColor,
SessionButtonType, SessionButtonType,
} from './session/SessionButton'; } 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 // from https://github.com/bvaughn/react-virtualized/blob/fb3484ed5dcc41bffae8eab029126c0fb8f7abc0/source/List/types.js#L5
export type RowRendererParamsType = { export type RowRendererParamsType = {
@ -36,11 +37,12 @@ interface State {
} }
interface Props { interface Props {
conversations?: Array<ConversationListItemPropsType>; conversations: Array<ConversationListItemPropsType>;
friends: Array<ConversationType>;
searchResults?: SearchResultsProps; searchResults?: SearchResultsProps;
searchTerm: string; searchTerm: string;
isSecondaryDevice: boolean; isSecondaryDevice: boolean;
openConversationInternal: (id: string, messageId?: string) => void; openConversationInternal: (id: string, messageId?: string) => void;
updateSearchTerm: (searchTerm: string) => void; updateSearchTerm: (searchTerm: string) => void;
search: (query: string, options: SearchOptions) => void; search: (query: string, options: SearchOptions) => void;
@ -111,9 +113,12 @@ export class LeftPane extends React.Component<Props, State> {
); );
} }
private renderContactSection() { private renderContactSection() {
const { const {
openConversationInternal, openConversationInternal,
friends,
conversations, conversations,
searchResults, searchResults,
searchTerm, searchTerm,
@ -127,6 +132,7 @@ export class LeftPane extends React.Component<Props, State> {
<LeftPaneContactSection <LeftPaneContactSection
openConversationInternal={openConversationInternal} openConversationInternal={openConversationInternal}
conversations={conversations} conversations={conversations}
friends={friends}
searchResults={searchResults} searchResults={searchResults}
searchTerm={searchTerm} searchTerm={searchTerm}
isSecondaryDevice={isSecondaryDevice} isSecondaryDevice={isSecondaryDevice}

@ -184,6 +184,9 @@ export class ActionsPanel extends React.Component<Props, State> {
let unreadCount = 0; let unreadCount = 0;
if (conversations !== undefined) { if (conversations !== undefined) {
conversations.some(function (conversation) { conversations.some(function (conversation) {
if (conversation.showFriendRequestIndicator) {
return false;
}
unreadCount += conversation.unreadCount; unreadCount += conversation.unreadCount;
if (unreadCount > 9) { if (unreadCount > 9) {
return true; return true;

@ -17,12 +17,14 @@ import {
import { AutoSizer, List } from 'react-virtualized'; import { AutoSizer, List } from 'react-virtualized';
import { validateNumber } from '../../types/PhoneNumber'; import { validateNumber } from '../../types/PhoneNumber';
import { ActionsPanel } from './ActionsPanel'; import { ActionsPanel } from './ActionsPanel';
import { ConversationType } from '../../state/ducks/conversations';
export interface Props { export interface Props {
searchTerm: string; searchTerm: string;
isSecondaryDevice: boolean; isSecondaryDevice: boolean;
conversations?: Array<ConversationListItemPropsType>; conversations: Array<ConversationListItemPropsType>;
friends: Array<ConversationType>;
searchResults?: SearchResultsProps; searchResults?: SearchResultsProps;
@ -64,7 +66,7 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
public renderHeader(): JSX.Element | undefined { public renderHeader(): JSX.Element | undefined {
const labels = [window.i18n('contactsHeader'), window.i18n('lists')]; const labels = [window.i18n('contactsHeader'), window.i18n('lists')];
const friendRequestCount = ActionsPanel.getFriendRequestsCount(this.props.conversations); const friendRequestCount = ActionsPanel.getFriendRequestsCount(this.props.conversations);
return LeftPane.renderHeader( return LeftPane.renderHeader(
labels, labels,
this.handleTabSelected, this.handleTabSelected,
@ -160,30 +162,47 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
); );
} }
public getCurrentConversations(): public getCurrentFriends():
| Array<ConversationListItemPropsType> | Array<ConversationType> {
| undefined { 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<ConversationListItemPropsType> {
const { conversations } = this.props; const { conversations } = this.props;
let conversationList = conversations; let conversationsList = conversations;
if (conversationList !== undefined) { console.log('conversations:', conversationsList);
conversationList = conversationList.filter( if (conversationsList !== undefined) {
conversation => conversationsList = conversationsList.filter(
!conversation.isSecondary && conversation.showFriendRequestIndicator conversation => conversation.showFriendRequestIndicator
); );
} }
return conversationList; return conversationsList;
} }
private renderList() { private renderList() {
const conversations = this.getCurrentConversations(); const friends = this.getCurrentFriends();
const friendsRequest = this.getFriendRequests();
if (!conversations) { if (!friends) {
throw new Error( 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 // 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 // it re-renders when our conversation data changes. Otherwise it would just render
@ -195,7 +214,7 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
<List <List
className="module-left-pane__virtual-list" className="module-left-pane__virtual-list"
height={height} height={height}
rowCount={conversations.length} rowCount={length}
rowHeight={64} rowHeight={64}
rowRenderer={this.renderRow} rowRenderer={this.renderRow}
width={width} width={width}
@ -216,19 +235,22 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
}: RowRendererParamsType): JSX.Element | undefined => { }: RowRendererParamsType): JSX.Element | undefined => {
const { openConversationInternal } = this.props; const { openConversationInternal } = this.props;
const conversations = this.getCurrentConversations(); const friends = this.getCurrentFriends();
const friendRequest = this.getFriendRequests();
if (!conversations) { let item;
throw new Error('renderRow: Tried to render without conversations'); if(index<friendRequest.length) {
item = friendRequest[index];
}
else {
item = friends[index-friendRequest.length];
} }
const conversation = conversations[index];
return ( return (
<ConversationListItem <ConversationListItem
key={key} key={key}
style={style} style={style}
{...conversation} {...item}
onClick={openConversationInternal} onClick={openConversationInternal}
i18n={window.i18n} i18n={window.i18n}
/> />

Loading…
Cancel
Save