From 2188aa26ceb5c1b1aed07a5c8649e7f5712732c2 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sun, 19 Mar 2023 22:30:51 -0500 Subject: [PATCH] Archive: Display deleted users in preview (#2805) --- src/components/common/PickerSelectedItem.tsx | 9 ++++++--- src/components/left/main/Archive.tsx | 5 ++++- src/components/middle/message/SponsoredMessage.tsx | 2 +- src/global/actions/ui/misc.ts | 2 +- src/global/helpers/chats.ts | 14 ++++++++++---- src/util/notifications.ts | 4 ++-- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/components/common/PickerSelectedItem.tsx b/src/components/common/PickerSelectedItem.tsx index 44adcd555..9058bcce3 100644 --- a/src/components/common/PickerSelectedItem.tsx +++ b/src/components/common/PickerSelectedItem.tsx @@ -1,7 +1,7 @@ -import type { FC, TeactNode } from '../../lib/teact/teact'; import React, { memo } from '../../lib/teact/teact'; import { withGlobal } from '../../global'; +import type { FC, TeactNode } from '../../lib/teact/teact'; import type { ApiChat, ApiUser } from '../../api/types'; import { selectChat, selectUser } from '../../global/selectors'; @@ -28,6 +28,7 @@ type OwnProps = { type StateProps = { chat?: ApiChat; user?: ApiUser; + currentUserId?: string; }; const PickerSelectedItem: FC = ({ @@ -35,11 +36,12 @@ const PickerSelectedItem: FC = ({ title, isMinimized, canClose, - onClick, clickArg, chat, user, className, + currentUserId, + onClick, }) => { const lang = useLang(); @@ -66,7 +68,7 @@ const PickerSelectedItem: FC = ({ const name = !chat || (user && !user.isSelf) ? getUserFirstOrLastName(user) - : getChatTitle(lang, chat, user); + : getChatTitle(lang, chat, chat.id === currentUserId); titleText = name ? renderText(name) : undefined; } @@ -113,6 +115,7 @@ export default memo(withGlobal( return { chat, user, + currentUserId: global.currentUserId, }; }, )(PickerSelectedItem)); diff --git a/src/components/left/main/Archive.tsx b/src/components/left/main/Archive.tsx index 9e6ceb93c..815b9c9c7 100644 --- a/src/components/left/main/Archive.tsx +++ b/src/components/left/main/Archive.tsx @@ -9,6 +9,7 @@ import buildClassName from '../../../util/buildClassName'; import { compact } from '../../../util/iteratees'; import { formatIntegerCompact } from '../../../util/textFormat'; import renderText from '../../common/helpers/renderText'; +import { getChatTitle } from '../../../global/helpers'; import useLang from '../../../hooks/useLang'; import { useFolderManagerForOrderedIds, useFolderManagerForUnreadCounters } from '../../../hooks/useFolderManager'; @@ -50,10 +51,12 @@ const Archive: FC = ({ return undefined; } + const title = getChatTitle(lang, chat); + return ( <> - {renderText(chat.title)} + {renderText(title)} {isLast ? '' : ', '} diff --git a/src/components/middle/message/SponsoredMessage.tsx b/src/components/middle/message/SponsoredMessage.tsx index 215c6748b..22b039589 100644 --- a/src/components/middle/message/SponsoredMessage.tsx +++ b/src/components/middle/message/SponsoredMessage.tsx @@ -118,7 +118,7 @@ const SponsoredMessage: FC = ({
{bot && renderText(getUserFullName(bot) || '')} - {channel && renderText(message.chatInviteTitle || getChatTitle(lang, channel, bot) || '')} + {channel && renderText(message.chatInviteTitle || getChatTitle(lang, channel) || '')}
diff --git a/src/global/actions/ui/misc.ts b/src/global/actions/ui/misc.ts index 13667c736..cab075b8c 100644 --- a/src/global/actions/ui/misc.ts +++ b/src/global/actions/ui/misc.ts @@ -672,7 +672,7 @@ addActionHandler('updatePageTitle', (global, actions, payload): ActionReturnType const { chatId, threadId } = messageList; const currentChat = selectChat(global, chatId); if (currentChat) { - const title = getChatTitle(langProvider.translate, currentChat, undefined, chatId === currentUserId); + const title = getChatTitle(langProvider.translate, currentChat, chatId === currentUserId); if (currentChat.isForum && currentChat.topics?.[threadId]) { setPageTitle(`${title} › ${currentChat.topics[threadId].title}`); return; diff --git a/src/global/helpers/chats.ts b/src/global/helpers/chats.ts index 896ffe64b..df3822342 100644 --- a/src/global/helpers/chats.ts +++ b/src/global/helpers/chats.ts @@ -80,9 +80,8 @@ export function getPrivateChatUserId(chat: ApiChat) { return chat.id; } -// TODO Get rid of `user` -export function getChatTitle(lang: LangFn, chat: ApiChat, user?: ApiUser, isSelf = false) { - if (isSelf || (user && chat.id === user.id && user.isSelf)) { +export function getChatTitle(lang: LangFn, chat: ApiChat, isSelf = false) { + if (isSelf) { return lang('SavedMessages'); } return chat.title || lang('HiddenName'); @@ -464,8 +463,15 @@ export function filterChatsByName( if (!chat) { return false; } + const isSelf = id === currentUserId; - return searchWords(getChatTitle(lang, chat, undefined, id === currentUserId)); + const translatedTitle = getChatTitle(lang, chat, isSelf); + if (isSelf) { + // Search both "Saved Messages" and user title + return searchWords(translatedTitle) || searchWords(chat.title); + } + + return searchWords(translatedTitle); }); } diff --git a/src/util/notifications.ts b/src/util/notifications.ts index 7ac7d7d85..20375f05f 100644 --- a/src/util/notifications.ts +++ b/src/util/notifications.ts @@ -287,7 +287,7 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage, reaction?: A .filter(Boolean) : undefined; const privateChatUserId = getPrivateChatUserId(chat); - const privateChatUser = privateChatUserId ? selectUser(global, privateChatUserId) : undefined; + const isSelf = privateChatUserId === global.currentUserId; const topic = selectTopicFromMessage(global, message); @@ -321,7 +321,7 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage, reaction?: A body = 'New message'; } - let title = isScreenLocked ? APP_NAME : getChatTitle(translate, chat, privateChatUser); + let title = isScreenLocked ? APP_NAME : getChatTitle(translate, chat, isSelf); if (message.isSilent) { title += ' 🔕';