diff --git a/build.cmd b/build.cmd deleted file mode 100644 index 4c53576c0..000000000 --- a/build.cmd +++ /dev/null @@ -1 +0,0 @@ -go build -o \ No newline at end of file diff --git a/internal/rpc/msg/sync_msg.go b/internal/rpc/msg/sync_msg.go index 8cfac93bd..70967a1ba 100644 --- a/internal/rpc/msg/sync_msg.go +++ b/internal/rpc/msg/sync_msg.go @@ -108,11 +108,11 @@ func (m *msgServer) GetMaxSeq(ctx context.Context, req *sdkws.GetMaxSeqReq) (*sd func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (resp *msg.SearchMessageResp, err error) { var chatLogs []*sdkws.MsgData + var total int32 resp = &msg.SearchMessageResp{} - if chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil { + if total, chatLogs, err = m.MsgDatabase.SearchMessage(ctx, req); err != nil { return nil, err } - var num int for _, chatLog := range chatLogs { pbChatLog := &msg.ChatLog{} utils.CopyStructFields(pbChatLog, chatLog) @@ -146,9 +146,8 @@ func (m *msgServer) SearchMessage(ctx context.Context, req *msg.SearchMessageReq pbChatLog.GroupType = group.GroupType } resp.ChatLogs = append(resp.ChatLogs, pbChatLog) - num++ } - resp.ChatLogsNum = int32(num) + resp.ChatLogsNum = total return resp, nil } diff --git a/pkg/common/db/controller/msg.go b/pkg/common/db/controller/msg.go index fdda23ac9..37a71bafa 100644 --- a/pkg/common/db/controller/msg.go +++ b/pkg/common/db/controller/msg.go @@ -92,7 +92,7 @@ type CommonMsgDatabase interface { GetConversationMinMaxSeqInMongoAndCache(ctx context.Context, conversationID string) (minSeqMongo, maxSeqMongo, minSeqCache, maxSeqCache int64, err error) SetSendMsgStatus(ctx context.Context, id string, status int32) error GetSendMsgStatus(ctx context.Context, id string) (int32, error) - SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (msgData []*sdkws.MsgData, err error) + SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (total int32, msgData []*sdkws.MsgData, err error) // to mq MsgToMQ(ctx context.Context, key string, msg2mq *sdkws.MsgData) error @@ -940,14 +940,14 @@ func (db *commonMsgDatabase) RangeGroupSendCount( return db.msgDocDatabase.RangeGroupSendCount(ctx, start, end, ase, pageNumber, showNumber) } -func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (msgData []*sdkws.MsgData, err error) { +func (db *commonMsgDatabase) SearchMessage(ctx context.Context, req *pbMsg.SearchMessageReq) (total int32, msgData []*sdkws.MsgData, err error) { var totalMsgs []*sdkws.MsgData - msgs, err := db.msgDocDatabase.SearchMessage(ctx, req) + total, msgs, err := db.msgDocDatabase.SearchMessage(ctx, req) if err != nil { - return nil, err + return 0, nil, err } for _, msg := range msgs { totalMsgs = append(totalMsgs, convert.MsgDB2Pb(msg.Msg)) } - return totalMsgs, nil + return total, totalMsgs, nil } diff --git a/pkg/common/db/table/unrelation/msg.go b/pkg/common/db/table/unrelation/msg.go index ac4602d35..dc16613ed 100644 --- a/pkg/common/db/table/unrelation/msg.go +++ b/pkg/common/db/table/unrelation/msg.go @@ -110,7 +110,7 @@ type MsgDocModelInterface interface { GetMsgDocModelByIndex(ctx context.Context, conversationID string, index, sort int64) (*MsgDocModel, error) DeleteMsgsInOneDocByIndex(ctx context.Context, docID string, indexes []int) error MarkSingleChatMsgsAsRead(ctx context.Context, userID string, docID string, indexes []int64) error - SearchMessage(ctx context.Context, req *msg.SearchMessageReq) ([]*MsgInfoModel, error) + SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (int32, []*MsgInfoModel, error) RangeUserSendCount( ctx context.Context, start time.Time, diff --git a/pkg/common/db/unrelation/msg.go b/pkg/common/db/unrelation/msg.go index 222b70190..b7403ebde 100644 --- a/pkg/common/db/unrelation/msg.go +++ b/pkg/common/db/unrelation/msg.go @@ -1067,20 +1067,20 @@ func (m *MsgMongoDriver) RangeGroupSendCount( return result[0].MsgCount, result[0].UserCount, groups, dateCount, nil } -func (m *MsgMongoDriver) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) ([]*table.MsgInfoModel, error) { - msgs, err := m.searchMessage(ctx, req) +func (m *MsgMongoDriver) SearchMessage(ctx context.Context, req *msg.SearchMessageReq) (int32, []*table.MsgInfoModel, error) { + total, msgs, err := m.searchMessage(ctx, req) if err != nil { - return nil, err + return 0, nil, err } for _, msg1 := range msgs { if msg1.IsRead { msg1.Msg.IsRead = true } } - return msgs, nil + return total, msgs, nil } -func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessageReq) ([]*table.MsgInfoModel, error) { +func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessageReq) (int32, []*table.MsgInfoModel, error) { var pipe mongo.Pipeline condition := bson.A{} if req.SendTime != "" { @@ -1153,16 +1153,16 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa } cursor, err := m.MsgCollection.Aggregate(ctx, pipe) if err != nil { - return nil, err + return 0, nil, err } var msgsDocs []table.MsgDocModel err = cursor.All(ctx, &msgsDocs) if err != nil { - return nil, err + return 0, nil, err } if len(msgsDocs) == 0 { - return nil, errs.Wrap(mongo.ErrNoDocuments) + return 0, nil, errs.Wrap(mongo.ErrNoDocuments) } msgs := make([]*table.MsgInfoModel, 0) for index := range msgsDocs { @@ -1187,14 +1187,14 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa } data, err := json.Marshal(&revokeContent) if err != nil { - return nil, err + return 0, nil, err } elem := sdkws.NotificationElem{ Detail: string(data), } content, err := json.Marshal(&elem) if err != nil { - return nil, err + return 0, nil, err } msg.Msg.ContentType = constant.MsgRevokeNotification msg.Msg.Content = string(content) @@ -1209,5 +1209,5 @@ func (m *MsgMongoDriver) searchMessage(ctx context.Context, req *msg.SearchMessa } else { msgs = msgs[start:] } - return msgs, nil + return n, msgs, nil }