mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 11:06:43 +08:00
GetMsgBySeqIndexIn1Doc
This commit is contained in:
parent
9651549005
commit
55099274fc
@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
@ -186,9 +187,12 @@ func Test_Revoke(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_FindBySeq(t *testing.T) {
|
func Test_FindBySeq(t *testing.T) {
|
||||||
|
if err := log.InitFromConfig("", 6, true, false, "", 2); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
db := GetDB()
|
db := GetDB()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
fmt.Println(db.getMsgBySeqs(ctx, "100", "si_100_101", []int64{1}))
|
fmt.Println(db.msgDocDatabase.(*unrelation.MsgMongoDriver).GetMsgBySeqIndexIn1Doc(ctx, "100", "si_100_101:0", []int64{1}))
|
||||||
//res, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, "123456", "test:0", []int64{1, 2, 3})
|
//res, err := db.msgDocDatabase.GetMsgBySeqIndexIn1Doc(ctx, "123456", "test:0", []int64{1, 2, 3})
|
||||||
//if err != nil {
|
//if err != nil {
|
||||||
// t.Fatal(err)
|
// t.Fatal(err)
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
||||||
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
|
table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
|
||||||
@ -182,7 +181,6 @@ func (m *MsgMongoDriver) DeleteDocs(ctx context.Context, docIDs []string) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, userID string, docID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) {
|
func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, userID string, docID string, seqs []int64) (msgs []*table.MsgInfoModel, err error) {
|
||||||
log.ZDebug(ctx, "GetMsgBySeqIndexIn1Doc in", "docID", docID, "userID", userID, "seqs", seqs)
|
|
||||||
indexs := make([]int64, 0, len(seqs))
|
indexs := make([]int64, 0, len(seqs))
|
||||||
for _, seq := range seqs {
|
for _, seq := range seqs {
|
||||||
indexs = append(indexs, m.model.GetMsgIndex(seq))
|
indexs = append(indexs, m.model.GetMsgIndex(seq))
|
||||||
@ -238,26 +236,21 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, userID stri
|
|||||||
if err := cur.All(ctx, &msgDocModel); err != nil {
|
if err := cur.All(ctx, &msgDocModel); err != nil {
|
||||||
return nil, errs.Wrap(err)
|
return nil, errs.Wrap(err)
|
||||||
}
|
}
|
||||||
log.ZDebug(ctx, "GetMsgBySeqIndexIn1Doc mongo res", "docID", docID, "userID", userID, "seqs", seqs, "msgDocModel", len(msgDocModel))
|
|
||||||
if len(msgDocModel) == 0 {
|
if len(msgDocModel) == 0 {
|
||||||
return nil, errs.Wrap(mongo.ErrNoDocuments)
|
return nil, errs.Wrap(mongo.ErrNoDocuments)
|
||||||
}
|
}
|
||||||
for i, model := range msgDocModel[0].Msg {
|
for i, msg := range msgDocModel[0].Msg {
|
||||||
if i < 10 {
|
if msg != nil && msg.Msg != nil && msg.Revoke != nil {
|
||||||
log.ZDebug(ctx, "GetMsgBySeqIndexIn1Doc for", "index", i, "model", model, "eq nil", model == nil)
|
|
||||||
log.ZDebug(ctx, "GetMsgBySeqIndexIn1Doc for", "index", i, "msg", model.Msg, "del", model.DelList, "revoke", model.Revoke)
|
|
||||||
}
|
|
||||||
if model.Msg != nil && model.Revoke != nil {
|
|
||||||
var conversationID string
|
var conversationID string
|
||||||
if index := strings.LastIndex(docID, ":"); index > 0 {
|
if index := strings.LastIndex(docID, ":"); index > 0 {
|
||||||
conversationID = docID[:index]
|
conversationID = docID[:index]
|
||||||
}
|
}
|
||||||
tips := sdkws.RevokeMsgTips{
|
tips := sdkws.RevokeMsgTips{
|
||||||
RevokerUserID: model.Revoke.UserID,
|
RevokerUserID: msg.Revoke.UserID,
|
||||||
ClientMsgID: model.Msg.ClientMsgID,
|
ClientMsgID: msg.Msg.ClientMsgID,
|
||||||
RevokeTime: model.Revoke.Time,
|
RevokeTime: msg.Revoke.Time,
|
||||||
SesstionType: model.Msg.SessionType,
|
SesstionType: msg.Msg.SessionType,
|
||||||
Seq: model.Msg.Seq,
|
Seq: msg.Msg.Seq,
|
||||||
ConversationID: conversationID,
|
ConversationID: conversationID,
|
||||||
}
|
}
|
||||||
tipsData, _ := json.Marshal(&tips)
|
tipsData, _ := json.Marshal(&tips)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user