From 34fde5f71a3f251e3dfce1ba7d51ea8fd032976c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Fri, 3 Jan 2020 11:12:43 +1100 Subject: [PATCH] contact list, show receivedfriendrequest, then sent, then friends --- js/models/conversations.js | 5 +- ts/components/ConversationListItem.tsx | 26 +++++----- ts/components/session/ActionsPanel.tsx | 8 +-- .../session/LeftPaneContactSection.tsx | 50 +++++++++---------- .../session/LeftPaneMessageSection.tsx | 2 +- 5 files changed, 44 insertions(+), 47 deletions(-) diff --git a/js/models/conversations.js b/js/models/conversations.js index 3b733709d..0e1b9c9d6 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -565,10 +565,11 @@ title: this.getTitle(), unreadCount: this.get('unreadCount') || 0, mentionedUs: this.get('mentionedUs') || false, - showFriendRequestIndicator: this.isPendingFriendRequest(), + isPendingFriendRequest: this.isPendingFriendRequest(), + hasReceivedFriendRequest: this.hasReceivedFriendRequest(), + hasSentFriendRequest: this.hasSentFriendRequest(), isBlocked: this.isBlocked(), isSecondary: !!this.get('secondaryStatus'), - phoneNumber: format(this.id, { ourRegionCode: regionCode, }), diff --git a/ts/components/ConversationListItem.tsx b/ts/components/ConversationListItem.tsx index 12e4fc3f3..0985545c9 100644 --- a/ts/components/ConversationListItem.tsx +++ b/ts/components/ConversationListItem.tsx @@ -37,7 +37,9 @@ export type PropsData = { isRss: boolean; }; - showFriendRequestIndicator?: boolean; + isPendingFriendRequest?: boolean; + hasReceivedFriendRequest?: boolean; + hasSentFriendRequest?: boolean; isBlocked?: boolean; isOnline?: boolean; hasNickname?: boolean; @@ -75,15 +77,15 @@ export class ConversationListItem extends React.PureComponent { phoneNumber, profileName, isOnline, - showFriendRequestIndicator, + isPendingFriendRequest, } = this.props; let borderColor = undefined; - if (!showFriendRequestIndicator) { + if (!isPendingFriendRequest) { borderColor = isOnline ? Colors.ONLINE : Colors.OFFLINE; } - const iconSize = showFriendRequestIndicator ? 28 : 48; + const iconSize = isPendingFriendRequest ? 28 : 48; return (
@@ -123,7 +125,7 @@ export class ConversationListItem extends React.PureComponent { } public renderHeader() { - const { unreadCount, i18n, isMe, lastUpdated, isFriendItem, showFriendRequestIndicator } = this.props; + const { unreadCount, i18n, isMe, lastUpdated, isFriendItem, hasReceivedFriendRequest } = this.props; return (
@@ -137,7 +139,7 @@ export class ConversationListItem extends React.PureComponent { > {isMe ? i18n('noteToSelf') : this.renderUser()}
- {showFriendRequestIndicator || this.renderUnread()} + {hasReceivedFriendRequest || this.renderUnread()} {!isFriendItem && (
{ : null )} > - {showFriendRequestIndicator || ( { unreadCount, i18n, isFriendItem, - showFriendRequestIndicator, + isPendingFriendRequest, } = this.props; if (isFriendItem) { @@ -237,7 +239,7 @@ export class ConversationListItem extends React.PureComponent { text = text.replace(/<[^>]*>?/gm, ''); } - if (showFriendRequestIndicator) { + if (isPendingFriendRequest) { text = text.replace('Friend Request: ', ''); } @@ -298,7 +300,7 @@ export class ConversationListItem extends React.PureComponent { onClick, id, isSelected, - showFriendRequestIndicator, + hasReceivedFriendRequest, isBlocked, style, mentionedUs, @@ -327,7 +329,7 @@ export class ConversationListItem extends React.PureComponent { ? 'module-conversation-list-item--mentioned-us' : null, isSelected ? 'module-conversation-list-item--is-selected' : null, - showFriendRequestIndicator + hasReceivedFriendRequest ? 'module-conversation-list-item--has-friend-request' : null, isBlocked ? 'module-conversation-list-item--is-blocked' : null @@ -338,7 +340,7 @@ export class ConversationListItem extends React.PureComponent { {this.renderHeader()} {this.renderMessage()}
- {showFriendRequestIndicator && this.renderFriendRequestButtons()} + {hasReceivedFriendRequest && this.renderFriendRequestButtons()}
{this.renderContextMenu(triggerId)} diff --git a/ts/components/session/ActionsPanel.tsx b/ts/components/session/ActionsPanel.tsx index 226da5a77..57753a0b2 100644 --- a/ts/components/session/ActionsPanel.tsx +++ b/ts/components/session/ActionsPanel.tsx @@ -184,7 +184,7 @@ export class ActionsPanel extends React.Component { let unreadCount = 0; if (conversations !== undefined) { conversations.some(function (conversation) { - if (conversation.showFriendRequestIndicator) { + if (conversation.isPendingFriendRequest) { return false; } unreadCount += conversation.unreadCount; @@ -204,11 +204,7 @@ export class ActionsPanel extends React.Component { // We assume a friend request already read is still a friend valid request conversations.some(function (conversation) { // Ignore friend request with lastmessage status as sent as this is a friend request we made ourself - const isValidFriendRequest = conversation.showFriendRequestIndicator - && conversation.lastMessage - && conversation.lastMessage.status !== 'sent' - && conversation.lastMessage.status !== 'sending'; - friendRequestCount += isValidFriendRequest ? 1 : 0; + friendRequestCount += conversation.hasReceivedFriendRequest ? 1 : 0; if (friendRequestCount > 9) { return true; } diff --git a/ts/components/session/LeftPaneContactSection.tsx b/ts/components/session/LeftPaneContactSection.tsx index 88475d6f9..de0e72f71 100644 --- a/ts/components/session/LeftPaneContactSection.tsx +++ b/ts/components/session/LeftPaneContactSection.tsx @@ -167,7 +167,6 @@ export class LeftPaneContactSection extends React.Component { const { friends } = this.props; let friendList = friends; - console.log('friends:', friendList); if (friendList !== undefined) { friendList = friendList.filter( friend => @@ -178,35 +177,33 @@ export class LeftPaneContactSection extends React.Component { return friendList; } - - public getFriendRequests(): Array { + // true: received only, false: sent only + private getFriendRequests(received:boolean): Array { const { conversations } = this.props; let conversationsList = conversations; - console.log('conversations:', conversationsList); if (conversationsList !== undefined) { - // ignore friend request we made ourself - conversationsList = conversationsList.filter( - conversation => conversation.showFriendRequestIndicator && conversation.lastMessage && conversation.lastMessage.status !== 'sent' && conversation.lastMessage.status !== 'sending' - ); + if (received) { + conversationsList = conversationsList.filter( + conversation => (conversation.hasReceivedFriendRequest)); + } else { + conversationsList = conversationsList.filter( + conversation => (conversation.hasSentFriendRequest)); + } } return conversationsList; } private renderList() { + const receivedFriendsRequest = this.getFriendRequests(true); + const sentFriendsRequest = this.getFriendRequests(false); const friends = this.getCurrentFriends(); - const friendsRequest = this.getFriendRequests(); - if (!friends) { - throw new Error( - '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 - // on startup and scroll. + const combined = [...receivedFriendsRequest, ...sentFriendsRequest, ...friends]; + + const length = combined.length; + const list = (
@@ -234,23 +231,24 @@ export class LeftPaneContactSection extends React.Component { style, }: RowRendererParamsType): JSX.Element | undefined => { + const receivedFriendsRequest = this.getFriendRequests(true); + const sentFriendsRequest = this.getFriendRequests(false); const friends = this.getCurrentFriends(); - const friendRequest = this.getFriendRequests(); - let item; - if(index= receivedFriendsRequest.length) { + onClick = this.props.openConversationInternal; + } return ( ); }; diff --git a/ts/components/session/LeftPaneMessageSection.tsx b/ts/components/session/LeftPaneMessageSection.tsx index 7308af30c..f91c6c6e8 100644 --- a/ts/components/session/LeftPaneMessageSection.tsx +++ b/ts/components/session/LeftPaneMessageSection.tsx @@ -61,7 +61,7 @@ export class LeftPaneMessageSection extends React.Component { if (conversationList !== undefined) { conversationList = conversationList.filter( conversation => !conversation.isSecondary - && !conversation.showFriendRequestIndicator + && !conversation.isPendingFriendRequest ); }