summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2010-11-15 13:15:15 (GMT)
committerKevin Smith <git@kismith.co.uk>2010-11-15 13:15:15 (GMT)
commit0c6c79df29c58ff8790941ea40d40f84fae773c6 (patch)
tree0e7c99f5a8ad8ec286e89f1a69630d6de468ec30 /Swiften
parent004677623739ef53ae9f565d3ffd4d2b02a65d5a (diff)
downloadswift-contrib-0c6c79df29c58ff8790941ea40d40f84fae773c6.zip
swift-contrib-0c6c79df29c58ff8790941ea40d40f84fae773c6.tar.bz2
Clean MUC joins slightly.
In an attempt to catch errors, this doesn't Resolves: #691 but does add an assert that may help. It also fixes an error with created rooms not receiving updates presences. Release-Notes: Newly-created rooms will now receive your presence updates, consistent with existing rooms.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Elements/ErrorPayload.h4
-rw-r--r--Swiften/MUC/MUC.cpp19
-rw-r--r--Swiften/MUC/MUC.h2
3 files changed, 22 insertions, 3 deletions
diff --git a/Swiften/Elements/ErrorPayload.h b/Swiften/Elements/ErrorPayload.h
index 8c74f0c..fab398e 100644
--- a/Swiften/Elements/ErrorPayload.h
+++ b/Swiften/Elements/ErrorPayload.h
@@ -41,6 +41,10 @@ namespace Swift {
ErrorPayload(Condition condition = UndefinedCondition, Type type = Cancel, const String& text = String()) : type_(type), condition_(condition), text_(text) { }
+ ErrorPayload(const ErrorPayload& other) : type_(other.getType()), condition_(other.getCondition()), text_(other.getText()) {
+
+ }
+
Type getType() const {
return type_;
}
diff --git a/Swiften/MUC/MUC.cpp b/Swiften/MUC/MUC.cpp
index b0365d4..86c8ca9 100644
--- a/Swiften/MUC/MUC.cpp
+++ b/Swiften/MUC/MUC.cpp
@@ -15,9 +15,9 @@
#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"
#include "Swiften/MUC/MUCRegistry.h"
+#include "Swiften/Queries/GenericRequest.h"
namespace Swift {
@@ -44,6 +44,7 @@ void MUC::internalJoin(const String &nick) {
joinComplete_ = false;
ownMUCJID = JID(ownMUCJID.getNode(), ownMUCJID.getDomain(), nick);
boost::shared_ptr<Presence> joinPresence(presenceSender->getLastSentUndirectedPresence());
+ assert(joinPresence->getType() == Presence::Available);
joinPresence->setTo(ownMUCJID);
boost::shared_ptr<MUCPayload> mucPayload(new MUCPayload());
if (joinSince_ != boost::posix_time::not_a_date_time) {
@@ -162,16 +163,28 @@ void MUC::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
if (status.code == 201) {
/* Room is created and locked */
/* Currently deal with this by making an instant room */
+ ownMUCJID = presence->getFrom();
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, getJID(), iqRouter_->getNewIQID(), mucPayload));
- iqRouter_->sendIQ(iq);
+ GenericRequest<MUCOwnerPayload>* request = new GenericRequest<MUCOwnerPayload>(IQ::Set, getJID(), mucPayload, iqRouter_);
+ request->onResponse.connect(boost::bind(&MUC::handleCreationConfigResponse, this, _1, _2));
+ request->send();
}
}
}
}
+void MUC::handleCreationConfigResponse(boost::shared_ptr<MUCOwnerPayload> /*unused*/, const boost::optional<ErrorPayload>& error) {
+ if (error) {
+ boost::shared_ptr<ErrorPayload> errorCopy(new ErrorPayload(*error));
+ onJoinFailed(errorCopy);
+ } else {
+ /* onJoinComplete(getOwnNick()); isn't needed here, the presence will cause an emit elsewhere. */
+ presenceSender->addDirectedPresenceReceiver(ownMUCJID);
+ }
+}
+
//FIXME: Recognise Topic changes
//TODO: Invites(direct/mediated)
diff --git a/Swiften/MUC/MUC.h b/Swiften/MUC/MUC.h
index 672cdf2..3539e49 100644
--- a/Swiften/MUC/MUC.h
+++ b/Swiften/MUC/MUC.h
@@ -12,6 +12,7 @@
#include "Swiften/Elements/Presence.h"
#include "Swiften/MUC/MUCOccupant.h"
#include "Swiften/MUC/MUCRegistry.h"
+#include "Swiften/Elements/MUCOwnerPayload.h"
#include <boost/shared_ptr.hpp>
#include "Swiften/Base/boost_bsignals.h"
@@ -75,6 +76,7 @@ namespace Swift {
private:
void handleIncomingPresence(boost::shared_ptr<Presence> presence);
void internalJoin(const String& nick);
+ void handleCreationConfigResponse(boost::shared_ptr<MUCOwnerPayload>, const boost::optional<ErrorPayload>&);
private:
JID ownMUCJID;