|
|
|
@ -146,7 +146,7 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
// return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
|
|
|
|
|
rpc.encapsulateMsgData(pb.MsgData)
|
|
|
|
|
log.Info("", "this is a test MsgData ", pb.MsgData)
|
|
|
|
|
msgToMQ := pbChat.MsgDataToMQ{Token: pb.Token, OperationID: pb.OperationID, MsgData: pb.MsgData}
|
|
|
|
|
msgToMQSingle := pbChat.MsgDataToMQ{Token: pb.Token, OperationID: pb.OperationID, MsgData: pb.MsgData}
|
|
|
|
|
//options := utils.JsonStringToMap(pbData.Options)
|
|
|
|
|
isHistory := utils.GetSwitchFromOptions(pb.MsgData.Options, constant.IsHistory)
|
|
|
|
|
mReq := MsgCallBackReq{
|
|
|
|
@ -186,18 +186,18 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
}
|
|
|
|
|
isSend := modifyMessageByUserMessageReceiveOpt(pb.MsgData.RecvID, pb.MsgData.SendID, constant.SingleChatType, pb)
|
|
|
|
|
if isSend {
|
|
|
|
|
msgToMQ.MsgData = pb.MsgData
|
|
|
|
|
log.NewInfo(msgToMQ.OperationID, msgToMQ)
|
|
|
|
|
err1 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.RecvID)
|
|
|
|
|
msgToMQSingle.MsgData = pb.MsgData
|
|
|
|
|
log.NewInfo(msgToMQSingle.OperationID, msgToMQSingle)
|
|
|
|
|
err1 := rpc.sendMsgToKafka(&msgToMQSingle, msgToMQSingle.MsgData.RecvID)
|
|
|
|
|
if err1 != nil {
|
|
|
|
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:RecvID", msgToMQ.MsgData.RecvID, msgToMQ.String())
|
|
|
|
|
log.NewError(msgToMQSingle.OperationID, "kafka send msg err:RecvID", msgToMQSingle.MsgData.RecvID, msgToMQSingle.String())
|
|
|
|
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if msgToMQ.MsgData.SendID != msgToMQ.MsgData.RecvID { //Filter messages sent to yourself
|
|
|
|
|
err2 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.SendID)
|
|
|
|
|
if msgToMQSingle.MsgData.SendID != msgToMQSingle.MsgData.RecvID { //Filter messages sent to yourself
|
|
|
|
|
err2 := rpc.sendMsgToKafka(&msgToMQSingle, msgToMQSingle.MsgData.SendID)
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:SendID", msgToMQ.MsgData.SendID, msgToMQ.String())
|
|
|
|
|
log.NewError(msgToMQSingle.OperationID, "kafka send msg err:SendID", msgToMQSingle.MsgData.SendID, msgToMQSingle.String())
|
|
|
|
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -205,7 +205,7 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
if err := callbackAfterSendSingleMsg(pb); err != nil {
|
|
|
|
|
log.NewError(pb.OperationID, utils.GetSelfFuncName(), "callbackAfterSendSingleMsg failed", err.Error())
|
|
|
|
|
}
|
|
|
|
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
|
|
|
|
return returnMsg(&replay, pb, 0, "", msgToMQSingle.MsgData.ServerMsgID, msgToMQSingle.MsgData.SendTime)
|
|
|
|
|
case constant.GroupChatType:
|
|
|
|
|
// callback
|
|
|
|
|
canSend, err := callbackBeforeSendGroupMsg(pb)
|
|
|
|
@ -237,6 +237,7 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}(reply.MemberList)
|
|
|
|
|
log.Debug(pb.OperationID, "GetGroupAllMember userID list", memberUserIDList)
|
|
|
|
|
var addUidList []string
|
|
|
|
|
switch pb.MsgData.ContentType {
|
|
|
|
|
case constant.MemberKickedNotification:
|
|
|
|
@ -268,17 +269,25 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
for i := 0; i < len(memberUserIDList)/split; i++ {
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
go func(list []string) {
|
|
|
|
|
// log.Debug(pb.OperationID, "split userID ", list)
|
|
|
|
|
groupPB := pbChat.SendMsgReq{Token: pb.Token, OperationID: pb.OperationID, MsgData: &sdk_ws.MsgData{OfflinePushInfo: &sdk_ws.OfflinePushInfo{}}}
|
|
|
|
|
*groupPB.MsgData = *pb.MsgData
|
|
|
|
|
*groupPB.MsgData.OfflinePushInfo = *pb.MsgData.OfflinePushInfo
|
|
|
|
|
msgToMQGroup := pbChat.MsgDataToMQ{Token: groupPB.Token, OperationID: groupPB.OperationID, MsgData: groupPB.MsgData}
|
|
|
|
|
for _, v := range list {
|
|
|
|
|
pb.MsgData.RecvID = v
|
|
|
|
|
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, pb)
|
|
|
|
|
groupPB.MsgData.RecvID = v
|
|
|
|
|
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, &groupPB)
|
|
|
|
|
if isSend {
|
|
|
|
|
msgToMQ.MsgData = pb.MsgData
|
|
|
|
|
err := rpc.sendMsgToKafka(&msgToMQ, v)
|
|
|
|
|
msgToMQGroup.MsgData = groupPB.MsgData
|
|
|
|
|
// log.Debug(groupPB.OperationID, "sendMsgToKafka, ", v, groupID, msgToMQGroup.String())
|
|
|
|
|
err := rpc.sendMsgToKafka(&msgToMQGroup, v)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v, msgToMQ.String())
|
|
|
|
|
log.NewError(msgToMQGroup.OperationID, "kafka send msg err:UserId", v, msgToMQGroup.String())
|
|
|
|
|
} else {
|
|
|
|
|
sendTag = true
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.Debug(groupPB.OperationID, "not sendMsgToKafka, ", v)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wg.Done()
|
|
|
|
@ -287,17 +296,25 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
if remain > 0 {
|
|
|
|
|
wg.Add(1)
|
|
|
|
|
go func(list []string) {
|
|
|
|
|
// log.Debug(pb.OperationID, "split userID ", list)
|
|
|
|
|
groupPB := pbChat.SendMsgReq{Token: pb.Token, OperationID: pb.OperationID, MsgData: &sdk_ws.MsgData{OfflinePushInfo: &sdk_ws.OfflinePushInfo{}}}
|
|
|
|
|
*groupPB.MsgData = *pb.MsgData
|
|
|
|
|
*groupPB.MsgData.OfflinePushInfo = *pb.MsgData.OfflinePushInfo
|
|
|
|
|
msgToMQGroup := pbChat.MsgDataToMQ{Token: groupPB.Token, OperationID: groupPB.OperationID, MsgData: groupPB.MsgData}
|
|
|
|
|
for _, v := range list {
|
|
|
|
|
pb.MsgData.RecvID = v
|
|
|
|
|
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, pb)
|
|
|
|
|
groupPB.MsgData.RecvID = v
|
|
|
|
|
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, &groupPB)
|
|
|
|
|
if isSend {
|
|
|
|
|
msgToMQ.MsgData = pb.MsgData
|
|
|
|
|
err := rpc.sendMsgToKafka(&msgToMQ, v)
|
|
|
|
|
msgToMQGroup.MsgData = groupPB.MsgData
|
|
|
|
|
// log.Debug(groupPB.OperationID, "sendMsgToKafka, ", v, groupID, msgToMQGroup.String())
|
|
|
|
|
err := rpc.sendMsgToKafka(&msgToMQGroup, v)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v, msgToMQ.String())
|
|
|
|
|
log.NewError(msgToMQGroup.OperationID, "kafka send msg err:UserId", v, msgToMQGroup.String())
|
|
|
|
|
} else {
|
|
|
|
|
sendTag = true
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.Debug(groupPB.OperationID, "not sendMsgToKafka, ", v)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wg.Done()
|
|
|
|
@ -305,16 +322,16 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
}
|
|
|
|
|
wg.Wait()
|
|
|
|
|
|
|
|
|
|
log.Info(msgToMQ.OperationID, "addUidList", addUidList)
|
|
|
|
|
log.Info(msgToMQSingle.OperationID, "addUidList", addUidList)
|
|
|
|
|
for _, v := range addUidList {
|
|
|
|
|
pb.MsgData.RecvID = v
|
|
|
|
|
isSend := modifyMessageByUserMessageReceiveOpt(v, groupID, constant.GroupChatType, pb)
|
|
|
|
|
log.Info(msgToMQ.OperationID, "isSend", isSend)
|
|
|
|
|
log.Info(msgToMQSingle.OperationID, "isSend", isSend)
|
|
|
|
|
if isSend {
|
|
|
|
|
msgToMQ.MsgData = pb.MsgData
|
|
|
|
|
err := rpc.sendMsgToKafka(&msgToMQ, v)
|
|
|
|
|
msgToMQSingle.MsgData = pb.MsgData
|
|
|
|
|
err := rpc.sendMsgToKafka(&msgToMQSingle, v)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:UserId", v, msgToMQ.String())
|
|
|
|
|
log.NewError(msgToMQSingle.OperationID, "kafka send msg err:UserId", v, msgToMQSingle.String())
|
|
|
|
|
} else {
|
|
|
|
|
sendTag = true
|
|
|
|
|
}
|
|
|
|
@ -378,26 +395,26 @@ func (rpc *rpcChat) SendMsg(_ context.Context, pb *pbChat.SendMsgReq) (*pbChat.S
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
|
|
|
|
return returnMsg(&replay, pb, 0, "", msgToMQSingle.MsgData.ServerMsgID, msgToMQSingle.MsgData.SendTime)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
case constant.NotificationChatType:
|
|
|
|
|
msgToMQ.MsgData = pb.MsgData
|
|
|
|
|
log.NewInfo(msgToMQ.OperationID, msgToMQ)
|
|
|
|
|
err1 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.RecvID)
|
|
|
|
|
msgToMQSingle.MsgData = pb.MsgData
|
|
|
|
|
log.NewInfo(msgToMQSingle.OperationID, msgToMQSingle)
|
|
|
|
|
err1 := rpc.sendMsgToKafka(&msgToMQSingle, msgToMQSingle.MsgData.RecvID)
|
|
|
|
|
if err1 != nil {
|
|
|
|
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:RecvID", msgToMQ.MsgData.RecvID, msgToMQ.String())
|
|
|
|
|
log.NewError(msgToMQSingle.OperationID, "kafka send msg err:RecvID", msgToMQSingle.MsgData.RecvID, msgToMQSingle.String())
|
|
|
|
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if msgToMQ.MsgData.SendID != msgToMQ.MsgData.RecvID { //Filter messages sent to yourself
|
|
|
|
|
err2 := rpc.sendMsgToKafka(&msgToMQ, msgToMQ.MsgData.SendID)
|
|
|
|
|
if msgToMQSingle.MsgData.SendID != msgToMQSingle.MsgData.RecvID { //Filter messages sent to yourself
|
|
|
|
|
err2 := rpc.sendMsgToKafka(&msgToMQSingle, msgToMQSingle.MsgData.SendID)
|
|
|
|
|
if err2 != nil {
|
|
|
|
|
log.NewError(msgToMQ.OperationID, "kafka send msg err:SendID", msgToMQ.MsgData.SendID, msgToMQ.String())
|
|
|
|
|
log.NewError(msgToMQSingle.OperationID, "kafka send msg err:SendID", msgToMQSingle.MsgData.SendID, msgToMQSingle.String())
|
|
|
|
|
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return returnMsg(&replay, pb, 0, "", msgToMQ.MsgData.ServerMsgID, msgToMQ.MsgData.SendTime)
|
|
|
|
|
return returnMsg(&replay, pb, 0, "", msgToMQSingle.MsgData.ServerMsgID, msgToMQSingle.MsgData.SendTime)
|
|
|
|
|
default:
|
|
|
|
|
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
|
|
|
|
}
|
|
|
|
|