diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-26 13:25:09 +0100 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-03-26 13:25:09 +0100 |
commit | ec4110c63443e29c78fdf0f72af08f5395ec48f7 (patch) | |
tree | 9231a07da3124c70758ffa370be8c3ebb8eca3f7 /lib/events | |
parent | 3ba2acce470407854bb38b2633675e916a51a904 (diff) | |
download | libquotient-ec4110c63443e29c78fdf0f72af08f5395ec48f7.tar.gz libquotient-ec4110c63443e29c78fdf0f72af08f5395ec48f7.zip |
Refactoring around Connection::onSyncSuccess()
The method grew large and a bit unwieldy over the years.
Diffstat (limited to 'lib/events')
-rw-r--r-- | lib/events/event.h | 11 | ||||
-rw-r--r-- | lib/events/roomkeyevent.cpp | 6 | ||||
-rw-r--r-- | lib/events/roomkeyevent.h | 14 |
3 files changed, 17 insertions, 14 deletions
diff --git a/lib/events/event.h b/lib/events/event.h index f985ae92..6c8961ad 100644 --- a/lib/events/event.h +++ b/lib/events/event.h @@ -377,6 +377,17 @@ inline fn_return_t<FnT1> visit(const BaseEventT& event, FnT1&& visitor1, return visit(event, std::forward<FnT2>(visitor2), std::forward<FnTs>(visitors)...); } + +// A facility overload that calls void-returning visit() on each event +// over a range of event pointers +template <typename RangeT, typename... FnTs> +inline auto visitEach(RangeT&& events, FnTs&&... visitors) + -> std::enable_if_t<std::is_convertible_v< + std::decay_t<decltype(**events.begin())>, Event>> +{ + for (auto&& evtPtr: events) + visit(*evtPtr, std::forward<FnTs>(visitors)...); +} } // namespace Quotient Q_DECLARE_METATYPE(Quotient::Event*) Q_DECLARE_METATYPE(const Quotient::Event*) diff --git a/lib/events/roomkeyevent.cpp b/lib/events/roomkeyevent.cpp index 1fb2e9f5..66580430 100644 --- a/lib/events/roomkeyevent.cpp +++ b/lib/events/roomkeyevent.cpp @@ -4,8 +4,6 @@ using namespace Quotient; RoomKeyEvent::RoomKeyEvent(const QJsonObject &obj) : Event(typeId(), obj) { - _algorithm = contentJson()["algorithm"_ls].toString(); - _roomId = contentJson()["room_id"_ls].toString(); - _sessionId = contentJson()["session_id"_ls].toString(); - _sessionKey = contentJson()["session_key"_ls].toString(); + if (roomId().isEmpty()) + qCWarning(E2EE) << "Room key event has empty room id"; } diff --git a/lib/events/roomkeyevent.h b/lib/events/roomkeyevent.h index e4bcfd71..679cbf7c 100644 --- a/lib/events/roomkeyevent.h +++ b/lib/events/roomkeyevent.h @@ -10,16 +10,10 @@ public: RoomKeyEvent(const QJsonObject& obj); - const QString algorithm() const { return _algorithm; } - const QString roomId() const { return _roomId; } - const QString sessionId() const { return _sessionId; } - const QString sessionKey() const { return _sessionKey; } - -private: - QString _algorithm; - QString _roomId; - QString _sessionId; - QString _sessionKey; + QString algorithm() const { return content<QString>("algorithm"_ls); } + QString roomId() const { return content<QString>("room_id"_ls); } + QString sessionId() const { return content<QString>("session_id"_ls); } + QString sessionKey() const { return content<QString>("session_key"_ls); } }; REGISTER_EVENT_TYPE(RoomKeyEvent) } // namespace Quotient |