aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2012-09-12 14:33:43 +0200
committerJeremy Lainé <jeremy.laine@m4x.org>2012-09-12 14:33:43 +0200
commitef8fce0bb434c5fdc22630a0890a3c0fa4c7cc1f (patch)
treee0d64902da2332747cb4f5d6ce5edb6a2f4df169 /src
parentcd5287ba3fe64fd2782c10066a43c31b4c7694de (diff)
downloadqxmpp-ef8fce0bb434c5fdc22630a0890a3c0fa4c7cc1f.tar.gz
Add XEP-0045: Multi-User Chat attributes to QXmppPresence.
Diffstat (limited to 'src')
-rw-r--r--src/base/QXmppPresence.cpp45
-rw-r--r--src/base/QXmppPresence.h6
-rw-r--r--src/client/QXmppMucManager.cpp26
3 files changed, 57 insertions, 20 deletions
diff --git a/src/base/QXmppPresence.cpp b/src/base/QXmppPresence.cpp
index 5cd81739..a720a0e4 100644
--- a/src/base/QXmppPresence.cpp
+++ b/src/base/QXmppPresence.cpp
@@ -72,7 +72,9 @@ public:
// XEP-0045: Multi-User Chat
QXmppMucItem mucItem;
+ QString mucPassword;
QList<int> mucStatusCodes;
+ bool mucSupported;
};
/// Constructs a QXmppPresence.
@@ -83,6 +85,7 @@ QXmppPresence::QXmppPresence(QXmppPresence::Type type)
: d(new QXmppPresencePrivate)
{
d->type = type;
+ d->mucSupported = false;
d->vCardUpdateType = VCardUpdateNone;
}
@@ -198,7 +201,11 @@ void QXmppPresence::parse(const QDomElement &element)
while(!xElement.isNull())
{
// XEP-0045: Multi-User Chat
- if(xElement.namespaceURI() == ns_muc_user)
+ if(xElement.namespaceURI() == ns_muc) {
+ d->mucSupported = true;
+ d->mucPassword = xElement.firstChildElement("password").text();
+ }
+ else if(xElement.namespaceURI() == ns_muc_user)
{
QDomElement itemElement = xElement.firstChildElement("item");
d->mucItem.parse(itemElement);
@@ -273,6 +280,14 @@ void QXmppPresence::toXml(QXmlStreamWriter *xmlWriter) const
error().toXml(xmlWriter);
// XEP-0045: Multi-User Chat
+ if(d->mucSupported) {
+ xmlWriter->writeStartElement("x");
+ xmlWriter->writeAttribute("xmlns", ns_muc);
+ if (!d->mucPassword.isEmpty())
+ xmlWriter->writeTextElement("password", d->mucPassword);
+ xmlWriter->writeEndElement();
+ }
+
if(!d->mucItem.isNull() || !d->mucStatusCodes.isEmpty())
{
xmlWriter->writeStartElement("x");
@@ -420,6 +435,20 @@ void QXmppPresence::setMucItem(const QXmppMucItem &item)
d->mucItem = item;
}
+/// Returns the password used to join a MUC room.
+
+QString QXmppPresence::mucPassword() const
+{
+ return d->mucPassword;
+}
+
+/// Sets the password used to join a MUC room.
+
+void QXmppPresence::setMucPassword(const QString &password)
+{
+ d->mucPassword = password;
+}
+
/// Returns the MUC status codes.
QList<int> QXmppPresence::mucStatusCodes() const
@@ -436,6 +465,20 @@ void QXmppPresence::setMucStatusCodes(const QList<int> &codes)
d->mucStatusCodes = codes;
}
+/// Returns true if the sender has indicated MUC support.
+
+bool QXmppPresence::isMucSupported() const
+{
+ return d->mucSupported;
+}
+
+/// Sets whether MUC is \a supported.
+
+void QXmppPresence::setMucSupported(bool supported)
+{
+ d->mucSupported = supported;
+}
+
/// \cond
const QXmppPresence::Status& QXmppPresence::status() const
{
diff --git a/src/base/QXmppPresence.h b/src/base/QXmppPresence.h
index c7e663e6..1029ce5c 100644
--- a/src/base/QXmppPresence.h
+++ b/src/base/QXmppPresence.h
@@ -142,9 +142,15 @@ public:
QXmppMucItem mucItem() const;
void setMucItem(const QXmppMucItem &item);
+ QString mucPassword() const;
+ void setMucPassword(const QString &password);
+
QList<int> mucStatusCodes() const;
void setMucStatusCodes(const QList<int> &codes);
+ bool isMucSupported() const;
+ void setMucSupported(bool supported);
+
/// XEP-0153: vCard-Based Avatars
QByteArray photoHash() const;
void setPhotoHash(const QByteArray&);
diff --git a/src/client/QXmppMucManager.cpp b/src/client/QXmppMucManager.cpp
index 811514c5..7f3b4b12 100644
--- a/src/client/QXmppMucManager.cpp
+++ b/src/client/QXmppMucManager.cpp
@@ -283,17 +283,8 @@ bool QXmppMucRoom::join()
QXmppPresence packet = d->client->clientPresence();
packet.setTo(d->ownJid());
packet.setType(QXmppPresence::Available);
- QXmppElement x;
- x.setTagName("x");
- x.setAttribute("xmlns", ns_muc);
- if (!d->password.isEmpty())
- {
- QXmppElement p;
- p.setTagName("password");
- p.setValue(d->password);
- x.appendChild(p);
- }
- packet.setExtensions(QXmppElementList() << x);
+ packet.setMucPassword(d->password);
+ packet.setMucSupported(true);
return d->client->sendPacket(packet);
}
@@ -717,15 +708,12 @@ void QXmppMucRoom::_q_presenceReceived(const QXmppPresence &presence)
}
}
else if (presence.type() == QXmppPresence::Error) {
- foreach (const QXmppElement &extension, presence.extensions()) {
- if (extension.tagName() == "x" && extension.attribute("xmlns") == ns_muc) {
- // emit error
- emit error(presence.error());
+ if (presence.isMucSupported()) {
+ // emit error
+ emit error(presence.error());
- // notify the user we left the room
- emit left();
- break;
- }
+ // notify the user we left the room
+ emit left();
}
}
}