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 { 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<OwnProps & StateProps> = ({
@ -35,11 +36,12 @@ const PickerSelectedItem: FC<OwnProps & StateProps> = ({
title,
isMinimized,
canClose,
onClick,
clickArg,
chat,
user,
className,
currentUserId,
onClick,
}) => {
const lang = useLang();
@ -66,7 +68,7 @@ const PickerSelectedItem: FC<OwnProps & StateProps> = ({
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<OwnProps>(
return {
chat,
user,
currentUserId: global.currentUserId,
};
},
)(PickerSelectedItem));

View File

@ -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<OwnProps> = ({
return undefined;
}
const title = getChatTitle(lang, chat);
return (
<>
<span className={buildClassName(styles.chat, archiveUnreadCount && chat.unreadCount && styles.unread)}>
{renderText(chat.title)}
{renderText(title)}
</span>
{isLast ? '' : ', '}
</>

View File

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

View File

@ -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);
});
}

View File

@ -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 += ' 🔕';