Skip to content

Commit

Permalink
feat: allow normal messages to use masked links
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnyTheCarrot committed Feb 27, 2024
1 parent f55f1ec commit daffe5e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 30 deletions.
14 changes: 4 additions & 10 deletions src/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -215,15 +215,9 @@ function Content(props: ContentProps) {
>
{props.message.content.length > 0 ? (
<>
{props.message.webhook_id !== undefined ? (
<LinkMarkdown mentions={props.message.mentions}>
{props.message.content}
</LinkMarkdown>
) : (
<Markdown mentions={props.message.mentions}>
{props.message.content}
</Markdown>
)}
<LinkMarkdown mentions={props.message.mentions}>
{props.message.content}
</LinkMarkdown>
{props.message.edited_timestamp && (
<Edited editedAt={props.message.edited_timestamp} />
)}
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
19 changes: 0 additions & 19 deletions src/markdown/render/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ const rulesWithoutMaskedLinks = createRules({
match: () => null,
},
});
const parse = parserFor(rulesWithoutMaskedLinks);

export const parseAllowLinks = parserFor(createRules(baseRules));
export const parseEmbedTitle = parserFor(
Expand Down Expand Up @@ -190,22 +189,6 @@ function handleUnicodeEmojis(content: string): string {
);
}

function Markdown({
children: content,
mentions,
users,
}: {
children: string;
mentions?: ChatMessage["mentions"];
users?: Map<string, APIUser>;
}) {
const unicodeEmojisHandled = handleUnicodeEmojis(content);

return content
? parse(unicodeEmojisHandled, undefined, { mentions, users })
: null;
}

export function LinkMarkdown({
children: content,
mentions,
Expand All @@ -221,5 +204,3 @@ export function LinkMarkdown({
? parseAllowLinks(unicodeEmojisHandled, undefined, { mentions, users })
: null;
}

export default Markdown;
32 changes: 32 additions & 0 deletions src/stories/Normal.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,38 @@ Basic.args = {
],
};

export const MaskedLinks: StoryFn<typeof MessageGroup> = 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<typeof MessageGroup> = Template.bind({});
Optimistic.args = {
messages: [
Expand Down

0 comments on commit daffe5e

Please sign in to comment.