summary refs log tree commit diff
path: root/src/timeline
diff options
context:
space:
mode:
authorCH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com>2020-08-18 11:29:02 +0530
committerCH Chethan Reddy <40890937+Chethan2k1@users.noreply.github.com>2020-08-18 11:29:02 +0530
commit8a4bd37fead20e24876ec9ce703cabb041ec67ba (patch)
tree7f304caad6226d252a912da0fafcdf9aaae86303 /src/timeline
parent[WIP] Room-Verification Messages (diff)
downloadnheko-8a4bd37fead20e24876ec9ce703cabb041ec67ba.tar.xz
[WIP] Room Verification Works!
Diffstat (limited to 'src/timeline')
-rw-r--r--src/timeline/EventStore.cpp22
-rw-r--r--src/timeline/EventStore.h1
-rw-r--r--src/timeline/TimelineModel.cpp7
-rw-r--r--src/timeline/TimelineViewManager.cpp71
4 files changed, 60 insertions, 41 deletions
diff --git a/src/timeline/EventStore.cpp b/src/timeline/EventStore.cpp

index 208b20e2..b210e157 100644 --- a/src/timeline/EventStore.cpp +++ b/src/timeline/EventStore.cpp
@@ -95,8 +95,8 @@ EventStore::EventStore(std::string room_id, QObject *) room_id_, txn_id, e.content, - [this, txn_id](const mtx::responses::EventId &event_id, - mtx::http::RequestErr err) { + [this, txn_id, e](const mtx::responses::EventId &event_id, + mtx::http::RequestErr err) { if (err) { const int status_code = static_cast<int>(err->status_code); @@ -108,7 +108,21 @@ EventStore::EventStore(std::string room_id, QObject *) emit messageFailed(txn_id); return; } + emit messageSent(txn_id, event_id.event_id.to_string()); + if constexpr (mtx::events::message_content_to_type< + decltype(e.content)> == + mtx::events::EventType::RoomEncrypted) { + auto event = + decryptEvent({room_id_, e.event_id}, e); + if (auto dec = + std::get_if<mtx::events::RoomEvent< + mtx::events::msg:: + KeyVerificationRequest>>(event)) { + emit updateFlowEventId( + event_id.event_id.to_string()); + } + } }); }, event->data); @@ -318,12 +332,12 @@ EventStore::reactions(const std::string &event_id) if (auto reaction = std::get_if<mtx::events::RoomEvent<mtx::events::msg::Reaction>>( related_event)) { - auto &agg = aggregation[reaction->content.relates_to.key]; + auto &agg = aggregation[reaction->content.relates_to.key.value()]; if (agg.count == 0) { Reaction temp{}; temp.key_ = - QString::fromStdString(reaction->content.relates_to.key); + QString::fromStdString(reaction->content.relates_to.key.value()); reactions.push_back(temp); } diff --git a/src/timeline/EventStore.h b/src/timeline/EventStore.h
index 28d46e90..55a66f49 100644 --- a/src/timeline/EventStore.h +++ b/src/timeline/EventStore.h
@@ -100,6 +100,7 @@ signals: void messageFailed(std::string txn_id); void startDMVerification( mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &msg); + void updateFlowEventId(std::string event_id); public slots: void addPending(mtx::events::collections::TimelineEvents event); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 809fe382..dc5eb8cc 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -22,8 +22,6 @@ #include "Utils.h" #include "dialogs/RawMessage.h" -#include <iostream> - Q_DECLARE_METATYPE(QModelIndex) namespace std { @@ -237,6 +235,9 @@ TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObj [this](mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> msg) { ChatPage::instance()->recievedRoomDeviceVerificationRequest(msg, this); }); + connect(&events, &EventStore::updateFlowEventId, this, [this](std::string event_id) { + this->updateFlowEventId(event_id); + }); } QHash<int, QByteArray> @@ -814,7 +815,6 @@ TimelineModel::sendEncryptedMessage(mtx::events::RoomEvent<T> msg) json doc = { {"type", to_string(msg.type)}, {"content", json(msg.content)}, {"room_id", room_id}}; - std::cout << doc.dump(2) << std::endl; try { // Check if we have already an outbound megolm session then we can use. @@ -1095,7 +1095,6 @@ struct SendMessageVisitor void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &msg) { - emit model_->updateFlowEventId(msg.event_id); model_->sendEncryptedMessage(msg); } void operator()(const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationReady> &msg) diff --git a/src/timeline/TimelineViewManager.cpp b/src/timeline/TimelineViewManager.cpp
index c16e09d1..fb4a094e 100644 --- a/src/timeline/TimelineViewManager.cpp +++ b/src/timeline/TimelineViewManager.cpp
@@ -194,13 +194,12 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin [this](const mtx::events::RoomEvent<mtx::events::msg::KeyVerificationRequest> &message, TimelineModel *model) { if (!(this->dvList->exist(QString::fromStdString(message.event_id)))) { - auto flow = - new DeviceVerificationFlow(this, DeviceVerificationFlow::Type::RoomMsg); + auto flow = new DeviceVerificationFlow( + this, DeviceVerificationFlow::Type::RoomMsg, model); if (std::find(message.content.methods.begin(), message.content.methods.end(), mtx::events::msg::VerificationMethods::SASv1) != message.content.methods.end()) { - flow->setModel(model); flow->setEventId(message.event_id); emit newDeviceVerificationRequest( std::move(flow), @@ -241,42 +240,48 @@ TimelineViewManager::TimelineViewManager(QSharedPointer<UserSettings> userSettin &ChatPage::recievedDeviceVerificationStart, this, [this](const mtx::events::msg::KeyVerificationStart &msg, std::string sender) { - if (!(this->dvList->exist(QString::fromStdString(msg.transaction_id.value())))) { - auto flow = new DeviceVerificationFlow(this); - flow->canonical_json = nlohmann::json(msg); - if ((std::find(msg.key_agreement_protocols.begin(), - msg.key_agreement_protocols.end(), - "curve25519-hkdf-sha256") != - msg.key_agreement_protocols.end()) && - (std::find(msg.hashes.begin(), msg.hashes.end(), "sha256") != - msg.hashes.end()) && - (std::find(msg.message_authentication_codes.begin(), - msg.message_authentication_codes.end(), - "hmac-sha256") != - msg.message_authentication_codes.end())) { - if (std::find(msg.short_authentication_string.begin(), - msg.short_authentication_string.end(), - mtx::events::msg::SASMethods::Emoji) != - msg.short_authentication_string.end()) { - flow->setMethod(DeviceVerificationFlow::Method::Emoji); - } else if (std::find(msg.short_authentication_string.begin(), + if (msg.transaction_id.has_value()) { + if (!(this->dvList->exist( + QString::fromStdString(msg.transaction_id.value())))) { + auto flow = new DeviceVerificationFlow(this); + flow->canonical_json = nlohmann::json(msg); + if ((std::find(msg.key_agreement_protocols.begin(), + msg.key_agreement_protocols.end(), + "curve25519-hkdf-sha256") != + msg.key_agreement_protocols.end()) && + (std::find(msg.hashes.begin(), msg.hashes.end(), "sha256") != + msg.hashes.end()) && + (std::find(msg.message_authentication_codes.begin(), + msg.message_authentication_codes.end(), + "hmac-sha256") != + msg.message_authentication_codes.end())) { + if (std::find(msg.short_authentication_string.begin(), + msg.short_authentication_string.end(), + mtx::events::msg::SASMethods::Emoji) != + msg.short_authentication_string.end()) { + flow->setMethod( + DeviceVerificationFlow::Method::Emoji); + } else if (std::find( + msg.short_authentication_string.begin(), msg.short_authentication_string.end(), mtx::events::msg::SASMethods::Decimal) != - msg.short_authentication_string.end()) { - flow->setMethod(DeviceVerificationFlow::Method::Decimal); + msg.short_authentication_string.end()) { + flow->setMethod( + DeviceVerificationFlow::Method::Decimal); + } else { + flow->cancelVerification( + DeviceVerificationFlow::Error::UnknownMethod); + return; + } + emit newDeviceVerificationRequest( + std::move(flow), + QString::fromStdString(msg.transaction_id.value()), + QString::fromStdString(sender), + QString::fromStdString(msg.from_device)); } else { flow->cancelVerification( DeviceVerificationFlow::Error::UnknownMethod); - return; } - emit newDeviceVerificationRequest( - std::move(flow), - QString::fromStdString(msg.transaction_id.value()), - QString::fromStdString(sender), - QString::fromStdString(msg.from_device)); - } else { - flow->cancelVerification( - DeviceVerificationFlow::Error::UnknownMethod); } } });