forked from blue/squawk
some refactoring, some improvements
This commit is contained in:
parent
be466fbad1
commit
e31ef78e71
13 changed files with 188 additions and 147 deletions
|
@ -358,8 +358,8 @@ std::pair<Shared::Message::State, QString> Core::MessageHandler::scheduleSending
|
|||
const QXmppE2eeExtension::MessageEncryptResult& res = task.result();
|
||||
if (std::holds_alternative<std::unique_ptr<QXmppMessage>>(res)) {
|
||||
const std::unique_ptr<QXmppMessage>& encrypted = std::get<std::unique_ptr<QXmppMessage>>(res);
|
||||
encrypted->setBody("This message is encrypted with OMEMO 2 but could not be decrypted");
|
||||
encrypted->setOutOfBandUrl("");
|
||||
encrypted->setBody(QString());
|
||||
encrypted->setOutOfBandUrl(QString());
|
||||
bool success = acc->client.sendPacket(*encrypted.get());
|
||||
if (success)
|
||||
return {Shared::Message::State::sent, ""};
|
||||
|
@ -375,8 +375,8 @@ std::pair<Shared::Message::State, QString> Core::MessageHandler::scheduleSending
|
|||
task.then(this, [this, id] (QXmppE2eeExtension::MessageEncryptResult&& result) {
|
||||
if (std::holds_alternative<std::unique_ptr<QXmppMessage>>(result)) {
|
||||
const std::unique_ptr<QXmppMessage>& encrypted = std::get<std::unique_ptr<QXmppMessage>>(result);
|
||||
encrypted->setBody("This message is encrypted with OMEMO 2 but could not be decrypted");
|
||||
encrypted->setOutOfBandUrl("");
|
||||
encrypted->setBody(QString());
|
||||
encrypted->setOutOfBandUrl(QString());
|
||||
bool success = acc->client.sendPacket(*encrypted.get());
|
||||
if (success) {
|
||||
std::tuple<bool, QString, QString> ids = getOriginalPendingMessageId(id, false);
|
||||
|
@ -602,7 +602,7 @@ void Core::MessageHandler::onUploadFileComplete(const std::list<Shared::MessageI
|
|||
|
||||
void Core::MessageHandler::sendMessageWithLocalUploadedFile(Shared::Message msg, const QString& url, bool newMessage) {
|
||||
msg.setOutOfBandUrl(url);
|
||||
if (msg.getBody().size() == 0) //not sure why, but most messages do that
|
||||
if (msg.getBody().size() == 0) //not sure why, but most messengers do that
|
||||
msg.setBody(url); //they duplicate oob in body, some of them wouldn't even show an attachment if you don't do that
|
||||
|
||||
performSending(msg, pendingCorrectionMessages.at(msg.getId()), newMessage);
|
||||
|
|
|
@ -52,6 +52,7 @@ QXmppTask<QXmppOmemoStorage::OmemoData> Core::OmemoHandler::allData() {
|
|||
OmemoData data;
|
||||
data.ownDevice = ownDevice;
|
||||
|
||||
// LMDBAL::Transaction txn = db.beginReadOnlyTransaction(); TODO need to enable transaction after fixing LMDBAL
|
||||
std::map<uint32_t, QByteArray> pkeys = preKeyPairs->readAll();
|
||||
for (const std::pair<const uint32_t, QByteArray>& pair : pkeys) {
|
||||
data.preKeyPairs.insert(pair.first, pair.second);
|
||||
|
@ -73,28 +74,30 @@ QXmppTask<QXmppOmemoStorage::OmemoData> Core::OmemoHandler::allData() {
|
|||
|
||||
QXmppTask<void> Core::OmemoHandler::addDevice(const QString& jid, uint32_t deviceId, const QXmppOmemoStorage::Device& device) {
|
||||
QHash<uint32_t, Device> devs;
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
bool had = true;
|
||||
try {
|
||||
devs = devices->getRecord(jid);
|
||||
devices->getRecord(jid, devs, txn);
|
||||
} catch (const LMDBAL::NotFound& error) {
|
||||
had = false;
|
||||
}
|
||||
|
||||
devs.insert(deviceId, device);
|
||||
if (had) {
|
||||
devices->changeRecord(jid, devs);
|
||||
} else {
|
||||
devices->addRecord(jid, devs);
|
||||
}
|
||||
devs.insert(deviceId, device); //overwrites
|
||||
if (had)
|
||||
devices->changeRecord(jid, devs, txn);
|
||||
else
|
||||
devices->addRecord(jid, devs, txn);
|
||||
|
||||
txn.commit();
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
QXmppTask<void> Core::OmemoHandler::addPreKeyPairs(const QHash<uint32_t, QByteArray>& keyPairs) {
|
||||
for (QHash<uint32_t, QByteArray>::const_iterator itr = keyPairs.begin(), end = keyPairs.end(); itr != end; ++itr) {
|
||||
preKeyPairs->forceRecord(itr.key(), itr.value());
|
||||
}
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
for (QHash<uint32_t, QByteArray>::const_iterator itr = keyPairs.begin(), end = keyPairs.end(); itr != end; ++itr)
|
||||
preKeyPairs->forceRecord(itr.key(), itr.value(), txn);
|
||||
|
||||
txn.commit();
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
|
@ -104,13 +107,15 @@ QXmppTask<void> Core::OmemoHandler::addSignedPreKeyPair(uint32_t keyId, const QX
|
|||
}
|
||||
|
||||
QXmppTask<void> Core::OmemoHandler::removeDevice(const QString& jid, uint32_t deviceId) {
|
||||
QHash<uint32_t, Device> devs = devices->getRecord(jid);
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
QHash<uint32_t, Device> devs = devices->getRecord(jid, txn);
|
||||
devs.remove(deviceId);
|
||||
if (devs.isEmpty()) {
|
||||
devices->removeRecord(jid);
|
||||
} else {
|
||||
devices->changeRecord(jid, devs);
|
||||
}
|
||||
if (devs.isEmpty())
|
||||
devices->removeRecord(jid, txn);
|
||||
else
|
||||
devices->changeRecord(jid, devs, txn);
|
||||
|
||||
txn.commit();
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
|
@ -120,7 +125,11 @@ QXmppTask<void> Core::OmemoHandler::removeDevices(const QString& jid) {
|
|||
}
|
||||
|
||||
QXmppTask<void> Core::OmemoHandler::removePreKeyPair(uint32_t keyId) {
|
||||
preKeyPairs->removeRecord(keyId);
|
||||
try {
|
||||
preKeyPairs->removeRecord(keyId);
|
||||
} catch (const LMDBAL::NotFound& e) {
|
||||
qDebug() << "Couldn't remove preKeyPair " << e.what();
|
||||
}
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
||||
|
@ -135,15 +144,12 @@ QXmppTask<void> Core::OmemoHandler::setOwnDevice(const std::optional<OwnDevice>&
|
|||
bool had = ownDevice.has_value();
|
||||
ownDevice = device;
|
||||
if (ownDevice.has_value()) {
|
||||
if (had) {
|
||||
if (had)
|
||||
meta->changeRecord("ownDevice", QVariant::fromValue(ownDevice.value()));
|
||||
} else {
|
||||
else
|
||||
meta->addRecord("ownDevice", QVariant::fromValue(ownDevice.value()));
|
||||
}
|
||||
} else {
|
||||
if (had) {
|
||||
meta->removeRecord("ownDevice");
|
||||
}
|
||||
} else if (had) {
|
||||
meta->removeRecord("ownDevice");
|
||||
}
|
||||
return Core::makeReadyTask();
|
||||
}
|
||||
|
@ -158,7 +164,7 @@ QXmppTask<void> Core::OmemoHandler::resetAll() {
|
|||
void Core::OmemoHandler::getDevices(const QString& jid, std::list<Shared::KeyInfo>& out) const {
|
||||
QHash<uint32_t, Device> devs;
|
||||
try {
|
||||
devs = devices->getRecord(jid);
|
||||
devices->getRecord(jid, devs);
|
||||
} catch (const LMDBAL::NotFound& error) {}
|
||||
|
||||
for (QHash<uint32_t, Device>::const_iterator itr = devs.begin(), end = devs.end(); itr != end; ++itr) {
|
||||
|
@ -169,6 +175,10 @@ 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});
|
||||
Contact* cnt = acc->rh->getContact(jid);
|
||||
if (cnt)
|
||||
cnt->omemoBundles = Shared::Possible::discovering;
|
||||
|
||||
task.then(this, std::bind(&OmemoHandler::onBundlesReceived, this, jid));
|
||||
}
|
||||
|
||||
|
@ -191,6 +201,10 @@ void Core::OmemoHandler::onBundlesReceived(const QString& jid) {
|
|||
}
|
||||
}
|
||||
|
||||
Contact* cnt = acc->rh->getContact(jid);
|
||||
if (cnt)
|
||||
cnt->omemoBundles = Shared::Possible::present;
|
||||
|
||||
acc->delay->receivedBundles(jid, keys);
|
||||
}
|
||||
|
||||
|
@ -217,7 +231,6 @@ void Core::OmemoHandler::onOmemoDeviceAdded(const QString& jid, uint32_t id) {
|
|||
qDebug() << "OMEMO device added for" << jid;
|
||||
}
|
||||
|
||||
|
||||
QDataStream & operator >> (QDataStream& in, QXmppOmemoStorage::Device& device) {
|
||||
in >> device.label;
|
||||
in >> device.keyId;
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
// Squawk messenger.
|
||||
// Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CORE_OMEMOHANDLER_H
|
||||
#define CORE_OMEMOHANDLER_H
|
||||
/*
|
||||
* Squawk messenger.
|
||||
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <list>
|
||||
|
@ -87,5 +87,3 @@ QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::Device& device);
|
|||
|
||||
QDataStream& operator << (QDataStream &out, const QXmppOmemoStorage::OwnDevice& device);
|
||||
QDataStream& operator >> (QDataStream &in, QXmppOmemoStorage::OwnDevice& device);
|
||||
|
||||
#endif // CORE_OMEMOHANDLER_H
|
||||
|
|
|
@ -28,9 +28,8 @@ Core::TrustHandler::TrustHandler(Account* account):
|
|||
ownKeys(db.addCache<QString, QByteArray>("ownKeys")),
|
||||
keysByProtocol()
|
||||
{
|
||||
if (!protocols.open(QIODevice::ReadWrite | QIODevice::Text)) { //never supposed to happen since I have just created a directory;
|
||||
if (!protocols.open(QIODevice::ReadWrite | QIODevice::Text)) //never supposed to happen since I have just created a directory;
|
||||
throw LMDBAL::Directory(protocols.fileName().toStdString());
|
||||
}
|
||||
|
||||
QTextStream in(&protocols);
|
||||
while(!in.atEnd()) {
|
||||
|
@ -53,11 +52,10 @@ Core::TrustHandler::~TrustHandler() {
|
|||
|
||||
Core::TrustHandler::KeyCache * Core::TrustHandler::getCache(const QString& encryption) {
|
||||
std::map<QString, KeyCache*>::iterator itr = keysByProtocol.find(encryption);
|
||||
if (itr == keysByProtocol.end()) {
|
||||
if (itr == keysByProtocol.end())
|
||||
return createNewCache(encryption);
|
||||
} else {
|
||||
else
|
||||
return itr->second;
|
||||
}
|
||||
}
|
||||
|
||||
Core::TrustHandler::KeyCache * Core::TrustHandler::createNewCache(const QString& encryption) {
|
||||
|
@ -65,9 +63,9 @@ Core::TrustHandler::KeyCache * Core::TrustHandler::createNewCache(const QString&
|
|||
KeyCache* cache = db.addCache<QString, Keys>(encryption.toStdString());
|
||||
keysByProtocol.insert(std::make_pair(encryption, cache));
|
||||
|
||||
if(!protocols.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||
if (!protocols.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
|
||||
throw LMDBAL::Directory(protocols.fileName().toStdString());
|
||||
}
|
||||
|
||||
QTextStream out(&protocols);
|
||||
out << encryption + "\n";
|
||||
protocols.close();
|
||||
|
@ -83,10 +81,12 @@ QXmppTask<void> Core::TrustHandler::resetAll(const QString& encryption) {
|
|||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
KeyCache* cache = itr->second;
|
||||
std::map<QString, Keys> keys = cache->readAll();
|
||||
cache->drop();
|
||||
std::map<QString, Keys> keys = cache->readAll(txn);
|
||||
cache->drop(txn);
|
||||
|
||||
txn.commit();
|
||||
for (const std::pair<const QString, Keys>& pair : keys) {
|
||||
bool empty = true;
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : pair.second) {
|
||||
|
@ -105,8 +105,8 @@ QXmppTask<void> Core::TrustHandler::resetAll(const QString& encryption) {
|
|||
QXmppTask<QXmpp::TrustLevel> Core::TrustHandler::trustLevel(
|
||||
const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
const QByteArray& keyId)
|
||||
{
|
||||
const QByteArray& keyId
|
||||
) {
|
||||
KeyCache* cache = getCache(encryption);
|
||||
Shared::TrustLevel level = Shared::TrustLevel::undecided;
|
||||
try {
|
||||
|
@ -122,15 +122,17 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
const QString& encryption,
|
||||
const QList<QString>& keyOwnerJids,
|
||||
QXmpp::TrustLevel oldTrustLevel,
|
||||
QXmpp::TrustLevel newTrustLevel)
|
||||
{
|
||||
QXmpp::TrustLevel newTrustLevel
|
||||
) {
|
||||
QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys;
|
||||
Shared::TrustLevel oldLevel = convert(oldTrustLevel);
|
||||
Shared::TrustLevel newLevel = convert(newTrustLevel);
|
||||
std::set<QString> modifiedJids;
|
||||
KeyCache* cache = getCache(encryption);
|
||||
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
for (const QString& keyOwnerJid : keyOwnerJids) {
|
||||
Keys map = cache->getRecord(keyOwnerJid);
|
||||
Keys map = cache->getRecord(keyOwnerJid, txn);
|
||||
uint count = 0;
|
||||
for (std::pair<const QByteArray, Shared::TrustLevel>& pair : map) {
|
||||
Shared::TrustLevel& current = pair.second;
|
||||
|
@ -142,8 +144,9 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
}
|
||||
}
|
||||
if (count > 0)
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
cache->changeRecord(keyOwnerJid, map, txn);
|
||||
}
|
||||
txn.commit();
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
|
@ -153,18 +156,19 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::setTrustLevel(
|
||||
const QString& encryption,
|
||||
const QMultiHash<QString, QByteArray>& keyIds,
|
||||
QXmpp::TrustLevel trustLevel)
|
||||
{
|
||||
QXmpp::TrustLevel trustLevel
|
||||
) {
|
||||
QHash<QString, QMultiHash<QString, QByteArray>> modifiedKeys;
|
||||
Shared::TrustLevel level = convert(trustLevel);
|
||||
std::set<QString> modifiedJids;
|
||||
KeyCache* cache = getCache(encryption);
|
||||
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
for (MultySB::const_iterator itr = keyIds.begin(), end = keyIds.end(); itr != end; ++itr) {
|
||||
const QString& keyOwnerJid = itr.key();
|
||||
const QByteArray& keyId = itr.value();
|
||||
try {
|
||||
Keys map = cache->getRecord(keyOwnerJid);
|
||||
Keys map = cache->getRecord(keyOwnerJid, txn);
|
||||
std::pair<Keys::iterator, bool> result = map.insert(std::make_pair(keyId, level));
|
||||
bool changed = result.second;
|
||||
if (!changed && result.first->second != level) {
|
||||
|
@ -174,15 +178,16 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
if (changed) {
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
cache->changeRecord(keyOwnerJid, map);
|
||||
cache->changeRecord(keyOwnerJid, map, txn);
|
||||
}
|
||||
} catch (const LMDBAL::NotFound& e) {
|
||||
Keys map({{keyId, level}});
|
||||
modifiedKeys[encryption].insert(keyOwnerJid, keyId);
|
||||
modifiedJids.insert(keyOwnerJid);
|
||||
cache->addRecord(keyOwnerJid, map);
|
||||
cache->addRecord(keyOwnerJid, map, txn);
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
@ -190,10 +195,11 @@ QXmppTask<QHash<QString, QMultiHash<QString, QByteArray>>> Core::TrustHandler::s
|
|||
return Core::makeReadyTask(std::move(modifiedKeys));
|
||||
}
|
||||
|
||||
QXmppTask<bool> Core::TrustHandler::hasKey(const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
{
|
||||
QXmppTask<bool> Core::TrustHandler::hasKey(
|
||||
const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
QXmpp::TrustLevels trustLevels
|
||||
) {
|
||||
KeyCache* cache = getCache(encryption);
|
||||
bool found = false;
|
||||
try {
|
||||
|
@ -211,8 +217,8 @@ QXmppTask<bool> Core::TrustHandler::hasKey(const QString& encryption,
|
|||
QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> Core::TrustHandler::keys(
|
||||
const QString& encryption,
|
||||
const QList<QString>& keyOwnerJids,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
{
|
||||
QXmpp::TrustLevels trustLevels
|
||||
) {
|
||||
HSHBTL res;
|
||||
|
||||
KeyCache* cache = getCache(encryption);
|
||||
|
@ -233,8 +239,8 @@ QXmppTask<QHash<QString, QHash<QByteArray, QXmpp::TrustLevel>>> Core::TrustHandl
|
|||
|
||||
QXmppTask<QHash<QXmpp::TrustLevel, QMultiHash<QString, QByteArray>>> Core::TrustHandler::keys(
|
||||
const QString& encryption,
|
||||
QXmpp::TrustLevels trustLevels)
|
||||
{
|
||||
QXmpp::TrustLevels trustLevels
|
||||
) {
|
||||
QHash<TL, MultySB> res;
|
||||
KeyCache* cache = getCache(encryption);
|
||||
std::map<QString, Keys> storage = cache->readAll();
|
||||
|
@ -253,9 +259,11 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption) {
|
|||
if (itr == keysByProtocol.end())
|
||||
return Core::makeReadyTask();
|
||||
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
KeyCache* cache = itr->second;
|
||||
std::map<QString, Keys> keys = cache->readAll();
|
||||
cache->drop();
|
||||
std::map<QString, Keys> keys = cache->readAll(txn);
|
||||
cache->drop(txn);
|
||||
txn.commit();
|
||||
|
||||
for (const std::pair<const QString, Keys>& pair : keys) {
|
||||
bool empty = true;
|
||||
|
@ -292,8 +300,9 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const
|
|||
for (const QByteArray& keyId : keyIds)
|
||||
set.insert(keyId);
|
||||
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
KeyCache* cache = getCache(encryption);
|
||||
std::map<QString, Keys> data = cache->readAll();
|
||||
std::map<QString, Keys> data = cache->readAll(txn);
|
||||
std::set<QString> modifiedJids;
|
||||
|
||||
for (std::map<QString, Keys>::iterator cItr = data.begin(), cEnd = data.end(); cItr != cEnd; /*no increment*/) {
|
||||
|
@ -311,10 +320,10 @@ QXmppTask<void> Core::TrustHandler::removeKeys(const QString& encryption, const
|
|||
else
|
||||
++cItr;
|
||||
}
|
||||
if (modifiedJids.size() > 0) {
|
||||
cache->replaceAll(data);
|
||||
}
|
||||
if (modifiedJids.size() > 0)
|
||||
cache->replaceAll(data, txn);
|
||||
|
||||
txn.commit();
|
||||
for (const QString& jid : modifiedJids)
|
||||
emit trustLevelsChanged(jid, getSummary(jid));
|
||||
|
||||
|
@ -325,14 +334,15 @@ QXmppTask<void> Core::TrustHandler::addKeys(
|
|||
const QString& encryption,
|
||||
const QString& keyOwnerJid,
|
||||
const QList<QByteArray>& keyIds,
|
||||
QXmpp::TrustLevel trustLevel)
|
||||
{
|
||||
QXmpp::TrustLevel trustLevel
|
||||
) {
|
||||
KeyCache* cache = getCache(encryption);
|
||||
Shared::TrustLevel level = convert(trustLevel);
|
||||
Keys data;
|
||||
bool had = false;
|
||||
LMDBAL::WriteTransaction txn = db.beginTransaction();
|
||||
try {
|
||||
data = cache->getRecord(keyOwnerJid);
|
||||
data = cache->getRecord(keyOwnerJid, txn);
|
||||
had = true;
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
for (const QByteArray& keyId : keyIds) {
|
||||
|
@ -342,10 +352,11 @@ QXmppTask<void> Core::TrustHandler::addKeys(
|
|||
}
|
||||
|
||||
if (had)
|
||||
cache->changeRecord(keyOwnerJid, data);
|
||||
cache->changeRecord(keyOwnerJid, data, txn);
|
||||
else
|
||||
cache->addRecord(keyOwnerJid, data);
|
||||
cache->addRecord(keyOwnerJid, data, txn);
|
||||
|
||||
txn.commit();
|
||||
emit trustLevelsChanged(keyOwnerJid, getSummary(keyOwnerJid));
|
||||
|
||||
return Core::makeReadyTask();
|
||||
|
@ -418,9 +429,9 @@ Shared::TrustSummary Core::TrustHandler::getSummary(const QString& jid) const {
|
|||
try {
|
||||
Keys keys = pair.second->getRecord(jid);
|
||||
Shared::EncryptionProtocol protocol = Shared::TrustSummary::protocolValues.at(pair.first);
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : keys) {
|
||||
for (const std::pair<const QByteArray, Shared::TrustLevel>& trust : keys)
|
||||
result.increment(protocol, trust.second);
|
||||
}
|
||||
|
||||
} catch (const LMDBAL::NotFound& e) {}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue