fix(room): handle reaction updates in onRoomMessage WS handler
Root cause: publish_reaction_event sends a RoomMessageEvent (not reaction_added) with reactions field set. The onRoomMessage handler previously returned prev immediately when a duplicate ID was found, skipping the reaction update entirely. Fix: - Add reactions field to RoomMessagePayload so TypeScript knows it's there - When a duplicate message ID is found AND payload carries reactions, update the existing message's reactions field instead of ignoring - ReactionItem and ReactionGroup have identical shapes, so assignment works
This commit is contained in:
parent
0cbf6d6aa1
commit
047782e585
@ -424,8 +424,20 @@ export function RoomProvider({
|
|||||||
// Use ref to get current activeRoomId to avoid stale closure
|
// Use ref to get current activeRoomId to avoid stale closure
|
||||||
if (payload.room_id === activeRoomIdRef.current) {
|
if (payload.room_id === activeRoomIdRef.current) {
|
||||||
setMessages((prev) => {
|
setMessages((prev) => {
|
||||||
// Deduplicate by both ID (for normal) and seq (for optimistic replacement)
|
// Check if this is a reaction-update event (same ID, different reactions).
|
||||||
if (prev.some((m) => m.id === payload.id)) {
|
// publish_reaction_event sends RoomMessageEvent with reactions field set.
|
||||||
|
const existingIdx = prev.findIndex((m) => m.id === payload.id);
|
||||||
|
if (existingIdx !== -1) {
|
||||||
|
// Message already exists — update reactions if provided.
|
||||||
|
// Reaction events have empty content/sender_type.
|
||||||
|
if (payload.reactions !== undefined) {
|
||||||
|
const updated = [...prev];
|
||||||
|
updated[existingIdx] = { ...updated[existingIdx], reactions: payload.reactions };
|
||||||
|
const msg = updated[existingIdx];
|
||||||
|
saveMessage(msg).catch(() => {});
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
// Duplicate of a real message — ignore
|
||||||
return prev;
|
return prev;
|
||||||
}
|
}
|
||||||
// Also check if there's an optimistic message with the same seq that should be replaced
|
// Also check if there's an optimistic message with the same seq that should be replaced
|
||||||
|
|||||||
@ -166,6 +166,8 @@ export interface RoomMessagePayload {
|
|||||||
send_at: string;
|
send_at: string;
|
||||||
seq: number;
|
seq: number;
|
||||||
display_name?: string;
|
display_name?: string;
|
||||||
|
/** Present when this event carries reaction updates for the message */
|
||||||
|
reactions?: ReactionItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProjectEventPayload {
|
export interface ProjectEventPayload {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user