fix(chat): 撤回消息时回退未读角标,避免当成新消息

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-17 04:55:17 +08:00
parent c9d27b2b0c
commit d1155cbd64
4 changed files with 58 additions and 16 deletions

View File

@@ -175,6 +175,7 @@ export default function ChatShell({
const off = realtime.on<RtChatUnreadData>(RT_CHAT_UNREAD, (data) => {
if (!data?.room_id) return;
if (activeRoomId === data.room_id) return;
const delta = typeof data.delta === "number" ? data.delta : 1;
setRooms((prev) => {
const idx = prev.findIndex((r) => r.id === data.room_id);
if (idx < 0) {
@@ -183,9 +184,17 @@ export default function ChatShell({
}
const next = [...prev];
const cur = next[idx];
// 撤回回退:只改角标,预览由 chat:message_recalled 负责,避免覆盖「已撤回」
if (delta < 0) {
next[idx] = {
...cur,
unread_count: Math.max(0, (cur.unread_count || 0) + delta),
};
return next;
}
next[idx] = {
...cur,
unread_count: (cur.unread_count || 0) + (data.delta || 1),
unread_count: (cur.unread_count || 0) + delta,
last_message_id: data.message_id,
last_message: {
id: data.message_id,