From 758a9d95f3e738f9c352b37e5753ff510e185a68 Mon Sep 17 00:00:00 2001 From: blue Date: Thu, 29 Dec 2022 01:41:59 +0300 Subject: [PATCH] replaced one structure, stored omemo support in Global object --- core/handlers/omemohandler.cpp | 25 ++++++------------------- core/handlers/omemohandler.h | 10 ++++------ main/main.cpp | 1 - shared/global.cpp | 6 ++++++ shared/global.h | 1 + 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/core/handlers/omemohandler.cpp b/core/handlers/omemohandler.cpp index 8ce5932..57d9749 100644 --- a/core/handlers/omemohandler.cpp +++ b/core/handlers/omemohandler.cpp @@ -26,7 +26,7 @@ Core::OmemoHandler::OmemoHandler(Account* account) : meta(db.addCache("meta")), devices(db.addCache>("devices")), preKeyPairs(db.addCache("preKeyPairs")), - signedPreKeyPairs(db.addCache("signedPreKeyPairs")) + signedPreKeyPairs(db.addCache("signedPreKeyPairs")) { db.open(); try { @@ -61,9 +61,10 @@ QFuture Core::OmemoHandler::allData() { data.preKeyPairs.insert(pair.first, pair.second); } - std::map spre = signedPreKeyPairs->readAll(); - for (const std::pair& pair : spre) { - data.signedPreKeyPairs.insert(pair.first, pair.second); + std::map spre = signedPreKeyPairs->readAll(); + for (const std::pair& pair : spre) { + QXmppOmemoStorage::SignedPreKeyPair qxpair = {pair.second.first, pair.second.second}; + data.signedPreKeyPairs.insert(pair.first, qxpair); } std::map> devs = devices->readAll(); @@ -105,7 +106,7 @@ QFuture Core::OmemoHandler::addPreKeyPairs(const QHash Core::OmemoHandler::addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair& keyPair) { - signedPreKeyPairs->forceRecord(keyId, keyPair); + signedPreKeyPairs->forceRecord(keyId, std::make_pair(keyPair.creationDate, keyPair.data)); return emptyVoidFuture(); } @@ -202,17 +203,3 @@ QDataStream & operator << (QDataStream& out, const QXmppOmemoStorage::OwnDevice& return out; } - -QDataStream & operator >> (QDataStream& in, QXmppOmemoStorage::SignedPreKeyPair& pair) { - in >> pair.creationDate; - in >> pair.data; - - return in; -} - -QDataStream & operator << (QDataStream& out, const QXmppOmemoStorage::SignedPreKeyPair& pair) { - out << pair.creationDate; - out << pair.data; - - return out; -} diff --git a/core/handlers/omemohandler.h b/core/handlers/omemohandler.h index bae14cb..cea9603 100644 --- a/core/handlers/omemohandler.h +++ b/core/handlers/omemohandler.h @@ -22,7 +22,6 @@ Q_DECLARE_METATYPE(QXmppOmemoStorage::OwnDevice); Q_DECLARE_METATYPE(QXmppOmemoStorage::Device); -Q_DECLARE_METATYPE(QXmppOmemoStorage::SignedPreKeyPair); namespace Core { class Account; @@ -30,6 +29,8 @@ class Account; class OmemoHandler : public QXmppOmemoStorage { public: + typedef std::pair SignedPreKeyPair; + OmemoHandler(Account* account); ~OmemoHandler() override; @@ -37,7 +38,7 @@ public: QFuture setOwnDevice(const std::optional &device) override; - QFuture addSignedPreKeyPair(uint32_t keyId, const SignedPreKeyPair &keyPair) override; + QFuture addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair &keyPair) override; QFuture removeSignedPreKeyPair(uint32_t keyId) override; QFuture addPreKeyPairs(const QHash &keyPairs) override; @@ -61,7 +62,7 @@ private: DataBase::Cache* meta; DataBase::Cache>* devices; DataBase::Cache* preKeyPairs; - DataBase::Cache* signedPreKeyPairs; + DataBase::Cache* signedPreKeyPairs; }; } @@ -72,7 +73,4 @@ QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::Device& device); QDataStream& operator << (QDataStream &out, const QXmppOmemoStorage::OwnDevice& device); QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::OwnDevice& device); -QDataStream& operator << (QDataStream &out, const QXmppOmemoStorage::SignedPreKeyPair& device); -QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::SignedPreKeyPair& device); - #endif // CORE_OMEMOHANDLER_H diff --git a/main/main.cpp b/main/main.cpp index 020d755..2958b66 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -54,7 +54,6 @@ int main(int argc, char *argv[]) qRegisterMetaType("QXmppOmemoStorage::OwnDevice"); qRegisterMetaTypeStreamOperators("QXmppOmemoStorage::OwnDevice"); qRegisterMetaType("QXmppOmemoStorage::Device"); - qRegisterMetaType("QXmppOmemoStorage::SignedPreKeyPair"); #endif QApplication app(argc, argv); diff --git a/shared/global.cpp b/shared/global.cpp index a6f17dc..2e2978a 100644 --- a/shared/global.cpp +++ b/shared/global.cpp @@ -20,6 +20,11 @@ #include "enums.h" #include "ui/models/roster.h" +#ifdef WITH_OMEMO +constexpr bool OMEMO_SUPPORT = true; +#else +constexpr bool OMEMO_SUPPORT = false +#endif Shared::Global* Shared::Global::instance = 0; const std::set Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"}; @@ -96,6 +101,7 @@ Shared::Global::Global(): }), defaultSystemStyle(QApplication::style()->objectName()), defaultSystemPalette(QApplication::palette()), + omemoSupport(OMEMO_SUPPORT), pluginSupport({ {"KWallet", false}, {"openFileManagerWindowJob", false}, diff --git a/shared/global.h b/shared/global.h index ebed931..d212cd1 100644 --- a/shared/global.h +++ b/shared/global.h @@ -99,6 +99,7 @@ namespace Shared { static QString getColorSchemeName(const QString& path); static void setTheme(const QString& path); static void setStyle(const QString& style); + const bool omemoSupport; template static T fromInt(int src);