1
0
forked from blue/squawk

support of the new managers in account code, new states, new lambdas, even launches now, even receives some bundles

This commit is contained in:
Blue 2022-12-27 01:01:01 +03:00
parent db3bc358a7
commit dfe72ca36c
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
12 changed files with 113 additions and 25 deletions

View File

@ -51,6 +51,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
um(new QXmppUploadRequestManager()), um(new QXmppUploadRequestManager()),
dm(client.findExtension<QXmppDiscoveryManager>()), dm(client.findExtension<QXmppDiscoveryManager>()),
rcpm(new QXmppMessageReceiptManager()), rcpm(new QXmppMessageReceiptManager()),
psm(new QXmppPubSubManager()),
reconnectScheduled(false), reconnectScheduled(false),
reconnectTimer(new QTimer), reconnectTimer(new QTimer),
network(p_net), network(p_net),
@ -58,7 +59,8 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
lastError(Error::none), lastError(Error::none),
pepSupport(Shared::Support::unknown), pepSupport(Shared::Support::unknown),
active(p_active), active(p_active),
notReadyPassword(false) notReadyPassword(false),
loadingOmemo(false)
{ {
config.setUser(p_login); config.setUser(p_login);
config.setDomain(p_server); config.setDomain(p_server);
@ -99,10 +101,31 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
client.addExtension(rcpm); client.addExtension(rcpm);
QObject::connect(rcpm, &QXmppMessageReceiptManager::messageDelivered, mh, &MessageHandler::onReceiptReceived); QObject::connect(rcpm, &QXmppMessageReceiptManager::messageDelivered, mh, &MessageHandler::onReceiptReceived);
client.addExtension(psm);
#ifdef WITH_OMEMO #ifdef WITH_OMEMO
client.addExtension(tm); client.addExtension(tm);
client.addExtension(om); client.addExtension(om);
qDebug("Added OMEMO manager");
if (oh->hasOwnDevice()) {
QFuture<bool> future = om->load();
loadingOmemo = true;
QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>(this);
QObject::connect(watcher, &QFutureWatcherBase::finished, [watcher, this] () {
loadingOmemo = false;
if (state == Shared::ConnectionState::scheduled) {
client.connectToServer(config, presence);
}
if (watcher->result()) {
qDebug() << "successfully loaded OMEMO data for account" << getName();
} else {
qDebug() << "couldn't load OMEMO data for account" << getName();
}
watcher->deleteLater();
});
watcher->setFuture(future);
}
#endif #endif
reconnectTimer->setSingleShot(true); reconnectTimer->setSingleShot(true);
@ -161,9 +184,14 @@ void Core::Account::connect()
if (state == Shared::ConnectionState::disconnected) { if (state == Shared::ConnectionState::disconnected) {
if (notReadyPassword) { if (notReadyPassword) {
emit needPassword(); emit needPassword();
} else {
if (loadingOmemo) {
state = Shared::ConnectionState::scheduled;
emit connectionStateChanged(state);
} else { } else {
client.connectToServer(config, presence); client.connectToServer(config, presence);
} }
}
} else { } else {
qDebug("An attempt to connect an account which is already connected, skipping"); qDebug("An attempt to connect an account which is already connected, skipping");
@ -186,7 +214,12 @@ void Core::Account::disconnect()
} }
if (state != Shared::ConnectionState::disconnected) { if (state != Shared::ConnectionState::disconnected) {
//rh->clearConferences(); //rh->clearConferences();
if (state != Shared::ConnectionState::scheduled) {
client.disconnectFromServer(); client.disconnectFromServer();
} else {
state = Shared::ConnectionState::disconnected;
emit connectionStateChanged(state);
}
} }
} }
@ -199,9 +232,29 @@ void Core::Account::onClientStateChange(QXmppClient::State st)
Shared::ConnectionState os = state; Shared::ConnectionState os = state;
state = Shared::ConnectionState::connected; state = Shared::ConnectionState::connected;
if (os == Shared::ConnectionState::connecting) { if (os == Shared::ConnectionState::connecting) {
qDebug() << "running service discovery for account" << name; #ifdef WITH_OMEMO
dm->requestItems(getServer()); if (!oh->hasOwnDevice()) {
dm->requestInfo(getServer()); qDebug() << "setting up OMEMO data for account" << getName();
QFuture<bool> future = om->setUp();
QFutureWatcher<bool> *watcher = new QFutureWatcher<bool>(this);
QObject::connect(watcher, &QFutureWatcherBase::finished, [watcher, this] () {
if (watcher->result()) {
qDebug() << "successfully set up OMEMO data for account" << getName();
} else {
qDebug() << "couldn't set up OMEMO data for account" << getName();
}
watcher->deleteLater();
if (state == Shared::ConnectionState::connected) {
runDiscoveryService();
}
});
watcher->setFuture(future);
} else {
runDiscoveryService();
}
#else
runDiscoveryService();
#endif
} }
lastError = Error::none; lastError = Error::none;
emit connectionStateChanged(state); emit connectionStateChanged(state);
@ -270,6 +323,13 @@ void Core::Account::setAvailability(Shared::Availability avail)
} }
} }
void Core::Account::runDiscoveryService() {
qDebug() << "running service discovery for account" << name;
dm->requestItems(getServer());
dm->requestInfo(getServer());
}
void Core::Account::onPresenceReceived(const QXmppPresence& p_presence) void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
{ {
QString id = p_presence.from(); QString id = p_presence.from();

View File

@ -42,6 +42,7 @@
#include <QXmppUploadRequestManager.h> #include <QXmppUploadRequestManager.h>
#include <QXmppVCardManager.h> #include <QXmppVCardManager.h>
#include <QXmppMessageReceiptManager.h> #include <QXmppMessageReceiptManager.h>
#include <QXmppPubSubManager.h>
#include <shared/shared.h> #include <shared/shared.h>
#include <shared/identity.h> #include <shared/identity.h>
@ -195,6 +196,7 @@ private:
QXmppUploadRequestManager* um; QXmppUploadRequestManager* um;
QXmppDiscoveryManager* dm; QXmppDiscoveryManager* dm;
QXmppMessageReceiptManager* rcpm; QXmppMessageReceiptManager* rcpm;
QXmppPubSubManager* psm;
bool reconnectScheduled; bool reconnectScheduled;
QTimer* reconnectTimer; QTimer* reconnectTimer;
@ -204,6 +206,7 @@ private:
Shared::Support pepSupport; Shared::Support pepSupport;
bool active; bool active;
bool notReadyPassword; bool notReadyPassword;
bool loadingOmemo;
private slots: private slots:
void onClientStateChange(QXmppClient::State state); void onClientStateChange(QXmppClient::State state);
@ -223,6 +226,7 @@ private:
void handleDisconnection(); void handleDisconnection();
void onReconnectTimer(); void onReconnectTimer();
void setPepSupport(Shared::Support support); void setPepSupport(Shared::Support support);
void runDiscoveryService();
}; };
} }

View File

@ -21,7 +21,8 @@
Core::DiscoveryHandler::DiscoveryHandler(Core::Account* account): Core::DiscoveryHandler::DiscoveryHandler(Core::Account* account):
QObject(), QObject(),
acc(account) {} acc(account),
omemoToCarbonsConnected (false) {}
Core::DiscoveryHandler::~DiscoveryHandler() {} Core::DiscoveryHandler::~DiscoveryHandler() {}
@ -79,6 +80,19 @@ void Core::DiscoveryHandler::onInfoReceived(const QXmppDiscoveryIq& info)
if (enableCC) { if (enableCC) {
qDebug() << "Enabling carbon copies for account" << accName; qDebug() << "Enabling carbon copies for account" << accName;
acc->cm->setCarbonsEnabled(true); acc->cm->setCarbonsEnabled(true);
#ifdef WITH_OMEMO
if (!omemoToCarbonsConnected && acc->oh->hasOwnDevice()) {
// connect(this, &QXmppCarbonManager::messageSent, acc->om, &QXmppOmemoManager::handleMessage);
// connect(this, &QXmppCarbonManager::messageReceived, acc->om, &QXmppOmemoManager::handleMessage);
omemoToCarbonsConnected = true;
}
} else {
if (omemoToCarbonsConnected) {
// disconnect(this, &QXmppCarbonManager::messageSent, acc->om, &QXmppOmemoManager::handleMessage);
// disconnect(this, &QXmppCarbonManager::messageReceived, acc->om, &QXmppOmemoManager::handleMessage);
omemoToCarbonsConnected = false;
}
#endif
} }
qDebug() << "Requesting account" << accName << "capabilities"; qDebug() << "Requesting account" << accName << "capabilities";

View File

@ -40,6 +40,7 @@ private slots:
private: private:
Account* acc; Account* acc;
bool omemoToCarbonsConnected;
}; };
} }

View File

@ -31,7 +31,7 @@ Core::OmemoHandler::OmemoHandler(Account* account) :
db.open(); db.open();
try { try {
QVariant own = meta->getRecord("ownDevice"); QVariant own = meta->getRecord("ownDevice");
ownDevice.value() = own.value<OwnDevice>(); ownDevice = own.value<OwnDevice>();
qDebug() << "Successfully found own device omemo data for account" << acc->getName(); qDebug() << "Successfully found own device omemo data for account" << acc->getName();
} catch (const DataBase::NotFound& e) { } catch (const DataBase::NotFound& e) {
qDebug() << "No device omemo data was found for account" << acc->getName(); qDebug() << "No device omemo data was found for account" << acc->getName();
@ -42,6 +42,10 @@ Core::OmemoHandler::~OmemoHandler() {
db.close(); db.close();
} }
bool Core::OmemoHandler::hasOwnDevice() {
return ownDevice.has_value();
}
QFuture<void> Core::OmemoHandler::emptyVoidFuture() { QFuture<void> Core::OmemoHandler::emptyVoidFuture() {
QFutureInterface<QXmppOmemoStorage::OmemoData> result(QFutureInterfaceBase::Started); QFutureInterface<QXmppOmemoStorage::OmemoData> result(QFutureInterfaceBase::Started);
result.reportFinished(); result.reportFinished();
@ -101,7 +105,7 @@ QFuture<void> Core::OmemoHandler::addPreKeyPairs(const QHash<uint32_t, QByteArra
} }
QFuture<void> Core::OmemoHandler::addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair& keyPair) { QFuture<void> Core::OmemoHandler::addSignedPreKeyPair(uint32_t keyId, const QXmppOmemoStorage::SignedPreKeyPair& keyPair) {
signedPreKeyPairs->addRecord(keyId, keyPair); signedPreKeyPairs->forceRecord(keyId, keyPair);
return emptyVoidFuture(); return emptyVoidFuture();
} }

View File

@ -49,6 +49,8 @@ public:
QFuture<void> resetAll() override; QFuture<void> resetAll() override;
bool hasOwnDevice();
private: private:
static QFuture<void> emptyVoidFuture(); static QFuture<void> emptyVoidFuture();

View File

@ -265,10 +265,13 @@ void Core::Squawk::disconnectAccount(const QString& account)
void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_state) void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_state)
{ {
Account* acc = static_cast<Account*>(sender()); Account* acc = static_cast<Account*>(sender());
emit changeAccount(acc->getName(), { QMap<QString, QVariant> changes = {
{"state", QVariant::fromValue(p_state)}, {"state", QVariant::fromValue(p_state)}
{"error", ""} };
}); if (acc->getLastError() == Account::Error::none) {
changes.insert("error", "");
}
emit changeAccount(acc->getName(), changes);
#ifdef WITH_KWALLET #ifdef WITH_KWALLET
if (p_state == Shared::ConnectionState::connected) { if (p_state == Shared::ConnectionState::connected) {

View File

@ -187,15 +187,6 @@ private slots:
private: private:
void readSettings(); void readSettings();
void parseAccount(
const QString& login,
const QString& server,
const QString& password,
const QString& name,
const QString& resource,
bool active,
Shared::AccountPassword passwordType
);
static const quint64 passwordHash = 0x08d054225ac4871d; static const quint64 passwordHash = 0x08d054225ac4871d;
}; };

View File

@ -52,6 +52,9 @@ int main(int argc, char *argv[])
qRegisterMetaType<Shared::Availability>("Shared::Availability"); qRegisterMetaType<Shared::Availability>("Shared::Availability");
#ifdef WITH_OMEMO #ifdef WITH_OMEMO
qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice"); qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
qRegisterMetaTypeStreamOperators<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
qRegisterMetaType<QXmppOmemoStorage::Device>("QXmppOmemoStorage::Device");
qRegisterMetaType<QXmppOmemoStorage::SignedPreKeyPair>("QXmppOmemoStorage::SignedPreKeyPair");
#endif #endif
QApplication app(argc, argv); QApplication app(argc, argv);

View File

@ -29,12 +29,13 @@ Q_NAMESPACE
enum class ConnectionState { enum class ConnectionState {
disconnected, disconnected,
scheduled,
connecting, connecting,
connected, connected,
error error
}; };
Q_ENUM_NS(ConnectionState) Q_ENUM_NS(ConnectionState)
static const std::deque<QString> connectionStateThemeIcons = {"state-offline", "state-sync", "state-ok", "state-error"}; static const std::deque<QString> connectionStateThemeIcons = {"state-offline", "state-sync", "state-sync", "state-ok", "state-error"};
static const ConnectionState ConnectionStateHighest = ConnectionState::error; static const ConnectionState ConnectionStateHighest = ConnectionState::error;
static const ConnectionState ConnectionStateLowest = ConnectionState::disconnected; static const ConnectionState ConnectionStateLowest = ConnectionState::disconnected;

View File

@ -49,6 +49,7 @@ Shared::Global::Global():
}), }),
connectionState({ connectionState({
tr("Disconnected", "ConnectionState"), tr("Disconnected", "ConnectionState"),
tr("Scheduled", "ConnectionState"),
tr("Connecting", "ConnectionState"), tr("Connecting", "ConnectionState"),
tr("Connected", "ConnectionState"), tr("Connected", "ConnectionState"),
tr("Error", "ConnectionState") tr("Error", "ConnectionState")

View File

@ -48,6 +48,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsLightBig = {
static const std::deque<QString> fallbackConnectionStateThemeIconsLightBig = { static const std::deque<QString> fallbackConnectionStateThemeIconsLightBig = {
":images/fallback/light/big/state-offline.svg", ":images/fallback/light/big/state-offline.svg",
":images/fallback/light/big/state-sync.svg", ":images/fallback/light/big/state-sync.svg",
":images/fallback/light/big/state-sync.svg",
":images/fallback/light/big/state-ok.svg", ":images/fallback/light/big/state-ok.svg",
":images/fallback/light/big/state-error.svg" ":images/fallback/light/big/state-error.svg"
}; };
@ -73,6 +74,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsLightSmall =
static const std::deque<QString> fallbackConnectionStateThemeIconsLightSmall = { static const std::deque<QString> fallbackConnectionStateThemeIconsLightSmall = {
":images/fallback/light/small/state-offline.svg", ":images/fallback/light/small/state-offline.svg",
":images/fallback/light/small/state-sync.svg", ":images/fallback/light/small/state-sync.svg",
":images/fallback/light/small/state-sync.svg",
":images/fallback/light/small/state-ok.svg", ":images/fallback/light/small/state-ok.svg",
":images/fallback/light/small/state-error.svg" ":images/fallback/light/small/state-error.svg"
}; };
@ -98,6 +100,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsDarkBig = {
static const std::deque<QString> fallbackConnectionStateThemeIconsDarkBig = { static const std::deque<QString> fallbackConnectionStateThemeIconsDarkBig = {
":images/fallback/dark/big/state-offline.svg", ":images/fallback/dark/big/state-offline.svg",
":images/fallback/dark/big/state-sync.svg", ":images/fallback/dark/big/state-sync.svg",
":images/fallback/dark/big/state-sync.svg",
":images/fallback/dark/big/state-ok.svg", ":images/fallback/dark/big/state-ok.svg",
":images/fallback/dark/big/state-error.svg" ":images/fallback/dark/big/state-error.svg"
}; };
@ -123,6 +126,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsDarkSmall =
static const std::deque<QString> fallbackConnectionStateThemeIconsDarkSmall = { static const std::deque<QString> fallbackConnectionStateThemeIconsDarkSmall = {
":images/fallback/dark/small/state-offline.svg", ":images/fallback/dark/small/state-offline.svg",
":images/fallback/dark/small/state-sync.svg", ":images/fallback/dark/small/state-sync.svg",
":images/fallback/dark/small/state-sync.svg",
":images/fallback/dark/small/state-ok.svg", ":images/fallback/dark/small/state-ok.svg",
":images/fallback/dark/small/state-error.svg" ":images/fallback/dark/small/state-error.svg"
}; };