This commit is contained in:
withchao 2023-02-13 11:24:13 +08:00
parent bf5a5bffa0
commit 991a4d1d95
4 changed files with 41 additions and 64 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -0,0 +1,7 @@
package msg
import "context"
func DeleteMessageNotification(ctx context.Context, userID string, seqs []uint32) {
panic("todo")
}

View File

@ -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 {