88 "math"
99 "sync"
1010
11+ "sort"
12+ "time"
13+
1114 "github.com/openimsdk/openim-sdk-core/v3/internal/group"
1215 "github.com/openimsdk/openim-sdk-core/v3/internal/interaction"
1316 "github.com/openimsdk/openim-sdk-core/v3/internal/relation"
@@ -30,9 +33,6 @@ import (
3033 "github.com/openimsdk/tools/log"
3134 "github.com/openimsdk/tools/utils/datautil"
3235
33- "sort"
34- "time"
35-
3636 "github.com/openimsdk/openim-sdk-core/v3/pkg/utils"
3737 "github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
3838)
@@ -225,6 +225,7 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
225225
226226 for conversationID , msgs := range allMsg {
227227 conversationIDs = append (conversationIDs , conversationID )
228+
228229 log .ZDebug (ctx , "parse message in one conversation" , "conversationID" , conversationID , "message length" , len (msgs .Msgs ), "data" , msgs .Msgs )
229230
230231 clientIDs := make ([]string , 0 , len (msgs .Msgs ))
@@ -436,27 +437,30 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
436437 }
437438 }
438439
439- if err := c .db .BatchUpdateConversationList (ctx , append (mapConversationToList (conversationChangedSet ), mapConversationToList (phConversationChangedSet )... )); err != nil {
440+ if err := c .db .BatchUpdateConversationList (ctx , append (datautil . Values (conversationChangedSet ), datautil . Values (phConversationChangedSet )... )); err != nil {
440441 log .ZError (ctx , "insert changed conversation err :" , err )
441442 }
442443 //New conversation storage
443444
444- if err := c .db .BatchInsertConversationList (ctx , mapConversationToList (phNewConversationSet )); err != nil {
445+ if err := c .db .BatchInsertConversationList (ctx , datautil . Values (phNewConversationSet )); err != nil {
445446 log .ZError (ctx , "insert new conversation err:" , err )
446447 }
447448 log .ZDebug (ctx , "before trigger msg" , "cost time" , time .Since (b ).Seconds (), "len" , len (allMsg ))
448449
449- c .newMessage (ctx , newMessages , conversationChangedSet , newConversationSet , onlineMap )
450-
450+ if c .batchMsgListener () != nil {
451+ c .batchNewMessages (ctx , newMessages , conversationChangedSet , newConversationSet , onlineMap )
452+ } else {
453+ c .newMessage (ctx , newMessages , conversationChangedSet , newConversationSet , onlineMap )
454+ }
451455 if len (newConversationSet ) > 0 {
452- c .doUpdateConversation (common. Cmd2Value { Value : common. UpdateConNode { Action : constant . NewConDirect , Args : utils .StructToJsonString (mapConversationToList (newConversationSet ))}} )
456+ c .ConversationListener (). OnNewConversation ( utils .StructToJsonString (datautil . Values (newConversationSet )))
453457 }
454458 if len (conversationChangedSet ) > 0 {
455- c .doUpdateConversation (common. Cmd2Value { Value : common. UpdateConNode { Action : constant . ConChangeDirect , Args : utils .StructToJsonString (mapConversationToList (conversationChangedSet ))}} )
459+ c .ConversationListener (). OnConversationChanged ( utils .StructToJsonString (datautil . Values (conversationChangedSet )))
456460 }
457461
458462 if isTriggerUnReadCount {
459- c . doUpdateConversation (common. Cmd2Value { Value : common. UpdateConNode { Action : constant . TotalUnreadMessageChanged , Args : "" }} )
463+ _ = c . OnTotalUnreadMessageCountChanged ( ctx )
460464 }
461465
462466 for _ , msgs := range allMsg {
@@ -474,6 +478,18 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
474478 log .ZDebug (ctx , "insert msg" , "duration" , fmt .Sprintf ("%dms" , time .Since (b )), "len" , len (allMsg ))
475479}
476480
481+ func (c * Conversation ) OnTotalUnreadMessageCountChanged (ctx context.Context ) error {
482+ log .ZInfo (ctx , "OnTotalUnreadMessageCountChanged" , "caller" , common .GetCaller (2 ))
483+ totalUnreadCount , err := c .db .GetTotalUnreadMsgCountDB (ctx )
484+ if err != nil {
485+ log .ZWarn (ctx , "TotalUnreadMessageChanged GetTotalUnreadMsgCountDB err" , err )
486+ } else {
487+ log .ZDebug (ctx , "TotalUnreadMessageChanged" , "totalUnreadCount" , totalUnreadCount )
488+ c .ConversationListener ().OnTotalUnreadMessageCountChanged (totalUnreadCount )
489+ }
490+ return nil
491+ }
492+
477493func (c * Conversation ) doMsgSyncByReinstalled (c2v common.Cmd2Value ) {
478494 allMsg := c2v .Value .(sdk_struct.CmdMsgSyncInReinstall ).Msgs
479495 ctx := c2v .Ctx
0 commit comments