Skip to content

Commit

Permalink
fix: single chat unread status change. (#1171)
Browse files Browse the repository at this point in the history
* fix: to start im or chat, ZooKeeper must be started first.

* fix: msg gateway start output err info

Signed-off-by: Gordon <[email protected]>

* fix: msg gateway start output err info

Signed-off-by: Gordon <[email protected]>

* chore: package path changes

Signed-off-by: withchao <[email protected]>

* fix: go mod update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* chore: package path changes

Signed-off-by: withchao <[email protected]>

* chore: package path changes

Signed-off-by: withchao <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: get all userID

Signed-off-by: Gordon <[email protected]>

* fix: msggateway add online status call

Signed-off-by: Gordon <[email protected]>

* refactor: log change

Signed-off-by: Gordon <[email protected]>

* refactor: log change

Signed-off-by: Gordon <[email protected]>

* chore: network mode change

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat: add api of get server time

Signed-off-by: Gordon <[email protected]>

* feat: remove go work sum

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: pull message add isRead field

Signed-off-by: Gordon <[email protected]>

* fix: check msg-transfer script

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix: start don't kill old process

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: check component

Signed-off-by: Gordon <[email protected]>

* fix: pull message set isRead only message come from single.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: add ex field to update group info.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* cicd: robot automated Change

* refactor: change project module name.

Signed-off-by: Gordon <[email protected]>

* refactor: change project module name.

Signed-off-by: Gordon <[email protected]>

* refactor: change project module name.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* test: for pressure test.

Signed-off-by: Gordon <[email protected]>

* test: for pressure test.

Signed-off-by: Gordon <[email protected]>

* test: for pressure test.

Signed-off-by: Gordon <[email protected]>

* test: message log.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* fxi: component check output valid info.

Signed-off-by: Gordon <[email protected]>

* fxi: component check output valid info.

Signed-off-by: Gordon <[email protected]>

* test: send message test log.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* cicd: robot automated Change

* test: remove info log.

Signed-off-by: Gordon <[email protected]>

* feat: api of send message add sendTime field.

Signed-off-by: Gordon <[email protected]>

* fix: add callback for update user's info.

* cicd: robot automated Change

* fix: change callback command name.

* cicd: robot automated Change

* fix: single chat unread status change.

* fix: single chat unread status change.

* fix: single chat unread status change.

* fix: user status change.

* cicd: robot automated Change

* fix: user status change.

* fix: user status change.

* fix: user status change.

* cicd: robot automated Change

* fix: ws close when user logout.

---------

Signed-off-by: Gordon <[email protected]>
Signed-off-by: withchao <[email protected]>
Signed-off-by: Gordon <[email protected]>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: withchao <[email protected]>
Co-authored-by: Xinwei Xiong <[email protected]>
Co-authored-by: FGadvancer <[email protected]>
  • Loading branch information
4 people committed Oct 13, 2023
1 parent b783f0e commit 8e64306
Show file tree
Hide file tree
Showing 20 changed files with 279 additions and 217 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require github.com/google/uuid v1.3.1

require (
github.com/IBM/sarama v1.41.2
github.com/OpenIMSDK/protocol v0.0.24
github.com/OpenIMSDK/protocol v0.0.25
github.com/OpenIMSDK/tools v0.0.14
github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible
github.com/go-redis/redis v6.15.9+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/IBM/sarama v1.41.2 h1:ZDBZfGPHAD4uuAtSv4U22fRZBgst0eEwGFzLj0fb85c=
github.com/IBM/sarama v1.41.2/go.mod h1:xdpu7sd6OE1uxNdjYTSKUfY8FaKkJES9/+EyjSgiGQk=
github.com/OpenIMSDK/protocol v0.0.24 h1:wk/S0GOGVh8mBbpmjKxSsyYMhyBazdn/ZcS9VqXfT24=
github.com/OpenIMSDK/protocol v0.0.24/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/OpenIMSDK/protocol v0.0.25 h1:AtB0Ia5LO26oqPoPJDIS4UMH3Wb2li96fMgfzI2cr4I=
github.com/OpenIMSDK/protocol v0.0.25/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ=
github.com/OpenIMSDK/tools v0.0.14/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
Expand Down
10 changes: 7 additions & 3 deletions internal/msggateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func (c *Client) handleMessage(message []byte) error {
binaryReq.ReqIdentifier,
)
}
c.replyMessage(ctx, &binaryReq, messageErr, resp)
return nil

return c.replyMessage(ctx, &binaryReq, messageErr, resp)
}

func (c *Client) setAppBackgroundStatus(ctx context.Context, req Req) ([]byte, error) {
Expand All @@ -229,7 +229,7 @@ func (c *Client) close() {
c.longConnServer.UnRegister(c)
}

func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, resp []byte) {
func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, resp []byte) error {
errResp := apiresp.ParseError(err)
mReply := Resp{
ReqIdentifier: binaryReq.ReqIdentifier,
Expand All @@ -244,6 +244,10 @@ func (c *Client) replyMessage(ctx context.Context, binaryReq *Req, err error, re
if err != nil {
log.ZWarn(ctx, "wireBinaryMsg replyMessage", err, "resp", mReply.String())
}
if binaryReq.ReqIdentifier == WsLogoutMsg {
return errors.New("user logout")
}
return nil
}

func (c *Client) PushMessage(ctx context.Context, msgData *sdkws.MsgData) error {
Expand Down
70 changes: 46 additions & 24 deletions internal/rpc/msg/as_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func (m *msgServer) SetConversationHasReadSeq(
if err := m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq); err != nil {
return nil, err
}
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID, req.UserID, nil, req.HasReadSeq); err != nil {
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID,
req.UserID, nil, req.HasReadSeq); err != nil {
return
}
return &msg.SetConversationHasReadSeqResp{}, nil
Expand Down Expand Up @@ -119,7 +120,8 @@ func (m *msgServer) MarkMsgsAsRead(
return
}
}
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, m.conversationAndGetRecvID(conversation, req.UserID), req.Seqs, hasReadSeq); err != nil {
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID,
m.conversationAndGetRecvID(conversation, req.UserID), req.Seqs, hasReadSeq); err != nil {
return
}
return &msg.MarkMsgsAsReadResp{}, nil
Expand All @@ -131,44 +133,61 @@ func (m *msgServer) MarkConversationAsRead(
) (resp *msg.MarkConversationAsReadResp, err error) {
conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID)
if err != nil {
return
return nil, err
}
hasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
if err != nil && errs.Unwrap(err) != redis.Nil {
return
return nil, err
}
log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq, "req.HasReadSeq", req.HasReadSeq)
var seqs []int64
if len(req.Seqs) == 0 {

log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq,
"req.HasReadSeq", req.HasReadSeq)
if conversation.ConversationType == constant.SingleChatType {
for i := hasReadSeq + 1; i <= req.HasReadSeq; i++ {
seqs = append(seqs, i)
}
} else {
seqs = req.Seqs
}
if len(seqs) > 0 {
log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID)
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
return

if len(seqs) > 0 {
log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID)
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
return nil, err
}
}
}
if req.HasReadSeq > hasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
if err != nil {
return
if req.HasReadSeq > hasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
if err != nil {
return nil, err
}
hasReadSeq = req.HasReadSeq
}
hasReadSeq = req.HasReadSeq
}
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, m.conversationAndGetRecvID(conversation, req.UserID), seqs, hasReadSeq); err != nil {
return
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID,
m.conversationAndGetRecvID(conversation, req.UserID), seqs, hasReadSeq); err != nil {
return nil, err
}

} else if conversation.ConversationType == constant.SuperGroupChatType {
if req.HasReadSeq > hasReadSeq {
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
if err != nil {
return nil, err
}
hasReadSeq = req.HasReadSeq
}
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID,
req.UserID, seqs, hasReadSeq); err != nil {
return nil, err
}

}

return &msg.MarkConversationAsReadResp{}, nil
}

func (m *msgServer) sendMarkAsReadNotification(
ctx context.Context,
conversationID string,
sesstionType int32,
sessionType int32,
sendID, recvID string,
seqs []int64,
hasReadSeq int64,
Expand All @@ -179,6 +198,9 @@ func (m *msgServer) sendMarkAsReadNotification(
Seqs: seqs,
HasReadSeq: hasReadSeq,
}
m.notificationSender.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sesstionType, tips)
err := m.notificationSender.NotificationWithSesstionType(ctx, sendID, recvID, constant.HasReadReceipt, sessionType, tips)
if err != nil {
log.ZWarn(ctx, "send has read Receipt err", err)
}
return nil
}
36 changes: 19 additions & 17 deletions internal/rpc/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ func (s *userServer) SubscribeOrCancelUsersStatus(ctx context.Context, req *pbus
}

// GetUserStatus Get the online status of the user.
func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatusReq) (resp *pbuser.GetUserStatusResp, err error) {
func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatusReq) (resp *pbuser.GetUserStatusResp,
err error) {
onlineStatusList, err := s.UserDatabase.GetUserStatus(ctx, req.UserIDs)
if err != nil {
return nil, err
Expand All @@ -298,31 +299,32 @@ func (s *userServer) GetUserStatus(ctx context.Context, req *pbuser.GetUserStatu
}

// SetUserStatus Synchronize user's online status.
func (s *userServer) SetUserStatus(ctx context.Context, req *pbuser.SetUserStatusReq) (resp *pbuser.SetUserStatusResp, err error) {
err = s.UserDatabase.SetUserStatus(ctx, req.StatusList)
func (s *userServer) SetUserStatus(ctx context.Context, req *pbuser.SetUserStatusReq) (resp *pbuser.SetUserStatusResp,
err error) {
err = s.UserDatabase.SetUserStatus(ctx, req.UserID, req.Status, req.PlatformID)
if err != nil {
return nil, err
}
for _, value := range req.StatusList {
list, err := s.UserDatabase.GetSubscribedList(ctx, value.UserID)
if err != nil {
return nil, err
}
for _, userID := range list {
tips := &sdkws.UserStatusChangeTips{
FromUserID: value.UserID,
ToUserID: userID,
Status: value.Status,
PlatformID: value.PlatformIDs[0],
}
s.userNotificationSender.UserStatusChangeNotification(ctx, tips)
list, err := s.UserDatabase.GetSubscribedList(ctx, req.UserID)
if err != nil {
return nil, err
}
for _, userID := range list {
tips := &sdkws.UserStatusChangeTips{
FromUserID: req.UserID,
ToUserID: userID,
Status: req.Status,
PlatformID: req.PlatformID,
}
s.userNotificationSender.UserStatusChangeNotification(ctx, tips)
}

return &pbuser.SetUserStatusResp{}, nil
}

// GetSubscribeUsersStatus Get the online status of subscribers.
func (s *userServer) GetSubscribeUsersStatus(ctx context.Context, req *pbuser.GetSubscribeUsersStatusReq) (*pbuser.GetSubscribeUsersStatusResp, error) {
func (s *userServer) GetSubscribeUsersStatus(ctx context.Context,
req *pbuser.GetSubscribeUsersStatusReq) (*pbuser.GetSubscribeUsersStatusResp, error) {
userList, err := s.UserDatabase.GetAllSubscribeList(ctx, req.UserID)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 8e64306

Please sign in to comment.