Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR-219] Allow normal messages to use masked links #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { Markdown, LinkMarkdown } from "./markdown/render";
6 changes: 2 additions & 4 deletions src/markdown/render/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ const rulesWithoutMaskedLinks = createRules({
match: () => null,
},
});
const parse = parserFor(rulesWithoutMaskedLinks);

const parse = parserFor(rulesWithoutMaskedLinks);
export const parseAllowLinks = parserFor(createRules(baseRules));
export const parseEmbedTitle = parserFor(
R.omit(
Expand Down Expand Up @@ -190,7 +190,7 @@ function handleUnicodeEmojis(content: string): string {
);
}

function Markdown({
export function Markdown({
children: content,
mentions,
users,
Expand Down Expand Up @@ -221,5 +221,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