contact list, show receivedfriendrequest, then sent, then friends

pull/712/head
Audric Ackermann 5 years ago
parent cf7747b92d
commit 34fde5f71a

@ -565,10 +565,11 @@
title: this.getTitle(), title: this.getTitle(),
unreadCount: this.get('unreadCount') || 0, unreadCount: this.get('unreadCount') || 0,
mentionedUs: this.get('mentionedUs') || false, mentionedUs: this.get('mentionedUs') || false,
showFriendRequestIndicator: this.isPendingFriendRequest(), isPendingFriendRequest: this.isPendingFriendRequest(),
hasReceivedFriendRequest: this.hasReceivedFriendRequest(),
hasSentFriendRequest: this.hasSentFriendRequest(),
isBlocked: this.isBlocked(), isBlocked: this.isBlocked(),
isSecondary: !!this.get('secondaryStatus'), isSecondary: !!this.get('secondaryStatus'),
phoneNumber: format(this.id, { phoneNumber: format(this.id, {
ourRegionCode: regionCode, ourRegionCode: regionCode,
}), }),

@ -37,7 +37,9 @@ export type PropsData = {
isRss: boolean; isRss: boolean;
}; };
showFriendRequestIndicator?: boolean; isPendingFriendRequest?: boolean;
hasReceivedFriendRequest?: boolean;
hasSentFriendRequest?: boolean;
isBlocked?: boolean; isBlocked?: boolean;
isOnline?: boolean; isOnline?: boolean;
hasNickname?: boolean; hasNickname?: boolean;
@ -75,15 +77,15 @@ export class ConversationListItem extends React.PureComponent<Props> {
phoneNumber, phoneNumber,
profileName, profileName,
isOnline, isOnline,
showFriendRequestIndicator, isPendingFriendRequest,
} = this.props; } = this.props;
let borderColor = undefined; let borderColor = undefined;
if (!showFriendRequestIndicator) { if (!isPendingFriendRequest) {
borderColor = isOnline ? Colors.ONLINE : Colors.OFFLINE; borderColor = isOnline ? Colors.ONLINE : Colors.OFFLINE;
} }
const iconSize = showFriendRequestIndicator ? 28 : 48; const iconSize = isPendingFriendRequest ? 28 : 48;
return ( return (
<div className="module-conversation-list-item__avatar-container"> <div className="module-conversation-list-item__avatar-container">
@ -123,7 +125,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
} }
public renderHeader() { public renderHeader() {
const { unreadCount, i18n, isMe, lastUpdated, isFriendItem, showFriendRequestIndicator } = this.props; const { unreadCount, i18n, isMe, lastUpdated, isFriendItem, hasReceivedFriendRequest } = this.props;
return ( return (
<div className="module-conversation-list-item__header"> <div className="module-conversation-list-item__header">
@ -137,7 +139,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
> >
{isMe ? i18n('noteToSelf') : this.renderUser()} {isMe ? i18n('noteToSelf') : this.renderUser()}
</div> </div>
{showFriendRequestIndicator || this.renderUnread()} {hasReceivedFriendRequest || this.renderUnread()}
{!isFriendItem && ( {!isFriendItem && (
<div <div
className={classNames( className={classNames(
@ -147,7 +149,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
: null : null
)} )}
> >
{showFriendRequestIndicator || (<Timestamp {!hasReceivedFriendRequest && (<Timestamp
timestamp={lastUpdated} timestamp={lastUpdated}
extended={false} extended={false}
module="module-conversation-list-item__header__timestamp" module="module-conversation-list-item__header__timestamp"
@ -219,7 +221,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
unreadCount, unreadCount,
i18n, i18n,
isFriendItem, isFriendItem,
showFriendRequestIndicator, isPendingFriendRequest,
} = this.props; } = this.props;
if (isFriendItem) { if (isFriendItem) {
@ -237,7 +239,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
text = text.replace(/<[^>]*>?/gm, ''); text = text.replace(/<[^>]*>?/gm, '');
} }
if (showFriendRequestIndicator) { if (isPendingFriendRequest) {
text = text.replace('Friend Request: ', ''); text = text.replace('Friend Request: ', '');
} }
@ -298,7 +300,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
onClick, onClick,
id, id,
isSelected, isSelected,
showFriendRequestIndicator, hasReceivedFriendRequest,
isBlocked, isBlocked,
style, style,
mentionedUs, mentionedUs,
@ -327,7 +329,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
? 'module-conversation-list-item--mentioned-us' ? 'module-conversation-list-item--mentioned-us'
: null, : null,
isSelected ? 'module-conversation-list-item--is-selected' : null, isSelected ? 'module-conversation-list-item--is-selected' : null,
showFriendRequestIndicator hasReceivedFriendRequest
? 'module-conversation-list-item--has-friend-request' ? 'module-conversation-list-item--has-friend-request'
: null, : null,
isBlocked ? 'module-conversation-list-item--is-blocked' : null isBlocked ? 'module-conversation-list-item--is-blocked' : null
@ -338,7 +340,7 @@ export class ConversationListItem extends React.PureComponent<Props> {
{this.renderHeader()} {this.renderHeader()}
{this.renderMessage()} {this.renderMessage()}
</div> </div>
{showFriendRequestIndicator && this.renderFriendRequestButtons()} {hasReceivedFriendRequest && this.renderFriendRequestButtons()}
</div> </div>
</ContextMenuTrigger> </ContextMenuTrigger>
<Portal>{this.renderContextMenu(triggerId)}</Portal> <Portal>{this.renderContextMenu(triggerId)}</Portal>

@ -184,7 +184,7 @@ 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) { if (conversation.isPendingFriendRequest) {
return false; return false;
} }
unreadCount += conversation.unreadCount; unreadCount += conversation.unreadCount;
@ -204,11 +204,7 @@ export class ActionsPanel extends React.Component<Props, State> {
// We assume a friend request already read is still a friend valid request // We assume a friend request already read is still a friend valid request
conversations.some(function (conversation) { conversations.some(function (conversation) {
// Ignore friend request with lastmessage status as sent as this is a friend request we made ourself // Ignore friend request with lastmessage status as sent as this is a friend request we made ourself
const isValidFriendRequest = conversation.showFriendRequestIndicator friendRequestCount += conversation.hasReceivedFriendRequest ? 1 : 0;
&& conversation.lastMessage
&& conversation.lastMessage.status !== 'sent'
&& conversation.lastMessage.status !== 'sending';
friendRequestCount += isValidFriendRequest ? 1 : 0;
if (friendRequestCount > 9) { if (friendRequestCount > 9) {
return true; return true;
} }

@ -167,7 +167,6 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
const { friends } = this.props; const { friends } = this.props;
let friendList = friends; let friendList = friends;
console.log('friends:', friendList);
if (friendList !== undefined) { if (friendList !== undefined) {
friendList = friendList.filter( friendList = friendList.filter(
friend => friend =>
@ -178,35 +177,33 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
return friendList; return friendList;
} }
// true: received only, false: sent only
public getFriendRequests(): Array<ConversationListItemPropsType> { private getFriendRequests(received:boolean): Array<ConversationListItemPropsType> {
const { conversations } = this.props; const { conversations } = this.props;
let conversationsList = conversations; let conversationsList = conversations;
console.log('conversations:', conversationsList);
if (conversationsList !== undefined) { if (conversationsList !== undefined) {
// ignore friend request we made ourself if (received) {
conversationsList = conversationsList.filter( conversationsList = conversationsList.filter(
conversation => conversation.showFriendRequestIndicator && conversation.lastMessage && conversation.lastMessage.status !== 'sent' && conversation.lastMessage.status !== 'sending' conversation => (conversation.hasReceivedFriendRequest));
); } else {
conversationsList = conversationsList.filter(
conversation => (conversation.hasSentFriendRequest));
}
} }
return conversationsList; return conversationsList;
} }
private renderList() { private renderList() {
const receivedFriendsRequest = this.getFriendRequests(true);
const sentFriendsRequest = this.getFriendRequests(false);
const friends = this.getCurrentFriends(); const friends = this.getCurrentFriends();
const friendsRequest = this.getFriendRequests();
if (!friends) { const combined = [...receivedFriendsRequest, ...sentFriendsRequest, ...friends];
throw new Error(
'render: must provided friends if no search results are provided' const length = combined.length;
);
}
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 list = ( const list = (
<div className="module-left-pane__list" key={0}> <div className="module-left-pane__list" key={0}>
<AutoSizer> <AutoSizer>
@ -234,23 +231,24 @@ export class LeftPaneContactSection extends React.Component<Props, any> {
style, style,
}: RowRendererParamsType): JSX.Element | undefined => { }: RowRendererParamsType): JSX.Element | undefined => {
const receivedFriendsRequest = this.getFriendRequests(true);
const sentFriendsRequest = this.getFriendRequests(false);
const friends = this.getCurrentFriends(); const friends = this.getCurrentFriends();
const friendRequest = this.getFriendRequests();
let item; const combined = [...receivedFriendsRequest, ...sentFriendsRequest, ...friends];
if(index<friendRequest.length) {
item = friendRequest[index];
}
else {
item = friends[index-friendRequest.length];
}
const item = combined[index];
let onClick = undefined;
if (index >= receivedFriendsRequest.length) {
onClick = this.props.openConversationInternal;
}
return ( return (
<ConversationListItem <ConversationListItem
key={key} key={key}
style={style} style={style}
{...item} {...item}
i18n={window.i18n} i18n={window.i18n}
onClick={onClick}
/> />
); );
}; };

@ -61,7 +61,7 @@ export class LeftPaneMessageSection extends React.Component<Props, any> {
if (conversationList !== undefined) { if (conversationList !== undefined) {
conversationList = conversationList.filter( conversationList = conversationList.filter(
conversation => !conversation.isSecondary conversation => !conversation.isSecondary
&& !conversation.showFriendRequestIndicator && !conversation.isPendingFriendRequest
); );
} }

Loading…
Cancel
Save