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.
60 lines
1.9 KiB
60 lines
1.9 KiB
package friend
|
|
|
|
import (
|
|
cbApi "Open_IM/pkg/callback_struct"
|
|
"Open_IM/pkg/common/config"
|
|
"Open_IM/pkg/common/constant"
|
|
"Open_IM/pkg/common/http"
|
|
"Open_IM/pkg/common/log"
|
|
"Open_IM/pkg/common/tracelog"
|
|
pbFriend "Open_IM/pkg/proto/friend"
|
|
"context"
|
|
|
|
//"Open_IM/pkg/proto/msg"
|
|
"Open_IM/pkg/utils"
|
|
http2 "net/http"
|
|
)
|
|
|
|
func callbackBeforeAddFriendV1(ctx context.Context, req *pbFriend.AddFriendReq) error {
|
|
resp := callbackBeforeAddFriend(ctx, req)
|
|
if resp.ErrCode != 0 {
|
|
return (&constant.ErrInfo{
|
|
ErrCode: resp.ErrCode,
|
|
ErrMsg: resp.ErrMsg,
|
|
}).Wrap()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func callbackBeforeAddFriend(ctx context.Context, req *pbFriend.AddFriendReq) cbApi.CommonCallbackResp {
|
|
callbackResp := cbApi.CommonCallbackResp{OperationID: tracelog.GetOperationID(ctx)}
|
|
if !config.Config.Callback.CallbackBeforeAddFriend.Enable {
|
|
return callbackResp
|
|
}
|
|
|
|
commonCallbackReq := &cbApi.CallbackBeforeAddFriendReq{
|
|
CallbackCommand: constant.CallbackBeforeAddFriendCommand,
|
|
FromUserID: req.FromUserID,
|
|
ToUserID: req.ToUserID,
|
|
ReqMsg: req.ReqMsg,
|
|
OperationID: tracelog.GetOperationID(ctx),
|
|
}
|
|
resp := &cbApi.CallbackBeforeAddFriendResp{
|
|
CommonCallbackResp: &callbackResp,
|
|
}
|
|
//utils.CopyStructFields(req, msg.MsgData)
|
|
defer log.NewDebug(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), commonCallbackReq, *resp)
|
|
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil {
|
|
callbackResp.ErrCode = http2.StatusInternalServerError
|
|
callbackResp.ErrMsg = err.Error()
|
|
if !*config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue {
|
|
callbackResp.ActionCode = constant.ActionForbidden
|
|
return callbackResp
|
|
} else {
|
|
callbackResp.ActionCode = constant.ActionAllow
|
|
return callbackResp
|
|
}
|
|
}
|
|
return callbackResp
|
|
}
|