From 1a8df50987bff37f91c8562d58fbff08c292847a Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 26 Jul 2021 17:35:49 +0300 Subject: [PATCH] Action Message: Better formatting (#1329) --- src/api/gramjs/apiBuilders/messages.ts | 2 +- .../helpers/renderActionMessageText.tsx | 33 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 1fce42b16..a0f0ce1b5 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -636,7 +636,7 @@ function buildAction( text = 'Migrated from %target_chat%'; translationValues.push('%target_chat%'); } else if (action instanceof GramJs.MessageActionPinMessage) { - text = 'Notification.PinnedTextMessage'; + text = 'Chat.Service.Group.UpdatedPinnedMessage1'; translationValues.push('%action_origin%', '%message%'); } else if (action instanceof GramJs.MessageActionHistoryClear) { text = 'HistoryCleared'; diff --git a/src/components/common/helpers/renderActionMessageText.tsx b/src/components/common/helpers/renderActionMessageText.tsx index e725a9fc4..4949c64c2 100644 --- a/src/components/common/helpers/renderActionMessageText.tsx +++ b/src/components/common/helpers/renderActionMessageText.tsx @@ -39,11 +39,14 @@ export function renderActionMessageText( } const { text, translationValues } = message.content.action; const content: TextPart[] = []; - const textOptions: ActionMessageTextOptions = { ...options, maxTextLength: 16 }; + const textOptions: ActionMessageTextOptions = { ...options, maxTextLength: 32 }; + const translationKey = text === 'Chat.Service.Group.UpdatedPinnedMessage1' && !targetMessage + ? 'Message.PinnedGenericMessage' + : text; let unprocessed: string; let processed = processPlaceholder( - lang(text, translationValues && translationValues.length ? translationValues : undefined), + lang(translationKey, translationValues && translationValues.length ? translationValues : undefined), '%action_origin%', actionOrigin ? (!options.isEmbedded && renderOriginContent(lang, actionOrigin, options.asPlain)) || NBSP @@ -112,20 +115,24 @@ function renderMessageContent(lang: LangFn, message: ApiMessage, options: Action photo, video, document, sticker, } = getMessageContent(message); - const showQuotes = text && !photo && !video && !document && !sticker; - let messageText = trimText(text as string, options.maxTextLength)!; + const { maxTextLength, isEmbedded, asPlain } = options; - if (photo) { - messageText = 'a photo'; - } else if (video) { - messageText = video.isGif ? 'a GIF' : 'a video'; - } else if (document) { - messageText = 'a document'; - } else if (sticker) { - messageText = `«${text}»`; + const showQuotes = isEmbedded && text && !photo && !video && !document && !sticker; + let messageText = trimText(text as string, maxTextLength)!; + + if (isEmbedded) { + if (photo) { + messageText = 'a photo'; + } else if (video) { + messageText = video.isGif ? 'a GIF' : 'a video'; + } else if (document) { + messageText = 'a document'; + } else if (sticker) { + messageText = text; + } } - if (options.asPlain) { + if (asPlain) { return showQuotes ? `«${messageText}»` : messageText; }