diff --git a/README.md b/README.md index 6a3d03465..9f9e09ebc 100644 --- a/README.md +++ b/README.md @@ -36,75 +36,69 @@ By deployment of the Open-IM-Server on the customer's server, developers can int > Open-IM relies on five open source high-performance components: ETCD, MySQL, MongoDB, Redis, and Kafka. Privatization deployment Before Open-IM-Server, please make sure that the above five components have been installed. If your server does not have the above components, you must first install Missing components. If you have the above components, it is recommended to use them directly. If not, it is recommended to use Docker-compose, no To install dependencies, one-click deployment, faster and more convenient. -#### Source code deployment +#### Deploy using Docker -1. Install [Go environment](https://golang.org/doc/install). Make sure Go version is at least 1.15. +1. Install [Go environment](https://golang.org/doc/install). Make sure Go version is at least 1.17 -2. Clone the Open-IM project to your server. +2. Clone the Open-IM project to your server ``` git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive ``` -3. Build and start Service. +3. Deploy - 1. Shell authorization + 1. Modify env ``` - #cd Open-IM-server/script - - chmod +x *.sh + #cd Open-IM-server + USER=root + PASSWORD=openIM123 #Password with more than 8 digits, excluding special characters + ENDPOINT=http://127.0.0.1:10005 #Replace 127.0.0.1 with Internet IP + DATA_DIR=./ ``` - 2. Execute the build shell - + 2. Deploy && Start + ``` - ./build_all_service.sh + chmod +x install_im_server.sh; + ./install_im_server.sh; ``` - - 3. Start service - - ``` - ./start_all.sh - ``` - + 4. Check service - + ``` - ./check_all.sh + cd script; + ./docker_check_service.sh./check_all.sh ``` - + ![OpenIMServersonSystempng](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Open-IM-Servers-on-System.png) -#### Docker deployment +#### Deploy using source code -All images are available at https://hub.docker.com/r/lyt1123/open_im_server +1. Go 1.17 or above。 +2. Clone -1. [Install Docker](https://docs.docker.com/install/) 1.13 or above. +```shell +git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive +cd cmd/Open-IM-SDK-Core +git checkout main +``` -2. [Install Docker Compose](https://docs.docker.com/compose/install/) 1.22 or above. +1. Set executable permissions -3. Clone the Open-IM project to your server. +```shell +cd ../../script/ +chmod +x *.sh +``` - ``` - git clone https://github.com/OpenIMSDK/Open-IM-Server.git --recursive - ``` +1. build -4. Start docker-compose with one click(Docker automatically pulls all images) +```shell +./batch_build_all_service.sh +``` - ``` - cd Open-IM-Server - docker-compose up -d - ``` - -5. Check service - - ``` - ./docker_check_service.sh - ./check_all.sh - ``` - - ![OpenIMServersondockerpng](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/Open-IM-Servers-on-docker.png) +all services build success ### CONFIGURATION INSTRUCTIONS diff --git a/config/config.yaml b/config/config.yaml index 966c613f4..474832f34 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -345,7 +345,7 @@ callback: enable: false callbackTimeOut: 2 callbackFailedContinue: true # 回调超时是否继续 - callbackBeforeExtendMsgModify: + callbackBeforeSetGroupMemberInfo: enable: false callbackTimeOut: 2 callbackFailedContinue: true # 回调超时是否继续 diff --git a/docker-compose.yaml b/docker-compose.yaml index 59e18d17b..4188bbdf8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -139,7 +139,7 @@ services: max-file: "2" open_im_enterprise: - image: openim/open_im_enterprise:v1.0.0 + image: openim/open_im_enterprise:v1.0.2 container_name: open_im_enterprise volumes: - ./logs:/Open-IM-Enterprise/logs diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index 90dc63af0..5bf450a69 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -10,6 +10,8 @@ import ( pbGroup "Open_IM/pkg/proto/group" "Open_IM/pkg/utils" http2 "net/http" + + "google.golang.org/protobuf/types/known/wrapperspb" ) func callbackBeforeCreateGroup(req *pbGroup.CreateGroupReq) cbApi.CommonCallbackResp { @@ -126,3 +128,56 @@ func CallbackBeforeMemberJoinGroup(operationID string, groupMember *db.GroupMemb } return callbackResp } + +func CallbackBeforeSetGroupMemberInfo(req *pbGroup.SetGroupMemberInfoReq) cbApi.CommonCallbackResp { + callbackResp := cbApi.CommonCallbackResp{OperationID: req.OperationID} + if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.Enable { + return callbackResp + } + callbackReq := cbApi.CallbackBeforeSetGroupMemberInfoReq{ + CallbackCommand: constant.CallbackBeforeSetGroupMemberInfoCommand, + OperationID: req.OperationID, + GroupID: req.GroupID, + UserID: req.UserID, + } + if req.Nickname != nil { + callbackReq.Nickname = req.Nickname.Value + } + if req.FaceURL != nil { + callbackReq.FaceURL = req.FaceURL.Value + } + if req.RoleLevel != nil { + callbackReq.RoleLevel = req.RoleLevel.Value + } + if req.Ex != nil { + callbackReq.Ex = req.Ex.Value + } + resp := &cbApi.CallbackBeforeSetGroupMemberInfoResp{ + CommonCallbackResp: &callbackResp, + } + + if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetGroupMemberInfoCommand, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackTimeOut); err != nil { + callbackResp.ErrCode = http2.StatusInternalServerError + callbackResp.ErrMsg = err.Error() + if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.CallbackFailedContinue { + callbackResp.ActionCode = constant.ActionForbidden + return callbackResp + } else { + callbackResp.ActionCode = constant.ActionAllow + return callbackResp + } + } + if resp.FaceURL != nil { + 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 +} diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 64cddba02..4d68582e5 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -30,6 +30,7 @@ import ( grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "google.golang.org/grpc" + "google.golang.org/protobuf/types/known/wrapperspb" "gorm.io/gorm" ) @@ -1765,11 +1766,35 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S log.Error(req.OperationID, errMsg) return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } + cbReq := &pbGroup.SetGroupMemberInfoReq{ + GroupID: req.GroupID, + UserID: req.UserID, + OperationID: req.OperationID, + OpUserID: req.OpUserID, + Nickname: &wrapperspb.StringValue{Value: req.Nickname}, + } + callbackResp := CallbackBeforeSetGroupMemberInfo(cbReq) + if callbackResp.ErrCode != 0 { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "CallbackBeforeMemberJoinGroup resp: ", callbackResp) + } + if callbackResp.ActionCode != constant.ActionAllow { + if callbackResp.ErrCode == 0 { + callbackResp.ErrCode = 201 + } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CallbackBeforeMemberJoinGroup result", "end rpc and return", callbackResp) + return &pbGroup.SetGroupMemberNicknameResp{ + CommonResp: &pbGroup.CommonResp{ + ErrCode: int32(callbackResp.ErrCode), + ErrMsg: callbackResp.ErrMsg, + }, + }, nil + } + nickName := cbReq.Nickname.Value groupMemberInfo := db.GroupMember{} groupMemberInfo.UserID = req.UserID groupMemberInfo.GroupID = req.GroupID - if req.Nickname == "" { + if nickName == "" { userNickname, err := imdb.GetUserNameByUserID(groupMemberInfo.UserID) if err != nil { errMsg := req.OperationID + " GetUserNameByUserID failed " + err.Error() @@ -1778,7 +1803,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S } groupMemberInfo.Nickname = userNickname } else { - groupMemberInfo.Nickname = req.Nickname + groupMemberInfo.Nickname = nickName } if err := rocksCache.DelGroupMemberInfoFromCache(req.GroupID, req.UserID); err != nil { @@ -1805,6 +1830,23 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr resp.CommonResp.ErrMsg = err.Error() return resp, nil } + callbackResp := CallbackBeforeSetGroupMemberInfo(req) + if callbackResp.ErrCode != 0 { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "CallbackBeforeMemberJoinGroup resp: ", callbackResp) + } + if callbackResp.ActionCode != constant.ActionAllow { + if callbackResp.ErrCode == 0 { + callbackResp.ErrCode = 201 + } + log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "CallbackBeforeMemberJoinGroup result", "end rpc and return", callbackResp) + return &pbGroup.SetGroupMemberInfoResp{ + CommonResp: &pbGroup.CommonResp{ + ErrCode: int32(callbackResp.ErrCode), + ErrMsg: callbackResp.ErrMsg, + }, + }, nil + } + groupMember := db.GroupMember{ GroupID: req.GroupID, UserID: req.UserID, diff --git a/pkg/call_back_struct/group.go b/pkg/call_back_struct/group.go index 33a18d9c0..a040adcf0 100644 --- a/pkg/call_back_struct/group.go +++ b/pkg/call_back_struct/group.go @@ -46,3 +46,22 @@ type CallbackBeforeMemberJoinGroupResp struct { MuteEndTime *int64 `json:"muteEndTime"` Ex *string `json:"ex"` } + +type CallbackBeforeSetGroupMemberInfoReq struct { + CallbackCommand string `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + UserID string `json:"userID"` + Nickname string `json:"nickName"` + FaceURL string `json:"faceURL"` + RoleLevel int32 `json:"roleLevel"` + Ex string `json:"ex"` +} + +type CallbackBeforeSetGroupMemberInfoResp struct { + *CommonCallbackResp + Ex *string `json:"ex"` + Nickname *string `json:"nickName"` + FaceURL *string `json:"faceURL"` + RoleLevel *int32 `json:"roleLevel"` +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 855d5c6fb..32ad9391b 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -292,7 +292,7 @@ type config struct { CallbackBeforeAddFriend callBackConfig `yaml:"callbackBeforeAddFriend"` CallbackBeforeCreateGroup callBackConfig `yaml:"callbackBeforeCreateGroup"` CallbackBeforeMemberJoinGroup callBackConfig `yaml:"callbackBeforeMemberJoinGroup"` - CallbackBeforeExtendMsgModify callBackConfig `yaml:"callbackBeforeExtendMsgModify"` + CallbackBeforeSetGroupMemberInfo callBackConfig `yaml:"callbackBeforeSetGroupMemberInfo"` } `yaml:"callback"` Notification struct { ///////////////////////group///////////////////////////// diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index ff2e0097f..250bf5856 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -202,20 +202,21 @@ const ( VerificationCodeForResetSuffix = "_forReset" //callbackCommand - CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand" - CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand" - CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand" - CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand" - CallbackMsgModifyCommand = "callbackMsgModifyCommand" - CallbackUserOnlineCommand = "callbackUserOnlineCommand" - CallbackUserOfflineCommand = "callbackUserOfflineCommand" - CallbackUserKickOffCommand = "callbackUserKickOffCommand" - CallbackOfflinePushCommand = "callbackOfflinePushCommand" - CallbackOnlinePushCommand = "callbackOnlinePushCommand" - CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand" - CallbackBeforeAddFriendCommand = "callbackBeforeAddFriendCommand" - CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroupCommand" - CallbackBeforeMemberJoinGroupCommand = "callbackBeforeMemberJoinGroupCommand" + CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand" + CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand" + CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand" + CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand" + CallbackMsgModifyCommand = "callbackMsgModifyCommand" + CallbackUserOnlineCommand = "callbackUserOnlineCommand" + CallbackUserOfflineCommand = "callbackUserOfflineCommand" + CallbackUserKickOffCommand = "callbackUserKickOffCommand" + CallbackOfflinePushCommand = "callbackOfflinePushCommand" + CallbackOnlinePushCommand = "callbackOnlinePushCommand" + CallbackSuperGroupOnlinePushCommand = "callbackSuperGroupOnlinePushCommand" + CallbackBeforeAddFriendCommand = "callbackBeforeAddFriendCommand" + CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroupCommand" + CallbackBeforeMemberJoinGroupCommand = "callbackBeforeMemberJoinGroupCommand" + CallbackBeforeSetGroupMemberInfoCommand = "CallbackBeforeSetGroupMemberInfoCommand" //callback actionCode ActionAllow = 0