test-errcode
withchao 2 years ago
parent c93aa15473
commit ed466387e4

@ -1,89 +1,155 @@
package msggateway
import (
cbApi "Open_IM/pkg/callback_struct"
cbapi "Open_IM/pkg/callbackstruct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
http2 "net/http"
"Open_IM/pkg/common/tracelog"
"context"
"time"
)
func callbackUserOnline(operationID, userID string, platformID int, token string, isAppBackground bool, connID string) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
func url() string {
return config.Config.Callback.CallbackUrl
}
func CallbackUserOnline(ctx context.Context, userID string, platformID int, isAppBackground bool, connID string) error {
if !config.Config.Callback.CallbackUserOnline.Enable {
return callbackResp
return nil
}
callbackUserOnlineReq := cbApi.CallbackUserOnlineReq{
Token: token,
UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
req := cbapi.CallbackUserOnlineReq{
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackUserOnlineCommand,
OperationID: operationID,
PlatformID: int32(platformID),
OperationID: tracelog.GetOperationID(ctx),
PlatformID: platformID,
Platform: constant.PlatformIDToName(platformID),
},
UserID: userID,
},
Seq: int(time.Now().UnixNano() / 1e6),
Seq: time.Now().UnixMilli(),
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
resp := cbapi.CommonCallbackResp{}
return http.CallBackPostReturn(url(), &req, &resp, config.Config.Callback.CallbackUserOnline)
}
func callbackUserOffline(operationID, userID string, platformID int, connID string) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
func CallbackUserOffline(ctx context.Context, userID string, platformID int, connID string) error {
if !config.Config.Callback.CallbackUserOffline.Enable {
return callbackResp
return nil
}
callbackOfflineReq := cbApi.CallbackUserOfflineReq{
UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
req := &cbapi.CallbackUserOfflineReq{
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackUserOfflineCommand,
OperationID: operationID,
PlatformID: int32(platformID),
OperationID: tracelog.GetOperationID(ctx),
PlatformID: platformID,
Platform: constant.PlatformIDToName(platformID),
},
UserID: userID,
},
Seq: int(time.Now().UnixNano() / 1e6),
Seq: time.Now().UnixMilli(),
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
resp := &cbapi.CallbackUserOfflineResp{}
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackUserOffline)
}
func callbackUserKickOff(operationID string, userID string, platformID int) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
func CallbackUserKickOff(ctx context.Context, userID string, platformID int) error {
if !config.Config.Callback.CallbackUserKickOff.Enable {
return callbackResp
return nil
}
callbackUserKickOffReq := cbApi.CallbackUserKickOffReq{
UserStatusCallbackReq: cbApi.UserStatusCallbackReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
req := &cbapi.CallbackUserKickOffReq{
UserStatusCallbackReq: cbapi.UserStatusCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackUserKickOffCommand,
OperationID: operationID,
PlatformID: int32(platformID),
OperationID: tracelog.GetOperationID(ctx),
PlatformID: 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()
Seq: time.Now().UnixMilli(),
}
return callbackResp
resp := &cbapi.CommonCallbackResp{}
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackUserOffline)
}
//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
//}

@ -1,28 +1,30 @@
package logic
import (
cbApi "Open_IM/pkg/callback_struct"
"Open_IM/pkg/common/callback"
cbapi "Open_IM/pkg/callbackstruct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/tracelog"
common "Open_IM/pkg/proto/sdkws"
"Open_IM/pkg/utils"
http2 "net/http"
"context"
)
func callbackOfflinePush(operationID string, userIDList []string, msg *common.MsgData, offlinePushUserIDList *[]string) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
func url() string {
return config.Config.Callback.CallbackUrl
}
func CallbackOfflinePush(ctx context.Context, userIDList []string, msg *common.MsgData, offlinePushUserIDList *[]string) error {
if !config.Config.Callback.CallbackOfflinePush.Enable {
return callbackResp
return nil
}
req := cbApi.CallbackBeforePushReq{
UserStatusBatchCallbackReq: cbApi.UserStatusBatchCallbackReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
req := &cbapi.CallbackBeforePushReq{
UserStatusBatchCallbackReq: cbapi.UserStatusBatchCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackOfflinePushCommand,
OperationID: operationID,
PlatformID: msg.SenderPlatformID,
OperationID: tracelog.GetOperationID(ctx),
PlatformID: int(msg.SenderPlatformID),
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
UserIDList: userIDList,
@ -34,120 +36,214 @@ func callbackOfflinePush(operationID string, userIDList []string, msg *common.Ms
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDList: msg.AtUserIDList,
Content: callback.GetContent(msg),
}
resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOfflinePushCommand, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil {
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
Content: utils.GetContent(msg),
}
resp := &cbapi.CallbackBeforePushResp{}
err := http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackOfflinePush)
if err != nil {
return err
}
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
if len(resp.UserIDList) != 0 {
*offlinePushUserIDList = resp.UserIDList
}
if resp.OfflinePushInfo != nil {
msg.OfflinePushInfo = resp.OfflinePushInfo
}
}
log.NewDebug(operationID, utils.GetSelfFuncName(), offlinePushUserIDList, resp.UserIDList)
return callbackResp
return nil
}
func callbackOnlinePush(operationID string, userIDList []string, msg *common.MsgData) cbApi.CommonCallbackResp {
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
if !config.Config.Callback.CallbackOnlinePush.Enable || utils.IsContain(msg.SendID, userIDList) {
return callbackResp
func CallbackOnlinePush(operationID string, userIDList []string, msg *common.MsgData) error {
if !config.Config.Callback.CallbackOnlinePush.Enable || utils.Contain(msg.SendID, userIDList...) {
return nil
}
req := cbApi.CallbackBeforePushReq{
UserStatusBatchCallbackReq: cbApi.UserStatusBatchCallbackReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
req := cbapi.CallbackBeforePushReq{
UserStatusBatchCallbackReq: cbapi.UserStatusBatchCallbackReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackOnlinePushCommand,
OperationID: operationID,
PlatformID: msg.SenderPlatformID,
PlatformID: int(msg.SenderPlatformID),
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
UserIDList: userIDList,
},
//OfflinePushInfo: msg.OfflinePushInfo,
ClientMsgID: msg.ClientMsgID,
SendID: msg.SendID,
GroupID: msg.GroupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDList: msg.AtUserIDList,
Content: callback.GetContent(msg),
}
resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOnlinePushCommand, req, resp, config.Config.Callback.CallbackOnlinePush.CallbackTimeOut); err != nil {
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
}
Content: utils.GetContent(msg),
}
if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
//if resp.OfflinePushInfo != nil {
// msg.OfflinePushInfo = resp.OfflinePushInfo
//}
}
return callbackResp
resp := &cbapi.CallbackBeforePushResp{}
return http.CallBackPostReturn(url(), req, resp, config.Config.Callback.CallbackOnlinePush)
}
func callbackBeforeSuperGroupOnlinePush(operationID string, groupID string, msg *common.MsgData, pushToUserList *[]string) cbApi.CommonCallbackResp {
log.Debug(operationID, utils.GetSelfFuncName(), groupID, msg.String(), pushToUserList)
callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
func CallbackBeforeSuperGroupOnlinePush(ctx context.Context, groupID string, msg *common.MsgData, pushToUserList *[]string) error {
if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.Enable {
return callbackResp
return nil
}
req := cbApi.CallbackBeforeSuperGroupOnlinePushReq{
UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
req := cbapi.CallbackBeforeSuperGroupOnlinePushReq{
UserStatusBaseCallback: cbapi.UserStatusBaseCallback{
CallbackCommand: constant.CallbackSuperGroupOnlinePushCommand,
OperationID: operationID,
PlatformID: msg.SenderPlatformID,
OperationID: tracelog.GetOperationID(ctx),
PlatformID: int(msg.SenderPlatformID),
Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
},
//OfflinePushInfo: msg.OfflinePushInfo,
ClientMsgID: msg.ClientMsgID,
SendID: msg.SendID,
GroupID: groupID,
ContentType: msg.ContentType,
SessionType: msg.SessionType,
AtUserIDList: msg.AtUserIDList,
Content: callback.GetContent(msg),
Content: utils.GetContent(msg),
Seq: msg.Seq,
}
resp := &cbApi.CallbackBeforeSuperGroupOnlinePushResp{CommonCallbackResp: &callbackResp}
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackSuperGroupOnlinePushCommand, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackFailedContinue {
callbackResp.ActionCode = constant.ActionForbidden
return callbackResp
} else {
callbackResp.ActionCode = constant.ActionAllow
return callbackResp
}
resp := &cbapi.CallbackBeforeSuperGroupOnlinePushResp{}
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush); err != nil {
return err
}
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
//}
}
log.NewDebug(operationID, utils.GetSelfFuncName(), pushToUserList, resp.UserIDList)
return callbackResp
return nil
}
//func callbackOfflinePush(operationID string, userIDList []string, msg *common.MsgData, offlinePushUserIDList *[]string) cbApi.CommonCallbackResp {
// callbackResp := cbapi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackOfflinePush.Enable {
// return callbackResp
// }
// req := cbApi.CallbackBeforePushReq{
// UserStatusBatchCallbackReq: cbApi.UserStatusBatchCallbackReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackOfflinePushCommand,
// OperationID: operationID,
// PlatformID: msg.SenderPlatformID,
// Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
// },
// UserIDList: userIDList,
// },
// OfflinePushInfo: msg.OfflinePushInfo,
// ClientMsgID: msg.ClientMsgID,
// SendID: msg.SendID,
// GroupID: msg.GroupID,
// ContentType: msg.ContentType,
// SessionType: msg.SessionType,
// AtUserIDList: msg.AtUserIDList,
// Content: callback.GetContent(msg),
// }
// resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOfflinePushCommand, req, resp, config.Config.Callback.CallbackOfflinePush.CallbackTimeOut); err != nil {
// 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
// }
// }
// if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
// if len(resp.UserIDList) != 0 {
// *offlinePushUserIDList = resp.UserIDList
// }
// if resp.OfflinePushInfo != nil {
// msg.OfflinePushInfo = resp.OfflinePushInfo
// }
// }
// log.NewDebug(operationID, utils.GetSelfFuncName(), offlinePushUserIDList, resp.UserIDList)
// return callbackResp
//}
//
//func callbackOnlinePush(operationID string, userIDList []string, msg *common.MsgData) cbApi.CommonCallbackResp {
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackOnlinePush.Enable || utils.IsContain(msg.SendID, userIDList) {
// return callbackResp
// }
// 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,
// ClientMsgID: msg.ClientMsgID,
// SendID: msg.SendID,
// GroupID: msg.GroupID,
// ContentType: msg.ContentType,
// SessionType: msg.SessionType,
// AtUserIDList: msg.AtUserIDList,
// Content: callback.GetContent(msg),
// }
// resp := &cbApi.CallbackBeforePushResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackOnlinePushCommand, req, resp, config.Config.Callback.CallbackOnlinePush.CallbackTimeOut); err != nil {
// 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
// }
// }
// if resp.ErrCode == constant.CallbackHandleSuccess && resp.ActionCode == constant.ActionAllow {
// //if resp.OfflinePushInfo != nil {
// // msg.OfflinePushInfo = resp.OfflinePushInfo
// //}
// }
// return callbackResp
//}
//
//func callbackBeforeSuperGroupOnlinePush(operationID string, groupID string, msg *common.MsgData, pushToUserList *[]string) cbApi.CommonCallbackResp {
// log.Debug(operationID, utils.GetSelfFuncName(), groupID, msg.String(), pushToUserList)
// callbackResp := cbApi.CommonCallbackResp{OperationID: operationID}
// if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.Enable {
// return callbackResp
// }
// req := cbApi.CallbackBeforeSuperGroupOnlinePushReq{
// UserStatusBaseCallback: cbApi.UserStatusBaseCallback{
// CallbackCommand: constant.CallbackSuperGroupOnlinePushCommand,
// OperationID: operationID,
// PlatformID: msg.SenderPlatformID,
// Platform: constant.PlatformIDToName(int(msg.SenderPlatformID)),
// },
// //OfflinePushInfo: msg.OfflinePushInfo,
// ClientMsgID: msg.ClientMsgID,
// SendID: msg.SendID,
// GroupID: groupID,
// ContentType: msg.ContentType,
// SessionType: msg.SessionType,
// AtUserIDList: msg.AtUserIDList,
// Content: callback.GetContent(msg),
// Seq: msg.Seq,
// }
// resp := &cbApi.CallbackBeforeSuperGroupOnlinePushResp{CommonCallbackResp: &callbackResp}
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackSuperGroupOnlinePushCommand, req, resp, config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// if !config.Config.Callback.CallbackBeforeSuperGroupOnlinePush.CallbackFailedContinue {
// callbackResp.ActionCode = constant.ActionForbidden
// return callbackResp
// } else {
// callbackResp.ActionCode = constant.ActionAllow
// return callbackResp
// }
// }
// 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
// //}
// }
// log.NewDebug(operationID, utils.GetSelfFuncName(), pushToUserList, resp.UserIDList)
// return callbackResp
//
//}

@ -5,55 +5,22 @@ import (
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/tracelog"
pbfriend "Open_IM/pkg/proto/friend"
"context"
//"Open_IM/pkg/proto/msg"
"Open_IM/pkg/utils"
http2 "net/http"
)
func callbackBeforeAddFriendV1(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error {
resp := callbackBeforeAddFriend(ctx, req)
if resp.ErrCode != 0 {
return (&constant.ErrInfo{
ErrCode: resp.ErrCode,
ErrMsg: resp.ErrMsg,
}).Wrap()
}
return nil
}
func callbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) cbapi.CommonCallbackResp {
callbackResp := cbapi.CommonCallbackResp{OperationID: tracelog.GetOperationID(ctx)}
func CallbackBeforeAddFriend(ctx context.Context, req *pbfriend.ApplyToAddFriendReq) error {
if !config.Config.Callback.CallbackBeforeAddFriend.Enable {
return callbackResp
return nil
}
commonCallbackReq := &cbapi.CallbackBeforeAddFriendReq{
cbReq := &cbapi.CallbackBeforeAddFriendReq{
CallbackCommand: constant.CallbackBeforeAddFriendCommand,
FromUserID: req.FromUserID,
ToUserID: req.ToUserID,
ReqMsg: req.ReqMsg,
OperationID: tracelog.GetOperationID(ctx),
}
resp := &cbapi.CallbackBeforeAddFriendResp{
CommonCallbackResp: &callbackResp,
}
//utils.CopyStructFields(req, msg.MsgData)
defer log.NewDebug(tracelog.GetOperationID(ctx), utils.GetSelfFuncName(), commonCallbackReq, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeAddFriendCommand, commonCallbackReq, resp, config.Config.Callback.CallbackBeforeAddFriend); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
if !*config.Config.Callback.CallbackBeforeAddFriend.CallbackFailedContinue {
callbackResp.ActionCode = constant.ActionForbidden
return callbackResp
} else {
callbackResp.ActionCode = constant.ActionAllow
return callbackResp
}
}
return callbackResp
resp := &cbapi.CallbackBeforeAddFriendResp{}
return http.CallBackPostReturn(config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeAddFriend)
}

@ -50,7 +50,7 @@ func (s *friendServer) ApplyToAddFriend(ctx context.Context, req *pbfriend.Apply
if err := tokenverify.CheckAccessV3(ctx, req.FromUserID); err != nil {
return nil, err
}
if err := callbackBeforeAddFriendV1(ctx, req); err != nil {
if err := CallbackBeforeAddFriend(ctx, req); err != nil {
return nil, err
}
if req.ToUserID == req.FromUserID {

@ -44,7 +44,7 @@ func CallbackBeforeCreateGroup(ctx context.Context, req *group.CreateGroupReq) (
})
}
resp := &callbackstruct.CallbackBeforeCreateGroupResp{}
err = http.CallBackPostReturnV2(config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeCreateGroup)
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, cbReq, resp, config.Config.Callback.CallbackBeforeCreateGroup)
if err != nil {
return err
}
@ -79,7 +79,7 @@ func CallbackBeforeMemberJoinGroup(ctx context.Context, groupMember *relation.Gr
GroupEx: groupEx,
}
resp := &callbackstruct.CallbackBeforeMemberJoinGroupResp{}
err = http.CallBackPostReturnV2(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup)
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeMemberJoinGroup)
if err != nil {
return err
}
@ -119,7 +119,7 @@ func CallbackBeforeSetGroupMemberInfo(ctx context.Context, req *group.SetGroupMe
callbackReq.Ex = &req.Ex.Value
}
resp := &callbackstruct.CallbackBeforeSetGroupMemberInfoResp{}
err = http.CallBackPostReturnV2(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo)
err = http.CallBackPostReturn(config.Config.Callback.CallbackUrl, callbackReq, resp, config.Config.Callback.CallbackBeforeSetGroupMemberInfo)
if err != nil {
return err
}

@ -46,7 +46,7 @@ func CallbackBeforeSendSingleMsg(ctx context.Context, msg *pbChat.SendMsgReq) er
RecvID: msg.MsgData.RecvID,
}
resp := &cbapi.CallbackBeforeSendSingleMsgResp{}
return http.CallBackPostReturnV2(cbURL(), req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg)
return http.CallBackPostReturn(cbURL(), req, resp, config.Config.Callback.CallbackBeforeSendSingleMsg)
}
func CallbackAfterSendSingleMsg(ctx context.Context, msg *pbChat.SendMsgReq) error {
@ -58,7 +58,7 @@ func CallbackAfterSendSingleMsg(ctx context.Context, msg *pbChat.SendMsgReq) err
RecvID: msg.MsgData.RecvID,
}
resp := &cbapi.CallbackAfterSendSingleMsgResp{}
return http.CallBackPostReturnV2(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendSingleMsg)
return http.CallBackPostReturn(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendSingleMsg)
}
func CallbackBeforeSendGroupMsg(ctx context.Context, msg *pbChat.SendMsgReq) error {
@ -70,7 +70,7 @@ func CallbackBeforeSendGroupMsg(ctx context.Context, msg *pbChat.SendMsgReq) err
GroupID: msg.MsgData.GroupID,
}
resp := &cbapi.CallbackBeforeSendGroupMsgResp{}
return http.CallBackPostReturnV2(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendSingleMsg)
return http.CallBackPostReturn(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendSingleMsg)
}
func CallbackAfterSendGroupMsg(ctx context.Context, msg *pbChat.SendMsgReq) error {
@ -82,7 +82,7 @@ func CallbackAfterSendGroupMsg(ctx context.Context, msg *pbChat.SendMsgReq) erro
GroupID: msg.MsgData.GroupID,
}
resp := &cbapi.CallbackAfterSendGroupMsgResp{}
return http.CallBackPostReturnV2(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg)
return http.CallBackPostReturn(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg)
}
func CallbackMsgModify(ctx context.Context, msg *pbChat.SendMsgReq) error {
@ -93,7 +93,7 @@ func CallbackMsgModify(ctx context.Context, msg *pbChat.SendMsgReq) error {
CommonCallbackReq: toCommonCallback(ctx, msg, constant.CallbackMsgModifyCommand),
}
resp := &cbapi.CallbackMsgModifyCommandResp{}
if err := http.CallBackPostReturnV2(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg); err != nil {
if err := http.CallBackPostReturn(cbURL(), req, resp, config.Config.Callback.CallbackAfterSendGroupMsg); err != nil {
return err
}
if resp.Content != nil {

@ -1,21 +1,23 @@
package msg
import (
cb "Open_IM/pkg/callbackstruct"
cbapi "Open_IM/pkg/callbackstruct"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/constant"
"Open_IM/pkg/common/http"
"Open_IM/pkg/common/log"
"Open_IM/pkg/common/tracelog"
"Open_IM/pkg/proto/msg"
"Open_IM/pkg/utils"
http2 "net/http"
"context"
)
func callbackSetMessageReactionExtensions(setReq *msg.SetMessageReactionExtensionsReq) *cb.CallbackBeforeSetMessageReactionExtResp {
callbackResp := cb.CommonCallbackResp{OperationID: setReq.OperationID}
log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), setReq.String())
req := cb.CallbackBeforeSetMessageReactionExtReq{
OperationID: setReq.OperationID,
func CallbackSetMessageReactionExtensions(ctx context.Context, setReq *msg.SetMessageReactionExtensionsReq) error {
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
return nil
}
req := &cbapi.CallbackBeforeSetMessageReactionExtReq{
OperationID: tracelog.GetOperationID(ctx),
CallbackCommand: constant.CallbackBeforeSetMessageReactionExtensionCommand,
SourceID: setReq.SourceID,
OpUserID: setReq.OpUserID,
@ -26,20 +28,15 @@ func callbackSetMessageReactionExtensions(setReq *msg.SetMessageReactionExtensio
IsExternalExtensions: setReq.IsExternalExtensions,
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
}
resp := &cb.CallbackBeforeSetMessageReactionExtResp{CommonCallbackResp: &callbackResp}
defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeSetMessageReactionExtensionCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
}
return resp
resp := &cbapi.CallbackBeforeSetMessageReactionExtResp{}
return http.CallBackPostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg)
}
func callbackDeleteMessageReactionExtensions(setReq *msg.DeleteMessageListReactionExtensionsReq) *cb.CallbackDeleteMessageReactionExtResp {
callbackResp := cb.CommonCallbackResp{OperationID: setReq.OperationID}
log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), setReq.String())
req := cbApi.CallbackDeleteMessageReactionExtReq{
func CallbackDeleteMessageReactionExtensions(setReq *msg.DeleteMessageListReactionExtensionsReq) error {
if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
return nil
}
req := &cbapi.CallbackDeleteMessageReactionExtReq{
OperationID: setReq.OperationID,
CallbackCommand: constant.CallbackBeforeDeleteMessageReactionExtensionsCommand,
SourceID: setReq.SourceID,
@ -50,55 +47,53 @@ func callbackDeleteMessageReactionExtensions(setReq *msg.DeleteMessageListReacti
IsExternalExtensions: setReq.IsExternalExtensions,
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
}
resp := &cbApi.CallbackDeleteMessageReactionExtResp{CommonCallbackResp: &callbackResp}
resp := &cbapi.CallbackDeleteMessageReactionExtResp{}
defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackBeforeDeleteMessageReactionExtensionsCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
}
return resp
return http.CallBackPostReturn(config.Config.Callback.CallbackUrl, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg)
}
func callbackGetMessageListReactionExtensions(getReq *msg.GetMessageListReactionExtensionsReq) *cb.CallbackGetMessageListReactionExtResp {
callbackResp := cb.CommonCallbackResp{OperationID: getReq.OperationID}
log.NewDebug(getReq.OperationID, utils.GetSelfFuncName(), getReq.String())
req := cbApi.CallbackGetMessageListReactionExtReq{
OperationID: getReq.OperationID,
CallbackCommand: constant.CallbackGetMessageListReactionExtensionsCommand,
SourceID: getReq.SourceID,
OpUserID: getReq.OpUserID,
SessionType: getReq.SessionType,
TypeKeyList: getReq.TypeKeyList,
MessageKeyList: getReq.MessageReactionKeyList,
}
resp := &cbApi.CallbackGetMessageListReactionExtResp{CommonCallbackResp: &callbackResp}
defer log.NewDebug(getReq.OperationID, utils.GetSelfFuncName(), req, *resp)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackGetMessageListReactionExtensionsCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
}
return resp
}
func callbackAddMessageReactionExtensions(setReq *msg.AddMessageReactionExtensionsReq) *cb.CallbackAddMessageReactionExtResp {
callbackResp := cb.CommonCallbackResp{OperationID: setReq.OperationID}
log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), setReq.String())
req := cbApi.CallbackAddMessageReactionExtReq{
OperationID: setReq.OperationID,
CallbackCommand: constant.CallbackAddMessageListReactionExtensionsCommand,
SourceID: setReq.SourceID,
OpUserID: setReq.OpUserID,
SessionType: setReq.SessionType,
ReactionExtensionList: setReq.ReactionExtensionList,
ClientMsgID: setReq.ClientMsgID,
IsReact: setReq.IsReact,
IsExternalExtensions: setReq.IsExternalExtensions,
MsgFirstModifyTime: setReq.MsgFirstModifyTime,
}
resp := &cb.CallbackAddMessageReactionExtResp{CommonCallbackResp: &callbackResp}
defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp, *resp.CommonCallbackResp, resp.IsReact, resp.MsgFirstModifyTime)
if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAddMessageListReactionExtensionsCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
callbackResp.ErrCode = http2.StatusInternalServerError
callbackResp.ErrMsg = err.Error()
}
return resp
}
//func CallbackGetMessageListReactionExtensions(getReq *msg.GetMessageListReactionExtensionsReq) error {
// if !config.Config.Callback.CallbackAfterSendGroupMsg.Enable {
// return nil
// }
// req := cbapi.CallbackGetMessageListReactionExtReq{
// OperationID: getReq.OperationID,
// CallbackCommand: constant.CallbackGetMessageListReactionExtensionsCommand,
// SourceID: getReq.SourceID,
// OpUserID: getReq.OpUserID,
// SessionType: getReq.SessionType,
// TypeKeyList: getReq.TypeKeyList,
// MessageKeyList: getReq.MessageReactionKeyList,
// }
// resp := &cbApi.CallbackGetMessageListReactionExtResp{CommonCallbackResp: &callbackResp}
// defer log.NewDebug(getReq.OperationID, utils.GetSelfFuncName(), req, *resp)
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackGetMessageListReactionExtensionsCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// }
// return resp
//}
//func callbackAddMessageReactionExtensions(setReq *msg.AddMessageReactionExtensionsReq) *cb.CallbackAddMessageReactionExtResp {
// callbackResp := cbapi.CommonCallbackResp{OperationID: setReq.OperationID}
// log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), setReq.String())
// req := cbapi.CallbackAddMessageReactionExtReq{
// OperationID: setReq.OperationID,
// CallbackCommand: constant.CallbackAddMessageListReactionExtensionsCommand,
// SourceID: setReq.SourceID,
// OpUserID: setReq.OpUserID,
// SessionType: setReq.SessionType,
// ReactionExtensionList: setReq.ReactionExtensionList,
// ClientMsgID: setReq.ClientMsgID,
// IsReact: setReq.IsReact,
// IsExternalExtensions: setReq.IsExternalExtensions,
// MsgFirstModifyTime: setReq.MsgFirstModifyTime,
// }
// resp := &cbapi.CallbackAddMessageReactionExtResp{CommonCallbackResp: &callbackResp}
// defer log.NewDebug(setReq.OperationID, utils.GetSelfFuncName(), req, *resp, *resp.CommonCallbackResp, resp.IsReact, resp.MsgFirstModifyTime)
// if err := http.CallBackPostReturn(config.Config.Callback.CallbackUrl, constant.CallbackAddMessageListReactionExtensionsCommand, req, resp, config.Config.Callback.CallbackAfterSendGroupMsg.CallbackTimeOut); err != nil {
// callbackResp.ErrCode = http2.StatusInternalServerError
// callbackResp.ErrMsg = err.Error()
// }
// return resp
//
//}

@ -56,10 +56,14 @@ func (c CommonCallbackResp) Parse() error {
type UserStatusBaseCallback struct {
CallbackCommand string `json:"callbackCommand"`
OperationID string `json:"operationID"`
PlatformID int32 `json:"platformID"`
PlatformID int `json:"platformID"`
Platform string `json:"platform"`
}
func (c UserStatusBaseCallback) GetCallbackCommand() string {
return c.CallbackCommand
}
type UserStatusCallbackReq struct {
UserStatusBaseCallback
UserID string `json:"userID"`

@ -1,7 +1,7 @@
package callbackstruct
type CallbackBeforeAddFriendReq struct {
CallbackCommand string `json:"callbackCommand"`
CallbackCommand `json:"callbackCommand"`
FromUserID string `json:"fromUserID" `
ToUserID string `json:"toUserID"`
ReqMsg string `json:"reqMsg"`

@ -68,7 +68,7 @@ type CallbackMsgModifyCommandResp struct {
}
type CallbackBeforeSetMessageReactionExtReq struct {
OperationID string `json:"operationID"`
CallbackCommand string `json:"callbackCommand"`
CallbackCommand `json:"callbackCommand"`
SourceID string `json:"sourceID"`
OpUserID string `json:"opUserID"`
SessionType int32 `json:"sessionType"`
@ -84,8 +84,8 @@ type CallbackBeforeSetMessageReactionExtResp struct {
MsgFirstModifyTime int64 `json:"msgFirstModifyTime"`
}
type CallbackDeleteMessageReactionExtReq struct {
CallbackCommand `json:"callbackCommand"`
OperationID string `json:"operationID"`
CallbackCommand string `json:"callbackCommand"`
SourceID string `json:"sourceID"`
OpUserID string `json:"opUserID"`
SessionType int32 `json:"sessionType"`

@ -2,8 +2,8 @@ package callbackstruct
type CallbackUserOnlineReq struct {
UserStatusCallbackReq
Token string `json:"token"`
Seq int `json:"seq"`
//Token string `json:"token"`
Seq int64 `json:"seq"`
IsAppBackground bool `json:"isAppBackground"`
ConnID string `json:"connID"`
}
@ -14,7 +14,7 @@ type CallbackUserOnlineResp struct {
type CallbackUserOfflineReq struct {
UserStatusCallbackReq
Seq int `json:"seq"`
Seq int64 `json:"seq"`
ConnID string `json:"connID"`
}
@ -24,7 +24,7 @@ type CallbackUserOfflineResp struct {
type CallbackUserKickOffReq struct {
UserStatusCallbackReq
Seq int `json:"seq"`
Seq int64 `json:"seq"`
}
type CallbackUserKickOffResp struct {

@ -59,7 +59,7 @@ func Post(url string, data interface{}, timeOutSecond int) (content []byte, err
return result, nil
}
func CallBackPostReturn(url, callbackCommand string, input interface{}, output cbapi.CallbackResp, callbackConfig config.CallBackConfig) error {
func callBackPostReturn(url, callbackCommand string, input interface{}, output cbapi.CallbackResp, callbackConfig config.CallBackConfig) error {
v := urlLib.Values{}
v.Set("callbackCommand", callbackCommand)
url = url + "?" + v.Encode()
@ -79,6 +79,6 @@ func CallBackPostReturn(url, callbackCommand string, input interface{}, output c
return output.Parse()
}
func CallBackPostReturnV2(url string, req cbapi.CallbackReq, resp cbapi.CallbackResp, callbackConfig config.CallBackConfig) error {
return CallBackPostReturn(url, req.GetCallbackCommand(), req, resp, callbackConfig)
func CallBackPostReturn(url string, req cbapi.CallbackReq, resp cbapi.CallbackResp, callbackConfig config.CallBackConfig) error {
return callBackPostReturn(url, req.GetCallbackCommand(), req, resp, callbackConfig)
}

Loading…
Cancel
Save