fix: callback update.

pull/2148/head
Gordon 1 year ago
parent e618a8f282
commit e82fd5a95e

@ -16,6 +16,7 @@ package push
import ( import (
"context" "context"
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct" "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/config"
@ -26,6 +27,7 @@ import (
) )
func (p *Pusher) webhookBeforeOfflinePush(ctx context.Context, before *config.BeforeConfig, userIDs []string, msg *sdkws.MsgData, offlinePushUserIDs *[]string) error { func (p *Pusher) webhookBeforeOfflinePush(ctx context.Context, before *config.BeforeConfig, userIDs []string, msg *sdkws.MsgData, offlinePushUserIDs *[]string) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
if msg.ContentType == constant.Typing { if msg.ContentType == constant.Typing {
return nil return nil
} }
@ -62,9 +64,11 @@ func (p *Pusher) webhookBeforeOfflinePush(ctx context.Context, before *config.Be
msg.OfflinePushInfo = resp.OfflinePushInfo msg.OfflinePushInfo = resp.OfflinePushInfo
} }
return nil return nil
})
} }
func (p *Pusher) webhookBeforeOnlinePush(ctx context.Context, before *config.BeforeConfig, userIDs []string, msg *sdkws.MsgData) error { func (p *Pusher) webhookBeforeOnlinePush(ctx context.Context, before *config.BeforeConfig, userIDs []string, msg *sdkws.MsgData) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
if datautil.Contain(msg.SendID, userIDs...) || msg.ContentType == constant.Typing { if datautil.Contain(msg.SendID, userIDs...) || msg.ContentType == constant.Typing {
return nil return nil
} }
@ -91,6 +95,7 @@ func (p *Pusher) webhookBeforeOnlinePush(ctx context.Context, before *config.Bef
return err return err
} }
return nil return nil
})
} }
func (p *Pusher) webhookBeforeGroupOnlinePush( func (p *Pusher) webhookBeforeGroupOnlinePush(
@ -100,6 +105,7 @@ func (p *Pusher) webhookBeforeGroupOnlinePush(
msg *sdkws.MsgData, msg *sdkws.MsgData,
pushToUserIDs *[]string, pushToUserIDs *[]string,
) error { ) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
if msg.ContentType == constant.Typing { if msg.ContentType == constant.Typing {
return nil return nil
} }
@ -127,4 +133,5 @@ func (p *Pusher) webhookBeforeGroupOnlinePush(
*pushToUserIDs = resp.UserIDs *pushToUserIDs = resp.UserIDs
} }
return nil return nil
})
} }

@ -16,6 +16,7 @@ package friend
import ( import (
"context" "context"
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct" 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/config"
@ -32,6 +33,7 @@ func (s *friendServer) webhookAfterDeleteFriend(ctx context.Context, after *conf
} }
func (s *friendServer) webhookBeforeAddFriend(ctx context.Context, before *config.BeforeConfig, req *pbfriend.ApplyToAddFriendReq) error { func (s *friendServer) webhookBeforeAddFriend(ctx context.Context, before *config.BeforeConfig, req *pbfriend.ApplyToAddFriendReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &cbapi.CallbackBeforeAddFriendReq{ cbReq := &cbapi.CallbackBeforeAddFriendReq{
CallbackCommand: cbapi.CallbackBeforeAddFriendCommand, CallbackCommand: cbapi.CallbackBeforeAddFriendCommand,
FromUserID: req.FromUserID, FromUserID: req.FromUserID,
@ -45,6 +47,7 @@ func (s *friendServer) webhookBeforeAddFriend(ctx context.Context, before *confi
return err return err
} }
return nil return nil
})
} }
func (s *friendServer) webhookAfterAddFriend(ctx context.Context, after *config.AfterConfig, req *pbfriend.ApplyToAddFriendReq) { func (s *friendServer) webhookAfterAddFriend(ctx context.Context, after *config.AfterConfig, req *pbfriend.ApplyToAddFriendReq) {
@ -91,6 +94,7 @@ func (s *friendServer) webhookAfterRemoveBlack(ctx context.Context, after *confi
} }
func (s *friendServer) webhookBeforeSetFriendRemark(ctx context.Context, before *config.BeforeConfig, req *pbfriend.SetFriendRemarkReq) error { func (s *friendServer) webhookBeforeSetFriendRemark(ctx context.Context, before *config.BeforeConfig, req *pbfriend.SetFriendRemarkReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &cbapi.CallbackBeforeSetFriendRemarkReq{ cbReq := &cbapi.CallbackBeforeSetFriendRemarkReq{
CallbackCommand: cbapi.CallbackBeforeSetFriendRemarkCommand, CallbackCommand: cbapi.CallbackBeforeSetFriendRemarkCommand,
OwnerUserID: req.OwnerUserID, OwnerUserID: req.OwnerUserID,
@ -105,12 +109,11 @@ func (s *friendServer) webhookBeforeSetFriendRemark(ctx context.Context, before
req.Remark = resp.Remark req.Remark = resp.Remark
} }
return nil return nil
})
} }
func (s *friendServer) webhookBeforeAddBlack(ctx context.Context, before *config.BeforeConfig, req *pbfriend.AddBlackReq) error { func (s *friendServer) webhookBeforeAddBlack(ctx context.Context, before *config.BeforeConfig, req *pbfriend.AddBlackReq) error {
if !before.Enable { return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
return nil
}
cbReq := &cbapi.CallbackBeforeAddBlackReq{ cbReq := &cbapi.CallbackBeforeAddBlackReq{
CallbackCommand: cbapi.CallbackBeforeAddBlackCommand, CallbackCommand: cbapi.CallbackBeforeAddBlackCommand,
OwnerUserID: req.OwnerUserID, OwnerUserID: req.OwnerUserID,
@ -118,12 +121,11 @@ func (s *friendServer) webhookBeforeAddBlack(ctx context.Context, before *config
} }
resp := &cbapi.CallbackBeforeAddBlackResp{} resp := &cbapi.CallbackBeforeAddBlackResp{}
return s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before) return s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before)
})
} }
func (s *friendServer) webhookBeforeAddFriendAgree(ctx context.Context, before *config.BeforeConfig, req *pbfriend.RespondFriendApplyReq) error { func (s *friendServer) webhookBeforeAddFriendAgree(ctx context.Context, before *config.BeforeConfig, req *pbfriend.RespondFriendApplyReq) error {
if !before.Enable { return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
return nil
}
cbReq := &cbapi.CallbackBeforeAddFriendAgreeReq{ cbReq := &cbapi.CallbackBeforeAddFriendAgreeReq{
CallbackCommand: cbapi.CallbackBeforeAddFriendAgreeCommand, CallbackCommand: cbapi.CallbackBeforeAddFriendAgreeCommand,
FromUserID: req.FromUserID, FromUserID: req.FromUserID,
@ -133,12 +135,11 @@ func (s *friendServer) webhookBeforeAddFriendAgree(ctx context.Context, before *
} }
resp := &cbapi.CallbackBeforeAddFriendAgreeResp{} resp := &cbapi.CallbackBeforeAddFriendAgreeResp{}
return s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before) return s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before)
})
} }
func (s *friendServer) webhookBeforeImportFriends(ctx context.Context, before *config.BeforeConfig, req *pbfriend.ImportFriendReq) error { func (s *friendServer) webhookBeforeImportFriends(ctx context.Context, before *config.BeforeConfig, req *pbfriend.ImportFriendReq) error {
if !before.Enable { return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
return nil
}
cbReq := &cbapi.CallbackBeforeImportFriendsReq{ cbReq := &cbapi.CallbackBeforeImportFriendsReq{
CallbackCommand: cbapi.CallbackBeforeImportFriendsCommand, CallbackCommand: cbapi.CallbackBeforeImportFriendsCommand,
OwnerUserID: req.OwnerUserID, OwnerUserID: req.OwnerUserID,
@ -152,4 +153,5 @@ func (s *friendServer) webhookBeforeImportFriends(ctx context.Context, before *c
req.FriendUserIDs = resp.FriendUserIDs req.FriendUserIDs = resp.FriendUserIDs
} }
return nil return nil
})
} }

@ -20,6 +20,7 @@ import (
"github.com/openimsdk/open-im-server/v3/pkg/callbackstruct" "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/config"
"github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation" "github.com/openimsdk/open-im-server/v3/pkg/common/db/table/relation"
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
"github.com/openimsdk/protocol/constant" "github.com/openimsdk/protocol/constant"
"github.com/openimsdk/protocol/group" "github.com/openimsdk/protocol/group"
"github.com/openimsdk/protocol/wrapperspb" "github.com/openimsdk/protocol/wrapperspb"
@ -31,6 +32,7 @@ import (
// CallbackBeforeCreateGroup callback before create group. // CallbackBeforeCreateGroup callback before create group.
func (s *groupServer) webhookBeforeCreateGroup(ctx context.Context, before *config.BeforeConfig, req *group.CreateGroupReq) error { func (s *groupServer) webhookBeforeCreateGroup(ctx context.Context, before *config.BeforeConfig, req *group.CreateGroupReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{ cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{
CallbackCommand: callbackstruct.CallbackBeforeCreateGroupCommand, CallbackCommand: callbackstruct.CallbackBeforeCreateGroupCommand,
OperationID: mcontext.GetOperationID(ctx), OperationID: mcontext.GetOperationID(ctx),
@ -71,6 +73,7 @@ func (s *groupServer) webhookBeforeCreateGroup(ctx context.Context, before *conf
datautil.NotNilReplace(&req.GroupInfo.NeedVerification, resp.NeedVerification) datautil.NotNilReplace(&req.GroupInfo.NeedVerification, resp.NeedVerification)
datautil.NotNilReplace(&req.GroupInfo.LookMemberInfo, resp.LookMemberInfo) datautil.NotNilReplace(&req.GroupInfo.LookMemberInfo, resp.LookMemberInfo)
return nil return nil
})
} }
func (s *groupServer) webhookAfterCreateGroup(ctx context.Context, after *config.AfterConfig, req *group.CreateGroupReq) { func (s *groupServer) webhookAfterCreateGroup(ctx context.Context, after *config.AfterConfig, req *group.CreateGroupReq) {
@ -98,6 +101,7 @@ func (s *groupServer) webhookAfterCreateGroup(ctx context.Context, after *config
} }
func (s *groupServer) webhookBeforeMemberJoinGroup(ctx context.Context, before *config.BeforeConfig, groupMember *relation.GroupMemberModel, groupEx string) error { func (s *groupServer) webhookBeforeMemberJoinGroup(ctx context.Context, before *config.BeforeConfig, groupMember *relation.GroupMemberModel, groupEx string) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &callbackstruct.CallbackBeforeMemberJoinGroupReq{ cbReq := &callbackstruct.CallbackBeforeMemberJoinGroupReq{
CallbackCommand: callbackstruct.CallbackBeforeMemberJoinGroupCommand, CallbackCommand: callbackstruct.CallbackBeforeMemberJoinGroupCommand,
GroupID: groupMember.GroupID, GroupID: groupMember.GroupID,
@ -118,9 +122,11 @@ func (s *groupServer) webhookBeforeMemberJoinGroup(ctx context.Context, before *
datautil.NotNilReplace(&groupMember.Nickname, resp.Nickname) datautil.NotNilReplace(&groupMember.Nickname, resp.Nickname)
datautil.NotNilReplace(&groupMember.RoleLevel, resp.RoleLevel) datautil.NotNilReplace(&groupMember.RoleLevel, resp.RoleLevel)
return nil return nil
})
} }
func (s *groupServer) webhookBeforeSetGroupMemberInfo(ctx context.Context, before *config.BeforeConfig, req *group.SetGroupMemberInfo) error { func (s *groupServer) webhookBeforeSetGroupMemberInfo(ctx context.Context, before *config.BeforeConfig, req *group.SetGroupMemberInfo) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := callbackstruct.CallbackBeforeSetGroupMemberInfoReq{ cbReq := callbackstruct.CallbackBeforeSetGroupMemberInfoReq{
CallbackCommand: callbackstruct.CallbackBeforeSetGroupMemberInfoCommand, CallbackCommand: callbackstruct.CallbackBeforeSetGroupMemberInfoCommand,
GroupID: req.GroupID, GroupID: req.GroupID,
@ -155,6 +161,7 @@ func (s *groupServer) webhookBeforeSetGroupMemberInfo(ctx context.Context, befor
req.Ex = wrapperspb.String(*resp.Ex) req.Ex = wrapperspb.String(*resp.Ex)
} }
return nil return nil
})
} }
func (s *groupServer) webhookAfterSetGroupMemberInfo(ctx context.Context, after *config.AfterConfig, req *group.SetGroupMemberInfo) { func (s *groupServer) webhookAfterSetGroupMemberInfo(ctx context.Context, after *config.AfterConfig, req *group.SetGroupMemberInfo) {
@ -202,12 +209,14 @@ func (s *groupServer) webhookAfterDismissGroup(ctx context.Context, after *confi
} }
func (s *groupServer) webhookBeforeApplyJoinGroup(ctx context.Context, before *config.BeforeConfig, req *callbackstruct.CallbackJoinGroupReq) (err error) { func (s *groupServer) webhookBeforeApplyJoinGroup(ctx context.Context, before *config.BeforeConfig, req *callbackstruct.CallbackJoinGroupReq) (err error) {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
req.CallbackCommand = callbackstruct.CallbackBeforeJoinGroupCommand req.CallbackCommand = callbackstruct.CallbackBeforeJoinGroupCommand
resp := &callbackstruct.CallbackJoinGroupResp{} resp := &callbackstruct.CallbackJoinGroupResp{}
if err := s.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil { if err := s.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
return err return err
} }
return nil return nil
})
} }
func (s *groupServer) webhookAfterTransferGroupOwner(ctx context.Context, after *config.AfterConfig, req *group.TransferGroupOwnerReq) { func (s *groupServer) webhookAfterTransferGroupOwner(ctx context.Context, after *config.AfterConfig, req *group.TransferGroupOwnerReq) {
@ -221,6 +230,7 @@ func (s *groupServer) webhookAfterTransferGroupOwner(ctx context.Context, after
} }
func (s *groupServer) webhookBeforeInviteUserToGroup(ctx context.Context, before *config.BeforeConfig, req *group.InviteUserToGroupReq) (err error) { func (s *groupServer) webhookBeforeInviteUserToGroup(ctx context.Context, before *config.BeforeConfig, req *group.InviteUserToGroupReq) (err error) {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &callbackstruct.CallbackBeforeInviteUserToGroupReq{ cbReq := &callbackstruct.CallbackBeforeInviteUserToGroupReq{
CallbackCommand: callbackstruct.CallbackBeforeInviteJoinGroupCommand, CallbackCommand: callbackstruct.CallbackBeforeInviteJoinGroupCommand,
OperationID: mcontext.GetOperationID(ctx), OperationID: mcontext.GetOperationID(ctx),
@ -239,6 +249,7 @@ func (s *groupServer) webhookBeforeInviteUserToGroup(ctx context.Context, before
// You might want to update the req.Members list or handle it as per your business logic // You might want to update the req.Members list or handle it as per your business logic
} }
return nil return nil
})
} }
func (s *groupServer) webhookAfterJoinGroup(ctx context.Context, after *config.AfterConfig, req *group.JoinGroupReq) { func (s *groupServer) webhookAfterJoinGroup(ctx context.Context, after *config.AfterConfig, req *group.JoinGroupReq) {
@ -254,9 +265,7 @@ func (s *groupServer) webhookAfterJoinGroup(ctx context.Context, after *config.A
} }
func (s *groupServer) webhookBeforeSetGroupInfo(ctx context.Context, before *config.BeforeConfig, req *group.SetGroupInfoReq) error { func (s *groupServer) webhookBeforeSetGroupInfo(ctx context.Context, before *config.BeforeConfig, req *group.SetGroupInfoReq) error {
if !before.Enable { return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
return nil
}
cbReq := &callbackstruct.CallbackBeforeSetGroupInfoReq{ cbReq := &callbackstruct.CallbackBeforeSetGroupInfoReq{
CallbackCommand: callbackstruct.CallbackBeforeSetGroupInfoCommand, CallbackCommand: callbackstruct.CallbackBeforeSetGroupInfoCommand,
GroupID: req.GroupInfoForSet.GroupID, GroupID: req.GroupInfoForSet.GroupID,
@ -301,6 +310,7 @@ func (s *groupServer) webhookBeforeSetGroupInfo(ctx context.Context, before *con
datautil.NotNilReplace(&req.GroupInfoForSet.FaceURL, &resp.FaceURL) datautil.NotNilReplace(&req.GroupInfoForSet.FaceURL, &resp.FaceURL)
datautil.NotNilReplace(&req.GroupInfoForSet.Introduction, &resp.Introduction) datautil.NotNilReplace(&req.GroupInfoForSet.Introduction, &resp.Introduction)
return nil return nil
})
} }
func (s *groupServer) webhookAfterSetGroupInfo(ctx context.Context, after *config.AfterConfig, req *group.SetGroupInfoReq) { func (s *groupServer) webhookAfterSetGroupInfo(ctx context.Context, after *config.AfterConfig, req *group.SetGroupInfoReq) {

@ -16,6 +16,7 @@ package msg
import ( import (
"context" "context"
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct" 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/config"
@ -61,6 +62,7 @@ func GetContent(msg *sdkws.MsgData) string {
} }
func (m *msgServer) webhookBeforeSendSingleMsg(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error { func (m *msgServer) webhookBeforeSendSingleMsg(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
if msg.MsgData.ContentType == constant.Typing { if msg.MsgData.ContentType == constant.Typing {
return nil return nil
} }
@ -74,6 +76,7 @@ func (m *msgServer) webhookBeforeSendSingleMsg(ctx context.Context, before *conf
} }
return nil return nil
})
} }
func (m *msgServer) webhookAfterSendSingleMsg(ctx context.Context, after *config.AfterConfig, msg *pbchat.SendMsgReq) { func (m *msgServer) webhookAfterSendSingleMsg(ctx context.Context, after *config.AfterConfig, msg *pbchat.SendMsgReq) {
@ -88,6 +91,7 @@ func (m *msgServer) webhookAfterSendSingleMsg(ctx context.Context, after *config
} }
func (m *msgServer) webhookBeforeSendGroupMsg(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error { func (m *msgServer) webhookBeforeSendGroupMsg(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
if msg.MsgData.ContentType == constant.Typing { if msg.MsgData.ContentType == constant.Typing {
return nil return nil
} }
@ -100,6 +104,7 @@ func (m *msgServer) webhookBeforeSendGroupMsg(ctx context.Context, before *confi
return err return err
} }
return nil return nil
})
} }
func (m *msgServer) webhookAfterSendGroupMsg(ctx context.Context, after *config.AfterConfig, msg *pbchat.SendMsgReq) { func (m *msgServer) webhookAfterSendGroupMsg(ctx context.Context, after *config.AfterConfig, msg *pbchat.SendMsgReq) {
@ -114,6 +119,7 @@ func (m *msgServer) webhookAfterSendGroupMsg(ctx context.Context, after *config.
} }
func (m *msgServer) webhookBeforeMsgModify(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error { func (m *msgServer) webhookBeforeMsgModify(ctx context.Context, before *config.BeforeConfig, msg *pbchat.SendMsgReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
if msg.MsgData.ContentType != constant.Text { if msg.MsgData.ContentType != constant.Text {
return nil return nil
} }
@ -145,6 +151,7 @@ func (m *msgServer) webhookBeforeMsgModify(ctx context.Context, before *config.B
datautil.NotNilReplace(&msg.MsgData.AttachedInfo, resp.AttachedInfo) datautil.NotNilReplace(&msg.MsgData.AttachedInfo, resp.AttachedInfo)
datautil.NotNilReplace(&msg.MsgData.Ex, resp.Ex) datautil.NotNilReplace(&msg.MsgData.Ex, resp.Ex)
return nil return nil
})
} }
func (m *msgServer) webhookAfterGroupMsgRead(ctx context.Context, after *config.AfterConfig, req *cbapi.CallbackGroupMsgReadReq) { func (m *msgServer) webhookAfterGroupMsgRead(ctx context.Context, after *config.AfterConfig, req *cbapi.CallbackGroupMsgReadReq) {

@ -16,6 +16,7 @@ package user
import ( import (
"context" "context"
"github.com/openimsdk/open-im-server/v3/pkg/common/webhook"
"github.com/openimsdk/tools/utils/datautil" "github.com/openimsdk/tools/utils/datautil"
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct" cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
@ -24,6 +25,7 @@ import (
) )
func (s *userServer) webhookBeforeUpdateUserInfo(ctx context.Context, before *config.BeforeConfig, req *pbuser.UpdateUserInfoReq) error { func (s *userServer) webhookBeforeUpdateUserInfo(ctx context.Context, before *config.BeforeConfig, req *pbuser.UpdateUserInfoReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &cbapi.CallbackBeforeUpdateUserInfoReq{ cbReq := &cbapi.CallbackBeforeUpdateUserInfoReq{
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoCommand, CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoCommand,
UserID: req.UserInfo.UserID, UserID: req.UserInfo.UserID,
@ -39,6 +41,7 @@ func (s *userServer) webhookBeforeUpdateUserInfo(ctx context.Context, before *co
datautil.NotNilReplace(&req.UserInfo.Ex, resp.Ex) datautil.NotNilReplace(&req.UserInfo.Ex, resp.Ex)
datautil.NotNilReplace(&req.UserInfo.Nickname, resp.Nickname) datautil.NotNilReplace(&req.UserInfo.Nickname, resp.Nickname)
return nil return nil
})
} }
func (s *userServer) webhookAfterUpdateUserInfo(ctx context.Context, after *config.AfterConfig, req *pbuser.UpdateUserInfoReq) { func (s *userServer) webhookAfterUpdateUserInfo(ctx context.Context, after *config.AfterConfig, req *pbuser.UpdateUserInfoReq) {
@ -52,6 +55,7 @@ func (s *userServer) webhookAfterUpdateUserInfo(ctx context.Context, after *conf
} }
func (s *userServer) webhookBeforeUpdateUserInfoEx(ctx context.Context, before *config.BeforeConfig, req *pbuser.UpdateUserInfoExReq) error { func (s *userServer) webhookBeforeUpdateUserInfoEx(ctx context.Context, before *config.BeforeConfig, req *pbuser.UpdateUserInfoExReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &cbapi.CallbackBeforeUpdateUserInfoExReq{ cbReq := &cbapi.CallbackBeforeUpdateUserInfoExReq{
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoExCommand, CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoExCommand,
UserID: req.UserInfo.UserID, UserID: req.UserInfo.UserID,
@ -67,6 +71,7 @@ func (s *userServer) webhookBeforeUpdateUserInfoEx(ctx context.Context, before *
datautil.NotNilReplace(req.UserInfo.Ex, resp.Ex) datautil.NotNilReplace(req.UserInfo.Ex, resp.Ex)
datautil.NotNilReplace(req.UserInfo.Nickname, resp.Nickname) datautil.NotNilReplace(req.UserInfo.Nickname, resp.Nickname)
return nil return nil
})
} }
func (s *userServer) webhookAfterUpdateUserInfoEx(ctx context.Context, after *config.AfterConfig, req *pbuser.UpdateUserInfoExReq) { func (s *userServer) webhookAfterUpdateUserInfoEx(ctx context.Context, after *config.AfterConfig, req *pbuser.UpdateUserInfoExReq) {
@ -80,6 +85,7 @@ func (s *userServer) webhookAfterUpdateUserInfoEx(ctx context.Context, after *co
} }
func (s *userServer) webhookBeforeUserRegister(ctx context.Context, before *config.BeforeConfig, req *pbuser.UserRegisterReq) error { func (s *userServer) webhookBeforeUserRegister(ctx context.Context, before *config.BeforeConfig, req *pbuser.UserRegisterReq) error {
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
cbReq := &cbapi.CallbackBeforeUserRegisterReq{ cbReq := &cbapi.CallbackBeforeUserRegisterReq{
CallbackCommand: cbapi.CallbackBeforeUserRegisterCommand, CallbackCommand: cbapi.CallbackBeforeUserRegisterCommand,
Secret: req.Secret, Secret: req.Secret,
@ -96,6 +102,7 @@ func (s *userServer) webhookBeforeUserRegister(ctx context.Context, before *conf
req.Users = resp.Users req.Users = resp.Users
} }
return nil return nil
})
} }
func (s *userServer) webhookAfterUserRegister(ctx context.Context, after *config.AfterConfig, req *pbuser.UserRegisterReq) { func (s *userServer) webhookAfterUserRegister(ctx context.Context, after *config.AfterConfig, req *pbuser.UserRegisterReq) {

@ -0,0 +1,13 @@
package webhook
import (
"context"
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
)
func WithCondition(ctx context.Context, before *config.BeforeConfig, callback func(context.Context) error) error {
if !before.Enable {
return nil
}
return callback(ctx)
}

@ -57,11 +57,8 @@ func NewWebhookClient(url string, options ...*memAsyncQueue.MemoryQueue) *Client
} }
func (c *Client) SyncPost(ctx context.Context, command string, req callbackstruct.CallbackReq, resp callbackstruct.CallbackResp, before *config.BeforeConfig) error { func (c *Client) SyncPost(ctx context.Context, command string, req callbackstruct.CallbackReq, resp callbackstruct.CallbackResp, before *config.BeforeConfig) error {
if before.Enable {
return c.post(ctx, command, req, resp, before.Timeout) return c.post(ctx, command, req, resp, before.Timeout)
} }
return nil
}
func (c *Client) AsyncPost(ctx context.Context, command string, req callbackstruct.CallbackReq, resp callbackstruct.CallbackResp, after *config.AfterConfig) { func (c *Client) AsyncPost(ctx context.Context, command string, req callbackstruct.CallbackReq, resp callbackstruct.CallbackResp, after *config.AfterConfig) {
if after.Enable { if after.Enable {

Loading…
Cancel
Save