Files
Nitro-V3/src/hooks/mentions/mentionToastsStore.ts
T
medievalshell 0df810c556 feat(mentions): @ autocomplete, blue @nick, avatar notification toast
- Chat input @ autocomplete: typing @ shows online users (room users +
  online friends + room aliases) with avatars; arrows/Tab/Enter to pick.
- Any valid @nick token is highlighted blue in chat bubbles (like @all),
  giving visual feedback that it is a recognised mention.
- Side notification toast on a received mention: sender avatar (from the
  new senderFigure wire field) + message + dismiss; dismiss marks it read
  so the toolbar unread badge updates. Auto-hides after 8s.
- IMentionEntry/parsers carry senderFigure end to end.
2026-06-04 01:18:26 +02:00

59 lines
1.5 KiB
TypeScript

import { IMentionEntry } from '../../api';
// Toast laterali per le menzioni appena ricevute (avatar + messaggio + dismiss).
// Separato da mentionsStore: i toast sono effimeri, le menzioni persistono nel pannello.
export interface MentionToast
{
mentionId: number;
senderId: number;
senderUsername: string;
senderFigure: string;
message: string;
roomName: string;
}
const MAX_TOASTS = 4;
let toasts: MentionToast[] = [];
const listeners = new Set<() => void>();
const emit = (): void =>
{
for(const listener of listeners) listener();
};
export const subscribeMentionToasts = (callback: () => void): (() => void) =>
{
listeners.add(callback);
return () => { listeners.delete(callback); };
};
export const getMentionToasts = (): ReadonlyArray<MentionToast> => toasts;
export const pushMentionToast = (entry: IMentionEntry): void =>
{
toasts = [
{
mentionId: entry.mentionId,
senderId: entry.senderId,
senderUsername: entry.senderUsername,
senderFigure: entry.senderFigure,
message: entry.message,
roomName: entry.roomName
},
...toasts.filter(toast => toast.mentionId !== entry.mentionId)
].slice(0, MAX_TOASTS);
emit();
};
export const dismissMentionToast = (mentionId: number): void =>
{
const next = toasts.filter(toast => toast.mentionId !== mentionId);
if(next.length === toasts.length) return;
toasts = next;
emit();
};