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/msggateway/callback.go

156 lines
6.2 KiB

2 years ago
package msggateway
3 years ago
import (
2 years ago
"context"
2 years ago
cbapi "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"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/tracelog"
3 years ago
"time"
3 years ago
)
2 years ago
func url() string {
return config.Config.Callback.CallbackUrl
}
func CallbackUserOnline(ctx context.Context, userID string, platformID int, isAppBackground bool, connID string) error {
3 years ago
if !config.Config.Callback.CallbackUserOnline.Enable {
2 years ago
return nil
3 years ago
}
2 years ago
req := cbapi.CallbackUserOnlineReq{
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackUserOnlineCommand,
2 years ago
OperationID: tracelog.GetOperationID(ctx),
PlatformID: platformID,
Platform: constant.PlatformIDToName(platformID),
},
UserID: userID,
3 years ago
},
2 years ago
Seq: time.Now().UnixMilli(),
2 years ago
IsAppBackground: isAppBackground,
ConnID: connID,
3 years ago
}
2 years ago
resp := cbapi.CommonCallbackResp{}
return http.CallBackPostReturn(url(), &req, &resp, config.Config.Callback.CallbackUserOnline)
3 years ago
}
2 years ago
func CallbackUserOffline(ctx context.Context, userID string, platformID int, connID string) error {
3 years ago
if !config.Config.Callback.CallbackUserOffline.Enable {
2 years ago
return nil
3 years ago
}
2 years ago
req := &cbapi.CallbackUserOfflineReq{
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackUserOfflineCommand,
2 years ago
OperationID: tracelog.GetOperationID(ctx),
PlatformID: platformID,
Platform: constant.PlatformIDToName(platformID),
},
UserID: userID,
3 years ago
},
2 years ago
Seq: time.Now().UnixMilli(),
2 years ago
ConnID: connID,
3 years ago
}
2 years ago
resp := &cbapi.CallbackUserOfflineResp{}
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackUserOffline)
3 years ago
}
2 years ago
2 years ago
func CallbackUserKickOff(ctx context.Context, userID string, platformID int) error {
2 years ago
if !config.Config.Callback.CallbackUserKickOff.Enable {
2 years ago
return nil
2 years ago
}
2 years ago
req := &cbapi.CallbackUserKickOffReq{
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
2 years ago
CallbackCommand: constant.CallbackUserKickOffCommand,
2 years ago
OperationID: tracelog.GetOperationID(ctx),
PlatformID: platformID,
2 years ago
Platform: constant.PlatformIDToName(platformID),
},
UserID: userID,
},
2 years ago
Seq: time.Now().UnixMilli(),
2 years ago
}
2 years ago
resp := &cbapi.CommonCallbackResp{}
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackUserOffline)
2 years ago
}
2 years ago
//func callbackUserOnline(operationID, userID string, platformID int, token string, isAppBackground bool, connID string) cbApi.CommonCallbackResp {
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackUserOnline.Enable {
// return callbackResp
// }
// callbackUserOnlineReq := cbApi.CallbackUserOnlineReq{
// Token: token,
// UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackUserOnlineCommand,
// OperationID: operationID,
// PlatformID: int32(platformID),
// Platform: constant.PlatformIDToName(platformID),
// },
// UserID: userID,
// },
// Seq: int(time.Now().UnixNano() / 1e6),
// IsAppBackground: isAppBackground,
// ConnID: connID,
// }
// callbackUserOnlineResp := &cbApi.CallbackUserOnlineResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOnlineCommand, callbackUserOnlineReq, callbackUserOnlineResp, config.Config.Callback.CallbackUserOnline.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// }
// return callbackResp
//}
//func callbackUserOffline(operationID, userID string, platformID int, connID string) cbApi.CommonCallbackResp {
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackUserOffline.Enable {
// return callbackResp
// }
// callbackOfflineReq := cbApi.CallbackUserOfflineReq{
// UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackUserOfflineCommand,
// OperationID: operationID,
// PlatformID: int32(platformID),
// Platform: constant.PlatformIDToName(platformID),
// },
// UserID: userID,
// },
// Seq: int(time.Now().UnixNano() / 1e6),
// ConnID: connID,
// }
// callbackUserOfflineResp := &cbApi.CallbackUserOfflineResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserOfflineCommand, callbackOfflineReq, callbackUserOfflineResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// }
// return callbackResp
//}
//func callbackUserKickOff(operationID string, userID string, platformID int) cbApi.CommonCallbackResp {
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackUserKickOff.Enable {
// return callbackResp
// }
// callbackUserKickOffReq := cbApi.CallbackUserKickOffReq{
// UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackUserKickOffCommand,
// OperationID: operationID,
// PlatformID: int32(platformID),
// Platform: constant.PlatformIDToName(platformID),
// },
// UserID: userID,
// },
// Seq: int(time.Now().UnixNano() / 1e6),
// }
// callbackUserKickOffResp := &cbApi.CallbackUserKickOffResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackUserKickOffCommand, callbackUserKickOffReq, callbackUserKickOffResp, config.Config.Callback.CallbackUserOffline.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// }
// return callbackResp
//}