Fix room mention (#1459)
* create room mention with alias if possible * display room mention text as they were sent
This commit is contained in:
parent
ed3d14b131
commit
a2692e1469
3 changed files with 10 additions and 11 deletions
|
@ -32,14 +32,14 @@ function UnknownRoomMentionItem({
|
||||||
const mx = useMatrixClient();
|
const mx = useMatrixClient();
|
||||||
const roomAlias: string = roomAliasFromQueryText(mx, query.text);
|
const roomAlias: string = roomAliasFromQueryText(mx, query.text);
|
||||||
|
|
||||||
|
const handleSelect = () => handleAutocomplete(roomAlias, roomAlias);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
as="button"
|
as="button"
|
||||||
radii="300"
|
radii="300"
|
||||||
onKeyDown={(evt: ReactKeyboardEvent<HTMLButtonElement>) =>
|
onKeyDown={(evt: ReactKeyboardEvent<HTMLButtonElement>) => onTabPress(evt, handleSelect)}
|
||||||
onTabPress(evt, () => handleAutocomplete(roomAlias, roomAlias))
|
onClick={handleSelect}
|
||||||
}
|
|
||||||
onClick={() => handleAutocomplete(roomAlias, roomAlias)}
|
|
||||||
before={
|
before={
|
||||||
<Avatar size="200">
|
<Avatar size="200">
|
||||||
<Icon src={Icons.Hash} size="100" />
|
<Icon src={Icons.Hash} size="100" />
|
||||||
|
@ -140,15 +140,17 @@ export function RoomMentionAutocomplete({
|
||||||
const avatarUrl = getRoomAvatarUrl(mx, room);
|
const avatarUrl = getRoomAvatarUrl(mx, room);
|
||||||
const iconSrc = !dm && joinRuleToIconSrc(Icons, room.getJoinRule(), room.isSpaceRoom());
|
const iconSrc = !dm && joinRuleToIconSrc(Icons, room.getJoinRule(), room.isSpaceRoom());
|
||||||
|
|
||||||
|
const handleSelect = () => handleAutocomplete(room.getCanonicalAlias() ?? rId, room.name);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
key={rId}
|
key={rId}
|
||||||
as="button"
|
as="button"
|
||||||
radii="300"
|
radii="300"
|
||||||
onKeyDown={(evt: ReactKeyboardEvent<HTMLButtonElement>) =>
|
onKeyDown={(evt: ReactKeyboardEvent<HTMLButtonElement>) =>
|
||||||
onTabPress(evt, () => handleAutocomplete(rId, room.name))
|
onTabPress(evt, handleSelect)
|
||||||
}
|
}
|
||||||
onClick={() => handleAutocomplete(room.getCanonicalAlias() ?? rId, room.name)}
|
onClick={handleSelect}
|
||||||
after={
|
after={
|
||||||
<Text size="T200" priority="300" truncate>
|
<Text size="T200" priority="300" truncate>
|
||||||
{room.getCanonicalAlias() ?? ''}
|
{room.getCanonicalAlias() ?? ''}
|
||||||
|
|
|
@ -74,7 +74,7 @@ const elementToInlineNode = (node: Element): MentionElement | EmoticonElement |
|
||||||
if (typeof href !== 'string') return undefined;
|
if (typeof href !== 'string') return undefined;
|
||||||
const [mxId] = parseMatrixToUrl(href);
|
const [mxId] = parseMatrixToUrl(href);
|
||||||
if (mxId) {
|
if (mxId) {
|
||||||
return createMentionElement(mxId, mxId, false);
|
return createMentionElement(mxId, parseNodeText(node) || mxId, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|
|
@ -180,10 +180,7 @@ export const getReactCustomHtmlParser = (
|
||||||
mentionPrefix === '#'
|
mentionPrefix === '#'
|
||||||
? getRoomWithCanonicalAlias(mx, mentionId)
|
? getRoomWithCanonicalAlias(mx, mentionId)
|
||||||
: mx.getRoom(mentionId);
|
: mx.getRoom(mentionId);
|
||||||
const mentionName = mentionRoom?.name;
|
|
||||||
|
|
||||||
const mentionDisplayName =
|
|
||||||
mentionName && (mentionName.startsWith('#') ? mentionName : `#${mentionName}`);
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
{...props}
|
{...props}
|
||||||
|
@ -198,7 +195,7 @@ export const getReactCustomHtmlParser = (
|
||||||
onClick={params.handleMentionClick}
|
onClick={params.handleMentionClick}
|
||||||
style={{ cursor: 'pointer' }}
|
style={{ cursor: 'pointer' }}
|
||||||
>
|
>
|
||||||
{mentionDisplayName ?? mentionId}
|
{domToReact(children, opts)}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue