aboutsummaryrefslogtreecommitdiff
path: root/lib/events/stateevent.h
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2019-06-24 07:21:13 +0900
commit63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408 (patch)
tree2552f5049a6ef7ba0034483b25ca4ab33d1fcb13 /lib/events/stateevent.h
parente083d327e6f6581210f8d077d8bbe1151e81e82c (diff)
parent93f0c8fe89f448d1d58caa757573f17102369471 (diff)
downloadlibquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.tar.gz
libquotient-63ae79c3e2820efc2ba60d33e2caf2d7b9b3c408.zip
Merge branch 'master' into clang-format
# Conflicts: # CMakeLists.txt # lib/avatar.cpp # lib/connection.cpp # lib/connection.h # lib/connectiondata.cpp # lib/csapi/account-data.cpp # lib/csapi/account-data.h # lib/csapi/capabilities.cpp # lib/csapi/capabilities.h # lib/csapi/content-repo.cpp # lib/csapi/create_room.cpp # lib/csapi/filter.cpp # lib/csapi/joining.cpp # lib/csapi/keys.cpp # lib/csapi/list_joined_rooms.cpp # lib/csapi/notifications.cpp # lib/csapi/openid.cpp # lib/csapi/presence.cpp # lib/csapi/pushrules.cpp # lib/csapi/registration.cpp # lib/csapi/room_upgrades.cpp # lib/csapi/room_upgrades.h # lib/csapi/search.cpp # lib/csapi/users.cpp # lib/csapi/versions.cpp # lib/csapi/whoami.cpp # lib/csapi/{{base}}.cpp.mustache # lib/events/accountdataevents.h # lib/events/eventcontent.h # lib/events/roommemberevent.cpp # lib/events/stateevent.cpp # lib/jobs/basejob.cpp # lib/jobs/basejob.h # lib/networkaccessmanager.cpp # lib/networksettings.cpp # lib/room.cpp # lib/room.h # lib/settings.cpp # lib/settings.h # lib/syncdata.cpp # lib/user.cpp # lib/user.h # lib/util.cpp
Diffstat (limited to 'lib/events/stateevent.h')
-rw-r--r--lib/events/stateevent.h189
1 files changed, 95 insertions, 94 deletions
diff --git a/lib/events/stateevent.h b/lib/events/stateevent.h
index 1a02646b..8a89c86c 100644
--- a/lib/events/stateevent.h
+++ b/lib/events/stateevent.h
@@ -20,110 +20,111 @@
#include "roomevent.h"
-namespace QMatrixClient {
- class StateEventBase : public RoomEvent
- {
- public:
- using factory_t = EventFactory<StateEventBase>;
+namespace QMatrixClient
+{
+class StateEventBase : public RoomEvent
+{
+public:
+ using factory_t = EventFactory<StateEventBase>;
- using RoomEvent::RoomEvent;
- ~StateEventBase() override = default;
+ using RoomEvent::RoomEvent;
+ ~StateEventBase() override = default;
- bool isStateEvent() const override { return true; }
- QString replacedState() const;
- void dumpTo(QDebug dbg) const override;
+ bool isStateEvent() const override { return true; }
+ QString replacedState() const;
+ void dumpTo(QDebug dbg) const override;
- virtual bool repeatsState() const;
- };
- using StateEventPtr = event_ptr_tt<StateEventBase>;
- using StateEvents = EventsArray<StateEventBase>;
+ virtual bool repeatsState() const;
+};
+using StateEventPtr = event_ptr_tt<StateEventBase>;
+using StateEvents = EventsArray<StateEventBase>;
- template <> inline bool is<StateEventBase>(const Event& e)
- {
- return e.isStateEvent();
- }
+template <>
+inline bool is<StateEventBase>(const Event& e)
+{
+ return e.isStateEvent();
+}
+
+/**
+ * A combination of event type and state key uniquely identifies a piece
+ * of state in Matrix.
+ * \sa
+ * https://matrix.org/docs/spec/client_server/unstable.html#types-of-room-events
+ */
+using StateEventKey = QPair<QString, QString>;
- /**
- * A combination of event type and state key uniquely identifies a piece
- * of state in Matrix.
- * \sa
- * https://matrix.org/docs/spec/client_server/unstable.html#types-of-room-events
- */
- using StateEventKey = QPair<QString, QString>;
+template <typename ContentT>
+struct Prev
+{
+ template <typename... ContentParamTs>
+ explicit Prev(const QJsonObject& unsignedJson,
+ ContentParamTs&&... contentParams)
+ : senderId(unsignedJson.value("prev_sender"_ls).toString())
+ , content(unsignedJson.value(PrevContentKeyL).toObject(),
+ std::forward<ContentParamTs>(contentParams)...)
+ {}
- template <typename ContentT> struct Prev {
- template <typename... ContentParamTs>
- explicit Prev(const QJsonObject& unsignedJson,
- ContentParamTs&&... contentParams)
- : senderId(unsignedJson.value("prev_sender"_ls).toString()),
- content(unsignedJson.value(PrevContentKeyL).toObject(),
- std::forward<ContentParamTs>(contentParams)...)
- {
- }
+ QString senderId;
+ ContentT content;
+};
- QString senderId;
- ContentT content;
- };
+template <typename ContentT>
+class StateEvent : public StateEventBase
+{
+public:
+ using content_type = ContentT;
- template <typename ContentT> class StateEvent : public StateEventBase
+ template <typename... ContentParamTs>
+ explicit StateEvent(Type type, const QJsonObject& fullJson,
+ ContentParamTs&&... contentParams)
+ : StateEventBase(type, fullJson)
+ , _content(contentJson(), std::forward<ContentParamTs>(contentParams)...)
{
- public:
- using content_type = ContentT;
-
- template <typename... ContentParamTs>
- explicit StateEvent(Type type, const QJsonObject& fullJson,
- ContentParamTs&&... contentParams)
- : StateEventBase(type, fullJson),
- _content(contentJson(),
- std::forward<ContentParamTs>(contentParams)...)
- {
- const auto& unsignedData = unsignedJson();
- if (unsignedData.contains(PrevContentKeyL))
- _prev = std::make_unique<Prev<ContentT>>(
- unsignedData,
- std::forward<ContentParamTs>(contentParams)...);
- }
- template <typename... ContentParamTs>
- explicit StateEvent(Type type, event_mtype_t matrixType,
- ContentParamTs&&... contentParams)
- : StateEventBase(type, matrixType),
- _content(std::forward<ContentParamTs>(contentParams)...)
- {
- editJson().insert(ContentKey, _content.toJson());
- }
+ const auto& unsignedData = unsignedJson();
+ if (unsignedData.contains(PrevContentKeyL))
+ _prev = std::make_unique<Prev<ContentT>>(
+ unsignedData, std::forward<ContentParamTs>(contentParams)...);
+ }
+ template <typename... ContentParamTs>
+ explicit StateEvent(Type type, event_mtype_t matrixType,
+ ContentParamTs&&... contentParams)
+ : StateEventBase(type, matrixType)
+ , _content(std::forward<ContentParamTs>(contentParams)...)
+ {
+ editJson().insert(ContentKey, _content.toJson());
+ }
- const ContentT& content() const { return _content; }
- template <typename VisitorT> void editContent(VisitorT&& visitor)
- {
- visitor(_content);
- editJson()[ContentKeyL] = _content.toJson();
- }
- [[deprecated("Use prevContent instead")]] const ContentT*
- prev_content() const
- {
- return prevContent();
- }
- const ContentT* prevContent() const
- {
- return _prev ? &_prev->content : nullptr;
- }
- QString prevSenderId() const
- {
- return _prev ? _prev->senderId : QString();
- }
+ const ContentT& content() const { return _content; }
+ template <typename VisitorT>
+ void editContent(VisitorT&& visitor)
+ {
+ visitor(_content);
+ editJson()[ContentKeyL] = _content.toJson();
+ }
+ [[deprecated("Use prevContent instead")]] const ContentT* prev_content() const
+ {
+ return prevContent();
+ }
+ const ContentT* prevContent() const
+ {
+ return _prev ? &_prev->content : nullptr;
+ }
+ QString prevSenderId() const { return _prev ? _prev->senderId : QString(); }
- private:
- ContentT _content;
- std::unique_ptr<Prev<ContentT>> _prev;
- };
+private:
+ ContentT _content;
+ std::unique_ptr<Prev<ContentT>> _prev;
+};
} // namespace QMatrixClient
-namespace std {
- template <> struct hash<QMatrixClient::StateEventKey> {
- size_t
- operator()(const QMatrixClient::StateEventKey& k) const Q_DECL_NOEXCEPT
- {
- return qHash(k);
- }
- };
-}
+namespace std
+{
+template <>
+struct hash<QMatrixClient::StateEventKey>
+{
+ size_t operator()(const QMatrixClient::StateEventKey& k) const Q_DECL_NOEXCEPT
+ {
+ return qHash(k);
+ }
+};
+} // namespace std