diff options
Diffstat (limited to 'events/tagevent.cpp')
-rw-r--r-- | events/tagevent.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/events/tagevent.cpp b/events/tagevent.cpp new file mode 100644 index 00000000..9f381c76 --- /dev/null +++ b/events/tagevent.cpp @@ -0,0 +1,42 @@ +#include "tagevent.h" + +using namespace QMatrixClient; + +TagRecord::TagRecord(const QJsonObject& json) + : order(json.value("order").toString()) +{ } + +TagEvent::TagEvent(const QJsonObject& obj) + : Event(Type::Tag, obj) +{ + Q_ASSERT(obj["type"].toString() == TypeId); +} + +QStringList TagEvent::tagNames() const +{ + return tagsObject().keys(); +} + +QHash<QString, TagRecord> TagEvent::tags() const +{ + QHash<QString, TagRecord> result; + auto allTags { tagsObject() }; + for (auto it = allTags.begin(); it != allTags.end(); ++ it) + result.insert(it.key(), TagRecord(it.value().toObject())); + return result; +} + +bool TagEvent::isFavourite() const +{ + return tagsObject().contains("m.favourite"); +} + +bool TagEvent::isLowPriority() const +{ + return tagsObject().contains("m.lowpriority"); +} + +QJsonObject TagEvent::tagsObject() const +{ + return contentJson().value("tags").toObject(); +} |