mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-11-24 18:43:44 +08:00
refactor(core): streamline message gateway imports and declarations
This commit is contained in:
parent
6b3ca879d0
commit
11309b2917
@ -23,7 +23,6 @@ import (
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
"github.com/openimsdk/protocol/sdkws"
|
||||
@ -173,8 +172,6 @@ func (c *Client) handleMessage(message []byte) error {
|
||||
ctx := mcontext.WithMustInfoCtx(
|
||||
[]string{binaryReq.OperationID, binaryReq.SendID, constant.PlatformIDToName(c.PlatformID), c.ctx.GetConnID()},
|
||||
)
|
||||
ctx = authverify.WithIMAdminUserIDs(ctx, c.longConnServer.(*WsServer).msgGatewayConfig.Share.IMAdminUser.UserIDs)
|
||||
|
||||
log.ZDebug(ctx, "gateway req message", "req", binaryReq.String())
|
||||
|
||||
var (
|
||||
|
||||
@ -22,7 +22,6 @@ import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/rpcli"
|
||||
"github.com/openimsdk/protocol/constant"
|
||||
@ -156,16 +155,11 @@ func (g *GrpcHandler) SendMessage(ctx context.Context, data *Req) ([]byte, error
|
||||
if err := proto.Unmarshal(data.Data, &msgData); err != nil {
|
||||
return nil, errs.WrapMsg(err, "SendMessage: error unmarshaling message data", "action", "unmarshal", "dataType", "MsgData")
|
||||
}
|
||||
if err := authverify.CheckAccess(ctx, msgData.SendID); err != nil {
|
||||
return nil, err
|
||||
if msgData.ContentType >= constant.NotificationBegin && msgData.ContentType <= constant.NotificationEnd {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("SendMessage: clients cannot send notification content types")
|
||||
}
|
||||
if !authverify.IsAdmin(ctx) {
|
||||
if msgData.ContentType >= constant.NotificationBegin && msgData.ContentType <= constant.NotificationEnd {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("SendMessage: clients cannot send notification content types")
|
||||
}
|
||||
if msgData.SessionType == constant.NotificationChatType || msgprocessor.IsNotificationByMsg(&msgData) {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("SendMessage: clients cannot send to notification sessions")
|
||||
}
|
||||
if msgData.SessionType == constant.NotificationChatType || msgprocessor.IsNotificationByMsg(&msgData) {
|
||||
return nil, errs.ErrNoPermission.WrapMsg("SendMessage: clients cannot send to notification sessions")
|
||||
}
|
||||
|
||||
if err := g.validate.Struct(&msgData); err != nil {
|
||||
@ -203,9 +197,6 @@ func (g *GrpcHandler) PullMessageBySeqList(ctx context.Context, data *Req) ([]by
|
||||
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
||||
return nil, errs.WrapMsg(err, "err proto unmarshal", "action", "unmarshal", "dataType", "PullMessageBySeqsReq")
|
||||
}
|
||||
if err := authverify.CheckAccess(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := g.validate.Struct(data); err != nil {
|
||||
return nil, errs.WrapMsg(err, "validation failed", "action", "validate", "dataType", "PullMessageBySeqsReq")
|
||||
}
|
||||
@ -225,9 +216,6 @@ func (g *GrpcHandler) GetConversationsHasReadAndMaxSeq(ctx context.Context, data
|
||||
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
||||
return nil, errs.WrapMsg(err, "err proto unmarshal", "action", "unmarshal", "dataType", "GetConversationsHasReadAndMaxSeq")
|
||||
}
|
||||
if err := authverify.CheckAccess(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := g.validate.Struct(data); err != nil {
|
||||
return nil, errs.WrapMsg(err, "validation failed", "action", "validate", "dataType", "GetConversationsHasReadAndMaxSeq")
|
||||
}
|
||||
@ -247,9 +235,6 @@ func (g *GrpcHandler) GetSeqMessage(ctx context.Context, data *Req) ([]byte, err
|
||||
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
||||
return nil, errs.WrapMsg(err, "error unmarshaling request", "action", "unmarshal", "dataType", "GetSeqMessage")
|
||||
}
|
||||
if err := authverify.CheckAccess(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := g.validate.Struct(data); err != nil {
|
||||
return nil, errs.WrapMsg(err, "validation failed", "action", "validate", "dataType", "GetSeqMessage")
|
||||
}
|
||||
@ -269,9 +254,6 @@ func (g *GrpcHandler) UserLogout(ctx context.Context, data *Req) ([]byte, error)
|
||||
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
||||
return nil, errs.WrapMsg(err, "error unmarshaling request", "action", "unmarshal", "dataType", "DelUserPushTokenReq")
|
||||
}
|
||||
if err := authverify.CheckAccess(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := g.pushClient.PushMsgServiceClient.DelUserPushToken(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -299,9 +281,6 @@ func (g *GrpcHandler) GetLastMessage(ctx context.Context, data *Req) ([]byte, er
|
||||
if err := proto.Unmarshal(data.Data, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := authverify.CheckAccess(ctx, req.UserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := g.msgClient.GetLastMessage(ctx, &req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user