From 3341b46ddafa01d6d15fa85b43e26112434856cf Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 11 May 2023 11:56:19 -0500 Subject: [PATCH] statusSchema: add HTML fields --- app/soapbox/schemas/status.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/soapbox/schemas/status.ts b/app/soapbox/schemas/status.ts index ea55d5085..4905fb5a3 100644 --- a/app/soapbox/schemas/status.ts +++ b/app/soapbox/schemas/status.ts @@ -1,5 +1,9 @@ +import escapeTextContentForBrowser from 'escape-html'; import { z } from 'zod'; +import emojify from 'soapbox/features/emoji'; +import { stripCompatibilityFeatures } from 'soapbox/utils/html'; + import { accountSchema } from './account'; import { attachmentSchema } from './attachment'; import { cardSchema } from './card'; @@ -8,7 +12,7 @@ import { groupSchema } from './group'; import { mentionSchema } from './mention'; import { pollSchema } from './poll'; import { tagSchema } from './tag'; -import { contentSchema, dateSchema, filteredArray } from './utils'; +import { contentSchema, dateSchema, filteredArray, makeCustomEmojiMap } from './utils'; const tombstoneSchema = z.object({ reason: z.enum(['deleted']), @@ -59,6 +63,17 @@ const baseStatusSchema = z.object({ const statusSchema = baseStatusSchema.extend({ quote: baseStatusSchema.nullable().catch(null), reblog: baseStatusSchema.nullable().catch(null), +}).transform((status) => { + const emojiMap = makeCustomEmojiMap(status.emojis); + + const contentHtml = stripCompatibilityFeatures(emojify(status.content, emojiMap)); + const spoilerHtml = emojify(escapeTextContentForBrowser(status.spoiler_text), emojiMap); + + return { + ...status, + contentHtml, + spoilerHtml, + }; }); type Status = z.infer;