Files
open-im-server/internal/rpc/friend/callback.go
T

35 lines
1.1 KiB
Go
Raw Normal View History

2022-02-28 17:57:03 +08:00
package friend
2022-10-19 21:06:48 +08:00
import (
2023-02-01 11:15:39 +08:00
"context"
2023-06-09 19:44:45 +08:00
2023-03-16 10:46:06 +08:00
cbapi "github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/http"
2023-03-21 12:28:21 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
2023-06-09 19:44:45 +08:00
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
2023-03-16 10:46:06 +08:00
pbfriend "github.com/OpenIMSDK/Open-IM-Server/pkg/proto/friend"
2022-10-19 21:06:48 +08:00
)
2023-02-15 15:50:52 +08:00
func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error {
2022-10-19 21:06:48 +08:00
if !config.Config.Callback.CallbackBeforeAddFriend.Enable {
2023-02-15 15:50:52 +08:00
return nil
2022-10-19 21:06:48 +08:00
}
2023-02-15 15:50:52 +08:00
cbReq := &cbapi.CallbackBeforeAddFriendReq{
2022-10-19 21:06:48 +08:00
CallbackCommand: constant.CallbackBeforeAddFriendCommand,
2023-02-01 11:15:39 +08:00
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
2022-10-19 21:06:48 +08:00
ReqMsg: req.ReqMsg,
2023-03-21 12:28:21 +08:00
OperationID: mcontext.GetOperationID(ctx),
2022-10-19 21:06:48 +08:00
}
2023-02-15 15:50:52 +08:00
resp := &cbapi.CallbackBeforeAddFriendResp{}
2023-06-09 19:44:45 +08:00
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil {
if err == errs.ErrCallbackContinue {
return nil
}
return err
}
return nil
2022-10-19 21:06:48 +08:00
}