mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-27 04:16:25 -08:00
fix: route Matrix URI mentions in profiles
This commit is contained in:
2 files changed
+33
-8
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { Box, Button, color, config, Menu, MenuItem, Scroll, Text, toRem } from 'folds';
|
||||
import type { CSSProperties, SyntheticEvent } from 'react';
|
||||
import { useCallback, useLayoutEffect, useMemo, useState } from 'react';
|
||||
import type { CSSProperties } from 'react';
|
||||
import { useLayoutEffect, useMemo, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import type { Opts as LinkifyOpts } from 'linkifyjs';
|
||||
@@ -61,6 +61,7 @@ import { IgnoredUserAlert, MutualRoomsChip, OptionsChip, ServerChip, ShareChip }
|
||||
import { UserHero, UserHeroName } from './UserHero';
|
||||
import { KnownMembership } from '$types/matrix-sdk';
|
||||
import { useRoomMemberHydration } from '$hooks/useRoomMemberHydration';
|
||||
import { useMentionClickHandler } from '$hooks/useMentionClickHandler';
|
||||
import * as css from './styles.css';
|
||||
import * as prefix from '$unstable/prefixes';
|
||||
import type { Persona } from '$app/persona';
|
||||
@@ -496,10 +497,7 @@ export function UserRoomProfile({
|
||||
navigate(withSearchParam(getDirectCreatePath(), directSearchParam));
|
||||
};
|
||||
|
||||
// Todo eventually maybe
|
||||
const mentionClickHandler = useCallback((e: SyntheticEvent<HTMLElement>) => {
|
||||
e.preventDefault();
|
||||
}, []);
|
||||
const mentionClickHandler = useMentionClickHandler(room.roomId);
|
||||
const settingsLinkBaseUrl = useSettingsLinkBaseUrl();
|
||||
|
||||
const linkifyOpts = useMemo<LinkifyOpts>(
|
||||
@@ -530,8 +528,17 @@ export function UserRoomProfile({
|
||||
linkifyOpts,
|
||||
useAuthentication,
|
||||
handleSpoilerClick: spoilerClickHandler,
|
||||
handleMentionClick: mentionClickHandler,
|
||||
}),
|
||||
[mx, room, linkifyOpts, settingsLinkBaseUrl, useAuthentication, spoilerClickHandler]
|
||||
[
|
||||
mx,
|
||||
room,
|
||||
linkifyOpts,
|
||||
settingsLinkBaseUrl,
|
||||
useAuthentication,
|
||||
spoilerClickHandler,
|
||||
mentionClickHandler,
|
||||
]
|
||||
);
|
||||
|
||||
const backgroundColor = fetchedProfile.heroColor ?? color.Surface.Container;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import type { ReactEventHandler } from 'react';
|
||||
import parse from 'html-react-parser';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import * as customHtmlCss from '$styles/CustomHtml.css';
|
||||
@@ -514,6 +515,23 @@ describe('matrix: URI mentions', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['matrix:u/bob:example.org', '@bob'],
|
||||
['matrix:roomid/room:example.org', '#Lobby'],
|
||||
])('routes a matrix: %s mention through the click handler', (href, label) => {
|
||||
const handleMentionClick = vi.fn<ReactEventHandler<HTMLElement>>();
|
||||
const parserOptions = getReactCustomHtmlParser(roomMx(), '!room:example.com', {
|
||||
settingsLinkBaseUrl,
|
||||
linkifyOpts: LINKIFY_OPTS,
|
||||
handleMentionClick,
|
||||
});
|
||||
|
||||
render(<div>{parse(`<a href="${href}">${href}</a>`, parserOptions)}</div>);
|
||||
|
||||
fireEvent.click(screen.getByRole('link', { name: label }));
|
||||
expect(handleMentionClick).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('renders a matrix: room URI with via servers and falls back to the room name', () => {
|
||||
renderParsedHtml(
|
||||
'<a href="matrix:roomid/room:example.org?via=elsewhere.ca">matrix:roomid/room:example.org?via=elsewhere.ca</a>',
|
||||
|
||||
Reference in new issue
Block a user