You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/rpc/msg/chat.go

64 lines
2.8 KiB

package msg
import (
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/db"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/token_verify"
2 years ago
pbChat "Open_IM/pkg/proto/msg"
"Open_IM/pkg/utils"
"context"
)
func (rpc *rpcChat) ClearMsg(_ context.Context, req *pbChat.ClearMsgReq) (*pbChat.ClearMsgResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc req: ", req.String())
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.UserID) {
errMsg := "No permission" + req.OpUserID + req.UserID
log.Error(req.OperationID, errMsg)
2 years ago
return &pbChat.ClearMsgResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "CleanUpOneUserAllMsgFromRedis args", req.UserID)
3 years ago
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)
2 years ago
return &pbChat.ClearMsgResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
}
log.Debug(req.OperationID, "CleanUpUserMsgFromMongo args", req.UserID)
3 years ago
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)
2 years ago
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
}
2 years ago
func (rpc *rpcChat) SetMsgMinSeq(_ context.Context, req *pbChat.SetMsgMinSeqReq) (*pbChat.SetMsgMinSeqResp, error) {
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc req: ", req.String())
if req.OpUserID != req.UserID && !token_verify.IsManagerUserID(req.UserID) {
errMsg := "No permission" + req.OpUserID + req.UserID
log.Error(req.OperationID, errMsg)
2 years ago
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrNoPermission.ErrCode, ErrMsg: errMsg}, nil
2 years ago
}
if req.GroupID == "" {
err := db.DB.SetUserMinSeq(req.UserID, req.MinSeq)
if err != nil {
errMsg := "SetUserMinSeq failed " + err.Error() + req.OperationID + req.UserID + utils.Uint32ToString(req.MinSeq)
log.Error(req.OperationID, errMsg)
2 years ago
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
2 years ago
}
return &pbChat.SetMsgMinSeqResp{}, nil
}
2 years ago
err := db.DB.SetGroupUserMinSeq(req.GroupID, req.UserID, uint64(req.MinSeq))
2 years ago
if err != nil {
errMsg := "SetGroupUserMinSeq failed " + err.Error() + req.OperationID + req.GroupID + req.UserID + utils.Uint32ToString(req.MinSeq)
log.Error(req.OperationID, errMsg)
2 years ago
return &pbChat.SetMsgMinSeqResp{ErrCode: constant.ErrDatabase.ErrCode, ErrMsg: errMsg}, nil
2 years ago
}
return &pbChat.SetMsgMinSeqResp{}, nil
}