forked from blue/squawk
DONT TAKE, BROKEN! first application of delay manager in code, reception of bundles
This commit is contained in:
parent
5ba97ecc25
commit
927bdf0dab
16 changed files with 261 additions and 139 deletions
|
@ -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;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <functional>
|
||||
|
||||
#include <QXmppOmemoStorage.h>
|
||||
#include <cache.h>
|
||||
|
@ -32,8 +33,9 @@ Q_DECLARE_METATYPE(QXmppOmemoStorage::Device);
|
|||
namespace Core {
|
||||
class Account;
|
||||
|
||||
class OmemoHandler : public QXmppOmemoStorage
|
||||
class OmemoHandler :public QObject, public QXmppOmemoStorage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
typedef std::pair<QDateTime, QByteArray> SignedPreKeyPair;
|
||||
|
||||
|
@ -58,8 +60,14 @@ public:
|
|||
|
||||
bool hasOwnDevice();
|
||||
|
||||
void requestBundles(const QString& jid);
|
||||
void requestOwnBundles();
|
||||
void getDevices(const QString& jid, std::list<Shared::KeyInfo>& out) const;
|
||||
|
||||
private slots:
|
||||
void onBundlesReceived(const QString& jid);
|
||||
void onOwnBundlesReceived();
|
||||
|
||||
private:
|
||||
Account* acc;
|
||||
std::optional<OwnDevice> ownDevice;
|
||||
|
|
|
@ -156,7 +156,7 @@ void Core::RosterHandler::careAboutAvatar(Core::RosterItem* item, QMap<QString,
|
|||
} else {
|
||||
data.insert("avatarState", QVariant::fromValue(Shared::Avatar::empty));
|
||||
data.insert("avatarPath", "");
|
||||
acc->vh->requestVCard(item->jid);
|
||||
acc->delay->requestVCard(item->jid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ void Core::RosterHandler::handleNewRosterItem(Core::RosterItem* contact)
|
|||
connect(contact, &RosterItem::historyResponse, this->acc, &Account::onContactHistoryResponse);
|
||||
connect(contact, &RosterItem::nameChanged, this, &RosterHandler::onContactNameChanged);
|
||||
connect(contact, &RosterItem::avatarChanged, this, &RosterHandler::onContactAvatarChanged);
|
||||
connect(contact, &RosterItem::requestVCard, this->acc->vh, &VCardHandler::requestVCard);
|
||||
connect(contact, &RosterItem::requestVCard, acc->delay, &DelayManager::Manager::getVCard);
|
||||
}
|
||||
|
||||
void Core::RosterHandler::handleNewContact(Core::Contact* contact)
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <shared/message.h>
|
||||
#include <core/contact.h>
|
||||
#include <core/conference.h>
|
||||
#include <core/delayManager/manager.h>
|
||||
|
||||
namespace Core {
|
||||
|
||||
|
|
|
@ -89,8 +89,12 @@ QXmppTask<QXmpp::TrustLevel> Core::TrustHandler::trustLevel(
|
|||
const QString& keyOwnerJid,
|
||||
const QByteArray& keyId)
|
||||
{
|
||||
Keys map = getCache(encryption)->getRecord(keyOwnerJid);
|
||||
Shared::TrustLevel level = map.at(keyId);
|
||||
KeyCache* cache = getCache(encryption);
|
||||
Shared::TrustLevel level = Shared::TrustLevel::undecided;
|
||||
try {
|
||||
Keys map = cache->getRecord(keyOwnerJid);
|
||||
level = map.at(keyId);
|
||||
} catch (const DataBase::NotFound& e) {}
|
||||
return Core::makeReadyTask(std::move(convert(level)));
|
||||
}
|
||||
|
||||
|
@ -134,15 +138,22 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
for (MultySB::const_iterator itr = keyIds.begin(), end = keyIds.end(); itr != end; ++itr) {
|
||||
const QString& keyOwnerJid = itr.key();
|
||||
const QByteArray& keyId = itr.value();
|
||||
Keys map = cache->getRecord(keyOwnerJid);
|
||||
std::pair<Keys::iterator, bool> result = map.insert(std::make_pair(keyId, level));
|
||||
if (result.second) {
|
||||
try {
|
||||
Keys map = cache->getRecord(keyOwnerJid);
|
||||
std::pair<Keys::iterator, bool> result = map.insert(std::make_pair(keyId, level));
|
||||
bool changed = result.second;
|
||||
if (!changed && result.first->second != level) {
|
||||
result.first->second = level;
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
Keys map({{keyId, level}});
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
} else if (result.first->second != level) {
|
||||
result.first->second = level;
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
cache->addRecord(keyOwnerJid, map);
|
||||
}
|
||||
}
|
||||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
|
@ -199,9 +210,8 @@ QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> TrustHandle
|
|||
for (const std::pair<const QString, Keys>& value : storage) {
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& pair : value.second) {
|
||||
QXmpp::TrustLevel level = convert(pair.second);
|
||||
if (!trustLevels || trustLevels.testFlag(level)) {
|
||||
if (!trustLevels || trustLevels.testFlag(level))
|
||||
res[level].insert(value.first, pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Core::makeReadyTask(std::move(res));
|
||||
|
@ -219,9 +229,8 @@ QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QStrin
|
|||
|
||||
QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<QByteArray>& keyIds) {
|
||||
std::set<QByteArray> set;
|
||||
for (const QByteArray& keyId : keyIds) {
|
||||
for (const QByteArray& keyId : keyIds)
|
||||
set.insert(keyId);
|
||||
}
|
||||
|
||||
KeyCache* cache = getCache(encryption);
|
||||
std::map<QString, Keys> data = cache->readAll();
|
||||
|
@ -233,19 +242,16 @@ QXmppTask<void> TrustHandler::removeKeys(const QString& encryption, const QList<
|
|||
if (set.erase(keyId)) {
|
||||
byOwner.erase(itr++);
|
||||
changed = true;
|
||||
} else {
|
||||
} else
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
if (byOwner.size() > 0) {
|
||||
if (byOwner.size() > 0)
|
||||
data.erase(cItr++);
|
||||
} else {
|
||||
else
|
||||
++cItr;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
if (changed)
|
||||
cache->replaceAll(data);
|
||||
}
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
@ -266,9 +272,8 @@ QXmppTask<void> TrustHandler::addKeys(
|
|||
} catch (const DataBase::NotFound& e) {}
|
||||
for (const QByteArray& keyId : keyIds) {
|
||||
std::pair<Keys::iterator, bool> result = data.insert(std::make_pair(keyId, level));
|
||||
if (!result.second) {
|
||||
if (!result.second)
|
||||
result.first->second = level;
|
||||
}
|
||||
}
|
||||
|
||||
if (had) {
|
||||
|
|
|
@ -17,13 +17,9 @@
|
|||
#include "vcardhandler.h"
|
||||
#include "core/account.h"
|
||||
|
||||
constexpr const char* ns_omemo_2 = "urn:xmpp:omemo:2";
|
||||
|
||||
Core::VCardHandler::VCardHandler(Account* account):
|
||||
QObject(),
|
||||
acc(account),
|
||||
ownVCardRequestInProgress(false),
|
||||
pendingVCardRequests(),
|
||||
avatarHash(),
|
||||
avatarType()
|
||||
{
|
||||
|
@ -90,36 +86,20 @@ void Core::VCardHandler::onVCardReceived(const QXmppVCardIq& card) {
|
|||
if (comps.size() > 1) {
|
||||
resource = comps.back();
|
||||
}
|
||||
pendingVCardRequests.erase(id);
|
||||
RosterItem* item = acc->rh->getRosterItem(jid);
|
||||
|
||||
if (item == 0) {
|
||||
if (jid == acc->getBareJid()) {
|
||||
if (jid == acc->getBareJid())
|
||||
onOwnVCardReceived(card);
|
||||
} else {
|
||||
else
|
||||
qDebug() << "received vCard" << jid << "doesn't belong to any of known contacts or conferences, skipping";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Shared::Info info(jid, Shared::EntryType::contact);
|
||||
item->handleResponseVCard(card, resource, info.getVCardRef());
|
||||
#ifdef WITH_OMEMO
|
||||
std::list<Shared::KeyInfo>& aks = info.getActiveKeysRef();
|
||||
acc->oh->getDevices(jid, aks);
|
||||
std::map<QByteArray, Shared::TrustLevel> trustLevels = acc->th->getKeys(ns_omemo_2, jid);
|
||||
|
||||
qDebug() << "OMEMO info for " << jid << " devices:" << aks.size() << ", trustLevels:" << trustLevels.size();
|
||||
for (Shared::KeyInfo& key : aks) {
|
||||
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!";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
emit acc->infoReady(info);
|
||||
Shared::VCard vCard;
|
||||
item->handleResponseVCard(card, resource, vCard);
|
||||
acc->delay->receivedVCard(id, vCard);
|
||||
}
|
||||
|
||||
void Core::VCardHandler::onOwnVCardReceived(const QXmppVCardIq& card) {
|
||||
|
@ -201,10 +181,7 @@ void Core::VCardHandler::onOwnVCardReceived(const QXmppVCardIq& card) {
|
|||
emit acc->changed(change);
|
||||
}
|
||||
|
||||
ownVCardRequestInProgress = false;
|
||||
|
||||
Shared::Info info(acc->getBareJid(), Shared::EntryType::ownAccount);
|
||||
Shared::VCard& vCard = info.getVCardRef();
|
||||
Shared::VCard vCard;
|
||||
initializeVCard(vCard, card);
|
||||
|
||||
if (avatarType.size() > 0) {
|
||||
|
@ -214,52 +191,24 @@ void Core::VCardHandler::onOwnVCardReceived(const QXmppVCardIq& card) {
|
|||
vCard.setAvatarType(Shared::Avatar::empty);
|
||||
}
|
||||
|
||||
emit acc->infoReady(info);
|
||||
}
|
||||
|
||||
void Core::VCardHandler::handleOffline() {
|
||||
pendingVCardRequests.clear();
|
||||
for (const QString& jid : pendingVCardRequests) {
|
||||
Shared::Info info(jid, Shared::EntryType::none);
|
||||
emit acc->infoReady(info); //need to show it better in the future, like with an error
|
||||
}
|
||||
pendingVCardRequests.clear();
|
||||
ownVCardRequestInProgress = false;
|
||||
}
|
||||
|
||||
void Core::VCardHandler::requestVCard(const QString& jid) {
|
||||
if (pendingVCardRequests.find(jid) == pendingVCardRequests.end()) {
|
||||
qDebug() << "requesting vCard" << jid;
|
||||
if (jid == acc->getBareJid()) {
|
||||
if (!ownVCardRequestInProgress) {
|
||||
acc->vm->requestClientVCard();
|
||||
ownVCardRequestInProgress = true;
|
||||
}
|
||||
} else {
|
||||
acc->vm->requestVCard(jid);
|
||||
pendingVCardRequests.insert(jid);
|
||||
}
|
||||
}
|
||||
if (acc->delay->isOwnVCardPending())
|
||||
acc->delay->receivedOwnVCard(vCard);
|
||||
}
|
||||
|
||||
void Core::VCardHandler::handlePresenceOfMyAccountChange(const QXmppPresence& p_presence) {
|
||||
if (!ownVCardRequestInProgress) {
|
||||
if (!acc->delay->isOwnVCardPending()) {
|
||||
switch (p_presence.vCardUpdateType()) {
|
||||
case QXmppPresence::VCardUpdateNone: //this presence has nothing to do with photo
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateNotReady: //let's say the photo didn't change here
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateNoPhoto: //there is no photo, need to drop if any
|
||||
if (avatarType.size() > 0) {
|
||||
acc->vm->requestClientVCard();
|
||||
ownVCardRequestInProgress = true;
|
||||
}
|
||||
if (avatarType.size() > 0)
|
||||
acc->delay->getOwnVCard();
|
||||
break;
|
||||
case QXmppPresence::VCardUpdateValidPhoto: //there is a photo, need to load
|
||||
if (avatarHash != p_presence.photoHash()) {
|
||||
acc->vm->requestClientVCard();
|
||||
ownVCardRequestInProgress = true;
|
||||
}
|
||||
if (avatarHash != p_presence.photoHash())
|
||||
acc->delay->getOwnVCard();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,8 +42,6 @@ public:
|
|||
VCardHandler(Account* account);
|
||||
~VCardHandler();
|
||||
|
||||
void handleOffline();
|
||||
void requestVCard(const QString& jid);
|
||||
void handlePresenceOfMyAccountChange(const QXmppPresence& p_presence);
|
||||
void uploadVCard(const Shared::VCard& card);
|
||||
QString getAvatarPath() const;
|
||||
|
@ -57,8 +55,6 @@ private slots:
|
|||
private:
|
||||
Account* acc;
|
||||
|
||||
bool ownVCardRequestInProgress;
|
||||
std::set<QString> pendingVCardRequests;
|
||||
QString avatarHash;
|
||||
QString avatarType;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue