|
@@ -4,6 +4,11 @@ import type { WorkspaceAgent, WorkspaceConversation } from '../shared/workspace.
|
|
|
import { emptyUnread, type UnreadSnapshot, type UnreadConversation } from '../shared/unread.js'
|
|
import { emptyUnread, type UnreadSnapshot, type UnreadConversation } from '../shared/unread.js'
|
|
|
import { notificationPlainText } from './notificationText.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,
|
|
export function unreadSnapshot(workspace:WorkspaceStore, cache:ChatCacheStore, owner:string,
|
|
|
allowed:(node:string,profile:string)=>boolean = ()=>true):UnreadSnapshot {
|
|
allowed:(node:string,profile:string)=>boolean = ()=>true):UnreadSnapshot {
|
|
|
const result=emptyUnread()
|
|
const result=emptyUnread()
|
|
@@ -24,7 +29,7 @@ export function unreadSnapshot(workspace:WorkspaceStore, cache:ChatCacheStore, o
|
|
|
if(!messages.length)continue
|
|
if(!messages.length)continue
|
|
|
const last=messages.at(-1)!
|
|
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,
|
|
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))
|
|
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
|
|
for(const row of result.conversations)result[row.mode]+=row.count
|