diff --git a/core/account.cpp b/core/account.cpp index 48c48f9..c3203b4 100644 --- a/core/account.cpp +++ b/core/account.cpp @@ -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 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); + } } } } diff --git a/core/contact.cpp b/core/contact.cpp index 0471a5c..3030f4d 100644 --- a/core/contact.cpp +++ b/core/contact.cpp @@ -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;} + + + diff --git a/core/contact.h b/core/contact.h index aa81010..01c082f 100644 --- a/core/contact.h +++ b/core/contact.h @@ -21,8 +21,11 @@ #include #include + #include "rosteritem.h" +#include + 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 groups; Shared::SubscriptionState subscriptionState; + Shared::Support pep; }; } diff --git a/core/handlers/rosterhandler.cpp b/core/handlers/rosterhandler.cpp index 6a233d6..748f0f7 100644 --- a/core/handlers/rosterhandler.cpp +++ b/core/handlers/rosterhandler.cpp @@ -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& pair : contacts) { + if (pair.second->getPepSupport() == Shared::Support::unknown) { + acc->dm->requestInfo(pair.first); + } + } + } } } diff --git a/core/handlers/rosterhandler.h b/core/handlers/rosterhandler.h index 02bbc98..7be38e1 100644 --- a/core/handlers/rosterhandler.h +++ b/core/handlers/rosterhandler.h @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -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> groups; std::map queuedContacts; std::set outOfRosterContacts; - bool pepSupport; + Shared::Support pepSupport; }; } diff --git a/shared/CMakeLists.txt b/shared/CMakeLists.txt index 7495d4e..51c599f 100644 --- a/shared/CMakeLists.txt +++ b/shared/CMakeLists.txt @@ -22,4 +22,8 @@ target_sources(squawk PRIVATE clientinfo.cpp identity.h identity.cpp + form.h + form.cpp + field.h + field.cpp ) diff --git a/shared/enums.h b/shared/enums.h index cb41443..273a22d 100644 --- a/shared/enums.h +++ b/shared/enums.h @@ -117,5 +117,12 @@ Q_ENUM_NS(AccountPassword) static const AccountPassword AccountPasswordHighest = AccountPassword::kwallet; static const AccountPassword AccountPasswordLowest = AccountPassword::plain; +enum class Support { + unknown, + supported, + unsupported +}; +Q_ENUM_NS(Support) + } #endif // SHARED_ENUMS_H diff --git a/shared/field.cpp b/shared/field.cpp new file mode 100644 index 0000000..f469646 --- /dev/null +++ b/shared/field.cpp @@ -0,0 +1,28 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#include "field.h" + +Shared::Field::Field(Shared::Field::Type fieldTtype): + type(fieldTtype), + key(), + label(), + description(), + required(false), + options(), + value() +{ +} diff --git a/shared/field.h b/shared/field.h new file mode 100644 index 0000000..e7c9a02 --- /dev/null +++ b/shared/field.h @@ -0,0 +1,61 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#ifndef SHARED_FIELD_H +#define SHARED_FIELD_H + +#include + +#include +#include + +namespace Shared { + +/** + * @todo write docs + */ +class Field +{ +public: + enum class Type { + boolean, + fixed, + hidden, + jidMultiple, + jidSingle, + listMultiple, + listSingle, + textMultiple, + textPrivate, + textSingle + }; + + Field(Type fieldType); + +public: + const Type type; + QString key; + QString label; + QString description; + bool required; + std::list> options; + QVariant value; + +}; + +} + +#endif // SHARED_FIELD_H diff --git a/shared/form.cpp b/shared/form.cpp new file mode 100644 index 0000000..bf309ca --- /dev/null +++ b/shared/form.cpp @@ -0,0 +1,23 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#include "form.h" + +Shared::Form::Form(Shared::Form::Type formType): + type(formType), + title(), + instructions(), + fields() {} diff --git a/shared/form.h b/shared/form.h new file mode 100644 index 0000000..08c8c95 --- /dev/null +++ b/shared/form.h @@ -0,0 +1,48 @@ +// Squawk messenger. +// Copyright (C) 2019 Yury Gubich +// +// 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 . + +#ifndef SHARED_FORM_H +#define SHARED_FORM_H + +#include + +#include + +namespace Shared { + +class Form +{ +public: + enum class Type { + none, + form, + submit, + cancel, + result + }; + + Form(Type formType); + +public: + const Type type; + QString title; + QString instructions; + std::list fields; +}; + +} + +#endif // SHARED_FORM_H