first thought about forms, discovering contact pep support

This commit is contained in:
Blue 2022-08-26 01:49:49 +03:00
parent c50cd1140e
commit 7b2b7ee5d5
Signed by: blue
GPG key ID: 9B203B252A63EE38
11 changed files with 230 additions and 9 deletions

View file

@ -623,12 +623,13 @@ void Core::Account::onDiscoveryInfoReceived(const QXmppDiscoveryIq& info)
bool pepSupported = false;
for (const QXmppDiscoveryIq::Identity& identity : identities) {
QString type = identity.type();
qDebug() << " " << identity.category() << type;
if (type == "pep") {
QString category = identity.category();
qDebug() << " " << category << type;
if (type == "pep" && category == "pubsub") {
pepSupported = true;
}
}
rh->setPepSupport(pepSupported);
rh->setPepSupport(pepSupported ? Shared::Support::supported : Shared::Support::unsupported);
} else {
qDebug() << "Received info for account" << name << "about" << from;
QString node = info.queryNode();
@ -651,6 +652,22 @@ void Core::Account::onDiscoveryInfoReceived(const QXmppDiscoveryIq& info)
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);
}
}
}
}

View file

@ -22,7 +22,8 @@
Core::Contact::Contact(const QString& pJid, const QString& account, QObject* parent):
RosterItem(pJid, account, parent),
groups(),
subscriptionState(Shared::SubscriptionState::unknown)
subscriptionState(Shared::SubscriptionState::unknown),
pep(Shared::Support::unknown)
{
}
@ -98,3 +99,15 @@ void Core::Contact::handlePresence(const QXmppPresence& pres)
}
}
}
void Core::Contact::setPepSupport(Shared::Support support) {
if (pep != support) {
pep = support;
}
}
Shared::Support Core::Contact::getPepSupport() const {
return pep;}

View file

@ -21,8 +21,11 @@
#include <QObject>
#include <QSet>
#include "rosteritem.h"
#include <shared/enums.h>
namespace Core {
class Contact : public RosterItem
@ -38,6 +41,9 @@ public:
void setSubscriptionState(Shared::SubscriptionState state);
Shared::SubscriptionState getSubscriptionState() const;
void setPepSupport(Shared::Support support);
Shared::Support getPepSupport() const;
void handlePresence(const QXmppPresence & pres) override;
signals:
@ -48,6 +54,7 @@ signals:
private:
QSet<QString> groups;
Shared::SubscriptionState subscriptionState;
Shared::Support pep;
};
}

View file

@ -27,7 +27,7 @@ Core::RosterHandler::RosterHandler(Core::Account* account):
groups(),
queuedContacts(),
outOfRosterContacts(),
pepSupport(false)
pepSupport(Shared::Support::unknown)
{
connect(acc->rm, &QXmppRosterManager::rosterReceived, this, &RosterHandler::onRosterReceived);
connect(acc->rm, &QXmppRosterManager::itemAdded, this, &RosterHandler::onRosterItemAdded);
@ -111,6 +111,10 @@ void Core::RosterHandler::addedAccount(const QString& jid)
if (grCount == 0) {
emit acc->addContact(jid, "", cData);
}
if (pepSupport == Shared::Support::supported) {
acc->dm->requestInfo(jid);
//acc->dm->requestItems(jid);
}
handleNewContact(contact);
}
}
@ -588,13 +592,21 @@ void Core::RosterHandler::handleOffline()
pair.second->clearArchiveRequests();
pair.second->downgradeDatabaseState();
}
setPepSupport(false);
setPepSupport(Shared::Support::unknown);
}
void Core::RosterHandler::setPepSupport(bool support)
void Core::RosterHandler::setPepSupport(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);
}
}
}
}
}

View file

@ -32,6 +32,7 @@
#include <QXmppMucManager.h>
#include <QXmppRosterIq.h>
#include <shared/enums.h>
#include <shared/message.h>
#include <core/contact.h>
#include <core/conference.h>
@ -64,7 +65,7 @@ public:
void storeConferences();
void clearConferences();
void setPepSupport(bool support);
void setPepSupport(Shared::Support support);
private slots:
void onRosterReceived();
@ -108,7 +109,7 @@ private:
std::map<QString, std::set<QString>> groups;
std::map<QString, QString> queuedContacts;
std::set<QString> outOfRosterContacts;
bool pepSupport;
Shared::Support pepSupport;
};
}