2019-08-14 14:54:46 +00:00
|
|
|
/*
|
|
|
|
* Squawk messenger.
|
2019-08-21 09:35:07 +00:00
|
|
|
* Copyright (C) 2019 Yury Gubich <blue@macaw.me>
|
2019-08-14 14:54:46 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-29 14:54:34 +00:00
|
|
|
#include "account.h"
|
2019-06-28 15:15:30 +00:00
|
|
|
#include <QXmppMessage.h>
|
2022-08-27 11:39:24 +00:00
|
|
|
|
2019-04-07 14:02:41 +00:00
|
|
|
#include <QDateTime>
|
2019-03-29 14:54:34 +00:00
|
|
|
|
2023-08-15 15:28:25 +00:00
|
|
|
#include "shared/defines.h"
|
|
|
|
|
2023-03-17 20:59:51 +00:00
|
|
|
Core::Account::Account(
|
|
|
|
const QString& p_login,
|
|
|
|
const QString& p_server,
|
|
|
|
const QString& p_password,
|
|
|
|
const QString& p_name,
|
|
|
|
bool p_active,
|
|
|
|
NetworkAccess* p_net,
|
|
|
|
QObject* parent
|
|
|
|
):
|
2019-03-29 14:54:34 +00:00
|
|
|
QObject(parent),
|
2019-03-30 20:13:13 +00:00
|
|
|
name(p_name),
|
2020-06-20 22:26:30 +00:00
|
|
|
archiveQueries(),
|
2019-03-31 21:05:09 +00:00
|
|
|
client(),
|
2019-04-07 20:14:15 +00:00
|
|
|
config(),
|
|
|
|
presence(),
|
2020-04-03 22:28:15 +00:00
|
|
|
state(Shared::ConnectionState::disconnected),
|
2022-12-19 15:43:24 +00:00
|
|
|
|
|
|
|
mh(new MessageHandler(this)),
|
|
|
|
rh(new RosterHandler(this)),
|
|
|
|
vh(new VCardHandler(this)),
|
|
|
|
dh(new DiscoveryHandler(this)),
|
2023-03-17 20:59:51 +00:00
|
|
|
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
2022-12-19 15:43:24 +00:00
|
|
|
th(new TrustHandler(this)),
|
2023-03-17 20:59:51 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_OMEMO
|
2022-12-19 15:43:24 +00:00
|
|
|
oh(new OmemoHandler(this)),
|
|
|
|
om(new QXmppOmemoManager(oh)),
|
|
|
|
#endif
|
2023-03-11 22:38:54 +00:00
|
|
|
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
2023-03-17 20:59:51 +00:00
|
|
|
tm(new QXmppTrustManager(th)),
|
2023-03-11 22:38:54 +00:00
|
|
|
cm(new QXmppCarbonManagerV2()),
|
2023-03-16 19:38:05 +00:00
|
|
|
psm(new QXmppPubSubManager()),
|
2023-03-11 22:38:54 +00:00
|
|
|
#else
|
2019-04-13 20:38:20 +00:00
|
|
|
cm(new QXmppCarbonManager()),
|
2023-03-11 22:38:54 +00:00
|
|
|
#endif
|
2019-04-17 20:08:56 +00:00
|
|
|
am(new QXmppMamManager()),
|
2019-07-11 08:51:52 +00:00
|
|
|
mm(new QXmppMucManager()),
|
|
|
|
bm(new QXmppBookmarkManager()),
|
2019-11-02 20:50:25 +00:00
|
|
|
rm(client.findExtension<QXmppRosterManager>()),
|
|
|
|
vm(client.findExtension<QXmppVCardManager>()),
|
2019-11-09 14:04:27 +00:00
|
|
|
um(new QXmppUploadRequestManager()),
|
2019-11-12 13:38:01 +00:00
|
|
|
dm(client.findExtension<QXmppDiscoveryManager>()),
|
2020-03-27 20:59:30 +00:00
|
|
|
rcpm(new QXmppMessageReceiptManager()),
|
2020-05-21 15:42:40 +00:00
|
|
|
reconnectScheduled(false),
|
|
|
|
reconnectTimer(new QTimer),
|
2020-03-25 15:28:36 +00:00
|
|
|
network(p_net),
|
2023-03-10 18:43:31 +00:00
|
|
|
delay(nullptr),
|
2020-04-28 20:35:52 +00:00
|
|
|
passwordType(Shared::AccountPassword::plain),
|
2022-04-14 08:13:27 +00:00
|
|
|
lastError(Error::none),
|
2022-08-27 11:39:24 +00:00
|
|
|
pepSupport(Shared::Support::unknown),
|
2022-04-12 20:33:10 +00:00
|
|
|
active(p_active),
|
2022-12-26 22:01:01 +00:00
|
|
|
notReadyPassword(false),
|
|
|
|
loadingOmemo(false)
|
2019-03-29 14:54:34 +00:00
|
|
|
{
|
2019-04-07 20:14:15 +00:00
|
|
|
config.setUser(p_login);
|
|
|
|
config.setDomain(p_server);
|
|
|
|
config.setPassword(p_password);
|
2019-06-12 17:18:18 +00:00
|
|
|
config.setAutoAcceptSubscriptions(true);
|
2020-04-28 20:35:52 +00:00
|
|
|
//config.setAutoReconnectionEnabled(false);
|
2023-03-10 18:43:31 +00:00
|
|
|
delay = new DelayManager::Manager(getBareJid());
|
|
|
|
QObject::connect(delay, &DelayManager::Manager::gotInfo, this, &Account::infoReady);
|
|
|
|
QObject::connect(delay, &DelayManager::Manager::gotOwnInfo, this, &Account::infoReady);
|
|
|
|
|
|
|
|
QObject::connect(delay, &DelayManager::Manager::requestOwnVCard, vm, &QXmppVCardManager::requestClientVCard);
|
|
|
|
QObject::connect(delay, &DelayManager::Manager::requestVCard, vm, &QXmppVCardManager::requestVCard);
|
2022-12-19 15:43:24 +00:00
|
|
|
|
|
|
|
rh->initialize();
|
|
|
|
vh->initialize();
|
|
|
|
dh->initialize();
|
2019-04-07 20:14:15 +00:00
|
|
|
|
2020-05-21 15:42:40 +00:00
|
|
|
QObject::connect(&client, &QXmppClient::stateChanged, this, &Account::onClientStateChange);
|
2019-10-15 19:25:40 +00:00
|
|
|
QObject::connect(&client, &QXmppClient::presenceReceived, this, &Account::onPresenceReceived);
|
2020-04-28 20:35:52 +00:00
|
|
|
QObject::connect(&client, &QXmppClient::messageReceived, mh, &MessageHandler::onMessageReceived);
|
2019-10-15 19:25:40 +00:00
|
|
|
QObject::connect(&client, &QXmppClient::error, this, &Account::onClientError);
|
2019-04-03 21:23:51 +00:00
|
|
|
|
2019-04-12 15:22:10 +00:00
|
|
|
client.addExtension(cm);
|
|
|
|
|
2023-03-11 22:38:54 +00:00
|
|
|
#if (QXMPP_VERSION) < QT_VERSION_CHECK(1, 5, 0)
|
2020-04-28 20:35:52 +00:00
|
|
|
QObject::connect(cm, &QXmppCarbonManager::messageReceived, mh, &MessageHandler::onCarbonMessageReceived);
|
|
|
|
QObject::connect(cm, &QXmppCarbonManager::messageSent, mh, &MessageHandler::onCarbonMessageSent);
|
2023-03-11 22:38:54 +00:00
|
|
|
#endif
|
2019-04-13 20:38:20 +00:00
|
|
|
|
|
|
|
client.addExtension(am);
|
|
|
|
|
2019-10-15 19:25:40 +00:00
|
|
|
QObject::connect(am, &QXmppMamManager::logMessage, this, &Account::onMamLog);
|
|
|
|
QObject::connect(am, &QXmppMamManager::archivedMessageReceived, this, &Account::onMamMessageReceived);
|
|
|
|
QObject::connect(am, &QXmppMamManager::resultsRecieved, this, &Account::onMamResultsReceived);
|
2019-07-11 08:51:52 +00:00
|
|
|
|
|
|
|
client.addExtension(mm);
|
|
|
|
client.addExtension(bm);
|
2019-11-09 14:04:27 +00:00
|
|
|
client.addExtension(um);
|
2020-04-28 20:35:52 +00:00
|
|
|
QObject::connect(um, &QXmppUploadRequestManager::slotReceived, mh, &MessageHandler::onUploadSlotReceived);
|
|
|
|
QObject::connect(um, &QXmppUploadRequestManager::requestFailed, mh, &MessageHandler::onUploadSlotRequestFailed);
|
2019-11-09 14:04:27 +00:00
|
|
|
|
2021-04-18 12:49:20 +00:00
|
|
|
QObject::connect(network, &NetworkAccess::uploadFileComplete, mh, &MessageHandler::onUploadFileComplete);
|
|
|
|
QObject::connect(network, &NetworkAccess::downloadFileComplete, mh, &MessageHandler::onDownloadFileComplete);
|
|
|
|
QObject::connect(network, &NetworkAccess::loadFileError, mh, &MessageHandler::onLoadFileError);
|
2019-11-11 15:19:54 +00:00
|
|
|
|
2020-03-27 20:59:30 +00:00
|
|
|
client.addExtension(rcpm);
|
2020-04-28 20:35:52 +00:00
|
|
|
QObject::connect(rcpm, &QXmppMessageReceiptManager::messageDelivered, mh, &MessageHandler::onReceiptReceived);
|
2022-08-29 18:34:25 +00:00
|
|
|
|
2022-12-26 22:01:01 +00:00
|
|
|
client.addExtension(psm);
|
|
|
|
|
2022-08-29 18:34:25 +00:00
|
|
|
#ifdef WITH_OMEMO
|
2023-03-10 18:43:31 +00:00
|
|
|
QObject::connect(delay, &DelayManager::Manager::requestBundles, oh, &OmemoHandler::requestBundles);
|
|
|
|
QObject::connect(delay, &DelayManager::Manager::requestOwnBundles, oh, &OmemoHandler::requestOwnBundles);
|
|
|
|
|
2023-03-15 18:17:44 +00:00
|
|
|
QObject::connect(om, &QXmppOmemoManager::deviceAdded, oh, &OmemoHandler::onOmemoDeviceAdded);
|
|
|
|
|
2022-12-19 15:43:24 +00:00
|
|
|
client.addExtension(tm);
|
2022-08-29 18:34:25 +00:00
|
|
|
client.addExtension(om);
|
2023-03-02 18:17:06 +00:00
|
|
|
om->setSecurityPolicy(QXmpp::Toakafa);
|
2022-12-26 22:01:01 +00:00
|
|
|
|
|
|
|
if (oh->hasOwnDevice()) {
|
2023-01-29 17:26:54 +00:00
|
|
|
QXmppTask<bool> future = om->load();
|
2022-12-26 22:01:01 +00:00
|
|
|
loadingOmemo = true;
|
2023-01-29 17:26:54 +00:00
|
|
|
future.then(this, [this] (bool result) {
|
2022-12-26 22:01:01 +00:00
|
|
|
loadingOmemo = false;
|
2023-11-09 22:36:30 +00:00
|
|
|
if (state == Shared::ConnectionState::scheduled)
|
2022-12-26 22:01:01 +00:00
|
|
|
client.connectToServer(config, presence);
|
2023-11-09 22:36:30 +00:00
|
|
|
|
|
|
|
if (result)
|
2022-12-26 22:01:01 +00:00
|
|
|
qDebug() << "successfully loaded OMEMO data for account" << getName();
|
2023-11-09 22:36:30 +00:00
|
|
|
else
|
2022-12-26 22:01:01 +00:00
|
|
|
qDebug() << "couldn't load OMEMO data for account" << getName();
|
|
|
|
});
|
|
|
|
}
|
2022-08-29 18:34:25 +00:00
|
|
|
#endif
|
2020-03-27 20:59:30 +00:00
|
|
|
|
2020-05-21 15:42:40 +00:00
|
|
|
reconnectTimer->setSingleShot(true);
|
2020-06-20 22:26:30 +00:00
|
|
|
QObject::connect(reconnectTimer, &QTimer::timeout, this, &Account::onReconnectTimer);
|
2020-05-21 15:42:40 +00:00
|
|
|
|
2022-04-12 20:33:10 +00:00
|
|
|
if (name == "Test") {
|
|
|
|
QXmppLogger* logger = new QXmppLogger(this);
|
|
|
|
logger->setLoggingType(QXmppLogger::SignalLogging);
|
|
|
|
client.setLogger(logger);
|
|
|
|
|
2023-08-15 15:28:25 +00:00
|
|
|
QObject::connect(logger, &QXmppLogger::message, this, [](QXmppLogger::MessageType type, const QString& text) {
|
|
|
|
SHARED_UNUSED(type);
|
2022-04-12 20:33:10 +00:00
|
|
|
qDebug() << text;
|
|
|
|
});
|
|
|
|
}
|
2019-03-29 14:54:34 +00:00
|
|
|
}
|
|
|
|
|
2023-03-17 20:59:51 +00:00
|
|
|
Core::Account::~Account() {
|
2020-05-21 15:42:40 +00:00
|
|
|
if (reconnectScheduled) {
|
|
|
|
reconnectScheduled = false;
|
|
|
|
reconnectTimer->stop();
|
|
|
|
}
|
|
|
|
|
2021-04-18 12:49:20 +00:00
|
|
|
QObject::disconnect(network, &NetworkAccess::uploadFileComplete, mh, &MessageHandler::onUploadFileComplete);
|
|
|
|
QObject::disconnect(network, &NetworkAccess::downloadFileComplete, mh, &MessageHandler::onDownloadFileComplete);
|
|
|
|
QObject::disconnect(network, &NetworkAccess::loadFileError, mh, &MessageHandler::onLoadFileError);
|
2019-11-11 15:19:54 +00:00
|
|
|
|
2023-03-16 19:38:05 +00:00
|
|
|
rh->clear(); //conferenses inside of roster handler hold QXmppMuc objects.
|
|
|
|
//If we destroy QXmppMucManager, then when we will be destroying RosterHandler
|
|
|
|
//it will try to destory Core::Conference objects
|
|
|
|
//and inside of those QXmppMuc objects will already be destroyed.
|
|
|
|
//So, clear will start the destruction from Core::Conference and this way it's not gonna crash
|
|
|
|
|
|
|
|
delete delay;
|
2020-05-21 15:42:40 +00:00
|
|
|
delete reconnectTimer;
|
2020-03-27 20:59:30 +00:00
|
|
|
delete rcpm;
|
2019-11-09 14:04:27 +00:00
|
|
|
delete um;
|
2019-07-11 08:51:52 +00:00
|
|
|
delete bm;
|
|
|
|
delete mm;
|
|
|
|
delete am;
|
|
|
|
delete cm;
|
2023-03-16 19:38:05 +00:00
|
|
|
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 5, 0)
|
|
|
|
delete psm;
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_OMEMO
|
|
|
|
delete om;
|
|
|
|
delete tm;
|
|
|
|
delete oh;
|
|
|
|
delete th;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
delete dh;
|
|
|
|
delete vh;
|
|
|
|
delete rh;
|
|
|
|
delete mh;
|
2019-03-31 21:05:09 +00:00
|
|
|
}
|
2019-03-29 14:54:34 +00:00
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
Shared::ConnectionState Core::Account::getState() const {
|
|
|
|
return state;}
|
2019-03-31 21:05:09 +00:00
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::connect() {
|
2020-06-20 22:26:30 +00:00
|
|
|
if (reconnectScheduled) {
|
|
|
|
reconnectScheduled = false;
|
|
|
|
reconnectTimer->stop();
|
|
|
|
}
|
2020-04-03 22:28:15 +00:00
|
|
|
if (state == Shared::ConnectionState::disconnected) {
|
2022-04-12 20:33:10 +00:00
|
|
|
if (notReadyPassword) {
|
|
|
|
emit needPassword();
|
|
|
|
} else {
|
2022-12-26 22:01:01 +00:00
|
|
|
if (loadingOmemo) {
|
|
|
|
state = Shared::ConnectionState::scheduled;
|
|
|
|
emit connectionStateChanged(state);
|
|
|
|
} else {
|
|
|
|
client.connectToServer(config, presence);
|
|
|
|
}
|
2022-04-12 20:33:10 +00:00
|
|
|
}
|
|
|
|
|
2019-03-31 21:05:09 +00:00
|
|
|
} else {
|
|
|
|
qDebug("An attempt to connect an account which is already connected, skipping");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onReconnectTimer() {
|
2020-06-20 22:26:30 +00:00
|
|
|
if (reconnectScheduled) {
|
|
|
|
reconnectScheduled = false;
|
|
|
|
connect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::disconnect() {
|
2020-05-21 15:42:40 +00:00
|
|
|
if (reconnectScheduled) {
|
|
|
|
reconnectScheduled = false;
|
|
|
|
reconnectTimer->stop();
|
|
|
|
}
|
2020-04-03 22:28:15 +00:00
|
|
|
if (state != Shared::ConnectionState::disconnected) {
|
2020-06-20 22:26:30 +00:00
|
|
|
//rh->clearConferences();
|
2022-12-26 22:01:01 +00:00
|
|
|
if (state != Shared::ConnectionState::scheduled) {
|
|
|
|
client.disconnectFromServer();
|
|
|
|
} else {
|
|
|
|
state = Shared::ConnectionState::disconnected;
|
|
|
|
emit connectionStateChanged(state);
|
|
|
|
}
|
2019-03-31 21:05:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onClientStateChange(QXmppClient::State st) {
|
2020-05-21 15:42:40 +00:00
|
|
|
switch (st) {
|
|
|
|
case QXmppClient::ConnectedState: {
|
|
|
|
if (state != Shared::ConnectionState::connected) {
|
|
|
|
if (client.isActive()) {
|
|
|
|
Shared::ConnectionState os = state;
|
|
|
|
state = Shared::ConnectionState::connected;
|
|
|
|
if (os == Shared::ConnectionState::connecting) {
|
2022-12-26 22:01:01 +00:00
|
|
|
#ifdef WITH_OMEMO
|
|
|
|
if (!oh->hasOwnDevice()) {
|
|
|
|
qDebug() << "setting up OMEMO data for account" << getName();
|
2023-11-10 22:26:16 +00:00
|
|
|
om->changeDeviceLabel(QGuiApplication::applicationDisplayName() + " - " + QSysInfo::productType());
|
2023-01-29 17:26:54 +00:00
|
|
|
QXmppTask<bool> future = om->setUp();
|
|
|
|
future.then(this, [this] (bool result) {
|
|
|
|
if (result)
|
2022-12-26 22:01:01 +00:00
|
|
|
qDebug() << "successfully set up OMEMO data for account" << getName();
|
2023-01-29 17:26:54 +00:00
|
|
|
else
|
2022-12-26 22:01:01 +00:00
|
|
|
qDebug() << "couldn't set up OMEMO data for account" << getName();
|
2023-01-29 17:26:54 +00:00
|
|
|
|
|
|
|
if (state == Shared::ConnectionState::connected)
|
2022-12-26 22:01:01 +00:00
|
|
|
runDiscoveryService();
|
2023-01-29 17:26:54 +00:00
|
|
|
|
2022-12-26 22:01:01 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
runDiscoveryService();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
runDiscoveryService();
|
|
|
|
#endif
|
2020-05-21 15:42:40 +00:00
|
|
|
}
|
2022-04-14 08:13:27 +00:00
|
|
|
lastError = Error::none;
|
2020-05-21 15:42:40 +00:00
|
|
|
emit connectionStateChanged(state);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qDebug() << "Something weird happened - xmpp client of account" << name
|
|
|
|
<< "reported about successful connection but account was in" << state << "state";
|
|
|
|
}
|
2019-05-24 14:46:34 +00:00
|
|
|
}
|
2020-05-21 15:42:40 +00:00
|
|
|
break;
|
|
|
|
case QXmppClient::ConnectingState: {
|
|
|
|
if (state != Shared::ConnectionState::connecting) {
|
|
|
|
state = Shared::ConnectionState::connecting;
|
|
|
|
emit connectionStateChanged(state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QXmppClient::DisconnectedState: {
|
|
|
|
if (state != Shared::ConnectionState::disconnected) {
|
2020-08-07 23:33:03 +00:00
|
|
|
handleDisconnection();
|
2020-05-21 15:42:40 +00:00
|
|
|
state = Shared::ConnectionState::disconnected;
|
|
|
|
emit connectionStateChanged(state);
|
|
|
|
} else {
|
|
|
|
qDebug() << "Something weird happened - xmpp client of account" << name
|
|
|
|
<< "reported about disconnection but account was in" << state << "state";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2019-03-31 21:05:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::reconnect() {
|
2022-04-12 20:33:10 +00:00
|
|
|
if (!reconnectScheduled) { //TODO define behavior if It was connection or disconnecting
|
|
|
|
if (state == Shared::ConnectionState::connected) {
|
|
|
|
reconnectScheduled = true;
|
|
|
|
reconnectTimer->start(500);
|
|
|
|
client.disconnectFromServer();
|
|
|
|
} else {
|
|
|
|
qDebug() << "An attempt to reconnect account" << getName() << "which was not connected";
|
|
|
|
}
|
2019-05-24 14:46:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
Shared::Availability Core::Account::getAvailability() const {
|
2020-06-14 21:23:43 +00:00
|
|
|
if (state == Shared::ConnectionState::connected) {
|
|
|
|
QXmppPresence::AvailableStatusType pres = presence.availableStatusType();
|
|
|
|
return static_cast<Shared::Availability>(pres); //they are compatible;
|
|
|
|
} else {
|
|
|
|
return Shared::Availability::offline;
|
2019-04-06 10:14:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::setAvailability(Shared::Availability avail) {
|
2020-06-14 21:23:43 +00:00
|
|
|
if (avail == Shared::Availability::offline) {
|
|
|
|
disconnect(); //TODO not sure how to do here - changing state may cause connection or disconnection
|
2019-04-19 09:12:12 +00:00
|
|
|
} else {
|
2020-06-14 21:23:43 +00:00
|
|
|
QXmppPresence::AvailableStatusType pres = static_cast<QXmppPresence::AvailableStatusType>(avail);
|
2019-04-19 09:12:12 +00:00
|
|
|
|
2020-06-14 21:23:43 +00:00
|
|
|
presence.setAvailableStatusType(pres);
|
2023-11-10 22:26:16 +00:00
|
|
|
if (state != Shared::ConnectionState::disconnected)
|
2020-06-14 21:23:43 +00:00
|
|
|
client.setClientPresence(presence);
|
2019-04-03 21:23:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-26 22:01:01 +00:00
|
|
|
void Core::Account::runDiscoveryService() {
|
|
|
|
qDebug() << "running service discovery for account" << name;
|
|
|
|
dm->requestItems(getServer());
|
|
|
|
dm->requestInfo(getServer());
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onPresenceReceived(const QXmppPresence& p_presence) {
|
2019-10-16 19:38:35 +00:00
|
|
|
QString id = p_presence.from();
|
2019-04-07 14:02:41 +00:00
|
|
|
QStringList comps = id.split("/");
|
2020-07-26 19:41:30 +00:00
|
|
|
QString jid = comps.front().toLower();
|
2019-04-07 14:02:41 +00:00
|
|
|
QString resource = comps.back();
|
|
|
|
|
2022-04-08 16:18:15 +00:00
|
|
|
if (jid == getBareJid()) {
|
2023-02-20 18:12:32 +00:00
|
|
|
if (resource == getResource())
|
2020-04-03 22:28:15 +00:00
|
|
|
emit availabilityChanged(static_cast<Shared::Availability>(p_presence.availableStatusType()));
|
2023-02-20 18:12:32 +00:00
|
|
|
|
2022-08-27 11:39:24 +00:00
|
|
|
vh->handlePresenceOfMyAccountChange(p_presence);
|
2019-10-15 19:25:40 +00:00
|
|
|
} else {
|
2020-06-14 21:23:43 +00:00
|
|
|
RosterItem* item = rh->getRosterItem(jid);
|
2024-01-31 23:22:49 +00:00
|
|
|
if (item != nullptr) {
|
|
|
|
if (item->isMuc()) //MUC presence is handled by inner muc events
|
|
|
|
return;
|
|
|
|
else
|
|
|
|
item->handlePresence(p_presence);
|
|
|
|
}
|
2019-04-07 20:14:15 +00:00
|
|
|
}
|
|
|
|
|
2019-10-16 19:38:35 +00:00
|
|
|
switch (p_presence.type()) {
|
2019-04-07 14:02:41 +00:00
|
|
|
case QXmppPresence::Error:
|
2019-10-16 19:38:35 +00:00
|
|
|
qDebug() << "An error reported by presence from" << id << p_presence.error().text();
|
2019-04-07 14:02:41 +00:00
|
|
|
break;
|
2024-01-31 23:22:49 +00:00
|
|
|
case QXmppPresence::Available: {
|
2019-10-16 19:38:35 +00:00
|
|
|
QDateTime lastInteraction = p_presence.lastUserInteraction();
|
2024-01-31 23:22:49 +00:00
|
|
|
if (!lastInteraction.isValid())
|
2020-03-30 21:17:10 +00:00
|
|
|
lastInteraction = QDateTime::currentDateTimeUtc();
|
2024-01-31 23:22:49 +00:00
|
|
|
|
2019-04-07 14:02:41 +00:00
|
|
|
emit addPresence(jid, resource, {
|
|
|
|
{"lastActivity", lastInteraction},
|
2019-10-16 19:38:35 +00:00
|
|
|
{"availability", p_presence.availableStatusType()}, //TODO check and handle invisible
|
2022-08-22 20:29:43 +00:00
|
|
|
{"status", p_presence.statusText()},
|
2023-03-14 19:49:58 +00:00
|
|
|
{"client", QVariant::fromValue(
|
|
|
|
Shared::ClientId(
|
|
|
|
p_presence.capabilityNode(),
|
|
|
|
p_presence.capabilityVer().toBase64(),
|
|
|
|
p_presence.capabilityHash())
|
|
|
|
)
|
|
|
|
}
|
2019-04-07 14:02:41 +00:00
|
|
|
});
|
2024-01-31 23:22:49 +00:00
|
|
|
} break;
|
2019-04-07 14:02:41 +00:00
|
|
|
case QXmppPresence::Unavailable:
|
|
|
|
emit removePresence(jid, resource);
|
|
|
|
break;
|
|
|
|
case QXmppPresence::Subscribe:
|
|
|
|
qDebug("xmpp presence \"subscribe\" received, do not yet know what to do, skipping");
|
2022-09-03 11:39:42 +00:00
|
|
|
break;
|
2019-04-07 14:02:41 +00:00
|
|
|
case QXmppPresence::Subscribed:
|
|
|
|
qDebug("xmpp presence \"subscribed\" received, do not yet know what to do, skipping");
|
2022-09-03 11:39:42 +00:00
|
|
|
break;
|
2019-04-07 14:02:41 +00:00
|
|
|
case QXmppPresence::Unsubscribe:
|
|
|
|
qDebug("xmpp presence \"unsubscribe\" received, do not yet know what to do, skipping");
|
2022-09-03 11:39:42 +00:00
|
|
|
break;
|
2019-04-07 14:02:41 +00:00
|
|
|
case QXmppPresence::Unsubscribed:
|
|
|
|
qDebug("xmpp presence \"unsubscribed\" received, do not yet know what to do, skipping");
|
2022-09-03 11:39:42 +00:00
|
|
|
break;
|
2019-04-07 14:02:41 +00:00
|
|
|
case QXmppPresence::Probe:
|
|
|
|
qDebug("xmpp presence \"probe\" received, do not yet know what to do, skipping");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onMamMessageReceived(const QString& queryId, const QXmppMessage& msg) {
|
2019-09-10 14:33:39 +00:00
|
|
|
if (msg.id().size() > 0 && (msg.body().size() > 0 || msg.outOfBandUrl().size() > 0)) {
|
2020-06-20 22:26:30 +00:00
|
|
|
std::map<QString, QString>::const_iterator itr = archiveQueries.find(queryId);
|
|
|
|
if (itr != archiveQueries.end()) {
|
2020-04-19 13:13:15 +00:00
|
|
|
QString jid = itr->second;
|
2020-06-14 21:23:43 +00:00
|
|
|
RosterItem* item = rh->getRosterItem(jid);
|
2020-04-19 13:13:15 +00:00
|
|
|
|
|
|
|
Shared::Message sMsg(static_cast<Shared::Message::Type>(msg.type()));
|
2020-04-28 20:35:52 +00:00
|
|
|
mh->initializeMessage(sMsg, msg, false, true, true);
|
2020-04-19 13:13:15 +00:00
|
|
|
sMsg.setState(Shared::Message::State::sent);
|
|
|
|
|
|
|
|
QString oId = msg.replaceId();
|
2023-02-20 18:12:32 +00:00
|
|
|
if (oId.size() > 0)
|
2020-04-19 13:13:15 +00:00
|
|
|
item->correctMessageInArchive(oId, sMsg);
|
2023-02-20 18:12:32 +00:00
|
|
|
else
|
2020-04-19 13:13:15 +00:00
|
|
|
item->addMessageToArchive(sMsg);
|
2020-03-28 14:05:49 +00:00
|
|
|
}
|
2019-08-21 09:35:07 +00:00
|
|
|
}
|
2020-03-26 15:08:44 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::requestArchive(const QString& jid, int count, const QString& before) {
|
2020-03-26 15:08:44 +00:00
|
|
|
qDebug() << "An archive request for " << jid << ", before " << before;
|
2023-11-10 22:26:16 +00:00
|
|
|
RosterItem* item = rh->getRosterItem(jid);
|
2020-03-26 15:08:44 +00:00
|
|
|
|
2023-11-10 22:26:16 +00:00
|
|
|
if (item == nullptr) {
|
2019-04-21 19:17:04 +00:00
|
|
|
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the contact with such id wasn't found, skipping";
|
2020-08-21 20:57:48 +00:00
|
|
|
emit responseArchive(jid, std::list<Shared::Message>(), true);
|
2019-04-21 19:17:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-19 13:13:15 +00:00
|
|
|
if (state != Shared::ConnectionState::connected) {
|
|
|
|
qDebug() << "An attempt to request archive for" << jid << "in account" << name << ", but the account is not online, skipping";
|
2023-11-10 22:26:16 +00:00
|
|
|
emit responseArchive(jid, std::list<Shared::Message>(), false);
|
|
|
|
return;
|
2020-04-19 13:13:15 +00:00
|
|
|
}
|
|
|
|
|
2023-11-10 22:26:16 +00:00
|
|
|
#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);
|
2019-05-15 17:36:37 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onContactNeedHistory(const QString& before, const QString& after, const QDateTime& at) {
|
2019-08-14 14:54:46 +00:00
|
|
|
RosterItem* contact = static_cast<RosterItem*>(sender());
|
2020-05-21 15:42:40 +00:00
|
|
|
|
2020-05-22 16:28:26 +00:00
|
|
|
QString to;
|
|
|
|
QString with;
|
2019-04-13 20:38:20 +00:00
|
|
|
QXmppResultSetQuery query;
|
2020-05-21 15:42:40 +00:00
|
|
|
QDateTime start;
|
2019-04-13 20:38:20 +00:00
|
|
|
query.setMax(100);
|
2020-05-21 15:42:40 +00:00
|
|
|
|
|
|
|
if (contact->getArchiveState() == RosterItem::empty) {
|
2019-05-15 17:36:37 +00:00
|
|
|
query.setBefore(before);
|
2020-05-21 15:42:40 +00:00
|
|
|
qDebug() << "Requesting remote history from empty for" << contact->jid;
|
|
|
|
} else {
|
|
|
|
if (before.size() > 0) {
|
|
|
|
query.setBefore(before);
|
|
|
|
}
|
|
|
|
if (after.size() > 0) { //there is some strange behavior of ejabberd server returning empty result set
|
|
|
|
if (at.isValid()) { //there can be some useful information about it here https://github.com/processone/ejabberd/issues/2924
|
|
|
|
start = at;
|
|
|
|
} else {
|
|
|
|
query.setAfter(after);
|
|
|
|
}
|
2019-07-01 06:31:38 +00:00
|
|
|
}
|
2021-10-06 15:01:11 +00:00
|
|
|
if (before.size() == 0 && after.size() == 0) {
|
|
|
|
// https://xmpp.org/extensions/xep-0313.html#sect-idm46556759682304
|
|
|
|
// To request the page at the end of the archive
|
|
|
|
// (i.e. the most recent messages), include just an
|
|
|
|
// empty <before/> element in the RSM part of the query.
|
|
|
|
// As defined by RSM, this will return the last page of the archive.
|
|
|
|
query.setBefore("");
|
|
|
|
}
|
2020-05-21 15:42:40 +00:00
|
|
|
qDebug() << "Remote query for" << contact->jid << "from" << after << ", to" << before;
|
2019-05-15 17:36:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 16:28:26 +00:00
|
|
|
if (contact->isMuc()) {
|
|
|
|
to = contact->jid;
|
|
|
|
} else {
|
|
|
|
with = contact->jid;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString q = am->retrieveArchivedMessages(to, "", with, start, QDateTime(), query);
|
2020-06-20 22:26:30 +00:00
|
|
|
archiveQueries.insert(std::make_pair(q, contact->jid));
|
2019-04-13 20:38:20 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onMamResultsReceived(const QString& queryId, const QXmppResultSetReply& resultSetReply, bool complete) {
|
2020-06-20 22:26:30 +00:00
|
|
|
std::map<QString, QString>::const_iterator itr = archiveQueries.find(queryId);
|
|
|
|
if (itr != archiveQueries.end()) {
|
2020-04-19 13:13:15 +00:00
|
|
|
QString jid = itr->second;
|
2020-06-20 22:26:30 +00:00
|
|
|
archiveQueries.erase(itr);
|
2020-04-19 13:13:15 +00:00
|
|
|
|
2020-06-14 21:23:43 +00:00
|
|
|
RosterItem* ri = rh->getRosterItem(jid);
|
2020-04-19 13:13:15 +00:00
|
|
|
|
2023-03-16 19:38:05 +00:00
|
|
|
if (ri != nullptr) {
|
2020-05-21 15:42:40 +00:00
|
|
|
qDebug() << "Flushing messages for" << jid << ", complete:" << complete;
|
2020-04-19 13:13:15 +00:00
|
|
|
ri->flushMessagesToArchive(complete, resultSetReply.first(), resultSetReply.last());
|
|
|
|
}
|
2019-04-13 20:38:20 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-19 09:12:12 +00:00
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onMamLog(QXmppLogger::MessageType type, const QString& msg) {
|
2023-08-15 15:28:25 +00:00
|
|
|
SHARED_UNUSED(type);
|
2019-06-28 15:15:30 +00:00
|
|
|
qDebug() << "MAM MESSAGE LOG::";
|
|
|
|
qDebug() << msg;
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onClientError(QXmppClient::Error err) {
|
2020-04-13 19:57:23 +00:00
|
|
|
qDebug() << "Error";
|
2019-05-24 14:46:34 +00:00
|
|
|
QString errorText;
|
|
|
|
QString errorType;
|
2022-04-14 08:13:27 +00:00
|
|
|
lastError = Error::other;
|
2019-05-15 17:36:37 +00:00
|
|
|
switch (err) {
|
|
|
|
case QXmppClient::SocketError:
|
2019-05-24 14:46:34 +00:00
|
|
|
errorText = client.socketErrorString();
|
|
|
|
errorType = "Client socket error";
|
2019-05-15 17:36:37 +00:00
|
|
|
break;
|
2019-05-24 14:46:34 +00:00
|
|
|
case QXmppClient::XmppStreamError: {
|
|
|
|
QXmppStanza::Error::Condition cnd = client.xmppStreamError();
|
|
|
|
|
|
|
|
switch (cnd) {
|
|
|
|
case QXmppStanza::Error::BadRequest:
|
|
|
|
errorText = "Bad request";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::Conflict:
|
|
|
|
errorText = "Conflict";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::FeatureNotImplemented:
|
|
|
|
errorText = "Feature is not implemented";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::Forbidden:
|
|
|
|
errorText = "Forbidden";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::Gone:
|
|
|
|
errorText = "Gone";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::InternalServerError:
|
|
|
|
errorText = "Internal server error";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::ItemNotFound:
|
|
|
|
errorText = "Item was not found";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::JidMalformed:
|
|
|
|
errorText = "Malformed JID";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::NotAcceptable:
|
|
|
|
errorText = "Not acceptable";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::NotAllowed:
|
|
|
|
errorText = "Not allowed";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::NotAuthorized:
|
|
|
|
errorText = "Authentication error";
|
2022-04-14 08:13:27 +00:00
|
|
|
lastError = Error::authentication;
|
2019-05-24 14:46:34 +00:00
|
|
|
break;
|
2021-04-18 12:49:20 +00:00
|
|
|
#if (QXMPP_VERSION) < QT_VERSION_CHECK(1, 3, 0)
|
2019-05-24 14:46:34 +00:00
|
|
|
case QXmppStanza::Error::PaymentRequired:
|
|
|
|
errorText = "Payment is required";
|
|
|
|
break;
|
2021-04-18 12:49:20 +00:00
|
|
|
#endif
|
2019-05-24 14:46:34 +00:00
|
|
|
case QXmppStanza::Error::RecipientUnavailable:
|
|
|
|
errorText = "Recipient is unavailable";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::Redirect:
|
|
|
|
errorText = "Redirected";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::RegistrationRequired:
|
|
|
|
errorText = "Registration is required";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::RemoteServerNotFound:
|
|
|
|
errorText = "Remote server was not found";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::RemoteServerTimeout:
|
|
|
|
errorText = "Remote server timeout";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::ResourceConstraint:
|
|
|
|
errorText = "Resource constraint";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::ServiceUnavailable:
|
|
|
|
errorText = "Redirected";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::SubscriptionRequired:
|
|
|
|
errorText = "Subscription is required";
|
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::UndefinedCondition:
|
|
|
|
errorText = "Undefined condition";
|
2020-06-20 22:26:30 +00:00
|
|
|
reconnectScheduled = true;
|
|
|
|
reconnectTimer->start(500); //let's reconnect here just for now, it seems to be something broken in QXMPP
|
2019-05-24 14:46:34 +00:00
|
|
|
break;
|
|
|
|
case QXmppStanza::Error::UnexpectedRequest:
|
|
|
|
errorText = "Unexpected request";
|
|
|
|
break;
|
2020-04-15 17:27:38 +00:00
|
|
|
#if (QXMPP_VERSION) >= QT_VERSION_CHECK(1, 3, 0)
|
2020-04-13 19:57:23 +00:00
|
|
|
case QXmppStanza::Error::PolicyViolation:
|
|
|
|
errorText = "Policy violation";
|
|
|
|
break;
|
2020-04-14 19:40:32 +00:00
|
|
|
#endif
|
2022-01-05 19:29:34 +00:00
|
|
|
default:
|
|
|
|
errorText = "Unknown Error";
|
|
|
|
break;
|
2019-05-24 14:46:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
errorType = "Client stream error";
|
|
|
|
}
|
|
|
|
|
2019-05-15 17:36:37 +00:00
|
|
|
break;
|
|
|
|
case QXmppClient::KeepAliveError:
|
2019-05-24 14:46:34 +00:00
|
|
|
errorText = "Client keep alive error";
|
2019-05-15 17:36:37 +00:00
|
|
|
break;
|
2019-11-17 10:24:12 +00:00
|
|
|
case QXmppClient::NoError:
|
|
|
|
break; //not exactly sure what to do here
|
2019-05-15 17:36:37 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 14:46:34 +00:00
|
|
|
qDebug() << errorType << errorText;
|
|
|
|
emit error(errorText);
|
2019-05-15 17:36:37 +00:00
|
|
|
}
|
2019-06-12 17:18:18 +00:00
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::subscribeToContact(const QString& jid, const QString& reason) {
|
|
|
|
if (state == Shared::ConnectionState::connected)
|
2019-11-02 20:50:25 +00:00
|
|
|
rm->subscribe(jid, reason);
|
2023-02-20 18:12:32 +00:00
|
|
|
else
|
2019-06-14 16:36:04 +00:00
|
|
|
qDebug() << "An attempt to subscribe account " << name << " to contact " << jid << " but the account is not in the connected state, skipping";
|
2019-06-12 17:18:18 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::unsubscribeFromContact(const QString& jid, const QString& reason) {
|
|
|
|
if (state == Shared::ConnectionState::connected)
|
2019-11-02 20:50:25 +00:00
|
|
|
rm->unsubscribe(jid, reason);
|
2023-02-20 18:12:32 +00:00
|
|
|
else
|
2019-06-14 16:36:04 +00:00
|
|
|
qDebug() << "An attempt to unsubscribe account " << name << " from contact " << jid << " but the account is not in the connected state, skipping";
|
2019-06-12 17:18:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 21:23:43 +00:00
|
|
|
void Core::Account::removeContactRequest(const QString& jid) {
|
|
|
|
rh->removeContactRequest(jid);}
|
2019-07-11 08:51:52 +00:00
|
|
|
|
2020-06-14 21:23:43 +00:00
|
|
|
void Core::Account::addContactRequest(const QString& jid, const QString& name, const QSet<QString>& groups) {
|
|
|
|
rh->addContactRequest(jid, name, groups);}
|
2019-08-29 14:19:35 +00:00
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::setRoomAutoJoin(const QString& jid, bool joined) {
|
2020-06-14 21:23:43 +00:00
|
|
|
Conference* conf = rh->getConference(jid);
|
|
|
|
if (conf == 0) {
|
2019-08-29 14:19:35 +00:00
|
|
|
qDebug() << "An attempt to set auto join to the non existing room" << jid << "of the account" << getName() << ", skipping";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-14 21:23:43 +00:00
|
|
|
conf->setAutoJoin(joined);
|
2019-08-29 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::setRoomJoined(const QString& jid, bool joined) {
|
2020-06-14 21:23:43 +00:00
|
|
|
Conference* conf = rh->getConference(jid);
|
|
|
|
if (conf == 0) {
|
2019-08-29 14:19:35 +00:00
|
|
|
qDebug() << "An attempt to set joined to the non existing room" << jid << "of the account" << getName() << ", skipping";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-14 21:23:43 +00:00
|
|
|
conf->setJoined(joined);
|
2019-08-29 14:19:35 +00:00
|
|
|
}
|
2019-09-01 19:46:12 +00:00
|
|
|
|
2023-11-05 01:12:15 +00:00
|
|
|
void Core::Account::setContactEncryption(const QString& jid, Shared::EncryptionProtocol value) {
|
|
|
|
Contact* cnt = rh->getContact(jid);
|
|
|
|
if (cnt == nullptr) {
|
|
|
|
qDebug() << "An attempt to set encryption to the non-existing contact" << jid << "of the account" << getName() << ", skipping";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt->setEncryption(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-24 22:41:06 +00:00
|
|
|
void Core::Account::discoverInfo(const QString& address, const QString& node) {
|
|
|
|
if (state == Shared::ConnectionState::connected) {
|
|
|
|
dm->requestInfo(address, node);
|
|
|
|
} else {
|
|
|
|
qDebug() << "An attempt to send a discover info by account" << name <<
|
|
|
|
"sending request to" << address << "about node" << node <<
|
|
|
|
"but the account is not in the connected state, skipping";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::setPepSupport(Shared::Support support) {
|
2022-08-27 11:39:24 +00:00
|
|
|
if (support != pepSupport) {
|
|
|
|
pepSupport = support;
|
|
|
|
emit pepSupportChanged(pepSupport);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::handleDisconnection() {
|
2022-08-27 11:39:24 +00:00
|
|
|
setPepSupport(Shared::Support::unknown);
|
2023-03-10 18:43:31 +00:00
|
|
|
delay->disconnected();
|
2023-03-11 22:38:54 +00:00
|
|
|
#if (QXMPP_VERSION) < QT_VERSION_CHECK(1, 5, 0)
|
2020-08-07 23:33:03 +00:00
|
|
|
cm->setCarbonsEnabled(false);
|
2023-03-11 22:38:54 +00:00
|
|
|
#endif
|
2020-06-20 22:26:30 +00:00
|
|
|
rh->handleOffline();
|
|
|
|
archiveQueries.clear();
|
2020-04-19 13:13:15 +00:00
|
|
|
}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::onContactHistoryResponse(const std::list<Shared::Message>& list, bool last) {
|
2020-08-21 20:57:48 +00:00
|
|
|
RosterItem* contact = static_cast<RosterItem*>(sender());
|
|
|
|
|
|
|
|
qDebug() << "Collected history for contact " << contact->jid << list.size() << "elements";
|
2023-02-20 18:12:32 +00:00
|
|
|
if (last)
|
2020-08-21 20:57:48 +00:00
|
|
|
qDebug() << "The response contains the first accounted message";
|
2023-02-20 18:12:32 +00:00
|
|
|
|
2020-08-21 20:57:48 +00:00
|
|
|
emit responseArchive(contact->jid, list, last);
|
|
|
|
}
|
2021-04-28 20:26:19 +00:00
|
|
|
|
2022-04-12 20:33:10 +00:00
|
|
|
bool Core::Account::getActive() const {
|
|
|
|
return active;}
|
|
|
|
|
|
|
|
void Core::Account::setActive(bool p_active) {
|
|
|
|
if (active != p_active) {
|
|
|
|
active = p_active;
|
|
|
|
|
2023-03-17 20:59:51 +00:00
|
|
|
emit changed({{"active", active}});
|
2022-04-12 20:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-08 16:18:15 +00:00
|
|
|
QString Core::Account::getResource() const {
|
|
|
|
return config.resource();}
|
|
|
|
|
|
|
|
void Core::Account::setResource(const QString& p_resource) {
|
|
|
|
config.setResource(p_resource);}
|
|
|
|
|
|
|
|
QString Core::Account::getBareJid() const {
|
|
|
|
return getLogin() + "@" + getServer();}
|
|
|
|
|
|
|
|
QString Core::Account::getFullJid() const {
|
|
|
|
return getBareJid() + "/" + getResource();}
|
|
|
|
|
|
|
|
QString Core::Account::getName() const {
|
|
|
|
return name;}
|
|
|
|
|
|
|
|
QString Core::Account::getLogin() const {
|
|
|
|
return config.user();}
|
|
|
|
|
|
|
|
QString Core::Account::getPassword() const {
|
|
|
|
return config.password();}
|
|
|
|
|
|
|
|
QString Core::Account::getServer() const {
|
|
|
|
return config.domain();}
|
|
|
|
|
|
|
|
Shared::AccountPassword Core::Account::getPasswordType() const {
|
|
|
|
return passwordType;}
|
|
|
|
|
|
|
|
void Core::Account::setPasswordType(Shared::AccountPassword pt) {
|
|
|
|
passwordType = pt; }
|
|
|
|
|
|
|
|
void Core::Account::setLogin(const QString& p_login) {
|
2023-03-10 18:43:31 +00:00
|
|
|
config.setUser(p_login);
|
|
|
|
delay->setOwnJid(getBareJid());
|
|
|
|
}
|
2022-04-08 16:18:15 +00:00
|
|
|
|
|
|
|
void Core::Account::setName(const QString& p_name) {
|
|
|
|
name = p_name;}
|
|
|
|
|
|
|
|
void Core::Account::setPassword(const QString& p_password) {
|
2022-04-12 20:33:10 +00:00
|
|
|
config.setPassword(p_password);
|
|
|
|
notReadyPassword = false;
|
|
|
|
}
|
2022-04-08 16:18:15 +00:00
|
|
|
|
|
|
|
void Core::Account::setServer(const QString& p_server) {
|
2023-03-10 18:43:31 +00:00
|
|
|
config.setDomain(p_server);
|
|
|
|
delay->setOwnJid(getBareJid());
|
|
|
|
}
|
2022-04-08 16:18:15 +00:00
|
|
|
|
|
|
|
void Core::Account::sendMessage(const Shared::Message& data) {
|
|
|
|
mh->sendMessage(data);}
|
|
|
|
|
2021-04-28 20:26:19 +00:00
|
|
|
void Core::Account::requestChangeMessage(const QString& jid, const QString& messageId, const QMap<QString, QVariant>& data){
|
|
|
|
mh->requestChangeMessage(jid, messageId, data);}
|
2021-05-22 22:03:14 +00:00
|
|
|
|
|
|
|
void Core::Account::resendMessage(const QString& jid, const QString& id) {
|
|
|
|
mh->resendMessage(jid, id);}
|
2022-03-28 20:25:33 +00:00
|
|
|
|
|
|
|
void Core::Account::replaceMessage(const QString& originalId, const Shared::Message& data) {
|
|
|
|
mh->sendMessage(data, false, originalId);}
|
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::requestInfo(const QString& jid) {
|
|
|
|
//TODO switch case of what kind of entity this info request is about
|
|
|
|
//right now it could be only about myself or some contact
|
2023-03-10 18:43:31 +00:00
|
|
|
delay->getInfo(jid);
|
|
|
|
//vh->requestVCard(jid);
|
2023-02-20 18:12:32 +00:00
|
|
|
}
|
2022-04-08 16:18:15 +00:00
|
|
|
|
2023-02-20 18:12:32 +00:00
|
|
|
void Core::Account::updateInfo(const Shared::Info& info) {
|
|
|
|
//TODO switch case of what kind of entity this info update is about
|
|
|
|
//right now it could be only about myself
|
2023-03-01 19:32:41 +00:00
|
|
|
vh->uploadVCard(info.getVCardRef());
|
2023-11-17 00:08:40 +00:00
|
|
|
const std::list<Shared::KeyInfo>& keys = info.getActiveKeysRef();
|
|
|
|
for (const Shared::KeyInfo& info : keys) {
|
|
|
|
qDebug() << "An attempt to save key: ";
|
|
|
|
qDebug() << "id:" << info.id;
|
|
|
|
qDebug() << "label:" << info.label;
|
|
|
|
qDebug() << "current device:" << info.currentDevice;
|
|
|
|
qDebug() << "... but it's not implemented yet, ignoring";
|
|
|
|
}
|
2023-02-20 18:12:32 +00:00
|
|
|
}
|
2022-04-08 16:18:15 +00:00
|
|
|
|
|
|
|
QString Core::Account::getAvatarPath() const {
|
|
|
|
return vh->getAvatarPath();}
|
|
|
|
|
|
|
|
void Core::Account::removeRoomRequest(const QString& jid){
|
|
|
|
rh->removeRoomRequest(jid);}
|
|
|
|
|
|
|
|
void Core::Account::addRoomRequest(const QString& jid, const QString& nick, const QString& password, bool autoJoin) {
|
|
|
|
rh->addRoomRequest(jid, nick, password, autoJoin);}
|
|
|
|
|
|
|
|
void Core::Account::addContactToGroupRequest(const QString& jid, const QString& groupName) {
|
|
|
|
rh->addContactToGroupRequest(jid, groupName);}
|
|
|
|
|
|
|
|
void Core::Account::removeContactFromGroupRequest(const QString& jid, const QString& groupName) {
|
|
|
|
rh->removeContactFromGroupRequest(jid, groupName);}
|
|
|
|
|
2023-03-17 20:59:51 +00:00
|
|
|
void Core::Account::renameContactRequest(const QString& jid, const QString& newName) {
|
2022-04-08 16:18:15 +00:00
|
|
|
Contact* cnt = rh->getContact(jid);
|
2023-03-17 20:59:51 +00:00
|
|
|
if (cnt == 0)
|
2022-04-08 16:18:15 +00:00
|
|
|
qDebug() << "An attempt to rename non existing contact" << jid << "of account" << name << ", skipping";
|
2023-03-17 20:59:51 +00:00
|
|
|
else
|
2022-04-08 16:18:15 +00:00
|
|
|
rm->renameItem(jid, newName);
|
|
|
|
}
|
2022-04-12 20:33:10 +00:00
|
|
|
|
|
|
|
void Core::Account::invalidatePassword() {
|
|
|
|
notReadyPassword = true;}
|
|
|
|
|
2022-04-14 08:13:27 +00:00
|
|
|
Core::Account::Error Core::Account::getLastError() const {
|
|
|
|
return lastError;}
|
|
|
|
|