"use client"; import { useMemo } from "react"; import { cn } from "@/lib/utils"; import type { MessageReaction } from "@/types"; interface MessageReactionsProps { reactions: MessageReaction[]; currentUserId: string | undefined; /** Toggle the agent's reaction. If the agent already has this emoji → * caller should send empty to remove; otherwise swap/add. */ onToggle: (emoji: string) => void; } interface ReactionGroup { emoji: string; count: number; byCurrentUser: boolean; } function groupReactions( reactions: MessageReaction[], currentUserId: string | undefined, ): ReactionGroup[] { const map = new Map(); for (const r of reactions) { const existing = map.get(r.emoji); const isMine = r.actor_type === "agent" && !!currentUserId && r.actor_id === currentUserId; if (existing) { existing.count += 1; existing.byCurrentUser = existing.byCurrentUser || isMine; } else { map.set(r.emoji, { emoji: r.emoji, count: 1, byCurrentUser: isMine }); } } return [...map.values()]; } export function MessageReactions({ reactions, currentUserId, onToggle, }: MessageReactionsProps) { const groups = useMemo( () => groupReactions(reactions, currentUserId), [reactions, currentUserId], ); if (groups.length === 0) return null; return (
{groups.map((g) => ( ))}
); }