test friend and blacklist

pull/1499/head
AndrewZuo01 2 years ago
parent c9cdb0ebe2
commit 1c46148c89

@ -397,7 +397,7 @@ callback:
enable: false
timeout: 5
failedContinue: true
##TODO CALLBACK TEST
##TODO CALLBACK
setGroupInfoAfter:
enable: false
timeout: 5
@ -410,7 +410,34 @@ callback:
enable: false
timeout: 5
failedContinue: true
addBlackBefore:
enable: false
timeout: 5
failedContinue: true
addFriendAfter:
enable: false
timeout: 5
failedContinue: true
addFriendAgreeBefore:
enable: false
timeout: 5
failedContinue: true
deleteFriendAfter:
enable: false
timeout: 5
failedContinue: true
importFriendsBefore:
enable: false
timeout: 5
failedContinue: true
importFriendsAfter:
enable: false
timeout: 5
failedContinue: true
removeBlackAfter:
enable: false
timeout: 5
failedContinue: true
###################### Prometheus ######################
# Prometheus configuration for various services
# The number of Prometheus ports per service needs to correspond to rpcPort

@ -74,6 +74,9 @@ func (s *friendServer) RemoveBlack(
return nil, err
}
s.notificationSender.BlackDeletedNotification(ctx, req)
if err := CallbackAfterRemoveBlack(ctx, req); err != nil {
return nil, err
}
return &pbfriend.RemoveBlackResp{}, nil
}

@ -17,6 +17,7 @@ package friend
import (
"context"
"github.com/OpenIMSDK/tools/utils"
"time"
"github.com/OpenIMSDK/protocol/constant"
pbfriend "github.com/OpenIMSDK/protocol/friend"
@ -111,3 +112,84 @@ func CallbackBeforeAddFriendAgree(ctx context.Context, req *pbfriend.RespondFrie
utils.StructFieldNotNilReplace(req, resp)
return nil
}
func CallbackAfterDeleteFriend(ctx context.Context, req *pbfriend.DeleteFriendReq) error {
if !config.Config.Callback.CallbackAfterDeleteFriend.Enable {
return nil
}
cbReq := &cbapi.CallbackAfterDeleteFriendReq{
CallbackCommand: cbapi.CallbackAfterDeleteFriendCommand,
OwnerUserID: req.OwnerUserID,
FriendUserID: req.FriendUserID,
EventTime: time.Now().UnixMilli(),
}
resp := &cbapi.CallbackAfterDeleteFriendResp{}
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterDeleteFriend); err != nil {
if err == errs.ErrCallbackContinue {
return nil
}
return err
}
utils.StructFieldNotNilReplace(req, resp)
return nil
}
func CallbackBeforeImportFriends(ctx context.Context, req *pbfriend.ImportFriendReq) error {
if !config.Config.Callback.CallbackBeforeImportFriends.Enable {
return nil
}
cbReq := &cbapi.CallbackBeforeImportFriendsReq{
CallbackCommand: cbapi.CallbackBeforeImportFriendsCommand,
OwnerUserID: req.OwnerUserID,
FriendUserIDs: req.FriendUserIDs,
EventTime: time.Now().UnixMilli(),
}
resp := &cbapi.CallbackBeforeImportFriendsResp{}
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeImportFriends); err != nil {
if err == errs.ErrCallbackContinue {
return nil
}
return err
}
utils.StructFieldNotNilReplace(req, resp)
return nil
}
func CallbackAfterImportFriends(ctx context.Context, req *pbfriend.ImportFriendReq) error {
if !config.Config.Callback.CallbackAfterImportFriends.Enable {
return nil
}
cbReq := &cbapi.CallbackAfterImportFriendsReq{
CallbackCommand: cbapi.CallbackAfterImportFriendsCommand,
OwnerUserID: req.OwnerUserID,
FriendUserIDs: req.FriendUserIDs,
EventTime: time.Now().UnixMilli(),
}
resp := &cbapi.CallbackAfterImportFriendsResp{}
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterImportFriends); err != nil {
if err == errs.ErrCallbackContinue {
return nil
}
return err
}
utils.StructFieldNotNilReplace(req, resp)
return nil
}
func CallbackAfterRemoveBlack(ctx context.Context, req *pbfriend.RemoveBlackReq) error {
if !config.Config.Callback.CallbackAfterRemoveBlack.Enable {
return nil
}
cbReq := &cbapi.CallbackAfterRemoveBlackReq{
CallbackCommand: cbapi.CallbackAfterRemoveBlackCommand,
OwnerUserID: req.OwnerUserID,
BlackUserID: req.BlackUserID,
EventTime: time.Now().UnixMilli(),
}
resp := &cbapi.CallbackAfterRemoveBlackResp{}
if err := http.CallBackPostReturn(ctx, config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackAfterRemoveBlack); err != nil {
if err == errs.ErrCallbackContinue {
return nil
}
return err
}
utils.StructFieldNotNilReplace(req, resp)
return nil
}

@ -144,6 +144,10 @@ func (s *friendServer) ImportFriends(
if utils.Duplicate(req.FriendUserIDs) {
return nil, errs.ErrArgs.Wrap("friend userID repeated")
}
if err := CallbackBeforeImportFriends(ctx, req); err != nil {
return nil, err
}
if err := s.friendDatabase.BecomeFriends(ctx, req.OwnerUserID, req.FriendUserIDs, constant.BecomeFriendByImport); err != nil {
return nil, err
}
@ -154,6 +158,9 @@ func (s *friendServer) ImportFriends(
HandleResult: constant.FriendResponseAgree,
})
}
if err := CallbackAfterImportFriends(ctx, req); err != nil {
return nil, err
}
return &pbfriend.ImportFriendResp{}, nil
}
@ -214,6 +221,9 @@ func (s *friendServer) DeleteFriend(
return nil, err
}
s.notificationSender.FriendDeletedNotification(ctx, req)
if err := CallbackAfterDeleteFriend(ctx, req); err != nil {
return nil, err
}
return resp, nil
}

@ -5,9 +5,12 @@ const CallbackAfterJoinGroupCommand = "CallbackAfterJoinGroupCommand"
const CallbackAfterSetGroupInfoCommand = "CallbackAfterSetGroupInfoCommand"
const CallbackBeforeSetGroupInfoCommand = "CallbackBeforeSetGroupInfoCommand"
// TODO CALLBACK
const CallbackAfterRevokeMsgCommand = "CallbackBeforeAfterMsgCommand"
const CallbackBeforeAddBlackCommand = "CallbackBeforeAddBlackCommand"
const CallbackAfterAddFriendCommand = "CallbackAfterAddFriendCommand"
const CallbackBeforeAddFriendAgreeCommand = "CallbackBeforeAddFriendAgreeCommand"
const CallbackAfterDeleteFriendCommand = "CallbackAfterDeleteFriendCommand"
const CallbackBeforeImportFriendsCommand = "CallbackBeforeImportFriendsCommand"
const CallbackAfterImportFriendsCommand = "CallbackAfterImportFriendsCommand"
const CallbackAfterRemoveBlackCommand = "CallbackAfterRemoveBlackCommand"

@ -59,3 +59,42 @@ type CallbackBeforeAddFriendAgreeReq struct {
type CallbackBeforeAddFriendAgreeResp struct {
CommonCallbackResp
}
type CallbackAfterDeleteFriendReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"ownerUserID" `
FriendUserID string `json:"friendUserID"`
EventTime int64 `json:"eventTime"`
}
type CallbackAfterDeleteFriendResp struct {
CommonCallbackResp
}
type CallbackBeforeImportFriendsReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"ownerUserID" `
FriendUserIDs []string `json:"friendUserIDs"`
EventTime int64 `json:"eventTime"`
}
type CallbackBeforeImportFriendsResp struct {
CommonCallbackResp
}
type CallbackAfterImportFriendsReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"ownerUserID" `
FriendUserIDs []string `json:"friendUserIDs"`
EventTime int64 `json:"eventTime"`
}
type CallbackAfterImportFriendsResp struct {
CommonCallbackResp
}
type CallbackAfterRemoveBlackReq struct {
CallbackCommand `json:"callbackCommand"`
OwnerUserID string `json:"ownerUserID"`
BlackUserID string `json:"blackUserID""`
EventTime int64 `json:"eventTime"`
}
type CallbackAfterRemoveBlackResp struct {
CommonCallbackResp
}

@ -267,11 +267,15 @@ type configStruct struct {
CallbackAfterJoinGroup CallBackConfig `yaml:"joinGroupAfter"`
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"`
CallbackAfterDeleteFriend CallBackConfig `yaml:"deleteFriendAfter"`
CallbackBeforeImportFriends CallBackConfig `yaml:"importFriendsBefore"`
CallbackAfterImportFriends CallBackConfig `yaml:"importFriendsAfter"`
CallbackAfterRemoveBlack CallBackConfig `yaml:"removeBlackAfter"`
} `yaml:"callback"`
Prometheus struct {

Loading…
Cancel
Save