This commit is contained in:
wangchuxiao 2023-05-11 21:32:12 +08:00
parent dd99f52355
commit 8aff2e86a8
4 changed files with 34 additions and 11 deletions

View File

@ -11,6 +11,7 @@ import (
type ConversationLocalCacheInterface interface { type ConversationLocalCacheInterface interface {
GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error) GetRecvMsgNotNotifyUserIDs(ctx context.Context, groupID string) ([]string, error)
GetConversationIDs(ctx context.Context, userID string) ([]string, error)
} }
type ConversationLocalCache struct { type ConversationLocalCache struct {
@ -40,3 +41,18 @@ func (g *ConversationLocalCache) GetRecvMsgNotNotifyUserIDs(ctx context.Context,
} }
return resp.UserIDs, nil return resp.UserIDs, nil
} }
func (g *ConversationLocalCache) GetConversationIDs(ctx context.Context, userID string) ([]string, error) {
conn, err := g.client.GetConn(ctx, config.Config.RpcRegisterName.OpenImConversationName)
if err != nil {
return nil, err
}
client := conversation.NewConversationClient(conn)
resp, err := client.GetConversationIDs(ctx, &conversation.GetConversationIDsReq{
UserID: userID,
})
if err != nil {
return nil, err
}
return resp.ConversationIDs, nil
}

View File

@ -46,7 +46,7 @@ func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(resp.GroupAbstractInfos) < 0 { if len(resp.GroupAbstractInfos) < 1 {
return nil, errs.ErrGroupIDNotFound return nil, errs.ErrGroupIDNotFound
} }
localHashInfo, ok := g.cache[groupID] localHashInfo, ok := g.cache[groupID]

View File

@ -3,6 +3,9 @@ package unrelation
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"time"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/config" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/config"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror" "github.com/OpenIMSDK/Open-IM-Server/pkg/common/mw/specialerror"
@ -11,8 +14,6 @@ import (
"go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/x/bsonx" "go.mongodb.org/mongo-driver/x/bsonx"
"strings"
"time"
) )
type Mongo struct { type Mongo struct {

View File

@ -144,7 +144,6 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID strin
bson.M{ bson.M{
"$project": bson.M{ "$project": bson.M{
"msgs": bson.M{ "msgs": bson.M{
// "$slice": []interface{}{"$msgs", beginIndex, num},
"$slice": bson.A{"$msgs", beginIndex, num}, "$slice": bson.A{"$msgs", beginIndex, num},
}, },
}, },
@ -154,16 +153,23 @@ func (m *MsgMongoDriver) GetMsgBySeqIndexIn1Doc(ctx context.Context, docID strin
if err != nil { if err != nil {
return nil, nil, errs.Wrap(err) return nil, nil, errs.Wrap(err)
} }
log.ZDebug(ctx, "info", "beginIndex", beginIndex, "num", num) defer cursor.Close(ctx)
var msgInfos []*table.MsgInfoModel var doc table.MsgDocModel
if err := cursor.All(ctx, &msgInfos); err != nil { i := 0
return nil, nil, err for cursor.Next(ctx) {
err := cursor.Decode(&doc)
if err != nil {
return nil, nil, err
}
if i == 0 {
break
}
} }
if len(msgInfos) < 1 { if len(doc.Msg) < 1 {
return nil, nil, errs.ErrRecordNotFound.Wrap("mongo GetMsgBySeqIndex failed, len is 0") return nil, nil, errs.ErrRecordNotFound.Wrap("mongo GetMsgBySeqIndex failed, len is 0")
} }
log.ZDebug(ctx, "msgInfos", "num", len(msgInfos)) log.ZDebug(ctx, "msgInfos", "num", len(doc.Msg))
for _, v := range msgInfos { for _, v := range doc.Msg {
var msg sdkws.MsgData var msg sdkws.MsgData
if err := proto.Unmarshal(v.Msg, &msg); err != nil { if err := proto.Unmarshal(v.Msg, &msg); err != nil {
return nil, nil, err return nil, nil, err