diff options
-rw-r--r-- | lib/connection.cpp | 8 | ||||
-rw-r--r-- | lib/crypto/qolmaccount.cpp | 6 | ||||
-rw-r--r-- | lib/crypto/qolmaccount.h | 9 |
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index d652c113..d7115885 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -456,7 +456,11 @@ void Connection::Private::completeSetup(const QString& mxId) AccountSettings accountSettings(data->userId()); // init olmAccount - olmAccount = std::make_unique<QOlmAccount>(data->userId(), data->deviceId()); + olmAccount = std::make_unique<QOlmAccount>(data->userId(), data->deviceId(), q); + connect(olmAccount.get(), &QOlmAccount::needsSave, q, [=](){ + auto pickle = olmAccount->pickle(Unencrypted{}); + AccountSettings(data->userId()).setEncryptionAccountPickle(std::get<QByteArray>(pickle)); + }); if (accountSettings.encryptionAccountPickle().isEmpty()) { // create new account and save unpickle data @@ -1283,7 +1287,7 @@ bool Connection::isLoggedIn() const { return !accessToken().isEmpty(); } #ifdef Quotient_E2EE_ENABLED QOlmAccount *Connection::olmAccount() const { - return d->olmAccount.get(); //d->encryptionManager->account(); + return d->olmAccount.get(); } #endif // Quotient_E2EE_ENABLED diff --git a/lib/crypto/qolmaccount.cpp b/lib/crypto/qolmaccount.cpp index 22b1faef..44959ac2 100644 --- a/lib/crypto/qolmaccount.cpp +++ b/lib/crypto/qolmaccount.cpp @@ -46,8 +46,9 @@ QByteArray getRandom(size_t bufferSize) return buffer; } -QOlmAccount::QOlmAccount(const QString &userId, const QString &deviceId) - : m_userId(userId) +QOlmAccount::QOlmAccount(const QString &userId, const QString &deviceId, QObject *parent) + : QObject(parent) + , m_userId(userId) , m_deviceId(deviceId) { } @@ -158,6 +159,7 @@ size_t QOlmAccount::generateOneTimeKeys(size_t numberOfKeys) const if (error == olm_error()) { throw lastError(m_account); } + Q_EMIT needsSave(); return error; } diff --git a/lib/crypto/qolmaccount.h b/lib/crypto/qolmaccount.h index 54d8506c..1f94ab2b 100644 --- a/lib/crypto/qolmaccount.h +++ b/lib/crypto/qolmaccount.h @@ -23,10 +23,11 @@ class Connection; //! \code{.cpp} //! const auto olmAccount = new QOlmAccount(this); //! \endcode -class QOlmAccount +class QOlmAccount : public QObject { + Q_OBJECT public: - QOlmAccount(const QString &userId, const QString &deviceId); + QOlmAccount(const QString &userId, const QString &deviceId, QObject *parent = nullptr); ~QOlmAccount(); //! Creates a new instance of OlmAccount. During the instantiation @@ -98,6 +99,10 @@ public: // HACK do not use directly QOlmAccount(OlmAccount *account); OlmAccount *data(); + +Q_SIGNALS: + void needsSave() const; + private: OlmAccount *m_account = nullptr; // owning QString m_userId; |