aboutsummaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorLinus Jahn <lnj@kaidan.im>2020-04-05 15:46:40 +0200
committerLNJ <lnj@kaidan.im>2020-04-05 16:31:44 +0200
commit92ca98fd87764eda452a063bb06611f79829fd69 (patch)
tree6818626b7da6072b7ebd6a17cca16ec003010089 /src/base
parentf3aa893f5165feb3020b691434c7ce17119559fd (diff)
downloadqxmpp-92ca98fd87764eda452a063bb06611f79829fd69.tar.gz
QXmppRosterIq: Add 'approved' attribute from RFC6121
The 'approved' attribute was added in RFC6121 to indicate whether a pre-approved subscription exists.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/QXmppRosterIq.cpp42
-rw-r--r--src/base/QXmppRosterIq.h2
2 files changed, 43 insertions, 1 deletions
diff --git a/src/base/QXmppRosterIq.cpp b/src/base/QXmppRosterIq.cpp
index 0397c94d..ef06dd0a 100644
--- a/src/base/QXmppRosterIq.cpp
+++ b/src/base/QXmppRosterIq.cpp
@@ -159,24 +159,32 @@ void QXmppRosterIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
class QXmppRosterIq::ItemPrivate : public QSharedData
{
public:
+ ItemPrivate();
+
QString bareJid;
Item::SubscriptionType type;
QString name;
// can be subscribe/unsubscribe (attribute "ask")
QString subscriptionStatus;
QSet<QString> groups;
+ bool approved;
// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
bool isMixChannel = false;
QString mixParticipantId;
};
+QXmppRosterIq::ItemPrivate::ItemPrivate()
+ : type(QXmppRosterIq::Item::NotSet),
+ approved(false)
+{
+}
+
///
/// Constructs a new roster entry.
///
QXmppRosterIq::Item::Item()
: d(new ItemPrivate)
{
- d->type = NotSet;
}
QXmppRosterIq::Item::Item(const QXmppRosterIq::Item &other) = default;
@@ -277,6 +285,7 @@ QXmppRosterIq::Item::subscriptionType() const
return d->type;
}
+
///
/// Sets the subscription type of the roster entry.
///
@@ -287,6 +296,30 @@ void QXmppRosterIq::Item::setSubscriptionType(SubscriptionType type)
d->type = type;
}
+///
+/// Returns whether the item has a pre-approved presence subscription.
+///
+/// \since QXmpp 1.3
+///
+bool QXmppRosterIq::Item::isApproved() const
+{
+ return d->approved;
+}
+
+///
+/// Sets whether the item has a pre-approved presence subscription.
+///
+/// This cannot be used to initiate a pre-approved subscription. For this
+/// purpose the client must send a &lt;presence/&gt; stanza of type
+/// \c subscribed to the user.
+///
+/// \since QXmpp 1.3
+///
+void QXmppRosterIq::Item::setIsApproved(bool approved)
+{
+ d->approved = approved;
+}
+
QString QXmppRosterIq::Item::getSubscriptionTypeStr() const
{
switch (d->type) {
@@ -375,6 +408,11 @@ void QXmppRosterIq::Item::parse(const QDomElement &element)
setSubscriptionTypeFromStr(element.attribute(QStringLiteral("subscription")));
setSubscriptionStatus(element.attribute(QStringLiteral("ask")));
+ // pre-approved
+ const QString approved = element.attribute(QStringLiteral("approved"));
+ d->approved = (approved == QStringLiteral("1") || approved == QStringLiteral("true"));
+
+ // groups
QDomElement groupElement = element.firstChildElement(QStringLiteral("group"));
while (!groupElement.isNull()) {
d->groups << groupElement.text();
@@ -396,6 +434,8 @@ void QXmppRosterIq::Item::toXml(QXmlStreamWriter *writer) const
helperToXmlAddAttribute(writer, QStringLiteral("name"), d->name);
helperToXmlAddAttribute(writer, QStringLiteral("subscription"), getSubscriptionTypeStr());
helperToXmlAddAttribute(writer, QStringLiteral("ask"), subscriptionStatus());
+ if (d->approved)
+ writer->writeAttribute(QStringLiteral("approved"), QStringLiteral("true"));
QSet<QString>::const_iterator i = d->groups.constBegin();
while (i != d->groups.constEnd()) {
diff --git a/src/base/QXmppRosterIq.h b/src/base/QXmppRosterIq.h
index 6567ba62..77e9b522 100644
--- a/src/base/QXmppRosterIq.h
+++ b/src/base/QXmppRosterIq.h
@@ -72,12 +72,14 @@ public:
QString name() const;
QString subscriptionStatus() const;
SubscriptionType subscriptionType() const;
+ bool isApproved() const;
void setBareJid(const QString &);
void setGroups(const QSet<QString> &);
void setName(const QString &);
void setSubscriptionStatus(const QString &);
void setSubscriptionType(SubscriptionType);
+ void setIsApproved(bool);
// XEP-0405: Mediated Information eXchange (MIX): Participant Server Requirements
bool isMixChannel() const;