Add support non-encrypted room-verification messages

This commit is contained in:
Chethan2k1 2020-09-08 20:39:31 +05:30
parent e8eeb480d5
commit 898be090af
2 changed files with 60 additions and 58 deletions

View file

@ -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<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
&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<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationRequest>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationRequest>>(d_event);
last_verification_request_event = *msg;
continue;
} else if (std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationCancel>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationCancel>>(d_event);
last_verification_cancel_event = *msg;
ChatPage::instance()->recievedDeviceVerificationCancel(
msg->content);
continue;
} else if (std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationAccept>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationAccept>>(d_event);
ChatPage::instance()->recievedDeviceVerificationAccept(
msg->content);
continue;
} else if (std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationKey>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationKey>>(d_event);
ChatPage::instance()->recievedDeviceVerificationKey(
msg->content);
continue;
} else if (std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationMac>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationMac>>(d_event);
ChatPage::instance()->recievedDeviceVerificationMac(
msg->content);
continue;
} else if (std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationReady>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationReady>>(d_event);
ChatPage::instance()->recievedDeviceVerificationReady(
msg->content);
continue;
} else if (std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationDone>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationDone>>(d_event);
ChatPage::instance()->recievedDeviceVerificationDone(
msg->content);
continue;
} else if (std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationStart>>(d_event)) {
auto msg = std::get_if<mtx::events::RoomEvent<
mtx::events::msg::KeyVerificationStart>>(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<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest>>(&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest>>(event);
last_verification_request_event = msg;
return;
} else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationCancel>>(
&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationCancel>>(event);
last_verification_cancel_event = msg;
ChatPage::instance()->recievedDeviceVerificationCancel(msg.content);
return;
} else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationAccept>>(
&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationAccept>>(event);
ChatPage::instance()->recievedDeviceVerificationAccept(msg.content);
return;
} else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationKey>>(
&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationKey>>(event);
ChatPage::instance()->recievedDeviceVerificationKey(msg.content);
return;
} else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationMac>>(
&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationMac>>(event);
ChatPage::instance()->recievedDeviceVerificationMac(msg.content);
return;
} else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady>>(
&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady>>(event);
ChatPage::instance()->recievedDeviceVerificationReady(msg.content);
return;
} else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationDone>>(
&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationDone>>(event);
ChatPage::instance()->recievedDeviceVerificationDone(msg.content);
return;
} else if (std::get_if<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationStart>>(
&event)) {
auto msg =
std::get<mtx::events::RoomEvent<mtx::events::msg::KeyVerificationStart>>(event);
ChatPage::instance()->recievedDeviceVerificationStart(msg.content, msg.sender);
return;
}
}
QVariantList
EventStore::reactions(const std::string &event_id)
{

View file

@ -110,6 +110,7 @@ private:
mtx::events::collections::TimelineEvents *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_;