From 1cd1192af7f660baf9b86524abf0b6c7204341c2 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Wed, 5 Sep 2012 16:11:48 +0200 Subject: Add QXmppMucRoom::ban() slot to ban users. --- src/client/QXmppMucManager.cpp | 35 +++++++++++++++++++++++++++++++++++ src/client/QXmppMucManager.h | 1 + 2 files changed, 36 insertions(+) (limited to 'src/client') diff --git a/src/client/QXmppMucManager.cpp b/src/client/QXmppMucManager.cpp index 222d14de..5b006af2 100644 --- a/src/client/QXmppMucManager.cpp +++ b/src/client/QXmppMucManager.cpp @@ -226,6 +226,41 @@ QXmppMucRoom::Actions QXmppMucRoom::allowedActions() const return d->allowedActions; } +/// Bans the specified user from the chat room. +/// +/// The specified \a jid can be either an "anonymized" room participant JID +/// such of the form theroom@conference.example.com/nickname or a real JID. +/// +/// \return true if the request was sent, false otherwise + +bool QXmppMucRoom::ban(const QString &jid, const QString &reason) +{ + QString realJid; + if (QXmppUtils::jidToBareJid(jid) == d->jid) { + // an "anonymized" JID was specified, look up the real JID + if (d->participants.contains(jid)) + realJid = d->participants.value(jid).mucItem().jid(); + if (realJid.isEmpty()) { + qWarning("Coud not determine real JID for %s", qPrintable(jid)); + return false; + } + } else { + realJid = jid; + } + + QXmppMucItem item; + item.setAffiliation(QXmppMucItem::OutcastAffiliation); + item.setJid(realJid); + item.setReason(reason); + + QXmppMucAdminIq iq; + iq.setType(QXmppIq::Set); + iq.setTo(d->jid); + iq.setItems(QList() << item); + + return d->client->sendPacket(iq); +} + /// Returns true if you are currently in the room. bool QXmppMucRoom::isJoined() const diff --git a/src/client/QXmppMucManager.h b/src/client/QXmppMucManager.h index 9d103c12..77760b1f 100644 --- a/src/client/QXmppMucManager.h +++ b/src/client/QXmppMucManager.h @@ -188,6 +188,7 @@ signals: void subjectChanged(const QString &subject); public slots: + bool ban(const QString &jid, const QString &reason); bool join(); bool kick(const QString &jid, const QString &reason); bool leave(const QString &message = QString()); -- cgit v1.2.3