From 473c956b1b057b8e6fe50f8bd6d038f488048008 Mon Sep 17 00:00:00 2001 From: away <1819625428@qq.com> Date: Mon, 28 Jun 2021 19:23:43 +0800 Subject: [PATCH] msg update --- src/msg_transfer/logic/db.go | 2 +- src/msg_transfer/logic/history_msg_handler.go | 61 +++++-------------- 2 files changed, 16 insertions(+), 47 deletions(-) diff --git a/src/msg_transfer/logic/db.go b/src/msg_transfer/logic/db.go index 99aa11474..93dccfc2b 100644 --- a/src/msg_transfer/logic/db.go +++ b/src/msg_transfer/logic/db.go @@ -12,7 +12,7 @@ func saveUserChat(uid string, pbMsg *pbMsg.MsgSvrToPushSvrChatMsg) error { return err } pbMsg.RecvSeq = seq - return db.DB.SaveUserChat(uid, pbMsg) + return db.DB.SaveUserChat(uid, pbMsg.SendTime, pbMsg) } func getGroupList(groupID string) ([]string, error) { diff --git a/src/msg_transfer/logic/history_msg_handler.go b/src/msg_transfer/logic/history_msg_handler.go index 827b89481..8ef4098ce 100644 --- a/src/msg_transfer/logic/history_msg_handler.go +++ b/src/msg_transfer/logic/history_msg_handler.go @@ -6,7 +6,6 @@ import ( kfk "Open_IM/src/common/kafka" "Open_IM/src/common/log" pbMsg "Open_IM/src/proto/chat" - pb "Open_IM/src/proto/group" pbPush "Open_IM/src/proto/push" "Open_IM/src/utils" "context" @@ -55,10 +54,8 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) isHistory := utils.GetSwitchFromOptions(Options, "history") //Control whether to store history messages (mysql) isPersist := utils.GetSwitchFromOptions(Options, "persistent") - //Control whether to push message to sender's other terminal - isSenderSync := utils.GetSwitchFromOptions(Options, "senderSync") if pbData.SessionType == constant.SingleChatType { - log.Info("", "", "msg_transfer chat type = SingleChatType", isHistory, isPersist, isSenderSync) + log.Info("", "", "msg_transfer chat type = SingleChatType", isHistory, isPersist) if isHistory { if msgKey == pbSaveData.RecvID { err := saveUserChat(pbData.RecvID, &pbSaveData) @@ -73,58 +70,30 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string) if err != nil { log.ErrorByKv("data insert to mongo err", pbSaveData.OperationID, "data", pbSaveData.String(), "err", err.Error()) } - if isSenderSync { - pbSaveData.ContentType = constant.SyncSenderMsg - log.WarnByKv("SyncSenderMsg come here", pbData.OperationID, pbSaveData.String()) - sendMessageToPush(&pbSaveData) - } + //if isSenderSync { + // pbSaveData.ContentType = constant.SyncSenderMsg + // log.WarnByKv("SyncSenderMsg come here", pbData.OperationID, pbSaveData.String()) + // sendMessageToPush(&pbSaveData) + //} } } + log.InfoByKv("msg_transfer handle topic success...", "", "") } else if pbData.SessionType == constant.GroupChatType { log.Info("", "", "msg_transfer chat type = GroupChatType") - - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName) - client := pb.NewGroupClient(etcdConn) - req := &pb.GetGroupInfoReq{ - GroupID: pbSaveData.RecvID, - Token: pbData.Token, - OperationID: pbSaveData.OperationID, - } - log.Info("", "", "msg_transfer call group rpc, data = %s", req.String()) - reply, err := client.GetGroupInfo(context.Background(), req) - if err != nil { - log.Error("", "", "msg_transfer client.GetGroupInfo fail, err = %s", err.Error()) - return + uidAndGroupID := strings.Split(pbData.RecvID, " ") + saveUserChat(uidAndGroupID[0], &pbSaveData) + pbSaveData.Options = pbData.Options + pbSaveData.OfflineInfo = pbData.OfflineInfo + if utils.IsContain(uidAndGroupID[0], pbData.ForceList) { + pbSaveData.IsEmphasize = true } - for _, v := range reply.GroupMemberList { - //Store RecvID is userID+" "+groupID when chatType is Group - pbSaveData.RecvID = v.UserID + " " + pbSaveData.RecvID - if isHistory { - saveUserChat(v.UserID, &pbSaveData) - } - pbSaveData.Options = pbData.Options - pbSaveData.OfflineInfo = pbData.OfflineInfo - if v.UserID != pbSaveData.SendID { - if utils.IsContain(v.UserID, pbData.ForceList) { - pbSaveData.IsEmphasize = true - } - sendMessageToPush(&pbSaveData) - } else { - if isSenderSync { - pbSaveData.ContentType = constant.SyncSenderMsg - sendMessageToPush(&pbSaveData) - } - - } - - } - + sendMessageToPush(&pbSaveData) + log.InfoByKv("msg_transfer handle topic success...", "", "") } else { log.Error("", "", "msg_transfer recv chat err, chat.MsgFrom = %d", pbData.SessionType) } - log.InfoByKv("msg_transfer handle topic success...", "", "") } func (HistoryConsumerHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }