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 +- room.cpp | 29 +++++++++++++++++++++++++++++ room.h | 9 +++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) 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 diff --git a/room.cpp b/room.cpp index 29244da2..db36a713 100644 --- a/room.cpp +++ b/room.cpp @@ -564,6 +564,21 @@ const QHash& Room::tags() const return d->tags; } +TagRecord Room::tag(const QString& name) const +{ + return d->tags.value(name); +} + +bool Room::isFavourite() const +{ + return d->tags.contains(FavouriteTag); +} + +bool Room::isLowPriority() const +{ + return d->tags.contains(LowPriorityTag); +} + const RoomMessageEvent* Room::Private::getEventWithFile(const QString& eventId) const { @@ -1635,6 +1650,20 @@ QJsonObject Room::Private::toJson() const result.insert("ephemeral", ephemeralObj); } + { + QJsonObject accountDataObj; + if (!tags.empty()) + { + QJsonObject tagsObj; + for (auto it = tags.begin(); it != tags.end(); ++it) + tagsObj.insert(it.key(), { {"order", it->order} }); + if (!tagsObj.empty()) + accountDataObj.insert("m.tag", tagsObj); + } + if (!accountDataObj.empty()) + result.insert("account_data", accountDataObj); + } + QJsonObject unreadNotificationsObj; if (highlightCount > 0) unreadNotificationsObj.insert("highlight_count", highlightCount); diff --git a/room.h b/room.h index 6dba6156..8e27a608 100644 --- a/room.h +++ b/room.h @@ -242,6 +242,15 @@ namespace QMatrixClient QStringList tagNames() const; const QHash& tags() const; + TagRecord tag(const QString& name) const; + + /** Check whether the list of tags has m.favourite */ + bool isFavourite() const; + /** Check whether the list of tags has m.lowpriority */ + bool isLowPriority() const; + + /** Check whether this room is a direct chat */ + bool isDirectChat() const; Q_INVOKABLE QUrl urlToThumbnail(const QString& eventId); Q_INVOKABLE QUrl urlToDownload(const QString& eventId); -- cgit v1.2.3