From b7b049e4b182f9f377965dfd0ec234d56e55f862 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Tue, 14 Nov 2023 18:16:00 +0800 Subject: [PATCH] feat:callback test --- config/config.yaml | 6 ++- internal/rpc/group/callback.go | 42 ++++++++++++++++++++ internal/rpc/group/group.go | 9 +++++ pkg/callbackstruct/common.go | 3 +- pkg/callbackstruct/friend.go | 23 +++++++++++ pkg/callbackstruct/group.go | 71 ++++++++++++++++++++++++++++++++++ pkg/callbackstruct/message.go | 34 ++++++++++++++++ pkg/common/config/config.go | 1 + 8 files changed, 187 insertions(+), 2 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index e375118f7..60a0ac236 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -312,7 +312,7 @@ iosPush: # Timeout in seconds # Whether to continue execution if callback fails callback: - url: + url: "http://127.0.0.1:8080/sdkName" beforeSendSingleMsg: enable: false timeout: 5 @@ -364,6 +364,10 @@ callback: enable: false timeout: 5 failedContinue: true + afterCreateGroup: + enable: false + timeout: 5 + failedContinue: true beforeMemberJoinGroup: enable: false timeout: 5 diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index 38174738b..01d7f44e6 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -86,6 +86,48 @@ func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) ( return nil } +func CallbackAfterCreateGroup(ctx context.Context, req *group.CreateGroupReq) (err error) { + if !config.Config.Callback.CallbackBeforeCreateGroup.Enable { + return nil + } + cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{ + CallbackCommand: "callbackAfterCreateGroupCommand", + OperationID: mcontext.GetOperationID(ctx), + GroupInfo: req.GroupInfo, + } + cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{ + UserID: req.OwnerUserID, + RoleLevel: constant.GroupOwner, + }) + for _, userID := range req.AdminUserIDs { + cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{ + UserID: userID, + RoleLevel: constant.GroupAdmin, + }) + } + for _, userID := range req.MemberUserIDs { + cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{ + UserID: userID, + RoleLevel: constant.GroupOrdinaryUsers, + }) + } + resp := &callbackstruct.CallbackBeforeCreateGroupResp{} + err = http.CallBackPostReturn( + ctx, + config.Config.Callback.CallbackUrl, + cbReq, + resp, + config.Config.Callback.CallbackBeforeCreateGroup, + ) + if err != nil { + if err == errs.ErrCallbackContinue { + return nil + } + return err + } + return nil +} + func CallbackBeforeMemberJoinGroup( ctx context.Context, groupMember *relation.GroupMemberModel, diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 6a0ce5733..7327257bd 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -225,6 +225,7 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbgroup.CreateGroupR if len(userMap) != len(userIDs) { return nil, errs.ErrUserIDNotFound.Wrap("user not found") } + // Callback Before create Group if err := CallbackBeforeCreateGroup(ctx, req); err != nil { return nil, err } @@ -298,6 +299,14 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbgroup.CreateGroupR } s.Notification.GroupCreatedNotification(ctx, tips) } + reqCallBackAfter := &pbgroup.CreateGroupReq{ + GroupInfo: resp.GroupInfo, + } + + if err := CallbackAfterCreateGroup(ctx, reqCallBackAfter); err != nil { + return nil, err + } + return resp, nil } diff --git a/pkg/callbackstruct/common.go b/pkg/callbackstruct/common.go index ef84d52b9..0922dbf19 100644 --- a/pkg/callbackstruct/common.go +++ b/pkg/callbackstruct/common.go @@ -51,10 +51,11 @@ type CallbackResp interface { } type CommonCallbackResp struct { - ActionCode int `json:"actionCode"` + ActionCode int32 `json:"actionCode"` ErrCode int32 `json:"errCode"` ErrMsg string `json:"errMsg"` ErrDlt string `json:"errDlt"` + NextCode int32 `json:"nextCode"` } func (c CommonCallbackResp) Parse() error { diff --git a/pkg/callbackstruct/friend.go b/pkg/callbackstruct/friend.go index 7e89824e2..bbafb7f2f 100644 --- a/pkg/callbackstruct/friend.go +++ b/pkg/callbackstruct/friend.go @@ -25,3 +25,26 @@ type CallbackBeforeAddFriendReq struct { type CallbackBeforeAddFriendResp struct { CommonCallbackResp } + +type CallBackAddFriendReplyBeforeReq struct { + CallbackCommand `json:"callbackCommand"` + FromUserID string `json:"fromUserID" ` + ToUserID string `json:"toUserID"` + OperationID string `json:"operationID"` +} + +type CallBackAddFriendReplyBeforeResp struct { + CommonCallbackResp +} + +type CallbackAfterAddFriendReq struct { + CallbackCommand `json:"callbackCommand"` + FromUserID string `json:"fromUserID" ` + ToUserID string `json:"toUserID"` + ReqMsg string `json:"reqMsg"` + OperationID string `json:"operationID"` +} + +type CallbackAfterAddFriendResp struct { + CommonCallbackResp +} diff --git a/pkg/callbackstruct/group.go b/pkg/callbackstruct/group.go index 11b33bf0a..423f31fab 100644 --- a/pkg/callbackstruct/group.go +++ b/pkg/callbackstruct/group.go @@ -86,3 +86,74 @@ type CallbackBeforeSetGroupMemberInfoResp struct { FaceURL *string `json:"faceURL"` RoleLevel *int32 `json:"roleLevel"` } + +type CallbackAfterGroupMemberExitReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + UserID string `json:"userID"` + GroupType *int32 `json:"groupType"` + ExitType string `json:"exitType"` + MuteEndTime *int64 `json:"muteEndTime"` +} + +type CallbackAfterGroupMemberExitResp struct { + CommonCallbackResp +} + +type CallbackAfterUngroupReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + GroupType *int32 `json:"groupType"` + OwnerID string `json:"ownerID"` + MemberList []string `json:"memberList"` + MuteEndTime *int64 `json:"muteEndTime"` +} + +type CallbackAfterUngroupResp struct { + CommonCallbackResp +} + +type CallbackAfterSetGroupInfoReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + GroupType *int32 `json:"groupType"` + UserID string `json:"userID"` + Name string `json:"name"` + Notification string `json:"notification"` + GroupUrl string `json:"groupUrl"` + MuteEndTime *int64 `json:"muteEndTime"` +} + +type CallbackAfterSetGroupInfoResp struct { + CommonCallbackResp +} + +type CallbackAfterRevokeMsgReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + GroupID string `json:"groupID"` + GroupType *int32 `json:"groupType"` + UserID string `json:"userID"` + Content string `json:"content"` + MuteEndTime *int64 `json:"muteEndTime"` +} + +type CallbackAfterRevokeMsgResp struct { + CommonCallbackResp +} + +type CallbackGroupMsgReadReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + SendID string `json:"sendID"` + ReceiveID string `json:"receiveID"` + UnreadMsgNum int64 `json:"UnreadMsgNum"` + MuteEndTime *int64 `json:"muteEndTime"` +} + +type CallbackGroupMsgReadResp struct { + CommonCallbackResp +} diff --git a/pkg/callbackstruct/message.go b/pkg/callbackstruct/message.go index f404088e8..e5916e326 100644 --- a/pkg/callbackstruct/message.go +++ b/pkg/callbackstruct/message.go @@ -79,3 +79,37 @@ type CallbackMsgModifyCommandResp struct { AttachedInfo *string `json:"attachedInfo"` Ex *string `json:"ex"` } + +type CallbackSendGroupMsgErrorReq struct { + CommonCallbackReq + GroupID string `json:"groupID"` +} + +type CallbackSendGroupMsgErrorResp struct { + CommonCallbackResp +} + +type CallbackSingleMsgReadReq struct { + CallbackCommand string `json:"callbackCommand"` + OperationID string `json:"operationID"` + SendID string `json:"sendID"` + ReceiveID string `json:"receiveID"` + MuteEndTime *int64 `json:"muteEndTime"` +} + +type CallbackSingleMsgReadResp struct { + CommonCallbackResp +} + +type CallbackSingleMsgRevokeReq struct { + CallbackCommand `json:"callbackCommand"` + OperationID string `json:"operationID"` + SendID string `json:"sendID"` + ReceiveID string `json:"receiveID"` + Content string `json:"content"` + MuteEndTime *int64 `json:"muteEndTime"` +} + +type CallbackSingleMsgRevokeResp struct { + CommonCallbackResp +} diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index d7cecc616..1ab61c3da 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -257,6 +257,7 @@ type configStruct struct { CallbackBeforeAddFriend CallBackConfig `yaml:"beforeAddFriend"` CallbackBeforeUpdateUserInfo CallBackConfig `yaml:"beforeUpdateUserInfo"` CallbackBeforeCreateGroup CallBackConfig `yaml:"beforeCreateGroup"` + CallbackAfterCreateGroup CallBackConfig `yaml:"afterCreateGroup"` CallbackBeforeMemberJoinGroup CallBackConfig `yaml:"beforeMemberJoinGroup"` CallbackBeforeSetGroupMemberInfo CallBackConfig `yaml:"beforeSetGroupMemberInfo"` } `yaml:"callback"`