mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Fix potential crash from the room directory
This commit is contained in:
parent
fd949f0b83
commit
0b8709a0ea
2 changed files with 48 additions and 18 deletions
|
@ -29,12 +29,6 @@ RoomDirectoryModel::RoomDirectoryModel(QObject *parent, const std::string &serve
|
|||
i++;
|
||||
}
|
||||
});
|
||||
|
||||
connect(this,
|
||||
&RoomDirectoryModel::fetchedRoomsBatch,
|
||||
this,
|
||||
&RoomDirectoryModel::displayRooms,
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray>
|
||||
|
@ -170,22 +164,28 @@ RoomDirectoryModel::fetchMore(const QModelIndex &)
|
|||
loadingMoreRooms_ = true;
|
||||
emit loadingMoreRoomsChanged();
|
||||
|
||||
auto job = QSharedPointer<FetchRoomsChunkFromDirectoryJob>::create();
|
||||
connect(job.data(),
|
||||
&FetchRoomsChunkFromDirectoryJob::fetchedRoomsBatch,
|
||||
this,
|
||||
&RoomDirectoryModel::displayRooms);
|
||||
|
||||
http::client()->post_public_rooms(
|
||||
req,
|
||||
[requested_server, this, req](const mtx::responses::PublicRooms &res,
|
||||
mtx::http::RequestErr err) {
|
||||
loadingMoreRooms_ = false;
|
||||
emit loadingMoreRoomsChanged();
|
||||
|
||||
[requested_server, job, req](const mtx::responses::PublicRooms &res,
|
||||
mtx::http::RequestErr err) {
|
||||
if (err) {
|
||||
nhlog::net()->error("Failed to retrieve rooms from mtxclient - {} - {} - {}",
|
||||
mtx::errors::to_string(err->matrix_error.errcode),
|
||||
err->matrix_error.error,
|
||||
err->parse_error);
|
||||
} else if (req.filter.generic_search_term == this->userSearchString_ &&
|
||||
req.since == this->prevBatch_ && requested_server == this->server_) {
|
||||
} else {
|
||||
nhlog::net()->debug("signalling chunk to GUI thread");
|
||||
emit fetchedRoomsBatch(res.chunk, res.next_batch);
|
||||
emit job->fetchedRoomsBatch(res.chunk,
|
||||
res.next_batch,
|
||||
req.filter.generic_search_term,
|
||||
requested_server,
|
||||
req.since);
|
||||
}
|
||||
},
|
||||
requested_server);
|
||||
|
@ -193,8 +193,19 @@ RoomDirectoryModel::fetchMore(const QModelIndex &)
|
|||
|
||||
void
|
||||
RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> fetched_rooms,
|
||||
const std::string &next_batch)
|
||||
const std::string &next_batch,
|
||||
const std::string &search_term,
|
||||
const std::string &server,
|
||||
const std::string &since)
|
||||
{
|
||||
if (search_term != this->userSearchString_ || since != this->prevBatch_ ||
|
||||
server != this->server_) {
|
||||
return;
|
||||
}
|
||||
|
||||
loadingMoreRooms_ = false;
|
||||
emit loadingMoreRoomsChanged();
|
||||
|
||||
nhlog::net()->debug("Prev batch: {} | Next batch: {}", prevBatch_, next_batch);
|
||||
|
||||
if (fetched_rooms.empty()) {
|
||||
|
|
|
@ -13,6 +13,24 @@
|
|||
|
||||
#include <mtx/responses/public_rooms.hpp>
|
||||
|
||||
class FetchRoomsChunkFromDirectoryJob final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FetchRoomsChunkFromDirectoryJob(QObject *p = nullptr)
|
||||
: QObject(p)
|
||||
{
|
||||
}
|
||||
|
||||
signals:
|
||||
void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms,
|
||||
const std::string &next_batch,
|
||||
const std::string &search_term,
|
||||
const std::string &server,
|
||||
const std::string &since);
|
||||
};
|
||||
|
||||
class RoomDirectoryModel : public QAbstractListModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -55,8 +73,6 @@ public:
|
|||
Q_INVOKABLE void joinRoom(const int &index = -1);
|
||||
|
||||
signals:
|
||||
void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms,
|
||||
const std::string &next_batch);
|
||||
void loadingMoreRoomsChanged();
|
||||
void reachedEndOfPaginationChanged();
|
||||
|
||||
|
@ -67,7 +83,10 @@ public slots:
|
|||
private slots:
|
||||
|
||||
void displayRooms(std::vector<mtx::responses::PublicRoomsChunk> rooms,
|
||||
const std::string &next_batch);
|
||||
const std::string &next_batch,
|
||||
const std::string &search_term,
|
||||
const std::string &server,
|
||||
const std::string &since);
|
||||
|
||||
private:
|
||||
bool canJoinRoom(const QString &room) const;
|
||||
|
|
Loading…
Reference in a new issue