diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-31 08:53:32 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2017-12-31 08:53:32 +0900 |
commit | 0b5f0deb773f850d1b905fafc656f67f5b63de24 (patch) | |
tree | b5e0ad5a4558a86d9c95a5d14cc3595e0fa2b5d8 /events | |
parent | cbfe29b3435fbe47fee268facbe6a82000fce0ad (diff) | |
parent | 2c440249052b0d518fccd953a7dc657f9eed7ab7 (diff) | |
download | libquotient-0b5f0deb773f850d1b905fafc656f67f5b63de24.tar.gz libquotient-0b5f0deb773f850d1b905fafc656f67f5b63de24.zip |
Merge branch 'master' into kitsune-gtad
Diffstat (limited to 'events')
-rw-r--r-- | events/event.cpp | 10 | ||||
-rw-r--r-- | events/event.h | 27 |
2 files changed, 31 insertions, 6 deletions
diff --git a/events/event.cpp b/events/event.cpp index e74bc114..c7345a13 100644 --- a/events/event.cpp +++ b/events/event.cpp @@ -144,3 +144,13 @@ RoomEventPtr _impl::doMakeEvent(const QJsonObject& obj) RoomAvatarEvent, EncryptionEvent, RedactionEvent> (obj, obj["type"].toString()) }; } + +StateEventBase::~StateEventBase() = default; + +bool StateEventBase::repeatsState() const +{ + auto contentJson = originalJsonObject().value("content"); + auto prevContentJson = originalJsonObject().value("unsigned") + .toObject().value("prev_content"); + return contentJson == prevContentJson; +} diff --git a/events/event.h b/events/event.h index d4923f1f..319c3443 100644 --- a/events/event.h +++ b/events/event.h @@ -240,8 +240,23 @@ namespace QMatrixClient RoomEvents::iterator end() { return to; } }; + class StateEventBase: public RoomEvent + { + public: + explicit StateEventBase(Type type, const QJsonObject& obj) + : RoomEvent(obj.contains("state_key") ? type : Type::Unknown, + obj) + { } + explicit StateEventBase(Type type) + : RoomEvent(type) + { } + ~StateEventBase() override = 0; + + virtual bool repeatsState() const; + }; + template <typename ContentT> - class StateEvent: public RoomEvent + class StateEvent: public StateEventBase { public: using content_type = ContentT; @@ -249,19 +264,19 @@ namespace QMatrixClient template <typename... ContentParamTs> explicit StateEvent(Type type, const QJsonObject& obj, ContentParamTs&&... contentParams) - : RoomEvent(obj.contains("state_key") ? type : Type::Unknown, - obj) + : StateEventBase(type, obj) , _content(contentJson(), std::forward<ContentParamTs>(contentParams)...) { - if (obj.contains("prev_content")) + auto unsignedData = obj.value("unsigned").toObject(); + if (unsignedData.contains("prev_content")) _prev.reset(new ContentT( - obj["prev_content"].toObject(), + unsignedData.value("prev_content").toObject(), std::forward<ContentParamTs>(contentParams)...)); } template <typename... ContentParamTs> explicit StateEvent(Type type, ContentParamTs&&... contentParams) - : RoomEvent(type) + : StateEventBase(type) , _content(std::forward<ContentParamTs>(contentParams)...) { } |