summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-09-05 23:15:44 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-09-05 23:15:44 +0200
commite035d1407a80efc54ae46f9662dcc4fde9196df4 (patch)
tree2bd0a43eed33d8ca13bc16c2a8fd5443c406ccfe
parentMerge pull request #712 from Thulinma/improvedProfiles (diff)
downloadnheko-e035d1407a80efc54ae46f9662dcc4fde9196df4.tar.xz
Conduit does not send count, if it didn't change
-rw-r--r--src/ChatPage.cpp45
1 files changed, 22 insertions, 23 deletions
diff --git a/src/ChatPage.cpp b/src/ChatPage.cpp
index 80d06ae2..437bd658 100644
--- a/src/ChatPage.cpp
+++ b/src/ChatPage.cpp
@@ -939,33 +939,32 @@ ChatPage::currentPresence() const
 void
 ChatPage::ensureOneTimeKeyCount(const std::map<std::string, uint16_t> &counts)
 {
-        uint16_t count = 0;
-        if (auto c = counts.find(mtx::crypto::SIGNED_CURVE25519); c != counts.end())
-                count = c->second;
+        if (auto count = counts.find(mtx::crypto::SIGNED_CURVE25519); c != counts.end()) {
+                if (count < MAX_ONETIME_KEYS) {
+                        const int nkeys = MAX_ONETIME_KEYS - count;
 
-        if (count < MAX_ONETIME_KEYS) {
-                const int nkeys = MAX_ONETIME_KEYS - count;
+                        nhlog::crypto()->info(
+                          "uploading {} {} keys", nkeys, mtx::crypto::SIGNED_CURVE25519);
+                        olm::client()->generate_one_time_keys(nkeys);
 
-                nhlog::crypto()->info(
-                  "uploading {} {} keys", nkeys, mtx::crypto::SIGNED_CURVE25519);
-                olm::client()->generate_one_time_keys(nkeys);
-
-                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));
+                        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));
 
-                                  if (err->status_code < 400 || err->status_code >= 500)
-                                          return;
-                          }
+                                          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();
-                  });
+                                  // mark as published anyway, otherwise we may end up in a loop.
+                                  olm::mark_keys_as_published();
+                          });
+                }
         }
 }