diff --git a/internal/rpc/msg/delete.go b/internal/rpc/msg/delete.go index bc02a01dd..1b8306614 100644 --- a/internal/rpc/msg/delete.go +++ b/internal/rpc/msg/delete.go @@ -101,6 +101,7 @@ func (m *msgServer) DeleteMsgPhysical(ctx context.Context, req *msg.DeleteMsgPhy } func (m *msgServer) clearConversation(ctx context.Context, conversationIDs []string, userID string, deleteSyncOpt *msg.DeleteSyncOpt) error { + defer log.ZDebug(ctx, "clearConversation return line") conversations, err := m.Conversation.GetConversationsByConversationID(ctx, conversationIDs) if err != nil { return err @@ -135,5 +136,8 @@ func (m *msgServer) clearConversation(ctx context.Context, conversationIDs []str m.notificationSender.NotificationWithSesstionType(ctx, userID, m.conversationAndGetRecvID(conversation, userID), constant.ClearConversationNotification, conversation.ConversationType, tips) } } + if err := m.MsgDatabase.UserSetHasReadSeqs(ctx, userID, maxSeqs); err != nil { + return err + } return nil } diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 7f13c3aab..0d717cfd4 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -13,7 +13,6 @@ import ( "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/relation" tablerelation "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/relation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/tx" - "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" registry "github.com/OpenIMSDK/Open-IM-Server/pkg/discoveryregistry" "github.com/OpenIMSDK/Open-IM-Server/pkg/errs" @@ -94,14 +93,14 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI if err != nil { return nil, err } + _ = s.notificationSender.UserInfoUpdatedNotification(ctx, req.UserInfo.UserID) friends, err := s.friendRpcClient.GetFriendIDs(ctx, req.UserInfo.UserID) if err != nil { return nil, err } - for _, v := range friends { - s.notificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, v, mcontext.GetOpUserID(ctx)) + for _, friendID := range friends { + s.notificationSender.FriendInfoUpdatedNotification(ctx, req.UserInfo.UserID, friendID) } - s.notificationSender.UserInfoUpdatedNotification(ctx, mcontext.GetOpUserID(ctx), req.UserInfo.UserID) return resp, nil } @@ -116,7 +115,7 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbuser.Se if err := s.UpdateByMap(ctx, req.UserID, m); err != nil { return nil, err } - s.notificationSender.UserInfoUpdatedNotification(ctx, req.UserID, req.UserID) + s.notificationSender.UserInfoUpdatedNotification(ctx, req.UserID) return resp, nil } diff --git a/pkg/common/db/cache/msg.go b/pkg/common/db/cache/msg.go index 30d5f1ffc..ec6037ae7 100644 --- a/pkg/common/db/cache/msg.go +++ b/pkg/common/db/cache/msg.go @@ -63,6 +63,8 @@ type SeqCache interface { SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error // k: user, v: seq SetHasReadSeqs(ctx context.Context, conversationID string, hasReadSeqs map[string]int64) error + // k: conversation, v :seq + UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) GetHasReadSeq(ctx context.Context, userID string, conversationID string) (int64, error) } @@ -245,6 +247,12 @@ func (c *msgCache) SetHasReadSeqs(ctx context.Context, conversationID string, ha }) } +func (c *msgCache) UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error { + return c.setSeqs(ctx, hasReadSeqs, func(conversationID string) string { + return c.getHasReadSeqKey(conversationID, userID) + }) +} + func (c *msgCache) GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) { return c.getSeqs(ctx, conversationIDs, func(conversationID string) string { return c.getHasReadSeqKey(conversationID, userID) diff --git a/pkg/common/db/controller/msg.go b/pkg/common/db/controller/msg.go index 0176c9475..4cb1f0580 100644 --- a/pkg/common/db/controller/msg.go +++ b/pkg/common/db/controller/msg.go @@ -69,6 +69,7 @@ type CommonMsgDatabase interface { SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error GetHasReadSeqs(ctx context.Context, userID string, conversationIDs []string) (map[string]int64, error) GetHasReadSeq(ctx context.Context, userID string, conversationID string) (int64, error) + UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error GetMongoMaxAndMinSeq(ctx context.Context, conversationID string) (maxSeq, minSeq int64, err error) GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) @@ -807,6 +808,10 @@ func (db *commonMsgDatabase) SetUserConversationsMinSeqs(ctx context.Context, us return db.cache.SetUserConversationsMinSeqs(ctx, userID, seqs) } +func (db *commonMsgDatabase) UserSetHasReadSeqs(ctx context.Context, userID string, hasReadSeqs map[string]int64) error { + return db.cache.UserSetHasReadSeqs(ctx, userID, hasReadSeqs) +} + func (db *commonMsgDatabase) SetHasReadSeq(ctx context.Context, userID string, conversationID string, hasReadSeq int64) error { return db.cache.SetHasReadSeq(ctx, userID, conversationID, hasReadSeq) } diff --git a/pkg/rpcclient/notification/friend.go b/pkg/rpcclient/notification/friend.go index 7c655686d..803c748c0 100644 --- a/pkg/rpcclient/notification/friend.go +++ b/pkg/rpcclient/notification/friend.go @@ -2,6 +2,7 @@ package notification import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/convert" @@ -91,9 +92,9 @@ func (f *FriendNotificationSender) getFromToUserNickname(ctx context.Context, fr return users[fromUserID].Nickname, users[toUserID].Nickname, nil } -func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Context, opUserID string, changedUserID string) error { +func (f *FriendNotificationSender) UserInfoUpdatedNotification(ctx context.Context, changedUserID string) error { tips := sdkws.UserInfoUpdatedTips{UserID: changedUserID} - return f.Notification(ctx, opUserID, changedUserID, constant.UserInfoUpdatedNotification, &tips) + return f.Notification(ctx, mcontext.GetOpUserID(ctx), changedUserID, constant.UserInfoUpdatedNotification, &tips) } func (f *FriendNotificationSender) FriendApplicationAddNotification(ctx context.Context, req *pbFriend.ApplyToAddFriendReq) error { @@ -171,7 +172,7 @@ func (c *FriendNotificationSender) BlackDeletedNotification(ctx context.Context, c.Notification(ctx, req.OwnerUserID, req.BlackUserID, constant.BlackDeletedNotification, &blackDeletedTips) } -func (c *FriendNotificationSender) FriendInfoUpdatedNotification(ctx context.Context, changedUserID string, needNotifiedUserID string, opUserID string) { +func (c *FriendNotificationSender) FriendInfoUpdatedNotification(ctx context.Context, changedUserID string, needNotifiedUserID string) { tips := sdkws.UserInfoUpdatedTips{UserID: changedUserID} - c.Notification(ctx, opUserID, needNotifiedUserID, constant.FriendInfoUpdatedNotification, &tips) + c.Notification(ctx, mcontext.GetOpUserID(ctx), needNotifiedUserID, constant.FriendInfoUpdatedNotification, &tips) }