fix(chat): 撤回消息时回退未读角标,避免当成新消息
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -96,6 +96,7 @@ export interface RtChatRecalledData {
|
||||
}
|
||||
|
||||
// 未读增量(推送给未在房内订阅的成员,用于 Header / 会话列表角标)
|
||||
// delta 通常为 +1(新消息);撤回未读消息时为 -1,此时不含 preview,不得当新消息处理
|
||||
export interface RtChatUnreadData {
|
||||
room_id: number;
|
||||
message_id: number;
|
||||
|
||||
Reference in New Issue
Block a user