From bb60976e7e9ca2a3f9ad54a571564de2b42c5d5c Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 19 Sep 2019 22:44:25 +0200 Subject: Reenable encrypted messages --- src/timeline2/TimelineModel.h | 57 +++++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'src/timeline2/TimelineModel.h') diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index 2cd22661..7723ef66 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -8,6 +8,7 @@ #include #include +#include "Cache.h" #include "Logging.h" #include "MatrixClient.h" @@ -86,6 +87,19 @@ enum EventState Q_ENUM_NS(EventState) } +class StateKeeper +{ +public: + StateKeeper(std::function &&fn) + : fn_(std::move(fn)) + {} + + ~StateKeeper() { fn_(); } + +private: + std::function fn_; +}; + struct DecryptionResult { //! The decrypted content as a normal plaintext event. @@ -164,6 +178,13 @@ private: const mtx::events::EncryptedEvent &e) const; std::vector internalAddEvents( const std::vector &timeline); + void sendEncryptedMessage(const std::string &txn_id, nlohmann::json content); + void handleClaimedKeys(std::shared_ptr keeper, + const std::map &room_key, + const std::map &pks, + const std::string &user_id, + const mtx::responses::ClaimKeys &res, + mtx::http::RequestErr err); QHash events; QSet pending, failed, read; @@ -200,20 +221,24 @@ TimelineModel::sendMessage(const T &msg) this->eventOrder.insert(this->eventOrder.end(), txn_id_qstr); endInsertRows(); - http::client()->send_room_message( - room_id_.toStdString(), - txn_id, - msg, - [this, txn_id, txn_id_qstr](const mtx::responses::EventId &res, - mtx::http::RequestErr err) { - if (err) { - const int status_code = static_cast(err->status_code); - nhlog::net()->warn("[{}] failed to send message: {} {}", - txn_id, - err->matrix_error.error, - status_code); - emit messageFailed(txn_id_qstr); - } - emit messageSent(txn_id_qstr, QString::fromStdString(res.event_id.to_string())); - }); + if (cache::client()->isRoomEncrypted(room_id_.toStdString())) + sendEncryptedMessage(txn_id, nlohmann::json(msg)); + else + http::client()->send_room_message( + room_id_.toStdString(), + txn_id, + msg, + [this, txn_id, txn_id_qstr](const mtx::responses::EventId &res, + mtx::http::RequestErr err) { + if (err) { + const int status_code = static_cast(err->status_code); + nhlog::net()->warn("[{}] failed to send message: {} {}", + txn_id, + err->matrix_error.error, + status_code); + emit messageFailed(txn_id_qstr); + } + emit messageSent(txn_id_qstr, + QString::fromStdString(res.event_id.to_string())); + }); } -- cgit 1.5.1