From 646ee63846c8985b6222ae1096ccc970a1834ce5 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 1 Mar 2018 20:12:43 +0900 Subject: Fix tags saving/restoring (finally) Closes #134. --- events/tagevent.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'events/tagevent.h') 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 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; + + 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() }} }}; + } } -- cgit v1.2.3