forked from blue/squawk
removed own VCard request at the start if the presence doesn't show that the avatar changed, little refactoring
This commit is contained in:
parent
7b2b7ee5d5
commit
b6ba022bff
10 changed files with 215 additions and 129 deletions
121
core/account.cpp
121
core/account.cpp
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "account.h"
|
||||
#include <QXmppMessage.h>
|
||||
|
||||
#include <QDateTime>
|
||||
|
||||
using namespace Core;
|
||||
|
@ -44,12 +45,13 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
network(p_net),
|
||||
passwordType(Shared::AccountPassword::plain),
|
||||
lastError(Error::none),
|
||||
pepSupport(false),
|
||||
pepSupport(Shared::Support::unknown),
|
||||
active(p_active),
|
||||
notReadyPassword(false),
|
||||
mh(new MessageHandler(this)),
|
||||
rh(new RosterHandler(this)),
|
||||
vh(new VCardHandler(this))
|
||||
vh(new VCardHandler(this)),
|
||||
dh(new DiscoveryHandler(this))
|
||||
{
|
||||
config.setUser(p_login);
|
||||
config.setDomain(p_server);
|
||||
|
@ -79,9 +81,6 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
QObject::connect(um, &QXmppUploadRequestManager::slotReceived, mh, &MessageHandler::onUploadSlotReceived);
|
||||
QObject::connect(um, &QXmppUploadRequestManager::requestFailed, mh, &MessageHandler::onUploadSlotRequestFailed);
|
||||
|
||||
QObject::connect(dm, &QXmppDiscoveryManager::itemsReceived, this, &Account::onDiscoveryItemsReceived);
|
||||
QObject::connect(dm, &QXmppDiscoveryManager::infoReceived, this, &Account::onDiscoveryInfoReceived);
|
||||
|
||||
QObject::connect(network, &NetworkAccess::uploadFileComplete, mh, &MessageHandler::onUploadFileComplete);
|
||||
QObject::connect(network, &NetworkAccess::downloadFileComplete, mh, &MessageHandler::onDownloadFileComplete);
|
||||
QObject::connect(network, &NetworkAccess::loadFileError, mh, &MessageHandler::onLoadFileError);
|
||||
|
@ -93,8 +92,6 @@ Account::Account(const QString& p_login, const QString& p_server, const QString&
|
|||
QObject::connect(reconnectTimer, &QTimer::timeout, this, &Account::onReconnectTimer);
|
||||
|
||||
if (name == "Test") {
|
||||
qDebug() << "Presence capabilities: " << presence.capabilityNode();
|
||||
|
||||
QXmppLogger* logger = new QXmppLogger(this);
|
||||
logger->setLoggingType(QXmppLogger::SignalLogging);
|
||||
client.setLogger(logger);
|
||||
|
@ -263,9 +260,8 @@ void Core::Account::onPresenceReceived(const QXmppPresence& p_presence)
|
|||
if (jid == getBareJid()) {
|
||||
if (resource == getResource()) {
|
||||
emit availabilityChanged(static_cast<Shared::Availability>(p_presence.availableStatusType()));
|
||||
} else {
|
||||
vh->handleOtherPresenceOfMyAccountChange(p_presence);
|
||||
}
|
||||
vh->handlePresenceOfMyAccountChange(p_presence);
|
||||
} else {
|
||||
RosterItem* item = rh->getRosterItem(jid);
|
||||
if (item != 0) {
|
||||
|
@ -574,104 +570,6 @@ void Core::Account::setRoomJoined(const QString& jid, bool joined)
|
|||
conf->setJoined(joined);
|
||||
}
|
||||
|
||||
void Core::Account::onDiscoveryItemsReceived(const QXmppDiscoveryIq& items)
|
||||
{
|
||||
if (items.from() == getServer()) {
|
||||
std::set<QString> needToRequest;
|
||||
qDebug() << "Server items list received for account " << name << ":";
|
||||
for (QXmppDiscoveryIq::Item item : items.items()) {
|
||||
QString jid = item.jid();
|
||||
if (jid != getServer()) {
|
||||
qDebug() << " Node" << jid;
|
||||
needToRequest.insert(jid);
|
||||
} else {
|
||||
qDebug() << " " << item.node().toStdString().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
for (const QString& jid : needToRequest) {
|
||||
dm->requestInfo(jid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::onDiscoveryInfoReceived(const QXmppDiscoveryIq& info)
|
||||
{
|
||||
QString from = info.from();
|
||||
if (from == getServer()) {
|
||||
bool enableCC = false;
|
||||
qDebug() << "Server info received for account" << name;
|
||||
QStringList features = info.features();
|
||||
qDebug() << "List of supported features of the server " << getServer() << ":";
|
||||
for (const QString& feature : features) {
|
||||
qDebug() << " " << feature.toStdString().c_str();
|
||||
if (feature == "urn:xmpp:carbons:2") {
|
||||
enableCC = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (enableCC) {
|
||||
qDebug() << "Enabling carbon copies for account" << name;
|
||||
cm->setCarbonsEnabled(true);
|
||||
}
|
||||
|
||||
qDebug() << "Requesting account" << name << "capabilities";
|
||||
dm->requestInfo(getBareJid());
|
||||
} else if (from == getBareJid()) {
|
||||
qDebug() << "Received capabilities for account" << name << ":";
|
||||
QList<QXmppDiscoveryIq::Identity> identities = info.identities();
|
||||
bool pepSupported = false;
|
||||
for (const QXmppDiscoveryIq::Identity& identity : identities) {
|
||||
QString type = identity.type();
|
||||
QString category = identity.category();
|
||||
qDebug() << " " << category << type;
|
||||
if (type == "pep" && category == "pubsub") {
|
||||
pepSupported = true;
|
||||
}
|
||||
}
|
||||
rh->setPepSupport(pepSupported ? Shared::Support::supported : Shared::Support::unsupported);
|
||||
} else {
|
||||
qDebug() << "Received info for account" << name << "about" << from;
|
||||
QString node = info.queryNode();
|
||||
if (!node.isEmpty()) {
|
||||
QStringList feats = info.features();
|
||||
std::set<Shared::Identity> identities;
|
||||
std::set<QString> features(feats.begin(), feats.end());
|
||||
QList<QXmppDiscoveryIq::Identity> idents = info.identities();
|
||||
for (const QXmppDiscoveryIq::Identity& ident : idents) {
|
||||
Shared::Identity identity;
|
||||
identity.category = ident.category();
|
||||
identity.language = ident.language();
|
||||
identity.name = ident.name();
|
||||
identity.type = ident.type();
|
||||
identities.insert(identity);
|
||||
|
||||
qDebug() << " " << identity.name << identity.category << identity.type;
|
||||
}
|
||||
for (const QString& feat : features) {
|
||||
qDebug() << " " << feat;
|
||||
}
|
||||
emit infoDiscovered(from, node, identities, features);
|
||||
} else {
|
||||
Contact* cont = rh->getContact(from);
|
||||
if (cont != nullptr) {
|
||||
qDebug() << "Received info for account" << name << "about" << from;
|
||||
QList<QXmppDiscoveryIq::Identity> identities = info.identities();
|
||||
bool pepSupported = false;
|
||||
for (const QXmppDiscoveryIq::Identity& identity : identities) {
|
||||
QString type = identity.type();
|
||||
QString category = identity.category();
|
||||
qDebug() << " " << category << type;
|
||||
if (type == "pep" && category == "pubsub") {
|
||||
pepSupported = true;
|
||||
}
|
||||
}
|
||||
cont->setPepSupport(pepSupported ? Shared::Support::supported : Shared::Support::unsupported);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::discoverInfo(const QString& address, const QString& node) {
|
||||
if (state == Shared::ConnectionState::connected) {
|
||||
dm->requestInfo(address, node);
|
||||
|
@ -682,8 +580,17 @@ void Core::Account::discoverInfo(const QString& address, const QString& node) {
|
|||
}
|
||||
}
|
||||
|
||||
void Core::Account::setPepSupport(Shared::Support support)
|
||||
{
|
||||
if (support != pepSupport) {
|
||||
pepSupport = support;
|
||||
emit pepSupportChanged(pepSupport);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::Account::handleDisconnection()
|
||||
{
|
||||
setPepSupport(Shared::Support::unknown);
|
||||
cm->setCarbonsEnabled(false);
|
||||
rh->handleOffline();
|
||||
vh->handleOffline();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue