mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-30 10:39:47 +08:00
msg del
This commit is contained in:
parent
bf5a5bffa0
commit
991a4d1d95
@ -1,83 +1,43 @@
|
|||||||
package msg
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/constant"
|
|
||||||
"Open_IM/pkg/common/db"
|
|
||||||
"Open_IM/pkg/common/log"
|
|
||||||
"Open_IM/pkg/common/tokenverify"
|
"Open_IM/pkg/common/tokenverify"
|
||||||
"Open_IM/pkg/proto/msg"
|
"Open_IM/pkg/proto/msg"
|
||||||
common "Open_IM/pkg/proto/sdkws"
|
common "Open_IM/pkg/proto/sdkws"
|
||||||
"Open_IM/pkg/utils"
|
|
||||||
"context"
|
"context"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (rpc *msgServer) DelMsgList(_ context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) {
|
func (s *msgServer) DelMsgList(ctx context.Context, req *common.DelMsgListReq) (*common.DelMsgListResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String())
|
|
||||||
resp := &common.DelMsgListResp{}
|
resp := &common.DelMsgListResp{}
|
||||||
select {
|
if err := s.MsgInterface.DelMsgFromCache(ctx, req.UserID, req.SeqList); err != nil {
|
||||||
case rpc.delMsgCh <- deleteMsg{
|
return nil, err
|
||||||
UserID: req.UserID,
|
}
|
||||||
OpUserID: req.OpUserID,
|
DeleteMessageNotification(ctx, req.UserID, req.SeqList)
|
||||||
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
|
return resp, nil
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
|
||||||
return resp, nil
|
func (s *msgServer) DelSuperGroupMsg(ctx context.Context, req *msg.DelSuperGroupMsgReq) (*msg.DelSuperGroupMsgResp, error) {
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
resp := &msg.DelSuperGroupMsgResp{}
|
resp := &msg.DelSuperGroupMsgResp{}
|
||||||
groupMaxSeq, err := db.DB.GetGroupMaxSeq(req.GroupID)
|
if err := tokenverify.CheckAdmin(ctx); err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
log.NewError(req.OperationID, "GetGroupMaxSeq false ", req.OpUserID, req.UserID, req.GroupID)
|
|
||||||
resp.ErrCode = constant.ErrDB.ErrCode
|
|
||||||
resp.ErrMsg = err.Error()
|
|
||||||
return resp, nil
|
|
||||||
}
|
}
|
||||||
err = db.DB.SetGroupUserMinSeq(req.GroupID, req.UserID, groupMaxSeq)
|
maxSeq, err := s.MsgInterface.GetGroupMaxSeq(ctx, req.GroupID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.NewError(req.OperationID, "SetGroupUserMinSeq false ", req.OpUserID, req.UserID, req.GroupID)
|
return nil, err
|
||||||
resp.ErrCode = constant.ErrDB.ErrCode
|
}
|
||||||
resp.ErrMsg = err.Error()
|
if err := s.MsgInterface.SetGroupUserMinSeq(ctx, req.GroupID, maxSeq); err != nil {
|
||||||
return resp, nil
|
return nil, err
|
||||||
}
|
}
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String())
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rpc *msgServer) ClearMsg(_ context.Context, req *pbChat.ClearMsgReq) (*pbChat.ClearMsgResp, error) {
|
func (s *msgServer) ClearMsg(ctx context.Context, req *msg.ClearMsgReq) (*msg.ClearMsgResp, error) {
|
||||||
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc req: ", req.String())
|
resp := &msg.ClearMsgResp{}
|
||||||
if req.OpUserID != req.UserID && !tokenverify.IsManagerUserID(req.UserID) {
|
if err := tokenverify.CheckAccessV3(ctx, req.UserID); err != nil {
|
||||||
errMsg := "No permission" + req.OpUserID + req.UserID
|
return nil, err
|
||||||
log.Error(req.OperationID, errMsg)
|
|
||||||
return &pbChat.ClearMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil
|
|
||||||
}
|
}
|
||||||
log.Debug(req.OperationID, "CleanUpOneUserAllMsgFromRedis args", req.UserID)
|
if err := s.MsgInterface.DelUserAllSeq(ctx, req.UserID); err != nil {
|
||||||
err := db.DB.CleanUpOneUserAllMsgFromRedis(req.UserID, req.OperationID)
|
return nil, err
|
||||||
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
|
|
||||||
}
|
}
|
||||||
log.Debug(req.OperationID, "CleanUpUserMsgFromMongo args", req.UserID)
|
return resp, nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package msg
|
package msg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"Open_IM/pkg/common/constant"
|
||||||
"Open_IM/pkg/common/tracelog"
|
"Open_IM/pkg/common/tracelog"
|
||||||
pbMsg "Open_IM/pkg/proto/msg"
|
pbMsg "Open_IM/pkg/proto/msg"
|
||||||
"context"
|
"context"
|
||||||
@ -14,11 +15,15 @@ func (s *msgServer) SetSendMsgStatus(ctx context.Context, req *pbMsg.SetSendMsgS
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *msgServer) GetSendMsgStatus(ctx context.Context, req *pbMsg.GetSendMsgStatusReq) (resp *pbMsg.GetSendMsgStatusResp, err error) {
|
func (s *msgServer) GetSendMsgStatus(ctx context.Context, req *pbMsg.GetSendMsgStatusReq) (*pbMsg.GetSendMsgStatusResp, error) {
|
||||||
resp = &pbMsg.GetSendMsgStatusResp{}
|
resp := &pbMsg.GetSendMsgStatusResp{}
|
||||||
resp.Status, err = s.MsgInterface.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx))
|
status, err := s.MsgInterface.GetSendMsgStatus(ctx, tracelog.GetOperationID(ctx))
|
||||||
if err != nil {
|
if IsNotFound(err) {
|
||||||
|
resp.Status = constant.MsgStatusNotExist
|
||||||
|
return resp, nil
|
||||||
|
} else if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
resp.Status = status
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
7
internal/rpc/msg/notification.go
Normal file
7
internal/rpc/msg/notification.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package msg
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
func DeleteMessageNotification(ctx context.Context, userID string, seqs []uint32) {
|
||||||
|
panic("todo")
|
||||||
|
}
|
@ -22,6 +22,11 @@ type MsgInterface interface {
|
|||||||
// status
|
// status
|
||||||
SetSendMsgStatus(ctx context.Context, id string, status int32) error
|
SetSendMsgStatus(ctx context.Context, id string, status int32) error
|
||||||
GetSendMsgStatus(ctx context.Context, id string) (int32, error) // 不存在返回 constant.MsgStatusNotExist
|
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 {
|
type MsgDatabaseInterface interface {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user