Skip to content

Commit

Permalink
fix: add callback for update user's info. (#1112)
Browse files Browse the repository at this point in the history
* fix: to start im or chat, ZooKeeper must be started first.

* fix: msg gateway start output err info

Signed-off-by: Gordon <[email protected]>

* fix: msg gateway start output err info

Signed-off-by: Gordon <[email protected]>

* chore: package path changes

Signed-off-by: withchao <[email protected]>

* fix: go mod update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* chore: package path changes

Signed-off-by: withchao <[email protected]>

* chore: package path changes

Signed-off-by: withchao <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: token update

Signed-off-by: Gordon <[email protected]>

* fix: get all userID

Signed-off-by: Gordon <[email protected]>

* fix: msggateway add online status call

Signed-off-by: Gordon <[email protected]>

* refactor: log change

Signed-off-by: Gordon <[email protected]>

* refactor: log change

Signed-off-by: Gordon <[email protected]>

* chore: network mode change

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* feat: add api of get server time

Signed-off-by: Gordon <[email protected]>

* feat: remove go work sum

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: pull message add isRead field

Signed-off-by: Gordon <[email protected]>

* fix: check msg-transfer script

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix:  script update

Signed-off-by: Gordon <[email protected]>

* fix: start don't kill old process

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: check component

Signed-off-by: Gordon <[email protected]>

* fix: pull message set isRead only message come from single.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* fix: multiple gateway kick user each other.

Signed-off-by: Gordon <[email protected]>

* fix: add ex field to update group info.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* cicd: robot automated Change

* refactor: change project module name.

Signed-off-by: Gordon <[email protected]>

* refactor: change project module name.

Signed-off-by: Gordon <[email protected]>

* refactor: change project module name.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* test: for pressure test.

Signed-off-by: Gordon <[email protected]>

* test: for pressure test.

Signed-off-by: Gordon <[email protected]>

* test: for pressure test.

Signed-off-by: Gordon <[email protected]>

* test: message log.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* fxi: component check output valid info.

Signed-off-by: Gordon <[email protected]>

* fxi: component check output valid info.

Signed-off-by: Gordon <[email protected]>

* test: send message test log.

Signed-off-by: Gordon <[email protected]>

* cicd: robot automated Change

* cicd: robot automated Change

* test: remove info log.

Signed-off-by: Gordon <[email protected]>

* feat: api of send message add sendTime field.

Signed-off-by: Gordon <[email protected]>

* fix: add callback for update user's info.

* cicd: robot automated Change

* fix: change callback command name.

---------

Signed-off-by: Gordon <[email protected]>
Signed-off-by: withchao <[email protected]>
Signed-off-by: Gordon <[email protected]>
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: withchao <[email protected]>
Co-authored-by: Xinwei Xiong <[email protected]>
Co-authored-by: FGadvancer <[email protected]>
  • Loading branch information
4 people authored Sep 22, 2023
1 parent 6c0be3f commit 8006462
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 3 deletions.
4 changes: 4 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ callback:
enable: false
timeout: 5
failedContinue: true
beforeUpdateUserInfo:
enable: false
timeout: 5
failedContinue: true
beforeCreateGroup:
enable: false
timeout: 5
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require github.com/google/uuid v1.3.1

require (
github.com/IBM/sarama v1.41.1
github.com/OpenIMSDK/protocol v0.0.23
github.com/OpenIMSDK/protocol v0.0.24
github.com/OpenIMSDK/tools v0.0.14
github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible
github.com/go-redis/redis v6.15.9+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ firebase.google.com/go v3.13.0+incompatible/go.mod h1:xlah6XbEyW6tbfSklcfe5FHJIw
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/IBM/sarama v1.41.1 h1:B4/TdHce/8Ipza+qrLIeNJ9D1AOxZVp/3uDv6H/dp2M=
github.com/IBM/sarama v1.41.1/go.mod h1:JFCPURVskaipJdKRFkiE/OZqQHw7jqliaJmRwXCmSSw=
github.com/OpenIMSDK/protocol v0.0.23 h1:L545aRQez6Ro+AaJB1Z6Mz7ojnDtp41WqASxYveCkcE=
github.com/OpenIMSDK/protocol v0.0.23/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/OpenIMSDK/protocol v0.0.24 h1:wk/S0GOGVh8mBbpmjKxSsyYMhyBazdn/ZcS9VqXfT24=
github.com/OpenIMSDK/protocol v0.0.24/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
github.com/OpenIMSDK/tools v0.0.14 h1:WLof/+WxyPyRST+QkoTKubYCiV73uCLiL8pgnpH/yKQ=
github.com/OpenIMSDK/tools v0.0.14/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI=
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
Expand Down
53 changes: 53 additions & 0 deletions internal/rpc/user/callback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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"

"github.com/OpenIMSDK/protocol/constant"
pbuser "github.com/OpenIMSDK/protocol/user"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/mcontext"
"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"
)

func CallbackBeforeUpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserInfoReq) error {
if !config.Config.Callback.CallbackBeforeUpdateUserInfo.Enable {
return nil
}
cbReq := &cbapi.CallbackBeforeUpdateUserInfoReq{
CallbackCommand: constant.CallbackBeforeUpdateUserInfoCommand,
OperationID: mcontext.GetOperationID(ctx),
UserID: req.UserInfo.UserID,
FaceURL: &req.UserInfo.FaceURL,
Nickname: &req.UserInfo.Nickname,
}
resp := &cbapi.CallbackBeforeUpdateUserInfoResp{}
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeUpdateUserInfo); err != nil {
if err == errs.ErrCallbackContinue {
return nil
}
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
}
3 changes: 3 additions & 0 deletions internal/rpc/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbuser.UpdateUserI
if err != nil {
return nil, err
}
if err := CallbackBeforeUpdateUserInfo(ctx, req); err != nil {
return nil, err
}
user := convert.UserPb2DB(req.UserInfo)
if err != nil {
return nil, err
Expand Down
30 changes: 30 additions & 0 deletions pkg/callbackstruct/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 callbackstruct

type CallbackBeforeUpdateUserInfoReq struct {
CallbackCommand `json:"callbackCommand"`
OperationID string `json:"operationID"`
UserID string `json:"userID"`
Nickname *string `json:"nickName"`
FaceURL *string `json:"faceURL"`
Ex *string `json:"ex"`
}
type CallbackBeforeUpdateUserInfoResp struct {
CommonCallbackResp
Nickname *string `json:"nickName"`
FaceURL *string `json:"faceURL"`
Ex *string `json:"ex"`
}
1 change: 1 addition & 0 deletions pkg/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ type configStruct struct {
CallbackOnlinePush CallBackConfig `yaml:"onlinePush"`
CallbackBeforeSuperGroupOnlinePush CallBackConfig `yaml:"superGroupOnlinePush"`
CallbackBeforeAddFriend CallBackConfig `yaml:"beforeAddFriend"`
CallbackBeforeUpdateUserInfo CallBackConfig `yaml:"beforeUpdateUserInfo"`
CallbackBeforeCreateGroup CallBackConfig `yaml:"beforeCreateGroup"`
CallbackBeforeMemberJoinGroup CallBackConfig `yaml:"beforeMemberJoinGroup"`
CallbackBeforeSetGroupMemberInfo CallBackConfig `yaml:"beforeSetGroupMemberInfo"`
Expand Down

0 comments on commit 8006462

Please sign in to comment.