From 74d1c8547a6af3177cf618063f541e6da9240012 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 28 Jan 2022 02:12:04 +0100 Subject: [PATCH] Action Message: Fix missing origin name --- .../helpers/renderActionMessageText.tsx | 19 ++++++++----------- src/components/left/main/Chat.tsx | 7 +++---- src/components/middle/ActionMessage.tsx | 18 +++++++++++------- src/util/notifications.ts | 8 ++++---- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/components/common/helpers/renderActionMessageText.tsx b/src/components/common/helpers/renderActionMessageText.tsx index 2b40133b0..4f14fc363 100644 --- a/src/components/common/helpers/renderActionMessageText.tsx +++ b/src/components/common/helpers/renderActionMessageText.tsx @@ -8,7 +8,6 @@ import { getChatTitle, getMessageContent, getMessageSummaryText, getUserFullName, - isUserId, } from '../../../modules/helpers'; import trimText from '../../../util/trimText'; import { formatCurrency } from '../../../util/formatCurrency'; @@ -31,7 +30,8 @@ const NBSP = '\u00A0'; export function renderActionMessageText( lang: LangFn, message: ApiMessage, - actionOrigin?: ApiUser | ApiChat, + actionOriginUser?: ApiUser, + actionOriginChat?: ApiChat, targetUsers?: ApiUser[], targetMessage?: ApiMessage, targetChatId?: string, @@ -65,9 +65,12 @@ export function renderActionMessageText( processed = processPlaceholder( unprocessed, '%action_origin%', - actionOrigin - ? (!options.isEmbedded && renderOriginContent(lang, actionOrigin, options.asPlain)) || NBSP - : 'User', + actionOriginUser ? ( + (!options.isEmbedded && renderUserContent(actionOriginUser, options.asPlain)) || NBSP + + ) : actionOriginChat ? ( + (!options.isEmbedded && renderChatContent(lang, actionOriginChat, options.asPlain)) || NBSP + ) : 'User', ); unprocessed = processed.pop() as string; @@ -174,12 +177,6 @@ function renderMessageContent(lang: LangFn, message: ApiMessage, options: Action ); } -function renderOriginContent(lang: LangFn, origin: ApiUser | ApiChat, asPlain?: boolean) { - return isUserId(origin.id) - ? renderUserContent(origin as ApiUser, asPlain) - : renderChatContent(lang, origin as ApiChat, asPlain); -} - function renderGroupCallContent(groupCall: Partial, text: TextPart[]): string | TextPart | undefined { return ( diff --git a/src/components/left/main/Chat.tsx b/src/components/left/main/Chat.tsx index fd4bb7770..06c6088b2 100644 --- a/src/components/left/main/Chat.tsx +++ b/src/components/left/main/Chat.tsx @@ -235,16 +235,15 @@ const Chat: FC = ({ } if (isAction) { - const actionOrigin = chat && (isChatChannel(chat) || lastMessage.senderId === lastMessage.chatId) - ? chat - : lastMessageSender; + const isChat = chat && (isChatChannel(chat) || lastMessage.senderId === lastMessage.chatId); return (

{renderActionMessageText( lang, lastMessage, - actionOrigin, + !isChat ? lastMessageSender : undefined, + isChat ? chat : undefined, actionTargetUsers, actionTargetMessage, actionTargetChatId, diff --git a/src/components/middle/ActionMessage.tsx b/src/components/middle/ActionMessage.tsx index 934e8ba41..f9c30ad76 100644 --- a/src/components/middle/ActionMessage.tsx +++ b/src/components/middle/ActionMessage.tsx @@ -36,7 +36,8 @@ type OwnProps = { type StateProps = { usersById: Record; - sender?: ApiUser | ApiChat; + senderUser?: ApiUser; + senderChat?: ApiChat; targetUserIds?: string[]; targetMessage?: ApiMessage; targetChatId?: string; @@ -54,7 +55,8 @@ const ActionMessage: FC = ({ appearanceOrder = 0, isLastInList, usersById, - sender, + senderUser, + senderChat, targetUserIds, targetMessage, targetChatId, @@ -91,7 +93,8 @@ const ActionMessage: FC = ({ const content = renderActionMessageText( lang, message, - sender, + senderUser, + senderChat, targetUsers, targetMessage, targetChatId, @@ -159,13 +162,14 @@ export default memo(withGlobal( const { direction: focusDirection, noHighlight: noFocusHighlight } = (isFocused && global.focusedMessage) || {}; const chat = selectChat(global, message.chatId); - const sender = chat && (isChatChannel(chat) || userId === message.chatId) - ? chat - : userId ? selectUser(global, userId) : undefined; + const isChat = chat && (isChatChannel(chat) || userId === message.chatId); + const senderUser = !isChat && userId ? selectUser(global, userId) : undefined; + const senderChat = isChat ? chat : undefined; return { usersById, - sender, + senderUser, + senderChat, targetChatId, targetUserIds, targetMessage, diff --git a/src/util/notifications.ts b/src/util/notifications.ts index db52d7146..ab949d83f 100644 --- a/src/util/notifications.ts +++ b/src/util/notifications.ts @@ -277,13 +277,13 @@ function getNotificationContent(chat: ApiChat, message: ApiMessage) { let body: string; if (selectShouldShowMessagePreview(chat, selectNotifySettings(global), selectNotifyExceptions(global))) { if (isActionMessage(message)) { - const actionOrigin = chat && (isChatChannel(chat) || message.senderId === message.chatId) - ? chat - : messageSender; + const isChat = chat && (isChatChannel(chat) || message.senderId === message.chatId); + body = renderActionMessageText( getTranslation, message, - actionOrigin, + !isChat ? messageSender : undefined, + isChat ? chat : undefined, actionTargetUsers, actionTargetMessage, actionTargetChatId,