aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/connection.cpp4
-rw-r--r--lib/converters.cpp4
-rw-r--r--lib/events/typingevent.cpp1
-rw-r--r--lib/jobs/downloadfilejob.cpp2
-rw-r--r--lib/networkaccessmanager.cpp7
-rw-r--r--lib/room.cpp55
-rw-r--r--lib/uri.cpp8
-rw-r--r--lib/uriresolver.cpp2
-rw-r--r--lib/user.cpp4
-rw-r--r--lib/util.cpp5
-rw-r--r--tests/quotest.cpp38
11 files changed, 68 insertions, 62 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp
index 8c51c84c..b037bf49 100644
--- a/lib/connection.cpp
+++ b/lib/connection.cpp
@@ -929,8 +929,8 @@ void Connection::doInDirectChat(User* u,
// There can be more than one DC; find the first valid (existing and
// not left), and delete inexistent (forgotten?) ones along the way.
DirectChatsMap removals;
- for (auto it = std::as_const(d->directChats).find(u);
- it != d->directChats.end() && it.key() == u; ++it) {
+ for (auto it = d->directChats.constFind(u);
+ it != d->directChats.cend() && it.key() == u; ++it) {
const auto& roomId = *it;
if (auto r = room(roomId, JoinState::Join)) {
Q_ASSERT(r->id() == roomId);
diff --git a/lib/converters.cpp b/lib/converters.cpp
index e5236bb9..9f570087 100644
--- a/lib/converters.cpp
+++ b/lib/converters.cpp
@@ -32,9 +32,9 @@ QVariant JsonConverter<QVariant>::load(const QJsonValue& jv)
return jv.toVariant();
}
-QJsonObject JsonConverter<QVariantHash>::dump(const QVariantHash& map)
+QJsonObject JsonConverter<QVariantHash>::dump(const QVariantHash& vh)
{
- return QJsonObject::fromVariantHash(map);
+ return QJsonObject::fromVariantHash(vh);
}
QVariantHash JsonConverter<QVariantHash>::load(const QJsonValue& jv)
diff --git a/lib/events/typingevent.cpp b/lib/events/typingevent.cpp
index 0c5fc6ba..a95d2f0d 100644
--- a/lib/events/typingevent.cpp
+++ b/lib/events/typingevent.cpp
@@ -25,6 +25,7 @@ using namespace Quotient;
TypingEvent::TypingEvent(const QJsonObject& obj) : Event(typeId(), obj)
{
const auto& array = contentJson()["user_ids"_ls].toArray();
+ _users.reserve(array.size());
for (const auto& user : array)
_users.push_back(user.toString());
}
diff --git a/lib/jobs/downloadfilejob.cpp b/lib/jobs/downloadfilejob.cpp
index 7b4cf690..0011a97c 100644
--- a/lib/jobs/downloadfilejob.cpp
+++ b/lib/jobs/downloadfilejob.cpp
@@ -64,7 +64,7 @@ void DownloadFileJob::onSentRequest(QNetworkReply* reply)
return;
auto sizeHeader = reply->header(QNetworkRequest::ContentLengthHeader);
if (sizeHeader.isValid()) {
- auto targetSize = sizeHeader.value<qint64>();
+ auto targetSize = sizeHeader.toLongLong();
if (targetSize != -1)
if (!d->tempFile->resize(targetSize)) {
qCWarning(JOBS) << "Failed to allocate" << targetSize
diff --git a/lib/networkaccessmanager.cpp b/lib/networkaccessmanager.cpp
index b9037bcc..e8aa85df 100644
--- a/lib/networkaccessmanager.cpp
+++ b/lib/networkaccessmanager.cpp
@@ -52,9 +52,10 @@ static NetworkAccessManager* createNam()
auto nam = new NetworkAccessManager(QCoreApplication::instance());
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
// See #109; in newer Qt, bearer management is deprecated altogether
- nam->connect(nam, &QNetworkAccessManager::networkAccessibleChanged, [nam] {
- nam->setNetworkAccessible(QNetworkAccessManager::Accessible);
- });
+ NetworkAccessManager::connect(nam,
+ &QNetworkAccessManager::networkAccessibleChanged, [nam] {
+ nam->setNetworkAccessible(QNetworkAccessManager::Accessible);
+ });
#endif
return nam;
}
diff --git a/lib/room.cpp b/lib/room.cpp
index a5ed76a8..fcc22436 100644
--- a/lib/room.cpp
+++ b/lib/room.cpp
@@ -366,7 +366,7 @@ public:
*/
bool processReplacement(const RoomMessageEvent& newEvent);
- void setTags(TagsMap newTags);
+ void setTags(TagsMap&& newTags);
QJsonObject toJson() const;
@@ -1089,11 +1089,11 @@ void Room::setTags(TagsMap newTags, ActionScope applyOn)
if (propagate) {
for (auto* r = this; (r = r->successor(joinStates));)
- r->setTags(newTags, ActionScope::ThisRoomOnly);
+ r->setTags(d->tags, ActionScope::ThisRoomOnly);
}
}
-void Room::Private::setTags(TagsMap newTags)
+void Room::Private::setTags(TagsMap&& newTags)
{
emit q->tagsAboutToChange();
const auto keys = newTags.keys();
@@ -1208,8 +1208,8 @@ QString Room::fileNameToDownload(const QString& eventId) const
FileTransferInfo Room::fileTransferInfo(const QString& id) const
{
- auto infoIt = d->fileTransfers.find(id);
- if (infoIt == d->fileTransfers.end())
+ const auto infoIt = d->fileTransfers.constFind(id);
+ if (infoIt == d->fileTransfers.cend())
return {};
// FIXME: Add lib tests to make sure FileTransferInfo::status stays
@@ -1238,8 +1238,8 @@ QUrl Room::fileSource(const QString& id) const
return url;
// No urlToDownload means it's a pending or completed upload.
- auto infoIt = d->fileTransfers.find(id);
- if (infoIt != d->fileTransfers.end())
+ auto infoIt = d->fileTransfers.constFind(id);
+ if (infoIt != d->fileTransfers.cend())
return QUrl::fromLocalFile(infoIt->localFileInfo.absoluteFilePath());
qCWarning(MAIN) << "File source for identifier" << id << "not found";
@@ -1285,7 +1285,7 @@ const StateEventBase* Room::getCurrentState(const QString& evtType,
RoomEventPtr Room::decryptMessage(const EncryptedEvent& encryptedEvent)
{
#ifndef Quotient_E2EE_ENABLED
- Q_UNUSED(encryptedEvent);
+ Q_UNUSED(encryptedEvent)
qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
return {};
#else // Quotient_E2EE_ENABLED
@@ -1310,10 +1310,9 @@ void Room::handleRoomKeyEvent(const RoomKeyEvent& roomKeyEvent,
const QString& senderKey)
{
#ifndef Quotient_E2EE_ENABLED
- Q_UNUSED(roomKeyEvent);
- Q_UNUSED(senderKey);
+ Q_UNUSED(roomKeyEvent)
+ Q_UNUSED(senderKey)
qCWarning(E2EE) << "End-to-end encryption (E2EE) support is turned off.";
- return;
#else // Quotient_E2EE_ENABLED
if (roomKeyEvent.algorithm() != MegolmV1AesSha2AlgoKey) {
qCWarning(E2EE) << "Ignoring unsupported algorithm"
@@ -1433,7 +1432,7 @@ Room::Private::moveEventsToTimeline(RoomEventsRange events,
}
const auto insertedSize = (index - baseIndex) * placement;
Q_ASSERT(insertedSize == int(events.size()));
- return insertedSize;
+ return Timeline::size_type(insertedSize);
}
QString Room::roomMembername(const User* u) const
@@ -1615,8 +1614,8 @@ QString Room::retryMessage(const QString& txnId)
const auto it = findPendingEvent(txnId);
Q_ASSERT(it != d->unsyncedEvents.end());
qCDebug(EVENTS) << "Retrying transaction" << txnId;
- const auto& transferIt = d->fileTransfers.find(txnId);
- if (transferIt != d->fileTransfers.end()) {
+ const auto& transferIt = d->fileTransfers.constFind(txnId);
+ if (transferIt != d->fileTransfers.cend()) {
Q_ASSERT(transferIt->isUpload);
if (transferIt->status == FileTransferInfo::Completed) {
qCDebug(MESSAGES)
@@ -1713,7 +1712,8 @@ QString Room::postFile(const QString& plainText, const QUrl& localPath,
// to enable the preview while the event is pending.
uploadFile(txnId, localPath);
// Below, the upload job is used as a context object to clean up connections
- connect(this, &Room::fileTransferCompleted, d->fileTransfers[txnId].job,
+ const auto& transferJob = d->fileTransfers.value(txnId).job;
+ connect(this, &Room::fileTransferCompleted, transferJob,
[this, txnId](const QString& id, const QUrl&, const QUrl& mxcUri) {
if (id == txnId) {
auto it = findPendingEvent(txnId);
@@ -1732,7 +1732,7 @@ QString Room::postFile(const QString& plainText, const QUrl& localPath,
}
}
});
- connect(this, &Room::fileTransferCancelled, d->fileTransfers[txnId].job,
+ connect(this, &Room::fileTransferCancelled, transferJob,
[this, txnId](const QString& id) {
if (id == txnId) {
auto it = findPendingEvent(txnId);
@@ -1940,8 +1940,8 @@ void Room::uploadFile(const QString& id, const QUrl& localFilename,
void Room::downloadFile(const QString& eventId, const QUrl& localFilename)
{
- auto ongoingTransfer = d->fileTransfers.find(eventId);
- if (ongoingTransfer != d->fileTransfers.end()
+ if (auto ongoingTransfer = d->fileTransfers.constFind(eventId);
+ ongoingTransfer != d->fileTransfers.cend()
&& ongoingTransfer->status == FileTransferInfo::Started) {
qCWarning(MAIN) << "Transfer for" << eventId
<< "is ongoing; download won't start";
@@ -1998,8 +1998,8 @@ void Room::downloadFile(const QString& eventId, const QUrl& localFilename)
void Room::cancelFileTransfer(const QString& id)
{
- auto it = d->fileTransfers.find(id);
- if (it == d->fileTransfers.end()) {
+ const auto it = d->fileTransfers.constFind(id);
+ if (it == d->fileTransfers.cend()) {
qCWarning(MAIN) << "No information on file transfer" << id << "in room"
<< d->id;
return;
@@ -2101,8 +2101,8 @@ bool Room::Private::processRedaction(const RedactionEvent& redaction)
{
// Can't use findInTimeline because it returns a const iterator, and
// we need to change the underlying TimelineItem.
- const auto pIdx = eventsIndex.find(redaction.redactedEvent());
- if (pIdx == eventsIndex.end())
+ const auto pIdx = eventsIndex.constFind(redaction.redactedEvent());
+ if (pIdx == eventsIndex.cend())
return false;
Q_ASSERT(q->isValidIndex(*pIdx));
@@ -2172,8 +2172,8 @@ bool Room::Private::processReplacement(const RoomMessageEvent& newEvent)
{
// Can't use findInTimeline because it returns a const iterator, and
// we need to change the underlying TimelineItem.
- const auto pIdx = eventsIndex.find(newEvent.replacedEvent());
- if (pIdx == eventsIndex.end())
+ const auto pIdx = eventsIndex.constFind(newEvent.replacedEvent());
+ if (pIdx == eventsIndex.cend())
return false;
Q_ASSERT(q->isValidIndex(*pIdx));
@@ -2418,12 +2418,11 @@ Room::Changes Room::processStateEvent(const RoomEvent& e)
if (!e.isStateEvent())
return Change::NoChange;
- // Find a value (create empty if necessary) and get a reference to it
- // getCurrentState<> is not used here because it (creates and) returns
+ // Find a value (create an empty one if necessary) and get a reference
+ // to it. Can't use getCurrentState<>() because it (creates and) returns
// a stub if a value is not found, and what's needed here is a "real" event
// or nullptr.
- const auto*& curStateEvent =
- d->currentState[{ e.matrixType(), e.stateKey() }];
+ auto& curStateEvent = d->currentState[{ e.matrixType(), e.stateKey() }];
// Prepare for the state change
const auto oldRme = static_cast<const RoomMemberEvent*>(curStateEvent);
visit(e, [this, &oldRme](const RoomMemberEvent& rme) {
diff --git a/lib/uri.cpp b/lib/uri.cpp
index 0e2bcb87..e0912eb6 100644
--- a/lib/uri.cpp
+++ b/lib/uri.cpp
@@ -32,7 +32,7 @@ Uri::Uri(QByteArray primaryId, QByteArray secondaryId, QString query)
primaryType_ = Type(p.sigil);
auto safePrimaryId = primaryId.mid(1);
safePrimaryId.replace('/', "%2F");
- pathToBe = p.uriString + std::move(safePrimaryId);
+ pathToBe = p.uriString + safePrimaryId;
break;
}
if (!secondaryId.isEmpty()) {
@@ -42,12 +42,12 @@ Uri::Uri(QByteArray primaryId, QByteArray secondaryId, QString query)
}
auto safeSecondaryId = secondaryId.mid(1);
safeSecondaryId.replace('/', "%2F");
- pathToBe += "/event/" + std::move(safeSecondaryId);
+ pathToBe += "/event/" + safeSecondaryId;
}
setPath(pathToBe, QUrl::TolerantMode);
}
if (!query.isEmpty())
- setQuery(std::move(query));
+ setQuery(query);
}
static inline auto encodedPath(const QUrl& url)
@@ -156,7 +156,7 @@ QUrl Uri::toUrl(UriForm form) const
return {};
if (form == CanonicalUri || type() == NonMatrix)
- return *this;
+ return *this; // NOLINT(cppcoreguidelines-slicing): It's intentional
QUrl url;
url.setScheme("https");
diff --git a/lib/uriresolver.cpp b/lib/uriresolver.cpp
index ec30512c..27360bcc 100644
--- a/lib/uriresolver.cpp
+++ b/lib/uriresolver.cpp
@@ -75,6 +75,8 @@ private:
std::tuple<FnTs...> fns_;
};
+template <typename... FnTs>
+StaticUriDispatcher(FnTs&&... fns) -> StaticUriDispatcher<FnTs...>;
UriResolveResult Quotient::visitResource(
Connection* account, const Uri& uri,
diff --git a/lib/user.cpp b/lib/user.cpp
index 3c9652b0..85f9d9a7 100644
--- a/lib/user.cpp
+++ b/lib/user.cpp
@@ -101,7 +101,7 @@ QString User::id() const { return d->id; }
bool User::isGuest() const
{
Q_ASSERT(!d->id.isEmpty() && d->id.startsWith('@'));
- auto it = std::find_if_not(d->id.begin() + 1, d->id.end(),
+ auto it = std::find_if_not(d->id.cbegin() + 1, d->id.cend(),
[](QChar c) { return c.isDigit(); });
Q_ASSERT(it != d->id.end());
return *it == ':';
@@ -203,7 +203,7 @@ bool User::Private::doSetAvatar(SourceT&& source, User* q)
return;
}
- defaultAvatar->updateUrl(move(newUrl));
+ defaultAvatar->updateUrl(newUrl);
emit q->avatarChanged(q, nullptr);
});
});
diff --git a/lib/util.cpp b/lib/util.cpp
index ffb36068..875d7522 100644
--- a/lib/util.cpp
+++ b/lib/util.cpp
@@ -161,9 +161,6 @@ static_assert(std::is_same<fn_arg_t<Fo1>, int>(),
"Test fn_arg_t defaulting to first argument");
template <typename T>
-static QString ft(T&&)
-{
- return {};
-}
+static QString ft(T&&);
static_assert(std::is_same<fn_arg_t<decltype(ft<QString>)>, QString&&>(),
"Test function templates");
diff --git a/tests/quotest.cpp b/tests/quotest.cpp
index 19d5eec0..29b33edb 100644
--- a/tests/quotest.cpp
+++ b/tests/quotest.cpp
@@ -104,17 +104,21 @@ private slots:
// Add more tests above here
public:
- Room* room() const { return targetRoom; }
- Connection* connection() const { return targetRoom->connection(); }
+ [[nodiscard]] Room* room() const { return targetRoom; }
+ [[nodiscard]] Connection* connection() const
+ {
+ return targetRoom->connection();
+ }
private:
- bool checkFileSendingOutcome(const TestToken& thisTest,
- const QString& txnId, const QString& fileName);
- bool checkRedactionOutcome(const QByteArray& thisTest,
- const QString& evtIdToRedact);
-
- bool validatePendingEvent(const QString& txnId);
- bool checkDirectChat() const;
+ [[nodiscard]] bool checkFileSendingOutcome(const TestToken& thisTest,
+ const QString& txnId,
+ const QString& fileName);
+ [[nodiscard]] bool checkRedactionOutcome(const QByteArray& thisTest,
+ const QString& evtIdToRedact);
+
+ [[nodiscard]] bool validatePendingEvent(const QString& txnId);
+ [[nodiscard]] bool checkDirectChat() const;
void finishTest(const TestToken& token, bool condition, const char* file,
int line);
@@ -185,7 +189,7 @@ TestManager::TestManager(int& argc, char** argv)
[this](const QString& error) {
clog << "Failed to resolve the server: " << error.toStdString()
<< endl;
- this->exit(-2);
+ QCoreApplication::exit(-2);
},
Qt::QueuedConnection);
connect(c, &Connection::loginError, this,
@@ -195,7 +199,7 @@ TestManager::TestManager(int& argc, char** argv)
<< message.toStdString() << endl
<< "Details:" << endl
<< details.toStdString() << endl;
- this->exit(-2);
+ QCoreApplication::exit(-2);
},
Qt::QueuedConnection);
connect(c, &Connection::loadedRoomState, this, &TestManager::onNewRoom);
@@ -320,7 +324,7 @@ TEST_IMPL(loadMembers)
FAIL_TEST();
}
r->setDisplayed();
- connect(r, &Room::allMembersLoaded, [this, thisTest, r] {
+ connect(r, &Room::allMembersLoaded, this, [this, thisTest, r] {
FINISH_TEST(r->memberNames().size() >= r->joinedCount());
});
return false;
@@ -748,7 +752,7 @@ TEST_IMPL(visitResources)
static const QStringList viaServers { "matrix.org", "example.org" };
static const auto viaQuery =
std::accumulate(viaServers.cbegin(), viaServers.cend(), joinQuery,
- [](QString q, const QString& s) {
+ [](const QString& q, const QString& s) {
return q + "&via=" + s;
});
static const QStringList joinByIdUris {
@@ -806,7 +810,8 @@ void TestManager::conclude()
// Now just wait until all the pending events reach the server
connectUntil(room, &Room::messageSent, this, [this, room, plainReport] {
const auto& pendingEvents = room->pendingEvents();
- if (auto c = std::count_if(pendingEvents.begin(), pendingEvents.end(),
+ if (auto c = std::count_if(pendingEvents.cbegin(),
+ pendingEvents.cend(),
[](const PendingEventItem& pe) {
return pe.deliveryStatus()
< EventStatus::ReachedServer;
@@ -837,8 +842,8 @@ void TestManager::finalize()
{
clog << "Logging out" << endl;
c->logout();
- connect(c, &Connection::loggedOut,
- this, [this] { this->exit(failed.size() + running.size()); },
+ connect(c, &Connection::loggedOut, this,
+ [this] { QCoreApplication::exit(failed.size() + running.size()); },
Qt::QueuedConnection);
}
@@ -850,6 +855,7 @@ int main(int argc, char* argv[])
<< endl;
return -1;
}
+ // NOLINTNEXTLINE(readability-static-accessed-through-instance)
return TestManager(argc, argv).exec();
}