From ec4110c63443e29c78fdf0f72af08f5395ec48f7 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Thu, 26 Mar 2020 13:25:09 +0100 Subject: Refactoring around Connection::onSyncSuccess() The method grew large and a bit unwieldy over the years. --- lib/events/event.h | 11 +++++++++++ lib/events/roomkeyevent.cpp | 6 ++---- lib/events/roomkeyevent.h | 14 ++++---------- 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'lib/events') 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 visit(const BaseEventT& event, FnT1&& visitor1, return visit(event, std::forward(visitor2), std::forward(visitors)...); } + +// A facility overload that calls void-returning visit() on each event +// over a range of event pointers +template +inline auto visitEach(RangeT&& events, FnTs&&... visitors) + -> std::enable_if_t, Event>> +{ + for (auto&& evtPtr: events) + visit(*evtPtr, std::forward(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("algorithm"_ls); } + QString roomId() const { return content("room_id"_ls); } + QString sessionId() const { return content("session_id"_ls); } + QString sessionKey() const { return content("session_key"_ls); } }; REGISTER_EVENT_TYPE(RoomKeyEvent) } // namespace Quotient -- cgit v1.2.3