Action Message: Fix missing origin name

This commit is contained in:
Alexander Zinchuk 2022-01-28 02:12:04 +01:00
parent 97891c02a5
commit 74d1c8547a
4 changed files with 26 additions and 26 deletions

View File

@ -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<ApiGroupCall>, text: TextPart[]): string | TextPart | undefined {
return (
<GroupCallLink groupCall={groupCall}>

View File

@ -235,16 +235,15 @@ const Chat: FC<OwnProps & StateProps> = ({
}
if (isAction) {
const actionOrigin = chat && (isChatChannel(chat) || lastMessage.senderId === lastMessage.chatId)
? chat
: lastMessageSender;
const isChat = chat && (isChatChannel(chat) || lastMessage.senderId === lastMessage.chatId);
return (
<p className="last-message" dir={lang.isRtl ? 'auto' : 'ltr'}>
{renderActionMessageText(
lang,
lastMessage,
actionOrigin,
!isChat ? lastMessageSender : undefined,
isChat ? chat : undefined,
actionTargetUsers,
actionTargetMessage,
actionTargetChatId,

View File

@ -36,7 +36,8 @@ type OwnProps = {
type StateProps = {
usersById: Record<string, ApiUser>;
sender?: ApiUser | ApiChat;
senderUser?: ApiUser;
senderChat?: ApiChat;
targetUserIds?: string[];
targetMessage?: ApiMessage;
targetChatId?: string;
@ -54,7 +55,8 @@ const ActionMessage: FC<OwnProps & StateProps> = ({
appearanceOrder = 0,
isLastInList,
usersById,
sender,
senderUser,
senderChat,
targetUserIds,
targetMessage,
targetChatId,
@ -91,7 +93,8 @@ const ActionMessage: FC<OwnProps & StateProps> = ({
const content = renderActionMessageText(
lang,
message,
sender,
senderUser,
senderChat,
targetUsers,
targetMessage,
targetChatId,
@ -159,13 +162,14 @@ export default memo(withGlobal<OwnProps>(
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,

View File

@ -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,