forked from blue/squawk
showing the button for encryption if there is at least one omemo key, trust summary update calculations
This commit is contained in:
parent
4f295fee3c
commit
69d797fe51
9 changed files with 134 additions and 39 deletions
|
@ -39,6 +39,10 @@ void Core::RosterHandler::initialize() {
|
|||
connect(acc->bm, &QXmppBookmarkManager::bookmarksReceived, this, &RosterHandler::bookmarksReceived);
|
||||
|
||||
connect(acc, &Account::pepSupportChanged, this, &RosterHandler::onPepSupportedChanged);
|
||||
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
connect(acc->th, &TrustHandler::trustLevelsChanged, this, &RosterHandler::onTrustChanged);
|
||||
#endif
|
||||
}
|
||||
|
||||
Core::RosterHandler::~RosterHandler() {
|
||||
|
@ -214,10 +218,13 @@ void Core::RosterHandler::onContactGroupAdded(const QString& group) {
|
|||
if (contact->groupsCount() == 1) {
|
||||
// not sure i need to handle it here, the situation with grouped and ungrouped contacts handled on the client anyway
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QVariant> cData({
|
||||
{"name", contact->getName()},
|
||||
{"state", QVariant::fromValue(contact->getSubscriptionState())},
|
||||
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
||||
{"trust", QVariant::fromValue(acc->th->getSummary(contact->jid))},
|
||||
#endif
|
||||
{"encryption", contact->isEncryptionEnabled()}
|
||||
});
|
||||
addToGroup(contact->jid, group);
|
||||
|
@ -229,7 +236,7 @@ void Core::RosterHandler::onContactGroupRemoved(const QString& group) {
|
|||
if (contact->groupsCount() == 0) {
|
||||
// not sure i need to handle it here, the situation with grouped and ungrouped contacts handled on the client anyway
|
||||
}
|
||||
|
||||
|
||||
emit acc->removeContact(contact->jid, group);
|
||||
removeFromGroup(contact->jid, group);
|
||||
}
|
||||
|
@ -246,12 +253,14 @@ void Core::RosterHandler::onContactEncryptionChanged(bool value) {
|
|||
|
||||
void Core::RosterHandler::onContactSubscriptionStateChanged(Shared::SubscriptionState cstate) {
|
||||
Contact* contact = static_cast<Contact*>(sender());
|
||||
QMap<QString, QVariant> cData({
|
||||
{"state", QVariant::fromValue(cstate)},
|
||||
});
|
||||
emit acc->changeContact(contact->jid, cData);
|
||||
emit acc->changeContact(contact->jid, {{"state", QVariant::fromValue(cstate)}});
|
||||
}
|
||||
|
||||
void Core::RosterHandler::onTrustChanged(const QString& jid, const Shared::TrustSummary& trust) {
|
||||
emit acc->changeContact(jid, {{"trust", QVariant::fromValue(trust)}});
|
||||
}
|
||||
|
||||
|
||||
void Core::RosterHandler::addToGroup(const QString& jid, const QString& group) {
|
||||
std::map<QString, std::set<QString>>::iterator gItr = groups.find(group);
|
||||
if (gItr == groups.end()) {
|
||||
|
@ -296,18 +305,18 @@ Core::RosterItem * Core::RosterHandler::getRosterItem(const QString& jid) {
|
|||
Core::Conference * Core::RosterHandler::getConference(const QString& jid) {
|
||||
Conference* item = 0;
|
||||
std::map<QString, Conference*>::const_iterator coitr = conferences.find(jid.toLower());
|
||||
if (coitr != conferences.end()) {
|
||||
if (coitr != conferences.end())
|
||||
item = coitr->second;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
Core::Contact * Core::RosterHandler::getContact(const QString& jid) {
|
||||
Contact* item = 0;
|
||||
std::map<QString, Contact*>::const_iterator citr = contacts.find(jid.toLower());
|
||||
if (citr != contacts.end()) {
|
||||
if (citr != contacts.end())
|
||||
item = citr->second;
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -527,7 +536,6 @@ void Core::RosterHandler::handleOffline() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void Core::RosterHandler::onPepSupportedChanged(Shared::Support support) {
|
||||
if (support == Shared::Support::supported) {
|
||||
for (const std::pair<const QString, Contact*>& pair : contacts) {
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
#include <shared/enums.h>
|
||||
#include <shared/message.h>
|
||||
#include <shared/trustsummary.h>
|
||||
|
||||
#include <core/contact.h>
|
||||
#include <core/conference.h>
|
||||
#include <core/delayManager/manager.h>
|
||||
|
@ -75,6 +77,7 @@ private slots:
|
|||
void onRosterItemAdded(const QString& bareJid);
|
||||
void onRosterItemChanged(const QString& bareJid);
|
||||
void onRosterItemRemoved(const QString& bareJid);
|
||||
void onTrustChanged(const QString& jid, const Shared::TrustSummary& trust);
|
||||
|
||||
void onMucRoomAdded(QXmppMucRoom* room);
|
||||
void onMucJoinedChanged(bool joined);
|
||||
|
|
|
@ -79,7 +79,25 @@ Core::TrustHandler::KeyCache * Core::TrustHandler::createNewCache(const QString&
|
|||
QXmppTask<void> Core::TrustHandler::resetAll(const QString& encryption) {
|
||||
securityPolicies->removeRecord(encryption);
|
||||
ownKeys->removeRecord(encryption);
|
||||
getCache(encryption)->drop();
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(encryption);
|
||||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
KeyCache* cache = itr->second;
|
||||
std::map<QString, Keys> keys = cache->readAll();
|
||||
cache->drop();
|
||||
|
||||
for (const std::pair<const QString, Keys>& pair : keys) {
|
||||
bool empty = true;
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : pair.second) {
|
||||
if (trust.second != Shared::TrustLevel::undecided) {
|
||||
empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty)
|
||||
emit trustLevelsChanged(pair.first, getSummary(pair.first));
|
||||
}
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
@ -109,6 +127,7 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys;
|
||||
Shared::TrustLevel oldLevel = convert(oldTrustLevel);
|
||||
Shared::TrustLevel newLevel = convert(newTrustLevel);
|
||||
std::set<QString> modifiedJids;
|
||||
KeyCache* cache = getCache(encryption);
|
||||
for (const QString& keyOwnerJid : keyOwnerJids) {
|
||||
Keys map = cache->getRecord(keyOwnerJid);
|
||||
|
@ -118,13 +137,16 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
if (current == oldLevel) {
|
||||
current = newLevel;
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, pair.first);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
++count;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
if (count > 0)
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
}
|
||||
}
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
}
|
||||
|
||||
|
@ -135,6 +157,7 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
{
|
||||
QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys;
|
||||
Shared::TrustLevel level = convert(trustLevel);
|
||||
std::set<QString> modifiedJids;
|
||||
KeyCache* cache = getCache(encryption);
|
||||
|
||||
for (MultySB::const_iterator itr = keyIds.begin(), end = keyIds.end(); itr != end; ++itr) {
|
||||
|
@ -150,14 +173,20 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
}
|
||||
if (changed) {
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
}
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
Keys map({{keyId, level}});
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
cache->addRecord(keyOwnerJid, map);
|
||||
}
|
||||
}
|
||||
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
}
|
||||
|
||||
|
@ -220,12 +249,41 @@ QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> Core::Trust
|
|||
}
|
||||
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption) {
|
||||
getCache(encryption)->drop();
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(encryption);
|
||||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
KeyCache* cache = itr->second;
|
||||
std::map<QString, Keys> keys = cache->readAll();
|
||||
cache->drop();
|
||||
|
||||
for (const std::pair<const QString, Keys>& pair : keys) {
|
||||
bool empty = true;
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : pair.second) {
|
||||
if (trust.second != Shared::TrustLevel::undecided) {
|
||||
empty = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty)
|
||||
emit trustLevelsChanged(pair.first, getSummary(pair.first));
|
||||
}
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const QString& keyOwnerJid) {
|
||||
getCache(encryption)->removeRecord(keyOwnerJid);
|
||||
std::map<QString, KeyCache*>::const_iterator itr = keysByProtocol.find(encryption);
|
||||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
KeyCache* cache = itr->second;
|
||||
try {
|
||||
cache->removeRecord(keyOwnerJid);
|
||||
emit trustLevelsChanged(keyOwnerJid, getSummary(keyOwnerJid)); //TODO there is a probability of notification without the actial change
|
||||
} catch (const DataBase::NotFound& e) {} //if the movin entry was empty or if it consisted of Undecided keys
|
||||
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
|
@ -236,14 +294,15 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const
|
|||
|
||||
KeyCache* cache = getCache(encryption);
|
||||
std::map<QString, Keys> data = cache->readAll();
|
||||
bool changed = false;
|
||||
std::set<QString> modifiedJids;
|
||||
|
||||
for (std::map<QString, Keys>::iterator cItr = data.begin(), cEnd = data.end(); cItr != cEnd; /*no increment*/) {
|
||||
Keys& byOwner = cItr->second;
|
||||
for (Keys::const_iterator itr = byOwner.begin(), end = byOwner.end(); itr != end; /*no increment*/) {
|
||||
const QByteArray& keyId = itr->first;
|
||||
if (set.erase(keyId)) {
|
||||
byOwner.erase(itr++);
|
||||
changed = true;
|
||||
modifiedJids.insert(cItr->first);
|
||||
} else
|
||||
++itr;
|
||||
}
|
||||
|
@ -252,8 +311,12 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const
|
|||
else
|
||||
++cItr;
|
||||
}
|
||||
if (changed)
|
||||
if (modifiedJids.size() > 0) {
|
||||
cache->replaceAll(data);
|
||||
}
|
||||
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
@ -278,11 +341,12 @@ QXmppTask<void> Core::TrustHandler::addKeys(
|
|||
result.first->second = level;
|
||||
}
|
||||
|
||||
if (had) {
|
||||
if (had)
|
||||
cache->changeRecord(keyOwnerJid, data);
|
||||
} else {
|
||||
else
|
||||
cache->addRecord(keyOwnerJid, data);
|
||||
}
|
||||
|
||||
emit trustLevelsChanged(keyOwnerJid, getSummary(keyOwnerJid));
|
||||
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,10 @@ public:
|
|||
TrustHandler(Account* account);
|
||||
~TrustHandler();
|
||||
|
||||
signals:
|
||||
void trustLevelsChanged(const QString& jid, const Shared::TrustSummary& summary) const;
|
||||
|
||||
public:
|
||||
typedef QMultiHash<QString, QByteArray> MultySB;
|
||||
typedef QHash<QString, MultySB> HashSM;
|
||||
typedef const QList<QString>& CLSR;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue