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
|
@ -5,4 +5,6 @@ target_sources(squawk PRIVATE
|
|||
rosterhandler.h
|
||||
vcardhandler.cpp
|
||||
vcardhandler.h
|
||||
discoveryhandler.cpp
|
||||
discoveryhandler.h
|
||||
)
|
||||
|
|
135
core/handlers/discoveryhandler.cpp
Normal file
135
core/handlers/discoveryhandler.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
// 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/>.
|
||||
|
||||
#include "discoveryhandler.h"
|
||||
#include "core/account.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
Core::DiscoveryHandler::DiscoveryHandler(Core::Account* account):
|
||||
QObject(),
|
||||
acc(account)
|
||||
{
|
||||
QObject::connect(acc->dm, &QXmppDiscoveryManager::itemsReceived, this, &DiscoveryHandler::onItemsReceived);
|
||||
QObject::connect(acc->dm, &QXmppDiscoveryManager::infoReceived, this, &DiscoveryHandler::onInfoReceived);
|
||||
|
||||
acc->dm->setClientType("pc");
|
||||
acc->dm->setClientCategory("client");
|
||||
acc->dm->setClientName(qApp->applicationDisplayName() + " " + qApp->applicationVersion());
|
||||
acc->dm->setClientCapabilitiesNode("https://git.macaw.me/blue/squawk");
|
||||
}
|
||||
|
||||
void Core::DiscoveryHandler::onItemsReceived(const QXmppDiscoveryIq& items)
|
||||
{
|
||||
QString server = acc->getServer();
|
||||
if (items.from() == server) {
|
||||
std::set<QString> needToRequest;
|
||||
qDebug() << "Server items list received for account " << acc->getName() << ":";
|
||||
for (QXmppDiscoveryIq::Item item : items.items()) {
|
||||
QString jid = item.jid();
|
||||
if (jid != server) {
|
||||
qDebug() << " Node" << jid;
|
||||
needToRequest.insert(jid);
|
||||
} else {
|
||||
qDebug() << " " << item.node().toStdString().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
for (const QString& jid : needToRequest) {
|
||||
acc->dm->requestInfo(jid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Core::DiscoveryHandler::onInfoReceived(const QXmppDiscoveryIq& info)
|
||||
{
|
||||
QString from = info.from();
|
||||
QString server = acc->getServer();
|
||||
QString accName = acc->getName();
|
||||
QString bareJid = acc->getBareJid();
|
||||
if (from == server) {
|
||||
bool enableCC = false;
|
||||
qDebug() << "Server info received for account" << accName;
|
||||
QStringList features = info.features();
|
||||
qDebug() << "List of supported features of the server " << server << ":";
|
||||
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" << accName;
|
||||
acc->cm->setCarbonsEnabled(true);
|
||||
}
|
||||
|
||||
qDebug() << "Requesting account" << accName << "capabilities";
|
||||
acc->dm->requestInfo(bareJid);
|
||||
} else if (from == bareJid) {
|
||||
qDebug() << "Received capabilities for account" << accName << ":";
|
||||
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;
|
||||
}
|
||||
}
|
||||
acc->setPepSupport(pepSupported ? Shared::Support::supported : Shared::Support::unsupported);
|
||||
} else {
|
||||
qDebug() << "Received info for account" << accName << "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 acc->infoDiscovered(from, node, identities, features);
|
||||
} else {
|
||||
Contact* cont = acc->rh->getContact(from);
|
||||
if (cont != nullptr) {
|
||||
qDebug() << "Received info for account" << accName << "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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
core/handlers/discoveryhandler.h
Normal file
45
core/handlers/discoveryhandler.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
// 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_DISCOVERYHANDLER_H
|
||||
#define CORE_DISCOVERYHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <QXmppDiscoveryManager.h>
|
||||
#include <QXmppDiscoveryIq.h>
|
||||
|
||||
namespace Core {
|
||||
class Account;
|
||||
|
||||
class DiscoveryHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiscoveryHandler(Account* account);
|
||||
~DiscoveryHandler();
|
||||
|
||||
private slots:
|
||||
void onItemsReceived (const QXmppDiscoveryIq& items);
|
||||
void onInfoReceived (const QXmppDiscoveryIq& info);
|
||||
|
||||
private:
|
||||
Account* acc;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // CORE_DISCOVERYHANDLER_H
|
|
@ -26,8 +26,7 @@ Core::RosterHandler::RosterHandler(Core::Account* account):
|
|||
conferences(),
|
||||
groups(),
|
||||
queuedContacts(),
|
||||
outOfRosterContacts(),
|
||||
pepSupport(Shared::Support::unknown)
|
||||
outOfRosterContacts()
|
||||
{
|
||||
connect(acc->rm, &QXmppRosterManager::rosterReceived, this, &RosterHandler::onRosterReceived);
|
||||
connect(acc->rm, &QXmppRosterManager::itemAdded, this, &RosterHandler::onRosterItemAdded);
|
||||
|
@ -37,6 +36,8 @@ Core::RosterHandler::RosterHandler(Core::Account* account):
|
|||
|
||||
connect(acc->mm, &QXmppMucManager::roomAdded, this, &RosterHandler::onMucRoomAdded);
|
||||
connect(acc->bm, &QXmppBookmarkManager::bookmarksReceived, this, &RosterHandler::bookmarksReceived);
|
||||
|
||||
connect(acc, &Account::pepSupportChanged, this, &RosterHandler::onPepSupportedChanged);
|
||||
}
|
||||
|
||||
Core::RosterHandler::~RosterHandler()
|
||||
|
@ -52,8 +53,6 @@ Core::RosterHandler::~RosterHandler()
|
|||
|
||||
void Core::RosterHandler::onRosterReceived()
|
||||
{
|
||||
acc->requestVCard(acc->getBareJid()); //TODO need to make sure server actually supports vCards
|
||||
|
||||
QStringList bj = acc->rm->getRosterBareJids();
|
||||
for (int i = 0; i < bj.size(); ++i) {
|
||||
const QString& jid = bj[i];
|
||||
|
@ -111,7 +110,7 @@ void Core::RosterHandler::addedAccount(const QString& jid)
|
|||
if (grCount == 0) {
|
||||
emit acc->addContact(jid, "", cData);
|
||||
}
|
||||
if (pepSupport == Shared::Support::supported) {
|
||||
if (acc->pepSupport == Shared::Support::supported) {
|
||||
acc->dm->requestInfo(jid);
|
||||
//acc->dm->requestItems(jid);
|
||||
}
|
||||
|
@ -592,20 +591,15 @@ void Core::RosterHandler::handleOffline()
|
|||
pair.second->clearArchiveRequests();
|
||||
pair.second->downgradeDatabaseState();
|
||||
}
|
||||
setPepSupport(Shared::Support::unknown);
|
||||
}
|
||||
|
||||
|
||||
void Core::RosterHandler::setPepSupport(Shared::Support support)
|
||||
void Core::RosterHandler::onPepSupportedChanged(Shared::Support support)
|
||||
{
|
||||
if (pepSupport != support) {
|
||||
pepSupport = support;
|
||||
|
||||
if (pepSupport == Shared::Support::supported) {
|
||||
for (const std::pair<const QString, Contact*>& pair : contacts) {
|
||||
if (pair.second->getPepSupport() == Shared::Support::unknown) {
|
||||
acc->dm->requestInfo(pair.first);
|
||||
}
|
||||
if (support == Shared::Support::supported) {
|
||||
for (const std::pair<const QString, Contact*>& pair : contacts) {
|
||||
if (pair.second->getPepSupport() == Shared::Support::unknown) {
|
||||
acc->dm->requestInfo(pair.first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ public:
|
|||
|
||||
void storeConferences();
|
||||
void clearConferences();
|
||||
void setPepSupport(Shared::Support support);
|
||||
|
||||
private slots:
|
||||
void onRosterReceived();
|
||||
|
@ -89,6 +88,7 @@ private slots:
|
|||
void onContactNameChanged(const QString& name);
|
||||
void onContactSubscriptionStateChanged(Shared::SubscriptionState state);
|
||||
void onContactAvatarChanged(Shared::Avatar, const QString& path);
|
||||
void onPepSupportedChanged(Shared::Support support);
|
||||
|
||||
private:
|
||||
void addNewRoom(const QString& jid, const QString& nick, const QString& roomName, bool autoJoin);
|
||||
|
@ -109,7 +109,6 @@ private:
|
|||
std::map<QString, std::set<QString>> groups;
|
||||
std::map<QString, QString> queuedContacts;
|
||||
std::set<QString> outOfRosterContacts;
|
||||
Shared::Support pepSupport;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ void Core::VCardHandler::requestVCard(const QString& jid)
|
|||
}
|
||||
}
|
||||
|
||||
void Core::VCardHandler::handleOtherPresenceOfMyAccountChange(const QXmppPresence& p_presence)
|
||||
void Core::VCardHandler::handlePresenceOfMyAccountChange(const QXmppPresence& p_presence)
|
||||
{
|
||||
if (!ownVCardRequestInProgress) {
|
||||
switch (p_presence.vCardUpdateType()) {
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
void handleOffline();
|
||||
void requestVCard(const QString& jid);
|
||||
void handleOtherPresenceOfMyAccountChange(const QXmppPresence& p_presence);
|
||||
void handlePresenceOfMyAccountChange(const QXmppPresence& p_presence);
|
||||
void uploadVCard(const Shared::VCard& card);
|
||||
QString getAvatarPath() const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue