Skip to content

Commit afebca3

Browse files
committed
fix: directly deduplicate the messages pulled from the server. (#874)
Signed-off-by: Gordon <[email protected]>
1 parent 5500f4d commit afebca3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/conversation_msg/message_check.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,20 @@ func (c *Conversation) pullMessageIntoTable(ctx context.Context, pullMsgData map
432432
if err != nil {
433433
log.ZWarn(ctx, "Failed to get messages by ClientMsgIDs", err)
434434
}
435+
processedMsgIDs := make(map[string]*model_struct.LocalChatLog, len(msgs.Msgs))
435436
localMessagesMap := datautil.SliceToMap(localMessages, func(msg *model_struct.LocalChatLog) string { return msg.ClientMsgID })
436437
for _, v := range msgs.Msgs {
437438
log.ZDebug(ctx, "msg detail", "msg", v, "conversationID", conversationID)
438439
//When the message has been marked and deleted by the cloud, it is directly inserted locally
439440
//without any conversation and message update.
440441
msg := MsgDataToLocalChatLog(v)
442+
if existingMessage, ok := processedMsgIDs[v.ClientMsgID]; ok {
443+
c.handleExceptionMessages(ctx, existingMessage, msg)
444+
v.Status = msg.Status
445+
exceptionMsg = append(exceptionMsg, msg)
446+
insertMessage = append(insertMessage, msg)
447+
continue
448+
}
441449
if v.Status == constant.MsgStatusHasDeleted {
442450
c.handleExceptionMessages(ctx, nil, msg)
443451
v.ClientMsgID = msg.ClientMsgID
@@ -480,7 +488,7 @@ func (c *Conversation) pullMessageIntoTable(ctx context.Context, pullMsgData map
480488
insertMessage = append(insertMessage, msg)
481489
}
482490
}
483-
491+
processedMsgIDs[msg.ClientMsgID] = msg
484492
}
485493
timeNow := time.Now()
486494
insertMsg[conversationID] = append(insertMessage, c.faceURLAndNicknameHandle(ctx, selfInsertMessage, othersInsertMessage, conversationID)...)

0 commit comments

Comments
 (0)