Action Message: Better formatting (#1329)

This commit is contained in:
Alexander Zinchuk 2021-07-26 17:35:49 +03:00
parent 3004c27130
commit 1a8df50987
2 changed files with 21 additions and 14 deletions

View File

@ -636,7 +636,7 @@ function buildAction(
text = 'Migrated from %target_chat%'; text = 'Migrated from %target_chat%';
translationValues.push('%target_chat%'); translationValues.push('%target_chat%');
} else if (action instanceof GramJs.MessageActionPinMessage) { } else if (action instanceof GramJs.MessageActionPinMessage) {
text = 'Notification.PinnedTextMessage'; text = 'Chat.Service.Group.UpdatedPinnedMessage1';
translationValues.push('%action_origin%', '%message%'); translationValues.push('%action_origin%', '%message%');
} else if (action instanceof GramJs.MessageActionHistoryClear) { } else if (action instanceof GramJs.MessageActionHistoryClear) {
text = 'HistoryCleared'; text = 'HistoryCleared';

View File

@ -39,11 +39,14 @@ export function renderActionMessageText(
} }
const { text, translationValues } = message.content.action; const { text, translationValues } = message.content.action;
const content: TextPart[] = []; 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 unprocessed: string;
let processed = processPlaceholder( let processed = processPlaceholder(
lang(text, translationValues && translationValues.length ? translationValues : undefined), lang(translationKey, translationValues && translationValues.length ? translationValues : undefined),
'%action_origin%', '%action_origin%',
actionOrigin actionOrigin
? (!options.isEmbedded && renderOriginContent(lang, actionOrigin, options.asPlain)) || NBSP ? (!options.isEmbedded && renderOriginContent(lang, actionOrigin, options.asPlain)) || NBSP
@ -112,20 +115,24 @@ function renderMessageContent(lang: LangFn, message: ApiMessage, options: Action
photo, video, document, sticker, photo, video, document, sticker,
} = getMessageContent(message); } = getMessageContent(message);
const showQuotes = text && !photo && !video && !document && !sticker; const { maxTextLength, isEmbedded, asPlain } = options;
let messageText = trimText(text as string, options.maxTextLength)!;
if (photo) { const showQuotes = isEmbedded && text && !photo && !video && !document && !sticker;
messageText = 'a photo'; let messageText = trimText(text as string, maxTextLength)!;
} else if (video) {
messageText = video.isGif ? 'a GIF' : 'a video'; if (isEmbedded) {
} else if (document) { if (photo) {
messageText = 'a document'; messageText = 'a photo';
} else if (sticker) { } else if (video) {
messageText = `«${text}»`; 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; return showQuotes ? `«${messageText}»` : messageText;
} }