diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-02-20 01:04:49 +0100 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2023-02-20 01:04:49 +0100 |
commit | ac4c9e024ec84bc49f349426dbc382e138197435 (patch) | |
tree | 035268b0674d77b2ffa181a0b9ef0bef6a872649 /src/timeline | |
parent | Remove a few more unused symbols (diff) | |
download | nheko-ac4c9e024ec84bc49f349426dbc382e138197435.tar.xz |
More template bloat reduction
Diffstat (limited to 'src/timeline')
-rw-r--r-- | src/timeline/EventStore.cpp | 131 | ||||
-rw-r--r-- | src/timeline/EventStore.h | 1 | ||||
-rw-r--r-- | src/timeline/TimelineModel.cpp | 79 |
3 files changed, 111 insertions, 100 deletions
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index 5f118895..d035d840 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -242,24 +242,23 @@ EventStore::EventStore(std::string room_id, QObject *) if (!session.session) continue; - std::visit( - [&pending_event, &original_encrypted, &session, this](auto &msg) { - nlohmann::json doc = {{"type", mtx::events::to_string(msg.type)}, + auto doc = std::visit( + [this](auto &msg) { + return nlohmann::json{{"type", mtx::events::to_string(msg.type)}, {"content", nlohmann::json(msg.content)}, {"room_id", room_id_}}; + }, + pending_event->data); - auto data = olm::encrypt_group_message_with_session( - session.session, http::client()->device_id(), doc); + auto data = olm::encrypt_group_message_with_session( + session.session, http::client()->device_id(), std::move(doc)); - session.data.message_index = - olm_outbound_group_session_message_index(session.session.get()); - cache::updateOutboundMegolmSession( - room_id_, session.data, session.session); + session.data.message_index = + olm_outbound_group_session_message_index(session.session.get()); + cache::updateOutboundMegolmSession(room_id_, session.data, session.session); - original_encrypted.content = data; - pending_event->data = original_encrypted; - }, - pending_event->data); + original_encrypted.content = data; + pending_event->data = original_encrypted; } cache::client()->replaceEvent(room_id_, pending_event_id, *pending_event); @@ -367,6 +366,58 @@ EventStore::receivedSessionKey(const std::string &session_id) } } +namespace { +template<class... Ts> +struct overloaded : Ts... +{ + using Ts::operator()...; +}; +template<class... Ts> +overloaded(Ts...) -> overloaded<Ts...>; +} + +static void +handle_room_verification(EventStore *self, const mtx::events::collections::TimelineEvents &event) +{ + std::visit( + overloaded{ + [self](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &msg) { + nhlog::db()->debug("handle_room_verification: Request"); + emit self->startDMVerification(msg); + }, + [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationCancel> &msg) { + nhlog::db()->debug("handle_room_verification: Cancel"); + ChatPage::instance()->receivedDeviceVerificationCancel(msg.content); + }, + [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationAccept> &msg) { + nhlog::db()->debug("handle_room_verification: Accept"); + ChatPage::instance()->receivedDeviceVerificationAccept(msg.content); + }, + [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationKey> &msg) { + nhlog::db()->debug("handle_room_verification: Key"); + ChatPage::instance()->receivedDeviceVerificationKey(msg.content); + }, + [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationMac> &msg) { + nhlog::db()->debug("handle_room_verification: Mac"); + ChatPage::instance()->receivedDeviceVerificationMac(msg.content); + }, + [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady> &msg) { + nhlog::db()->debug("handle_room_verification: Ready"); + ChatPage::instance()->receivedDeviceVerificationReady(msg.content); + }, + [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationDone> &msg) { + nhlog::db()->debug("handle_room_verification: Done"); + ChatPage::instance()->receivedDeviceVerificationDone(msg.content); + }, + [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationStart> &msg) { + nhlog::db()->debug("handle_room_verification: Start"); + ChatPage::instance()->receivedDeviceVerificationStart(msg.content, msg.sender); + }, + [](const auto &) {}, + }, + event); +} + void EventStore::handleSync(const mtx::responses::Timeline &events) { @@ -464,64 +515,12 @@ EventStore::handleSync(const mtx::responses::Timeline &events) if (d_event->event && std::visit([](auto e) { return (e.sender != utils::localUser().toStdString()); }, *d_event->event)) { - handle_room_verification(*d_event->event); + handle_room_verification(this, *d_event->event); } } } } -namespace { -template<class... Ts> -struct overloaded : Ts... -{ - using Ts::operator()...; -}; -template<class... Ts> -overloaded(Ts...) -> overloaded<Ts...>; -} - -void -EventStore::handle_room_verification(mtx::events::collections::TimelineEvents event) -{ - std::visit( - overloaded{ - [this](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &msg) { - nhlog::db()->debug("handle_room_verification: Request"); - emit startDMVerification(msg); - }, - [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationCancel> &msg) { - nhlog::db()->debug("handle_room_verification: Cancel"); - ChatPage::instance()->receivedDeviceVerificationCancel(msg.content); - }, - [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationAccept> &msg) { - nhlog::db()->debug("handle_room_verification: Accept"); - ChatPage::instance()->receivedDeviceVerificationAccept(msg.content); - }, - [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationKey> &msg) { - nhlog::db()->debug("handle_room_verification: Key"); - ChatPage::instance()->receivedDeviceVerificationKey(msg.content); - }, - [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationMac> &msg) { - nhlog::db()->debug("handle_room_verification: Mac"); - ChatPage::instance()->receivedDeviceVerificationMac(msg.content); - }, - [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady> &msg) { - nhlog::db()->debug("handle_room_verification: Ready"); - ChatPage::instance()->receivedDeviceVerificationReady(msg.content); - }, - [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationDone> &msg) { - nhlog::db()->debug("handle_room_verification: Done"); - ChatPage::instance()->receivedDeviceVerificationDone(msg.content); - }, - [](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationStart> &msg) { - nhlog::db()->debug("handle_room_verification: Start"); - ChatPage::instance()->receivedDeviceVerificationStart(msg.content, msg.sender); - }, - [](const auto &) {}, - }, - event); -} - std::vector<mtx::events::collections::TimelineEvents> EventStore::edits(const std::string &event_id) { diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h index 45dc0169..54d94c23 100644 --- a/src/timeline/EventStore.h +++ b/src/timeline/EventStore.h @@ -131,7 +131,6 @@ private: olm::DecryptionResult * decryptEvent(const IdIndex &idx, const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e); - void handle_room_verification(mtx::events::collections::TimelineEvents event); std::string room_id_; diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index f9df1cf9..ed83a98d 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -46,113 +46,126 @@ namespace { struct RoomEventType { template<class T> - qml_mtx_events::EventType operator()(const mtx::events::Event<T> &e) + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<T> &e) { return qml_mtx_events::toRoomEventType(e.type); } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Audio> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Audio> &) { return qml_mtx_events::EventType::AudioMessage; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Confetti> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Confetti> &) { return qml_mtx_events::EventType::ConfettiMessage; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Emote> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Emote> &) { return qml_mtx_events::EventType::EmoteMessage; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::File> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::File> &) { return qml_mtx_events::EventType::FileMessage; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Image> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Image> &) { return qml_mtx_events::EventType::ImageMessage; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Notice> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Notice> &) { return qml_mtx_events::EventType::NoticeMessage; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Text> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Text> &) { return qml_mtx_events::EventType::TextMessage; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Video> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Video> &) { return qml_mtx_events::EventType::VideoMessage; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationRequest> &) { return qml_mtx_events::EventType::KeyVerificationRequest; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationStart> &) { return qml_mtx_events::EventType::KeyVerificationStart; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationMac> &) { return qml_mtx_events::EventType::KeyVerificationMac; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationAccept> &) { return qml_mtx_events::EventType::KeyVerificationAccept; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationReady> &) { return qml_mtx_events::EventType::KeyVerificationReady; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationCancel> &) { return qml_mtx_events::EventType::KeyVerificationCancel; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationKey> &) { return qml_mtx_events::EventType::KeyVerificationKey; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::KeyVerificationDone> &) { return qml_mtx_events::EventType::KeyVerificationDone; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::msg::Redacted> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::msg::Redacted> &) { return qml_mtx_events::EventType::Redacted; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::voip::CallInvite> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::voip::CallInvite> &) { return qml_mtx_events::EventType::CallInvite; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::voip::CallAnswer> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::voip::CallAnswer> &) { return qml_mtx_events::EventType::CallAnswer; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::voip::CallHangUp> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::voip::CallHangUp> &) { return qml_mtx_events::EventType::CallHangUp; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::voip::CallCandidates> &) { return qml_mtx_events::EventType::CallCandidates; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::voip::CallSelectAnswer> &) { return qml_mtx_events::EventType::CallSelectAnswer; } - qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::voip::CallReject> &) + constexpr qml_mtx_events::EventType + operator()(const mtx::events::Event<mtx::events::voip::CallReject> &) { return qml_mtx_events::EventType::CallReject; } - qml_mtx_events::EventType + constexpr qml_mtx_events::EventType operator()(const mtx::events::Event<mtx::events::voip::CallNegotiate> &) { return qml_mtx_events::EventType::CallNegotiate; @@ -1060,7 +1073,7 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) } template<typename T> -auto +static constexpr auto isMessage(const mtx::events::RoomEvent<T> &e) -> std::enable_if_t<std::is_same<decltype(e.content.msgtype), std::string>::value, bool> { @@ -1068,42 +1081,42 @@ isMessage(const mtx::events::RoomEvent<T> &e) } template<typename T> -auto +static constexpr auto isMessage(const mtx::events::Event<T> &) { return false; } template<typename T> -auto +static constexpr auto isMessage(const mtx::events::EncryptedEvent<T> &) { return true; } -auto +static constexpr auto isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallInvite> &) { return true; } -auto +static constexpr auto isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallAnswer> &) { return true; } -auto +static constexpr auto isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallHangUp> &) { return true; } -auto +static constexpr auto isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallReject> &) { return true; } -auto +static constexpr auto isMessage(const mtx::events::RoomEvent<mtx::events::voip::CallSelectAnswer> &) { return true; |