Procházet zdrojové kódy

兼容聊天日期并避免流式增量反复扫描未读历史

Samien před 1 měsícem
rodič
revize
283f8d746f
2 změnil soubory, kde provedl 9 přidání a 3 odebrání
  1. 6 1
      src/server/unreadCenter.ts
  2. 3 2
      src/server/workspaceStore.ts

+ 6 - 1
src/server/unreadCenter.ts

@@ -4,6 +4,11 @@ import type { WorkspaceAgent, WorkspaceConversation } from '../shared/workspace.
 import { emptyUnread, type UnreadSnapshot, type UnreadConversation } from '../shared/unread.js'
 import { notificationPlainText } from './notificationText.js'
 
+function messageTime(value:unknown):number {
+ const numeric=Number(value);if(Number.isFinite(numeric))return numeric>0&&numeric<100_000_000_000?numeric*1000:numeric
+ const parsed=typeof value==='string'?Date.parse(value):NaN;return Number.isFinite(parsed)?parsed:0
+}
+
 export function unreadSnapshot(workspace:WorkspaceStore, cache:ChatCacheStore, owner:string,
   allowed:(node:string,profile:string)=>boolean = ()=>true):UnreadSnapshot {
   const result=emptyUnread()
@@ -24,7 +29,7 @@ export function unreadSnapshot(workspace:WorkspaceStore, cache:ChatCacheStore, o
     if(!messages.length)continue
     const last=messages.at(-1)!
     result.conversations.push({mode:'chat',id:row.session_id,profile:row.profile,name:summary.title || summary.name || '未命名聊天',preview:notificationPlainText(typeof last.content==='string'?last.content:'',{maximum:160,fallback:'附件'}),count:messages.length,
-      updatedAt:Number(last.timestamp ?? last.created_at ?? last.createdAt ?? 0),messages:messages.map(m=>({id:m.id,seq:m.seq}))})
+      updatedAt:messageTime(last.timestamp ?? last.created_at ?? last.createdAt ?? summary.updated_at ?? 0),messages:messages.map(m=>({id:m.id,seq:m.seq}))})
   }
   result.conversations.sort((a,b)=>b.updatedAt-a.updatedAt || a.id.localeCompare(b.id))
   for(const row of result.conversations)result[row.mode]+=row.count

+ 3 - 2
src/server/workspaceStore.ts

@@ -1127,7 +1127,8 @@ export class WorkspaceStore {
       if (previous?.visible === false && message.visible !== false) message.seq = 0
       if (!message.seq) message.seq = c.lastSeq + 1
       c.lastSeq = Math.max(c.lastSeq, message.seq)
-      if (isWorkspaceChatReply(message) && !previous?.chatUnreadVersion) {
+      const eligible=isWorkspaceChatReply(message),previousEligible=!!previous&&isWorkspaceChatReply(previous)
+      if (eligible && !previous?.chatUnreadVersion) {
         c.unreadVersion=(c.unreadVersion ?? 0)+1
         message.chatUnreadVersion=c.unreadVersion
         if(task)task.unreadVersion=c.unreadVersion
@@ -1156,7 +1157,7 @@ export class WorkspaceStore {
         }
         this.put(owner, 'conversation-task', task.id, task)
       }
-      this.refreshChatUnread(owner,c)
+      if(eligible!==previousEligible || eligible&&!previous?.chatUnreadVersion)this.refreshChatUnread(owner,c)
       if(task && updateSummary)this.event(owner,'task.changed',this.requireTask(owner,c.id,task.id),c.id)
       if (patch) this.event(owner, 'message.patch', patch, c.id, { type: 'message.changed', data: message })
       else this.event(owner, 'message.changed', message, c.id)