From f15d616e20723da79a50197e217a0747e6c5595d Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 6 Jul 2021 19:12:39 +0300 Subject: [PATCH] Forward Picker: Show pinned contacts first (#1241) --- src/components/main/ForwardPicker.tsx | 15 ++++++++++++--- src/modules/helpers/chats.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/main/ForwardPicker.tsx b/src/components/main/ForwardPicker.tsx index 47e20b3f7..ea4f13957 100644 --- a/src/components/main/ForwardPicker.tsx +++ b/src/components/main/ForwardPicker.tsx @@ -11,7 +11,7 @@ import { getCanPostInChat, getChatTitle, isChatPrivate, sortChatIds, } from '../../modules/helpers'; import searchWords from '../../util/searchWords'; -import { pick } from '../../util/iteratees'; +import { pick, unique } from '../../util/iteratees'; import useInfiniteScroll from '../../hooks/useInfiniteScroll'; import useLang from '../../hooks/useLang'; import useKeyboardListNavigation from '../../hooks/useKeyboardListNavigation'; @@ -33,6 +33,7 @@ export type OwnProps = { type StateProps = { chatsById: Record; + pinnedIds?: number[]; activeListIds?: number[]; archivedListIds?: number[]; orderedPinnedIds?: number[]; @@ -48,6 +49,7 @@ const MODAL_HIDE_DELAY_MS = 300; const ForwardPicker: FC = ({ chatsById, + pinnedIds, activeListIds, archivedListIds, currentUserId, @@ -91,6 +93,11 @@ const ForwardPicker: FC = ({ ...archivedListIds || [], ]; + let priorityIds = pinnedIds || []; + if (currentUserId) { + priorityIds = unique([currentUserId, ...priorityIds]); + } + return sortChatIds([ ...listIds.filter((id) => { const chat = chatsById[id]; @@ -108,8 +115,8 @@ const ForwardPicker: FC = ({ return searchWords(getChatTitle(lang, chatsById[id], undefined, id === currentUserId), filter); }), - ], chatsById, undefined, currentUserId ? [currentUserId] : undefined, serverTimeOffset); - }, [activeListIds, archivedListIds, chatsById, currentUserId, filter, lang, serverTimeOffset]); + ], chatsById, undefined, priorityIds, serverTimeOffset); + }, [activeListIds, archivedListIds, chatsById, currentUserId, filter, lang, pinnedIds, serverTimeOffset]); const [viewportIds, getMore] = useInfiniteScroll(loadMoreChats, chatIds, Boolean(filter)); @@ -192,12 +199,14 @@ export default memo(withGlobal( chats: { byId: chatsById, listIds, + orderedPinnedIds, }, currentUserId, } = global; return { chatsById, + pinnedIds: orderedPinnedIds.active, activeListIds: listIds.active, archivedListIds: listIds.archived, currentUserId, diff --git a/src/modules/helpers/chats.ts b/src/modules/helpers/chats.ts index c2a8ec993..e7151042e 100644 --- a/src/modules/helpers/chats.ts +++ b/src/modules/helpers/chats.ts @@ -496,7 +496,7 @@ export function sortChatIds( // Assuming that last message date can't be less than now, // this should place prioritized on top of the list. // Then we subtract index of `id` in `priorityIds` to preserve selected order - priority += Date.now() + serverTimeOffset * 1000 + (priorityIds.length - priorityIds.indexOf(id)); + priority += Date.now() + serverTimeOffset * 1000 + (priorityIds.length - priorityIds.indexOf(id)) * 3e8; } return priority;