From 02a1d10a8bf8547865ceaf9e5958ecdbd4505555 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Mon, 29 May 2023 20:18:47 +0800 Subject: [PATCH] delete notification --- internal/rpc/msg/delete.go | 32 ++++++++++++++++++++++++++++++++ pkg/rpcclient/conversation.go | 9 +++++++++ pkg/rpcclient/msg.go | 8 +++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/internal/rpc/msg/delete.go b/internal/rpc/msg/delete.go index b0a18b999..6be3101cf 100644 --- a/internal/rpc/msg/delete.go +++ b/internal/rpc/msg/delete.go @@ -3,6 +3,7 @@ package msg import ( "context" + "github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/log" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/tokenverify" "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg" @@ -27,6 +28,7 @@ func (m *msgServer) ClearConversationsMsg(ctx context.Context, req *msg.ClearCon if err := m.MsgDatabase.SetUserConversationsMinSeqs(ctx, req.UserID, m.getMinSeqs(maxSeqs)); err != nil { return nil, err } + m.conversationClearSync(ctx, req.DeleteSyncOpt, req.UserID, req.ConversationIDs) return &msg.ClearConversationsMsgResp{}, nil } @@ -46,6 +48,7 @@ func (m *msgServer) UserClearAllMsg(ctx context.Context, req *msg.UserClearAllMs if err := m.MsgDatabase.SetUserConversationsMinSeqs(ctx, req.UserID, m.getMinSeqs(maxSeqs)); err != nil { return nil, err } + m.conversationClearSync(ctx, req.DeleteSyncOpt, req.UserID, conversationIDs) return &msg.UserClearAllMsgResp{}, nil } @@ -56,6 +59,7 @@ func (m *msgServer) DeleteMsgs(ctx context.Context, req *msg.DeleteMsgsReq) (*ms if err := m.MsgDatabase.DeleteUserMsgsBySeqs(ctx, req.UserID, req.ConversationID, req.Seqs); err != nil { return nil, err } + m.DeleteMsgsNotification(ctx, req.ConversationID, req.UserID, req.Seqs, req.DeleteSyncOpt) return &msg.DeleteMsgsResp{}, nil } @@ -78,3 +82,31 @@ func (m *msgServer) DeleteMsgPhysical(ctx context.Context, req *msg.DeleteMsgPhy } return &msg.DeleteMsgPhysicalResp{}, nil } + +func (m *msgServer) conversationClearSync(ctx context.Context, opt *msg.DeleteSyncOpt, userID string, conversationIDs []string) { + if opt == nil { + return + } + for _, conversationID := range conversationIDs { + conversation, err := m.Conversation.GetConversation(ctx, userID, conversationID) + if err != nil { + log.ZWarn(ctx, "GetConversation error", err, "conversationID", conversationID, "userID", userID) + continue + } + if conversation.ConversationType == constant.SingleChatType || conversation.ConversationType == constant.NotificationChatType { + + } else if conversation.ConversationType == constant.SuperGroupChatType { + + } + } + + if opt.IsSyncSelf { + + } else if opt.IsSyncOther { + } + +} + +func (m *msgServer) DeleteMsgsNotification(ctx context.Context, conversationID, userID string, seqs []int64, opt *msg.DeleteSyncOpt) error { + return nil +} diff --git a/pkg/rpcclient/conversation.go b/pkg/rpcclient/conversation.go index 05141e576..1077bbbc3 100644 --- a/pkg/rpcclient/conversation.go +++ b/pkg/rpcclient/conversation.go @@ -76,3 +76,12 @@ func (c *ConversationClient) GetConversationIDs(ctx context.Context, ownerUserID resp, err := conversation.NewConversationClient(cc).GetConversationIDs(ctx, &pbConversation.GetConversationIDsReq{UserID: ownerUserID}) return resp.ConversationIDs, err } + +func (c *ConversationClient) GetConversation(ctx context.Context, ownerUserID, conversationID string) (*pbConversation.Conversation, error) { + cc, err := c.getConn(ctx) + if err != nil { + return nil, err + } + resp, err := conversation.NewConversationClient(cc).GetConversation(ctx, &pbConversation.GetConversationReq{OwnerUserID: ownerUserID, ConversationID: conversationID}) + return resp.Conversation, err +} diff --git a/pkg/rpcclient/msg.go b/pkg/rpcclient/msg.go index 735a05a40..d89779171 100644 --- a/pkg/rpcclient/msg.go +++ b/pkg/rpcclient/msg.go @@ -52,6 +52,8 @@ func newContentTypeConf() map[int32]config.NotificationConf { constant.ConversationChangeNotification: config.Config.Notification.ConversationChanged, constant.ConversationUnreadNotification: config.Config.Notification.ConversationChanged, constant.ConversationPrivateChatNotification: config.Config.Notification.ConversationSetPrivate, + // msg + constant.MsgRevokeNotification: {IsSendMsg: false, ReliabilityLevel: constant.ReliableNotificationNoMsg}, } } @@ -158,7 +160,7 @@ func NewNotificationSender(opts ...NewNotificationSenderOptions) *NotificationSe return notificationSender } -func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...utils.OptionsOpt) error { +func (s *NotificationSender) NotificationWithSesstionType(ctx context.Context, sendID, recvID string, contentType, sesstionType int32, m proto.Message, opts ...utils.OptionsOpt) (err error) { n := sdkws.NotificationElem{Detail: utils.StructToJsonString(m)} content, err := json.Marshal(&n) if err != nil { @@ -196,3 +198,7 @@ func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID st } return err } + +func (s *NotificationSender) Notification(ctx context.Context, sendID, recvID string, contentType int32, m proto.Message, opts ...utils.OptionsOpt) error { + return s.NotificationWithSesstionType(ctx, sendID, recvID, contentType, s.sessionTypeConf[contentType], m, opts...) +}