You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/internal/push/callback.go

110 lines
3.9 KiB

2 years ago
package push
3 years ago
import (
2 years ago
"context"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/callbackstruct"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/http"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mcontext"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
3 years ago
)
2 years ago
func url() string {
return config.Config.Callback.CallbackUrl
}
2 years ago
func callbackOfflinePush(ctx context.Context, userIDs []string, msg *sdkws.MsgData, offlinePushUserIDs *[]string) error {
if !config.Config.Callback.CallbackOfflinePush.Enable {
2 years ago
return nil
}
2 years ago
req := &callbackstruct.CallbackBeforePushReq{
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
CallbackCommand: constant.CallbackOfflinePushCommand,
2 years ago
OperationID: mcontext.GetOperationID(ctx),
2 years ago
PlatformID: int(msg.SenderPlatformID),
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
2 years ago
UserIDList: userIDs,
},
OfflinePushInfo: msg.OfflinePushInfo,
ClientMsgID: msg.ClientMsgID,
SendID: msg.SendID,
GroupID: msg.GroupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
2 years ago
AtUserIDs: msg.AtUserIDList,
2 years ago
Content: utils.GetContent(msg),
}
2 years ago
resp := &callbackstruct.CallbackBeforePushResp{}
2 years ago
err := http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackOfflinePush)
if err != nil {
return err
}
2 years ago
if len(resp.UserIDs) != 0 {
*offlinePushUserIDs = resp.UserIDs
}
2 years ago
if resp.OfflinePushInfo != nil {
msg.OfflinePushInfo = resp.OfflinePushInfo
}
2 years ago
return nil
}
2 years ago
func callbackOnlinePush(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error {
if !config.Config.Callback.CallbackOnlinePush.Enable || utils.Contain(msg.SendID, userIDs...) {
2 years ago
return nil
}
2 years ago
req := callbackstruct.CallbackBeforePushReq{
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
CallbackCommand: constant.CallbackOnlinePushCommand,
2 years ago
OperationID: mcontext.GetOperationID(ctx),
2 years ago
PlatformID: int(msg.SenderPlatformID),
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
2 years ago
UserIDList: userIDs,
},
2 years ago
ClientMsgID: msg.ClientMsgID,
SendID: msg.SendID,
GroupID: msg.GroupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDs: msg.AtUserIDList,
Content: utils.GetContent(msg),
}
2 years ago
resp := &callbackstruct.CallbackBeforePushResp{}
2 years ago
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackOnlinePush)
}
2 years ago
func callbackBeforeSuperGroupOnlinePush(ctx context.Context, groupID string, msg *sdkws.MsgData, pushToUserIDs *[]string) error {
if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.Enable {
2 years ago
return nil
}
2 years ago
req := callbackstruct.CallbackBeforeSuperGroupOnlinePushReq{
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
CallbackCommand: constant.CallbackSuperGroupOnlinePushCommand,
2 years ago
OperationID: mcontext.GetOperationID(ctx),
2 years ago
PlatformID: int(msg.SenderPlatformID),
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
3 years ago
},
2 years ago
ClientMsgID: msg.ClientMsgID,
SendID: msg.SendID,
GroupID: groupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDs: msg.AtUserIDList,
Content: utils.GetContent(msg),
Seq: msg.Seq,
3 years ago
}
2 years ago
resp := &callbackstruct.CallbackBeforeSuperGroupOnlinePushResp{}
2 years ago
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush); err != nil {
return err
3 years ago
}
2 years ago
if len(resp.UserIDs) != 0 {
*pushToUserIDs = resp.UserIDs
}
2 years ago
return nil
3 years ago
}