summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-07-24 14:59:14 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-07-24 14:59:14 +0200
commita61678242b91944c07bf4b82b4eb25baad0db00b (patch)
tree4a1ff4d35700a9df512642ab8ac1bdfb65db06a7 /src
parentFix some issues when parsing or serializing enabled pack rooms (diff)
downloadnheko-a61678242b91944c07bf4b82b4eb25baad0db00b.tar.xz
Fix edge case that could lead to no new one time keys being uploaded
Diffstat (limited to 'src')
-rw-r--r--src/ChatPage.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp

index 6b8c1e10..615a15b3 100644 --- a/src/ChatPage.cpp +++ b/src/ChatPage.cpp
@@ -929,31 +929,33 @@ ChatPage::currentPresence() const void ChatPage::ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts) { - for (const auto &entry : counts) { - if (entry.second < MAX_ONETIME_KEYS) { - const int nkeys = MAX_ONETIME_KEYS - entry.second; + uint16_t count = 0; + if (auto c = counts.find(mtx::crypto::SIGNED_CURVE25519); c != counts.end()) + count = c->second; - nhlog::crypto()->info("uploading {} {} keys", nkeys, entry.first); - olm::client()->generate_one_time_keys(nkeys); + if (count < MAX_ONETIME_KEYS) { + const int nkeys = MAX_ONETIME_KEYS - count; - http::client()->upload_keys( - olm::client()->create_upload_keys_request(), - [](const mtx::responses::UploadKeys &, mtx::http::RequestErr err) { - if (err) { - nhlog::crypto()->warn( - "failed to update one-time keys: {} {} {}", - err->matrix_error.error, - static_cast<int>(err->status_code), - static_cast<int>(err->error_code)); + nhlog::crypto()->info( + "uploading {} {} keys", nkeys, mtx::crypto::SIGNED_CURVE25519); + olm::client()->generate_one_time_keys(nkeys); - if (err->status_code < 400 || err->status_code >= 500) - return; - } + http::client()->upload_keys( + olm::client()->create_upload_keys_request(), + [](const mtx::responses::UploadKeys &, mtx::http::RequestErr err) { + if (err) { + nhlog::crypto()->warn("failed to update one-time keys: {} {} {}", + err->matrix_error.error, + static_cast<int>(err->status_code), + static_cast<int>(err->error_code)); - // mark as published anyway, otherwise we may end up in a loop. - olm::mark_keys_as_published(); - }); - } + if (err->status_code < 400 || err->status_code >= 500) + return; + } + + // mark as published anyway, otherwise we may end up in a loop. + olm::mark_keys_as_published(); + }); } }