@@ -207,10 +207,8 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
207
207
var isTriggerUnReadCount bool
208
208
insertMsg := make (map [string ][]* model_struct.LocalChatLog , 10 )
209
209
updateMsg := make (map [string ][]* model_struct.LocalChatLog , 10 )
210
- var exceptionMsg []* model_struct.LocalErrChatLog
211
- //var unreadMessages []*model_struct.LocalConversationUnreadMessage
210
+ var exceptionMsg []* model_struct.LocalChatLog
212
211
var newMessages sdk_struct.NewMsgList
213
- // var reactionMsgModifierList, reactionMsgDeleterList sdk_struct.NewMsgList
214
212
215
213
var isUnreadCount , isConversationUpdate , isHistory , isNotPrivate , isSenderConversationUpdate bool
216
214
@@ -253,7 +251,10 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
253
251
254
252
//When the message has been marked and deleted by the cloud, it is directly inserted locally without any conversation and message update.
255
253
if msg .Status == constant .MsgStatusHasDeleted {
256
- insertMessage = append (insertMessage , MsgStructToLocalChatLog (msg ))
254
+ dbMessage := MsgStructToLocalChatLog (msg )
255
+ c .handleExceptionMessages (ctx , nil , dbMessage )
256
+ exceptionMsg = append (exceptionMsg , dbMessage )
257
+ insertMessage = append (insertMessage , dbMessage )
257
258
continue
258
259
}
259
260
@@ -269,10 +270,6 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
269
270
if ! isNotPrivate {
270
271
msg .AttachedInfoElem .IsPrivateChat = true
271
272
}
272
- if msg .ClientMsgID == "" {
273
- exceptionMsg = append (exceptionMsg , c .msgStructToLocalErrChatLog (msg ))
274
- continue
275
- }
276
273
if conversationID == "" {
277
274
log .ZError (ctx , "conversationID is empty" , errors .New ("conversationID is empty" ), "msg" , msg )
278
275
continue
@@ -285,16 +282,19 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
285
282
log .ZDebug (ctx , "decode message" , "msg" , msg )
286
283
if v .SendID == c .loginUserID { //seq
287
284
// Messages sent by myself //if sent through this terminal
288
- m , err := c .db .GetMessage (ctx , conversationID , msg .ClientMsgID )
285
+ existingMsg , err := c .db .GetMessage (ctx , conversationID , msg .ClientMsgID )
289
286
if err == nil {
290
287
log .ZInfo (ctx , "have message" , "msg" , msg )
291
- if m .Seq == 0 {
288
+ if existingMsg .Seq == 0 {
292
289
if ! isConversationUpdate {
293
290
msg .Status = constant .MsgStatusFiltered
294
291
}
295
292
updateMessage = append (updateMessage , MsgStructToLocalChatLog (msg ))
296
293
} else {
297
- exceptionMsg = append (exceptionMsg , c .msgStructToLocalErrChatLog (msg ))
294
+ dbMessage := MsgStructToLocalChatLog (msg )
295
+ c .handleExceptionMessages (ctx , existingMsg , dbMessage )
296
+ insertMessage = append (insertMessage , dbMessage )
297
+ exceptionMsg = append (exceptionMsg , dbMessage )
298
298
}
299
299
} else {
300
300
log .ZInfo (ctx , "sync message" , "msg" , msg )
@@ -322,7 +322,7 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
322
322
}
323
323
}
324
324
} else { //Sent by others
325
- if _ , err := c .db .GetMessage (ctx , conversationID , msg .ClientMsgID ); err != nil { //Deduplication operation
325
+ if existingMsg , err := c .db .GetMessage (ctx , conversationID , msg .ClientMsgID ); err != nil {
326
326
lc := model_struct.LocalConversation {
327
327
ConversationType : v .SessionType ,
328
328
LatestMsg : utils .StructToJsonString (msg ),
@@ -356,11 +356,10 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
356
356
}
357
357
358
358
} else {
359
- exceptionMsg = append (exceptionMsg , c .msgStructToLocalErrChatLog (msg ))
360
- log .ZWarn (ctx , "Deduplication operation " , nil , "msg" , * c .msgStructToLocalErrChatLog (msg ))
361
- msg .Status = constant .MsgStatusFiltered
362
- msg .ClientMsgID = msg .ClientMsgID + utils .Int64ToString (msg .Seq )
363
- othersInsertMessage = append (othersInsertMessage , MsgStructToLocalChatLog (msg ))
359
+ dbMessage := MsgStructToLocalChatLog (msg )
360
+ c .handleExceptionMessages (ctx , existingMsg , dbMessage )
361
+ insertMessage = append (insertMessage , dbMessage )
362
+ exceptionMsg = append (exceptionMsg , dbMessage )
364
363
}
365
364
}
366
365
}
@@ -458,6 +457,10 @@ func (c *Conversation) doMsgNew(c2v common.Cmd2Value) {
458
457
}
459
458
}
460
459
}
460
+ //Exception message storage
461
+ for _ , v := range exceptionMsg {
462
+ log .ZWarn (ctx , "exceptionMsg show: " , nil , "msg" , * v )
463
+ }
461
464
462
465
log .ZDebug (ctx , "insert msg" , "duration" , fmt .Sprintf ("%dms" , time .Since (b )), "len" , len (allMsg ))
463
466
}
@@ -471,6 +474,7 @@ func (c *Conversation) doMsgSyncByReinstalled(c2v common.Cmd2Value) {
471
474
472
475
insertMsg := make (map [string ][]* model_struct.LocalChatLog , 10 )
473
476
conversationList := make ([]* model_struct.LocalConversation , 0 )
477
+ var exceptionMsg []* model_struct.LocalChatLog
474
478
475
479
log .ZDebug (ctx , "message come here conversation ch in reinstalled" , "conversation length" , msgLen )
476
480
b := time .Now ()
@@ -497,7 +501,10 @@ func (c *Conversation) doMsgSyncByReinstalled(c2v common.Cmd2Value) {
497
501
498
502
//When the message has been marked and deleted by the cloud, it is directly inserted locally without any conversation and message update.
499
503
if msg .Status == constant .MsgStatusHasDeleted {
500
- insertMessage = append (insertMessage , MsgStructToLocalChatLog (msg ))
504
+ dbMessage := MsgStructToLocalChatLog (msg )
505
+ c .handleExceptionMessages (ctx , nil , dbMessage )
506
+ exceptionMsg = append (exceptionMsg , dbMessage )
507
+ insertMessage = append (insertMessage , dbMessage )
501
508
continue
502
509
}
503
510
msg .Status = constant .MsgStatusSendSuccess
@@ -552,6 +559,10 @@ func (c *Conversation) doMsgSyncByReinstalled(c2v common.Cmd2Value) {
552
559
553
560
// log.ZDebug(ctx, "progress is", "msgLen", msgLen, "msgOffset", c.msgOffset, "total", total, "now progress is", (c.msgOffset*(100-InitSyncProgress))/total + InitSyncProgress)
554
561
c .ConversationListener ().OnSyncServerProgress ((c .msgOffset * (100 - InitSyncProgress ))/ total + InitSyncProgress )
562
+ //Exception message storage
563
+ for _ , v := range exceptionMsg {
564
+ log .ZWarn (ctx , "exceptionMsg show: " , nil , "msg" , * v )
565
+ }
555
566
}
556
567
557
568
func (c * Conversation ) addInitProgress (progress int ) {
@@ -613,15 +624,6 @@ func (c *Conversation) genConversationGroupAtType(lc *model_struct.LocalConversa
613
624
}
614
625
}
615
626
616
- func (c * Conversation ) msgStructToLocalErrChatLog (m * sdk_struct.MsgStruct ) * model_struct.LocalErrChatLog {
617
- var lc model_struct.LocalErrChatLog
618
- copier .Copy (& lc , m )
619
- if m .SessionType == constant .WriteGroupChatType || m .SessionType == constant .ReadGroupChatType {
620
- lc .RecvID = m .GroupID
621
- }
622
- return & lc
623
- }
624
-
625
627
func (c * Conversation ) batchUpdateMessageList (ctx context.Context , updateMsg map [string ][]* model_struct.LocalChatLog ) error {
626
628
if updateMsg == nil {
627
629
return nil
@@ -678,7 +680,7 @@ func (c *Conversation) batchInsertMessageList(ctx context.Context, insertMsg map
678
680
}
679
681
err := c .db .BatchInsertMessageList (ctx , conversationID , messages )
680
682
if err != nil {
681
- log .ZError (ctx , "insert GetMessage detail err:" , err , "conversationID" , conversationID , "messages" , messages )
683
+ log .ZError (ctx , "BatchInsertMessageList detail err:" , err , "conversationID" , conversationID , "messages" , messages )
682
684
for _ , v := range messages {
683
685
e := c .db .InsertMessage (ctx , conversationID , v )
684
686
if e != nil {
0 commit comments