summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-09-13 21:18:44 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-09-13 21:26:44 (GMT)
commit6efbed866f78e0bdd685817d9ed80405a2bf55d7 (patch)
tree99edb5ecd8ea715f8a52579b7b7fb6627ced1d84
parent30c3130def563b76c18f6bc91bd527ef1ba092be (diff)
downloadswift-6efbed866f78e0bdd685817d9ed80405a2bf55d7.zip
swift-6efbed866f78e0bdd685817d9ed80405a2bf55d7.tar.bz2
When joining a new room, create an instant room.
Resolves: #112
-rw-r--r--Swift/Controllers/Chat/MUCController.cpp2
-rw-r--r--Swiften/Elements/MUCOwnerPayload.h30
-rw-r--r--Swiften/MUC/MUC.cpp13
-rw-r--r--Swiften/MUC/MUC.h5
-rw-r--r--Swiften/SConscript1
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp3
-rw-r--r--Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.cpp30
-rw-r--r--Swiften/Serializer/PayloadSerializers/MUCOwnerPayloadSerializer.h22
8 files changed, 103 insertions, 3 deletions
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 <boost/optional.hpp>
+
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class MUCOwnerPayload : public Payload {
+ public:
+ MUCOwnerPayload() {
+ }
+
+ boost::shared_ptr<Payload> getPayload() const {
+ return payload;
+ }
+
+ void setPayload(boost::shared_ptr<Payload> p) {
+ payload = p;
+ }
+
+ private:
+ boost::shared_ptr<Payload> 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<String, MUCOccupant> 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> 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<MUCOwnerPayload> mucPayload(new MUCOwnerPayload());
+ mucPayload->setPayload(boost::shared_ptr<Payload>(new Form(Form::SubmitType)));
+ boost::shared_ptr<IQ> 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<String, MUCOccupant> 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<MUCOwnerPayload>(), serializers(serializers) {
+}
+
+String MUCOwnerPayloadSerializer::serializePayload(boost::shared_ptr<MUCOwnerPayload> mucOwner) const {
+ XMLElement mucElement("query", "http://jabber.org/protocol/muc#owner");
+ boost::shared_ptr<Payload> payload = mucOwner->getPayload();
+ if (payload) {
+ PayloadSerializer* serializer = serializers->getPayloadSerializer(payload);
+ if (serializer) {
+ mucElement.addNode(boost::shared_ptr<XMLRawTextNode>(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<MUCOwnerPayload> {
+ public:
+ MUCOwnerPayloadSerializer(PayloadSerializerCollection* serializers);
+ virtual String serializePayload(boost::shared_ptr<MUCOwnerPayload> version) const;
+ private:
+ PayloadSerializerCollection* serializers;
+ };
+}
+