diff --git a/lib/shared/markdown.js b/lib/shared/markdown.js --- a/lib/shared/markdown.js +++ b/lib/shared/markdown.js @@ -251,6 +251,11 @@ } const spoilerRegex: RegExp = /^\|\|([^\n]+?)\|\|/g; +const replaceSpoilerRegex: RegExp = /\|\|(.+?)\|\|/g; +const spoilerReplacement: string = '⬛⬛⬛'; + +const stripSpoilersFromNotifications = (text: string): string => + text.replace(replaceSpoilerRegex, spoilerReplacement); export { paragraphRegex, @@ -272,4 +277,5 @@ matchList, parseList, matchMentions, + stripSpoilersFromNotifications, }; diff --git a/lib/shared/messages/text-message-spec.js b/lib/shared/messages/text-message-spec.js --- a/lib/shared/messages/text-message-spec.js +++ b/lib/shared/messages/text-message-spec.js @@ -16,7 +16,11 @@ import type { NotifTexts } from '../../types/notif-types'; import type { ThreadInfo } from '../../types/thread-types'; import type { RelativeUserInfo } from '../../types/user-types'; -import { type ASTNode, type SingleASTNode } from '../markdown'; +import { + type ASTNode, + type SingleASTNode, + stripSpoilersFromNotifications, +} from '../markdown'; import { threadIsGroupChat } from '../thread-utils'; import { stringForUser } from '../user-utils'; import type { @@ -168,18 +172,21 @@ messageInfo.type === messageTypes.TEXT, 'messageInfo should be messageTypes.TEXT!', ); + const notificationTextWithoutSpoilers = stripSpoilersFromNotifications( + messageInfo.text, + ); if (!threadInfo.name && !threadIsGroupChat(threadInfo)) { return { - merged: `${threadInfo.uiName}: ${messageInfo.text}`, - body: messageInfo.text, + merged: `${threadInfo.uiName}: ${notificationTextWithoutSpoilers}`, + body: notificationTextWithoutSpoilers, title: threadInfo.uiName, }; } else { const userString = stringForUser(messageInfo.creator); const threadName = params.notifThreadName(threadInfo); return { - merged: `${userString} to ${threadName}: ${messageInfo.text}`, - body: messageInfo.text, + merged: `${userString} to ${threadName}: ${notificationTextWithoutSpoilers}`, + body: notificationTextWithoutSpoilers, title: threadInfo.uiName, prefix: `${userString}:`, };