summary refs log tree commit diff
path: root/src/timeline2/TimelineModel.h
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2019-09-19 22:44:25 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2019-11-23 20:06:14 +0100
commitbb60976e7e9ca2a3f9ad54a571564de2b42c5d5c (patch)
treeb9c9eba0f49694e6fa8096f5184595154d798d61 /src/timeline2/TimelineModel.h
parentMake avatar in timeline smaller (diff)
downloadnheko-bb60976e7e9ca2a3f9ad54a571564de2b42c5d5c.tar.xz
Reenable encrypted messages
Diffstat (limited to 'src/timeline2/TimelineModel.h')
-rw-r--r--src/timeline2/TimelineModel.h57
1 files changed, 41 insertions, 16 deletions
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 <QHash> #include <QSet> +#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<void()> &&fn) + : fn_(std::move(fn)) + {} + + ~StateKeeper() { fn_(); } + +private: + std::function<void()> fn_; +}; + struct DecryptionResult { //! The decrypted content as a normal plaintext event. @@ -164,6 +178,13 @@ private: const mtx::events::EncryptedEvent<mtx::events::msg::Encrypted> &e) const; std::vector<QString> internalAddEvents( const std::vector<mtx::events::collections::TimelineEvents> &timeline); + void sendEncryptedMessage(const std::string &txn_id, nlohmann::json content); + void handleClaimedKeys(std::shared_ptr<StateKeeper> keeper, + const std::map<std::string, std::string> &room_key, + const std::map<std::string, DevicePublicKeys> &pks, + const std::string &user_id, + const mtx::responses::ClaimKeys &res, + mtx::http::RequestErr err); QHash<QString, mtx::events::collections::TimelineEvents> events; QSet<QString> 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<T, mtx::events::EventType::RoomMessage>( - 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<int>(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<T, mtx::events::EventType::RoomMessage>( + 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<int>(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())); + }); }