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:
parent
db3bc358a7
commit
dfe72ca36c
@ -51,6 +51,7 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
||||
um(new QXmppUploadRequestManager()),
|
||||
dm(client.findExtension<QXmppDiscoveryManager>()),
|
||||
rcpm(new QXmppMessageReceiptManager()),
|
||||
psm(new QXmppPubSubManager()),
|
||||
reconnectScheduled(false),
|
||||
reconnectTimer(new QTimer),
|
||||
network(p_net),
|
||||
@ -58,7 +59,8 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
||||
lastError(Error::none),
|
||||
pepSupport(Shared::Support::unknown),
|
||||
active(p_active),
|
||||
notReadyPassword(false)
|
||||
notReadyPassword(false),
|
||||
loadingOmemo(false)
|
||||
{
|
||||
config.setUser(p_login);
|
||||
config.setDomain(p_server);
|
||||
@ -99,10 +101,31 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
||||
client.addExtension(rcpm);
|
||||
QObject::connect(rcpm, &QXmppMessageReceiptManager::messageDelivered, mh, &MessageHandler::onReceiptReceived);
|
||||
|
||||
client.addExtension(psm);
|
||||
|
||||
#ifdef WITH_OMEMO
|
||||
client.addExtension(tm);
|
||||
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
|
||||
|
||||
reconnectTimer->setSingleShot(true);
|
||||
@ -162,7 +185,12 @@ void Core::Account::connect()
|
||||
if (notReadyPassword) {
|
||||
emit needPassword();
|
||||
} else {
|
||||
client.connectToServer(config, presence);
|
||||
if (loadingOmemo) {
|
||||
state = Shared::ConnectionState::scheduled;
|
||||
emit connectionStateChanged(state);
|
||||
} else {
|
||||
client.connectToServer(config, presence);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -186,7 +214,12 @@ void Core::Account::disconnect()
|
||||
}
|
||||
if (state != Shared::ConnectionState::disconnected) {
|
||||
//rh->clearConferences();
|
||||
client.disconnectFromServer();
|
||||
if (state != Shared::ConnectionState::scheduled) {
|
||||
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;
|
||||
state = Shared::ConnectionState::connected;
|
||||
if (os == Shared::ConnectionState::connecting) {
|
||||
qDebug() << "running service discovery for account" << name;
|
||||
dm->requestItems(getServer());
|
||||
dm->requestInfo(getServer());
|
||||
#ifdef WITH_OMEMO
|
||||
if (!oh->hasOwnDevice()) {
|
||||
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;
|
||||
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)
|
||||
{
|
||||
QString id = p_presence.from();
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include <QXmppUploadRequestManager.h>
|
||||
#include <QXmppVCardManager.h>
|
||||
#include <QXmppMessageReceiptManager.h>
|
||||
#include <QXmppPubSubManager.h>
|
||||
|
||||
#include <shared/shared.h>
|
||||
#include <shared/identity.h>
|
||||
@ -195,6 +196,7 @@ private:
|
||||
QXmppUploadRequestManager* um;
|
||||
QXmppDiscoveryManager* dm;
|
||||
QXmppMessageReceiptManager* rcpm;
|
||||
QXmppPubSubManager* psm;
|
||||
bool reconnectScheduled;
|
||||
QTimer* reconnectTimer;
|
||||
|
||||
@ -204,6 +206,7 @@ private:
|
||||
Shared::Support pepSupport;
|
||||
bool active;
|
||||
bool notReadyPassword;
|
||||
bool loadingOmemo;
|
||||
|
||||
private slots:
|
||||
void onClientStateChange(QXmppClient::State state);
|
||||
@ -223,6 +226,7 @@ private:
|
||||
void handleDisconnection();
|
||||
void onReconnectTimer();
|
||||
void setPepSupport(Shared::Support support);
|
||||
void runDiscoveryService();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,8 @@
|
||||
|
||||
Core::DiscoveryHandler::DiscoveryHandler(Core::Account* account):
|
||||
QObject(),
|
||||
acc(account) {}
|
||||
acc(account),
|
||||
omemoToCarbonsConnected (false) {}
|
||||
|
||||
Core::DiscoveryHandler::~DiscoveryHandler() {}
|
||||
|
||||
@ -79,6 +80,19 @@ void Core::DiscoveryHandler::onInfoReceived(const QXmppDiscoveryIq& info)
|
||||
if (enableCC) {
|
||||
qDebug() << "Enabling carbon copies for account" << accName;
|
||||
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";
|
||||
|
@ -40,6 +40,7 @@ private slots:
|
||||
|
||||
private:
|
||||
Account* acc;
|
||||
bool omemoToCarbonsConnected;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ Core::OmemoHandler::OmemoHandler(Account* account) :
|
||||
db.open();
|
||||
try {
|
||||
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();
|
||||
} catch (const DataBase::NotFound& e) {
|
||||
qDebug() << "No device omemo data was found for account" << acc->getName();
|
||||
@ -42,6 +42,10 @@ Core::OmemoHandler::~OmemoHandler() {
|
||||
db.close();
|
||||
}
|
||||
|
||||
bool Core::OmemoHandler::hasOwnDevice() {
|
||||
return ownDevice.has_value();
|
||||
}
|
||||
|
||||
QFuture<void> Core::OmemoHandler::emptyVoidFuture() {
|
||||
QFutureInterface<QXmppOmemoStorage::OmemoData> result(QFutureInterfaceBase::Started);
|
||||
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) {
|
||||
signedPreKeyPairs->addRecord(keyId, keyPair);
|
||||
signedPreKeyPairs->forceRecord(keyId, keyPair);
|
||||
return emptyVoidFuture();
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
|
||||
QFuture<void> resetAll() override;
|
||||
|
||||
bool hasOwnDevice();
|
||||
|
||||
private:
|
||||
static QFuture<void> emptyVoidFuture();
|
||||
|
||||
|
@ -265,10 +265,13 @@ void Core::Squawk::disconnectAccount(const QString& account)
|
||||
void Core::Squawk::onAccountConnectionStateChanged(Shared::ConnectionState p_state)
|
||||
{
|
||||
Account* acc = static_cast<Account*>(sender());
|
||||
emit changeAccount(acc->getName(), {
|
||||
{"state", QVariant::fromValue(p_state)},
|
||||
{"error", ""}
|
||||
});
|
||||
QMap<QString, QVariant> changes = {
|
||||
{"state", QVariant::fromValue(p_state)}
|
||||
};
|
||||
if (acc->getLastError() == Account::Error::none) {
|
||||
changes.insert("error", "");
|
||||
}
|
||||
emit changeAccount(acc->getName(), changes);
|
||||
|
||||
#ifdef WITH_KWALLET
|
||||
if (p_state == Shared::ConnectionState::connected) {
|
||||
|
@ -187,15 +187,6 @@ private slots:
|
||||
|
||||
private:
|
||||
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;
|
||||
};
|
||||
|
@ -52,6 +52,9 @@ int main(int argc, char *argv[])
|
||||
qRegisterMetaType<Shared::Availability>("Shared::Availability");
|
||||
#ifdef WITH_OMEMO
|
||||
qRegisterMetaType<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
|
||||
qRegisterMetaTypeStreamOperators<QXmppOmemoStorage::OwnDevice>("QXmppOmemoStorage::OwnDevice");
|
||||
qRegisterMetaType<QXmppOmemoStorage::Device>("QXmppOmemoStorage::Device");
|
||||
qRegisterMetaType<QXmppOmemoStorage::SignedPreKeyPair>("QXmppOmemoStorage::SignedPreKeyPair");
|
||||
#endif
|
||||
|
||||
QApplication app(argc, argv);
|
||||
|
@ -29,12 +29,13 @@ Q_NAMESPACE
|
||||
|
||||
enum class ConnectionState {
|
||||
disconnected,
|
||||
scheduled,
|
||||
connecting,
|
||||
connected,
|
||||
error
|
||||
};
|
||||
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 ConnectionStateLowest = ConnectionState::disconnected;
|
||||
|
||||
|
@ -49,6 +49,7 @@ Shared::Global::Global():
|
||||
}),
|
||||
connectionState({
|
||||
tr("Disconnected", "ConnectionState"),
|
||||
tr("Scheduled", "ConnectionState"),
|
||||
tr("Connecting", "ConnectionState"),
|
||||
tr("Connected", "ConnectionState"),
|
||||
tr("Error", "ConnectionState")
|
||||
|
@ -48,6 +48,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsLightBig = {
|
||||
static const std::deque<QString> fallbackConnectionStateThemeIconsLightBig = {
|
||||
":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-ok.svg",
|
||||
":images/fallback/light/big/state-error.svg"
|
||||
};
|
||||
@ -73,6 +74,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsLightSmall =
|
||||
static const std::deque<QString> fallbackConnectionStateThemeIconsLightSmall = {
|
||||
":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-ok.svg",
|
||||
":images/fallback/light/small/state-error.svg"
|
||||
};
|
||||
@ -98,6 +100,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsDarkBig = {
|
||||
static const std::deque<QString> fallbackConnectionStateThemeIconsDarkBig = {
|
||||
":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-ok.svg",
|
||||
":images/fallback/dark/big/state-error.svg"
|
||||
};
|
||||
@ -123,6 +126,7 @@ static const std::deque<QString> fallbackSubscriptionStateThemeIconsDarkSmall =
|
||||
static const std::deque<QString> fallbackConnectionStateThemeIconsDarkSmall = {
|
||||
":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-ok.svg",
|
||||
":images/fallback/dark/small/state-error.svg"
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user