|
|
@ -6,7 +6,6 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
|
|
table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
|
|
|
|
table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/proto/sdkws"
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/utils"
|
|
|
@ -178,58 +177,120 @@ func (m *MsgMongoDriver) DeleteDocs(ctx context.Context, docIDs []string) error
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) {
|
|
|
|
func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID string, userID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) {
|
|
|
|
beginSeq, endSeq := utils.GetSeqsBeginEnd(seqs)
|
|
|
|
indexs := make([]int64, 0, len(seqs))
|
|
|
|
beginIndex := m.model.GetMsgIndex(beginSeq)
|
|
|
|
for _, seq := range seqs {
|
|
|
|
num := endSeq - beginSeq + 1
|
|
|
|
indexs = append(indexs, m.model.GetMsgIndex(seq))
|
|
|
|
log.ZInfo(ctx, "GetMsgBySeqIndexIn1Doc", "docID", docID, "seqs", seqs, "beginSeq", beginSeq, "endSeq", endSeq, "beginIndex", beginIndex, "num", num)
|
|
|
|
}
|
|
|
|
pipeline := bson.A{
|
|
|
|
pipeline := mongo.Pipeline{
|
|
|
|
bson.M{
|
|
|
|
{
|
|
|
|
"$match": bson.M{"doc_id": docID},
|
|
|
|
{"$match", bson.D{
|
|
|
|
},
|
|
|
|
{"doc_id", docID},
|
|
|
|
bson.M{
|
|
|
|
}},
|
|
|
|
"$project": bson.M{
|
|
|
|
|
|
|
|
"msgs": bson.M{
|
|
|
|
|
|
|
|
"$slice": bson.A{"$msgs", beginIndex, num},
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{"$project", bson.D{
|
|
|
|
|
|
|
|
{"_id", 0},
|
|
|
|
|
|
|
|
{"msgs", bson.D{
|
|
|
|
|
|
|
|
{"$map", bson.D{
|
|
|
|
|
|
|
|
{"input", indexs},
|
|
|
|
|
|
|
|
{"as", "index"},
|
|
|
|
|
|
|
|
{"in", bson.D{
|
|
|
|
|
|
|
|
{"$let", bson.D{
|
|
|
|
|
|
|
|
{"vars", bson.D{
|
|
|
|
|
|
|
|
{"currentMsg", bson.D{
|
|
|
|
|
|
|
|
{"$arrayElemAt", []string{"$msgs", "$$index"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
{"in", bson.D{
|
|
|
|
|
|
|
|
{"$cond", bson.D{
|
|
|
|
|
|
|
|
{"if", bson.D{
|
|
|
|
|
|
|
|
{"$in", []string{userID, "$$currentMsg.del_list"}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
{"then", nil},
|
|
|
|
|
|
|
|
{"else", "$$currentMsg"},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
{"$project", bson.D{
|
|
|
|
|
|
|
|
{"doc_id", 0},
|
|
|
|
|
|
|
|
{"msgs.del_list", 0},
|
|
|
|
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor, err := m.MsgCollection.Aggregate(ctx, pipeline)
|
|
|
|
cur, err := m.MsgCollection.Aggregate(ctx, pipeline)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
defer cursor.Close(ctx)
|
|
|
|
defer cur.Close(ctx)
|
|
|
|
var doc table.MsgDocModel
|
|
|
|
var msgDocModel []table.MsgDocModel
|
|
|
|
if cursor.Next(ctx) {
|
|
|
|
if err := cur.All(ctx, &msgDocModel); err != nil {
|
|
|
|
if err := cursor.Decode(&doc); err != nil {
|
|
|
|
return nil, errs.Wrap(err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(msgDocModel) == 0 {
|
|
|
|
|
|
|
|
return nil, errs.Wrap(mongo.ErrNoDocuments)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgDocModel[0].Msg, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
////i := 0
|
|
|
|
|
|
|
|
//for cursor.Next(ctx) {
|
|
|
|
//func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) {
|
|
|
|
// err := cursor.Decode(&doc)
|
|
|
|
// beginSeq, endSeq := utils.GetSeqsBeginEnd(seqs)
|
|
|
|
|
|
|
|
// beginIndex := m.model.GetMsgIndex(beginSeq)
|
|
|
|
|
|
|
|
// num := endSeq - beginSeq + 1
|
|
|
|
|
|
|
|
// log.ZInfo(ctx, "GetMsgBySeqIndexIn1Doc", "docID", docID, "seqs", seqs, "beginSeq", beginSeq, "endSeq", endSeq, "beginIndex", beginIndex, "num", num)
|
|
|
|
|
|
|
|
// pipeline := bson.A{
|
|
|
|
|
|
|
|
// bson.M{
|
|
|
|
|
|
|
|
// "$match": bson.M{"doc_id": docID},
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// bson.M{
|
|
|
|
|
|
|
|
// "$project": bson.M{
|
|
|
|
|
|
|
|
// "msgs": bson.M{
|
|
|
|
|
|
|
|
// "$slice": bson.A{"$msgs", beginIndex, num},
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// cursor, err := m.MsgCollection.Aggregate(ctx, pipeline)
|
|
|
|
// if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
|
|
|
|
// return nil, errs.Wrap(err)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// defer cursor.Close(ctx)
|
|
|
|
|
|
|
|
// var doc table.MsgDocModel
|
|
|
|
|
|
|
|
// if cursor.Next(ctx) {
|
|
|
|
|
|
|
|
// if err := cursor.Decode(&doc); err != nil {
|
|
|
|
// return nil, err
|
|
|
|
// return nil, err
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// //if i == 0 {
|
|
|
|
// }
|
|
|
|
// // break
|
|
|
|
// ////i := 0
|
|
|
|
|
|
|
|
// //for cursor.Next(ctx) {
|
|
|
|
|
|
|
|
// // err := cursor.Decode(&doc)
|
|
|
|
|
|
|
|
// // if err != nil {
|
|
|
|
|
|
|
|
// // return nil, err
|
|
|
|
// // }
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// // //if i == 0 {
|
|
|
|
|
|
|
|
// // // break
|
|
|
|
|
|
|
|
// // //}
|
|
|
|
|
|
|
|
// //}
|
|
|
|
|
|
|
|
// log.ZDebug(ctx, "msgInfos", "num", len(doc.Msg), "docID", docID)
|
|
|
|
|
|
|
|
// for _, v := range doc.Msg {
|
|
|
|
|
|
|
|
// if v.Msg == nil {
|
|
|
|
|
|
|
|
// continue
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if v.Msg.Seq >= beginSeq && v.Msg.Seq <= endSeq {
|
|
|
|
|
|
|
|
// log.ZDebug(ctx, "find msg", "msg", v.Msg)
|
|
|
|
|
|
|
|
// msgs = append(msgs, v)
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// log.ZWarn(ctx, "this msg is at wrong position", nil, "msg", v.Msg)
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return msgs, nil
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
log.ZDebug(ctx, "msgInfos", "num", len(doc.Msg), "docID", docID)
|
|
|
|
|
|
|
|
for _, v := range doc.Msg {
|
|
|
|
|
|
|
|
if v.Msg == nil {
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Msg.Seq >= beginSeq && v.Msg.Seq <= endSeq {
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "find msg", "msg", v.Msg)
|
|
|
|
|
|
|
|
msgs = append(msgs, v)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.ZWarn(ctx, "this msg is at wrong position", nil, "msg", v.Msg)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgs, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *MsgMongoDriver) IsExistDocID(ctx context.Context, docID string) (bool, error) {
|
|
|
|
func (m *MsgMongoDriver) IsExistDocID(ctx context.Context, docID string) (bool, error) {
|
|
|
|
count, err := m.MsgCollection.CountDocuments(ctx, bson.M{"doc_id": docID})
|
|
|
|
count, err := m.MsgCollection.CountDocuments(ctx, bson.M{"doc_id": docID})
|
|
|
|