mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-05 08:12:22 -08:00
fix: room pings regression on dev
This commit is contained in:
1 parent
5272ca8c97
commit
f77906907e
3 files changed
+25
-5
No files matched your search
@@ -20,9 +20,9 @@ import { useAtomValue } from 'jotai';
|
||||
import { nicknamesAtom } from '$state/nicknames';
|
||||
import {
|
||||
createMentionElement,
|
||||
mentionNameForUserAutocomplete,
|
||||
moveCursor,
|
||||
replaceWithElement,
|
||||
resolveUserMentionName,
|
||||
} from '$components/editor/utils';
|
||||
import { getMxIdServer } from '$utils/mxIdHelper';
|
||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||
@@ -115,11 +115,13 @@ export function UserMentionAutocomplete({
|
||||
else resetSearch();
|
||||
}, [query.text, search, resetSearch]);
|
||||
|
||||
const handleAutocomplete: MentionAutoCompleteHandler = (uId) => {
|
||||
const handleAutocomplete: MentionAutoCompleteHandler = (id, displayName) => {
|
||||
const isRoomPing = displayName === '@room';
|
||||
const isCurrentRoom = roomId === id || room.getCanonicalAlias() === id || roomAliasOrId === id;
|
||||
const mentionEl = createMentionElement(
|
||||
uId,
|
||||
resolveUserMentionName(uId, { room, nicknames }),
|
||||
mx.getUserId() === uId || roomAliasOrId === uId
|
||||
id,
|
||||
mentionNameForUserAutocomplete(id, displayName, { room, nicknames }),
|
||||
isRoomPing ? isCurrentRoom : mx.getUserId() === id || isCurrentRoom
|
||||
);
|
||||
replaceWithElement(editor, query.range, mentionEl);
|
||||
moveCursor(editor, true);
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Room } from '$types/matrix-sdk';
|
||||
import {
|
||||
formatMentionElementDisplayName,
|
||||
formatUserMentionDisplayName,
|
||||
mentionNameForUserAutocomplete,
|
||||
resolveUserMentionName,
|
||||
} from './utils';
|
||||
import { BlockType } from './types';
|
||||
@@ -34,4 +35,11 @@ describe('mention resolve', () => {
|
||||
it('formatUserMentionDisplayName is idempotent for names that already include @', () => {
|
||||
expect(formatUserMentionDisplayName('@Alice')).toBe('@Alice');
|
||||
});
|
||||
|
||||
it('mentionNameForUserAutocomplete keeps @room for room pings', () => {
|
||||
expect(mentionNameForUserAutocomplete('!room:example.org', '@room')).toBe('@room');
|
||||
expect(mentionNameForUserAutocomplete('!room:example.org', '@room')).not.toBe(
|
||||
'@!room:example.org'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -31,6 +31,16 @@ export const resolveUserMentionName = (userId: string, options?: MentionResolveO
|
||||
return formatUserMentionDisplayName(base);
|
||||
};
|
||||
|
||||
/** {@link UserMentionAutocomplete} passes a display label, @room must stay literal, not resolved as a user. */
|
||||
export const mentionNameForUserAutocomplete = (
|
||||
id: string,
|
||||
displayName: string,
|
||||
options?: MentionResolveOptions
|
||||
): string => {
|
||||
if (displayName === '@room') return '@room';
|
||||
return resolveUserMentionName(id, options);
|
||||
};
|
||||
|
||||
/** Same #-prefix rule as {@link RoomMentionAutocomplete}. */
|
||||
export const formatRoomMentionDisplayName = (name: string): string => {
|
||||
if (name === '@room') return '@room';
|
||||
|
||||
Reference in new issue
Block a user