diff --git a/app/javascript/flavours/glitch/components/status/handled_link.stories.tsx b/app/javascript/flavours/glitch/components/status/handled_link.stories.tsx index f29f957dfe..e07d04b730 100644 --- a/app/javascript/flavours/glitch/components/status/handled_link.stories.tsx +++ b/app/javascript/flavours/glitch/components/status/handled_link.stories.tsx @@ -21,9 +21,13 @@ const meta = { render({ mentionAccount, hashtagAccount, ...args }) { let mention: HandledLinkProps['mention'] | undefined; if (mentionAccount === 'local') { - mention = { id: '1', acct: 'testuser' }; + mention = { id: '1', acct: 'testuser', username: 'testuser' }; } else if (mentionAccount === 'remote') { - mention = { id: '2', acct: 'remoteuser@mastodon.social' }; + mention = { + id: '2', + acct: 'remoteuser@mastodon.social', + username: 'remoteuser', + }; } return ( <> diff --git a/app/javascript/flavours/glitch/components/status/handled_link.tsx b/app/javascript/flavours/glitch/components/status/handled_link.tsx index 31b0307c61..035cb09b78 100644 --- a/app/javascript/flavours/glitch/components/status/handled_link.tsx +++ b/app/javascript/flavours/glitch/components/status/handled_link.tsx @@ -5,6 +5,7 @@ import classNames from 'classnames'; import { Link } from 'react-router-dom'; import type { ApiMentionJSON } from '@/flavours/glitch/api_types/statuses'; +import { useAppSelector } from '@/flavours/glitch/store'; import type { OnElementHandler } from '@/flavours/glitch/utils/html'; export interface HandledLinkProps { @@ -12,7 +13,7 @@ export interface HandledLinkProps { text: string; prevText?: string; hashtagAccountId?: string; - mention?: Pick; + mention?: Pick; } export const HandledLink: FC> = ({ @@ -25,6 +26,11 @@ export const HandledLink: FC> = ({ children, ...props }) => { + const rewriteMentions = useAppSelector( + // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access + (state) => state.local_settings.get('rewrite_mentions', 'no') as string, + ); + // Handle hashtags if (text.startsWith('#') || prevText?.endsWith('#')) { const hashtag = text.slice(1).trim(); @@ -39,6 +45,23 @@ export const HandledLink: FC> = ({ ); } else if (mention) { + // glitch-soc feature to rewrite mentions + if (rewriteMentions !== 'no') { + return ( + + @ + + {rewriteMentions === 'acct' ? mention.acct : mention.username} + + + ); + } + // Handle mentions return (