@@ -35,16 +35,20 @@ export const useChatMessages = ({
3535 }
3636
3737 const logMessagePhase = ( phase , details = { } ) => {
38- if ( ! isDesktopRenderer ( ) ) return
39- try {
40- window . wechatDesktop ?. logDebug ?. ( 'chat-messages' , phase , details )
41- } catch { }
42- console . info ( `[chat-messages] ${ phase } ` , {
38+ const payload = {
4339 account : String ( selectedAccount . value || '' ) . trim ( ) ,
4440 selectedUsername : String ( selectedContact . value ?. username || '' ) . trim ( ) ,
4541 activeMessagesFor : String ( activeMessagesFor . value || '' ) . trim ( ) ,
4642 ...details
47- } )
43+ }
44+
45+ if ( isDesktopRenderer ( ) ) {
46+ try {
47+ window . wechatDesktop ?. logDebug ?. ( 'chat-messages' , phase , payload )
48+ } catch { }
49+ }
50+
51+ console . info ( `[chat-messages] ${ phase } ` , payload )
4852 }
4953
5054 const summarizeRenderTypes = ( list ) => {
@@ -556,28 +560,38 @@ export const useChatMessages = ({
556560 params . render_types = messageTypeFilter . value
557561 }
558562
559- const response = await api . listChatMessages ( params )
560- if ( selectedContact . value ?. username !== username ) return
561-
562- const latest = ( response ?. messages || [ ] ) . map ( normalizeMessage )
563- const seenIds = new Set ( existing . map ( ( message ) => String ( message ?. id || '' ) ) )
564- const newOnes = [ ]
565- for ( const message of latest ) {
566- const id = String ( message ?. id || '' )
567- if ( ! id || seenIds . has ( id ) ) continue
568- seenIds . add ( id )
569- newOnes . push ( message )
570- }
571- if ( ! newOnes . length ) return
563+ try {
564+ const response = await api . listChatMessages ( params )
565+ if ( selectedContact . value ?. username !== username ) return
566+
567+ const rawMessages = response ?. messages || [ ]
568+ const latest = rawMessages . map ( normalizeMessage )
569+
570+ const seenIds = new Set ( existing . map ( ( message ) => String ( message ?. id || '' ) ) )
571+ const newOnes = [ ]
572+ for ( const message of latest ) {
573+ const id = String ( message ?. id || '' )
574+ if ( ! id || seenIds . has ( id ) ) continue
575+ seenIds . add ( id )
576+ newOnes . push ( message )
577+ }
578+ if ( ! newOnes . length ) return
572579
573- allMessages . value = { ...allMessages . value , [ username ] : [ ...existing , ...newOnes ] }
580+ allMessages . value = { ...allMessages . value , [ username ] : [ ...existing , ...newOnes ] }
574581
575- await nextTick ( )
576- const nextContainer = messageContainerRef . value
577- if ( nextContainer && atBottom ) {
578- nextContainer . scrollTop = nextContainer . scrollHeight
582+ await nextTick ( )
583+ const nextContainer = messageContainerRef . value
584+ if ( nextContainer && atBottom ) {
585+ nextContainer . scrollTop = nextContainer . scrollHeight
586+ }
587+ updateJumpToBottomState ( )
588+ } catch ( error ) {
589+ console . error ( '[chat-messages] refreshRealtimeIncremental:error' , {
590+ account : String ( selectedAccount . value || '' ) . trim ( ) ,
591+ username : String ( username || '' ) . trim ( ) ,
592+ error
593+ } )
579594 }
580- updateJumpToBottomState ( )
581595 }
582596
583597 let realtimeRefreshFuture = null
0 commit comments