1
0
forked from blue/squawk

some refactoring, some improvements

This commit is contained in:
Blue 2023-11-10 19:26:16 -03:00
parent be466fbad1
commit e31ef78e71
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
13 changed files with 188 additions and 147 deletions

View File

@ -266,6 +266,7 @@ void Core::Account::onClientStateChange(QXmppClient::State st) {
#ifdef WITH_OMEMO
if (!oh->hasOwnDevice()) {
qDebug() << "setting up OMEMO data for account" << getName();
om->changeDeviceLabel(QGuiApplication::applicationDisplayName() + " - " + QSysInfo::productType());
QXmppTask<bool> future = om->setUp();
future.then(this, [this] (bool result) {
if (result)
@ -342,11 +343,10 @@ void Core::Account::setAvailability(Shared::Availability avail) {
QXmppPresence::AvailableStatusType pres = static_cast<QXmppPresence::AvailableStatusType>(avail);
presence.setAvailableStatusType(pres);
if (state != Shared::ConnectionState::disconnected) {
if (state != Shared::ConnectionState::disconnected)
client.setClientPresence(presence);
}
}
}
void Core::Account::runDiscoveryService() {
qDebug() << "running service discovery for account" << name;
@ -437,9 +437,9 @@ void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMess
void Core::Account::requestArchive(const QString& jid, int count, const QString& before) {
qDebug() << "An archive request for " << jid << ", before " << before;
RosterItem* contact = rh->getRosterItem(jid);
RosterItem* item = rh->getRosterItem(jid);
if (contact == nullptr) {
if (item == nullptr) {
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the contact with such id wasn't found, skipping";
emit responseArchive(jid, std::list<Shared::Message>(), true);
return;
@ -447,10 +447,18 @@ void Core::Account::requestArchive(const QString& jid, int count, const QString&
if (state != Shared::ConnectionState::connected) {
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the account is not online, skipping";
emit responseArchive(contact->jid, std::list<Shared::Message>(), false);
emit responseArchive(jid, std::list<Shared::Message>(), false);
return;
}
contact->requestHistory(count, before);
#ifdef WITH_OMEMO
if (!item->isMuc()) {
Contact* contact = static_cast<Contact*>(item);
if (contact->omemoBundles == Shared::Possible::unknown)
oh->requestBundles(jid);
}
#endif
item->requestHistory(count, before);
}
void Core::Account::onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at) {

View File

@ -15,9 +15,7 @@
* 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_ACCOUNT_H
#define CORE_ACCOUNT_H
#pragma once
#include <QObject>
#include <QCryptographicHash>
@ -248,6 +246,3 @@ private:
void runDiscoveryService();
};
}
#endif // CORE_ACCOUNT_H

View File

@ -24,6 +24,10 @@ Core::Contact::Contact(const QString& pJid, const QString& account, QObject* par
groups(),
subscriptionState(Shared::SubscriptionState::unknown),
pep(Shared::Support::unknown)
#ifdef WITH_OMEMO
,omemoBundles(Shared::Possible::unknown)
#endif
{}
Core::Contact::~Contact() {}

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CORE_CONTACT_H
#define CORE_CONTACT_H
#pragma once
#include <QObject>
#include <QSet>
@ -28,8 +27,7 @@
namespace Core {
class Contact : public RosterItem
{
class Contact : public RosterItem {
Q_OBJECT
public:
Contact(const QString& pJid, const QString& account, QObject* parent = 0);
@ -56,7 +54,10 @@ private:
QSet<QString> groups;
Shared::SubscriptionState subscriptionState;
Shared::Support pep;
#ifdef WITH_OMEMO
public:
Shared::Possible omemoBundles;
#endif
};
}
#endif // CORE_CONTACT_H

View File

@ -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_DELAYMANAGER_MANAGER_H
#define CORE_DELAYMANAGER_MANAGER_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 <list>
#include <set>
@ -38,8 +38,7 @@
namespace Core {
namespace DelayManager {
class Manager : public QObject
{
class Manager : public QObject {
Q_OBJECT
public:
Manager(const QString& ownJid, Job::Id maxParallelJobs = 5, QObject* parent = nullptr);
@ -146,5 +145,3 @@ public:
}
}
#endif // CORE_DELAYMANAGER_MANAGER_H

View File

@ -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);

View File

@ -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) {
try {
preKeyPairs->removeRecord(keyId);
} catch (const LMDBAL::NotFound& e) {
qDebug() << "Couldn't remove preKeyPair " << e.what();
}
return Core::makeReadyTask();
}
@ -135,16 +144,13 @@ 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) {
} 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;

View File

@ -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

View File

@ -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,21 +52,20 @@ 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) {
db.close();
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,
QXmppTask<bool> Core::TrustHandler::hasKey(
const QString& encryption,
const QString& keyOwnerJid,
QXmpp::TrustLevels trustLevels)
{
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) {}
}

2
external/qxmpp vendored

@ -1 +1 @@
Subproject commit 9e9c22b16a39c7370fed31c6deea56d8abf72440
Subproject commit 8dda3c9921c34b9e33883b0d140e8de12edc0736

View File

@ -136,6 +136,14 @@ enum class Support {
};
Q_ENUM_NS(Support)
enum class Possible {
unknown,
discovering,
present,
abscent
};
Q_ENUM_NS(Possible)
enum class TrustLevel {
/// The key's trust is not decided.
undecided,

View File

@ -268,7 +268,9 @@ QDataStream& operator<<(QDataStream& out, const Shared::Message& info) {
out << info.rTo;
out << info.id;
out << info.body;
out << info.time;
quint64 msecs = info.time.toMSecsSinceEpoch();
out << msecs;
out << info.thread;
out << (quint8)info.type;
out << info.outgoing;
@ -297,7 +299,11 @@ QDataStream & operator>>(QDataStream& in, Shared::Message& info) {
in >> info.rTo;
in >> info.id;
in >> info.body;
in >> info.time;
quint64 msecs;
in >> msecs;
info.time = QDateTime::fromMSecsSinceEpoch(msecs);
in >> info.thread;
quint8 t;
in >> t;

View File

@ -32,10 +32,7 @@ Chat::Chat(Models::Account* acc, Models::Contact* p_contact, QWidget* parent):
connect(contact, &Models::Contact::childChanged, this, &Chat::onContactChanged);
#ifdef WITH_OMEMO
if (p_contact->hasKeys(Shared::EncryptionProtocol::omemo2)) {
m_ui->encryptionButton->setVisible(true);
updateEncryptionState();
}
#endif
}
@ -59,9 +56,7 @@ void Chat::onContactChanged(Models::Item* item, int row, int col) {
setAvatar(contact->getAvatarPath());
break;
#ifdef WITH_OMEMO
case 8:
m_ui->encryptionButton->setVisible(contact->hasKeys(Shared::EncryptionProtocol::omemo2));
break;
case 8: //[fallthrough]
case 9:
updateEncryptionState();
break;
@ -77,11 +72,16 @@ void Chat::updateState() {
}
void Chat::updateEncryptionState() {
if (contact->hasKeys(Shared::EncryptionProtocol::omemo2)) {
m_ui->encryptionButton->setVisible(true);
m_ui->encryptionButton->setEnabled(true);
if (contact->getEncryption() == Shared::EncryptionProtocol::omemo2)
m_ui->encryptionButton->setIcon(Shared::icon("lock"));
else
m_ui->encryptionButton->setIcon(Shared::icon("unlock"));
} else {
m_ui->encryptionButton->setVisible(false);
}
}