mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-29 00:39:18 +08:00
callback add
This commit is contained in:
parent
0bed7ee669
commit
dcfd802757
@ -8,7 +8,7 @@ etcd:
|
||||
etcdAddr: [ 127.0.0.1:2379 ] #单机部署时,默认即可
|
||||
|
||||
mysql:
|
||||
dbMysqlAddress: [ 43.128.5.63:13306 ] #mysql地址 目前仅支持单机,默认即可
|
||||
dbMysqlAddress: [ 127.0.0.1:13306 ] #mysql地址 目前仅支持单机,默认即可
|
||||
dbMysqlUserName: root #mysql用户名,建议修改
|
||||
dbMysqlPassword: openIM # mysql密码,建议修改
|
||||
dbMysqlDatabaseName: openIM_v2 #默认即可
|
||||
@ -19,7 +19,7 @@ mysql:
|
||||
dbMaxLifeTime: 120
|
||||
|
||||
mongo:
|
||||
dbAddress: [ 43.128.5.63:37017 ] #redis地址 目前仅支持单机,默认即可
|
||||
dbAddress: [ 127.0.0.1:37017 ] #redis地址 目前仅支持单机,默认即可
|
||||
dbDirect: false
|
||||
dbTimeout: 10
|
||||
dbDatabase: openIM #mongo db 默认即可
|
||||
@ -30,7 +30,7 @@ mongo:
|
||||
dbRetainChatRecords: 3650 #mongo保存离线消息时间(天),根据需求修改
|
||||
|
||||
redis:
|
||||
dbAddress: 43.128.5.63:16379 #redis地址 目前仅支持单机,默认即可
|
||||
dbAddress: 127.0.0.1:16379 #redis地址 目前仅支持单机,默认即可
|
||||
dbMaxIdle: 128
|
||||
dbMaxActive: 0
|
||||
dbIdleTimeout: 120
|
||||
|
@ -42,6 +42,7 @@ func init() {
|
||||
return
|
||||
}
|
||||
}
|
||||
// 自动化桶public的代码
|
||||
//err = minioClient.SetBucketPolicy(context.Background(), config.Config.Credential.Minio.Bucket, policy.BucketPolicyReadWrite)
|
||||
//if err != nil {
|
||||
// log.NewError("", utils.GetSelfFuncName(), "SetBucketPolicy failed please set in ", err.Error())
|
||||
|
@ -12,16 +12,19 @@ import (
|
||||
|
||||
func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable || msg.MsgData.ContentType != constant.Text {
|
||||
if !config.Config.Callback.CallbackbeforeSendSingleMsg.Enable {
|
||||
return true, nil
|
||||
}
|
||||
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq:cbApi.CommonCallbackReq{
|
||||
}}
|
||||
resp := &cbApi.CallbackBeforeSendSingleMsgResp{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.CallbackbeforeSendSingleMsg.CallbackTimeOut); err != nil && !config.Config.Callback.CallbackbeforeSendSingleMsg.CallbackFailedContinue{
|
||||
return false, err
|
||||
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
|
||||
}
|
||||
}
|
||||
if resp.ActionCode == constant.ActionForbidden {
|
||||
return false, nil
|
||||
@ -32,13 +35,14 @@ func callbackBeforeSendSingleMsg(msg *pbChat.SendMsgReq) (canSend bool, err erro
|
||||
|
||||
func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable || msg.MsgData.ContentType != constant.Text {
|
||||
if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable {
|
||||
return nil
|
||||
}
|
||||
req := cbApi.CallbackAfterSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
|
||||
resp := &cbApi.CallbackAfterSendSingleMsgResp{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.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil && config.Config.Callback.CallbackAfterSendSingleMsg.CallbackFailedContinue{
|
||||
if err := http.PostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendSingleMsg.CallbackTimeOut); err != nil{
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -47,14 +51,17 @@ func callbackAfterSendSingleMsg(msg *pbChat.SendMsgReq) error {
|
||||
|
||||
func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable || msg.MsgData.ContentType != constant.Text {
|
||||
if !config.Config.Callback.CallbackBeforeSendGroupMsg.Enable {
|
||||
return true, nil
|
||||
}
|
||||
req := cbApi.CallbackBeforeSendSingleMsgReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
|
||||
resp := &cbApi.CallbackBeforeSendGroupMsgResp{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.CallbackBeforeSendGroupMsg.CallbackTimeOut); err != nil && !config.Config.Callback.CallbackBeforeSendGroupMsg.CallbackFailedContinue{
|
||||
return false, nil
|
||||
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
|
||||
}
|
||||
}
|
||||
if resp.ActionCode == constant.ActionForbidden {
|
||||
return false, nil
|
||||
@ -64,9 +71,16 @@ func callbackBeforeSendGroupMsg(msg *pbChat.SendMsgReq) (canSend bool, err error
|
||||
|
||||
func callbackAfterSendGroupMsg(msg *pbChat.SendMsgReq) error {
|
||||
log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), msg)
|
||||
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable || msg.MsgData.ContentType != constant.Text {
|
||||
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
|
||||
return nil
|
||||
}
|
||||
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
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -76,13 +90,17 @@ func callBackWordFilter(msg *pbChat.SendMsgReq) (canSend bool, err error) {
|
||||
if !config.Config.Callback.CallbackWordFilter.Enable || msg.MsgData.ContentType != constant.Text {
|
||||
return true, nil
|
||||
}
|
||||
req := cbApi.CallBackWordFilterReq{
|
||||
CommonCallbackReq: cbApi.CommonCallbackReq{},
|
||||
}
|
||||
resp := cbApi.CallBackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||
req := cbApi.CallbackWordFilterReq{CommonCallbackReq: cbApi.CommonCallbackReq{}}
|
||||
resp := &cbApi.CallbackWordFilterResp{CommonCallbackResp: cbApi.CommonCallbackResp{}}
|
||||
defer log.NewDebug(msg.OperationID, utils.GetSelfFuncName(), req, resp)
|
||||
utils.CopyStructFields(&req, msg.MsgData)
|
||||
if err := http.PostReturn(msg.OperationID, req, &resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil {
|
||||
return false, err
|
||||
if err := http.PostReturn(msg.OperationID, req, resp, config.Config.Callback.CallbackWordFilter.CallbackTimeOut); err != nil {
|
||||
if !config.Config.Callback.CallbackWordFilter.CallbackFailedContinue {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
if resp.ActionCode == constant.ActionForbidden {
|
||||
return false, nil
|
||||
}
|
||||
msg.MsgData.Content = resp.Content
|
||||
return true, nil
|
||||
|
@ -131,7 +131,7 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
||||
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "CallbackBeforeSendMsg failed", err.Error(), pb.MsgData)
|
||||
}
|
||||
if !canSend {
|
||||
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return")
|
||||
log.NewDebug(pb.OperationID, utils.GetSelfFuncName(), "callback result", canSend, "end rpc and return", pb.MsgData)
|
||||
return returnMsg(&replay, pb, 201, "callback result stop rpc and return", "", 0)
|
||||
}
|
||||
switch pb.MsgData.SessionType {
|
||||
|
@ -164,28 +164,41 @@ func GetRangeDate(from, to time.Time) [][2]time.Time {
|
||||
}
|
||||
// month
|
||||
case !isInOneMonth(from, to):
|
||||
for i := 0; ; i++ {
|
||||
if i == 0 {
|
||||
fromTime := from
|
||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
} else {
|
||||
fromTime := getFirstDateOfNextNMonth(from, i)
|
||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
||||
if toTime.After(to) {
|
||||
toTime = to
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
if to.Sub(from) < time.Hour * 24 * 30 {
|
||||
for i := 0; ; i++ {
|
||||
fromTime := from.Add(time.Hour * 24 * time.Duration(i))
|
||||
toTime := from.Add(time.Hour * 24 * time.Duration(i+1))
|
||||
if toTime.After(to.Add(time.Hour * 24)) {
|
||||
break
|
||||
}
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
for i := 0; ; i++ {
|
||||
if i == 0 {
|
||||
fromTime := from
|
||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
} else {
|
||||
fromTime := getFirstDateOfNextNMonth(from, i)
|
||||
toTime := getFirstDateOfNextNMonth(fromTime, 1)
|
||||
if toTime.After(to) {
|
||||
toTime = to
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
break
|
||||
}
|
||||
times = append(times, [2]time.Time{
|
||||
fromTime, toTime,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return times
|
||||
|
@ -1,12 +1,16 @@
|
||||
package call_back_struct
|
||||
|
||||
type singleMsg struct {
|
||||
type msg struct {
|
||||
SendID string `json:"sendID"`
|
||||
RecvID string `json:"recvID"`
|
||||
ClientMsgID string `json:"clientMsgID"`
|
||||
ServerMsgID string `json:"serverMsgId"`
|
||||
SendTime int64 `json:"sendTime"`
|
||||
CreateTime int64 `json:"createTime"`
|
||||
Content []byte `json:"content"`
|
||||
}
|
||||
|
||||
type singleMsg struct {
|
||||
msg
|
||||
RecvID string `json:"recvID"`
|
||||
}
|
||||
|
||||
type CallbackBeforeSendSingleMsgReq struct {
|
||||
@ -16,6 +20,7 @@ type CallbackBeforeSendSingleMsgReq struct {
|
||||
|
||||
type CallbackBeforeSendSingleMsgResp struct {
|
||||
CommonCallbackResp
|
||||
singleMsg
|
||||
}
|
||||
|
||||
type CallbackAfterSendSingleMsgReq struct {
|
||||
@ -28,18 +33,22 @@ type CallbackAfterSendSingleMsgResp struct {
|
||||
}
|
||||
|
||||
type groupMsg struct {
|
||||
|
||||
msg
|
||||
GroupID string `json:"groupID"`
|
||||
}
|
||||
|
||||
type CallbackBeforeSendGroupMsgReq struct {
|
||||
CommonCallbackReq
|
||||
groupMsg
|
||||
}
|
||||
|
||||
type CallbackBeforeSendGroupMsgResp struct {
|
||||
CommonCallbackResp
|
||||
groupMsg
|
||||
}
|
||||
|
||||
type CallbackAfterSendGroupMsgReq struct {
|
||||
groupMsg
|
||||
CommonCallbackReq
|
||||
}
|
||||
|
||||
@ -47,15 +56,12 @@ type CallbackAfterSendGroupMsgResp struct {
|
||||
CommonCallbackResp
|
||||
}
|
||||
|
||||
type CallBackWordFilterReq struct {
|
||||
type CallbackWordFilterReq struct {
|
||||
CommonCallbackReq
|
||||
Content []byte `json:"content"`
|
||||
SendID string `json:"SendID"`
|
||||
RecvID string `json:"RecvID"`
|
||||
GroupID string `json:"GroupID"`
|
||||
}
|
||||
|
||||
type CallBackWordFilterResp struct {
|
||||
type CallbackWordFilterResp struct {
|
||||
CommonCallbackResp
|
||||
Content []byte `json:"content"`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user