mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-18 15:59:01 +08:00
change send message by ws and optimization
This commit is contained in:
@@ -41,7 +41,7 @@ func (rpc *rpcChat) PullMessage(_ context.Context, in *pbMsg.PullMessageReq) (*p
|
||||
resp := new(pbMsg.PullMessageResp)
|
||||
var respSingleMsgFormat []*pbMsg.GatherFormat
|
||||
var respGroupMsgFormat []*pbMsg.GatherFormat
|
||||
SingleMsgFormat, GroupMsgFormat, MaxSeq, MinSeq, err := commonDB.DB.GetUserChat(in.UserID, in.SeqBegin, in.SeqEnd)
|
||||
SingleMsgFormat, GroupMsgFormat, MaxSeq, MinSeq, err := commonDB.DB.GetMsgBySeqRange(in.UserID, in.SeqBegin, in.SeqEnd)
|
||||
if err != nil {
|
||||
log.ErrorByKv("pullMsg data error", in.OperationID, in.String())
|
||||
resp.ErrCode = 1
|
||||
@@ -59,6 +59,30 @@ func (rpc *rpcChat) PullMessage(_ context.Context, in *pbMsg.PullMessageReq) (*p
|
||||
GroupUserMsg: respGroupMsgFormat,
|
||||
}, nil
|
||||
}
|
||||
func (rpc *rpcChat) PullMessageBySeqList(_ context.Context, in *pbMsg.PullMessageBySeqListReq) (*pbMsg.PullMessageResp, error) {
|
||||
log.NewInfo(in.OperationID, "rpc PullMessageBySeqList is arriving", in.String())
|
||||
resp := new(pbMsg.PullMessageResp)
|
||||
var respSingleMsgFormat []*pbMsg.GatherFormat
|
||||
var respGroupMsgFormat []*pbMsg.GatherFormat
|
||||
SingleMsgFormat, GroupMsgFormat, MaxSeq, MinSeq, err := commonDB.DB.GetMsgBySeqList(in.UserID, in.SeqList)
|
||||
if err != nil {
|
||||
log.ErrorByKv("PullMessageBySeqList data error", in.OperationID, in.String())
|
||||
resp.ErrCode = 1
|
||||
resp.ErrMsg = err.Error()
|
||||
return resp, nil
|
||||
}
|
||||
respSingleMsgFormat = singleMsgHandleByUser(SingleMsgFormat, in.UserID)
|
||||
respGroupMsgFormat = groupMsgHandleByUser(GroupMsgFormat)
|
||||
return &pbMsg.PullMessageResp{
|
||||
ErrCode: 0,
|
||||
ErrMsg: "",
|
||||
MaxSeq: MaxSeq,
|
||||
MinSeq: MinSeq,
|
||||
SingleUserMsg: respSingleMsgFormat,
|
||||
GroupUserMsg: respGroupMsgFormat,
|
||||
}, nil
|
||||
panic("implement me")
|
||||
}
|
||||
func singleMsgHandleByUser(allMsg []*pbMsg.MsgFormat, ownerId string) []*pbMsg.GatherFormat {
|
||||
var userid string
|
||||
var respMsgFormat []*pbMsg.GatherFormat
|
||||
|
||||
@@ -43,9 +43,11 @@ type MsgCallBackResp struct {
|
||||
func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*pbChat.UserSendMsgResp, error) {
|
||||
replay := pbChat.UserSendMsgResp{}
|
||||
log.InfoByKv("sendMsg", pb.OperationID, "args", pb.String())
|
||||
time := utils.GetCurrentTimestampByMill()
|
||||
if !utils.VerifyToken(pb.Token, pb.SendID) {
|
||||
return returnMsg(&replay, pb, http.StatusUnauthorized, "token validate err,not authorized", "", 0)
|
||||
}
|
||||
log.NewInfo(pb.OperationID, "VerifyToken cost time ", utils.GetCurrentTimestampByMill()-time)
|
||||
serverMsgID := GetMsgID(pb.SendID)
|
||||
pbData := pbChat.WSToMsgSvrChatMsg{}
|
||||
pbData.MsgFrom = pb.MsgFrom
|
||||
@@ -64,7 +66,7 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*
|
||||
pbData.MsgID = serverMsgID
|
||||
pbData.OperationID = pb.OperationID
|
||||
pbData.Token = pb.Token
|
||||
pbData.SendTime = utils.GetCurrentTimestampByNano()
|
||||
pbData.SendTime = pb.SendTime
|
||||
m := MsgCallBackResp{}
|
||||
if config.Config.MessageCallBack.CallbackSwitch {
|
||||
bMsg, err := http2.Post(config.Config.MessageCallBack.CallbackUrl, MsgCallBackReq{
|
||||
@@ -88,85 +90,79 @@ func (rpc *rpcChat) UserSendMsg(_ context.Context, pb *pbChat.UserSendMsgReq) (*
|
||||
return returnMsg(&replay, pb, m.ResponseErrCode, m.ErrMsg, "", 0)
|
||||
} else {
|
||||
pbData.Content = m.ResponseResult.ModifiedMsg
|
||||
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
||||
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
||||
if err1 != nil || err2 != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch pbData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
||||
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
||||
if err1 != nil || err2 != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
case constant.GroupChatType:
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
req := &pbGroup.GetGroupAllMemberReq{
|
||||
GroupID: pbData.RecvID,
|
||||
Token: pbData.Token,
|
||||
OperationID: pbData.OperationID,
|
||||
}
|
||||
reply, err := client.GetGroupAllMember(context.Background(), req)
|
||||
}
|
||||
switch pbData.SessionType {
|
||||
case constant.SingleChatType:
|
||||
time := utils.GetCurrentTimestampByMill()
|
||||
err1 := rpc.sendMsgToKafka(&pbData, pbData.RecvID)
|
||||
err2 := rpc.sendMsgToKafka(&pbData, pbData.SendID)
|
||||
log.NewInfo(pb.OperationID, "send kafka cost time ", utils.GetCurrentTimestampByMill()-time)
|
||||
if err1 != nil || err2 != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
case constant.GroupChatType:
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
|
||||
client := pbGroup.NewGroupClient(etcdConn)
|
||||
req := &pbGroup.GetGroupAllMemberReq{
|
||||
GroupID: pbData.RecvID,
|
||||
Token: pbData.Token,
|
||||
OperationID: pbData.OperationID,
|
||||
}
|
||||
reply, err := client.GetGroupAllMember(context.Background(), req)
|
||||
if err != nil {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", err.Error())
|
||||
return returnMsg(&replay, pb, 201, err.Error(), "", 0)
|
||||
}
|
||||
if reply.ErrorCode != 0 {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrorMsg)
|
||||
return returnMsg(&replay, pb, reply.ErrorCode, reply.ErrorMsg, "", 0)
|
||||
}
|
||||
var addUidList []string
|
||||
switch pbData.ContentType {
|
||||
case constant.KickGroupMemberTip:
|
||||
var notification content_struct.NotificationContent
|
||||
var kickContent group.KickGroupMemberReq
|
||||
err := utils.JsonStringToStruct(pbData.Content, ¬ification)
|
||||
if err != nil {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", err.Error())
|
||||
return returnMsg(&replay, pb, 201, err.Error(), "", 0)
|
||||
}
|
||||
if reply.ErrorCode != 0 {
|
||||
log.Error(pbData.Token, pbData.OperationID, "rpc send_msg getGroupInfo failed, err = %s", reply.ErrorMsg)
|
||||
return returnMsg(&replay, pb, reply.ErrorCode, reply.ErrorMsg, "", 0)
|
||||
}
|
||||
var addUidList []string
|
||||
switch pbData.ContentType {
|
||||
case constant.KickGroupMemberTip:
|
||||
var notification content_struct.NotificationContent
|
||||
var kickContent group.KickGroupMemberReq
|
||||
err := utils.JsonStringToStruct(pbData.Content, ¬ification)
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
err := utils.JsonStringToStruct(notification.Detail, &kickContent)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
} else {
|
||||
err := utils.JsonStringToStruct(notification.Detail, &kickContent)
|
||||
if err != nil {
|
||||
log.ErrorByKv("json unmarshall err", pbData.OperationID, "err", err.Error())
|
||||
return returnMsg(&replay, pb, 200, err.Error(), "", 0)
|
||||
}
|
||||
for _, v := range kickContent.UidListInfo {
|
||||
addUidList = append(addUidList, v.UserId)
|
||||
}
|
||||
}
|
||||
case constant.QuitGroupTip:
|
||||
addUidList = append(addUidList, pbData.SendID)
|
||||
default:
|
||||
}
|
||||
groupID := pbData.RecvID
|
||||
for i, v := range reply.MemberList {
|
||||
pbData.RecvID = v.UserId + " " + groupID
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i))
|
||||
if err != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
for _, v := range kickContent.UidListInfo {
|
||||
addUidList = append(addUidList, v.UserId)
|
||||
}
|
||||
}
|
||||
for i, v := range addUidList {
|
||||
pbData.RecvID = v + " " + groupID
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i+1))
|
||||
if err != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
case constant.QuitGroupTip:
|
||||
addUidList = append(addUidList, pbData.SendID)
|
||||
default:
|
||||
|
||||
}
|
||||
groupID := pbData.RecvID
|
||||
for i, v := range reply.MemberList {
|
||||
pbData.RecvID = v.UserId + " " + groupID
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i))
|
||||
if err != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
for i, v := range addUidList {
|
||||
pbData.RecvID = v + " " + groupID
|
||||
err := rpc.sendMsgToKafka(&pbData, utils.IntToString(i+1))
|
||||
if err != nil {
|
||||
return returnMsg(&replay, pb, 201, "kafka send msg err", "", 0)
|
||||
}
|
||||
}
|
||||
return returnMsg(&replay, pb, 0, "", serverMsgID, pbData.SendTime)
|
||||
default:
|
||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||
|
||||
}
|
||||
return returnMsg(&replay, pb, 203, "unkonwn sessionType", "", 0)
|
||||
|
||||
}
|
||||
func (rpc *rpcChat) sendMsgToKafka(m *pbChat.WSToMsgSvrChatMsg, key string) error {
|
||||
@@ -186,6 +182,5 @@ func returnMsg(replay *pbChat.UserSendMsgResp, pb *pbChat.UserSendMsgReq, errCod
|
||||
replay.ReqIdentifier = pb.ReqIdentifier
|
||||
replay.ClientMsgID = pb.ClientMsgID
|
||||
replay.ServerMsgID = serverMsgID
|
||||
replay.SendTime = sendTime
|
||||
return replay, nil
|
||||
}
|
||||
|
||||
@@ -70,6 +70,12 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
groupInfoFromMysql, err := imdb.FindGroupInfoByGroupId(req.GroupID)
|
||||
if err != nil || groupInfoFromMysql == nil {
|
||||
log.NewError(req.OperationID, "get group info error", req.GroupID, req.UidList)
|
||||
return &pbGroup.InviteUserToGroupResp{ErrorCode: config.ErrAccess.ErrCode, ErrorMsg: config.ErrAccess.ErrMsg}, nil
|
||||
}
|
||||
|
||||
//
|
||||
//from User: invite: applicant
|
||||
//to user: invite: invited
|
||||
|
||||
Reference in New Issue
Block a user