aboutsummaryrefslogtreecommitdiff
path: root/events
diff options
context:
space:
mode:
Diffstat (limited to 'events')
-rw-r--r--events/tagevent.cpp21
-rw-r--r--events/tagevent.h27
2 files changed, 46 insertions, 2 deletions
diff --git a/events/tagevent.cpp b/events/tagevent.cpp
index c6297003..886a10c6 100644
--- a/events/tagevent.cpp
+++ b/events/tagevent.cpp
@@ -24,6 +24,12 @@ TagRecord::TagRecord(const QJsonObject& json)
: order(json.value("order").toString())
{ }
+TagEvent::TagEvent()
+ : Event(Type::Tag)
+{
+ // TODO: Support getting a list of tags and saving it
+}
+
TagEvent::TagEvent(const QJsonObject& obj)
: Event(Type::Tag, obj)
{
@@ -44,6 +50,21 @@ QHash<QString, TagRecord> TagEvent::tags() const
return result;
}
+bool TagEvent::empty() const
+{
+ return tagsObject().empty();
+}
+
+bool TagEvent::contains(const QString& name) const
+{
+ return tagsObject().contains(name);
+}
+
+TagRecord TagEvent::recordForTag(const QString& name) const
+{
+ return TagRecord(tagsObject().value(name).toObject());
+}
+
QJsonObject TagEvent::tagsObject() const
{
return contentJson().value("tags").toObject();
diff --git a/events/tagevent.h b/events/tagevent.h
index 44a7e49a..26fe8788 100644
--- a/events/tagevent.h
+++ b/events/tagevent.h
@@ -35,6 +35,7 @@ namespace QMatrixClient
class TagEvent : public Event
{
public:
+ TagEvent();
explicit TagEvent(const QJsonObject& obj);
/** Get the list of tag names */
@@ -43,9 +44,31 @@ namespace QMatrixClient
/** Get the list of tags along with information on each */
QHash<QString, TagRecord> tags() const;
- static constexpr const char * TypeId = "m.tag";
+ /** Check if the event lists no tags */
+ bool empty() const;
+
+ /** Check whether the tags list contains the specified name */
+ bool contains(const QString& name) const;
- protected:
+ /** Get the record for the given tag name */
+ TagRecord recordForTag(const QString& name) const;
+
+ /** Get the whole tags content as a JSON object
+ * It's NOT recommended to use this method directly from client code.
+ * Use other convenience methods provided by the class.
+ */
QJsonObject tagsObject() const;
+
+ static constexpr const char * TypeId = "m.tag";
};
+
+ using TagEventPtr = event_ptr_tt<TagEvent>;
+
+ inline QJsonValue toJson(const TagEventPtr& tagEvent)
+ {
+ return QJsonObject {{ "type", "m.tag" },
+ // TODO: Replace tagsObject() with a genuine list of tags
+ // (or make the needed JSON upon TagEvent creation)
+ { "content", QJsonObject {{ "tags", tagEvent->tagsObject() }} }};
+ }
}