Add spoilers to service notifications with auth code
This commit is contained in:
parent
5ca115c527
commit
e10f91e4f0
@ -10,6 +10,7 @@ import {
|
||||
getMessageSummaryDescription,
|
||||
getMessageSummaryEmoji,
|
||||
getMessageSummaryText,
|
||||
extractMessageText,
|
||||
TRUNCATED_SUMMARY_LENGTH,
|
||||
} from '../../global/helpers';
|
||||
import renderText from './helpers/renderText';
|
||||
@ -25,6 +26,7 @@ interface OwnProps {
|
||||
observeIntersectionForLoading?: ObserveFn;
|
||||
observeIntersectionForPlaying?: ObserveFn;
|
||||
withTranslucentThumbs?: boolean;
|
||||
inChatList?: boolean;
|
||||
}
|
||||
|
||||
function MessageSummary({
|
||||
@ -35,12 +37,13 @@ function MessageSummary({
|
||||
truncateLength = TRUNCATED_SUMMARY_LENGTH,
|
||||
observeIntersectionForLoading,
|
||||
observeIntersectionForPlaying,
|
||||
withTranslucentThumbs,
|
||||
withTranslucentThumbs = false,
|
||||
inChatList = false,
|
||||
}: OwnProps) {
|
||||
const { text, entities } = message.content.text || {};
|
||||
|
||||
const { text, entities } = extractMessageText(message, inChatList) || {};
|
||||
const hasSpoilers = entities?.some((e) => e.type === ApiMessageEntityTypes.Spoiler);
|
||||
const hasCustomEmoji = entities?.some((e) => e.type === ApiMessageEntityTypes.CustomEmoji);
|
||||
|
||||
if (!text || (!hasSpoilers && !hasCustomEmoji)) {
|
||||
const trimmedText = trimText(getMessageSummaryText(lang, message, noEmoji), truncateLength);
|
||||
|
||||
@ -65,6 +68,7 @@ function MessageSummary({
|
||||
observeIntersectionForPlaying={observeIntersectionForPlaying}
|
||||
withTranslucentThumbs={withTranslucentThumbs}
|
||||
truncateLength={truncateLength}
|
||||
inChatList={inChatList}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import type { ObserveFn } from '../../hooks/useIntersectionObserver';
|
||||
|
||||
import { ApiMessageEntityTypes } from '../../api/types';
|
||||
import trimText from '../../util/trimText';
|
||||
import { getMessageText, stripCustomEmoji } from '../../global/helpers';
|
||||
import { extractMessageText, getMessageText, stripCustomEmoji } from '../../global/helpers';
|
||||
import { renderTextWithEntities } from './helpers/renderTextWithEntities';
|
||||
import useSyncEffect from '../../hooks/useSyncEffect';
|
||||
|
||||
@ -24,6 +24,7 @@ interface OwnProps {
|
||||
observeIntersectionForPlaying?: ObserveFn;
|
||||
withTranslucentThumbs?: boolean;
|
||||
shouldRenderAsHtml?: boolean;
|
||||
inChatList?: boolean;
|
||||
}
|
||||
|
||||
const MIN_CUSTOM_EMOJIS_FOR_SHARED_CANVAS = 3;
|
||||
@ -41,6 +42,7 @@ function MessageText({
|
||||
observeIntersectionForPlaying,
|
||||
withTranslucentThumbs,
|
||||
shouldRenderAsHtml,
|
||||
inChatList,
|
||||
}: OwnProps) {
|
||||
// eslint-disable-next-line no-null/no-null
|
||||
const sharedCanvasRef = useRef<HTMLCanvasElement>(null);
|
||||
@ -49,10 +51,8 @@ function MessageText({
|
||||
|
||||
const textCacheBusterRef = useRef(0);
|
||||
|
||||
const formattedText = translatedText || message.content.text || undefined;
|
||||
|
||||
const formattedText = translatedText || extractMessageText(message, inChatList);
|
||||
const adaptedFormattedText = isForAnimation && formattedText ? stripCustomEmoji(formattedText) : formattedText;
|
||||
|
||||
const { text, entities } = adaptedFormattedText || {};
|
||||
|
||||
useSyncEffect(() => {
|
||||
|
||||
@ -214,6 +214,7 @@ function renderSummary(
|
||||
message={message}
|
||||
noEmoji={Boolean(blobUrl)}
|
||||
observeIntersectionForLoading={observeIntersection}
|
||||
inChatList
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
@ -295,3 +295,28 @@ export function mergeIdRanges(ranges: number[][], idsUpdate: number[]): number[]
|
||||
|
||||
return newOutlyingLists;
|
||||
}
|
||||
|
||||
export function extractMessageText(message: ApiMessage, inChatList = false) {
|
||||
const contentText = message.content.text;
|
||||
if (!contentText) return undefined;
|
||||
|
||||
const { text } = contentText;
|
||||
let { entities } = contentText;
|
||||
|
||||
if (text && inChatList && message.chatId === SERVICE_NOTIFICATIONS_USER_ID) {
|
||||
const authCode = text.match(/^\D*([\d-]{5,7})\D/)?.[1];
|
||||
if (authCode) {
|
||||
entities = [
|
||||
...entities || [],
|
||||
{
|
||||
type: ApiMessageEntityTypes.Spoiler,
|
||||
offset: text.indexOf(authCode),
|
||||
length: authCode.length,
|
||||
},
|
||||
];
|
||||
entities.sort((a, b) => (a.offset > b.offset ? 1 : -1));
|
||||
}
|
||||
}
|
||||
|
||||
return { text, entities };
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user