DONT TAKE, BROKEN! first application of delay manager in code, reception of bundles

This commit is contained in:
Blue 2023-03-10 21:43:31 +03:00
parent 5ba97ecc25
commit 927bdf0dab
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
16 changed files with 261 additions and 139 deletions

View file

@ -19,7 +19,10 @@
#include "core/account.h"
#include "core/adapterfunctions.h"
constexpr const char* ns_omemo_2 = "urn:xmpp:omemo:2";
Core::OmemoHandler::OmemoHandler(Account* account) :
QObject(),
QXmppOmemoStorage(),
acc(account),
ownDevice(std::nullopt),
@ -166,6 +169,51 @@ void Core::OmemoHandler::getDevices(const QString& jid, std::list<Shared::KeyInf
}
}
void Core::OmemoHandler::requestBundles(const QString& jid) {
QXmppTask<void> task = acc->om->buildMissingSessions({jid});
task.then(this, std::bind(&OmemoHandler::onBundlesReceived, this, jid));
}
void Core::OmemoHandler::requestOwnBundles() {
QXmppTask<void> task = acc->om->buildMissingSessions({acc->getBareJid()});
task.then(this, std::bind(&OmemoHandler::onOwnBundlesReceived, this));
}
void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
std::list<Shared::KeyInfo> keys;
acc->oh->getDevices(jid, keys);
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid);
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
for (Shared::KeyInfo& key : keys) {
std::map<QByteArray, Shared::TrustLevel>::const_iterator itr = trustLevels.find(key.fingerPrint);
if (itr != trustLevels.end()) {
key.trustLevel = itr->second;
qDebug() << "Found a trust level for a device!";
}
}
acc->delay->receivedBundles(jid, keys);
}
void Core::OmemoHandler::onOwnBundlesReceived() {
QString jid = acc->getBareJid();
std::list<Shared::KeyInfo> keys;
acc->oh->getDevices(jid, keys);
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid);
qDebug() << "OMEMO info for " << jid << " devices:" << keys.size() << ", trustLevels:" << trustLevels.size();
for (Shared::KeyInfo& key : keys) {
std::map<QByteArray, Shared::TrustLevel>::const_iterator itr = trustLevels.find(key.fingerPrint);
if (itr != trustLevels.end()) {
key.trustLevel = itr->second;
qDebug() << "Found a trust level for a device!";
}
}
acc->delay->receivedOwnBundles(keys);
}
QDataStream & operator >> (QDataStream& in, QXmppOmemoStorage::Device& device) {
in >> device.label;