From 206a24031d73159cb611892af192d0636c0fe4b1 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 7 Jan 2022 19:57:15 +0100 Subject: [PATCH] Message: Do not display message with spoilers --- src/api/gramjs/apiBuilders/messages.ts | 7 +++++++ src/config.ts | 2 ++ src/modules/helpers/messages.ts | 8 ++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/api/gramjs/apiBuilders/messages.ts b/src/api/gramjs/apiBuilders/messages.ts index 5c3befbd9..0d4dd6260 100644 --- a/src/api/gramjs/apiBuilders/messages.ts +++ b/src/api/gramjs/apiBuilders/messages.ts @@ -27,6 +27,7 @@ import { } from '../../types'; import { + CONTENT_NOT_SUPPORTED, DELETED_COMMENTS_CHANNEL_ID, LOCAL_MESSAGE_ID_BASE, SERVICE_NOTIFICATIONS_USER_ID, @@ -217,6 +218,12 @@ export function buildMessageTextContent( message: string, entities?: GramJs.TypeMessageEntity[], ): ApiFormattedText { + if (entities?.some((e) => e instanceof GramJs.MessageEntitySpoiler)) { + return { + text: CONTENT_NOT_SUPPORTED, + }; + } + return { text: message, ...(entities && { entities: entities.map(buildApiMessageEntity) }), diff --git a/src/config.ts b/src/config.ts index 2165eedf5..189241ac4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -145,6 +145,8 @@ export const CONTENT_TYPES_WITH_PREVIEW = new Set([ ...SUPPORTED_VIDEO_CONTENT_TYPES, ]); +export const CONTENT_NOT_SUPPORTED = 'The message is not supported on this version of Telegram.'; + // eslint-disable-next-line max-len export const RE_LINK_TEMPLATE = '((ftp|https?):\\/\\/)?((www\\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,63})\\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)'; export const RE_MENTION_TEMPLATE = '(@[\\w\\d_-]+)'; diff --git a/src/modules/helpers/messages.ts b/src/modules/helpers/messages.ts index 54220437c..76c31d20d 100644 --- a/src/modules/helpers/messages.ts +++ b/src/modules/helpers/messages.ts @@ -3,13 +3,17 @@ import { } from '../../api/types'; import { LangFn } from '../../hooks/useLang'; -import { LOCAL_MESSAGE_ID_BASE, SERVICE_NOTIFICATIONS_USER_ID, RE_LINK_TEMPLATE } from '../../config'; +import { + LOCAL_MESSAGE_ID_BASE, + SERVICE_NOTIFICATIONS_USER_ID, + RE_LINK_TEMPLATE, + CONTENT_NOT_SUPPORTED, +} from '../../config'; import { getUserFullName } from './users'; import { isWebpSupported, IS_OPUS_SUPPORTED } from '../../util/environment'; import { getChatTitle, isUserId } from './chats'; import parseEmojiOnlyString from '../../components/common/helpers/parseEmojiOnlyString'; -const CONTENT_NOT_SUPPORTED = 'The message is not supported on this version of Telegram'; const RE_LINK = new RegExp(RE_LINK_TEMPLATE, 'i'); const TRUNCATED_SUMMARY_LENGTH = 80;