mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-13 07:49:29 +00:00
Reimplement mention rewriting in new HTML handling code (#3247)
This commit is contained in:
@@ -21,9 +21,13 @@ const meta = {
|
|||||||
render({ mentionAccount, hashtagAccount, ...args }) {
|
render({ mentionAccount, hashtagAccount, ...args }) {
|
||||||
let mention: HandledLinkProps['mention'] | undefined;
|
let mention: HandledLinkProps['mention'] | undefined;
|
||||||
if (mentionAccount === 'local') {
|
if (mentionAccount === 'local') {
|
||||||
mention = { id: '1', acct: 'testuser' };
|
mention = { id: '1', acct: 'testuser', username: 'testuser' };
|
||||||
} else if (mentionAccount === 'remote') {
|
} else if (mentionAccount === 'remote') {
|
||||||
mention = { id: '2', acct: 'remoteuser@mastodon.social' };
|
mention = {
|
||||||
|
id: '2',
|
||||||
|
acct: 'remoteuser@mastodon.social',
|
||||||
|
username: 'remoteuser',
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import classNames from 'classnames';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
|
|
||||||
import type { ApiMentionJSON } from '@/flavours/glitch/api_types/statuses';
|
import type { ApiMentionJSON } from '@/flavours/glitch/api_types/statuses';
|
||||||
|
import { useAppSelector } from '@/flavours/glitch/store';
|
||||||
import type { OnElementHandler } from '@/flavours/glitch/utils/html';
|
import type { OnElementHandler } from '@/flavours/glitch/utils/html';
|
||||||
|
|
||||||
export interface HandledLinkProps {
|
export interface HandledLinkProps {
|
||||||
@@ -12,7 +13,7 @@ export interface HandledLinkProps {
|
|||||||
text: string;
|
text: string;
|
||||||
prevText?: string;
|
prevText?: string;
|
||||||
hashtagAccountId?: string;
|
hashtagAccountId?: string;
|
||||||
mention?: Pick<ApiMentionJSON, 'id' | 'acct'>;
|
mention?: Pick<ApiMentionJSON, 'id' | 'acct' | 'username'>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
|
export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
|
||||||
@@ -25,6 +26,11 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
|
|||||||
children,
|
children,
|
||||||
...props
|
...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
|
// Handle hashtags
|
||||||
if (text.startsWith('#') || prevText?.endsWith('#')) {
|
if (text.startsWith('#') || prevText?.endsWith('#')) {
|
||||||
const hashtag = text.slice(1).trim();
|
const hashtag = text.slice(1).trim();
|
||||||
@@ -39,6 +45,23 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
|
|||||||
</Link>
|
</Link>
|
||||||
);
|
);
|
||||||
} else if (mention) {
|
} else if (mention) {
|
||||||
|
// glitch-soc feature to rewrite mentions
|
||||||
|
if (rewriteMentions !== 'no') {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
className={classNames('mention', className)}
|
||||||
|
to={`/@${mention.acct}`}
|
||||||
|
title={`@${mention.acct}`}
|
||||||
|
data-hover-card-account={mention.id}
|
||||||
|
>
|
||||||
|
@
|
||||||
|
<span>
|
||||||
|
{rewriteMentions === 'acct' ? mention.acct : mention.username}
|
||||||
|
</span>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Handle mentions
|
// Handle mentions
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
Reference in New Issue
Block a user