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.
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
// Date/time helpers for the mentions box. Kept framework-free and pure so they
|
|
// are unit-testable. Timestamps are unix SECONDS (as carried on the wire).
|
|
|
|
export type MentionDateGroup = 'today' | 'yesterday' | 'older';
|
|
|
|
const DAY_MS = 86_400_000;
|
|
|
|
const startOfDay = (d: Date): number => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
|
|
const pad = (n: number): string => (n < 10 ? `0${ n }` : `${ n }`);
|
|
|
|
/**
|
|
* Bucket a mention timestamp into today / yesterday / older relative to `now`.
|
|
*/
|
|
export const getMentionDateGroup = (timestampSeconds: number, now: Date = new Date()): MentionDateGroup =>
|
|
{
|
|
if(!timestampSeconds || timestampSeconds <= 0) return 'older';
|
|
|
|
const ts = timestampSeconds * 1000;
|
|
const todayStart = startOfDay(now);
|
|
|
|
if(ts >= todayStart) return 'today';
|
|
if(ts >= (todayStart - DAY_MS)) return 'yesterday';
|
|
|
|
return 'older';
|
|
};
|
|
|
|
/**
|
|
* Compact per-row time label: HH:MM for today/yesterday (the section header
|
|
* disambiguates the day), DD-MM for older entries. Empty string when unknown.
|
|
*/
|
|
export const formatMentionTime = (timestampSeconds: number, now: Date = new Date()): string =>
|
|
{
|
|
if(!timestampSeconds || timestampSeconds <= 0) return '';
|
|
|
|
const d = new Date(timestampSeconds * 1000);
|
|
|
|
if(getMentionDateGroup(timestampSeconds, now) === 'older') return `${ pad(d.getDate()) }-${ pad(d.getMonth() + 1) }`;
|
|
|
|
return `${ pad(d.getHours()) }:${ pad(d.getMinutes()) }`;
|
|
};
|