diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-03-01 20:12:43 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-03-01 20:12:43 +0900 |
commit | 646ee63846c8985b6222ae1096ccc970a1834ce5 (patch) | |
tree | 0544391952c7899012a84b2e45f128cb10a21bd6 /events/tagevent.h | |
parent | 9ff04e98d62f93a7a6003fc80d189e96c6835f84 (diff) | |
download | libquotient-646ee63846c8985b6222ae1096ccc970a1834ce5.tar.gz libquotient-646ee63846c8985b6222ae1096ccc970a1834ce5.zip |
Fix tags saving/restoring (finally)
Closes #134.
Diffstat (limited to 'events/tagevent.h')
-rw-r--r-- | events/tagevent.h | 27 |
1 files changed, 25 insertions, 2 deletions
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() }} }}; + } } |