Add "new conversation" composer for direct messages
This commit is contained in:
parent
84dc166b63
commit
06fb4fd0bc
61 changed files with 5960 additions and 3887 deletions
63
ts/components/leftPane/getConversationInDirection.ts
Normal file
63
ts/components/leftPane/getConversationInDirection.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { find as findFirst, findLast, first, last } from 'lodash';
|
||||
|
||||
import { PropsData as ConversationListItemPropsType } from '../conversationList/ConversationListItem';
|
||||
import { isConversationUnread } from '../../util/isConversationUnread';
|
||||
import { FindDirection, ToFindType } from './LeftPaneHelper';
|
||||
|
||||
/**
|
||||
* This will look up or down in an array of conversations for the next one to select.
|
||||
* Refer to the tests for the intended behavior.
|
||||
*/
|
||||
export const getConversationInDirection = (
|
||||
conversations: ReadonlyArray<ConversationListItemPropsType>,
|
||||
toFind: Readonly<ToFindType>,
|
||||
selectedConversationId: undefined | string
|
||||
): undefined | { conversationId: string } => {
|
||||
// As an optimization, we don't need to search if no conversation is selected.
|
||||
const selectedConversationIndex = selectedConversationId
|
||||
? conversations.findIndex(({ id }) => id === selectedConversationId)
|
||||
: -1;
|
||||
|
||||
let conversation: ConversationListItemPropsType | undefined;
|
||||
|
||||
if (selectedConversationIndex < 0) {
|
||||
if (toFind.unreadOnly) {
|
||||
conversation =
|
||||
toFind.direction === FindDirection.Up
|
||||
? findLast(conversations, isConversationUnread)
|
||||
: findFirst(conversations, isConversationUnread);
|
||||
} else {
|
||||
conversation =
|
||||
toFind.direction === FindDirection.Up
|
||||
? last(conversations)
|
||||
: first(conversations);
|
||||
}
|
||||
} else if (toFind.unreadOnly) {
|
||||
conversation =
|
||||
toFind.direction === FindDirection.Up
|
||||
? findLast(
|
||||
conversations.slice(0, selectedConversationIndex),
|
||||
isConversationUnread
|
||||
)
|
||||
: findFirst(
|
||||
conversations.slice(selectedConversationIndex + 1),
|
||||
isConversationUnread
|
||||
);
|
||||
} else {
|
||||
const newIndex =
|
||||
selectedConversationIndex +
|
||||
(toFind.direction === FindDirection.Up ? -1 : 1);
|
||||
if (newIndex < 0) {
|
||||
conversation = last(conversations);
|
||||
} else if (newIndex >= conversations.length) {
|
||||
conversation = first(conversations);
|
||||
} else {
|
||||
conversation = conversations[newIndex];
|
||||
}
|
||||
}
|
||||
|
||||
return conversation ? { conversationId: conversation.id } : undefined;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue