diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-25 19:54:17 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-01-25 19:54:17 +0900 |
commit | 2f83e4be20a15013181c1ba6944e21f051ccac9d (patch) | |
tree | b6d1014f736b8c75e05e1dea8157e7ed04cc7820 /events/event.h | |
parent | d45298d5db97663f300879002a8e0ccdf6b8d523 (diff) | |
parent | 80f7e44e1a9056fc55147718dd2812eb93925ec1 (diff) | |
download | libquotient-2f83e4be20a15013181c1ba6944e21f051ccac9d.tar.gz libquotient-2f83e4be20a15013181c1ba6944e21f051ccac9d.zip |
Merge branch 'kitsune-avatar-url-properties'
Diffstat (limited to 'events/event.h')
-rw-r--r-- | events/event.h | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/events/event.h b/events/event.h index 6ed5ba49..b5a4d94e 100644 --- a/events/event.h +++ b/events/event.h @@ -256,6 +256,21 @@ namespace QMatrixClient }; template <typename ContentT> + struct Prev + { + template <typename... ContentParamTs> + explicit Prev(const QJsonObject& unsignedJson, + ContentParamTs&&... contentParams) + : senderId(unsignedJson.value("prev_sender").toString()) + , content(unsignedJson.value("prev_content").toObject(), + std::forward<ContentParamTs>(contentParams)...) + { } + + QString senderId; + ContentT content; + }; + + template <typename ContentT> class StateEvent: public StateEventBase { public: @@ -270,9 +285,8 @@ namespace QMatrixClient { auto unsignedData = obj.value("unsigned").toObject(); if (unsignedData.contains("prev_content")) - _prev.reset(new ContentT( - unsignedData.value("prev_content").toObject(), - std::forward<ContentParamTs>(contentParams)...)); + _prev = std::make_unique<Prev<ContentT>>(unsignedData, + std::forward<ContentParamTs>(contentParams)...); } template <typename... ContentParamTs> explicit StateEvent(Type type, ContentParamTs&&... contentParams) @@ -283,11 +297,15 @@ namespace QMatrixClient QJsonObject toJson() const { return _content.toJson(); } ContentT content() const { return _content; } - ContentT* prev_content() const { return _prev.data(); } + /** @deprecated Use prevContent instead */ + ContentT* prev_content() const { return prevContent(); } + ContentT* prevContent() const + { return _prev ? &_prev->content : nullptr; } + QString prevSenderId() const { return _prev ? _prev->senderId : ""; } protected: ContentT _content; - QScopedPointer<ContentT> _prev; + std::unique_ptr<Prev<ContentT>> _prev; }; } // namespace QMatrixClient Q_DECLARE_METATYPE(QMatrixClient::Event*) |