|
|
@ -36,7 +36,7 @@ type AtContent struct {
|
|
|
|
var grpcCons []*grpc.ClientConn
|
|
|
|
var grpcCons []*grpc.ClientConn
|
|
|
|
|
|
|
|
|
|
|
|
func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
|
|
|
func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
|
|
|
var wsResult []*pbRelay.SingleMsgToUser
|
|
|
|
var wsResult []*pbRelay.SingleMsgToUserPlatform
|
|
|
|
isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush)
|
|
|
|
isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush)
|
|
|
|
log.Debug(pushMsg.OperationID, "Get msg from msg_transfer And push msg", pushMsg.String())
|
|
|
|
log.Debug(pushMsg.OperationID, "Get msg from msg_transfer And push msg", pushMsg.String())
|
|
|
|
if len(grpcCons) == 0 {
|
|
|
|
if len(grpcCons) == 0 {
|
|
|
@ -132,104 +132,104 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
var wsResult []*pbRelay.SingleMsgToUser
|
|
|
|
|
|
|
|
isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush)
|
|
|
|
|
|
|
|
log.Debug(pushMsg.OperationID, "Get msg from msg_transfer And push msg", pushMsg.String())
|
|
|
|
|
|
|
|
if len(grpcCons) == 0 {
|
|
|
|
|
|
|
|
log.NewWarn(pushMsg.OperationID, "first GetConn4Unique ")
|
|
|
|
|
|
|
|
grpcCons = getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//Online push message
|
|
|
|
|
|
|
|
log.Debug("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String())
|
|
|
|
|
|
|
|
for _, v := range grpcCons {
|
|
|
|
|
|
|
|
msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
|
|
|
|
|
|
|
reply, err := msgClient.OnlinePushMsg(context.Background(), &pbRelay.OnlinePushMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserID: pushMsg.PushToUserID})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.NewError("push data to client rpc err", pushMsg.OperationID, "err", err)
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if reply != nil && reply.Resp != nil {
|
|
|
|
|
|
|
|
wsResult = append(wsResult, reply.Resp...)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.NewInfo(pushMsg.OperationID, "push_result", wsResult, "sendData", pushMsg.MsgData)
|
|
|
|
|
|
|
|
successCount++
|
|
|
|
|
|
|
|
if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID {
|
|
|
|
|
|
|
|
for _, v := range wsResult {
|
|
|
|
|
|
|
|
if v.ResultCode == 0 {
|
|
|
|
|
|
|
|
if utils.IsContainInt32(v.RecvPlatFormID, pushTerminal) {
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if utils.IsContainInt32(v.RecvPlatFormID, pushTerminal) {
|
|
|
|
|
|
|
|
//Use offline push messaging
|
|
|
|
|
|
|
|
var UIDList []string
|
|
|
|
|
|
|
|
UIDList = append(UIDList, v.RecvID)
|
|
|
|
|
|
|
|
customContent := OpenIMContent{
|
|
|
|
|
|
|
|
SessionType: int(pushMsg.MsgData.SessionType),
|
|
|
|
|
|
|
|
From: pushMsg.MsgData.SendID,
|
|
|
|
|
|
|
|
To: pushMsg.MsgData.RecvID,
|
|
|
|
|
|
|
|
Seq: pushMsg.MsgData.Seq,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bCustomContent, _ := json.Marshal(customContent)
|
|
|
|
|
|
|
|
jsonCustomContent := string(bCustomContent)
|
|
|
|
|
|
|
|
var content string
|
|
|
|
|
|
|
|
if pushMsg.MsgData.OfflinePushInfo != nil {
|
|
|
|
|
|
|
|
content = pushMsg.MsgData.OfflinePushInfo.Title
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) {
|
|
|
|
switch pushMsg.MsgData.ContentType {
|
|
|
|
// var wsResult []*pbRelay.SingelMsgToUserResultList
|
|
|
|
case constant.Text:
|
|
|
|
// isOfflinePush := utils.GetSwitchFromOptions(pushMsg.MsgData.Options, constant.IsOfflinePush)
|
|
|
|
content = constant.ContentType2PushContent[constant.Text]
|
|
|
|
// log.Debug(pushMsg.OperationID, "Get msg from msg_transfer And push msg", pushMsg.String())
|
|
|
|
case constant.Picture:
|
|
|
|
// if len(grpcCons) == 0 {
|
|
|
|
content = constant.ContentType2PushContent[constant.Picture]
|
|
|
|
// log.NewWarn(pushMsg.OperationID, "first GetConn4Unique ")
|
|
|
|
case constant.Voice:
|
|
|
|
// grpcCons = getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
|
|
|
|
content = constant.ContentType2PushContent[constant.Voice]
|
|
|
|
// }
|
|
|
|
case constant.Video:
|
|
|
|
// //Online push message
|
|
|
|
content = constant.ContentType2PushContent[constant.Video]
|
|
|
|
// log.Debug("test", pushMsg.OperationID, "len grpc", len(grpcCons), "data", pushMsg.String())
|
|
|
|
case constant.File:
|
|
|
|
// for _, v := range grpcCons {
|
|
|
|
content = constant.ContentType2PushContent[constant.File]
|
|
|
|
// msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
|
|
|
|
case constant.AtText:
|
|
|
|
// reply, err := msgClient.OnlineBatchPushOneMsg(context.Background(), &pbRelay.OnlineBatchPushOneMsgReq{OperationID: pushMsg.OperationID, MsgData: pushMsg.MsgData, PushToUserIDList: pushMsg.PushToUserID})
|
|
|
|
a := AtContent{}
|
|
|
|
// if err != nil {
|
|
|
|
_ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
|
|
|
|
// log.NewError("push data to client rpc err", pushMsg.OperationID, "err", err)
|
|
|
|
if utils.IsContain(v.RecvID, a.AtUserList) {
|
|
|
|
// continue
|
|
|
|
content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
|
|
|
|
// }
|
|
|
|
} else {
|
|
|
|
// if reply != nil && reply.SinglePushResult != nil {
|
|
|
|
content = constant.ContentType2PushContent[constant.GroupMsg]
|
|
|
|
// wsResult = append(wsResult, reply.SinglePushResult...)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
default:
|
|
|
|
// }
|
|
|
|
content = constant.ContentType2PushContent[constant.Common]
|
|
|
|
// log.NewInfo(pushMsg.OperationID, "push_result", wsResult, "sendData", pushMsg.MsgData)
|
|
|
|
}
|
|
|
|
// successCount++
|
|
|
|
}
|
|
|
|
// if isOfflinePush && pushMsg.PushToUserID != pushMsg.MsgData.SendID {
|
|
|
|
callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList[0], pushMsg.MsgData.OfflinePushInfo, v.RecvPlatFormID)
|
|
|
|
// for _, v := range wsResult {
|
|
|
|
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
|
|
|
|
// if v.ResultCode == 0 {
|
|
|
|
if callbackResp.ErrCode != 0 {
|
|
|
|
// if utils.IsContainInt32(v.RecvPlatFormID, pushTerminal) {
|
|
|
|
log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
|
|
|
|
// break
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if callbackResp.ActionCode != constant.ActionAllow {
|
|
|
|
// continue
|
|
|
|
log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offlinePush stop")
|
|
|
|
// }
|
|
|
|
break
|
|
|
|
// if utils.IsContainInt32(v.RecvPlatFormID, pushTerminal) {
|
|
|
|
}
|
|
|
|
// //Use offline push messaging
|
|
|
|
|
|
|
|
// var UIDList []string
|
|
|
|
if offlinePusher == nil {
|
|
|
|
// UIDList = append(UIDList, v.RecvID)
|
|
|
|
offlinePusher = jpush.JPushClient
|
|
|
|
// customContent := OpenIMContent{
|
|
|
|
}
|
|
|
|
// SessionType: int(pushMsg.MsgData.SessionType),
|
|
|
|
pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID)
|
|
|
|
// From: pushMsg.MsgData.SendID,
|
|
|
|
if err != nil {
|
|
|
|
// To: pushMsg.MsgData.RecvID,
|
|
|
|
log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
|
|
|
|
// Seq: pushMsg.MsgData.Seq,
|
|
|
|
} else {
|
|
|
|
// }
|
|
|
|
log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData)
|
|
|
|
// bCustomContent, _ := json.Marshal(customContent)
|
|
|
|
}
|
|
|
|
// jsonCustomContent := string(bCustomContent)
|
|
|
|
break
|
|
|
|
// var content string
|
|
|
|
}
|
|
|
|
// if pushMsg.MsgData.OfflinePushInfo != nil {
|
|
|
|
|
|
|
|
// content = pushMsg.MsgData.OfflinePushInfo.Title
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
}
|
|
|
|
// switch pushMsg.MsgData.ContentType {
|
|
|
|
}
|
|
|
|
// case constant.Text:
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.Text]
|
|
|
|
|
|
|
|
// case constant.Picture:
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.Picture]
|
|
|
|
|
|
|
|
// case constant.Voice:
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.Voice]
|
|
|
|
|
|
|
|
// case constant.Video:
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.Video]
|
|
|
|
|
|
|
|
// case constant.File:
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.File]
|
|
|
|
|
|
|
|
// case constant.AtText:
|
|
|
|
|
|
|
|
// a := AtContent{}
|
|
|
|
|
|
|
|
// _ = utils.JsonStringToStruct(string(pushMsg.MsgData.Content), &a)
|
|
|
|
|
|
|
|
// if utils.IsContain(v.RecvID, a.AtUserList) {
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.AtText] + constant.ContentType2PushContent[constant.Common]
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.GroupMsg]
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// default:
|
|
|
|
|
|
|
|
// content = constant.ContentType2PushContent[constant.Common]
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// callbackResp := callbackOfflinePush(pushMsg.OperationID, UIDList[0], pushMsg.MsgData.OfflinePushInfo, v.RecvPlatFormID)
|
|
|
|
|
|
|
|
// log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline callback Resp")
|
|
|
|
|
|
|
|
// if callbackResp.ErrCode != 0 {
|
|
|
|
|
|
|
|
// log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "callbackOfflinePush result: ", callbackResp)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if callbackResp.ActionCode != constant.ActionAllow {
|
|
|
|
|
|
|
|
// log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offlinePush stop")
|
|
|
|
|
|
|
|
// break
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if offlinePusher == nil {
|
|
|
|
|
|
|
|
// offlinePusher = jpush.JPushClient
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID)
|
|
|
|
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// log.NewError(pushMsg.OperationID, "offline push error", pushMsg.String(), err.Error())
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// log.NewDebug(pushMsg.OperationID, "offline push return result is ", pushResult, pushMsg.MsgData)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// break
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//func SendMsgByWS(m *pbChat.WSToMsgSvrChatMsg) {
|
|
|
|
//func SendMsgByWS(m *pbChat.WSToMsgSvrChatMsg) {
|
|
|
|
// m.MsgID = rpcChat.GetMsgID(m.SendID)
|
|
|
|
// m.MsgID = rpcChat.GetMsgID(m.SendID)
|
|
|
|