parent
c036d27b36
commit
b05e89cd67
@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
func RequiredIf(fl validator.FieldLevel) bool {
|
||||
sessionType := fl.Parent().FieldByName("SessionType").Int()
|
||||
switch sessionType {
|
||||
case constant.SingleChatType, constant.NotificationChatType:
|
||||
if fl.FieldName() == "RecvID" {
|
||||
return fl.Field().String() != ""
|
||||
}
|
||||
case constant.GroupChatType, constant.SuperGroupChatType:
|
||||
if fl.FieldName() == "GroupID" {
|
||||
return fl.Field().String() != ""
|
||||
}
|
||||
default:
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/msg"
|
||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
||||
)
|
||||
|
||||
type MessageInterceptorFunc func(ctx context.Context, req *msg.SendMsgReq) (*sdkws.MsgData, error)
|
||||
|
||||
func MessageHasReadEnabled(_ context.Context, req *msg.SendMsgReq) (*sdkws.MsgData, error) {
|
||||
switch req.MsgData.ContentType {
|
||||
case constant.HasReadReceipt:
|
||||
if config.Config.SingleMessageHasReadReceiptEnable {
|
||||
return req.MsgData, nil
|
||||
} else {
|
||||
return nil, errs.ErrMessageHasReadDisable.Wrap()
|
||||
}
|
||||
case constant.GroupHasReadReceipt:
|
||||
if config.Config.GroupMessageHasReadReceiptEnable {
|
||||
return req.MsgData, nil
|
||||
} else {
|
||||
return nil, errs.ErrMessageHasReadDisable.Wrap()
|
||||
}
|
||||
}
|
||||
return req.MsgData, nil
|
||||
}
|
||||
func MessageModifyCallback(ctx context.Context, req *msg.SendMsgReq) (*sdkws.MsgData, error) {
|
||||
if err := CallbackMsgModify(ctx, req); err != nil && err != errs.ErrCallbackContinue {
|
||||
log.ZWarn(ctx, "CallbackMsgModify failed", err, "req", req.String())
|
||||
return nil, err
|
||||
}
|
||||
return req.MsgData, nil
|
||||
}
|
||||
func MessageBeforeSendCallback(ctx context.Context, req *msg.SendMsgReq) (*sdkws.MsgData, error) {
|
||||
switch req.MsgData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
if err := CallbackBeforeSendSingleMsg(ctx, req); err != nil && err != errs.ErrCallbackContinue {
|
||||
log.ZWarn(ctx, "CallbackBeforeSendSingleMsg failed", err, "req", req.String())
|
||||
return nil, err
|
||||
}
|
||||
case constant.GroupChatType:
|
||||
if err := CallbackBeforeSendGroupMsg(ctx, req); err != nil && err != errs.ErrCallbackContinue {
|
||||
log.ZWarn(ctx, "CallbackBeforeSendGroupMsg failed", err, "req", req.String())
|
||||
return nil, err
|
||||
}
|
||||
case constant.NotificationChatType:
|
||||
case constant.SuperGroupChatType:
|
||||
if err := CallbackBeforeSendGroupMsg(ctx, req); err != nil && err != errs.ErrCallbackContinue {
|
||||
log.ZWarn(ctx, "CallbackBeforeSendGroupMsg failed", err, "req", req.String())
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, errs.ErrArgs.Wrap("unknown sessionType")
|
||||
}
|
||||
return req.MsgData, nil
|
||||
}
|
Loading…
Reference in new issue