callback add offline info

This commit is contained in:
Gordon 2022-08-19 13:04:38 +08:00
parent 40b7314f6d
commit 9a82dd356c
3 changed files with 27 additions and 7 deletions

View File

@ -12,7 +12,7 @@ import (
http2 "net/http" http2 "net/http"
) )
func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.MsgData, offlinePushUserIDList *[]string) cbApi.CommonCallbackResp { func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.MsgData, offlinePushUserIDList *[]string, offlineInfo *commonPb.OfflinePushInfo) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID} callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
if !config.Config.Callback.CallbackOfflinePush.Enable { if !config.Config.Callback.CallbackOfflinePush.Enable {
return callbackResp return callbackResp
@ -47,8 +47,13 @@ func callbackOfflinePush(operationID string, userIDList []string, msg *commonPb.
return callbackResp return callbackResp
} }
} }
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow && len(resp.UserIDList) != 0 { if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
*offlinePushUserIDList = resp.UserIDList if len(resp.UserIDList) != 0 {
*offlinePushUserIDList = resp.UserIDList
}
if resp.OfflinePushInfo != nil {
*offlineInfo = *resp.OfflinePushInfo
}
} }
log.NewDebug(operationID, utils.GetSelfFuncName(), offlinePushUserIDList, resp.UserIDList) log.NewDebug(operationID, utils.GetSelfFuncName(), offlinePushUserIDList, resp.UserIDList)
return callbackResp return callbackResp

View File

@ -17,6 +17,7 @@ import (
pbPush "Open_IM/pkg/proto/push" pbPush "Open_IM/pkg/proto/push"
pbRelay "Open_IM/pkg/proto/relay" pbRelay "Open_IM/pkg/proto/relay"
pbRtc "Open_IM/pkg/proto/rtc" pbRtc "Open_IM/pkg/proto/rtc"
commonPb "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils" "Open_IM/pkg/utils"
"context" "context"
"encoding/json" "encoding/json"
@ -123,8 +124,8 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
} }
} }
var offlineInfo commonPb.OfflinePushInfo
callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList, pushMsg.MsgData, &[]string{}) callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList, pushMsg.MsgData, &[]string{}, &offlineInfo)
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp") log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
if callbackResp.ErrCode != 0 { if callbackResp.ErrCode != 0 {
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp) log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
@ -133,6 +134,12 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offlinePush stop") log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offlinePush stop")
return return
} }
if offlineInfo.Title != "" {
content = offlineInfo.Title
}
if offlineInfo.Desc != "" {
jsonCustomContent = offlineInfo.Desc
}
if offlinePusher == nil { if offlinePusher == nil {
return return
} }
@ -258,7 +265,8 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
if len(onlineFailedUserIDList) > 0 { if len(onlineFailedUserIDList) > 0 {
var offlinePushUserIDList []string var offlinePushUserIDList []string
var needOfflinePushUserIDList []string var needOfflinePushUserIDList []string
callbackResp := callbackOfflinePush(pushMsg.OperationID, onlineFailedUserIDList, pushMsg.MsgData, &offlinePushUserIDList) var offlineInfo commonPb.OfflinePushInfo
callbackResp := callbackOfflinePush(pushMsg.OperationID, onlineFailedUserIDList, pushMsg.MsgData, &offlinePushUserIDList, &offlineInfo)
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp") log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
if callbackResp.ErrCode != 0 { if callbackResp.ErrCode != 0 {
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp) log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
@ -272,6 +280,12 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
} else { } else {
needOfflinePushUserIDList = onlineFailedUserIDList needOfflinePushUserIDList = onlineFailedUserIDList
} }
if offlineInfo.Title != "" {
content = offlineInfo.Title
}
if offlineInfo.Desc != "" {
jsonCustomContent = offlineInfo.Desc
}
if offlinePusher == nil { if offlinePusher == nil {
return return
} }

View File

@ -15,7 +15,8 @@ type CallbackBeforePushReq struct {
type CallbackBeforePushResp struct { type CallbackBeforePushResp struct {
*CommonCallbackResp *CommonCallbackResp
UserIDList []string `json:"userIDList"` UserIDList []string `json:"userIDList"`
OfflinePushInfo *commonPb.OfflinePushInfo `json:"offlinePushInfo"`
} }
type CallbackBeforeSuperGroupOnlinePushReq struct { type CallbackBeforeSuperGroupOnlinePushReq struct {