From 3635c185e93a6f7bf6e2f9c11b27966c2ee665ea Mon Sep 17 00:00:00 2001 From: CH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com> Date: Wed, 29 Jul 2020 03:25:47 +0530 Subject: Add Room Verification Messages --- src/DeviceVerificationFlow.cpp | 56 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'src/DeviceVerificationFlow.cpp') diff --git a/src/DeviceVerificationFlow.cpp b/src/DeviceVerificationFlow.cpp index 69de4937..0f521f92 100644 --- a/src/DeviceVerificationFlow.cpp +++ b/src/DeviceVerificationFlow.cpp @@ -1,7 +1,9 @@ #include "DeviceVerificationFlow.h" + #include "Cache.h" #include "ChatPage.h" #include "Logging.h" +#include "timeline/TimelineModel.h" #include #include @@ -12,12 +14,14 @@ static constexpr int TIMEOUT = 2 * 60 * 1000; // 2 minutes namespace msgs = mtx::events::msg; -DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow::Type) +DeviceVerificationFlow::DeviceVerificationFlow(QObject *, DeviceVerificationFlow::Type flow_type) + : type(flow_type) { timeout = new QTimer(this); timeout->setSingleShot(true); this->sas = olm::client()->sas_init(); this->isMacVerified = false; + connect(timeout, &QTimer::timeout, this, [this]() { emit timedout(); this->cancelVerification(DeviceVerificationFlow::Error::Timeout); @@ -267,6 +271,12 @@ DeviceVerificationFlow::getMethod() return this->method; } +DeviceVerificationFlow::Type +DeviceVerificationFlow::getType() +{ + return this->type; +} + bool DeviceVerificationFlow::getSender() { @@ -279,6 +289,12 @@ DeviceVerificationFlow::getSasList() return this->sasList; } +void +DeviceVerificationFlow::setModel(TimelineModel *&model) +{ + this->model_ = model; +} + void DeviceVerificationFlow::setTransactionId(QString transaction_id_) { @@ -318,6 +334,12 @@ DeviceVerificationFlow::setMethod(DeviceVerificationFlow::Method method_) this->method = method_; } +void +DeviceVerificationFlow::setType(Type type) +{ + this->type = type; +} + void DeviceVerificationFlow::setSender(bool sender_) { @@ -328,6 +350,13 @@ DeviceVerificationFlow::setSender(bool sender_) this->relation.in_reply_to.event_id = http::client()->generate_txn_id(); } +void +DeviceVerificationFlow::setEventId(std::string event_id) +{ + this->relation.in_reply_to.event_id = event_id; + this->transaction_id = event_id; +} + //! accepts a verification void DeviceVerificationFlow::acceptVerificationRequest() @@ -361,8 +390,9 @@ DeviceVerificationFlow::acceptVerificationRequest() err->matrix_error.error, static_cast(err->status_code)); }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { req.relates_to = this->relation; + (model_.value())->sendMessage(req); } } //! responds verification request @@ -389,8 +419,9 @@ DeviceVerificationFlow::sendVerificationReady() err->matrix_error.error, static_cast(err->status_code)); }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { req.relates_to = this->relation; + (model_.value())->sendMessage(req); } } //! accepts a verification @@ -414,8 +445,9 @@ DeviceVerificationFlow::sendVerificationDone() err->matrix_error.error, static_cast(err->status_code)); }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { req.relates_to = this->relation; + (model_.value())->sendMessage(req); } } //! starts the verification flow @@ -448,8 +480,9 @@ DeviceVerificationFlow::startVerificationRequest() err->matrix_error.error, static_cast(err->status_code)); }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { req.relates_to = this->relation; + (model_.value())->sendMessage(req); } } //! sends a verification request @@ -481,8 +514,8 @@ DeviceVerificationFlow::sendVerificationRequest() err->matrix_error.error, static_cast(err->status_code)); }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { - std::cout << "lulz" << std::endl; + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { + (model_.value())->sendMessage(req); } } //! cancels a verification flow @@ -531,8 +564,9 @@ DeviceVerificationFlow::cancelVerification(DeviceVerificationFlow::Error error_c this->deleteLater(); }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { req.relates_to = this->relation; + (model_.value())->sendMessage(req); } // TODO : Handle Blocking user better @@ -570,8 +604,9 @@ DeviceVerificationFlow::sendVerificationKey() err->matrix_error.error, static_cast(err->status_code)); }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { req.relates_to = this->relation; + (model_.value())->sendMessage(req); } } //! sends the mac of the keys @@ -618,8 +653,9 @@ DeviceVerificationFlow::sendVerificationMac() else this->isMacVerified = true; }); - } else if (this->type == DeviceVerificationFlow::Type::RoomMsg) { + } else if (this->type == DeviceVerificationFlow::Type::RoomMsg && model_.has_value()) { req.relates_to = this->relation; + (model_.value())->sendMessage(req); } } //! Completes the verification flow -- cgit 1.5.1