mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-04 03:12:19 +08:00
update three functions in friend category
This commit is contained in:
parent
4e515c0a86
commit
c9cdb0ebe2
@ -406,7 +406,10 @@ callback:
|
|||||||
enable: true
|
enable: true
|
||||||
timeout: 5
|
timeout: 5
|
||||||
failedContinue: true
|
failedContinue: true
|
||||||
|
revokeMsgAfter:
|
||||||
|
enable: false
|
||||||
|
timeout: 5
|
||||||
|
failedContinue: true
|
||||||
|
|
||||||
###################### Prometheus ######################
|
###################### Prometheus ######################
|
||||||
# Prometheus configuration for various services
|
# Prometheus configuration for various services
|
||||||
|
|||||||
@ -85,6 +85,9 @@ func (s *friendServer) AddBlack(ctx context.Context, req *pbfriend.AddBlackReq)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err := CallbackBeforeAddBlack(ctx, req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
black := relation.BlackModel{
|
black := relation.BlackModel{
|
||||||
OwnerUserID: req.OwnerUserID,
|
OwnerUserID: req.OwnerUserID,
|
||||||
BlockUserID: req.BlackUserID,
|
BlockUserID: req.BlackUserID,
|
||||||
|
|||||||
@ -16,6 +16,7 @@ package friend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github.com/OpenIMSDK/tools/utils"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/constant"
|
"github.com/OpenIMSDK/protocol/constant"
|
||||||
pbfriend "github.com/OpenIMSDK/protocol/friend"
|
pbfriend "github.com/OpenIMSDK/protocol/friend"
|
||||||
@ -47,3 +48,66 @@ func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriend
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -120,6 +120,9 @@ func (s *friendServer) ApplyToAddFriend(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.notificationSender.FriendApplicationAddNotification(ctx, req)
|
s.notificationSender.FriendApplicationAddNotification(ctx, req)
|
||||||
|
if err := CallbackAfterAddFriend(ctx, req); err != nil && err != errs.ErrCallbackContinue {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,6 +175,9 @@ func (s *friendServer) RespondFriendApply(
|
|||||||
HandleResult: req.HandleResult,
|
HandleResult: req.HandleResult,
|
||||||
}
|
}
|
||||||
if req.HandleResult == constant.FriendResponseAgree {
|
if req.HandleResult == constant.FriendResponseAgree {
|
||||||
|
if err := CallbackBeforeAddFriendAgree(ctx, req); err != nil && err != errs.ErrCallbackContinue {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
err := s.friendDatabase.AgreeFriendRequest(ctx, &friendRequest)
|
err := s.friendDatabase.AgreeFriendRequest(ctx, &friendRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -316,5 +316,3 @@ func CallbackAfterSetGroupInfo(ctx context.Context, req *group.SetGroupInfoReq)
|
|||||||
utils.StructFieldNotNilReplace(req, resp)
|
utils.StructFieldNotNilReplace(req, resp)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO CALLBACK
|
|
||||||
|
|||||||
@ -16,7 +16,6 @@ package msg
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/OpenIMSDK/protocol/sdkws"
|
"github.com/OpenIMSDK/protocol/sdkws"
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
@ -28,6 +27,7 @@ import (
|
|||||||
"github.com/OpenIMSDK/tools/utils"
|
"github.com/OpenIMSDK/tools/utils"
|
||||||
|
|
||||||
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"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/http"
|
"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
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -61,6 +61,7 @@ func (m *msgServer) RevokeMsg(ctx context.Context, req *msg.RevokeMsgReq) (*msg.
|
|||||||
if msgs[0].ContentType == constant.MsgRevokeNotification {
|
if msgs[0].ContentType == constant.MsgRevokeNotification {
|
||||||
return nil, errs.ErrMsgAlreadyRevoke.Wrap("msg already revoke")
|
return nil, errs.ErrMsgAlreadyRevoke.Wrap("msg already revoke")
|
||||||
}
|
}
|
||||||
|
|
||||||
data, _ := json.Marshal(msgs[0])
|
data, _ := json.Marshal(msgs[0])
|
||||||
log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data))
|
log.ZInfo(ctx, "GetMsgBySeqs", "conversationID", req.ConversationID, "seq", req.Seq, "msg", string(data))
|
||||||
var role int32
|
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 {
|
if err := m.notificationSender.NotificationWithSesstionType(ctx, req.UserID, recvID, constant.MsgRevokeNotification, msgs[0].SessionType, &tips); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if err = CallbackAfterRevokeMsg(ctx, req); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &msg.RevokeMsgResp{}, nil
|
return &msg.RevokeMsgResp{}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,3 +6,8 @@ const CallbackAfterSetGroupInfoCommand = "CallbackAfterSetGroupInfoCommand"
|
|||||||
const CallbackBeforeSetGroupInfoCommand = "CallbackBeforeSetGroupInfoCommand"
|
const CallbackBeforeSetGroupInfoCommand = "CallbackBeforeSetGroupInfoCommand"
|
||||||
|
|
||||||
// TODO CALLBACK
|
// TODO CALLBACK
|
||||||
|
|
||||||
|
const CallbackAfterRevokeMsgCommand = "CallbackBeforeAfterMsgCommand"
|
||||||
|
const CallbackBeforeAddBlackCommand = "CallbackBeforeAddBlackCommand"
|
||||||
|
const CallbackAfterAddFriendCommand = "CallbackAfterAddFriendCommand"
|
||||||
|
const CallbackBeforeAddFriendAgreeCommand = "CallbackBeforeAddFriendAgreeCommand"
|
||||||
|
|||||||
@ -25,3 +25,37 @@ type CallbackBeforeAddFriendReq struct {
|
|||||||
type CallbackBeforeAddFriendResp struct {
|
type CallbackBeforeAddFriendResp struct {
|
||||||
CommonCallbackResp
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -79,5 +79,3 @@ type CallbackMsgModifyCommandResp struct {
|
|||||||
AttachedInfo *string `json:"attachedInfo"`
|
AttachedInfo *string `json:"attachedInfo"`
|
||||||
Ex *string `json:"ex"`
|
Ex *string `json:"ex"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO CALLBACK 2
|
|
||||||
|
|||||||
11
pkg/callbackstruct/revoke.go
Normal file
11
pkg/callbackstruct/revoke.go
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -268,6 +268,10 @@ type configStruct struct {
|
|||||||
CallbackAfterSetGroupInfo CallBackConfig `yaml:"setGroupInfoAfter"`
|
CallbackAfterSetGroupInfo CallBackConfig `yaml:"setGroupInfoAfter"`
|
||||||
CallbackBeforeSetGroupInfo CallBackConfig `yaml:"setGroupInfoBefore"`
|
CallbackBeforeSetGroupInfo CallBackConfig `yaml:"setGroupInfoBefore"`
|
||||||
//TODO CALLBACK/
|
//TODO CALLBACK/
|
||||||
|
CallbackAfterRevokeMsg CallBackConfig `yaml:"revokeMsgAfter"`
|
||||||
|
CallbackBeforeAddBlack CallBackConfig `yaml:"addBlackBefore"`
|
||||||
|
CallbackAfterAddFriend CallBackConfig `yaml:"addFriendAfter"`
|
||||||
|
CallbackBeforeAddFriendAgree CallBackConfig `yaml:"addFriendAgreeBefore"`
|
||||||
} `yaml:"callback"`
|
} `yaml:"callback"`
|
||||||
|
|
||||||
Prometheus struct {
|
Prometheus struct {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user