Archive: Display deleted users in preview (#2805)

This commit is contained in:
Alexander Zinchuk 2023-03-19 22:30:51 -05:00
parent 3ea4f4d3ed
commit 2188aa26ce
6 changed files with 24 additions and 12 deletions

View File

@ -1,7 +1,7 @@
import type { FC, TeactNode } from '../../lib/teact/teact';
import React, { memo } from '../../lib/teact/teact'; import React, { memo } from '../../lib/teact/teact';
import { withGlobal } from '../../global'; import { withGlobal } from '../../global';
import type { FC, TeactNode } from '../../lib/teact/teact';
import type { ApiChat, ApiUser } from '../../api/types'; import type { ApiChat, ApiUser } from '../../api/types';
import { selectChat, selectUser } from '../../global/selectors'; import { selectChat, selectUser } from '../../global/selectors';
@ -28,6 +28,7 @@ type OwnProps = {
type StateProps = { type StateProps = {
chat?: ApiChat; chat?: ApiChat;
user?: ApiUser; user?: ApiUser;
currentUserId?: string;
}; };
const PickerSelectedItem: FC<OwnProps & StateProps> = ({ const PickerSelectedItem: FC<OwnProps & StateProps> = ({
@ -35,11 +36,12 @@ const PickerSelectedItem: FC<OwnProps & StateProps> = ({
title, title,
isMinimized, isMinimized,
canClose, canClose,
onClick,
clickArg, clickArg,
chat, chat,
user, user,
className, className,
currentUserId,
onClick,
}) => { }) => {
const lang = useLang(); const lang = useLang();
@ -66,7 +68,7 @@ const PickerSelectedItem: FC<OwnProps & StateProps> = ({
const name = !chat || (user && !user.isSelf) const name = !chat || (user && !user.isSelf)
? getUserFirstOrLastName(user) ? getUserFirstOrLastName(user)
: getChatTitle(lang, chat, user); : getChatTitle(lang, chat, chat.id === currentUserId);
titleText = name ? renderText(name) : undefined; titleText = name ? renderText(name) : undefined;
} }
@ -113,6 +115,7 @@ export default memo(withGlobal<OwnProps>(
return { return {
chat, chat,
user, user,
currentUserId: global.currentUserId,
}; };
}, },
)(PickerSelectedItem)); )(PickerSelectedItem));

View File

@ -9,6 +9,7 @@ import buildClassName from '../../../util/buildClassName';
import { compact } from '../../../util/iteratees'; import { compact } from '../../../util/iteratees';
import { formatIntegerCompact } from '../../../util/textFormat'; import { formatIntegerCompact } from '../../../util/textFormat';
import renderText from '../../common/helpers/renderText'; import renderText from '../../common/helpers/renderText';
import { getChatTitle } from '../../../global/helpers';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
import { useFolderManagerForOrderedIds, useFolderManagerForUnreadCounters } from '../../../hooks/useFolderManager'; import { useFolderManagerForOrderedIds, useFolderManagerForUnreadCounters } from '../../../hooks/useFolderManager';
@ -50,10 +51,12 @@ const Archive: FC<OwnProps> = ({
return undefined; return undefined;
} }
const title = getChatTitle(lang, chat);
return ( return (
<> <>
<span className={buildClassName(styles.chat, archiveUnreadCount && chat.unreadCount && styles.unread)}> <span className={buildClassName(styles.chat, archiveUnreadCount && chat.unreadCount && styles.unread)}>
{renderText(chat.title)} {renderText(title)}
</span> </span>
{isLast ? '' : ', '} {isLast ? '' : ', '}
</> </>

View File

@ -118,7 +118,7 @@ const SponsoredMessage: FC<OwnProps & StateProps> = ({
<div className="content-inner" dir="auto"> <div className="content-inner" dir="auto">
<div className="message-title" dir="ltr"> <div className="message-title" dir="ltr">
{bot && renderText(getUserFullName(bot) || '')} {bot && renderText(getUserFullName(bot) || '')}
{channel && renderText(message.chatInviteTitle || getChatTitle(lang, channel, bot) || '')} {channel && renderText(message.chatInviteTitle || getChatTitle(lang, channel) || '')}
</div> </div>
<div className="text-content with-meta" dir="auto" ref={contentRef}> <div className="text-content with-meta" dir="auto" ref={contentRef}>

View File

@ -672,7 +672,7 @@ addActionHandler('updatePageTitle', (global, actions, payload): ActionReturnType
const { chatId, threadId } = messageList; const { chatId, threadId } = messageList;
const currentChat = selectChat(global, chatId); const currentChat = selectChat(global, chatId);
if (currentChat) { 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]) { if (currentChat.isForum && currentChat.topics?.[threadId]) {
setPageTitle(`${title} ${currentChat.topics[threadId].title}`); setPageTitle(`${title} ${currentChat.topics[threadId].title}`);
return; return;

View File

@ -80,9 +80,8 @@ export function getPrivateChatUserId(chat: ApiChat) {
return chat.id; return chat.id;
} }
// TODO Get rid of `user` export function getChatTitle(lang: LangFn, chat: ApiChat, isSelf = false) {
export function getChatTitle(lang: LangFn, chat: ApiChat, user?: ApiUser, isSelf = false) { if (isSelf) {
if (isSelf || (user && chat.id === user.id && user.isSelf)) {
return lang('SavedMessages'); return lang('SavedMessages');
} }
return chat.title || lang('HiddenName'); return chat.title || lang('HiddenName');
@ -464,8 +463,15 @@ export function filterChatsByName(
if (!chat) { if (!chat) {
return false; 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);
}); });
} }

View File

@ -287,7 +287,7 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage, reaction?: A
.filter(Boolean) .filter(Boolean)
: undefined; : undefined;
const privateChatUserId = getPrivateChatUserId(chat); const privateChatUserId = getPrivateChatUserId(chat);
const privateChatUser = privateChatUserId ? selectUser(global, privateChatUserId) : undefined; const isSelf = privateChatUserId === global.currentUserId;
const topic = selectTopicFromMessage(global, message); const topic = selectTopicFromMessage(global, message);
@ -321,7 +321,7 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage, reaction?: A
body = 'New message'; body = 'New message';
} }
let title = isScreenLocked ? APP_NAME : getChatTitle(translate, chat, privateChatUser); let title = isScreenLocked ? APP_NAME : getChatTitle(translate, chat, isSelf);
if (message.isSilent) { if (message.isSilent) {
title += ' 🔕'; title += ' 🔕';