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

153 lines
6.0 KiB
Go
Raw Normal View History

2022-05-26 18:02:00 +08:00
package logic
import (
cbApi "Open_IM/pkg/call_back_struct"
2022-08-04 14:21:03 +08:00
"Open_IM/pkg/common/callback"
2022-05-26 18:02:00 +08:00
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
2022-07-29 14:36:07 +08:00
"Open_IM/pkg/common/log"
2022-05-26 18:02:00 +08:00
commonPb "Open_IM/pkg/proto/sdk_ws"
2022-07-29 14:36:07 +08:00
"Open_IM/pkg/utils"
2022-05-26 18:02:00 +08:00
http2 "net/http"
)
2022-09-01 21:05:16 +08:00
func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.MsgData, offlinePushUserIDList *[]string) cbApi.CommonCallbackResp {
2022-07-29 15:56:16 +08:00
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
if !config.Config.Callback.CallbackOfflinePush.Enable {
return callbackResp
}
2022-07-29 14:36:07 +08:00
req := cbApi.CallbackBeforePushReq{
UserStatusBatchCallbackReq: cbApi.UserStatusBatchCallbackReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
2022-07-29 15:56:16 +08:00
CallbackCommand: constant.CallbackOfflinePushCommand,
2022-07-29 14:36:07 +08:00
OperationID: operationID,
PlatformID: msg.SenderPlatformID,
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
UserIDList: userIDList,
},
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,
AtUserIDList: msg.AtUserIDList,
2022-08-04 14:21:03 +08:00
Content: callback.GetContent(msg),
2022-07-29 14:36:07 +08:00
}
2022-11-08 17:10:27 +08:00
resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
2022-10-20 12:01:06 +08:00
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOfflinePushCommand, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil {
2022-07-29 14:36:07 +08:00
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
if !config.Config.Callback.CallbackOfflinePush.CallbackFailedContinue {
callbackResp.ActionCode = constant.ActionForbidden
return callbackResp
} else {
callbackResp.ActionCode = constant.ActionAllow
return callbackResp
}
}
2022-08-19 13:04:38 +08:00
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
if len(resp.UserIDList) != 0 {
*offlinePushUserIDList = resp.UserIDList
}
if resp.OfflinePushInfo != nil {
2022-09-01 21:05:16 +08:00
msg.OfflinePushInfo = resp.OfflinePushInfo
2022-08-19 13:04:38 +08:00
}
2022-07-29 17:09:21 +08:00
}
log.NewDebug(operationID, utils.GetSelfFuncName(), offlinePushUserIDList, resp.UserIDList)
2022-07-29 14:36:07 +08:00
return callbackResp
}
func callbackOnlinePush(operationID string, userIDList []string, msg *commonPb.MsgData) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
2022-09-26 12:22:28 +08:00
if !config.Config.Callback.CallbackOnlinePush.Enable || utils.IsContain(msg.SendID, userIDList) {
2022-07-29 14:36:07 +08:00
return callbackResp
}
2022-07-29 15:56:16 +08:00
req := cbApi.CallbackBeforePushReq{
UserStatusBatchCallbackReq: cbApi.UserStatusBatchCallbackReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackOnlinePushCommand,
OperationID: operationID,
PlatformID: msg.SenderPlatformID,
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
UserIDList: userIDList,
},
OfflinePushInfo: msg.OfflinePushInfo,
2022-09-09 10:58:38 +08:00
ClientMsgID: msg.ClientMsgID,
2022-07-29 15:56:16 +08:00
SendID: msg.SendID,
GroupID: msg.GroupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDList: msg.AtUserIDList,
2022-08-04 14:21:03 +08:00
Content: callback.GetContent(msg),
2022-07-29 15:56:16 +08:00
}
2022-11-08 17:10:27 +08:00
resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
2022-10-20 12:01:06 +08:00
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOnlinePushCommand, req, resp, config.Config.Callback.CallbackOnlinePush.CallbackTimeOut); err != nil {
2022-07-29 15:56:16 +08:00
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
if !config.Config.Callback.CallbackOnlinePush.CallbackFailedContinue {
callbackResp.ActionCode = constant.ActionForbidden
return callbackResp
} else {
callbackResp.ActionCode = constant.ActionAllow
return callbackResp
}
}
2022-09-21 16:09:02 +08:00
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
if resp.OfflinePushInfo != nil {
msg.OfflinePushInfo = resp.OfflinePushInfo
}
}
2022-07-29 15:56:16 +08:00
return callbackResp
2022-07-29 14:36:07 +08:00
}
func callbackBeforeSuperGroupOnlinePush(operationID string, groupID string, msg *commonPb.MsgData, pushToUserList *[]string) cbApi.CommonCallbackResp {
2022-08-01 17:02:56 +08:00
log.Debug(operationID, utils.GetSelfFuncName(), groupID, msg.String(), pushToUserList)
2022-07-29 14:36:07 +08:00
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.Enable {
return callbackResp
}
req := cbApi.CallbackBeforeSuperGroupOnlinePushReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackSuperGroupOnlinePushCommand,
2022-05-26 18:02:00 +08:00
OperationID: operationID,
2022-05-27 19:33:47 +08:00
PlatformID: msg.SenderPlatformID,
2022-06-07 17:42:24 +08:00
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
2022-05-26 18:02:00 +08:00
},
2022-05-27 19:33:47 +08:00
OfflinePushInfo: msg.OfflinePushInfo,
2022-09-09 11:00:15 +08:00
ClientMsgID: msg.ClientMsgID,
2022-05-27 19:33:47 +08:00
SendID: msg.SendID,
2022-07-29 14:36:07 +08:00
GroupID: groupID,
2022-05-27 19:33:47 +08:00
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDList: msg.AtUserIDList,
2022-08-04 14:21:03 +08:00
Content: callback.GetContent(msg),
2022-05-26 18:02:00 +08:00
}
2022-11-08 17:10:27 +08:00
resp := &cbApi.CallbackBeforeSuperGroupOnlinePushResp{CommonCallbackResp: &callbackResp}
2022-10-20 12:01:06 +08:00
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackSuperGroupOnlinePushCommand, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackTimeOut); err != nil {
2022-05-26 18:02:00 +08:00
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
2022-07-29 15:56:16 +08:00
if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackFailedContinue {
2022-05-27 11:49:38 +08:00
callbackResp.ActionCode = constant.ActionForbidden
return callbackResp
} else {
callbackResp.ActionCode = constant.ActionAllow
return callbackResp
}
2022-05-26 18:02:00 +08:00
}
2022-09-21 16:09:02 +08:00
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
if len(resp.UserIDList) != 0 {
*pushToUserList = resp.UserIDList
}
if resp.OfflinePushInfo != nil {
msg.OfflinePushInfo = resp.OfflinePushInfo
}
2022-07-29 14:36:07 +08:00
}
log.NewDebug(operationID, utils.GetSelfFuncName(), pushToUserList, resp.UserIDList)
2022-05-26 18:02:00 +08:00
return callbackResp
2022-07-29 14:36:07 +08:00
2022-05-26 18:02:00 +08:00
}