Revert "update"

This reverts commit 185c2204
pull/4/head
away 3 years ago
parent 185c220429
commit 36d1585609

@ -12,7 +12,7 @@ func saveUserChat(uid string, pbMsg *pbMsg.MsgSvrToPushSvrChatMsg) error {
return err return err
} }
pbMsg.RecvSeq = seq pbMsg.RecvSeq = seq
return db.DB.SaveUserChat(uid, pbMsg.SendTime, pbMsg) return db.DB.SaveUserChat(uid, pbMsg)
} }
func getGroupList(groupID string) ([]string, error) { func getGroupList(groupID string) ([]string, error) {

@ -6,6 +6,7 @@ import (
kfk "Open_IM/src/common/kafka" kfk "Open_IM/src/common/kafka"
"Open_IM/src/common/log" "Open_IM/src/common/log"
pbMsg "Open_IM/src/proto/chat" pbMsg "Open_IM/src/proto/chat"
pb "Open_IM/src/proto/group"
pbPush "Open_IM/src/proto/push" pbPush "Open_IM/src/proto/push"
"Open_IM/src/utils" "Open_IM/src/utils"
"context" "context"
@ -54,8 +55,10 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
isHistory := utils.GetSwitchFromOptions(Options, "history") isHistory := utils.GetSwitchFromOptions(Options, "history")
//Control whether to store history messages (mysql) //Control whether to store history messages (mysql)
isPersist := utils.GetSwitchFromOptions(Options, "persistent") 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 { if pbData.SessionType == constant.SingleChatType {
log.Info("", "", "msg_transfer chat type = SingleChatType", isHistory, isPersist) log.Info("", "", "msg_transfer chat type = SingleChatType", isHistory, isPersist, isSenderSync)
if isHistory { if isHistory {
if msgKey == pbSaveData.RecvID { if msgKey == pbSaveData.RecvID {
err := saveUserChat(pbData.RecvID, &pbSaveData) err := saveUserChat(pbData.RecvID, &pbSaveData)
@ -70,30 +73,58 @@ func (mc *HistoryConsumerHandler) handleChatWs2Mongo(msg []byte, msgKey string)
if err != nil { if err != nil {
log.ErrorByKv("data insert to mongo err", pbSaveData.OperationID, "data", pbSaveData.String(), "err", err.Error()) log.ErrorByKv("data insert to mongo err", pbSaveData.OperationID, "data", pbSaveData.String(), "err", err.Error())
} }
//if isSenderSync { if isSenderSync {
// pbSaveData.ContentType = constant.SyncSenderMsg pbSaveData.ContentType = constant.SyncSenderMsg
// log.WarnByKv("SyncSenderMsg come here", pbData.OperationID, pbSaveData.String()) log.WarnByKv("SyncSenderMsg come here", pbData.OperationID, pbSaveData.String())
// sendMessageToPush(&pbSaveData) sendMessageToPush(&pbSaveData)
//} }
} }
} }
log.InfoByKv("msg_transfer handle topic success...", "", "")
} else if pbData.SessionType == constant.GroupChatType { } else if pbData.SessionType == constant.GroupChatType {
log.Info("", "", "msg_transfer chat type = GroupChatType") log.Info("", "", "msg_transfer chat type = GroupChatType")
uidAndGroupID := strings.Split(pbData.RecvID, " ")
saveUserChat(uidAndGroupID[0], &pbSaveData) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName)
pbSaveData.Options = pbData.Options client := pb.NewGroupClient(etcdConn)
pbSaveData.OfflineInfo = pbData.OfflineInfo req := &pb.GetGroupInfoReq{
if utils.IsContain(uidAndGroupID[0], pbData.ForceList) { GroupID: pbSaveData.RecvID,
pbSaveData.IsEmphasize = true 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
} }
sendMessageToPush(&pbSaveData) for _, v := range reply.GroupMemberList {
log.InfoByKv("msg_transfer handle topic success...", "", "") //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)
}
}
}
} else { } else {
log.Error("", "", "msg_transfer recv chat err, chat.MsgFrom = %d", pbData.SessionType) 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 } func (HistoryConsumerHandler) Setup(_ sarama.ConsumerGroupSession) error { return nil }

@ -6,9 +6,7 @@
*/ */
package content_struct package content_struct
import ( import "encoding/json"
"encoding/json"
)
type Content struct { type Content struct {
IsDisplay int32 `json:"isDisplay"` IsDisplay int32 `json:"isDisplay"`
@ -25,36 +23,3 @@ func (c *Content) contentToString() string {
dataString := string(data) dataString := string(data)
return dataString return dataString
} }
type groupMemberFullInfo struct {
GroupId string `json:"groupID"`
UserId string `json:"userId"`
Role int `json:"role"`
JoinTime uint64 `json:"joinTime"`
NickName string `json:"nickName"`
FaceUrl string `json:"faceUrl"`
}
type AgreeOrRejectGroupMember struct {
GroupId string `json:"groupID"`
UserId string `json:"userId"`
Role int `json:"role"`
JoinTime uint64 `json:"joinTime"`
NickName string `json:"nickName"`
FaceUrl string `json:"faceUrl"`
Reason string `json:"reason"`
}
type CreateGroupSysMsg struct {
uIdCreator string `creatorUid`
initMemberList []groupMemberFullInfo `json: initMemberList`
CreateTime uint64 `json:"CreateTime"`
Text string `json:"text"`
}
func NewCreateGroupSysMsgString(create *CreateGroupSysMsg, text string) string {
create.Text = text
jstring, _ := json.Marshal(create)
return string(jstring)
}

@ -8,9 +8,12 @@ package logic
import ( import (
"Open_IM/src/common/config" "Open_IM/src/common/config"
"Open_IM/src/common/db"
"Open_IM/src/common/db/mysql_model/im_mysql_model"
"Open_IM/src/common/kafka" "Open_IM/src/common/kafka"
"Open_IM/src/common/log" "Open_IM/src/common/log"
"Open_IM/src/utils" "Open_IM/src/utils"
"time"
) )
var ( var (
@ -32,5 +35,32 @@ func init() {
func Run() { func Run() {
go rpcServer.run() go rpcServer.run()
go scheduleDelete()
go pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&pushCh) go pushCh.pushConsumerGroup.RegisterHandleAndConsumer(&pushCh)
} }
func scheduleDelete() {
//uid, _ := im_mysql_model.SelectAllUID()
//db.DB.DelHistoryChat(0, uid)
//log.Info("", "", "sssssssssss")
//if err != nil {
// db.DB.DelHistoryChat(0, uid)
//}
for {
now := time.Now()
// 计算下一个零点
next := now.Add(time.Hour * 24)
next = time.Date(next.Year(), next.Month(), next.Day(), 0, 0, 0, 0, next.Location())
t := time.NewTimer(next.Sub(now))
<-t.C
uid, err := im_mysql_model.SelectAllUID()
if err != nil {
db.DB.DelHistoryChat(int64(config.Config.Mongo.DBRetainChatRecords), uid)
}
//以下为定时执行的操作
scheduleDelete()
}
}

@ -11,7 +11,6 @@ import (
"Open_IM/src/common/constant" "Open_IM/src/common/constant"
"Open_IM/src/common/log" "Open_IM/src/common/log"
pbChat "Open_IM/src/proto/chat" pbChat "Open_IM/src/proto/chat"
pbGroup "Open_IM/src/proto/group"
pbRelay "Open_IM/src/proto/relay" pbRelay "Open_IM/src/proto/relay"
pbGetInfo "Open_IM/src/proto/user" pbGetInfo "Open_IM/src/proto/user"
rpcChat "Open_IM/src/rpc/chat/chat" rpcChat "Open_IM/src/rpc/chat/chat"
@ -34,25 +33,19 @@ type EChatContent struct {
func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) { func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) {
var wsResult []*pbRelay.SingleMsgToUser var wsResult []*pbRelay.SingleMsgToUser
isShouldOfflinePush := true isShouldOfflinePush := true
MOptions := utils.JsonStringToMap(Options) //Control whether to push message to sender's other terminal MOptions := utils.JsonStringToMap(Options)
//isSenderSync := utils.GetSwitchFromOptions(MOptions, "senderSync")
isOfflinePush := utils.GetSwitchFromOptions(MOptions, "offlinePush") isOfflinePush := utils.GetSwitchFromOptions(MOptions, "offlinePush")
log.InfoByKv("Get chat from msg_transfer And push chat", sendPbData.OperationID, "PushData", sendPbData) log.InfoByKv("Get chat from msg_transfer And push chat", sendPbData.OperationID, "PushData", sendPbData)
grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName) grpcCons := getcdv3.GetConn4Unique(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOnlineMessageRelayName)
//Online push message //Online push message
log.InfoByKv("test", sendPbData.OperationID, "len grpc", len(grpcCons), "data", sendPbData)
for _, v := range grpcCons { for _, v := range grpcCons {
msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v) msgClient := pbRelay.NewOnlineMessageRelayServiceClient(v)
reply, err := msgClient.MsgToUser(context.Background(), sendPbData) reply, err := msgClient.MsgToUser(context.Background(), sendPbData)
if err != nil {
log.InfoByKv("push data to client rpc err", sendPbData.OperationID, "err", err)
}
if reply != nil && reply.Resp != nil && err == nil { if reply != nil && reply.Resp != nil && err == nil {
wsResult = append(wsResult, reply.Resp...) wsResult = append(wsResult, reply.Resp...)
} }
} }
log.InfoByKv("push_result", sendPbData.OperationID, "result", wsResult) if isOfflinePush && sendPbData.ContentType != constant.SyncSenderMsg {
if isOfflinePush {
for _, t := range pushTerminal { for _, t := range pushTerminal {
for _, v := range wsResult { for _, v := range wsResult {
@ -108,41 +101,12 @@ func MsgToUser(sendPbData *pbRelay.MsgToUserReq, OfflineInfo, Options string) {
func SendMsgByWS(m *pbChat.WSToMsgSvrChatMsg) { func SendMsgByWS(m *pbChat.WSToMsgSvrChatMsg) {
m.MsgID = rpcChat.GetMsgID(m.SendID) m.MsgID = rpcChat.GetMsgID(m.SendID)
switch m.SessionType { pid, offset, err := producer.SendMessage(m, m.SendID)
case constant.SingleChatType: if err != nil {
sendMsgToKafka(m, m.SendID, "msgKey--sendID") log.ErrorByKv("sys send msg to kafka failed", m.OperationID, "send data", m.String(), "pid", pid, "offset", offset, "err", err.Error(), "msgKey--sendID", m.SendID)
sendMsgToKafka(m, m.RecvID, "msgKey--recvID")
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: m.RecvID,
Token: config.Config.Secret,
OperationID: m.OperationID,
}
reply, err := client.GetGroupAllMember(context.Background(), req)
if err != nil {
log.Error(m.Token, m.OperationID, "rpc getGroupInfo failed, err = %s", err.Error())
return
}
if reply.ErrorCode != 0 {
log.Error(m.Token, m.OperationID, "rpc getGroupInfo failed, err = %s", reply.ErrorMsg)
return
}
groupID := m.RecvID
for _, v := range reply.MemberList {
m.RecvID = v.UserId + " " + groupID
sendMsgToKafka(m, m.RecvID, "msgKey--recvID+\" \"+groupID")
}
default:
} }
pid, offset, err = producer.SendMessage(m, m.RecvID)
}
func sendMsgToKafka(m *pbChat.WSToMsgSvrChatMsg, key string, flag string) {
pid, offset, err := producer.SendMessage(m, key)
if err != nil { if err != nil {
log.ErrorByKv("kafka send failed", m.OperationID, "send data", m.String(), "pid", pid, "offset", offset, "err", err.Error(), flag, key) log.ErrorByKv("kafka send failed", m.OperationID, "send data", m.String(), "pid", pid, "offset", offset, "err", err.Error(), "msgKey--recvID", m.RecvID)
} }
} }

Loading…
Cancel
Save