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/callback.go

116 lines
4.3 KiB

3 years ago
package msg
import (
cbApi "Open_IM/pkg/call_back_struct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
pbChat "Open_IM/pkg/proto/chat"
"Open_IM/pkg/utils"
)
func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
3 years ago
if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable {
3 years ago
return true, nil
}
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{
}}
resp := &cbApi.CallbackBeforeSendSingleMsgResp{CommonCallbackResp:cbApi.CommonCallbackResp{
}}
3 years ago
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
3 years ago
utils.CopyStructFields(req, msg.MsgData)
3 years ago
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil{
if !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue {
return false, err
}
3 years ago
}
if resp.ActionCode == constant.ActionForbidden {
return false, nil
}
return true, nil
}
func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
3 years ago
if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable {
3 years ago
return nil
}
req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
3 years ago
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
3 years ago
utils.CopyStructFields(req, msg.MsgData)
3 years ago
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{
3 years ago
return err
}
return nil
}
func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
3 years ago
if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable {
3 years ago
return true, nil
}
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
3 years ago
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
3 years ago
utils.CopyStructFields(req, msg.MsgData)
3 years ago
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil {
if !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue {
return false, nil
}
3 years ago
} else {
if resp.ActionCode == constant.ActionForbidden {
return false, nil
}
3 years ago
}
return true, nil
}
func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
3 years ago
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
3 years ago
return nil
}
3 years ago
req := cbApi.CallbackAfterSendGroupMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
utils.CopyStructFields(req, msg.MsgData)
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
return err
}
3 years ago
return nil
}
func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text {
return true, nil
}
3 years ago
req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
3 years ago
utils.CopyStructFields(&req, msg.MsgData)
3 years ago
req.Content = string(msg.MsgData.Content)
3 years ago
if err := http.PostReturn(msg.OperationID, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil {
if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue {
return false, err
}
3 years ago
} else {
msg.MsgData.Content = []byte(resp.Content)
if resp.ActionCode == constant.ActionForbidden {
return false, nil
}
3 years ago
}
3 years ago
return true, nil
}