Skip to content

Commit

Permalink
mark c2c add check
Browse files Browse the repository at this point in the history
  • Loading branch information
FGadvancer committed Feb 23, 2022
1 parent 2802f74 commit 992f76d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
21 changes: 16 additions & 5 deletions internal/conversation_msg/conversation.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,23 @@ func (c *Conversation) typingStatusUpdate(callback open_im_sdk_callback.Base, re

}

func (c *Conversation) markC2CMessageAsRead(callback open_im_sdk_callback.Base, msgIDList sdk.MarkC2CMessageAsReadParams, sourceMsgIDList, userID, operationID string) {
func (c *Conversation) markC2CMessageAsRead(callback open_im_sdk_callback.Base, msgIDList sdk.MarkC2CMessageAsReadParams, userID, operationID string) {
var localMessage db.LocalChatLog
var newMessageIDList []string
messages, err := c.db.GetMultipleMessage(msgIDList)
common.CheckDBErrCallback(callback, err, operationID)
for _, v := range messages {
if v.IsRead == false && v.ContentType < constant.NotificationBegin {
newMessageIDList = append(newMessageIDList, v.ClientMsgID)
}
}
if len(newMessageIDList) == 0 {
common.CheckAnyErrCallback(callback, 201, errors.New("message has been marked read"), operationID)
}
conversationID := utils.GetConversationIDBySessionType(userID, constant.SingleChatType)
s := sdk_struct.MsgStruct{}
c.initBasicInfo(&s, constant.UserMsgType, constant.HasReadReceipt, operationID)
s.Content = sourceMsgIDList
s.Content = utils.StructToJsonString(newMessageIDList)
options := make(map[string]bool, 5)
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
Expand All @@ -315,13 +326,13 @@ func (c *Conversation) markC2CMessageAsRead(callback open_im_sdk_callback.Base,
s.SendTime = resp.SendTime
s.Status = constant.MsgStatusFiltered
msgStructToLocalChatLog(&localMessage, &s)
err := c.db.InsertMessage(&localMessage)
err = c.db.InsertMessage(&localMessage)
if err != nil {
log.Error(operationID, "inset into chat log err", localMessage, s, err.Error())
}
err2 := c.db.UpdateMessageHasRead(userID, msgIDList)
err2 := c.db.UpdateMessageHasRead(userID, newMessageIDList)
if err2 != nil {
log.Error(operationID, "update message has read error", msgIDList, userID, err2.Error())
log.Error(operationID, "update message has read error", newMessageIDList, userID, err2.Error())
}
_ = common.TriggerCmdUpdateConversation(common.UpdateConNode{ConID: conversationID, Action: constant.UpdateLatestMessageChange}, c.ch)
//_ = common.TriggerCmdUpdateConversation(common.UpdateConNode{ConID: conversationID, Action: constant.ConChange, Args: []string{conversationID}}, c.ch)
Expand Down
2 changes: 1 addition & 1 deletion internal/conversation_msg/open_im_sdk_conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ func (c *Conversation) MarkC2CMessageAsRead(callback open_im_sdk_callback.Base,
callback.OnSuccess(sdk_params_callback.MarkC2CMessageAsReadCallback)
return
}
c.markC2CMessageAsRead(callback, unmarshalParams, msgIDList, userID, operationID)
c.markC2CMessageAsRead(callback, unmarshalParams, userID, operationID)
callback.OnSuccess(sdk_params_callback.MarkC2CMessageAsReadCallback)
log.NewInfo(operationID, "MarkC2CMessageAsRead callback: ", sdk_params_callback.MarkC2CMessageAsReadCallback)
}()
Expand Down
13 changes: 12 additions & 1 deletion pkg/db/chat_log_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,23 @@ func (d *DataBase) GetSendingMessageList() (result []*LocalChatLog, err error) {
func (d *DataBase) UpdateMessageHasRead(sendID string, msgIDList []string) error {
d.mRWMutex.Lock()
defer d.mRWMutex.Unlock()
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)
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)
if t.RowsAffected == 0 {
return utils.Wrap(errors.New("RowsAffected == 0"), "no update")
}
return utils.Wrap(t.Error, "UpdateMessageStatusBySourceID failed")
}
func (d *DataBase) GetMultipleMessage(conversationIDList []string) (result []*LocalChatLog, err error) {
d.mRWMutex.Lock()
defer d.mRWMutex.Unlock()
var messageList []LocalChatLog
err = utils.Wrap(d.conn.Where("client_msg_id IN ?", conversationIDList).Find(&messageList).Error, "GetMultipleMessage failed")
for _, v := range messageList {
v1 := v
result = append(result, &v1)
}
return result, err
}

func (d *DataBase) GetNormalMsgSeq() (uint32, error) {
d.mRWMutex.Lock()
Expand Down

0 comments on commit 992f76d

Please sign in to comment.