From daffe5ee42f288c5f59c278dc8165d2aca05b243 Mon Sep 17 00:00:00 2001 From: JohnyTheCarrot Date: Tue, 27 Feb 2024 10:47:10 +0100 Subject: [PATCH 1/3] feat: allow normal messages to use masked links --- src/Content/index.tsx | 14 ++++---------- src/index.tsx | 2 +- src/markdown/render/index.tsx | 19 ------------------- src/stories/Normal.stories.tsx | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/Content/index.tsx b/src/Content/index.tsx index 0300576..52d527a 100644 --- a/src/Content/index.tsx +++ b/src/Content/index.tsx @@ -7,7 +7,7 @@ import type { APIEmbedImage } from "discord-api-types/v10"; import { MessageFlags } from "discord-api-types/v10"; import Tooltip from "../Tooltip"; import SvgFromUrl from "../SvgFromUrl"; -import Markdown, { LinkMarkdown } from "../markdown/render"; +import { LinkMarkdown } from "../markdown/render"; import Attachment from "./Attachment"; import Sticker from "./Sticker"; import Embed from "./Embed"; @@ -215,15 +215,9 @@ function Content(props: ContentProps) { > {props.message.content.length > 0 ? ( <> - {props.message.webhook_id !== undefined ? ( - - {props.message.content} - - ) : ( - - {props.message.content} - - )} + + {props.message.content} + {props.message.edited_timestamp && ( )} diff --git a/src/index.tsx b/src/index.tsx index dfcb0d0..b8aaa89 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -53,4 +53,4 @@ export function MessageGroup(props: MessageProps) { export { default as Message } from "./Message"; export { default as MessageRendererProvider } from "./MessageRendererProvider"; -export { default as Markdown, LinkMarkdown } from "./markdown/render"; +export { LinkMarkdown } from "./markdown/render"; diff --git a/src/markdown/render/index.tsx b/src/markdown/render/index.tsx index be9b5cc..9aa8c71 100644 --- a/src/markdown/render/index.tsx +++ b/src/markdown/render/index.tsx @@ -160,7 +160,6 @@ const rulesWithoutMaskedLinks = createRules({ match: () => null, }, }); -const parse = parserFor(rulesWithoutMaskedLinks); export const parseAllowLinks = parserFor(createRules(baseRules)); export const parseEmbedTitle = parserFor( @@ -190,22 +189,6 @@ function handleUnicodeEmojis(content: string): string { ); } -function Markdown({ - children: content, - mentions, - users, -}: { - children: string; - mentions?: ChatMessage["mentions"]; - users?: Map; -}) { - const unicodeEmojisHandled = handleUnicodeEmojis(content); - - return content - ? parse(unicodeEmojisHandled, undefined, { mentions, users }) - : null; -} - export function LinkMarkdown({ children: content, mentions, @@ -221,5 +204,3 @@ export function LinkMarkdown({ ? parseAllowLinks(unicodeEmojisHandled, undefined, { mentions, users }) : null; } - -export default Markdown; diff --git a/src/stories/Normal.stories.tsx b/src/stories/Normal.stories.tsx index a39a6c5..b739fc9 100644 --- a/src/stories/Normal.stories.tsx +++ b/src/stories/Normal.stories.tsx @@ -73,6 +73,38 @@ Basic.args = { ], }; +export const MaskedLinks: StoryFn = Template.bind({}); +MaskedLinks.args = { + messages: [ + { + id: "1101622366137749574", + type: 0, + content: "hi this is a [masked link](https://widgetbot.io/)", + channel_id: "697138785317814292", + author: { + id: "933123872641921044", + username: "therealjethro", + global_name: "Jeff", + avatar: "e4d8c186d8900eed2ace6aed5cefe1c0", + discriminator: "0", + public_flags: 4604871, + }, + attachments: [], + embeds: [], + mentions: [], + mention_roles: [], + pinned: false, + mention_everyone: false, + tts: false, + timestamp: "2023-04-28T21:33:59.241000+00:00", + edited_timestamp: "2023-05-04T16:50:42.356000+00:00", + flags: 1, + components: [], + reactions: [], + }, + ], +}; + export const Optimistic: StoryFn = Template.bind({}); Optimistic.args = { messages: [ From 0606729a4a63c88139c6eb7148ce327117ac47ab Mon Sep 17 00:00:00 2001 From: JohnyTheCarrot Date: Wed, 15 May 2024 09:23:45 +0200 Subject: [PATCH 2/3] add Markdown component back --- src/markdown/render/index.tsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/markdown/render/index.tsx b/src/markdown/render/index.tsx index 9aa8c71..db63856 100644 --- a/src/markdown/render/index.tsx +++ b/src/markdown/render/index.tsx @@ -161,6 +161,7 @@ const rulesWithoutMaskedLinks = createRules({ }, }); +const parse = parserFor(rulesWithoutMaskedLinks); export const parseAllowLinks = parserFor(createRules(baseRules)); export const parseEmbedTitle = parserFor( R.omit( @@ -189,6 +190,22 @@ function handleUnicodeEmojis(content: string): string { ); } +export function Markdown({ + children: content, + mentions, + users, +}: { + children: string; + mentions?: ChatMessage["mentions"]; + users?: Map; +}) { + const unicodeEmojisHandled = handleUnicodeEmojis(content); + + return content + ? parse(unicodeEmojisHandled, undefined, { mentions, users }) + : null; +} + export function LinkMarkdown({ children: content, mentions, From 67e1a15bd145db4e84821af1f9b2c4a54388b388 Mon Sep 17 00:00:00 2001 From: Tuur Martens Date: Wed, 15 May 2024 09:28:18 +0200 Subject: [PATCH 3/3] Update src/index.tsx Co-authored-by: advaith --- src/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index b8aaa89..423d44c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -53,4 +53,4 @@ export function MessageGroup(props: MessageProps) { export { default as Message } from "./Message"; export { default as MessageRendererProvider } from "./MessageRendererProvider"; -export { LinkMarkdown } from "./markdown/render"; +export { Markdown, LinkMarkdown } from "./markdown/render";