diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp index e5eaefb8..af1f7b23 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp @@ -280,71 +280,18 @@ EventStore::handleSync(const mtx::responses::Timeline &events) } } + handle_room_verification(event); + // decrypting and checking some encrypted messages if (auto encrypted = std::get_if>( &event)) { - auto d_event = decryptEvent({room_id_, encrypted->event_id}, *encrypted); + mtx::events::collections::TimelineEvents *d_event = + decryptEvent({room_id_, encrypted->event_id}, *encrypted); if (std::visit( [](auto e) { return (e.sender != utils::localUser().toStdString()); }, *d_event)) { - if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - last_verification_request_event = *msg; - continue; - } else if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - last_verification_cancel_event = *msg; - ChatPage::instance()->recievedDeviceVerificationCancel( - msg->content); - continue; - } else if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - ChatPage::instance()->recievedDeviceVerificationAccept( - msg->content); - continue; - } else if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - ChatPage::instance()->recievedDeviceVerificationKey( - msg->content); - continue; - } else if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - ChatPage::instance()->recievedDeviceVerificationMac( - msg->content); - continue; - } else if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - ChatPage::instance()->recievedDeviceVerificationReady( - msg->content); - continue; - } else if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - ChatPage::instance()->recievedDeviceVerificationDone( - msg->content); - continue; - } else if (std::get_if>(d_event)) { - auto msg = std::get_if>(d_event); - ChatPage::instance()->recievedDeviceVerificationStart( - msg->content, msg->sender); - continue; - } + handle_room_verification(*d_event); } else { // only the key.verification.ready sent by localuser's other device // is of significance as it is used for detecting accepted request @@ -368,6 +315,60 @@ EventStore::handleSync(const mtx::responses::Timeline &events) } } +void +EventStore::handle_room_verification(mtx::events::collections::TimelineEvents event) +{ + if (std::get_if>(&event)) { + auto msg = + std::get>(event); + last_verification_request_event = msg; + return; + } else if (std::get_if>( + &event)) { + auto msg = + std::get>(event); + last_verification_cancel_event = msg; + ChatPage::instance()->recievedDeviceVerificationCancel(msg.content); + return; + } else if (std::get_if>( + &event)) { + auto msg = + std::get>(event); + ChatPage::instance()->recievedDeviceVerificationAccept(msg.content); + return; + } else if (std::get_if>( + &event)) { + auto msg = + std::get>(event); + ChatPage::instance()->recievedDeviceVerificationKey(msg.content); + return; + } else if (std::get_if>( + &event)) { + auto msg = + std::get>(event); + ChatPage::instance()->recievedDeviceVerificationMac(msg.content); + return; + } else if (std::get_if>( + &event)) { + auto msg = + std::get>(event); + ChatPage::instance()->recievedDeviceVerificationReady(msg.content); + return; + } else if (std::get_if>( + &event)) { + auto msg = + std::get>(event); + ChatPage::instance()->recievedDeviceVerificationDone(msg.content); + return; + } else if (std::get_if>( + &event)) { + auto msg = + std::get>(event); + ChatPage::instance()->recievedDeviceVerificationStart(msg.content, msg.sender); + return; + } +} + QVariantList EventStore::reactions(const std::string &event_id) { diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h index 4ff4fa3b..89a51477 100644 --- a/src/timeline/EventStore.h +++ b/src/timeline/EventStore.h @@ -110,6 +110,7 @@ private: mtx::events::collections::TimelineEvents *decryptEvent( const IdIndex &idx, const mtx::events::EncryptedEvent &e); + void handle_room_verification(mtx::events::collections::TimelineEvents event); std::string room_id_;