mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
msg
This commit is contained in:
parent
dd99f52355
commit
8aff2e86a8
@ -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
|
||||||
|
}
|
||||||
|
@ -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]
|
||||||
|
@ -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 {
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user