Skip to content

Commit 992f76d

Browse files
committed
mark c2c add check
1 parent 2802f74 commit 992f76d

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

internal/conversation_msg/conversation.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,23 @@ func (c *Conversation) typingStatusUpdate(callback open_im_sdk_callback.Base, re
299299

300300
}
301301

302-
func (c *Conversation) markC2CMessageAsRead(callback open_im_sdk_callback.Base, msgIDList sdk.MarkC2CMessageAsReadParams, sourceMsgIDList, userID, operationID string) {
302+
func (c *Conversation) markC2CMessageAsRead(callback open_im_sdk_callback.Base, msgIDList sdk.MarkC2CMessageAsReadParams, userID, operationID string) {
303303
var localMessage db.LocalChatLog
304+
var newMessageIDList []string
305+
messages, err := c.db.GetMultipleMessage(msgIDList)
306+
common.CheckDBErrCallback(callback, err, operationID)
307+
for _, v := range messages {
308+
if v.IsRead == false && v.ContentType < constant.NotificationBegin {
309+
newMessageIDList = append(newMessageIDList, v.ClientMsgID)
310+
}
311+
}
312+
if len(newMessageIDList) == 0 {
313+
common.CheckAnyErrCallback(callback, 201, errors.New("message has been marked read"), operationID)
314+
}
304315
conversationID := utils.GetConversationIDBySessionType(userID, constant.SingleChatType)
305316
s := sdk_struct.MsgStruct{}
306317
c.initBasicInfo(&s, constant.UserMsgType, constant.HasReadReceipt, operationID)
307-
s.Content = sourceMsgIDList
318+
s.Content = utils.StructToJsonString(newMessageIDList)
308319
options := make(map[string]bool, 5)
309320
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
310321
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
@@ -315,13 +326,13 @@ func (c *Conversation) markC2CMessageAsRead(callback open_im_sdk_callback.Base,
315326
s.SendTime = resp.SendTime
316327
s.Status = constant.MsgStatusFiltered
317328
msgStructToLocalChatLog(&localMessage, &s)
318-
err := c.db.InsertMessage(&localMessage)
329+
err = c.db.InsertMessage(&localMessage)
319330
if err != nil {
320331
log.Error(operationID, "inset into chat log err", localMessage, s, err.Error())
321332
}
322-
err2 := c.db.UpdateMessageHasRead(userID, msgIDList)
333+
err2 := c.db.UpdateMessageHasRead(userID, newMessageIDList)
323334
if err2 != nil {
324-
log.Error(operationID, "update message has read error", msgIDList, userID, err2.Error())
335+
log.Error(operationID, "update message has read error", newMessageIDList, userID, err2.Error())
325336
}
326337
_ = common.TriggerCmdUpdateConversation(common.UpdateConNode{ConID: conversationID, Action: constant.UpdateLatestMessageChange}, c.ch)
327338
//_ = common.TriggerCmdUpdateConversation(common.UpdateConNode{ConID: conversationID, Action: constant.ConChange, Args: []string{conversationID}}, c.ch)

internal/conversation_msg/open_im_sdk_conversation_msg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ func (c *Conversation) MarkC2CMessageAsRead(callback open_im_sdk_callback.Base,
917917
callback.OnSuccess(sdk_params_callback.MarkC2CMessageAsReadCallback)
918918
return
919919
}
920-
c.markC2CMessageAsRead(callback, unmarshalParams, msgIDList, userID, operationID)
920+
c.markC2CMessageAsRead(callback, unmarshalParams, userID, operationID)
921921
callback.OnSuccess(sdk_params_callback.MarkC2CMessageAsReadCallback)
922922
log.NewInfo(operationID, "MarkC2CMessageAsRead callback: ", sdk_params_callback.MarkC2CMessageAsReadCallback)
923923
}()

pkg/db/chat_log_model.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,23 @@ func (d *DataBase) GetSendingMessageList() (result []*LocalChatLog, err error) {
187187
func (d *DataBase) UpdateMessageHasRead(sendID string, msgIDList []string) error {
188188
d.mRWMutex.Lock()
189189
defer d.mRWMutex.Unlock()
190-
t := d.conn.Model(LocalChatLog{}).Debug().Where("send_id=? And is_read=? AND session_type=? AND client_msg_id in ?", sendID, constant.NotRead, constant.SingleChatType, msgIDList).Update("is_read", constant.HasRead)
190+
t := d.conn.Model(LocalChatLog{}).Debug().Where("send_id=? AND session_type=? AND client_msg_id in ?", sendID, constant.SingleChatType, msgIDList).Update("is_read", constant.HasRead)
191191
if t.RowsAffected == 0 {
192192
return utils.Wrap(errors.New("RowsAffected == 0"), "no update")
193193
}
194194
return utils.Wrap(t.Error, "UpdateMessageStatusBySourceID failed")
195195
}
196+
func (d *DataBase) GetMultipleMessage(conversationIDList []string) (result []*LocalChatLog, err error) {
197+
d.mRWMutex.Lock()
198+
defer d.mRWMutex.Unlock()
199+
var messageList []LocalChatLog
200+
err = utils.Wrap(d.conn.Where("client_msg_id IN ?", conversationIDList).Find(&messageList).Error, "GetMultipleMessage failed")
201+
for _, v := range messageList {
202+
v1 := v
203+
result = append(result, &v1)
204+
}
205+
return result, err
206+
}
196207

197208
func (d *DataBase) GetNormalMsgSeq() (uint32, error) {
198209
d.mRWMutex.Lock()

0 commit comments

Comments
 (0)