diff --git a/src/components/common/RecipientPicker.tsx b/src/components/common/RecipientPicker.tsx index 5d41834f4..300e83c5d 100644 --- a/src/components/common/RecipientPicker.tsx +++ b/src/components/common/RecipientPicker.tsx @@ -83,13 +83,16 @@ const RecipientPicker: FC = ({ return chat && getCanPostInChat(chat, MAIN_THREAD_ID, undefined, chatFullInfoById[id]); }); - const sorted = [ - ...(currentUserId ? [currentUserId] : []), - ...sortChatIds(unique([ + const sorted = sortChatIds( + unique([ + ...(currentUserId ? [currentUserId] : []), ...filterChatsByName(lang, chatIds, chatsById, search, currentUserId), ...(contactIds && filter.includes('users') ? filterUsersByName(contactIds, usersById, search) : []), - ]), undefined, priorityIds), - ]; + ]), + undefined, + priorityIds, + currentUserId, + ); return filterChatIdsByType(global, sorted, filter); }, [pinnedIds, currentUserId, activeListIds, search, archivedListIds, lang, contactIds, filter, isOpen]); diff --git a/src/components/common/helpers/sortChatIds.ts b/src/components/common/helpers/sortChatIds.ts index cd17bb8bd..53b3b47d6 100644 --- a/src/components/common/helpers/sortChatIds.ts +++ b/src/components/common/helpers/sortChatIds.ts @@ -10,10 +10,16 @@ export default function sortChatIds( chatIds: string[], shouldPrioritizeVerified = false, priorityIds?: string[], + currentUserId?: string, ) { // Avoid calling sort on every global change const global = getGlobal(); + return orderBy(chatIds, (id) => { + if (id === currentUserId) { + return Infinity; + } + const chat = selectChat(global, id); if (!chat) { return 0;