commit
b2a9867297
@ -1 +1 @@
|
||||
Subproject commit 992f76df0ee500a0377523b0780d3a85f2275755
|
||||
Subproject commit 1c6c7af5393b3e9eefbaf16b673519ca863a6c2c
|
@ -0,0 +1 @@
|
||||
package auth
|
@ -0,0 +1 @@
|
||||
package friend
|
@ -0,0 +1,9 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
pbGroup "Open_IM/pkg/proto/group"
|
||||
)
|
||||
|
||||
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) (bool, error) {
|
||||
return true, nil
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
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 copyCallbackCommonReqStruct(msg *pbChat.SendMsgReq) cbApi.CommonCallbackReq {
|
||||
return cbApi.CommonCallbackReq{
|
||||
SendID: msg.MsgData.SendID,
|
||||
ServerMsgID: msg.MsgData.ServerMsgID,
|
||||
ClientMsgID: msg.MsgData.ClientMsgID,
|
||||
OperationID: msg.OperationID,
|
||||
SenderPlatformID: msg.MsgData.SenderPlatformID,
|
||||
SenderNickname: msg.MsgData.SenderNickname,
|
||||
SessionType: msg.MsgData.SessionType,
|
||||
MsgFrom: msg.MsgData.MsgFrom,
|
||||
ContentType: msg.MsgData.ContentType,
|
||||
Status: msg.MsgData.Status,
|
||||
CreateTime: msg.MsgData.CreateTime,
|
||||
Content: string(msg.MsgData.Content),
|
||||
}
|
||||
}
|
||||
|
||||
func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||
if !config.Config.Callback.CallbackBeforeSendSingleMsg.Enable {
|
||||
return true, nil
|
||||
}
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendSingleMsgCommand
|
||||
req := cbApi.CallbackBeforeSendSingleMsgReq{
|
||||
CommonCallbackReq: commonCallbackReq,
|
||||
RecvID: msg.MsgData.RecvID,
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeSendSingleMsgResp{
|
||||
CommonCallbackResp: cbApi.CommonCallbackResp{},
|
||||
}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
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
|
||||
} else {
|
||||
return true, err
|
||||
}
|
||||
} else {
|
||||
if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
|
||||
if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable {
|
||||
return nil
|
||||
}
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||
commonCallbackReq.CallbackCommand = constant.CallbackAfterSendSingleMsgCommand
|
||||
req := cbApi.CallbackAfterSendSingleMsgReq{
|
||||
CommonCallbackReq: commonCallbackReq,
|
||||
RecvID: msg.MsgData.RecvID,
|
||||
}
|
||||
resp := &cbApi.CallbackAfterSendSingleMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||
if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable {
|
||||
return true, nil
|
||||
}
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||
commonCallbackReq.CallbackCommand = constant.CallbackBeforeSendGroupMsgCommand
|
||||
req := cbApi.CallbackAfterSendGroupMsgReq{
|
||||
CommonCallbackReq: commonCallbackReq,
|
||||
GroupID: msg.MsgData.GroupID,
|
||||
}
|
||||
resp := &cbApi.CallbackBeforeSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
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, err
|
||||
} else {
|
||||
return true, err
|
||||
}
|
||||
} else {
|
||||
if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
|
||||
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
|
||||
return nil
|
||||
}
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||
commonCallbackReq.CallbackCommand = constant.CallbackAfterSendGroupMsgCommand
|
||||
req := cbApi.CallbackAfterSendGroupMsgReq{
|
||||
CommonCallbackReq: commonCallbackReq,
|
||||
GroupID: msg.MsgData.GroupID,
|
||||
}
|
||||
resp := &cbApi.CallbackAfterSendGroupMsgResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||
|
||||
//utils.CopyStructFields(req, msg.MsgData)
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func callbackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||
if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text {
|
||||
return true, nil
|
||||
}
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
commonCallbackReq := copyCallbackCommonReqStruct(msg)
|
||||
commonCallbackReq.CallbackCommand = constant.CallbackWordFilterCommand
|
||||
req := cbApi.CallbackWordFilterReq{
|
||||
CommonCallbackReq: commonCallbackReq,
|
||||
}
|
||||
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||
//utils.CopyStructFields(&req., msg.MsgData)
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, *resp)
|
||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil {
|
||||
if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue {
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), "callback failed and config disable, stop this operation")
|
||||
return false, err
|
||||
} else {
|
||||
return true, err
|
||||
}
|
||||
} else {
|
||||
if resp.ActionCode == constant.ActionForbidden && resp.ErrCode == constant.CallbackHandleSuccess {
|
||||
return false, nil
|
||||
}
|
||||
if resp.ErrCode == constant.CallbackHandleSuccess {
|
||||
msg.MsgData.Content = []byte(resp.Content)
|
||||
}
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), string(msg.MsgData.Content))
|
||||
}
|
||||
return true, err
|
||||
}
|
@ -0,0 +1 @@
|
||||
package user
|
@ -0,0 +1 @@
|
||||
package utils
|
@ -1 +1,26 @@
|
||||
package call_back_struct
|
||||
|
||||
type CommonCallbackReq struct {
|
||||
SendID string `json:"sendID"`
|
||||
CallbackCommand string `json:"callbackCommand"`
|
||||
ServerMsgID string `json:"serverMsgID"`
|
||||
ClientMsgID string `json:"clientMsgID"`
|
||||
OperationID string `json:"operationID"`
|
||||
SenderPlatformID int32 `json:"senderPlatformID"`
|
||||
SenderNickname string `json:"senderNickname"`
|
||||
SessionType int32 `json:"sessionType"`
|
||||
MsgFrom int32 `json:"msgFrom"`
|
||||
ContentType int32 `json:"contentType"`
|
||||
Status int32 `json:"status"`
|
||||
CreateTime int64 `json:"createTime"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
type CommonCallbackResp struct {
|
||||
ActionCode int `json:"actionCode"`
|
||||
ErrCode int `json:"errCode"`
|
||||
ErrMsg string `json:"errMsg"`
|
||||
OperationID string `json:"operationID"`
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package call_back_struct
|
||||
|
||||
type CallbackBeforeCreateGroupReq struct {
|
||||
CommonCallbackReq
|
||||
}
|
||||
|
||||
type CallbackAfterCreateGroupResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
@ -1 +1,47 @@
|
||||
package call_back_struct
|
||||
|
||||
|
||||
type CallbackBeforeSendSingleMsgReq struct {
|
||||
CommonCallbackReq
|
||||
RecvID string `json:"recvID"`
|
||||
}
|
||||
|
||||
type CallbackBeforeSendSingleMsgResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
||||
|
||||
type CallbackAfterSendSingleMsgReq struct {
|
||||
CommonCallbackReq
|
||||
RecvID string `json:"recvID"`
|
||||
}
|
||||
|
||||
type CallbackAfterSendSingleMsgResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
||||
|
||||
type CallbackBeforeSendGroupMsgReq struct {
|
||||
CommonCallbackReq
|
||||
GroupID string `json:"groupID"`
|
||||
}
|
||||
|
||||
type CallbackBeforeSendGroupMsgResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
||||
|
||||
type CallbackAfterSendGroupMsgReq struct {
|
||||
CommonCallbackReq
|
||||
GroupID string `json:"groupID"`
|
||||
}
|
||||
|
||||
type CallbackAfterSendGroupMsgResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
||||
|
||||
type CallbackWordFilterReq struct {
|
||||
CommonCallbackReq
|
||||
}
|
||||
|
||||
type CallbackWordFilterResp struct {
|
||||
CommonCallbackResp
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package statistics
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Statistics struct {
|
||||
Count *uint64
|
||||
ModuleName string
|
||||
PrintArgs string
|
||||
SleepTime int
|
||||
}
|
||||
|
||||
func (s *Statistics) output() {
|
||||
t := time.NewTicker(time.Duration(s.SleepTime) * time.Second)
|
||||
defer t.Stop()
|
||||
//var sum uint64
|
||||
for {
|
||||
//sum = *s.Count
|
||||
select {
|
||||
case <-t.C:
|
||||
}
|
||||
//log.NewWarn("", " system stat ", s.ModuleName, s.PrintArgs, *s.Count-sum, "total:", *s.Count)
|
||||
}
|
||||
}
|
||||
|
||||
func NewStatistics(count *uint64, moduleName, printArgs string, sleepTime int) *Statistics {
|
||||
p := &Statistics{Count: count, ModuleName: moduleName, SleepTime: sleepTime, PrintArgs: printArgs}
|
||||
go p.output()
|
||||
return p
|
||||
}
|
Loading…
Reference in new issue