Linted code

This commit is contained in:
kamathmanu 2021-07-28 22:33:23 -04:00
parent 93f8c24fc5
commit 04d0d413e3
3 changed files with 157 additions and 149 deletions

View file

@ -12,7 +12,11 @@ RoomDirectoryModel::RoomDirectoryModel(QObject *parent, const std::string &s)
, server_(s) , server_(s)
, canFetchMore_(true) , canFetchMore_(true)
{ {
connect(this, &RoomDirectoryModel::fetchedRoomsBatch, this, &RoomDirectoryModel::displayRooms, Qt::QueuedConnection); connect(this,
&RoomDirectoryModel::fetchedRoomsBatch,
this,
&RoomDirectoryModel::displayRooms,
Qt::QueuedConnection);
} }
QHash<int, QByteArray> QHash<int, QByteArray>
@ -24,7 +28,8 @@ RoomDirectoryModel::roleNames() const
{Roles::AvatarUrl, "avatarUrl"}, {Roles::AvatarUrl, "avatarUrl"},
{Roles::Topic, "topic"}, {Roles::Topic, "topic"},
{Roles::MemberCount, "numMembers"}, {Roles::MemberCount, "numMembers"},
{Roles::Previewable, "canPreview"},}; {Roles::Previewable, "canPreview"},
};
} }
void void
@ -36,7 +41,7 @@ RoomDirectoryModel::resetDisplayedData()
nextBatch_ = ""; nextBatch_ = "";
canFetchMore_ = true; canFetchMore_ = true;
beginRemoveRows(QModelIndex(), 0 , static_cast<int> (publicRoomsData_.size())); beginRemoveRows(QModelIndex(), 0, static_cast<int>(publicRoomsData_.size()));
publicRoomsData_.clear(); publicRoomsData_.clear();
endRemoveRows(); endRemoveRows();
@ -70,8 +75,8 @@ RoomDirectoryModel::getViasForRoom(const std::vector<std::string> &aliases)
vias.reserve(aliases.size()); vias.reserve(aliases.size());
std::transform(aliases.begin(), aliases.end(), std::transform(
std::back_inserter(vias), [](const auto &alias) { aliases.begin(), aliases.end(), std::back_inserter(vias), [](const auto &alias) {
const auto roomAliasDelimiter = ":"; const auto roomAliasDelimiter = ":";
return alias.substr(alias.find(roomAliasDelimiter) + 1); return alias.substr(alias.find(roomAliasDelimiter) + 1);
}); });
@ -82,8 +87,7 @@ RoomDirectoryModel::getViasForRoom(const std::vector<std::string> &aliases)
void void
RoomDirectoryModel::joinRoom(const int &index) RoomDirectoryModel::joinRoom(const int &index)
{ {
if (index >= 0 && static_cast<size_t> (index) < publicRoomsData_.size()) if (index >= 0 && static_cast<size_t>(index) < publicRoomsData_.size()) {
{
const auto &chunk = publicRoomsData_[index]; const auto &chunk = publicRoomsData_[index];
nhlog::ui()->debug("'Joining room {}", chunk.room_id); nhlog::ui()->debug("'Joining room {}", chunk.room_id);
ChatPage::instance()->joinRoomVia(chunk.room_id, getViasForRoom(chunk.aliases)); ChatPage::instance()->joinRoomVia(chunk.room_id, getViasForRoom(chunk.aliases));
@ -93,11 +97,9 @@ RoomDirectoryModel::joinRoom(const int &index)
QVariant QVariant
RoomDirectoryModel::data(const QModelIndex &index, int role) const RoomDirectoryModel::data(const QModelIndex &index, int role) const
{ {
if (hasIndex(index.row(), index.column(), index.parent())) if (hasIndex(index.row(), index.column(), index.parent())) {
{
const auto &room_chunk = publicRoomsData_[index.row()]; const auto &room_chunk = publicRoomsData_[index.row()];
switch (role) switch (role) {
{
case Roles::Name: case Roles::Name:
return QString::fromStdString(room_chunk.name); return QString::fromStdString(room_chunk.name);
case Roles::Id: case Roles::Id:
@ -128,28 +130,29 @@ RoomDirectoryModel::fetchMore(const QModelIndex &)
// req.third_party_instance_id = third_party_instance_id; // req.third_party_instance_id = third_party_instance_id;
auto requested_server = server_; auto requested_server = server_;
http::client()->post_public_rooms(req, [requested_server, this, req] http::client()->post_public_rooms(
(const mtx::responses::PublicRooms &res, req,
mtx::http::RequestErr err) [requested_server, this, req](const mtx::responses::PublicRooms &res,
{ mtx::http::RequestErr err) {
if (err) { if (err) {
nhlog::net()->error nhlog::net()->error(
("Failed to retrieve rooms from mtxclient - {} - {} - {}", "Failed to retrieve rooms from mtxclient - {} - {} - {}",
mtx::errors::to_string(err->matrix_error.errcode), mtx::errors::to_string(err->matrix_error.errcode),
err->matrix_error.error, err->matrix_error.error,
err->parse_error); err->parse_error);
} else if ( req.filter.generic_search_term == this->userSearchString_ } else if (req.filter.generic_search_term == this->userSearchString_ &&
&& req.since == this->prevBatch_ req.since == this->prevBatch_ && requested_server == this->server_) {
&& requested_server == this->server_) {
nhlog::net()->debug("signalling chunk to GUI thread"); nhlog::net()->debug("signalling chunk to GUI thread");
emit fetchedRoomsBatch(res.chunk, res.prev_batch, res.next_batch); emit fetchedRoomsBatch(res.chunk, res.prev_batch, res.next_batch);
} }
}, requested_server); },
requested_server);
} }
void void
RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> fetched_rooms, RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> fetched_rooms,
const std::string &prev_batch, const std::string &next_batch) const std::string &prev_batch,
const std::string &next_batch)
{ {
nhlog::net()->debug("Prev batch: {} | Next batch: {}", prevBatch_, nextBatch_); nhlog::net()->debug("Prev batch: {} | Next batch: {}", prevBatch_, nextBatch_);
nhlog::net()->debug("NP batch: {} | NN batch: {}", prev_batch, next_batch); nhlog::net()->debug("NP batch: {} | NN batch: {}", prev_batch, next_batch);
@ -159,8 +162,11 @@ RoomDirectoryModel::displayRooms(std::vector<mtx::responses::PublicRoomsChunk> f
return; return;
} }
beginInsertRows(QModelIndex(), static_cast<int> (publicRoomsData_.size()), static_cast<int> (publicRoomsData_.size() + fetched_rooms.size()) - 1); beginInsertRows(QModelIndex(),
this->publicRoomsData_.insert(this->publicRoomsData_.end(), fetched_rooms.begin(), fetched_rooms.end()); static_cast<int>(publicRoomsData_.size()),
static_cast<int>(publicRoomsData_.size() + fetched_rooms.size()) - 1);
this->publicRoomsData_.insert(
this->publicRoomsData_.end(), fetched_rooms.begin(), fetched_rooms.end());
endInsertRows(); endInsertRows();
if (next_batch.empty()) { if (next_batch.empty()) {

View file

@ -7,12 +7,12 @@
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QHash> #include <QHash>
#include <QString> #include <QString>
#include <vector>
#include <string> #include <string>
#include <vector>
#include "MatrixClient.h" #include "MatrixClient.h"
#include <mtxclient/http/errors.hpp>
#include <mtx/responses/public_rooms.hpp> #include <mtx/responses/public_rooms.hpp>
#include <mtxclient/http/errors.hpp>
#include "Logging.h" #include "Logging.h"
@ -28,10 +28,10 @@ class RoomDirectoryModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
public: public:
explicit RoomDirectoryModel explicit RoomDirectoryModel(QObject *parent = nullptr, const std::string &s = "");
(QObject *parent = nullptr, const std::string &s = "");
enum Roles { enum Roles
{
Name = Qt::UserRole, Name = Qt::UserRole,
Id, Id,
AvatarUrl, AvatarUrl,
@ -45,8 +45,8 @@ public:
inline int rowCount(const QModelIndex &parent = QModelIndex()) const override inline int rowCount(const QModelIndex &parent = QModelIndex()) const override
{ {
(void) parent; (void)parent;
return static_cast<int> (publicRoomsData_.size()); return static_cast<int>(publicRoomsData_.size());
} }
inline bool canFetchMore(const QModelIndex &) const override inline bool canFetchMore(const QModelIndex &) const override
@ -60,13 +60,15 @@ public:
signals: signals:
void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms, void fetchedRoomsBatch(std::vector<mtx::responses::PublicRoomsChunk> rooms,
const std::string &prev_batch, const std::string &next_batch); const std::string &prev_batch,
const std::string &next_batch);
void serverChanged(); void serverChanged();
void searchTermEntered(); void searchTermEntered();
public slots: public slots:
void displayRooms(std::vector<mtx::responses::PublicRoomsChunk> rooms, void displayRooms(std::vector<mtx::responses::PublicRoomsChunk> rooms,
const std::string &prev, const std::string &next); const std::string &prev,
const std::string &next);
void setMatrixServer(const QString &s = ""); void setMatrixServer(const QString &s = "");
void setSearchTerm(const QString &f); void setSearchTerm(const QString &f);