2023-09-22 19:32:04 +08:00
|
|
|
// Copyright © 2023 OpenIM. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-01-26 10:02:53 +08:00
|
|
|
|
2023-09-22 19:32:04 +08:00
|
|
|
pbuser "github.com/OpenIMSDK/protocol/user"
|
|
|
|
"github.com/OpenIMSDK/tools/utils"
|
|
|
|
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/http"
|
|
|
|
)
|
|
|
|
|
2024-03-05 17:53:22 +08:00
|
|
|
func CallbackBeforeUpdateUserInfo(ctx context.Context, globalConfig *config.GlobalConfig, req *pbuser.UpdateUserInfoReq) error {
|
|
|
|
if !globalConfig.Callback.CallbackBeforeUpdateUserInfo.Enable {
|
2023-09-22 19:32:04 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cbReq := &cbapi.CallbackBeforeUpdateUserInfoReq{
|
2023-11-28 15:26:46 +08:00
|
|
|
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoCommand,
|
2023-09-22 19:32:04 +08:00
|
|
|
UserID: req.UserInfo.UserID,
|
|
|
|
FaceURL: &req.UserInfo.FaceURL,
|
|
|
|
Nickname: &req.UserInfo.Nickname,
|
|
|
|
}
|
|
|
|
resp := &cbapi.CallbackBeforeUpdateUserInfoResp{}
|
2024-03-05 17:53:22 +08:00
|
|
|
if err := http.CallBackPostReturn(ctx, globalConfig.Callback.CallbackUrl, cbReq, resp, globalConfig.Callback.CallbackBeforeUpdateUserInfo); err != nil {
|
2023-09-22 19:32:04 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
utils.NotNilReplace(&req.UserInfo.FaceURL, resp.FaceURL)
|
|
|
|
utils.NotNilReplace(&req.UserInfo.Ex, resp.Ex)
|
|
|
|
utils.NotNilReplace(&req.UserInfo.Nickname, resp.Nickname)
|
|
|
|
return nil
|
|
|
|
}
|
2024-03-05 17:53:22 +08:00
|
|
|
func CallbackAfterUpdateUserInfo(ctx context.Context, globalConfig *config.GlobalConfig, req *pbuser.UpdateUserInfoReq) error {
|
|
|
|
if !globalConfig.Callback.CallbackAfterUpdateUserInfo.Enable {
|
2023-11-28 15:26:46 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cbReq := &cbapi.CallbackAfterUpdateUserInfoReq{
|
|
|
|
CallbackCommand: cbapi.CallbackAfterUpdateUserInfoCommand,
|
|
|
|
UserID: req.UserInfo.UserID,
|
|
|
|
FaceURL: req.UserInfo.FaceURL,
|
|
|
|
Nickname: req.UserInfo.Nickname,
|
|
|
|
}
|
|
|
|
resp := &cbapi.CallbackAfterUpdateUserInfoResp{}
|
2024-03-05 17:53:22 +08:00
|
|
|
if err := http.CallBackPostReturn(ctx, globalConfig.Callback.CallbackUrl, cbReq, resp, globalConfig.Callback.CallbackBeforeUpdateUserInfo); err != nil {
|
2023-11-28 15:26:46 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-03-05 17:53:22 +08:00
|
|
|
func CallbackBeforeUpdateUserInfoEx(ctx context.Context, globalConfig *config.GlobalConfig, req *pbuser.UpdateUserInfoExReq) error {
|
|
|
|
if !globalConfig.Callback.CallbackBeforeUpdateUserInfoEx.Enable {
|
2023-12-28 14:45:27 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cbReq := &cbapi.CallbackBeforeUpdateUserInfoExReq{
|
|
|
|
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoExCommand,
|
|
|
|
UserID: req.UserInfo.UserID,
|
2023-12-29 20:38:43 +08:00
|
|
|
FaceURL: req.UserInfo.FaceURL,
|
|
|
|
Nickname: req.UserInfo.Nickname,
|
2023-12-28 14:45:27 +08:00
|
|
|
}
|
|
|
|
resp := &cbapi.CallbackBeforeUpdateUserInfoExResp{}
|
2024-03-05 17:53:22 +08:00
|
|
|
if err := http.CallBackPostReturn(ctx, globalConfig.Callback.CallbackUrl, cbReq, resp, globalConfig.Callback.CallbackBeforeUpdateUserInfoEx); err != nil {
|
2023-12-28 14:45:27 +08:00
|
|
|
return err
|
|
|
|
}
|
2023-12-29 20:38:43 +08:00
|
|
|
utils.NotNilReplace(req.UserInfo.FaceURL, resp.FaceURL)
|
2023-12-28 14:45:27 +08:00
|
|
|
utils.NotNilReplace(req.UserInfo.Ex, resp.Ex)
|
2023-12-29 20:38:43 +08:00
|
|
|
utils.NotNilReplace(req.UserInfo.Nickname, resp.Nickname)
|
2023-12-28 14:45:27 +08:00
|
|
|
return nil
|
|
|
|
}
|
2024-03-05 17:53:22 +08:00
|
|
|
func CallbackAfterUpdateUserInfoEx(ctx context.Context, globalConfig *config.GlobalConfig, req *pbuser.UpdateUserInfoExReq) error {
|
|
|
|
if !globalConfig.Callback.CallbackAfterUpdateUserInfoEx.Enable {
|
2023-12-28 14:45:27 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cbReq := &cbapi.CallbackAfterUpdateUserInfoExReq{
|
|
|
|
CallbackCommand: cbapi.CallbackAfterUpdateUserInfoExCommand,
|
|
|
|
UserID: req.UserInfo.UserID,
|
|
|
|
FaceURL: req.UserInfo.FaceURL,
|
|
|
|
Nickname: req.UserInfo.Nickname,
|
|
|
|
}
|
|
|
|
resp := &cbapi.CallbackAfterUpdateUserInfoExResp{}
|
2024-03-05 17:53:22 +08:00
|
|
|
if err := http.CallBackPostReturn(ctx, globalConfig.Callback.CallbackUrl, cbReq, resp, globalConfig.Callback.CallbackBeforeUpdateUserInfoEx); err != nil {
|
2023-12-28 14:45:27 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2023-11-28 15:26:46 +08:00
|
|
|
|
2024-03-05 17:53:22 +08:00
|
|
|
func CallbackBeforeUserRegister(ctx context.Context, globalConfig *config.GlobalConfig, req *pbuser.UserRegisterReq) error {
|
|
|
|
if !globalConfig.Callback.CallbackBeforeUserRegister.Enable {
|
2023-11-28 15:26:46 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cbReq := &cbapi.CallbackBeforeUserRegisterReq{
|
|
|
|
CallbackCommand: cbapi.CallbackBeforeUserRegisterCommand,
|
|
|
|
Secret: req.Secret,
|
|
|
|
Users: req.Users,
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := &cbapi.CallbackBeforeUserRegisterResp{}
|
2024-03-05 17:53:22 +08:00
|
|
|
if err := http.CallBackPostReturn(ctx, globalConfig.Callback.CallbackUrl, cbReq, resp, globalConfig.Callback.CallbackBeforeUpdateUserInfo); err != nil {
|
2023-11-28 15:26:46 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(resp.Users) != 0 {
|
|
|
|
req.Users = resp.Users
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-05 17:53:22 +08:00
|
|
|
func CallbackAfterUserRegister(ctx context.Context, globalConfig *config.GlobalConfig, req *pbuser.UserRegisterReq) error {
|
|
|
|
if !globalConfig.Callback.CallbackAfterUserRegister.Enable {
|
2023-11-28 15:26:46 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
cbReq := &cbapi.CallbackAfterUserRegisterReq{
|
|
|
|
CallbackCommand: cbapi.CallbackAfterUserRegisterCommand,
|
|
|
|
Secret: req.Secret,
|
|
|
|
Users: req.Users,
|
|
|
|
}
|
|
|
|
|
2023-11-30 10:10:48 +08:00
|
|
|
resp := &cbapi.CallbackAfterUserRegisterResp{}
|
2024-03-05 17:53:22 +08:00
|
|
|
if err := http.CallBackPostReturn(ctx, globalConfig.Callback.CallbackUrl, cbReq, resp, globalConfig.Callback.CallbackAfterUpdateUserInfo); err != nil {
|
2023-11-28 15:26:46 +08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|