From 6efbed866f78e0bdd685817d9ed80405a2bf55d7 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 13 Sep 2010 22:18:44 +0100 Subject: When joining a new room, create an instant room. Resolves: #112 diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index acef7ae..62e4e5e 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -48,7 +48,7 @@ MUCController::MUCController ( bool useDelayForLatency, TimerFactory* timerFactory, EventController* eventController) : - ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, muc, presenceOracle, avatarManager, useDelayForLatency, uiEventStream, eventController), muc_(new MUC(stanzaChannel, presenceSender, muc)), nick_(nick) { + ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, muc, presenceOracle, avatarManager, useDelayForLatency, uiEventStream, eventController), muc_(new MUC(stanzaChannel, iqRouter, presenceSender, muc)), nick_(nick) { parting_ = true; joined_ = false; lastWasPresence_ = false; diff --git a/Swiften/Elements/MUCOwnerPayload.h b/Swiften/Elements/MUCOwnerPayload.h new file mode 100644 index 0000000..c418cc6 --- /dev/null +++ b/Swiften/Elements/MUCOwnerPayload.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class MUCOwnerPayload : public Payload { + public: + MUCOwnerPayload() { + } + + boost::shared_ptr getPayload() const { + return payload; + } + + void setPayload(boost::shared_ptr p) { + payload = p; + } + + private: + boost::shared_ptr payload; + }; +} diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp index f4512a0..bcc9e6f 100644 --- a/Swiften/MUC/MUC.cpp +++ b/Swiften/MUC/MUC.cpp @@ -13,15 +13,18 @@ #include "Swiften/Presence/PresenceSender.h" #include "Swiften/Client/StanzaChannel.h" +#include "Swiften/Queries/IQRouter.h" +#include "Swiften/Elements/Form.h" #include "Swiften/Elements/IQ.h" #include "Swiften/Elements/MUCUserPayload.h" +#include "Swiften/Elements/MUCOwnerPayload.h" #include "Swiften/Elements/MUCPayload.h" namespace Swift { typedef std::pair StringMUCOccupantPair; -MUC::MUC(StanzaChannel* stanzaChannel, PresenceSender* presenceSender, const JID &muc) : ownMUCJID(muc), stanzaChannel(stanzaChannel), presenceSender(presenceSender) { +MUC::MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, PresenceSender* presenceSender, const JID &muc) : ownMUCJID(muc), stanzaChannel(stanzaChannel), iqRouter_(iqRouter), presenceSender(presenceSender), muc_(muc) { scopedConnection_ = stanzaChannel->onPresenceReceived.connect(boost::bind(&MUC::handleIncomingPresence, this, _1)); } @@ -134,6 +137,14 @@ void MUC::handleIncomingPresence(boost::shared_ptr presence) { onJoinComplete(getOwnNick()); presenceSender->addDirectedPresenceReceiver(ownMUCJID); } + if (status.code == 201) { + /* Room is created and locked */ + /* Currently deal with this by making an instant room */ + boost::shared_ptr mucPayload(new MUCOwnerPayload()); + mucPayload->setPayload(boost::shared_ptr(new Form(Form::SubmitType))); + boost::shared_ptr iq(IQ::createRequest(IQ::Set, muc_, iqRouter_->getNewIQID(), mucPayload)); + iqRouter_->sendIQ(iq); + } } } diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h index bccc26c..af3daa8 100644 --- a/Swiften/MUC/MUC.h +++ b/Swiften/MUC/MUC.h @@ -20,6 +20,7 @@ namespace Swift { class StanzaChannel; + class IQRouter; class PresenceSender; class MUC { @@ -28,7 +29,7 @@ namespace Swift { enum LeavingType { Part, Disconnect }; public: - MUC(StanzaChannel* stanzaChannel, PresenceSender* presenceSender, const JID &muc); + MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, PresenceSender* presenceSender, const JID &muc); void joinAs(const String &nick); /*void queryRoomInfo(); */ @@ -66,7 +67,9 @@ namespace Swift { private: JID ownMUCJID; StanzaChannel* stanzaChannel; + IQRouter* iqRouter_; PresenceSender* presenceSender; + JID muc_; std::map occupants; bool joinComplete_; boost::bsignals::scoped_connection scopedConnection_; diff --git a/Swiften/SConscript b/Swiften/SConscript index 83306b7..87afed9 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -74,6 +74,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp", "Serializer/PayloadSerializers/MUCPayloadSerializer.cpp", "Serializer/PayloadSerializers/MUCUserPayloadSerializer.cpp", + "Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp", "Serializer/PayloadSerializers/ResourceBindSerializer.cpp", "Serializer/PayloadSerializers/RosterSerializer.cpp", "Serializer/PayloadSerializers/SecurityLabelSerializer.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 275cbf1..d63c723 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -15,6 +15,7 @@ #include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h" #include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h" #include "Swiften/Serializer/PayloadSerializers/MUCUserPayloadSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h" #include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h" #include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h" #include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h" @@ -44,6 +45,8 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new ErrorSerializer()); serializers_.push_back(new RosterSerializer()); serializers_.push_back(new MUCPayloadSerializer()); + serializers_.push_back(new MUCUserPayloadSerializer()); + serializers_.push_back(new MUCOwnerPayloadSerializer(this)); serializers_.push_back(new SoftwareVersionSerializer()); serializers_.push_back(new StatusSerializer()); serializers_.push_back(new StatusShowSerializer()); diff --git a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp new file mode 100644 index 0000000..dbf79d4 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h" + +#include "Swiften/Serializer/PayloadSerializerCollection.h" +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" + +namespace Swift { + +MUCOwnerPayloadSerializer::MUCOwnerPayloadSerializer(PayloadSerializerCollection* serializers) : GenericPayloadSerializer(), serializers(serializers) { +} + +String MUCOwnerPayloadSerializer::serializePayload(boost::shared_ptr mucOwner) const { + XMLElement mucElement("query", "http://jabber.org/protocol/muc#owner"); + boost::shared_ptr payload = mucOwner->getPayload(); + if (payload) { + PayloadSerializer* serializer = serializers->getPayloadSerializer(payload); + if (serializer) { + mucElement.addNode(boost::shared_ptr(new XMLRawTextNode(serializer->serialize(payload)))); + } + } + return mucElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h new file mode 100644 index 0000000..862cfce --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010 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/MUCOwnerPayload.h" + +namespace Swift { + class PayloadSerializerCollection; + class MUCOwnerPayloadSerializer : public GenericPayloadSerializer { + public: + MUCOwnerPayloadSerializer(PayloadSerializerCollection* serializers); + virtual String serializePayload(boost::shared_ptr version) const; + private: + PayloadSerializerCollection* serializers; + }; +} + -- cgit v0.10.2-6-g49f6