mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
dcbf44aedb
Chat tagging: - Any @user is a visible tag in chat bubbles (the .mention-tag CSS never existed, so highlighting was invisible); self/alias mentions get a gold emphasis. Fixes cross-room tags not being highlighted. Mentions window: - Redesigned: unread count in the header, restyled filter chips + a refresh button, CSS-driven list/date-groups, adaptive height (compact when few, capped + scroll when many), polished empty state. - Rows: framed avatar (friends-list head crop so the face is never clipped), per-row unread dot, type marker, icon action buttons (goto / remove). - Re-requests from the server each time it opens. Autocomplete: - Never suggests the viewer themselves; suggests room users + online friends + aliases. Notifications: - Mention toast removed; mentions flow through the client's standard notification stream via a dedicated mention bubble (avatar + actions) in the default position. EVERY received mention surfaces (independent of the generic info-feed toggle, gated only by mentions_ui.enabled). Refactor (behaviour-preserving): - Centralised @-token classification in api/mentions/mentionTokens. - Moved mentionsFormat -> api/mentions, useMentionActions -> hooks/mentions. - Extracted ChatInputView @-autocomplete into a tested useChatMentions hook + pure helper; removed the dead duplicate useMentionAutocomplete.
113 lines
3.5 KiB
TypeScript
113 lines
3.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { MENTION_ROOM_ALIASES } from '../../../../api/mentions/mentionTokens';
|
|
import { highlightMentions } from './highlightMentions';
|
|
|
|
// A generic @user tag, and a self/alias mention (strong).
|
|
const TAG = (s: string) => `<span class="mention-tag">${ s }</span>`;
|
|
const SELF = (s: string) => `<span class="mention-tag mention-tag--self">${ s }</span>`;
|
|
|
|
describe('highlightMentions', () =>
|
|
{
|
|
it('marks the own-nick token as a self mention', () =>
|
|
{
|
|
const out = highlightMentions('hello @Bob how are you', 'Bob');
|
|
|
|
expect(out).toBe(`hello ${ SELF('@Bob') } how are you`);
|
|
});
|
|
|
|
it('marks a room-broadcast alias token as a self mention', () =>
|
|
{
|
|
const out = highlightMentions('@all party time', 'Bob');
|
|
|
|
expect(out).toBe(`${ SELF('@all') } party time`);
|
|
});
|
|
|
|
it('marks every configured room alias as a self mention', () =>
|
|
{
|
|
for(const alias of MENTION_ROOM_ALIASES)
|
|
{
|
|
const out = highlightMentions(`hey @${ alias }!`, 'Bob');
|
|
|
|
expect(out).toBe(`hey ${ SELF(`@${ alias }!`) }`);
|
|
}
|
|
});
|
|
|
|
it('tags other users (not me, not an alias) as generic mentions', () =>
|
|
{
|
|
const out = highlightMentions('hi @Charlie and @Dave', 'Bob');
|
|
|
|
expect(out).toBe(`hi ${ TAG('@Charlie') } and ${ TAG('@Dave') }`);
|
|
});
|
|
|
|
it('tags a cross-room user even when own username is empty', () =>
|
|
{
|
|
const out = highlightMentions('hi @Charlie', '');
|
|
|
|
expect(out).toBe(`hi ${ TAG('@Charlie') }`);
|
|
});
|
|
|
|
it('leaves non-mention text untouched', () =>
|
|
{
|
|
const text = 'just a normal sentence with no at signs';
|
|
|
|
expect(highlightMentions(text, 'Bob')).toBe(text);
|
|
});
|
|
|
|
it('keeps trailing punctuation inside the span (mirrors server stripping)', () =>
|
|
{
|
|
const out = highlightMentions('watch out @Bob! seriously', 'Bob');
|
|
|
|
expect(out).toBe(`watch out ${ SELF('@Bob!') } seriously`);
|
|
});
|
|
|
|
it('matches case-insensitively but preserves the original casing', () =>
|
|
{
|
|
const out = highlightMentions('yo @bOb whatup', 'BOB');
|
|
|
|
expect(out).toBe(`yo ${ SELF('@bOb') } whatup`);
|
|
});
|
|
|
|
it('preserves the original spacing verbatim', () =>
|
|
{
|
|
const out = highlightMentions('a @Bob\tb', 'Bob');
|
|
|
|
expect(out).toBe(`a ${ SELF('@Bob') }\tb`);
|
|
});
|
|
|
|
it('does not tag inside HTML tags produced by the formatter', () =>
|
|
{
|
|
const out = highlightMentions('<strong>hi @Bob</strong>', 'Bob');
|
|
|
|
expect(out).toBe(`<strong>hi ${ SELF('@Bob') }</strong>`);
|
|
});
|
|
|
|
it('leaves font-colour spans and line breaks intact', () =>
|
|
{
|
|
const html = '<span style="color:red">hi @Bob</span><br />bye';
|
|
const out = highlightMentions(html, 'Bob');
|
|
|
|
expect(out).toBe(`<span style="color:red">hi ${ SELF('@Bob') }</span><br />bye`);
|
|
});
|
|
|
|
it('handles a self mention and a generic tag in one message', () =>
|
|
{
|
|
const out = highlightMentions('@Bob and @Charlie listen', 'Bob');
|
|
|
|
expect(out).toBe(`${ SELF('@Bob') } and ${ TAG('@Charlie') } listen`);
|
|
});
|
|
|
|
it('ignores a bare @ with no nick', () =>
|
|
{
|
|
const text = 'email me @ home';
|
|
|
|
expect(highlightMentions(text, 'Bob')).toBe(text);
|
|
});
|
|
|
|
it('returns input verbatim when there is no @ at all (fast path)', () =>
|
|
{
|
|
const text = 'plain message';
|
|
|
|
expect(highlightMentions(text, 'Bob')).toBe(text);
|
|
});
|
|
});
|