From 9815e9a0a27f0c4a493ad96e9d865ee489ca9404 Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Fri, 25 Feb 2022 15:35:07 +0100 Subject: Save key counts to state Otherwise new one time keys will be uploaded on every start --- lib/connection.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/connection.cpp b/lib/connection.cpp index 0ef27486..4c614176 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -117,6 +117,7 @@ public: bool encryptionUpdateRequired = false; PicklingMode picklingMode = Unencrypted {}; Database *database = nullptr; + QHash oneTimeKeysCount; // A map from SenderKey to vector of InboundSession UnorderedMap> olmSessions; @@ -755,13 +756,12 @@ QJsonObject toJson(const DirectChatsMap& directChats) void Connection::onSyncSuccess(SyncData&& data, bool fromCache) { #ifdef Quotient_E2EE_ENABLED - const auto oneTimeKeyCount = - static_cast(data.deviceOneTimeKeysCount()[SignedCurve25519Key]); - if (oneTimeKeyCount < 0.4 * d->olmAccount->maxNumberOfOneTimeKeys() + d->oneTimeKeysCount = data.deviceOneTimeKeysCount(); + if (d->oneTimeKeysCount[SignedCurve25519Key] < 0.4 * d->olmAccount->maxNumberOfOneTimeKeys() && !d->isUploadingKeys) { d->isUploadingKeys = true; d->olmAccount->generateOneTimeKeys( - d->olmAccount->maxNumberOfOneTimeKeys() / 2 - oneTimeKeyCount); + d->olmAccount->maxNumberOfOneTimeKeys() / 2 - d->oneTimeKeysCount[SignedCurve25519Key]); auto keys = d->olmAccount->oneTimeKeys(); auto job = d->olmAccount->createUploadKeyRequest(keys); run(job, ForegroundRequest); @@ -1829,6 +1829,10 @@ void Connection::saveState() const QJsonObject { { QStringLiteral("events"), accountDataEvents } }); } + { + QJsonObject keysJson = toJson(d->oneTimeKeysCount); + rootObj.insert(QStringLiteral("device_one_time_keys_count"), keysJson); + } #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) const auto data = -- cgit v1.2.3