From ec412621d71b1a7758b15d2b3c5cd5e7b2081ab1 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 25 Feb 2018 18:57:02 +0900 Subject: Room and Connection: support room tags Closes #134. --- connection.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index 4b7d4abb..52fcc40b 100644 --- a/connection.cpp +++ b/connection.cpp @@ -520,6 +520,30 @@ QHash< QPair, Room* > Connection::roomMap() const return roomMap; } +QHash> Connection::tagsToRooms() const +{ + QHash> result; + for (auto* r: d->roomMap) + { + for (const auto& tagName: r->tagNames()) + result[tagName].push_back(r); + } + for (auto it = result.begin(); it != result.end(); ++it) + std::sort(it->begin(), it->end(), + [t=it.key()] (Room* r1, Room* r2) { + return r1->tags().value(t).order < r2->tags().value(t).order; + }); + return result; +} + +QVector Connection::roomsWithTag(const QString& tagName) const +{ + QVector rooms; + std::copy_if(d->roomMap.begin(), d->roomMap.end(), std::back_inserter(rooms), + [&tagName] (Room* r) { return r->tags().contains(tagName); }); + return rooms; +} + QMap Connection::users() const { return d->userMap; -- cgit v1.2.3 From 979756e26af57e715efe64f8de8068243fa27e9f Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Mon, 26 Feb 2018 11:09:34 +0900 Subject: Deal with memory more carefully Plugs some memory leaks reported by Valgrind. --- connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index 52fcc40b..7b72c592 100644 --- a/connection.cpp +++ b/connection.cpp @@ -599,7 +599,7 @@ Room* Connection::provideRoom(const QString& id, JoinState joinState) { qCDebug(MAIN) << "Deleting Invite state for room" << prevInvite->id(); emit aboutToDeleteRoom(prevInvite); - delete prevInvite; + prevInvite->deleteLater(); } } -- cgit v1.2.3 From f366cb25d1a5256341c1253fb04e36bd70373a70 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 27 Feb 2018 11:36:42 +0900 Subject: Room: Save tags in the cache; isFavourite() and isLowPriority() --- connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'connection.cpp') diff --git a/connection.cpp b/connection.cpp index 7b72c592..9a5a5a4e 100644 --- a/connection.cpp +++ b/connection.cpp @@ -627,7 +627,7 @@ void Connection::setHomeserver(const QUrl& url) emit homeserverChanged(homeserver()); } -static constexpr int CACHE_VERSION_MAJOR = 2; +static constexpr int CACHE_VERSION_MAJOR = 3; static constexpr int CACHE_VERSION_MINOR = 0; void Connection::saveState(const QUrl &toFile) const -- cgit v1.2.3