From 991a4d1d956f9d9510b2faa833f97265562cd0b3 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Mon, 13 Feb 2023 11:24:13 +0800 Subject: [PATCH] msg del --- internal/rpc/msg/delete.go | 80 ++++++++------------------------ internal/rpc/msg/msg_status.go | 13 ++++-- internal/rpc/msg/notification.go | 7 +++ pkg/common/db/controller/msg.go | 5 ++ 4 files changed, 41 insertions(+), 64 deletions(-) create mode 100644 internal/rpc/msg/notification.go diff --git a/internal/rpc/msg/delete.go b/internal/rpc/msg/delete.go index ee2c15d96..44b506df6 100644 --- a/internal/rpc/msg/delete.go +++ b/internal/rpc/msg/delete.go @@ -1,83 +1,43 @@ package msg import ( - "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" - "Open_IM/pkg/common/log" "Open_IM/pkg/common/tokenverify" "Open_IM/pkg/proto/msg" common "Open_IM/pkg/proto/sdkws" - "Open_IM/pkg/utils" "context" - "time" ) -func (rpc *msgServer) DelMsgList(_ context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) +func (s *msgServer) DelMsgList(ctx context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) { resp := &common.DelMsgListResp{} - select { - case rpc.delMsgCh <- deleteMsg{ - UserID: req.UserID, - OpUserID: req.OpUserID, - SeqList: req.SeqList, - OperationID: req.OperationID, - }: - case <-time.After(1 * time.Second): - resp.ErrCode = constant.ErrSendLimit.ErrCode - resp.ErrMsg = constant.ErrSendLimit.ErrMsg - return resp, nil + if err := s.MsgInterface.DelMsgFromCache(ctx, req.UserID, req.SeqList); err != nil { + return nil, err } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) + DeleteMessageNotification(ctx, req.UserID, req.SeqList) return resp, nil } -func (rpc *msgServer) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - if !tokenverify.CheckAccess(ctx, req.OpUserID, req.UserID) { - log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.UserID) - return &msg.DelSuperGroupMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: constant.ErrNoPermission.ErrMsg}, nil - } + +func (s *msgServer) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) { resp := &msg.DelSuperGroupMsgResp{} - groupMaxSeq, err := db.DB.GetGroupMaxSeq(req.GroupID) - if err != nil { - log.NewError(req.OperationID, "GetGroupMaxSeq false ", req.OpUserID, req.UserID, req.GroupID) - resp.ErrCode = constant.ErrDB.ErrCode - resp.ErrMsg = err.Error() - return resp, nil + if err := tokenverify.CheckAdmin(ctx); err != nil { + return nil, err } - err = db.DB.SetGroupUserMinSeq(req.GroupID, req.UserID, groupMaxSeq) + maxSeq, err := s.MsgInterface.GetGroupMaxSeq(ctx, req.GroupID) if err != nil { - log.NewError(req.OperationID, "SetGroupUserMinSeq false ", req.OpUserID, req.UserID, req.GroupID) - resp.ErrCode = constant.ErrDB.ErrCode - resp.ErrMsg = err.Error() - return resp, nil + return nil, err + } + if err := s.MsgInterface.SetGroupUserMinSeq(ctx, req.GroupID, maxSeq); err != nil { + return nil, err } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil } -func (rpc *msgServer) ClearMsg(_ context.Context, req *pbChat.ClearMsgReq) (*pbChat.ClearMsgResp, error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc req: ", req.String()) - if req.OpUserID != req.UserID && !tokenverify.IsManagerUserID(req.UserID) { - errMsg := "No permission" + req.OpUserID + req.UserID - log.Error(req.OperationID, errMsg) - return &pbChat.ClearMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil +func (s *msgServer) ClearMsg(ctx context.Context, req *msg.ClearMsgReq) (*msg.ClearMsgResp, error) { + resp := &msg.ClearMsgResp{} + if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil { + return nil, err } - log.Debug(req.OperationID, "CleanUpOneUserAllMsgFromRedis args", req.UserID) - err := db.DB.CleanUpOneUserAllMsgFromRedis(req.UserID, req.OperationID) - if err != nil { - errMsg := "CleanUpOneUserAllMsgFromRedis failed " + err.Error() + req.OperationID + req.UserID - log.Error(req.OperationID, errMsg) - return &pbChat.ClearMsgResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil + if err := s.MsgInterface.DelUserAllSeq(ctx, req.UserID); err != nil { + return nil, err } - log.Debug(req.OperationID, "CleanUpUserMsgFromMongo args", req.UserID) - err = db.DB.CleanUpUserMsgFromMongo(req.UserID, req.OperationID) - if err != nil { - errMsg := "CleanUpUserMsgFromMongo failed " + err.Error() + req.OperationID + req.UserID - log.Error(req.OperationID, errMsg) - return &pbChat.ClearMsgResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil - } - - resp := pbChat.ClearMsgResp{ErrCode: 0} - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return &resp, nil + return resp, nil } diff --git a/internal/rpc/msg/msg_status.go b/internal/rpc/msg/msg_status.go index fe05f5194..fb0ed2edf 100644 --- a/internal/rpc/msg/msg_status.go +++ b/internal/rpc/msg/msg_status.go @@ -1,6 +1,7 @@ package msg import ( + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/tracelog" pbMsg "Open_IM/pkg/proto/msg" "context" @@ -14,11 +15,15 @@ func (s *msgServer) SetSendMsgStatus(ctx context.Context, req *pbMsg.SetSendMsgS return resp, nil } -func (s *msgServer) GetSendMsgStatus(ctx context.Context, req *pbMsg.GetSendMsgStatusReq) (resp *pbMsg.GetSendMsgStatusResp, err error) { - resp = &pbMsg.GetSendMsgStatusResp{} - resp.Status, err = s.MsgInterface.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx)) - if err != nil { +func (s *msgServer) GetSendMsgStatus(ctx context.Context, req *pbMsg.GetSendMsgStatusReq) (*pbMsg.GetSendMsgStatusResp, error) { + resp := &pbMsg.GetSendMsgStatusResp{} + status, err := s.MsgInterface.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx)) + if IsNotFound(err) { + resp.Status = constant.MsgStatusNotExist + return resp, nil + } else if err != nil { return nil, err } + resp.Status = status return resp, nil } diff --git a/internal/rpc/msg/notification.go b/internal/rpc/msg/notification.go new file mode 100644 index 000000000..439c2e3b2 --- /dev/null +++ b/internal/rpc/msg/notification.go @@ -0,0 +1,7 @@ +package msg + +import "context" + +func DeleteMessageNotification(ctx context.Context, userID string, seqs []uint32) { + panic("todo") +} diff --git a/pkg/common/db/controller/msg.go b/pkg/common/db/controller/msg.go index fe8bf604f..3445e8dd1 100644 --- a/pkg/common/db/controller/msg.go +++ b/pkg/common/db/controller/msg.go @@ -22,6 +22,11 @@ type MsgInterface interface { // status SetSendMsgStatus(ctx context.Context, id string, status int32) error GetSendMsgStatus(ctx context.Context, id string) (int32, error) // 不存在返回 constant.MsgStatusNotExist + // delete + DelMsgFromCache(ctx context.Context, userID string, seqs []uint32) error + GetGroupMaxSeq(ctx context.Context, groupID string) (uint32, error) + SetGroupUserMinSeq(ctx context.Context, groupID string, seq uint32) error + DelUserAllSeq(ctx context.Context, userID string) error // redis and mongodb } type MsgDatabaseInterface interface {