mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Improve fetching of device keys after login
This commit is contained in:
parent
acb5ed6160
commit
ff560a09f5
4 changed files with 23 additions and 6 deletions
|
@ -4101,10 +4101,11 @@ Cache::updateUserKeys(const std::string &sync_token, const mtx::responses::Query
|
|||
(void)status;
|
||||
emit verificationStatusChanged(user);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emit verificationStatusChanged(user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cache::markUserKeysOutOfDate(const std::vector<std::string> &user_ids)
|
||||
|
@ -4311,9 +4312,10 @@ Cache::markDeviceVerified(const std::string &user_id, const std::string &key)
|
|||
(void)status;
|
||||
emit verificationStatusChanged(user);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
emit verificationStatusChanged(user_id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Cache::markDeviceUnverified(const std::string &user_id, const std::string &key)
|
||||
|
|
|
@ -526,6 +526,8 @@ ChatPage::tryInitialSync()
|
|||
for (const auto &entry : res.one_time_key_counts)
|
||||
nhlog::net()->info("uploaded {} {} one-time keys", entry.second, entry.first);
|
||||
|
||||
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
|
||||
|
||||
startInitialSync();
|
||||
});
|
||||
}
|
||||
|
@ -1143,7 +1145,7 @@ ChatPage::decryptDownloadedSecrets(mtx::secret_storage::AesHmacSha2KeyDescriptio
|
|||
if (!decrypted.empty()) {
|
||||
cache::storeSecret(secretName, decrypted);
|
||||
|
||||
if (deviceKeys &&
|
||||
if (deviceKeys && deviceKeys->device_keys.count(http::client()->device_id()) &&
|
||||
secretName == mtx::secret_storage::secrets::cross_signing_self_signing) {
|
||||
auto myKey = deviceKeys->device_keys.at(http::client()->device_id());
|
||||
if (myKey.user_id == http::client()->user_id().to_string() &&
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "SelfVerificationStatus.h"
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "Cache_p.h"
|
||||
#include "ChatPage.h"
|
||||
#include "Logging.h"
|
||||
|
@ -18,12 +20,13 @@
|
|||
SelfVerificationStatus::SelfVerificationStatus(QObject *o)
|
||||
: QObject(o)
|
||||
{
|
||||
connect(MainWindow::instance(), &MainWindow::reload, this, [this] {
|
||||
connect(ChatPage::instance(), &ChatPage::contentLoaded, this, [this] {
|
||||
connect(cache::client(),
|
||||
&Cache::selfVerificationStatusChanged,
|
||||
this,
|
||||
&SelfVerificationStatus::invalidate,
|
||||
Qt::UniqueConnection);
|
||||
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -268,8 +271,16 @@ SelfVerificationStatus::invalidate()
|
|||
|
||||
auto keys = cache::client()->userKeys(http::client()->user_id().to_string());
|
||||
if (!keys || keys->device_keys.find(http::client()->device_id()) == keys->device_keys.end()) {
|
||||
QTimer::singleShot(500, [] {
|
||||
if (keys && (keys->seen_device_ids.count(http::client()->device_id()) ||
|
||||
keys->seen_device_keys.count(olm::client()->identity_keys().curve25519))) {
|
||||
emit ChatPage::instance()->dropToLoginPageCb(
|
||||
tr("Identity key changed. This breaks E2EE, so logging out."));
|
||||
return;
|
||||
}
|
||||
|
||||
cache::client()->markUserKeysOutOfDate({http::client()->user_id().to_string()});
|
||||
|
||||
QTimer::singleShot(1'000, [] {
|
||||
cache::client()->query_keys(http::client()->user_id().to_string(),
|
||||
[](const UserKeyCache &, mtx::http::RequestErr) {});
|
||||
});
|
||||
|
|
|
@ -188,6 +188,7 @@ UserProfile::fetchDeviceList(const QString &userID)
|
|||
nhlog::net()->warn("failed to query device keys: {},{}",
|
||||
mtx::errors::to_string(err->matrix_error.errcode),
|
||||
static_cast<int>(err->status_code));
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure local key cache is up to date
|
||||
|
@ -201,6 +202,7 @@ UserProfile::fetchDeviceList(const QString &userID)
|
|||
nhlog::net()->warn("failed to query device keys: {},{}",
|
||||
mtx::errors::to_string(err->matrix_error.errcode),
|
||||
static_cast<int>(err->status_code));
|
||||
return;
|
||||
}
|
||||
|
||||
emit verificationStatiChanged();
|
||||
|
|
Loading…
Reference in a new issue