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