feat(desktop): expose reactions reveal-gate flag (ready)

This commit is contained in:
byGalax
2026-06-02 20:26:00 +02:00
parent 43a99a8d6d
commit 2372731504
+11 -1
View File
@@ -19,6 +19,10 @@ export interface UseMessageReactionsResult {
byMessage: Map<string, AggregatedReaction[]>; byMessage: Map<string, AggregatedReaction[]>;
toggle: (messageId: string, emoji: string) => Promise<void>; toggle: (messageId: string, emoji: string) => Promise<void>;
voteExclusive: (messageId: string, emoji: string, exclusiveEmojis: string[]) => Promise<void>; voteExclusive: (messageId: string, emoji: string, exclusiveEmojis: string[]) => Promise<void>;
// True once the reactions for the current message-id set have been fetched
// (or there are no messages). Drives MessageList's deferred reveal so the
// chat opens already showing reaction chips — no post-paint height jump.
ready: boolean;
} }
// Batch-fetches reactions for the given message ids + subscribes to the // Batch-fetches reactions for the given message ids + subscribes to the
@@ -29,10 +33,12 @@ export function useMessageReactions(
): UseMessageReactionsResult { ): UseMessageReactionsResult {
const idsKey = useMemo(() => messageIds.join(','), [messageIds]); const idsKey = useMemo(() => messageIds.join(','), [messageIds]);
const [rows, setRows] = useState<MessageReaction[]>([]); const [rows, setRows] = useState<MessageReaction[]>([]);
const [readyKey, setReadyKey] = useState<string | null>(null);
const refresh = useCallback(async () => { const refresh = useCallback(async () => {
if (messageIds.length === 0) { if (messageIds.length === 0) {
setRows([]); setRows([]);
setReadyKey(idsKey);
return; return;
} }
try { try {
@@ -40,6 +46,8 @@ export function useMessageReactions(
setRows(data); setRows(data);
} catch (err: unknown) { } catch (err: unknown) {
console.error('listReactionsForMessages failed', err); console.error('listReactionsForMessages failed', err);
} finally {
setReadyKey(idsKey);
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [idsKey]); }, [idsKey]);
@@ -129,5 +137,7 @@ export function useMessageReactions(
[byMessage, myId, refresh], [byMessage, myId, refresh],
); );
return { byMessage, toggle, voteExclusive }; const ready = readyKey === idsKey;
return { byMessage, toggle, voteExclusive, ready };
} }