summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/RoomDirectoryModel.cpp22
-rw-r--r--src/RoomDirectoryModel.h22
2 files changed, 32 insertions, 12 deletions
diff --git a/src/RoomDirectoryModel.cpp b/src/RoomDirectoryModel.cpp

index 2c633491..7d6be13e 100644 --- a/src/RoomDirectoryModel.cpp +++ b/src/RoomDirectoryModel.cpp
@@ -11,7 +11,6 @@ RoomDirectoryModel::RoomDirectoryModel(QObject *parent, const std::string &s) : QAbstractListModel(parent) , server_(s) - , canFetchMore_(true) { connect(this, &RoomDirectoryModel::fetchedRoomsBatch, @@ -127,6 +126,8 @@ RoomDirectoryModel::data(const QModelIndex &index, int role) const void RoomDirectoryModel::fetchMore(const QModelIndex &) { + if (!canFetchMore_) return; + nhlog::net()->debug("Fetching more rooms from mtxclient..."); mtx::requests::PublicRooms req; @@ -136,10 +137,19 @@ RoomDirectoryModel::fetchMore(const QModelIndex &) // req.third_party_instance_id = third_party_instance_id; auto requested_server = server_; + reachedEndOfPagination_ = false; + emit reachedEndOfPaginationChanged(); + + loadingMoreRooms_ = true; + emit loadingMoreRoomsChanged(); + http::client()->post_public_rooms( req, [requested_server, this, req](const mtx::responses::PublicRooms &res, mtx::http::RequestErr err) { + loadingMoreRooms_ = false; + emit loadingMoreRoomsChanged(); + if (err) { nhlog::net()->error( "Failed to retrieve rooms from mtxclient - {} - {} - {}", @@ -149,7 +159,7 @@ RoomDirectoryModel::fetchMore(const QModelIndex &) } else if (req.filter.generic_search_term == this->userSearchString_ && req.since == this->prevBatch_ && requested_server == this->server_) { nhlog::net()->debug("signalling chunk to GUI thread"); - emit fetchedRoomsBatch(res.chunk, res.prev_batch, res.next_batch); + emit fetchedRoomsBatch(res.chunk, res.next_batch); } }, requested_server); @@ -157,11 +167,9 @@ RoomDirectoryModel::fetchMore(const QModelIndex &) void RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> fetched_rooms, - const std::string &prev_batch, const std::string &next_batch) { - nhlog::net()->debug("Prev batch: {} | Next batch: {}", prevBatch_, nextBatch_); - nhlog::net()->debug("NP batch: {} | NN batch: {}", prev_batch, next_batch); + nhlog::net()->debug("Prev batch: {} | Next batch: {}", prevBatch_, next_batch); if (fetched_rooms.empty()) { nhlog::net()->error("mtxclient helper thread yielded empty chunk!"); @@ -177,7 +185,11 @@ RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> f if (next_batch.empty()) { canFetchMore_ = false; + reachedEndOfPagination_ = true; + emit reachedEndOfPaginationChanged(); } prevBatch_ = next_batch; + + nhlog::ui()->debug ("Finished loading rooms"); } diff --git a/src/RoomDirectoryModel.h b/src/RoomDirectoryModel.h
index 952ae3ff..a7e6c0bc 100644 --- a/src/RoomDirectoryModel.h +++ b/src/RoomDirectoryModel.h
@@ -27,6 +27,9 @@ class RoomDirectoryModel : public QAbstractListModel { Q_OBJECT + Q_PROPERTY (bool loadingMoreRooms READ loadingMoreRooms NOTIFY loadingMoreRoomsChanged) + Q_PROPERTY (bool reachedEndOfPagination READ reachedEndOfPagination NOTIFY reachedEndOfPaginationChanged) + public: explicit RoomDirectoryModel(QObject *parent = nullptr, const std::string &s = ""); @@ -49,10 +52,15 @@ public: return static_cast<int>(publicRoomsData_.size()); } - inline bool canFetchMore(const QModelIndex &) const override + bool canFetchMore(const QModelIndex &) const override { return canFetchMore_; } + + bool loadingMoreRooms() const { return loadingMoreRooms_; } + + bool reachedEndOfPagination() const { return reachedEndOfPagination_; } + void fetchMore(const QModelIndex &) override; Q_INVOKABLE bool canJoinRoom(const QByteArray &room); @@ -60,15 +68,13 @@ public: signals: void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms, - const std::string &prev_batch, const std::string &next_batch); - void serverChanged(); - void searchTermEntered(); + void loadingMoreRoomsChanged(); + void reachedEndOfPaginationChanged(); public slots: void displayRooms(std::vector<mtx::responses::PublicRoomsChunk> rooms, - const std::string &prev, - const std::string &next); + const std::string &next_batch); void setMatrixServer(const QString &s = ""); void setSearchTerm(const QString &f); @@ -79,7 +85,9 @@ private: std::string userSearchString_; std::string prevBatch_; std::string nextBatch_; - bool canFetchMore_; + bool canFetchMore_ {true}; + bool loadingMoreRooms_ {false}; + bool reachedEndOfPagination_ {false}; std::vector<mtx::responses::PublicRoomsChunk> publicRoomsData_; std::vector<std::string> getViasForRoom(const std::vector<std::string> &room);