replaced one structure, stored omemo support in Global object

This commit is contained in:
Blue 2022-12-29 01:41:59 +03:00
parent dfe72ca36c
commit 758a9d95f3
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
5 changed files with 17 additions and 26 deletions

View File

@ -26,7 +26,7 @@ Core::OmemoHandler::OmemoHandler(Account* account) :
meta(db.addCache<QString, QVariant>("meta")), meta(db.addCache<QString, QVariant>("meta")),
devices(db.addCache<QString, QHash<uint32_t, Device>>("devices")), devices(db.addCache<QString, QHash<uint32_t, Device>>("devices")),
preKeyPairs(db.addCache<uint32_t, QByteArray>("preKeyPairs")), preKeyPairs(db.addCache<uint32_t, QByteArray>("preKeyPairs")),
signedPreKeyPairs(db.addCache<uint32_t, QXmppOmemoStorage::SignedPreKeyPair>("signedPreKeyPairs")) signedPreKeyPairs(db.addCache<uint32_t, SignedPreKeyPair>("signedPreKeyPairs"))
{ {
db.open(); db.open();
try { try {
@ -61,9 +61,10 @@ QFuture<QXmppOmemoStorage::OmemoData> Core::OmemoHandler::allData() {
data.preKeyPairs.insert(pair.first, pair.second); data.preKeyPairs.insert(pair.first, pair.second);
} }
std::map<uint32_t, QXmppOmemoStorage::SignedPreKeyPair> spre = signedPreKeyPairs->readAll(); std::map<uint32_t, SignedPreKeyPair> spre = signedPreKeyPairs->readAll();
for (const std::pair<const uint32_t, QXmppOmemoStorage::SignedPreKeyPair>& pair : spre) { for (const std::pair<const uint32_t, SignedPreKeyPair>& pair : spre) {
data.signedPreKeyPairs.insert(pair.first, pair.second); QXmppOmemoStorage::SignedPreKeyPair qxpair = {pair.second.first, pair.second.second};
data.signedPreKeyPairs.insert(pair.first, qxpair);
} }
std::map<QString, QHash<uint32_t, Device>> devs = devices->readAll(); std::map<QString, QHash<uint32_t, Device>> devs = devices->readAll();
@ -105,7 +106,7 @@ QFuture<void> Core::OmemoHandler::addPreKeyPairs(const QHash<uint32_t, QByteArra
} }
QFuture<void> Core::OmemoHandler::addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair& keyPair) { QFuture<void> 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(); return emptyVoidFuture();
} }
@ -202,17 +203,3 @@ QDataStream & operator << (QDataStream& out, const QXmppOmemoStorage::OwnDevice&
return out; 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;
}

View File

@ -22,7 +22,6 @@
Q_DECLARE_METATYPE(QXmppOmemoStorage::OwnDevice); Q_DECLARE_METATYPE(QXmppOmemoStorage::OwnDevice);
Q_DECLARE_METATYPE(QXmppOmemoStorage::Device); Q_DECLARE_METATYPE(QXmppOmemoStorage::Device);
Q_DECLARE_METATYPE(QXmppOmemoStorage::SignedPreKeyPair);
namespace Core { namespace Core {
class Account; class Account;
@ -30,6 +29,8 @@ class Account;
class OmemoHandler : public QXmppOmemoStorage class OmemoHandler : public QXmppOmemoStorage
{ {
public: public:
typedef std::pair<QDateTime, QByteArray> SignedPreKeyPair;
OmemoHandler(Account* account); OmemoHandler(Account* account);
~OmemoHandler() override; ~OmemoHandler() override;
@ -37,7 +38,7 @@ public:
QFuture<void> setOwnDevice(const std::optional<OwnDevice> &device) override; QFuture<void> setOwnDevice(const std::optional<OwnDevice> &device) override;
QFuture<void> addSignedPreKeyPair(uint32_t keyId, const SignedPreKeyPair &keyPair) override; QFuture<void> addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair &keyPair) override;
QFuture<void> removeSignedPreKeyPair(uint32_t keyId) override; QFuture<void> removeSignedPreKeyPair(uint32_t keyId) override;
QFuture<void> addPreKeyPairs(const QHash<uint32_t, QByteArray> &keyPairs) override; QFuture<void> addPreKeyPairs(const QHash<uint32_t, QByteArray> &keyPairs) override;
@ -61,7 +62,7 @@ private:
DataBase::Cache<QString, QVariant>* meta; DataBase::Cache<QString, QVariant>* meta;
DataBase::Cache<QString, QHash<uint32_t, Device>>* devices; DataBase::Cache<QString, QHash<uint32_t, Device>>* devices;
DataBase::Cache<uint32_t, QByteArray>* preKeyPairs; DataBase::Cache<uint32_t, QByteArray>* preKeyPairs;
DataBase::Cache<uint32_t, QXmppOmemoStorage::SignedPreKeyPair>* signedPreKeyPairs; DataBase::Cache<uint32_t, SignedPreKeyPair>* signedPreKeyPairs;
}; };
} }
@ -72,7 +73,4 @@ QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::Device& device);
QDataStream& operator << (QDataStream &out, const QXmppOmemoStorage::OwnDevice& device); QDataStream& operator << (QDataStream &out, const QXmppOmemoStorage::OwnDevice& device);
QDataStream& operator >> (QDataStream &in, 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 #endif // CORE_OMEMOHANDLER_H

View File

@ -54,7 +54,6 @@ int main(int argc, char *argv[])
qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice"); qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
qRegisterMetaTypeStreamOperators<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice"); qRegisterMetaTypeStreamOperators<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
qRegisterMetaType<QXmppOmemoStorage::Device>("QXmppOmemoStorage::Device"); qRegisterMetaType<QXmppOmemoStorage::Device>("QXmppOmemoStorage::Device");
qRegisterMetaType<QXmppOmemoStorage::SignedPreKeyPair>("QXmppOmemoStorage::SignedPreKeyPair");
#endif #endif
QApplication app(argc, argv); QApplication app(argc, argv);

View File

@ -20,6 +20,11 @@
#include "enums.h" #include "enums.h"
#include "ui/models/roster.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; Shared::Global* Shared::Global::instance = 0;
const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"}; const std::set<QString> Shared::Global::supportedImagesExts = {"png", "jpg", "webp", "jpeg", "gif", "svg"};
@ -96,6 +101,7 @@ Shared::Global::Global():
}), }),
defaultSystemStyle(QApplication::style()->objectName()), defaultSystemStyle(QApplication::style()->objectName()),
defaultSystemPalette(QApplication::palette()), defaultSystemPalette(QApplication::palette()),
omemoSupport(OMEMO_SUPPORT),
pluginSupport({ pluginSupport({
{"KWallet", false}, {"KWallet", false},
{"openFileManagerWindowJob", false}, {"openFileManagerWindowJob", false},

View File

@ -99,6 +99,7 @@ namespace Shared {
static QString getColorSchemeName(const QString& path); static QString getColorSchemeName(const QString& path);
static void setTheme(const QString& path); static void setTheme(const QString& path);
static void setStyle(const QString& style); static void setStyle(const QString& style);
const bool omemoSupport;
template<typename T> template<typename T>
static T fromInt(int src); static T fromInt(int src);