diff --git a/deployments/templates/openim.yaml b/deployments/templates/openim.yaml index f0daaa934..9647f6832 100644 --- a/deployments/templates/openim.yaml +++ b/deployments/templates/openim.yaml @@ -406,7 +406,10 @@ callback: enable: true timeout: 5 failedContinue: true - + revokeMsgAfter: + enable: false + timeout: 5 + failedContinue: true ###################### Prometheus ###################### # Prometheus configuration for various services diff --git a/internal/rpc/friend/black.go b/internal/rpc/friend/black.go index b1a5ea6b5..29b598e0c 100644 --- a/internal/rpc/friend/black.go +++ b/internal/rpc/friend/black.go @@ -85,6 +85,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 bb687773e..77f0d0980 100644 --- a/internal/rpc/friend/callback.go +++ b/internal/rpc/friend/callback.go @@ -16,6 +16,7 @@ package friend import ( "context" + "github.com/OpenIMSDK/tools/utils" "github.com/OpenIMSDK/protocol/constant" pbfriend "github.com/OpenIMSDK/protocol/friend" @@ -47,3 +48,66 @@ func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriend } 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, + OperationID: mcontext.GetOperationID(ctx), + } + resp := &cbapi.CallbackBeforeAddBlackResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddBlack); err != nil { + if err == errs.ErrCallbackContinue { + return nil + } + return err + } + utils.StructFieldNotNilReplace(req, resp) + 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, + OperationID: mcontext.GetOperationID(ctx), + } + resp := &cbapi.CallbackAfterAddFriendResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterAddFriend); err != nil { + if err == errs.ErrCallbackContinue { + return nil + } + return err + } + utils.StructFieldNotNilReplace(req, resp) + 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, + OperationID: mcontext.GetOperationID(ctx), + } + resp := &cbapi.CallbackBeforeAddFriendAgreeResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriendAgree); err != nil { + if err == errs.ErrCallbackContinue { + return nil + } + return err + } + utils.StructFieldNotNilReplace(req, resp) + return nil +} diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index c563f77fe..dbaff5f7b 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -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 } @@ -172,6 +175,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 diff --git a/internal/rpc/group/callback.go b/internal/rpc/group/callback.go index 73ce6d080..3ad2c48b2 100644 --- a/internal/rpc/group/callback.go +++ b/internal/rpc/group/callback.go @@ -316,5 +316,3 @@ func CallbackAfterSetGroupInfo(ctx context.Context, req *group.SetGroupInfoReq) utils.StructFieldNotNilReplace(req, resp) return nil } - -// TODO CALLBACK diff --git a/internal/rpc/msg/callback.go b/internal/rpc/msg/callback.go index ab2c082aa..427f19ab3 100644 --- a/internal/rpc/msg/callback.go +++ b/internal/rpc/msg/callback.go @@ -16,7 +16,6 @@ package msg import ( "context" - "github.com/OpenIMSDK/protocol/sdkws" "google.golang.org/protobuf/proto" @@ -28,6 +27,7 @@ import ( "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" ) @@ -178,4 +178,23 @@ func callbackMsgModify(ctx context.Context, msg *pbchat.SendMsgReq) error { return nil } -//TODO CALLBACK +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.CallbackAfterSendGroupMsgResp{} + if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackAfterSetGroupInfo); err != nil { + if err == errs.ErrCallbackContinue { + return 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/pkg/callbackstruct/constant.go b/pkg/callbackstruct/constant.go index 9ce0f8656..56329d1cb 100644 --- a/pkg/callbackstruct/constant.go +++ b/pkg/callbackstruct/constant.go @@ -6,3 +6,8 @@ const CallbackAfterSetGroupInfoCommand = "CallbackAfterSetGroupInfoCommand" const CallbackBeforeSetGroupInfoCommand = "CallbackBeforeSetGroupInfoCommand" // TODO CALLBACK + +const CallbackAfterRevokeMsgCommand = "CallbackBeforeAfterMsgCommand" +const CallbackBeforeAddBlackCommand = "CallbackBeforeAddBlackCommand" +const CallbackAfterAddFriendCommand = "CallbackAfterAddFriendCommand" +const CallbackBeforeAddFriendAgreeCommand = "CallbackBeforeAddFriendAgreeCommand" diff --git a/pkg/callbackstruct/friend.go b/pkg/callbackstruct/friend.go index 7e89824e2..f78aa7d16 100644 --- a/pkg/callbackstruct/friend.go +++ b/pkg/callbackstruct/friend.go @@ -25,3 +25,37 @@ type CallbackBeforeAddFriendReq struct { type CallbackBeforeAddFriendResp 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 +} +type CallbackBeforeAddBlackReq struct { + CallbackCommand `json:"callbackCommand"` + OwnerUserID string `json:"ownerUserID" ` + BlackUserID string `json:"blackUserID"` + OperationID string `json:"operationID"` +} + +type CallbackBeforeAddBlackResp struct { + CommonCallbackResp +} + +type CallbackBeforeAddFriendAgreeReq struct { + CallbackCommand `json:"callbackCommand"` + FromUserID string `json:"fromUserID" ` + ToUserID string `json:"blackUserID"` + HandleResult int32 `json:"HandleResult"'` + HandleMsg string `json:"HandleMsg"'` + OperationID string `json:"operationID"` +} + +type CallbackBeforeAddFriendAgreeResp struct { + CommonCallbackResp +} diff --git a/pkg/callbackstruct/message.go b/pkg/callbackstruct/message.go index de8bae2c5..f404088e8 100644 --- a/pkg/callbackstruct/message.go +++ b/pkg/callbackstruct/message.go @@ -79,5 +79,3 @@ type CallbackMsgModifyCommandResp struct { AttachedInfo *string `json:"attachedInfo"` Ex *string `json:"ex"` } - -// TODO CALLBACK 2 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 3a59a4213..05cc770c6 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -268,6 +268,10 @@ type configStruct struct { CallbackAfterSetGroupInfo CallBackConfig `yaml:"setGroupInfoAfter"` CallbackBeforeSetGroupInfo CallBackConfig `yaml:"setGroupInfoBefore"` //TODO CALLBACK/ + CallbackAfterRevokeMsg CallBackConfig `yaml:"revokeMsgAfter"` + CallbackBeforeAddBlack CallBackConfig `yaml:"addBlackBefore"` + CallbackAfterAddFriend CallBackConfig `yaml:"addFriendAfter"` + CallbackBeforeAddFriendAgree CallBackConfig `yaml:"addFriendAgreeBefore"` } `yaml:"callback"` Prometheus struct {