summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-31 18:51:01 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-03 12:17:40 (GMT)
commitd509598b0f0edf5e103caedbab8662edc834445e (patch)
tree9365ef58175eee453f999c1c5b8515cb50cf90e0 /Swiften/MUC
parentbadcdcb7456d38016ea1746d6754a40dd9646813 (diff)
downloadswift-contrib-d509598b0f0edf5e103caedbab8662edc834445e.zip
swift-contrib-d509598b0f0edf5e103caedbab8662edc834445e.tar.bz2
Refactoring Presence & MUC handling.
Diffstat (limited to 'Swiften/MUC')
-rw-r--r--Swiften/MUC/MUC.cpp9
-rw-r--r--Swiften/MUC/MUC.h20
-rw-r--r--Swiften/MUC/MUCManager.cpp18
-rw-r--r--Swiften/MUC/MUCManager.h29
4 files changed, 68 insertions, 8 deletions
diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp
index cfd468c..9f7c500 100644
--- a/Swiften/MUC/MUC.cpp
+++ b/Swiften/MUC/MUC.cpp
@@ -9,7 +9,7 @@
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
-#include "Swiften/Presence/PresenceSender.h"
+#include "Swiften/Presence/DirectedPresenceSender.h"
#include "Swiften/Client/StanzaChannel.h"
#include "Swiften/Queries/IQRouter.h"
#include "Swiften/Elements/Form.h"
@@ -17,13 +17,15 @@
#include "Swiften/Elements/MUCUserPayload.h"
#include "Swiften/Elements/MUCOwnerPayload.h"
#include "Swiften/Elements/MUCPayload.h"
+#include "Swiften/MUC/MUCRegistry.h"
namespace Swift {
typedef std::pair<String, MUCOccupant> StringMUCOccupantPair;
-MUC::MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, PresenceSender* presenceSender, const JID &muc) : ownMUCJID(muc), stanzaChannel(stanzaChannel), iqRouter_(iqRouter), presenceSender(presenceSender), muc_(muc) {
+MUC::MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, const JID &muc, MUCRegistry* mucRegistry) : ownMUCJID(muc), stanzaChannel(stanzaChannel), iqRouter_(iqRouter), presenceSender(presenceSender), mucRegistry(mucRegistry) {
scopedConnection_ = stanzaChannel->onPresenceReceived.connect(boost::bind(&MUC::handleIncomingPresence, this, _1));
+ mucRegistry->addMUC(getJID());
}
//FIXME: discover reserved nickname
@@ -57,6 +59,7 @@ void MUC::joinWithContextSince(const String &nick) {
void MUC::part() {
presenceSender->removeDirectedPresenceReceiver(ownMUCJID);
+ mucRegistry->removeMUC(getJID());
}
void MUC::handleUserLeft(LeavingType type) {
@@ -157,7 +160,7 @@ void MUC::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
/* 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));
+ boost::shared_ptr<IQ> iq(IQ::createRequest(IQ::Set, getJID(), iqRouter_->getNewIQID(), mucPayload));
iqRouter_->sendIQ(iq);
}
}
diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h
index ea20ac4..29dbbe1 100644
--- a/Swiften/MUC/MUC.h
+++ b/Swiften/MUC/MUC.h
@@ -11,6 +11,7 @@
#include "Swiften/Elements/Message.h"
#include "Swiften/Elements/Presence.h"
#include "Swiften/MUC/MUCOccupant.h"
+#include "Swiften/MUC/MUCRegistry.h"
#include <boost/shared_ptr.hpp>
#include "Swiften/Base/boost_bsignals.h"
@@ -21,15 +22,24 @@
namespace Swift {
class StanzaChannel;
class IQRouter;
- class PresenceSender;
+ class DirectedPresenceSender;
class MUC {
public:
+ typedef boost::shared_ptr<MUC> ref;
+
enum JoinResult { JoinSucceeded, JoinFailed };
- enum LeavingType { Part, Disconnect };
+ enum LeavingType { Part, Disconnect };
public:
- MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, PresenceSender* presenceSender, const JID &muc);
+ MUC(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, const JID &muc, MUCRegistry* mucRegistry);
+
+ /**
+ * Returns the (bare) JID of the MUC.
+ */
+ JID getJID() const {
+ return ownMUCJID.toBare();
+ }
void joinAs(const String &nick);
void joinWithContextSince(const String &nick);
@@ -70,8 +80,8 @@ namespace Swift {
JID ownMUCJID;
StanzaChannel* stanzaChannel;
IQRouter* iqRouter_;
- PresenceSender* presenceSender;
- JID muc_;
+ DirectedPresenceSender* presenceSender;
+ MUCRegistry* mucRegistry;
std::map<String, MUCOccupant> occupants;
bool joinComplete_;
boost::bsignals::scoped_connection scopedConnection_;
diff --git a/Swiften/MUC/MUCManager.cpp b/Swiften/MUC/MUCManager.cpp
new file mode 100644
index 0000000..8950029
--- /dev/null
+++ b/Swiften/MUC/MUCManager.cpp
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swiften/MUC/MUCManager.h"
+
+namespace Swift {
+
+MUCManager::MUCManager(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, MUCRegistry* mucRegistry) : stanzaChannel(stanzaChannel), iqRouter(iqRouter), presenceSender(presenceSender), mucRegistry(mucRegistry) {
+}
+
+MUC::ref MUCManager::createMUC(const JID& jid) {
+ return MUC::ref(new MUC(stanzaChannel, iqRouter, presenceSender, jid, mucRegistry));
+}
+
+}
diff --git a/Swiften/MUC/MUCManager.h b/Swiften/MUC/MUCManager.h
new file mode 100644
index 0000000..0efdf9a
--- /dev/null
+++ b/Swiften/MUC/MUCManager.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include "Swiften/MUC/MUC.h"
+
+namespace Swift {
+ class IQRouter;
+ class StanzaChannel;
+ class DirectedPresenceSender;
+ class MUCRegistry;
+
+ class MUCManager {
+ public:
+ MUCManager(StanzaChannel* stanzaChannel, IQRouter* iqRouter, DirectedPresenceSender* presenceSender, MUCRegistry* mucRegistry);
+
+ MUC::ref createMUC(const JID&);
+
+ private:
+ StanzaChannel* stanzaChannel;
+ IQRouter* iqRouter;
+ DirectedPresenceSender* presenceSender;
+ MUCRegistry* mucRegistry;
+ };
+}