|
|
@ -7,17 +7,19 @@ import (
|
|
|
|
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
|
|
"Open_IM/pkg/common/db/mysql_model/im_mysql_model"
|
|
|
|
"Open_IM/pkg/common/http"
|
|
|
|
"Open_IM/pkg/common/http"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
|
|
|
|
"Open_IM/pkg/common/trace_log"
|
|
|
|
pbGroup "Open_IM/pkg/proto/group"
|
|
|
|
pbGroup "Open_IM/pkg/proto/group"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
http2 "net/http"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
|
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
|
|
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallbackResp {
|
|
|
|
func callbackBeforeCreateGroup(ctx context.Context, req *pbGroup.CreateGroupReq) (isPass bool, err error) {
|
|
|
|
callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID}
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
trace_log.SetContextInfo(ctx, utils.GetSelfFuncName(), err, "req", req, "isPass", isPass, "err", err)
|
|
|
|
|
|
|
|
}()
|
|
|
|
if !config.Config.Callback.CallbackBeforeCreateGroup.Enable {
|
|
|
|
if !config.Config.Callback.CallbackBeforeCreateGroup.Enable {
|
|
|
|
return callbackResp
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), req.String())
|
|
|
|
log.NewDebug(req.OperationID, utils.GetSelfFuncName(), req.String())
|
|
|
|
commonCallbackReq := &cbApi.CallbackBeforeCreateGroupReq{
|
|
|
|
commonCallbackReq := &cbApi.CallbackBeforeCreateGroupReq{
|
|
|
@ -26,23 +28,15 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback
|
|
|
|
GroupInfo: *req.GroupInfo,
|
|
|
|
GroupInfo: *req.GroupInfo,
|
|
|
|
InitMemberList: req.InitMemberList,
|
|
|
|
InitMemberList: req.InitMemberList,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID}
|
|
|
|
resp := &cbApi.CallbackBeforeCreateGroupResp{
|
|
|
|
resp := &cbApi.CallbackBeforeCreateGroupResp{
|
|
|
|
CommonCallbackResp: &callbackResp,
|
|
|
|
CommonCallbackResp: &callbackResp,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//utils.CopyStructFields(req, msg.MsgData)
|
|
|
|
//utils.CopyStructFields(req, msg.MsgData)
|
|
|
|
defer log.NewDebug(req.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp)
|
|
|
|
defer log.NewDebug(req.OperationID, utils.GetSelfFuncName(), commonCallbackReq, *resp)
|
|
|
|
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeCreateGroupCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeCreateGroup.CallbackTimeOut); err != nil {
|
|
|
|
isPass, err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeCreateGroupCommand, commonCallbackReq,
|
|
|
|
callbackResp.ErrCode = http2.StatusInternalServerError
|
|
|
|
resp, config.Config.Callback.CallbackBeforeCreateGroup.CallbackTimeOut, &config.Config.Callback.CallbackBeforeCreateGroup.CallbackFailedContinue)
|
|
|
|
callbackResp.ErrMsg = err.Error()
|
|
|
|
if isPass && err == nil {
|
|
|
|
if !config.Config.Callback.CallbackBeforeCreateGroup.CallbackFailedContinue {
|
|
|
|
|
|
|
|
callbackResp.ActionCode = constant.ActionForbidden
|
|
|
|
|
|
|
|
return callbackResp
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
callbackResp.ActionCode = constant.ActionAllow
|
|
|
|
|
|
|
|
return callbackResp
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
|
|
|
|
|
|
|
|
if resp.GroupID != nil {
|
|
|
|
if resp.GroupID != nil {
|
|
|
|
req.GroupInfo.GroupID = *resp.GroupID
|
|
|
|
req.GroupInfo.GroupID = *resp.GroupID
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -80,13 +74,16 @@ func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallback
|
|
|
|
req.GroupInfo.LookMemberInfo = *resp.LookMemberInfo
|
|
|
|
req.GroupInfo.LookMemberInfo = *resp.LookMemberInfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return callbackResp
|
|
|
|
return isPass, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func CallbackBeforeMemberJoinGroup(operationID string, groupMember *im_mysql_model.GroupMember, groupEx string) cbApi.CommonCallbackResp {
|
|
|
|
func CallbackBeforeMemberJoinGroup(ctx context.Context, operationID string, groupMember *im_mysql_model.GroupMember, groupEx string) (isPass bool, err error) {
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
trace_log.SetContextInfo(ctx, "CallbackBeforeMemberJoinGroup", err, "groupMember", *groupMember, "groupEx", groupEx, "isPass", isPass)
|
|
|
|
|
|
|
|
}()
|
|
|
|
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
|
|
|
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
|
|
|
|
if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable {
|
|
|
|
if !config.Config.Callback.CallbackBeforeMemberJoinGroup.Enable {
|
|
|
|
return callbackResp
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.NewDebug(operationID, "args: ", *groupMember)
|
|
|
|
log.NewDebug(operationID, "args: ", *groupMember)
|
|
|
|
callbackReq := cbApi.CallbackBeforeMemberJoinGroupReq{
|
|
|
|
callbackReq := cbApi.CallbackBeforeMemberJoinGroupReq{
|
|
|
@ -100,39 +97,35 @@ func CallbackBeforeMemberJoinGroup(operationID string, groupMember *im_mysql_mod
|
|
|
|
resp := &cbApi.CallbackBeforeMemberJoinGroupResp{
|
|
|
|
resp := &cbApi.CallbackBeforeMemberJoinGroupResp{
|
|
|
|
CommonCallbackResp: &callbackResp,
|
|
|
|
CommonCallbackResp: &callbackResp,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeMemberJoinGroupCommand, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackTimeOut); err != nil {
|
|
|
|
isPass, err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeMemberJoinGroupCommand, callbackReq,
|
|
|
|
callbackResp.ErrCode = http2.StatusInternalServerError
|
|
|
|
resp, config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackTimeOut, &config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackFailedContinue)
|
|
|
|
callbackResp.ErrMsg = err.Error()
|
|
|
|
if isPass && err == nil {
|
|
|
|
if !config.Config.Callback.CallbackBeforeMemberJoinGroup.CallbackFailedContinue {
|
|
|
|
if resp.MuteEndTime != nil {
|
|
|
|
callbackResp.ActionCode = constant.ActionForbidden
|
|
|
|
groupMember.MuteEndTime = utils.UnixSecondToTime(*resp.MuteEndTime)
|
|
|
|
return callbackResp
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if resp.FaceURL != nil {
|
|
|
|
callbackResp.ActionCode = constant.ActionAllow
|
|
|
|
groupMember.FaceURL = *resp.FaceURL
|
|
|
|
return callbackResp
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Ex != nil {
|
|
|
|
|
|
|
|
groupMember.Ex = *resp.Ex
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.NickName != nil {
|
|
|
|
|
|
|
|
groupMember.Nickname = *resp.NickName
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.RoleLevel != nil {
|
|
|
|
|
|
|
|
groupMember.RoleLevel = *resp.RoleLevel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if resp.MuteEndTime != nil {
|
|
|
|
return isPass, err
|
|
|
|
groupMember.MuteEndTime = utils.UnixSecondToTime(*resp.MuteEndTime)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.FaceURL != nil {
|
|
|
|
|
|
|
|
groupMember.FaceURL = *resp.FaceURL
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Ex != nil {
|
|
|
|
|
|
|
|
groupMember.Ex = *resp.Ex
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.NickName != nil {
|
|
|
|
|
|
|
|
groupMember.Nickname = *resp.NickName
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.RoleLevel != nil {
|
|
|
|
|
|
|
|
groupMember.RoleLevel = *resp.RoleLevel
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return callbackResp
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func CallbackBeforeSetGroupMemberInfo(req *pbGroup.SetGroupMemberInfoReq) cbApi.CommonCallbackResp {
|
|
|
|
func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGroupMemberInfoReq) (isPass bool, err error) {
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
trace_log.SetContextInfo(ctx, "CallbackBeforeSetGroupMemberInfo", err, "req", *req)
|
|
|
|
|
|
|
|
}()
|
|
|
|
callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID}
|
|
|
|
callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID}
|
|
|
|
if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.Enable {
|
|
|
|
if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.Enable {
|
|
|
|
return callbackResp
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callbackReq := cbApi.CallbackBeforeSetGroupMemberInfoReq{
|
|
|
|
callbackReq := cbApi.CallbackBeforeSetGroupMemberInfoReq{
|
|
|
|
CallbackCommand: constant.CallbackBeforeSetGroupMemberInfoCommand,
|
|
|
|
CallbackCommand: constant.CallbackBeforeSetGroupMemberInfoCommand,
|
|
|
@ -155,29 +148,21 @@ func CallbackBeforeSetGroupMemberInfo(req *pbGroup.SetGroupMemberInfoReq) cbApi.
|
|
|
|
resp := &cbApi.CallbackBeforeSetGroupMemberInfoResp{
|
|
|
|
resp := &cbApi.CallbackBeforeSetGroupMemberInfoResp{
|
|
|
|
CommonCallbackResp: &callbackResp,
|
|
|
|
CommonCallbackResp: &callbackResp,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
isPass, err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetGroupMemberInfoCommand, callbackReq,
|
|
|
|
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetGroupMemberInfoCommand, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackTimeOut); err != nil {
|
|
|
|
resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackTimeOut, &config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackFailedContinue)
|
|
|
|
callbackResp.ErrCode = http2.StatusInternalServerError
|
|
|
|
if isPass && err == nil {
|
|
|
|
callbackResp.ErrMsg = err.Error()
|
|
|
|
if resp.FaceURL != nil {
|
|
|
|
if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackFailedContinue {
|
|
|
|
req.FaceURL = &wrapperspb.StringValue{Value: *resp.FaceURL}
|
|
|
|
callbackResp.ActionCode = constant.ActionForbidden
|
|
|
|
}
|
|
|
|
return callbackResp
|
|
|
|
if resp.Nickname != nil {
|
|
|
|
} else {
|
|
|
|
req.Nickname = &wrapperspb.StringValue{Value: *resp.Nickname}
|
|
|
|
callbackResp.ActionCode = constant.ActionAllow
|
|
|
|
}
|
|
|
|
return callbackResp
|
|
|
|
if resp.RoleLevel != nil {
|
|
|
|
|
|
|
|
req.RoleLevel = &wrapperspb.Int32Value{Value: *resp.RoleLevel}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Ex != nil {
|
|
|
|
|
|
|
|
req.Ex = &wrapperspb.StringValue{Value: *resp.Ex}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if resp.FaceURL != nil {
|
|
|
|
return isPass, err
|
|
|
|
req.FaceURL = &wrapperspb.StringValue{Value: *resp.FaceURL}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Nickname != nil {
|
|
|
|
|
|
|
|
req.Nickname = &wrapperspb.StringValue{Value: *resp.Nickname}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.RoleLevel != nil {
|
|
|
|
|
|
|
|
req.RoleLevel = &wrapperspb.Int32Value{Value: *resp.RoleLevel}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Ex != nil {
|
|
|
|
|
|
|
|
req.Ex = &wrapperspb.StringValue{Value: *resp.Ex}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return callbackResp
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|