From 8b365ae49f2a6e148988f878f88d842851b016d1 Mon Sep 17 00:00:00 2001 From: Alan <68671759+hanzhixiao@users.noreply.github.com> Date: Fri, 18 Aug 2023 18:44:18 +0800 Subject: [PATCH] Searchmsg (#859) * fix:searchmsg Signed-off-by: hanzhixiao <709674996@qq.com> * fix:searchmsg Signed-off-by: hanzhixiao <709674996@qq.com> --------- Signed-off-by: hanzhixiao <709674996@qq.com> --- pkg/common/db/unrelation/msg.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/common/db/unrelation/msg.go b/pkg/common/db/unrelation/msg.go index ce51ca49c..a1594ecc8 100644 --- a/pkg/common/db/unrelation/msg.go +++ b/pkg/common/db/unrelation/msg.go @@ -19,6 +19,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/OpenIMSDK/tools/log" "time" "github.com/OpenIMSDK/protocol/msg" @@ -1166,9 +1167,7 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa if err != nil { return 0, nil, err } - if len(msgsDocs) == 0 { - return 0, nil, errs.Wrap(mongo.ErrNoDocuments) - } + log.ZDebug(ctx, "query mongoDB", "result", msgsDocs) msgs := make([]*table.MsgInfoModel, 0) for index := range msgsDocs { msgInfo := msgsDocs[index].Msg @@ -1207,7 +1206,9 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa } start := (req.Pagination.PageNumber - 1) * req.Pagination.ShowNumber n := int32(len(msgs)) - if start+req.Pagination.ShowNumber < n { + if start >= n { + return n, []*table.MsgInfoModel{}, nil + } else if start+req.Pagination.ShowNumber < n { msgs = msgs[start : start+req.Pagination.ShowNumber] } else { msgs = msgs[start:]