Files
open-im-server/internal/push/callback.go
T

110 lines
3.7 KiB
Go
Raw Normal View History

2023-02-20 10:13:29 +08:00
package push
2022-05-26 18:02:00 +08:00
import (
2023-02-23 19:15:30 +08:00
"OpenIM/pkg/callbackstruct"
"OpenIM/pkg/common/config"
"OpenIM/pkg/common/constant"
"OpenIM/pkg/common/http"
"OpenIM/pkg/common/tracelog"
"OpenIM/pkg/proto/sdkws"
"OpenIM/pkg/utils"
2023-02-15 15:50:52 +08:00
"context"
2022-05-26 18:02:00 +08:00
)
2023-02-15 15:50:52 +08:00
func url() string {
return config.Config.Callback.CallbackUrl
}
2023-02-22 19:51:14 +08:00
func callbackOfflinePush(ctx context.Context, userIDs []string, msg *sdkws.MsgData, offlinePushUserIDs *[]string) error {
2022-07-29 15:56:16 +08:00
if !config.Config.Callback.CallbackOfflinePush.Enable {
2023-02-15 15:50:52 +08:00
return nil
2022-07-29 15:56:16 +08:00
}
2023-02-20 10:13:29 +08:00
req := &callbackstruct.CallbackBeforePushReq{
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
2022-07-29 15:56:16 +08:00
CallbackCommand: constant.CallbackOfflinePushCommand,
2023-02-15 15:50:52 +08:00
OperationID: tracelog.GetOperationID(ctx),
PlatformID: int(msg.SenderPlatformID),
2022-07-29 14:36:07 +08:00
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
2023-02-22 19:51:14 +08:00
UserIDList: userIDs,
2022-07-29 14:36:07 +08:00
},
OfflinePushInfo: msg.OfflinePushInfo,
2022-09-09 10:58:38 +08:00
ClientMsgID: msg.ClientMsgID,
2022-07-29 14:36:07 +08:00
SendID: msg.SendID,
GroupID: msg.GroupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
2023-02-20 10:13:29 +08:00
AtUserIDs: msg.AtUserIDList,
2023-02-15 15:50:52 +08:00
Content: utils.GetContent(msg),
}
2023-02-20 10:13:29 +08:00
resp := &callbackstruct.CallbackBeforePushResp{}
2023-02-15 15:50:52 +08:00
err := http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackOfflinePush)
if err != nil {
return err
2022-07-29 14:36:07 +08:00
}
2023-02-22 19:51:14 +08:00
if len(resp.UserIDs) != 0 {
*offlinePushUserIDs = resp.UserIDs
2022-07-29 14:36:07 +08:00
}
2023-02-15 15:50:52 +08:00
if resp.OfflinePushInfo != nil {
msg.OfflinePushInfo = resp.OfflinePushInfo
2022-07-29 17:09:21 +08:00
}
2023-02-15 15:50:52 +08:00
return nil
2022-07-29 14:36:07 +08:00
}
2023-02-22 19:51:14 +08:00
func callbackOnlinePush(ctx context.Context, userIDs []string, msg *sdkws.MsgData) error {
if !config.Config.Callback.CallbackOnlinePush.Enable || utils.Contain(msg.SendID, userIDs...) {
2023-02-15 15:50:52 +08:00
return nil
2022-07-29 14:36:07 +08:00
}
2023-02-20 10:13:29 +08:00
req := callbackstruct.CallbackBeforePushReq{
UserStatusBatchCallbackReq: callbackstruct.UserStatusBatchCallbackReq{
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
2022-07-29 15:56:16 +08:00
CallbackCommand: constant.CallbackOnlinePushCommand,
2023-02-22 19:51:14 +08:00
OperationID: tracelog.GetOperationID(ctx),
2023-02-15 15:50:52 +08:00
PlatformID: int(msg.SenderPlatformID),
2022-07-29 15:56:16 +08:00
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
2023-02-22 19:51:14 +08:00
UserIDList: userIDs,
2022-07-29 15:56:16 +08:00
},
2023-02-20 10:13:29 +08:00
ClientMsgID: msg.ClientMsgID,
SendID: msg.SendID,
GroupID: msg.GroupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDs: msg.AtUserIDList,
Content: utils.GetContent(msg),
2022-07-29 15:56:16 +08:00
}
2023-02-20 10:13:29 +08:00
resp := &callbackstruct.CallbackBeforePushResp{}
2023-02-15 15:50:52 +08:00
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackOnlinePush)
2022-07-29 14:36:07 +08:00
}
2023-02-22 19:51:14 +08:00
func callbackBeforeSuperGroupOnlinePush(ctx context.Context, groupID string, msg *sdkws.MsgData, pushToUserIDs *[]string) error {
2022-07-29 14:36:07 +08:00
if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.Enable {
2023-02-15 15:50:52 +08:00
return nil
2022-07-29 14:36:07 +08:00
}
2023-02-20 10:13:29 +08:00
req := callbackstruct.CallbackBeforeSuperGroupOnlinePushReq{
UserStatusBaseCallback: callbackstruct.UserStatusBaseCallback{
2022-07-29 14:36:07 +08:00
CallbackCommand: constant.CallbackSuperGroupOnlinePushCommand,
2023-02-15 15:50:52 +08:00
OperationID: tracelog.GetOperationID(ctx),
PlatformID: int(msg.SenderPlatformID),
2022-06-07 17:42:24 +08:00
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
2022-05-26 18:02:00 +08:00
},
2023-02-22 19:51:14 +08:00
ClientMsgID: msg.ClientMsgID,
SendID: msg.SendID,
GroupID: groupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDs: msg.AtUserIDList,
Content: utils.GetContent(msg),
Seq: msg.Seq,
2022-05-26 18:02:00 +08:00
}
2023-02-20 10:13:29 +08:00
resp := &callbackstruct.CallbackBeforeSuperGroupOnlinePushResp{}
2023-02-15 15:50:52 +08:00
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush); err != nil {
return err
2022-05-26 18:02:00 +08:00
}
2023-02-22 19:51:14 +08:00
if len(resp.UserIDs) != 0 {
*pushToUserIDs = resp.UserIDs
2022-07-29 14:36:07 +08:00
}
2023-02-15 15:50:52 +08:00
return nil
2022-05-26 18:02:00 +08:00
}