mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 21:02:11 +08:00
fix: callback update.
This commit is contained in:
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,71 +27,75 @@ 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 {
|
||||||
if msg.ContentType == constant.Typing {
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
return nil
|
if msg.ContentType == constant.Typing {
|
||||||
}
|
return nil
|
||||||
req := &callbackstruct.CallbackBeforePushReq{
|
}
|
||||||
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
|
req := &callbackstruct.CallbackBeforePushReq{
|
||||||
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
|
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
|
||||||
CallbackCommand: callbackstruct.CallbackBeforeOfflinePushCommand,
|
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
|
||||||
OperationID: mcontext.GetOperationID(ctx),
|
CallbackCommand: callbackstruct.CallbackBeforeOfflinePushCommand,
|
||||||
PlatformID: int(msg.SenderPlatformID),
|
OperationID: mcontext.GetOperationID(ctx),
|
||||||
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
|
PlatformID: int(msg.SenderPlatformID),
|
||||||
|
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
|
||||||
|
},
|
||||||
|
UserIDList: userIDs,
|
||||||
},
|
},
|
||||||
UserIDList: userIDs,
|
OfflinePushInfo: msg.OfflinePushInfo,
|
||||||
},
|
ClientMsgID: msg.ClientMsgID,
|
||||||
OfflinePushInfo: msg.OfflinePushInfo,
|
SendID: msg.SendID,
|
||||||
ClientMsgID: msg.ClientMsgID,
|
GroupID: msg.GroupID,
|
||||||
SendID: msg.SendID,
|
ContentType: msg.ContentType,
|
||||||
GroupID: msg.GroupID,
|
SessionType: msg.SessionType,
|
||||||
ContentType: msg.ContentType,
|
AtUserIDs: msg.AtUserIDList,
|
||||||
SessionType: msg.SessionType,
|
Content: GetContent(msg),
|
||||||
AtUserIDs: msg.AtUserIDList,
|
}
|
||||||
Content: GetContent(msg),
|
|
||||||
}
|
|
||||||
|
|
||||||
resp := &callbackstruct.CallbackBeforePushResp{}
|
resp := &callbackstruct.CallbackBeforePushResp{}
|
||||||
|
|
||||||
if err := p.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
if err := p.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(resp.UserIDs) != 0 {
|
if len(resp.UserIDs) != 0 {
|
||||||
*offlinePushUserIDs = resp.UserIDs
|
*offlinePushUserIDs = resp.UserIDs
|
||||||
}
|
}
|
||||||
if resp.OfflinePushInfo != nil {
|
if resp.OfflinePushInfo != nil {
|
||||||
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 {
|
||||||
if datautil.Contain(msg.SendID, userIDs...) || msg.ContentType == constant.Typing {
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
return nil
|
if datautil.Contain(msg.SendID, userIDs...) || msg.ContentType == constant.Typing {
|
||||||
}
|
return nil
|
||||||
req := callbackstruct.CallbackBeforePushReq{
|
}
|
||||||
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
|
req := callbackstruct.CallbackBeforePushReq{
|
||||||
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
|
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
|
||||||
CallbackCommand: callbackstruct.CallbackBeforeOnlinePushCommand,
|
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
|
||||||
OperationID: mcontext.GetOperationID(ctx),
|
CallbackCommand: callbackstruct.CallbackBeforeOnlinePushCommand,
|
||||||
PlatformID: int(msg.SenderPlatformID),
|
OperationID: mcontext.GetOperationID(ctx),
|
||||||
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
|
PlatformID: int(msg.SenderPlatformID),
|
||||||
|
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
|
||||||
|
},
|
||||||
|
UserIDList: userIDs,
|
||||||
},
|
},
|
||||||
UserIDList: userIDs,
|
ClientMsgID: msg.ClientMsgID,
|
||||||
},
|
SendID: msg.SendID,
|
||||||
ClientMsgID: msg.ClientMsgID,
|
GroupID: msg.GroupID,
|
||||||
SendID: msg.SendID,
|
ContentType: msg.ContentType,
|
||||||
GroupID: msg.GroupID,
|
SessionType: msg.SessionType,
|
||||||
ContentType: msg.ContentType,
|
AtUserIDs: msg.AtUserIDList,
|
||||||
SessionType: msg.SessionType,
|
Content: GetContent(msg),
|
||||||
AtUserIDs: msg.AtUserIDList,
|
}
|
||||||
Content: GetContent(msg),
|
resp := &callbackstruct.CallbackBeforePushResp{}
|
||||||
}
|
if err := p.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
||||||
resp := &callbackstruct.CallbackBeforePushResp{}
|
return err
|
||||||
if err := p.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
}
|
||||||
return err
|
return nil
|
||||||
}
|
})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pusher) webhookBeforeGroupOnlinePush(
|
func (p *Pusher) webhookBeforeGroupOnlinePush(
|
||||||
@ -100,31 +105,33 @@ func (p *Pusher) webhookBeforeGroupOnlinePush(
|
|||||||
msg *sdkws.MsgData,
|
msg *sdkws.MsgData,
|
||||||
pushToUserIDs *[]string,
|
pushToUserIDs *[]string,
|
||||||
) error {
|
) error {
|
||||||
if msg.ContentType == constant.Typing {
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
|
if msg.ContentType == constant.Typing {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
req := callbackstruct.CallbackBeforeSuperGroupOnlinePushReq{
|
||||||
|
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
|
||||||
|
CallbackCommand: callbackstruct.CallbackBeforeGroupOnlinePushCommand,
|
||||||
|
OperationID: mcontext.GetOperationID(ctx),
|
||||||
|
PlatformID: int(msg.SenderPlatformID),
|
||||||
|
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
|
||||||
|
},
|
||||||
|
ClientMsgID: msg.ClientMsgID,
|
||||||
|
SendID: msg.SendID,
|
||||||
|
GroupID: groupID,
|
||||||
|
ContentType: msg.ContentType,
|
||||||
|
SessionType: msg.SessionType,
|
||||||
|
AtUserIDs: msg.AtUserIDList,
|
||||||
|
Content: GetContent(msg),
|
||||||
|
Seq: msg.Seq,
|
||||||
|
}
|
||||||
|
resp := &callbackstruct.CallbackBeforeSuperGroupOnlinePushResp{}
|
||||||
|
if err := p.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(resp.UserIDs) != 0 {
|
||||||
|
*pushToUserIDs = resp.UserIDs
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
})
|
||||||
req := callbackstruct.CallbackBeforeSuperGroupOnlinePushReq{
|
|
||||||
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
|
|
||||||
CallbackCommand: callbackstruct.CallbackBeforeGroupOnlinePushCommand,
|
|
||||||
OperationID: mcontext.GetOperationID(ctx),
|
|
||||||
PlatformID: int(msg.SenderPlatformID),
|
|
||||||
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
|
|
||||||
},
|
|
||||||
ClientMsgID: msg.ClientMsgID,
|
|
||||||
SendID: msg.SendID,
|
|
||||||
GroupID: groupID,
|
|
||||||
ContentType: msg.ContentType,
|
|
||||||
SessionType: msg.SessionType,
|
|
||||||
AtUserIDs: msg.AtUserIDList,
|
|
||||||
Content: GetContent(msg),
|
|
||||||
Seq: msg.Seq,
|
|
||||||
}
|
|
||||||
resp := &callbackstruct.CallbackBeforeSuperGroupOnlinePushResp{}
|
|
||||||
if err := p.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(resp.UserIDs) != 0 {
|
|
||||||
*pushToUserIDs = resp.UserIDs
|
|
||||||
}
|
|
||||||
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,19 +33,21 @@ 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 {
|
||||||
cbReq := &cbapi.CallbackBeforeAddFriendReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: cbapi.CallbackBeforeAddFriendCommand,
|
cbReq := &cbapi.CallbackBeforeAddFriendReq{
|
||||||
FromUserID: req.FromUserID,
|
CallbackCommand: cbapi.CallbackBeforeAddFriendCommand,
|
||||||
ToUserID: req.ToUserID,
|
FromUserID: req.FromUserID,
|
||||||
ReqMsg: req.ReqMsg,
|
ToUserID: req.ToUserID,
|
||||||
Ex: req.Ex,
|
ReqMsg: req.ReqMsg,
|
||||||
}
|
Ex: req.Ex,
|
||||||
resp := &cbapi.CallbackBeforeAddFriendResp{}
|
}
|
||||||
|
resp := &cbapi.CallbackBeforeAddFriendResp{}
|
||||||
|
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
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,65 +94,64 @@ 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 {
|
||||||
cbReq := &cbapi.CallbackBeforeSetFriendRemarkReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: cbapi.CallbackBeforeSetFriendRemarkCommand,
|
cbReq := &cbapi.CallbackBeforeSetFriendRemarkReq{
|
||||||
OwnerUserID: req.OwnerUserID,
|
CallbackCommand: cbapi.CallbackBeforeSetFriendRemarkCommand,
|
||||||
FriendUserID: req.FriendUserID,
|
OwnerUserID: req.OwnerUserID,
|
||||||
Remark: req.Remark,
|
FriendUserID: req.FriendUserID,
|
||||||
}
|
Remark: req.Remark,
|
||||||
resp := &cbapi.CallbackBeforeSetFriendRemarkResp{}
|
}
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
resp := &cbapi.CallbackBeforeSetFriendRemarkResp{}
|
||||||
return err
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
}
|
return err
|
||||||
if resp.Remark != "" {
|
}
|
||||||
req.Remark = resp.Remark
|
if 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{
|
||||||
}
|
CallbackCommand: cbapi.CallbackBeforeAddBlackCommand,
|
||||||
cbReq := &cbapi.CallbackBeforeAddBlackReq{
|
OwnerUserID: req.OwnerUserID,
|
||||||
CallbackCommand: cbapi.CallbackBeforeAddBlackCommand,
|
BlackUserID: req.BlackUserID,
|
||||||
OwnerUserID: req.OwnerUserID,
|
}
|
||||||
BlackUserID: req.BlackUserID,
|
resp := &cbapi.CallbackBeforeAddBlackResp{}
|
||||||
}
|
return s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before)
|
||||||
resp := &cbapi.CallbackBeforeAddBlackResp{}
|
})
|
||||||
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{
|
||||||
}
|
CallbackCommand: cbapi.CallbackBeforeAddFriendAgreeCommand,
|
||||||
cbReq := &cbapi.CallbackBeforeAddFriendAgreeReq{
|
FromUserID: req.FromUserID,
|
||||||
CallbackCommand: cbapi.CallbackBeforeAddFriendAgreeCommand,
|
ToUserID: req.ToUserID,
|
||||||
FromUserID: req.FromUserID,
|
HandleMsg: req.HandleMsg,
|
||||||
ToUserID: req.ToUserID,
|
HandleResult: req.HandleResult,
|
||||||
HandleMsg: req.HandleMsg,
|
}
|
||||||
HandleResult: req.HandleResult,
|
resp := &cbapi.CallbackBeforeAddFriendAgreeResp{}
|
||||||
}
|
return s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before)
|
||||||
resp := &cbapi.CallbackBeforeAddFriendAgreeResp{}
|
})
|
||||||
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 {
|
||||||
|
cbReq := &cbapi.CallbackBeforeImportFriendsReq{
|
||||||
|
CallbackCommand: cbapi.CallbackBeforeImportFriendsCommand,
|
||||||
|
OwnerUserID: req.OwnerUserID,
|
||||||
|
FriendUserIDs: req.FriendUserIDs,
|
||||||
|
}
|
||||||
|
resp := &cbapi.CallbackBeforeImportFriendsResp{}
|
||||||
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(resp.FriendUserIDs) > 0 {
|
||||||
|
req.FriendUserIDs = resp.FriendUserIDs
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
})
|
||||||
cbReq := &cbapi.CallbackBeforeImportFriendsReq{
|
|
||||||
CallbackCommand: cbapi.CallbackBeforeImportFriendsCommand,
|
|
||||||
OwnerUserID: req.OwnerUserID,
|
|
||||||
FriendUserIDs: req.FriendUserIDs,
|
|
||||||
}
|
|
||||||
resp := &cbapi.CallbackBeforeImportFriendsResp{}
|
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(resp.FriendUserIDs) > 0 {
|
|
||||||
req.FriendUserIDs = resp.FriendUserIDs
|
|
||||||
}
|
|
||||||
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,46 +32,48 @@ 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 {
|
||||||
cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: callbackstruct.CallbackBeforeCreateGroupCommand,
|
cbReq := &callbackstruct.CallbackBeforeCreateGroupReq{
|
||||||
OperationID: mcontext.GetOperationID(ctx),
|
CallbackCommand: callbackstruct.CallbackBeforeCreateGroupCommand,
|
||||||
GroupInfo: req.GroupInfo,
|
OperationID: mcontext.GetOperationID(ctx),
|
||||||
}
|
GroupInfo: req.GroupInfo,
|
||||||
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
|
}
|
||||||
UserID: req.OwnerUserID,
|
cbReq.InitMemberList = append(cbReq.InitMemberList, &apistruct.GroupAddMemberInfo{
|
||||||
RoleLevel: constant.GroupOwner,
|
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{}
|
||||||
|
|
||||||
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.GroupID, resp.GroupID)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.GroupName, resp.GroupName)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.Notification, resp.Notification)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.Introduction, resp.Introduction)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.FaceURL, resp.FaceURL)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.OwnerUserID, resp.OwnerUserID)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.Ex, resp.Ex)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.Status, resp.Status)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.CreatorUserID, resp.CreatorUserID)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.GroupType, resp.GroupType)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.NeedVerification, resp.NeedVerification)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfo.LookMemberInfo, resp.LookMemberInfo)
|
||||||
|
return nil
|
||||||
})
|
})
|
||||||
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{}
|
|
||||||
|
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.GroupID, resp.GroupID)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.GroupName, resp.GroupName)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.Notification, resp.Notification)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.Introduction, resp.Introduction)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.FaceURL, resp.FaceURL)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.OwnerUserID, resp.OwnerUserID)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.Ex, resp.Ex)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.Status, resp.Status)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.CreatorUserID, resp.CreatorUserID)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.GroupType, resp.GroupType)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.NeedVerification, resp.NeedVerification)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfo.LookMemberInfo, resp.LookMemberInfo)
|
|
||||||
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,63 +101,67 @@ 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 {
|
||||||
cbReq := &callbackstruct.CallbackBeforeMemberJoinGroupReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: callbackstruct.CallbackBeforeMemberJoinGroupCommand,
|
cbReq := &callbackstruct.CallbackBeforeMemberJoinGroupReq{
|
||||||
GroupID: groupMember.GroupID,
|
CallbackCommand: callbackstruct.CallbackBeforeMemberJoinGroupCommand,
|
||||||
UserID: groupMember.UserID,
|
GroupID: groupMember.GroupID,
|
||||||
Ex: groupMember.Ex,
|
UserID: groupMember.UserID,
|
||||||
GroupEx: groupEx,
|
Ex: groupMember.Ex,
|
||||||
}
|
GroupEx: groupEx,
|
||||||
resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{}
|
}
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{}
|
||||||
return err
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if resp.MuteEndTime != nil {
|
if resp.MuteEndTime != nil {
|
||||||
groupMember.MuteEndTime = time.UnixMilli(*resp.MuteEndTime)
|
groupMember.MuteEndTime = time.UnixMilli(*resp.MuteEndTime)
|
||||||
}
|
}
|
||||||
datautil.NotNilReplace(&groupMember.FaceURL, resp.FaceURL)
|
datautil.NotNilReplace(&groupMember.FaceURL, resp.FaceURL)
|
||||||
datautil.NotNilReplace(&groupMember.Ex, resp.Ex)
|
datautil.NotNilReplace(&groupMember.Ex, resp.Ex)
|
||||||
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 {
|
||||||
cbReq := callbackstruct.CallbackBeforeSetGroupMemberInfoReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: callbackstruct.CallbackBeforeSetGroupMemberInfoCommand,
|
cbReq := callbackstruct.CallbackBeforeSetGroupMemberInfoReq{
|
||||||
GroupID: req.GroupID,
|
CallbackCommand: callbackstruct.CallbackBeforeSetGroupMemberInfoCommand,
|
||||||
UserID: req.UserID,
|
GroupID: req.GroupID,
|
||||||
}
|
UserID: req.UserID,
|
||||||
if req.Nickname != nil {
|
}
|
||||||
cbReq.Nickname = &req.Nickname.Value
|
if req.Nickname != nil {
|
||||||
}
|
cbReq.Nickname = &req.Nickname.Value
|
||||||
if req.FaceURL != nil {
|
}
|
||||||
cbReq.FaceURL = &req.FaceURL.Value
|
if req.FaceURL != nil {
|
||||||
}
|
cbReq.FaceURL = &req.FaceURL.Value
|
||||||
if req.RoleLevel != nil {
|
}
|
||||||
cbReq.RoleLevel = &req.RoleLevel.Value
|
if req.RoleLevel != nil {
|
||||||
}
|
cbReq.RoleLevel = &req.RoleLevel.Value
|
||||||
if req.Ex != nil {
|
}
|
||||||
cbReq.Ex = &req.Ex.Value
|
if req.Ex != nil {
|
||||||
}
|
cbReq.Ex = &req.Ex.Value
|
||||||
resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{}
|
}
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{}
|
||||||
return err
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
}
|
return err
|
||||||
if resp.FaceURL != nil {
|
}
|
||||||
req.FaceURL = wrapperspb.String(*resp.FaceURL)
|
if resp.FaceURL != nil {
|
||||||
}
|
req.FaceURL = wrapperspb.String(*resp.FaceURL)
|
||||||
if resp.Nickname != nil {
|
}
|
||||||
req.Nickname = wrapperspb.String(*resp.Nickname)
|
if resp.Nickname != nil {
|
||||||
}
|
req.Nickname = wrapperspb.String(*resp.Nickname)
|
||||||
if resp.RoleLevel != nil {
|
}
|
||||||
req.RoleLevel = wrapperspb.Int32(*resp.RoleLevel)
|
if resp.RoleLevel != nil {
|
||||||
}
|
req.RoleLevel = wrapperspb.Int32(*resp.RoleLevel)
|
||||||
if resp.Ex != nil {
|
}
|
||||||
req.Ex = wrapperspb.String(*resp.Ex)
|
if resp.Ex != nil {
|
||||||
}
|
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) {
|
||||||
req.CallbackCommand = callbackstruct.CallbackBeforeJoinGroupCommand
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
resp := &callbackstruct.CallbackJoinGroupResp{}
|
req.CallbackCommand = callbackstruct.CallbackBeforeJoinGroupCommand
|
||||||
if err := s.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
resp := &callbackstruct.CallbackJoinGroupResp{}
|
||||||
return err
|
if err := s.webhookClient.SyncPost(ctx, req.GetCallbackCommand(), req, resp, before); err != nil {
|
||||||
}
|
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,24 +230,26 @@ 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) {
|
||||||
cbReq := &callbackstruct.CallbackBeforeInviteUserToGroupReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: callbackstruct.CallbackBeforeInviteJoinGroupCommand,
|
cbReq := &callbackstruct.CallbackBeforeInviteUserToGroupReq{
|
||||||
OperationID: mcontext.GetOperationID(ctx),
|
CallbackCommand: callbackstruct.CallbackBeforeInviteJoinGroupCommand,
|
||||||
GroupID: req.GroupID,
|
OperationID: mcontext.GetOperationID(ctx),
|
||||||
Reason: req.Reason,
|
GroupID: req.GroupID,
|
||||||
InvitedUserIDs: req.InvitedUserIDs,
|
Reason: req.Reason,
|
||||||
}
|
InvitedUserIDs: req.InvitedUserIDs,
|
||||||
|
}
|
||||||
|
|
||||||
resp := &callbackstruct.CallbackBeforeInviteUserToGroupResp{}
|
resp := &callbackstruct.CallbackBeforeInviteUserToGroupResp{}
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(resp.RefusedMembersAccount) > 0 {
|
if len(resp.RefusedMembersAccount) > 0 {
|
||||||
// Handle the scenario where certain members are refused
|
// 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
|
// 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,53 +265,52 @@ 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 {
|
||||||
|
cbReq := &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 {
|
||||||
|
cbReq.Ex = req.GroupInfoForSet.Ex.Value
|
||||||
|
}
|
||||||
|
log.ZDebug(ctx, "debug CallbackBeforeSetGroupInfo", "ex", cbReq.Ex)
|
||||||
|
if req.GroupInfoForSet.NeedVerification != nil {
|
||||||
|
cbReq.NeedVerification = req.GroupInfoForSet.NeedVerification.Value
|
||||||
|
}
|
||||||
|
if req.GroupInfoForSet.LookMemberInfo != nil {
|
||||||
|
cbReq.LookMemberInfo = req.GroupInfoForSet.LookMemberInfo.Value
|
||||||
|
}
|
||||||
|
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
||||||
|
cbReq.ApplyMemberFriend = req.GroupInfoForSet.ApplyMemberFriend.Value
|
||||||
|
}
|
||||||
|
resp := &callbackstruct.CallbackBeforeSetGroupInfoResp{}
|
||||||
|
|
||||||
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); 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)
|
||||||
|
}
|
||||||
|
datautil.NotNilReplace(&req.GroupInfoForSet.GroupID, &resp.GroupID)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfoForSet.GroupName, &resp.GroupName)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfoForSet.FaceURL, &resp.FaceURL)
|
||||||
|
datautil.NotNilReplace(&req.GroupInfoForSet.Introduction, &resp.Introduction)
|
||||||
return nil
|
return nil
|
||||||
}
|
})
|
||||||
cbReq := &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 {
|
|
||||||
cbReq.Ex = req.GroupInfoForSet.Ex.Value
|
|
||||||
}
|
|
||||||
log.ZDebug(ctx, "debug CallbackBeforeSetGroupInfo", "ex", cbReq.Ex)
|
|
||||||
if req.GroupInfoForSet.NeedVerification != nil {
|
|
||||||
cbReq.NeedVerification = req.GroupInfoForSet.NeedVerification.Value
|
|
||||||
}
|
|
||||||
if req.GroupInfoForSet.LookMemberInfo != nil {
|
|
||||||
cbReq.LookMemberInfo = req.GroupInfoForSet.LookMemberInfo.Value
|
|
||||||
}
|
|
||||||
if req.GroupInfoForSet.ApplyMemberFriend != nil {
|
|
||||||
cbReq.ApplyMemberFriend = req.GroupInfoForSet.ApplyMemberFriend.Value
|
|
||||||
}
|
|
||||||
resp := &callbackstruct.CallbackBeforeSetGroupInfoResp{}
|
|
||||||
|
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); 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)
|
|
||||||
}
|
|
||||||
datautil.NotNilReplace(&req.GroupInfoForSet.GroupID, &resp.GroupID)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfoForSet.GroupName, &resp.GroupName)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfoForSet.FaceURL, &resp.FaceURL)
|
|
||||||
datautil.NotNilReplace(&req.GroupInfoForSet.Introduction, &resp.Introduction)
|
|
||||||
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,19 +62,21 @@ 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 {
|
||||||
if msg.MsgData.ContentType == constant.Typing {
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
return nil
|
if msg.MsgData.ContentType == constant.Typing {
|
||||||
}
|
return nil
|
||||||
cbReq := &cbapi.CallbackBeforeSendSingleMsgReq{
|
}
|
||||||
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackBeforeSendSingleMsgCommand),
|
cbReq := &cbapi.CallbackBeforeSendSingleMsgReq{
|
||||||
RecvID: msg.MsgData.RecvID,
|
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackBeforeSendSingleMsgCommand),
|
||||||
}
|
RecvID: msg.MsgData.RecvID,
|
||||||
resp := &cbapi.CallbackBeforeSendSingleMsgResp{}
|
}
|
||||||
if err := m.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
resp := &cbapi.CallbackBeforeSendSingleMsgResp{}
|
||||||
return err
|
if err := m.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
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,18 +91,20 @@ 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 {
|
||||||
if msg.MsgData.ContentType == constant.Typing {
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
|
if msg.MsgData.ContentType == constant.Typing {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
cbReq := &cbapi.CallbackBeforeSendGroupMsgReq{
|
||||||
|
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackBeforeSendGroupMsgCommand),
|
||||||
|
GroupID: msg.MsgData.GroupID,
|
||||||
|
}
|
||||||
|
resp := &cbapi.CallbackBeforeSendGroupMsgResp{}
|
||||||
|
if err := m.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
})
|
||||||
cbReq := &cbapi.CallbackBeforeSendGroupMsgReq{
|
|
||||||
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackBeforeSendGroupMsgCommand),
|
|
||||||
GroupID: msg.MsgData.GroupID,
|
|
||||||
}
|
|
||||||
resp := &cbapi.CallbackBeforeSendGroupMsgResp{}
|
|
||||||
if err := m.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
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,37 +119,39 @@ 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 {
|
||||||
if msg.MsgData.ContentType != constant.Text {
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
return nil
|
if msg.MsgData.ContentType != constant.Text {
|
||||||
}
|
return nil
|
||||||
cbReq := &cbapi.CallbackMsgModifyCommandReq{
|
}
|
||||||
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackBeforeMsgModifyCommand),
|
cbReq := &cbapi.CallbackMsgModifyCommandReq{
|
||||||
}
|
CommonCallbackReq: toCommonCallback(ctx, msg, cbapi.CallbackBeforeMsgModifyCommand),
|
||||||
resp := &cbapi.CallbackMsgModifyCommandResp{}
|
}
|
||||||
if err := m.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
resp := &cbapi.CallbackMsgModifyCommandResp{}
|
||||||
return err
|
if err := m.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if resp.Content != nil {
|
if resp.Content != nil {
|
||||||
msg.MsgData.Content = []byte(*resp.Content)
|
msg.MsgData.Content = []byte(*resp.Content)
|
||||||
}
|
}
|
||||||
datautil.NotNilReplace(msg.MsgData.OfflinePushInfo, resp.OfflinePushInfo)
|
datautil.NotNilReplace(msg.MsgData.OfflinePushInfo, resp.OfflinePushInfo)
|
||||||
datautil.NotNilReplace(&msg.MsgData.RecvID, resp.RecvID)
|
datautil.NotNilReplace(&msg.MsgData.RecvID, resp.RecvID)
|
||||||
datautil.NotNilReplace(&msg.MsgData.GroupID, resp.GroupID)
|
datautil.NotNilReplace(&msg.MsgData.GroupID, resp.GroupID)
|
||||||
datautil.NotNilReplace(&msg.MsgData.ClientMsgID, resp.ClientMsgID)
|
datautil.NotNilReplace(&msg.MsgData.ClientMsgID, resp.ClientMsgID)
|
||||||
datautil.NotNilReplace(&msg.MsgData.ServerMsgID, resp.ServerMsgID)
|
datautil.NotNilReplace(&msg.MsgData.ServerMsgID, resp.ServerMsgID)
|
||||||
datautil.NotNilReplace(&msg.MsgData.SenderPlatformID, resp.SenderPlatformID)
|
datautil.NotNilReplace(&msg.MsgData.SenderPlatformID, resp.SenderPlatformID)
|
||||||
datautil.NotNilReplace(&msg.MsgData.SenderNickname, resp.SenderNickname)
|
datautil.NotNilReplace(&msg.MsgData.SenderNickname, resp.SenderNickname)
|
||||||
datautil.NotNilReplace(&msg.MsgData.SenderFaceURL, resp.SenderFaceURL)
|
datautil.NotNilReplace(&msg.MsgData.SenderFaceURL, resp.SenderFaceURL)
|
||||||
datautil.NotNilReplace(&msg.MsgData.SessionType, resp.SessionType)
|
datautil.NotNilReplace(&msg.MsgData.SessionType, resp.SessionType)
|
||||||
datautil.NotNilReplace(&msg.MsgData.MsgFrom, resp.MsgFrom)
|
datautil.NotNilReplace(&msg.MsgData.MsgFrom, resp.MsgFrom)
|
||||||
datautil.NotNilReplace(&msg.MsgData.ContentType, resp.ContentType)
|
datautil.NotNilReplace(&msg.MsgData.ContentType, resp.ContentType)
|
||||||
datautil.NotNilReplace(&msg.MsgData.Status, resp.Status)
|
datautil.NotNilReplace(&msg.MsgData.Status, resp.Status)
|
||||||
datautil.NotNilReplace(&msg.MsgData.Options, resp.Options)
|
datautil.NotNilReplace(&msg.MsgData.Options, resp.Options)
|
||||||
datautil.NotNilReplace(&msg.MsgData.AtUserIDList, resp.AtUserIDList)
|
datautil.NotNilReplace(&msg.MsgData.AtUserIDList, resp.AtUserIDList)
|
||||||
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,21 +25,23 @@ 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 {
|
||||||
cbReq := &cbapi.CallbackBeforeUpdateUserInfoReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoCommand,
|
cbReq := &cbapi.CallbackBeforeUpdateUserInfoReq{
|
||||||
UserID: req.UserInfo.UserID,
|
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoCommand,
|
||||||
FaceURL: &req.UserInfo.FaceURL,
|
UserID: req.UserInfo.UserID,
|
||||||
Nickname: &req.UserInfo.Nickname,
|
FaceURL: &req.UserInfo.FaceURL,
|
||||||
}
|
Nickname: &req.UserInfo.Nickname,
|
||||||
resp := &cbapi.CallbackBeforeUpdateUserInfoResp{}
|
}
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
resp := &cbapi.CallbackBeforeUpdateUserInfoResp{}
|
||||||
return err
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
datautil.NotNilReplace(&req.UserInfo.FaceURL, resp.FaceURL)
|
datautil.NotNilReplace(&req.UserInfo.FaceURL, resp.FaceURL)
|
||||||
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,21 +55,23 @@ 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 {
|
||||||
cbReq := &cbapi.CallbackBeforeUpdateUserInfoExReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoExCommand,
|
cbReq := &cbapi.CallbackBeforeUpdateUserInfoExReq{
|
||||||
UserID: req.UserInfo.UserID,
|
CallbackCommand: cbapi.CallbackBeforeUpdateUserInfoExCommand,
|
||||||
FaceURL: req.UserInfo.FaceURL,
|
UserID: req.UserInfo.UserID,
|
||||||
Nickname: req.UserInfo.Nickname,
|
FaceURL: req.UserInfo.FaceURL,
|
||||||
}
|
Nickname: req.UserInfo.Nickname,
|
||||||
resp := &cbapi.CallbackBeforeUpdateUserInfoExResp{}
|
}
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
resp := &cbapi.CallbackBeforeUpdateUserInfoExResp{}
|
||||||
return err
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
datautil.NotNilReplace(req.UserInfo.FaceURL, resp.FaceURL)
|
datautil.NotNilReplace(req.UserInfo.FaceURL, resp.FaceURL)
|
||||||
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,22 +85,24 @@ 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 {
|
||||||
cbReq := &cbapi.CallbackBeforeUserRegisterReq{
|
return webhook.WithCondition(ctx, before, func(ctx context.Context) error {
|
||||||
CallbackCommand: cbapi.CallbackBeforeUserRegisterCommand,
|
cbReq := &cbapi.CallbackBeforeUserRegisterReq{
|
||||||
Secret: req.Secret,
|
CallbackCommand: cbapi.CallbackBeforeUserRegisterCommand,
|
||||||
Users: req.Users,
|
Secret: req.Secret,
|
||||||
}
|
Users: req.Users,
|
||||||
|
}
|
||||||
|
|
||||||
resp := &cbapi.CallbackBeforeUserRegisterResp{}
|
resp := &cbapi.CallbackBeforeUserRegisterResp{}
|
||||||
|
|
||||||
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
if err := s.webhookClient.SyncPost(ctx, cbReq.GetCallbackCommand(), cbReq, resp, before); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(resp.Users) != 0 {
|
if len(resp.Users) != 0 {
|
||||||
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) {
|
||||||
|
|||||||
13
pkg/common/webhook/condition.go
Normal file
13
pkg/common/webhook/condition.go
Normal file
@ -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,10 +57,7 @@ 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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user