diff --git a/.env b/.env index ae76a0440..8213b9e3c 100644 --- a/.env +++ b/.env @@ -94,7 +94,7 @@ OPENIM_CHAT_NETWORK_ADDRESS=172.28.0.10 # Address or hostname for the Prometheus network. # Default: PROMETHEUS_NETWORK_ADDRESS=172.28.0.11 PROMETHEUS_NETWORK_ADDRESS=172.28.0.11 - + # Address or hostname for the Grafana network. # Default: GRAFANA_NETWORK_ADDRESS=172.28.0.12 GRAFANA_NETWORK_ADDRESS=172.28.0.12 @@ -106,7 +106,10 @@ NODE_EXPORTER_NETWORK_ADDRESS=172.28.0.13 # Address or hostname for the OpenIM admin network. # Default: OPENIM_ADMIN_NETWORK_ADDRESS=172.28.0.14 OPENIM_ADMIN_FRONT_NETWORK_ADDRESS=172.28.0.14 - + +# Address or hostname for the alertmanager network. +# Default: ALERT_MANAGER_NETWORK_ADDRESS=172.28.0.14 +ALERT_MANAGER_NETWORK_ADDRESS=172.28.0.14 # =============================================== # = Component Extension Configuration = # =============================================== @@ -306,3 +309,7 @@ GRAFANA_PORT=3000 # Port for the admin front. # Default: OPENIM_ADMIN_FRONT_PORT=11002 OPENIM_ADMIN_FRONT_PORT=11002 + +# Port for the alertmanager. +# Default: ALERT_MANAGER_PORT=19093 +ALERT_MANAGER_PORT=19093 diff --git a/cmd/openim-msggateway/main.go b/cmd/openim-msggateway/main.go index f6870694b..6d212e467 100644 --- a/cmd/openim-msggateway/main.go +++ b/cmd/openim-msggateway/main.go @@ -23,6 +23,7 @@ func main() { msgGatewayCmd.AddWsPortFlag() msgGatewayCmd.AddPortFlag() msgGatewayCmd.AddPrometheusPortFlag() + if err := msgGatewayCmd.Exec(); err != nil { panic(err.Error()) } diff --git a/config/alertmanager.yml b/config/alertmanager.yml index 71cdd2b8f..ee14b6464 100644 --- a/config/alertmanager.yml +++ b/config/alertmanager.yml @@ -26,7 +26,7 @@ route: receivers: - name: email email_configs: - - to: {EMAIL_TO:-'alert@example.com'} + - to: '{EMAIL_TO:-'alert@example.com'}' html: '{{ template "email.to.html" . }}' headers: { Subject: "[OPENIM-SERVER]Alarm" } send_resolved: true diff --git a/config/config.yaml b/config/config.yaml index e8995c82b..b17d10073 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -375,6 +375,10 @@ callback: enable: false timeout: 5 failedContinue: true + beforeInviteUserToGroup: + enable: true + timeout: 5 + failedContinue: true beforeSetGroupMemberInfo: enable: false timeout: 5 diff --git a/deployments/templates/alertmanager.yml b/deployments/templates/alertmanager.yml index 47090f148..ea99a9286 100644 --- a/deployments/templates/alertmanager.yml +++ b/deployments/templates/alertmanager.yml @@ -27,7 +27,7 @@ route: receivers: - name: email email_configs: - - to: ${ALERTMANAGER_EMAIL_TO} + - to: '${ALERTMANAGER_EMAIL_TO}' html: '{{ template "email.to.html" . }}' headers: { Subject: "[OPENIM-SERVER]Alarm" } - send_resolved: true \ No newline at end of file + send_resolved: true diff --git a/deployments/templates/openim.yaml b/deployments/templates/openim.yaml index fde05e86e..fc90bfc2f 100644 --- a/deployments/templates/openim.yaml +++ b/deployments/templates/openim.yaml @@ -320,7 +320,7 @@ iosPush: # Timeout in seconds # Whether to continue execution if callback fails callback: - url: + url: "" beforeSendSingleMsg: enable: ${CALLBACK_ENABLE} timeout: ${CALLBACK_TIMEOUT} @@ -389,6 +389,10 @@ callback: enable: ${CALLBACK_ENABLE} timeout: ${CALLBACK_TIMEOUT} failedContinue: ${CALLBACK_FAILED_CONTINUE} + afterSetGroupMemberInfo: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} setMessageReactionExtensions: enable: ${CALLBACK_ENABLE} timeout: ${CALLBACK_TIMEOUT} @@ -441,7 +445,66 @@ callback: enable: ${CALLBACK_ENABLE} timeout: ${CALLBACK_TIMEOUT} failedContinue: ${CALLBACK_FAILED_CONTINUE} - + afterGroupMsgRead: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + afterGroupMsgRevoke: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + afterJoinGroup: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + beforeInviteUserToGroup: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + joinGroupAfter: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + setGroupInfoAfter: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + setGroupInfoBefore: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + revokeMsgAfter: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + addBlackBefore: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + addFriendAfter: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + addFriendAgreeBefore: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + deleteFriendAfter: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + importFriendsBefore: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + importFriendsAfter: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} + removeBlackAfter: + enable: ${CALLBACK_ENABLE} + timeout: ${CALLBACK_TIMEOUT} + failedContinue: ${CALLBACK_FAILED_CONTINUE} ###################### Prometheus ###################### # Prometheus configuration for various services # The number of Prometheus ports per service needs to correspond to rpcPort diff --git a/docs/contrib/environment.md b/docs/contrib/environment.md index 6450549e7..0279c750e 100644 --- a/docs/contrib/environment.md +++ b/docs/contrib/environment.md @@ -501,7 +501,7 @@ This section involves setting up additional configuration variables for Websocke | TOKEN_EXPIRE | "90" | Token Expiry Time | | FRIEND_VERIFY | "false" | Friend Verification Enable | | IOS_PUSH_SOUND | "xxx" | iOS | -| CALLBACK_ENABLE | "true" | Enable callback | | | | +| CALLBACK_ENABLE | "false" | Enable callback | | CALLBACK_TIMEOUT | "5" | Maximum timeout for callback call | | CALLBACK_FAILED_CONTINUE| "true" | fails to continue to the next step | ### 2.20. Prometheus Configuration diff --git a/go.mod b/go.mod index fc7c615c6..8d767dbc1 100644 --- a/go.mod +++ b/go.mod @@ -38,7 +38,7 @@ require github.com/google/uuid v1.3.1 require ( github.com/IBM/sarama v1.41.3 github.com/OpenIMSDK/protocol v0.0.31 - github.com/OpenIMSDK/tools v0.0.16 + github.com/OpenIMSDK/tools v0.0.17 github.com/aliyun/aliyun-oss-go-sdk v2.2.9+incompatible github.com/go-redis/redis v6.15.9+incompatible github.com/go-sql-driver/mysql v1.7.1 diff --git a/go.sum b/go.sum index 10cb9ee8c..640b11e89 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/IBM/sarama v1.41.3 h1:MWBEJ12vHC8coMjdEXFq/6ftO6DUZnQlFYcxtOJFa7c= github.com/IBM/sarama v1.41.3/go.mod h1:Xxho9HkHd4K/MDUo/T/sOqwtX/17D33++E9Wib6hUdQ= github.com/OpenIMSDK/protocol v0.0.31 h1:ax43x9aqA6EKNXNukS5MT5BSTqkUmwO4uTvbJLtzCgE= github.com/OpenIMSDK/protocol v0.0.31/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y= -github.com/OpenIMSDK/tools v0.0.16 h1:te/GIq2imCMsrRPgU9OObYKbzZ3rT08Lih/o+3QFIz0= -github.com/OpenIMSDK/tools v0.0.16/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= +github.com/OpenIMSDK/tools v0.0.17 h1:1E1HUOL2W09YUHBb4wBwrXoTSZm5ONVwLxlEX1GhlKw= +github.com/OpenIMSDK/tools v0.0.17/go.mod h1:eg+q4A34Qmu73xkY0mt37FHGMCMfC6CtmOnm0kFEGFI= github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= diff --git a/internal/api/msg.go b/internal/api/msg.go index 38e207cfb..67b5f1eff 100644 --- a/internal/api/msg.go +++ b/internal/api/msg.go @@ -15,14 +15,6 @@ package api import ( - "github.com/OpenIMSDK/tools/mcontext" - "github.com/gin-gonic/gin" - "github.com/go-playground/validator/v10" - "github.com/mitchellh/mapstructure" - - "github.com/openimsdk/open-im-server/v3/pkg/authverify" - "github.com/openimsdk/open-im-server/v3/pkg/common/config" - "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/protocol/msg" "github.com/OpenIMSDK/protocol/sdkws" @@ -30,7 +22,13 @@ import ( "github.com/OpenIMSDK/tools/apiresp" "github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/log" + "github.com/OpenIMSDK/tools/mcontext" "github.com/OpenIMSDK/tools/utils" + "github.com/gin-gonic/gin" + "github.com/go-playground/validator/v10" + "github.com/mitchellh/mapstructure" + "github.com/openimsdk/open-im-server/v3/pkg/authverify" + "github.com/openimsdk/open-im-server/v3/pkg/common/config" "github.com/openimsdk/open-im-server/v3/pkg/apistruct" "github.com/openimsdk/open-im-server/v3/pkg/rpcclient" diff --git a/internal/msggateway/n_ws_server.go b/internal/msggateway/n_ws_server.go index 99a7a4805..5a061d7e1 100644 --- a/internal/msggateway/n_ws_server.go +++ b/internal/msggateway/n_ws_server.go @@ -121,6 +121,7 @@ func (ws *WsServer) UnRegister(c *Client) { } func (ws *WsServer) Validate(s interface{}) error { + //?question? return nil } diff --git a/internal/rpc/friend/black.go b/internal/rpc/friend/black.go index b1a5ea6b5..fee2d5480 100644 --- a/internal/rpc/friend/black.go +++ b/internal/rpc/friend/black.go @@ -74,6 +74,9 @@ func (s *friendServer) RemoveBlack( return nil, err } s.notificationSender.BlackDeletedNotification(ctx, req) + if err := CallbackAfterRemoveBlack(ctx, req); err != nil { + return nil, err + } return &pbfriend.RemoveBlackResp{}, nil } @@ -85,6 +88,9 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbfriend.AddBlackReq) if err != nil { return nil, err } + if err := CallbackBeforeAddBlack(ctx, req); err != nil { + return nil, err + } black := relation.BlackModel{ OwnerUserID: req.OwnerUserID, BlockUserID: req.BlackUserID, diff --git a/internal/rpc/friend/callback.go b/internal/rpc/friend/callback.go index d3b853ef9..d541071f5 100644 --- a/internal/rpc/friend/callback.go +++ b/internal/rpc/friend/callback.go @@ -16,9 +16,8 @@ package friend import ( "context" - "github.com/OpenIMSDK/tools/utils" - pbfriend "github.com/OpenIMSDK/protocol/friend" + "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" @@ -33,6 +32,7 @@ func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriend FromUserID: req.FromUserID, ToUserID: req.ToUserID, ReqMsg: req.ReqMsg, + Ex: req.Ex, } resp := &cbapi.CallbackBeforeAddFriendResp{} if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil { @@ -75,3 +75,116 @@ func CallbackAfterSetFriendRemark(ctx context.Context, req *pbfriend.SetFriendRe } return nil } +func CallbackBeforeAddBlack(ctx context.Context, req *pbfriend.AddBlackReq) error { + if !config.Config.Callback.CallbackBeforeAddBlack.Enable { + return nil + } + cbReq := &cbapi.CallbackBeforeAddBlackReq{ + CallbackCommand: cbapi.CallbackBeforeAddBlackCommand, + OwnerUserID: req.OwnerUserID, + BlackUserID: req.BlackUserID, + } + resp := &cbapi.CallbackBeforeAddBlackResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddBlack); err != nil { + return err + } + return nil +} +func CallbackAfterAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error { + if !config.Config.Callback.CallbackAfterAddFriend.Enable { + return nil + } + cbReq := &cbapi.CallbackAfterAddFriendReq{ + CallbackCommand: cbapi.CallbackAfterAddFriendCommand, + FromUserID: req.FromUserID, + ToUserID: req.ToUserID, + ReqMsg: req.ReqMsg, + } + resp := &cbapi.CallbackAfterAddFriendResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterAddFriend); err != nil { + return err + } + + return nil +} +func CallbackBeforeAddFriendAgree(ctx context.Context, req *pbfriend.RespondFriendApplyReq) error { + if !config.Config.Callback.CallbackBeforeAddFriendAgree.Enable { + return nil + } + cbReq := &cbapi.CallbackBeforeAddFriendAgreeReq{ + CallbackCommand: cbapi.CallbackBeforeAddFriendAgreeCommand, + FromUserID: req.FromUserID, + ToUserID: req.ToUserID, + HandleMsg: req.HandleMsg, + HandleResult: req.HandleResult, + } + resp := &cbapi.CallbackBeforeAddFriendAgreeResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriendAgree); err != nil { + return err + } + return nil +} +func CallbackAfterDeleteFriend(ctx context.Context, req *pbfriend.DeleteFriendReq) error { + if !config.Config.Callback.CallbackAfterDeleteFriend.Enable { + return nil + } + cbReq := &cbapi.CallbackAfterDeleteFriendReq{ + CallbackCommand: cbapi.CallbackAfterDeleteFriendCommand, + OwnerUserID: req.OwnerUserID, + FriendUserID: req.FriendUserID, + } + resp := &cbapi.CallbackAfterDeleteFriendResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterDeleteFriend); err != nil { + return err + } + return nil +} +func CallbackBeforeImportFriends(ctx context.Context, req *pbfriend.ImportFriendReq) error { + if !config.Config.Callback.CallbackBeforeImportFriends.Enable { + return nil + } + cbReq := &cbapi.CallbackBeforeImportFriendsReq{ + CallbackCommand: cbapi.CallbackBeforeImportFriendsCommand, + OwnerUserID: req.OwnerUserID, + FriendUserIDs: req.FriendUserIDs, + } + resp := &cbapi.CallbackBeforeImportFriendsResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeImportFriends); err != nil { + return err + } + if len(resp.FriendUserIDs) != 0 { + req.FriendUserIDs = resp.FriendUserIDs + } + return nil +} +func CallbackAfterImportFriends(ctx context.Context, req *pbfriend.ImportFriendReq) error { + if !config.Config.Callback.CallbackAfterImportFriends.Enable { + return nil + } + cbReq := &cbapi.CallbackAfterImportFriendsReq{ + CallbackCommand: cbapi.CallbackAfterImportFriendsCommand, + OwnerUserID: req.OwnerUserID, + FriendUserIDs: req.FriendUserIDs, + } + resp := &cbapi.CallbackAfterImportFriendsResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterImportFriends); err != nil { + return err + } + return nil +} + +func CallbackAfterRemoveBlack(ctx context.Context, req *pbfriend.RemoveBlackReq) error { + if !config.Config.Callback.CallbackAfterRemoveBlack.Enable { + return nil + } + cbReq := &cbapi.CallbackAfterRemoveBlackReq{ + CallbackCommand: cbapi.CallbackAfterRemoveBlackCommand, + OwnerUserID: req.OwnerUserID, + BlackUserID: req.BlackUserID, + } + resp := &cbapi.CallbackAfterRemoveBlackResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterRemoveBlack); err != nil { + return err + } + return nil +} diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 24014ace1..6e6b6d377 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -103,7 +103,7 @@ func (s *friendServer) ApplyToAddFriend( if req.ToUserID == req.FromUserID { return nil, errs.ErrCanNotAddYourself.Wrap() } - if err := CallbackBeforeAddFriend(ctx, req); err != nil && err != errs.ErrCallbackContinue { + if err = CallbackBeforeAddFriend(ctx, req); err != nil && err != errs.ErrCallbackContinue { return nil, err } if _, err := s.userRpcClient.GetUsersInfoMap(ctx, []string{req.ToUserID, req.FromUserID}); err != nil { @@ -120,6 +120,9 @@ func (s *friendServer) ApplyToAddFriend( return nil, err } s.notificationSender.FriendApplicationAddNotification(ctx, req) + if err = CallbackAfterAddFriend(ctx, req); err != nil && err != errs.ErrCallbackContinue { + return nil, err + } return resp, nil } @@ -141,6 +144,10 @@ func (s *friendServer) ImportFriends( if utils.Duplicate(req.FriendUserIDs) { return nil, errs.ErrArgs.Wrap("friend userID repeated") } + if err := CallbackBeforeImportFriends(ctx, req); err != nil { + return nil, err + } + if err := s.friendDatabase.BecomeFriends(ctx, req.OwnerUserID, req.FriendUserIDs, constant.BecomeFriendByImport); err != nil { return nil, err } @@ -151,6 +158,9 @@ func (s *friendServer) ImportFriends( HandleResult: constant.FriendResponseAgree, }) } + if err := CallbackAfterImportFriends(ctx, req); err != nil { + return nil, err + } return &pbfriend.ImportFriendResp{}, nil } @@ -172,6 +182,9 @@ func (s *friendServer) RespondFriendApply( HandleResult: req.HandleResult, } if req.HandleResult == constant.FriendResponseAgree { + if err := CallbackBeforeAddFriendAgree(ctx, req); err != nil && err != errs.ErrCallbackContinue { + return nil, err + } err := s.friendDatabase.AgreeFriendRequest(ctx, &friendRequest) if err != nil { return nil, err @@ -208,6 +221,9 @@ func (s *friendServer) DeleteFriend( return nil, err } s.notificationSender.FriendDeletedNotification(ctx, req) + if err := CallbackAfterDeleteFriend(ctx, req); err != nil { + return nil, err + } return resp, nil } diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index 13f9737b5..1599cc7b4 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -16,6 +16,7 @@ package group import ( "context" + "github.com/OpenIMSDK/tools/log" "time" "github.com/OpenIMSDK/protocol/constant" @@ -124,7 +125,14 @@ func CallbackBeforeMemberJoinGroup( GroupEx: groupEx, } resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{} - if err = http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup); err != nil { + err = http.CallBackPostReturn( + ctx, + config.Config.Callback.CallbackUrl, + callbackReq, + resp, + config.Config.Callback.CallbackBeforeMemberJoinGroup, + ) + if err != nil { return err } if resp.MuteEndTime != nil { @@ -159,7 +167,14 @@ func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMe callbackReq.Ex = &req.Ex.Value } resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{} - if err = http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo); err != nil { + err = http.CallBackPostReturn( + ctx, + config.Config.Callback.CallbackUrl, + callbackReq, + resp, + config.Config.Callback.CallbackBeforeSetGroupMemberInfo, + ) + if err != nil { return err } if resp.FaceURL != nil { @@ -176,13 +191,12 @@ func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMe } return nil } - func CallbackAfterSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMemberInfo) (err error) { if !config.Config.Callback.CallbackBeforeSetGroupMemberInfo.Enable { return nil } callbackReq := callbackstruct.CallbackAfterSetGroupMemberInfoReq{ - CallbackCommand: callbackstruct.CallbackBeforeSetGroupMemberInfoCommand, + CallbackCommand: callbackstruct.CallbackAfterSetGroupMemberInfoCommand, GroupID: req.GroupID, UserID: req.UserID, } @@ -199,7 +213,7 @@ func CallbackAfterSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMem callbackReq.Ex = &req.Ex.Value } resp := &callbackstruct.CallbackAfterSetGroupMemberInfoResp{} - if err = http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo); err != nil { + if err = http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackAfterSetGroupMemberInfo); err != nil { return err } return nil @@ -282,3 +296,135 @@ func CallbackTransferGroupOwnerAfter(ctx context.Context, req *pbgroup.TransferG } return nil } +func CallbackBeforeInviteUserToGroup(ctx context.Context, req *group.InviteUserToGroupReq) (err error) { + if !config.Config.Callback.CallbackBeforeInviteUserToGroup.Enable { + return nil + } + + callbackReq := &callbackstruct.CallbackBeforeInviteUserToGroupReq{ + CallbackCommand: callbackstruct.CallbackBeforeInviteJoinGroupCommand, + OperationID: mcontext.GetOperationID(ctx), + GroupID: req.GroupID, + Reason: req.Reason, + InvitedUserIDs: req.InvitedUserIDs, + } + + resp := &callbackstruct.CallbackBeforeInviteUserToGroupResp{} + err = http.CallBackPostReturn( + ctx, + config.Config.Callback.CallbackUrl, + callbackReq, + resp, + config.Config.Callback.CallbackBeforeInviteUserToGroup, + ) + + if err != nil { + return err + } + + if len(resp.RefusedMembersAccount) > 0 { + // Handle the scenario where certain members are refused + // You might want to update the req.Members list or handle it as per your business logic + } + utils.StructFieldNotNilReplace(req, resp) + + return nil +} + +func CallbackAfterJoinGroup(ctx context.Context, req *group.JoinGroupReq) error { + if !config.Config.Callback.CallbackAfterJoinGroup.Enable { + return nil + } + callbackReq := &callbackstruct.CallbackAfterJoinGroupReq{ + CallbackCommand: callbackstruct.CallbackAfterJoinGroupCommand, + OperationID: mcontext.GetOperationID(ctx), + GroupID: req.GroupID, + ReqMessage: req.ReqMessage, + JoinSource: req.JoinSource, + InviterUserID: req.InviterUserID, + } + resp := &callbackstruct.CallbackAfterJoinGroupResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackAfterJoinGroup); err != nil { + return err + } + return nil +} + +func CallbackBeforeSetGroupInfo(ctx context.Context, req *group.SetGroupInfoReq) error { + if !config.Config.Callback.CallbackBeforeSetGroupInfo.Enable { + return nil + } + callbackReq := &callbackstruct.CallbackBeforeSetGroupInfoReq{ + CallbackCommand: callbackstruct.CallbackBeforeSetGroupInfoCommand, + GroupID: req.GroupInfoForSet.GroupID, + Notification: req.GroupInfoForSet.Notification, + Introduction: req.GroupInfoForSet.Introduction, + FaceURL: req.GroupInfoForSet.FaceURL, + GroupName: req.GroupInfoForSet.GroupName, + } + + if req.GroupInfoForSet.Ex != nil { + callbackReq.Ex = req.GroupInfoForSet.Ex.Value + } + log.ZDebug(ctx, "debug CallbackBeforeSetGroupInfo", callbackReq.Ex) + if req.GroupInfoForSet.NeedVerification != nil { + callbackReq.NeedVerification = req.GroupInfoForSet.NeedVerification.Value + } + if req.GroupInfoForSet.LookMemberInfo != nil { + callbackReq.LookMemberInfo = req.GroupInfoForSet.LookMemberInfo.Value + } + if req.GroupInfoForSet.ApplyMemberFriend != nil { + callbackReq.ApplyMemberFriend = req.GroupInfoForSet.ApplyMemberFriend.Value + } + resp := &callbackstruct.CallbackBeforeSetGroupInfoResp{} + + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupInfo); err != nil { + return err + } + + if resp.Ex != nil { + req.GroupInfoForSet.Ex = wrapperspb.String(*resp.Ex) + } + if resp.NeedVerification != nil { + req.GroupInfoForSet.NeedVerification = wrapperspb.Int32(*resp.NeedVerification) + } + if resp.LookMemberInfo != nil { + req.GroupInfoForSet.LookMemberInfo = wrapperspb.Int32(*resp.LookMemberInfo) + } + if resp.ApplyMemberFriend != nil { + req.GroupInfoForSet.ApplyMemberFriend = wrapperspb.Int32(*resp.ApplyMemberFriend) + } + utils.StructFieldNotNilReplace(req, resp) + return nil +} +func CallbackAfterSetGroupInfo(ctx context.Context, req *group.SetGroupInfoReq) error { + if !config.Config.Callback.CallbackAfterSetGroupInfo.Enable { + return nil + } + callbackReq := &callbackstruct.CallbackAfterSetGroupInfoReq{ + CallbackCommand: callbackstruct.CallbackAfterSetGroupInfoCommand, + GroupID: req.GroupInfoForSet.GroupID, + Notification: req.GroupInfoForSet.Notification, + Introduction: req.GroupInfoForSet.Introduction, + FaceURL: req.GroupInfoForSet.FaceURL, + GroupName: req.GroupInfoForSet.GroupName, + } + if req.GroupInfoForSet.Ex != nil { + callbackReq.Ex = &req.GroupInfoForSet.Ex.Value + } + if req.GroupInfoForSet.NeedVerification != nil { + callbackReq.NeedVerification = &req.GroupInfoForSet.NeedVerification.Value + } + if req.GroupInfoForSet.LookMemberInfo != nil { + callbackReq.LookMemberInfo = &req.GroupInfoForSet.LookMemberInfo.Value + } + if req.GroupInfoForSet.ApplyMemberFriend != nil { + callbackReq.ApplyMemberFriend = &req.GroupInfoForSet.ApplyMemberFriend.Value + } + resp := &callbackstruct.CallbackAfterSetGroupInfoResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackAfterSetGroupInfo); err != nil { + return err + } + utils.StructFieldNotNilReplace(req, resp) + return nil +} diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 227b7959d..67cd70817 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -366,6 +366,7 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbgroup.GetJo func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.InviteUserToGroupReq) (*pbgroup.InviteUserToGroupResp, error) { resp := &pbgroup.InviteUserToGroupResp{} + if len(req.InvitedUserIDs) == 0 { return nil, errs.ErrArgs.Wrap("user empty") } @@ -376,6 +377,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite if err != nil { return nil, err } + if group.Status == constant.GroupStatusDismissed { return nil, errs.ErrDismissedAlready.Wrap() } @@ -399,6 +401,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite } groupMember = groupMembers[0] } + + if err := CallbackBeforeInviteUserToGroup(ctx, req); err != nil { + return nil, err + } if group.NeedVerification == constant.AllNeedVerification { if !authverify.IsAppManagerUid(ctx) { if !(groupMember.RoleLevel == constant.GroupOwner || groupMember.RoleLevel == constant.GroupAdmin) { @@ -413,6 +419,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbgroup.Invite HandledTime: time.Unix(0, 0), }) } + if err := s.GroupDatabase.CreateGroupRequest(ctx, requests); err != nil { return nil, err } @@ -818,6 +825,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbgroup case constant.GroupResponseRefuse: s.Notification.GroupApplicationRejectedNotification(ctx, req) } + return &pbgroup.GroupApplicationResponseResp{}, nil } @@ -872,10 +880,14 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbgroup.JoinGroupReq) if err := s.GroupDatabase.CreateGroup(ctx, nil, []*relationtb.GroupMemberModel{groupMember}); err != nil { return nil, err } + if err := s.conversationRpcClient.GroupChatFirstCreateConversation(ctx, req.GroupID, []string{req.InviterUserID}); err != nil { return nil, err } s.Notification.MemberEnterNotification(ctx, req.GroupID, req.InviterUserID) + if err = CallbackAfterJoinGroup(ctx, req); err != nil { + return nil, err + } return resp, nil } groupRequest := relationtb.GroupRequestModel{ @@ -957,6 +969,9 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbgroup.SetGroupInf return nil, errs.ErrNoPermission.Wrap("no group owner or admin") } } + if err := CallbackBeforeSetGroupInfo(ctx, req); err != nil { + return nil, err + } group, err := s.GroupDatabase.TakeGroup(ctx, req.GroupInfoForSet.GroupID) if err != nil { return nil, err @@ -1025,6 +1040,9 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbgroup.SetGroupInf default: s.Notification.GroupInfoSetNotification(ctx, tips) } + if err := CallbackAfterSetGroupInfo(ctx, req); err != nil { + return nil, err + } return resp, nil } diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index 85c002bf3..4ce5a5443 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -24,8 +24,8 @@ import ( "github.com/OpenIMSDK/tools/log" "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" ) @@ -98,10 +98,10 @@ func callbackAfterSendSingleMsg(ctx context.Context, msg *pbchat.SendMsgReq) err } func callbackBeforeSendGroupMsg(ctx context.Context, msg *pbchat.SendMsgReq) error { - if !config.Config.Callback.CallbackAfterSendSingleMsg.Enable { + if !config.Config.Callback.CallbackBeforeSendSingleMsg.Enable { return nil } - req := &cbapi.CallbackAfterSendGroupMsgReq{ + req := &cbapi.CallbackBeforeSendGroupMsgReq{ CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackBeforeSendGroupMsgCommand), GroupID: msg.MsgData.GroupID, } @@ -160,7 +160,6 @@ func callbackMsgModify(ctx context.Context, msg *pbchat.SendMsgReq) error { log.ZDebug(ctx, "callbackMsgModify", "msg", msg.MsgData) return nil } - func CallbackGroupMsgRead(ctx context.Context, req *cbapi.CallbackGroupMsgReadReq) error { if !config.Config.Callback.CallbackGroupMsgRead.Enable || req.ContentType != constant.Text { return nil @@ -180,10 +179,27 @@ func CallbackSingleMsgRead(ctx context.Context, req *cbapi.CallbackSingleMsgRead } req.CallbackCommand = cbapi.CallbackSingleMsgRead - resp := &cbapi.CallbackGroupMsgReadResp{} + resp := &cbapi.CallbackSingleMsgReadResp{} if err := http.CallBackPostReturn(ctx, cbURL(), req, resp, config.Config.Callback.CallbackMsgModify); err != nil { return err } return nil } +func CallbackAfterRevokeMsg(ctx context.Context, req *pbchat.RevokeMsgReq) error { + if !config.Config.Callback.CallbackAfterRevokeMsg.Enable { + return nil + } + callbackReq := &cbapi.CallbackAfterRevokeMsgReq{ + CallbackCommand: cbapi.CallbackAfterRevokeMsgCommand, + ConversationID: req.ConversationID, + Seq: req.Seq, + UserID: req.UserID, + } + resp := &cbapi.CallbackAfterRevokeMsgResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackAfterRevokeMsg); err != nil { + return err + } + utils.StructFieldNotNilReplace(req, resp) + return nil +} diff --git a/internal/rpc/msg/revoke.go b/internal/rpc/msg/revoke.go index 151d29fc1..d7362d339 100644 --- a/internal/rpc/msg/revoke.go +++ b/internal/rpc/msg/revoke.go @@ -61,6 +61,7 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg. if msgs[0].ContentType == constant.MsgRevokeNotification { return nil, errs.ErrMsgAlreadyRevoke.Wrap("msg already revoke") } + data, _ := json.Marshal(msgs[0]) log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data)) var role int32 @@ -128,5 +129,8 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg. if err := m.notificationSender.NotificationWithSesstionType(ctx, req.UserID, recvID, constant.MsgRevokeNotification, msgs[0].SessionType, &tips); err != nil { return nil, err } + if err = CallbackAfterRevokeMsg(ctx, req); err != nil { + return nil, err + } return &msg.RevokeMsgResp{}, nil } diff --git a/internal/rpc/user/callback.go b/internal/rpc/user/callback.go index 01de2734d..e87b4674e 100644 --- a/internal/rpc/user/callback.go +++ b/internal/rpc/user/callback.go @@ -91,8 +91,8 @@ func CallbackAfterUserRegister(ctx context.Context, req *pbuser.UserRegisterReq) Users: req.Users, } - resp := &cbapi.CallbackBeforeUserRegisterResp{} - if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeUpdateUserInfo); err != nil { + resp := &cbapi.CallbackAfterUserRegisterResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterUpdateUserInfo); err != nil { return err } return nil diff --git a/pkg/apistruct/msg.go b/pkg/apistruct/msg.go index 12cf253a0..61b4d832b 100644 --- a/pkg/apistruct/msg.go +++ b/pkg/apistruct/msg.go @@ -16,56 +16,56 @@ package apistruct type PictureBaseInfo struct { UUID string `mapstructure:"uuid"` - Type string `mapstructure:"type"` + Type string `mapstructure:"type" validate:"required"` Size int64 `mapstructure:"size"` - Width int32 `mapstructure:"width"` - Height int32 `mapstructure:"height"` - Url string `mapstructure:"url"` + Width int32 `mapstructure:"width" validate:"required"` + Height int32 `mapstructure:"height" validate:"required"` + Url string `mapstructure:"url" validate:"required"` } type PictureElem struct { SourcePath string `mapstructure:"sourcePath"` - SourcePicture PictureBaseInfo `mapstructure:"sourcePicture"` - BigPicture PictureBaseInfo `mapstructure:"bigPicture"` - SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture"` + SourcePicture PictureBaseInfo `mapstructure:"sourcePicture" validate:"required"` + BigPicture PictureBaseInfo `mapstructure:"bigPicture" validate:"required"` + SnapshotPicture PictureBaseInfo `mapstructure:"snapshotPicture" validate:"required"` } type SoundElem struct { UUID string `mapstructure:"uuid"` SoundPath string `mapstructure:"soundPath"` - SourceURL string `mapstructure:"sourceUrl"` + SourceURL string `mapstructure:"sourceUrl" validate:"required"` DataSize int64 `mapstructure:"dataSize"` - Duration int64 `mapstructure:"duration"` + Duration int64 `mapstructure:"duration" validate:"required,min=1"` } type VideoElem struct { - VideoPath string `mapstructure:"videoPath"` + VideoPath string `mapstructure:"videoPath" ` VideoUUID string `mapstructure:"videoUUID"` - VideoURL string `mapstructure:"videoUrl"` - VideoType string `mapstructure:"videoType"` - VideoSize int64 `mapstructure:"videoSize"` - Duration int64 `mapstructure:"duration"` + VideoURL string `mapstructure:"videoUrl" validate:"required"` + VideoType string `mapstructure:"videoType" validate:"required"` + VideoSize int64 `mapstructure:"videoSize" validate:"required"` + Duration int64 `mapstructure:"duration" validate:"required"` SnapshotPath string `mapstructure:"snapshotPath"` SnapshotUUID string `mapstructure:"snapshotUUID"` SnapshotSize int64 `mapstructure:"snapshotSize"` - SnapshotURL string `mapstructure:"snapshotUrl"` - SnapshotWidth int32 `mapstructure:"snapshotWidth"` - SnapshotHeight int32 `mapstructure:"snapshotHeight"` + SnapshotURL string `mapstructure:"snapshotUrl" validate:"required"` + SnapshotWidth int32 `mapstructure:"snapshotWidth" validate:"required"` + SnapshotHeight int32 `mapstructure:"snapshotHeight" validate:"required"` } type FileElem struct { - FilePath string `mapstructure:"filePath"` + FilePath string `mapstructure:"filePath" ` UUID string `mapstructure:"uuid"` - SourceURL string `mapstructure:"sourceUrl"` - FileName string `mapstructure:"fileName"` - FileSize int64 `mapstructure:"fileSize"` + SourceURL string `mapstructure:"sourceUrl" validate:"required"` + FileName string `mapstructure:"fileName" validate:"required"` + FileSize int64 `mapstructure:"fileSize" validate:"required"` } type AtElem struct { Text string `mapstructure:"text"` - AtUserList []string `mapstructure:"atUserList"` + AtUserList []string `mapstructure:"atUserList" validate:"required,max=1000"` IsAtSelf bool `mapstructure:"isAtSelf"` } type LocationElem struct { - Description string `mapstructure:"description"` - Longitude float64 `mapstructure:"longitude"` - Latitude float64 `mapstructure:"latitude"` + Description string `mapstructure:"description" ` + Longitude float64 `mapstructure:"longitude" validate:"required"` + Latitude float64 `mapstructure:"latitude" validate:"required"` } type CustomElem struct { Data string `mapstructure:"data" validate:"required"` @@ -80,18 +80,19 @@ type TextElem struct { type RevokeElem struct { RevokeMsgClientID string `mapstructure:"revokeMsgClientID" validate:"required"` } + type OANotificationElem struct { - NotificationName string `mapstructure:"notificationName" json:"notificationName" validate:"required"` - NotificationFaceURL string `mapstructure:"notificationFaceURL" json:"notificationFaceURL"` - NotificationType int32 `mapstructure:"notificationType" json:"notificationType" validate:"required"` - Text string `mapstructure:"text" json:"text" validate:"required"` - Url string `mapstructure:"url" json:"url"` - MixType int32 `mapstructure:"mixType" json:"mixType"` - PictureElem PictureElem `mapstructure:"pictureElem" json:"pictureElem"` - SoundElem SoundElem `mapstructure:"soundElem" json:"soundElem"` - VideoElem VideoElem `mapstructure:"videoElem" json:"videoElem"` - FileElem FileElem `mapstructure:"fileElem" json:"fileElem"` - Ex string `mapstructure:"ex" json:"ex"` + NotificationName string `mapstructure:"notificationName" json:"notificationName" validate:"required"` + NotificationFaceURL string `mapstructure:"notificationFaceURL" json:"notificationFaceURL"` + NotificationType int32 `mapstructure:"notificationType" json:"notificationType" validate:"required"` + Text string `mapstructure:"text" json:"text" validate:"required"` + Url string `mapstructure:"url" json:"url"` + MixType int32 `mapstructure:"mixType" json:"mixType" validate:"required"` + PictureElem *PictureElem `mapstructure:"pictureElem" json:"pictureElem"` + SoundElem *SoundElem `mapstructure:"soundElem" json:"soundElem"` + VideoElem *VideoElem `mapstructure:"videoElem" json:"videoElem"` + FileElem *FileElem `mapstructure:"fileElem" json:"fileElem"` + Ex string `mapstructure:"ex" json:"ex"` } type MessageRevoked struct { RevokerID string `mapstructure:"revokerID" json:"revokerID" validate:"required"` diff --git a/pkg/callbackstruct/constant.go b/pkg/callbackstruct/constant.go index f029e3713..2af337ac6 100644 --- a/pkg/callbackstruct/constant.go +++ b/pkg/callbackstruct/constant.go @@ -1,5 +1,20 @@ package callbackstruct +const CallbackBeforeInviteJoinGroupCommand = "callbackBeforeInviteJoinGroupCommand" +const CallbackAfterJoinGroupCommand = "callbackAfterJoinGroupCommand" +const CallbackAfterSetGroupInfoCommand = "callbackAfterSetGroupInfoCommand" +const CallbackBeforeSetGroupInfoCommand = "callbackBeforeSetGroupInfoCommand" + +const CallbackAfterRevokeMsgCommand = "callbackBeforeAfterMsgCommand" +const CallbackBeforeAddBlackCommand = "callbackBeforeAddBlackCommand" +const CallbackAfterAddFriendCommand = "callbackAfterAddFriendCommand" +const CallbackBeforeAddFriendAgreeCommand = "callbackBeforeAddFriendAgreeCommand" + +const CallbackAfterDeleteFriendCommand = "callbackAfterDeleteFriendCommand" +const CallbackBeforeImportFriendsCommand = "callbackBeforeImportFriendsCommand" +const CallbackAfterImportFriendsCommand = "callbackAfterImportFriendsCommand" +const CallbackAfterRemoveBlackCommand = "callbackAfterRemoveBlackCommand" + const ( CallbackQuitGroupCommand = "callbackQuitGroupCommand" CallbackKillGroupCommand = "callbackKillGroupCommand" @@ -29,5 +44,6 @@ const ( CallbackBeforeCreateGroupCommand = "callbackBeforeCreateGroupCommand" CallbackAfterCreateGroupCommand = "callbackAfterCreateGroupCommand" CallbackBeforeMemberJoinGroupCommand = "callbackBeforeMemberJoinGroupCommand" - CallbackBeforeSetGroupMemberInfoCommand = "CallbackBeforeSetGroupMemberInfoCommand" + CallbackBeforeSetGroupMemberInfoCommand = "callbackBeforeSetGroupMemberInfoCommand" + CallbackAfterSetGroupMemberInfoCommand = "callbackAfterSetGroupMemberInfoCommand" ) diff --git a/pkg/callbackstruct/friend.go b/pkg/callbackstruct/friend.go index ebbd08b19..3674a34da 100644 --- a/pkg/callbackstruct/friend.go +++ b/pkg/callbackstruct/friend.go @@ -19,6 +19,7 @@ type CallbackBeforeAddFriendReq struct { FromUserID string `json:"fromUserID" ` ToUserID string `json:"toUserID"` ReqMsg string `json:"reqMsg"` + Ex string `json:"ex"` } type CallbackBeforeAddFriendResp struct { @@ -35,6 +36,28 @@ type CallBackAddFriendReplyBeforeResp struct { CommonCallbackResp } +type CallbackBeforeSetFriendRemarkReq struct { + CallbackCommand `json:"callbackCommand"` + OwnerUserID string `json:"ownerUserID"` + FriendUserID string `json:"friendUserID"` + Remark string `json:"remark"` +} + +type CallbackBeforeSetFriendRemarkResp struct { + CommonCallbackResp + Remark string `json:"remark"` +} + +type CallbackAfterSetFriendRemarkReq struct { + CallbackCommand `json:"callbackCommand"` + OwnerUserID string `json:"ownerUserID"` + FriendUserID string `json:"friendUserID"` + Remark string `json:"remark"` +} + +type CallbackAfterSetFriendRemarkResp struct { + CommonCallbackResp +} type CallbackAfterAddFriendReq struct { CallbackCommand `json:"callbackCommand"` FromUserID string `json:"fromUserID" ` @@ -45,26 +68,60 @@ type CallbackAfterAddFriendReq struct { type CallbackAfterAddFriendResp struct { CommonCallbackResp } +type CallbackBeforeAddBlackReq struct { + CallbackCommand `json:"callbackCommand"` + OwnerUserID string `json:"ownerUserID" ` + BlackUserID string `json:"blackUserID"` +} -type CallbackBeforeSetFriendRemarkReq struct { +type CallbackBeforeAddBlackResp struct { + CommonCallbackResp +} + +type CallbackBeforeAddFriendAgreeReq struct { CallbackCommand `json:"callbackCommand"` - OwnerUserID string `json:"ownerUserID"` - FriendUserID string `json:"friendUserID"` - Remark string `json:"remark"` + FromUserID string `json:"fromUserID" ` + ToUserID string `json:"blackUserID"` + HandleResult int32 `json:"HandleResult"` + HandleMsg string `json:"HandleMsg"` } -type CallbackBeforeSetFriendRemarkResp struct { +type CallbackBeforeAddFriendAgreeResp struct { CommonCallbackResp - Remark string `json:"remark"` } -type CallbackAfterSetFriendRemarkReq struct { +type CallbackAfterDeleteFriendReq struct { CallbackCommand `json:"callbackCommand"` - OwnerUserID string `json:"ownerUserID"` + OwnerUserID string `json:"ownerUserID" ` FriendUserID string `json:"friendUserID"` - Remark string `json:"remark"` +} +type CallbackAfterDeleteFriendResp struct { + CommonCallbackResp } -type CallbackAfterSetFriendRemarkResp struct { +type CallbackBeforeImportFriendsReq struct { + CallbackCommand `json:"callbackCommand"` + OwnerUserID string `json:"ownerUserID" ` + FriendUserIDs []string `json:"friendUserIDs"` +} +type CallbackBeforeImportFriendsResp struct { + CommonCallbackResp + FriendUserIDs []string `json:"friendUserIDs"` +} +type CallbackAfterImportFriendsReq struct { + CallbackCommand `json:"callbackCommand"` + OwnerUserID string `json:"ownerUserID" ` + FriendUserIDs []string `json:"friendUserIDs"` +} +type CallbackAfterImportFriendsResp struct { + CommonCallbackResp +} + +type CallbackAfterRemoveBlackReq struct { + CallbackCommand `json:"callbackCommand"` + OwnerUserID string `json:"ownerUserID"` + BlackUserID string `json:"blackUserID"` +} +type CallbackAfterRemoveBlackResp struct { CommonCallbackResp } diff --git a/pkg/callbackstruct/group.go b/pkg/callbackstruct/group.go index 79e02ba0f..899b4312f 100644 --- a/pkg/callbackstruct/group.go +++ b/pkg/callbackstruct/group.go @@ -109,108 +109,127 @@ type CallbackAfterSetGroupMemberInfoResp struct { CommonCallbackResp } -type CallbackAfterGroupMemberExitReq struct { +type CallbackQuitGroupReq struct { CallbackCommand `json:"callbackCommand"` GroupID string `json:"groupID"` UserID string `json:"userID"` - GroupType *int32 `json:"groupType"` - ExitType string `json:"exitType"` } -type CallbackAfterGroupMemberExitResp struct { +type CallbackQuitGroupResp struct { CommonCallbackResp } -type CallbackAfterUngroupReq struct { +type CallbackKillGroupMemberReq struct { CallbackCommand `json:"callbackCommand"` GroupID string `json:"groupID"` - GroupType *int32 `json:"groupType"` - OwnerID string `json:"ownerID"` - MemberList []string `json:"memberList"` + KickedUserIDs []string `json:"kickedUserIDs"` + Reason string `json:"reason"` } -type CallbackAfterUngroupResp struct { +type CallbackKillGroupMemberResp struct { CommonCallbackResp } -type CallbackAfterSetGroupInfoReq struct { +type CallbackDisMissGroupReq struct { CallbackCommand `json:"callbackCommand"` - GroupID string `json:"groupID"` - GroupType *int32 `json:"groupType"` - UserID string `json:"userID"` - Name string `json:"name"` - Notification string `json:"notification"` - GroupUrl string `json:"groupUrl"` + GroupID string `json:"groupID"` + OwnerID string `json:"ownerID"` + GroupType string `json:"groupType"` + MembersID []string `json:"membersID"` } -type CallbackAfterSetGroupInfoResp struct { +type CallbackDisMissGroupResp struct { CommonCallbackResp } -type CallbackAfterRevokeMsgReq struct { +type CallbackJoinGroupReq struct { CallbackCommand `json:"callbackCommand"` GroupID string `json:"groupID"` - GroupType *int32 `json:"groupType"` - UserID string `json:"userID"` - Content string `json:"content"` + GroupType string `json:"groupType"` + ApplyID string `json:"applyID"` + ReqMessage string `json:"reqMessage"` } -type CallbackAfterRevokeMsgResp struct { +type CallbackJoinGroupResp struct { CommonCallbackResp } -type CallbackQuitGroupReq struct { +type CallbackTransferGroupOwnerReq struct { CallbackCommand `json:"callbackCommand"` GroupID string `json:"groupID"` - UserID string `json:"userID"` + OldOwnerUserID string `json:"oldOwnerUserID"` + NewOwnerUserID string `json:"newOwnerUserID"` } -type CallbackQuitGroupResp struct { +type CallbackTransferGroupOwnerResp struct { CommonCallbackResp } -type CallbackKillGroupMemberReq struct { +type CallbackBeforeInviteUserToGroupReq struct { CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` GroupID string `json:"groupID"` - KickedUserIDs []string `json:"kickedUserIDs"` Reason string `json:"reason"` + InvitedUserIDs []string `json:"invitedUserIDs"` } - -type CallbackKillGroupMemberResp struct { +type CallbackBeforeInviteUserToGroupResp struct { CommonCallbackResp + RefusedMembersAccount []string `json:"refusedMembersAccount,omitempty"` // Optional field to list members whose invitation is refused. } -type CallbackDisMissGroupReq struct { +type CallbackAfterJoinGroupReq struct { CallbackCommand `json:"callbackCommand"` - GroupID string `json:"groupID"` - OwnerID string `json:"ownerID"` - GroupType string `json:"groupType"` - MembersID []string `json:"membersID"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + ReqMessage string `json:"reqMessage"` + JoinSource int32 `json:"joinSource"` + InviterUserID string `json:"inviterUserID"` } - -type CallbackDisMissGroupResp struct { +type CallbackAfterJoinGroupResp struct { CommonCallbackResp } -type CallbackJoinGroupReq struct { - CallbackCommand `json:"callbackCommand"` - GroupID string `json:"groupID"` - GroupType string `json:"groupType"` - ApplyID string `json:"applyID"` - ReqMessage string `json:"reqMessage"` +type CallbackBeforeSetGroupInfoReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + GroupName string `json:"groupName"` + Notification string `json:"notification"` + Introduction string `json:"introduction"` + FaceURL string `json:"faceURL"` + Ex string `json:"ex"` + NeedVerification int32 `json:"needVerification"` + LookMemberInfo int32 `json:"lookMemberInfo"` + ApplyMemberFriend int32 `json:"applyMemberFriend"` } -type CallbackJoinGroupResp struct { +type CallbackBeforeSetGroupInfoResp struct { CommonCallbackResp + GroupID string ` json:"groupID"` + GroupName string `json:"groupName"` + Notification string `json:"notification"` + Introduction string `json:"introduction"` + FaceURL string `json:"faceURL"` + Ex *string `json:"ex"` + NeedVerification *int32 `json:"needVerification"` + LookMemberInfo *int32 `json:"lookMemberInfo"` + ApplyMemberFriend *int32 `json:"applyMemberFriend"` } -type CallbackTransferGroupOwnerReq struct { - CallbackCommand `json:"callbackCommand"` - GroupID string `json:"groupID"` - OldOwnerUserID string `json:"oldOwnerUserID"` - NewOwnerUserID string `json:"newOwnerUserID"` +type CallbackAfterSetGroupInfoReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + GroupName string `json:"groupName"` + Notification string `json:"notification"` + Introduction string `json:"introduction"` + FaceURL string `json:"faceURL"` + Ex *string `json:"ex"` + NeedVerification *int32 `json:"needVerification"` + LookMemberInfo *int32 `json:"lookMemberInfo"` + ApplyMemberFriend *int32 `json:"applyMemberFriend"` } -type CallbackTransferGroupOwnerResp struct { +type CallbackAfterSetGroupInfoResp struct { CommonCallbackResp } diff --git a/pkg/callbackstruct/message.go b/pkg/callbackstruct/message.go index 3adee618b..ae36d7139 100644 --- a/pkg/callbackstruct/message.go +++ b/pkg/callbackstruct/message.go @@ -80,26 +80,6 @@ type CallbackMsgModifyCommandResp struct { Ex *string `json:"ex"` } -type CallbackSendGroupMsgErrorReq struct { - CommonCallbackReq - GroupID string `json:"groupID"` -} - -type CallbackSendGroupMsgErrorResp struct { - CommonCallbackResp -} - -type CallbackSingleMsgRevokeReq struct { - CallbackCommand `json:"callbackCommand"` - SendID string `json:"sendID"` - ReceiveID string `json:"receiveID"` - Content string `json:"content"` -} - -type CallbackSingleMsgRevokeResp struct { - CommonCallbackResp -} - type CallbackGroupMsgReadReq struct { CallbackCommand `json:"callbackCommand"` SendID string `json:"sendID"` diff --git a/pkg/callbackstruct/revoke.go b/pkg/callbackstruct/revoke.go new file mode 100644 index 000000000..364c0162b --- /dev/null +++ b/pkg/callbackstruct/revoke.go @@ -0,0 +1,11 @@ +package callbackstruct + +type CallbackAfterRevokeMsgReq struct { + CallbackCommand `json:"callbackCommand"` + ConversationID string `json:"conversationID"` + Seq int64 `json:"seq"` + UserID string `json:"userID"` +} +type CallbackAfterRevokeMsgResp struct { + CommonCallbackResp +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index d8bee6af8..3c819ea2c 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -16,7 +16,6 @@ package config import ( "bytes" - "github.com/OpenIMSDK/tools/discoveryregistry" "gopkg.in/yaml.v3" ) @@ -282,11 +281,25 @@ type configStruct struct { CallbackAfterCreateGroup CallBackConfig `yaml:"afterCreateGroup"` CallbackBeforeMemberJoinGroup CallBackConfig `yaml:"beforeMemberJoinGroup"` CallbackBeforeSetGroupMemberInfo CallBackConfig `yaml:"beforeSetGroupMemberInfo"` + CallbackAfterSetGroupMemberInfo CallBackConfig `yaml:"afterSetGroupMemberInfo"` CallbackQuitGroup CallBackConfig `yaml:"quitGroup"` CallbackKillGroupMember CallBackConfig `yaml:"killGroupMember"` CallbackDismissGroup CallBackConfig `yaml:"dismissGroup"` CallbackBeforeJoinGroup CallBackConfig `yaml:"joinGroup"` CallbackTransferGroupOwnerAfter CallBackConfig `yaml:"transferGroupOwner"` + CallbackBeforeInviteUserToGroup CallBackConfig `yaml:"beforeInviteUserToGroup"` + CallbackAfterJoinGroup CallBackConfig `yaml:"joinGroupAfter"` + CallbackAfterSetGroupInfo CallBackConfig `yaml:"setGroupInfoAfter"` + CallbackBeforeSetGroupInfo CallBackConfig `yaml:"setGroupInfoBefore"` + CallbackAfterRevokeMsg CallBackConfig `yaml:"revokeMsgAfter"` + CallbackBeforeAddBlack CallBackConfig `yaml:"addBlackBefore"` + CallbackAfterAddFriend CallBackConfig `yaml:"addFriendAfter"` + CallbackBeforeAddFriendAgree CallBackConfig `yaml:"addFriendAgreeBefore"` + + CallbackAfterDeleteFriend CallBackConfig `yaml:"deleteFriendAfter"` + CallbackBeforeImportFriends CallBackConfig `yaml:"importFriendsBefore"` + CallbackAfterImportFriends CallBackConfig `yaml:"importFriendsAfter"` + CallbackAfterRemoveBlack CallBackConfig `yaml:"removeBlackAfter"` } `yaml:"callback"` Prometheus struct { diff --git a/scripts/install/environment.sh b/scripts/install/environment.sh index 98636bbde..b7c8a5dcb 100755 --- a/scripts/install/environment.sh +++ b/scripts/install/environment.sh @@ -386,10 +386,9 @@ def "IOS_PUSH_SOUND" "xxx" # IOS推送声音 def "IOS_BADGE_COUNT" "true" # IOS徽章计数 def "IOS_PRODUCTION" "false" # IOS生产 # callback 配置 -def "CALLBACK_ENABLE" "true" # 是否开启 Callback +def "CALLBACK_ENABLE" "false" # 是否开启 Callback def "CALLBACK_TIMEOUT" "5" # 最长超时时间 def "CALLBACK_FAILED_CONTINUE" "true" # 失败后是否继续 - ###################### Prometheus 配置信息 ###################### # 是否启用 Prometheus readonly PROMETHEUS_ENABLE=${PROMETHEUS_ENABLE:-'false'}