diff options
author | Kevin Smith <git@kismith.co.uk> | 2011-10-02 17:38:56 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2011-10-03 07:02:37 (GMT) |
commit | 4ea336d9d124f1c761b22943eaf6771e16a61e58 (patch) | |
tree | 7bcb7ac4366cf31a2f98654a5859de0b32fb318a /Swiften | |
parent | 123502d97dc20357ea03fd7f238f117aeb2d05c3 (diff) | |
download | swift-4ea336d9d124f1c761b22943eaf6771e16a61e58.zip swift-4ea336d9d124f1c761b22943eaf6771e16a61e58.tar.bz2 |
Simple MUC invites.
Resolves: #152
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Elements/MUCInvitationPayload.h | 68 | ||||
-rw-r--r-- | Swiften/MUC/MUC.cpp | 12 | ||||
-rw-r--r-- | Swiften/MUC/MUC.h | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp | 5 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp | 22 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h | 17 | ||||
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp | 2 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.cpp | 44 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h | 20 |
11 files changed, 194 insertions, 0 deletions
diff --git a/Swiften/Elements/MUCInvitationPayload.h b/Swiften/Elements/MUCInvitationPayload.h new file mode 100644 index 0000000..ebae61a --- /dev/null +++ b/Swiften/Elements/MUCInvitationPayload.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <string> + +#include <Swiften/Elements/Payload.h> +#include <Swiften/JID/JID.h> + +namespace Swift { + class MUCInvitationPayload : public Payload { + public: + typedef boost::shared_ptr<MUCInvitationPayload> ref; + MUCInvitationPayload() : continuation_(false) { + } + + void setIsContinuation(bool b) { + continuation_ = b; + } + + bool getIsContinuation() const { + return continuation_; + } + + void setJID(const JID& jid) { + jid_ = jid; + } + + const JID& getJID() const { + return jid_; + } + + void setPassword(const std::string& password) { + password_ = password; + } + + const std::string& getPassword() const { + return password_; + } + + void setReason(const std::string& text) { + reason_ = text; + } + + const std::string& getReason() const { + return reason_; + } + + void setThread(const std::string& thread) { + thread_ = thread; + } + + const std::string& getThread() const { + return thread_; + } + + private: + bool continuation_; + JID jid_; + std::string password_; + std::string reason_; + std::string thread_; + }; +} diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp index 6fe8f19..4c9e537 100644 --- a/Swiften/MUC/MUC.cpp +++ b/Swiften/MUC/MUC.cpp @@ -21,6 +21,7 @@ #include <Swiften/Elements/MUCAdminPayload.h> #include <Swiften/Elements/MUCPayload.h> #include <Swiften/Elements/MUCDestroyPayload.h> +#include <Swiften/Elements/MUCInvitationPayload.h> #include <Swiften/MUC/MUCRegistry.h> #include <Swiften/Queries/GenericRequest.h> @@ -286,6 +287,17 @@ void MUC::destroyRoom() { request->send(); } +void MUC::invitePerson(const JID& person, const std::string& reason) { + Message::ref message = boost::make_shared<Message>(); + message->setTo(person); + message->setType(Message::Normal); + MUCInvitationPayload::ref invite = boost::make_shared<MUCInvitationPayload>(); + invite->setReason(reason); + invite->setJID(ownMUCJID.toBare()); + message->addPayload(invite); + stanzaChannel->sendMessage(message); +} + //TODO: Invites(direct/mediated) //TODO: requesting membership diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h index b99c4b4..45b8004 100644 --- a/Swiften/MUC/MUC.h +++ b/Swiften/MUC/MUC.h @@ -61,6 +61,8 @@ namespace Swift { void requestConfigurationForm(); void configureRoom(Form::ref); void destroyRoom(); + /** Send an invite for the person to join the MUC */ + void invitePerson(const JID& person, const std::string& reason = ""); public: boost::signal<void (const std::string& /*nick*/)> onJoinComplete; boost::signal<void (ErrorPayload::ref)> onJoinFailed; diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 9865a1e..86ea1c6 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -47,6 +47,7 @@ #include <Swiften/Parser/PayloadParsers/MUCAdminPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCDestroyPayloadParser.h> +#include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> #include <Swiften/Parser/PayloadParsers/MUCOwnerPayloadParserFactory.h> #include <Swiften/Parser/PayloadParsers/NicknameParser.h> #include <Swiften/Parser/PayloadParsers/ReplaceParser.h> @@ -105,6 +106,10 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared<ChatStateParserFactory>()); factories_.push_back(boost::make_shared<MUCUserPayloadParserFactory>(this)); factories_.push_back(boost::make_shared<MUCOwnerPayloadParserFactory>(this)); + factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCAdminPayloadParser>("query", "http://jabber.org/protocol/muc#admin"))); + factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCInvitationPayloadParser>("x", "jabber:x:conference"))); + factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCDestroyPayloadParser>("destroy", "http://jabber.org/protocol/muc#user"))); + factories_.push_back(shared_ptr<PayloadParserFactory>(new GenericPayloadParserFactory<MUCDestroyPayloadParser>("destroy", "http://jabber.org/protocol/muc#owner"))); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCAdminPayloadParser> >("query", "http://jabber.org/protocol/muc#admin")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#user")); factories_.push_back(boost::make_shared<GenericPayloadParserFactory<MUCDestroyPayloadParser> >("destroy", "http://jabber.org/protocol/muc#owner")); diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp new file mode 100644 index 0000000..fa95af7 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h> + + + +namespace Swift { + +void MUCInvitationPayloadParser::handleTree(ParserElement::ref root) { + MUCInvitationPayload::ref invite = getPayloadInternal(); + invite->setIsContinuation(root->getAttributes().getBoolAttribute("continue", false)); + invite->setJID(JID(root->getAttributes().getAttribute("jid"))); + invite->setPassword(root->getAttributes().getAttribute("password")); + invite->setReason(root->getAttributes().getAttribute("reason")); + invite->setThread(root->getAttributes().getAttribute("thread")); +} + +} diff --git a/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h new file mode 100644 index 0000000..2cd3535 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/MUCInvitationPayloadParser.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Elements/MUCInvitationPayload.h> +#include <Swiften/Parser/GenericPayloadTreeParser.h> + +namespace Swift { + class MUCInvitationPayloadParser : public GenericPayloadTreeParser<MUCInvitationPayload> { + public: + virtual void handleTree(ParserElement::ref root); + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index 1cef02c..e1ec1d8 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -64,6 +64,7 @@ sources = [ "PayloadParsers/MUCAdminPayloadParser.cpp", "PayloadParsers/MUCOwnerPayloadParser.cpp", "PayloadParsers/MUCDestroyPayloadParser.cpp", + "PayloadParsers/MUCInvitationPayloadParser.cpp", "PayloadParsers/MUCItemParser.cpp", "PayloadParsers/NicknameParser.cpp", "PayloadParsers/ReplaceParser.cpp", diff --git a/Swiften/SConscript b/Swiften/SConscript index e650e2a..6d85d84 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -151,6 +151,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/MUCAdminPayloadSerializer.cpp", "Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp", "Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.cpp", + "Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.cpp", "Serializer/PayloadSerializers/ResourceBindSerializer.cpp", "Serializer/PayloadSerializers/RosterItemExchangeSerializer.cpp", "Serializer/PayloadSerializers/RosterSerializer.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index f3e22d2..87dfbc3 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -24,6 +24,7 @@ #include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h> #include <Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h> #include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h> #include <Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h> #include <Swiften/Serializer/PayloadSerializers/StatusSerializer.h> #include <Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h> @@ -74,6 +75,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new MUCPayloadSerializer()); serializers_.push_back(new MUCDestroyPayloadSerializer()); serializers_.push_back(new MUCAdminPayloadSerializer()); + serializers_.push_back(new MUCInvitationPayloadSerializer()); serializers_.push_back(new MUCOwnerPayloadSerializer(this)); serializers_.push_back(new MUCUserPayloadSerializer(this)); serializers_.push_back(new SoftwareVersionSerializer()); diff --git a/Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.cpp new file mode 100644 index 0000000..24e30e6 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> +#include <Swiften/Serializer/PayloadSerializers/MUCItemSerializer.h> + + +namespace Swift { + +MUCInvitationPayloadSerializer::MUCInvitationPayloadSerializer() : GenericPayloadSerializer<MUCInvitationPayload>() { +} + +std::string MUCInvitationPayloadSerializer::serializePayload(boost::shared_ptr<MUCInvitationPayload> payload) const { + XMLElement mucElement("x", "jabber:x:conference"); + if (payload->getIsContinuation()) { + mucElement.setAttribute("continue", "true"); + } + if (payload->getJID().isValid()) { + mucElement.setAttribute("jid", payload->getJID().toString()); + } + if (!payload->getPassword().empty()) { + mucElement.setAttribute("password", payload->getPassword()); + } + if (!payload->getReason().empty()) { + mucElement.setAttribute("reason", payload->getReason()); + } + if (!payload->getThread().empty()) { + mucElement.setAttribute("thread", payload->getThread()); + } + return mucElement.serialize(); +} + + +} diff --git a/Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h new file mode 100644 index 0000000..e60d5ca --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <Swiften/Serializer/GenericPayloadSerializer.h> +#include <Swiften/Elements/MUCInvitationPayload.h> + +namespace Swift { + class MUCInvitationPayloadSerializer : public GenericPayloadSerializer<MUCInvitationPayload> { + public: + MUCInvitationPayloadSerializer(); + + virtual std::string serializePayload(boost::shared_ptr<MUCInvitationPayload> version) const; + }; +} + |