summary refs log tree commit diff
path: root/src/ChatPage.cpp
diff options
context:
space:
mode:
authorDeepBlueV7.X <nicolas.werner@hotmail.de>2020-10-08 20:08:38 +0200
committerGitHub <noreply@github.com>2020-10-08 20:08:38 +0200
commit517a126a4427972668a97b21fc8684f7160976b9 (patch)
tree27142d719f848abe685897cd367e8d69a9bed719 /src/ChatPage.cpp
parentMerge pull request #294 from trilene/master (diff)
parentTry to fix windows build (diff)
downloadnheko-517a126a4427972668a97b21fc8684f7160976b9.tar.xz
Merge pull request #270 from Chethan2k1/device-verification
Device verification and Cross-Signing
Diffstat (limited to 'src/ChatPage.cpp')
-rw-r--r--src/ChatPage.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp

index 59ae7ef2..8e93c0f4 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp
@@ -26,6 +26,7 @@ #include "Cache.h" #include "Cache_p.h" #include "ChatPage.h" +#include "DeviceVerificationFlow.h" #include "EventAccessors.h" #include "Logging.h" #include "MainWindow.h" @@ -159,6 +160,10 @@ ChatPage::ChatPage(QSharedPointer<UserSettings> userSettings, QWidget *parent) view_manager_, &TimelineViewManager::clearCurrentRoomTimeline); + connect(text_input_, &TextInputWidget::rotateMegolmSession, this, [this]() { + cache::dropOutboundMegolmSession(current_room_.toStdString()); + }); + connect( new QShortcut(QKeySequence("Ctrl+Down"), this), &QShortcut::activated, this, [this]() { if (isVisible()) @@ -1456,6 +1461,46 @@ ChatPage::initiateLogout() emit showOverlayProgressBar(); } +void +ChatPage::query_keys(const std::string &user_id, + std::function<void(const UserKeyCache &, mtx::http::RequestErr)> cb) +{ + auto cache_ = cache::userKeys(user_id); + + if (cache_.has_value()) { + if (!cache_->updated_at.empty() && cache_->updated_at == cache_->last_changed) { + cb(cache_.value(), {}); + return; + } + } + + mtx::requests::QueryKeys req; + req.device_keys[user_id] = {}; + + std::string last_changed; + if (cache_) + last_changed = cache_->last_changed; + req.token = last_changed; + + http::client()->query_keys(req, + [cb, user_id, last_changed](const mtx::responses::QueryKeys &res, + mtx::http::RequestErr err) { + if (err) { + nhlog::net()->warn( + "failed to query device keys: {},{}", + err->matrix_error.errcode, + static_cast<int>(err->status_code)); + cb({}, err); + return; + } + + cache::updateUserKeys(last_changed, res); + + auto keys = cache::userKeys(user_id); + cb(keys.value_or(UserKeyCache{}), err); + }); +} + template<typename T> void ChatPage::connectCallMessage()