diff options
author | Kevin Smith <git@kismith.co.uk> | 2012-04-26 10:33:06 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2012-04-26 10:33:06 (GMT) |
commit | 9a34412bef9992d97d2d2094f5e42a3cc9470262 (patch) | |
tree | c808937c48561eae29a88b5c9ddb7bf14890c916 /Swift/Controllers/XMPPEvents | |
parent | 4fc14f392e953ee2309312d9d8a07dc01303c838 (diff) | |
download | swift-9a34412bef9992d97d2d2094f5e42a3cc9470262.zip swift-9a34412bef9992d97d2d2094f5e42a3cc9470262.tar.bz2 |
Avoid duplicate subscription requests.
Resolves: #1040
Resolves: #876
Diffstat (limited to 'Swift/Controllers/XMPPEvents')
-rw-r--r-- | Swift/Controllers/XMPPEvents/EventController.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/Swift/Controllers/XMPPEvents/EventController.cpp b/Swift/Controllers/XMPPEvents/EventController.cpp index 0808aa0..9841923 100644 --- a/Swift/Controllers/XMPPEvents/EventController.cpp +++ b/Swift/Controllers/XMPPEvents/EventController.cpp @@ -1,19 +1,19 @@ /* - * Copyright (c) 2010 Kevin Smith + * Copyright (c) 2010-2012 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ -#include "Swift/Controllers/XMPPEvents/EventController.h" +#include <Swift/Controllers/XMPPEvents/EventController.h> #include <boost/bind.hpp> #include <algorithm> #include <Swiften/Base/foreach.h> -#include "Swift/Controllers/XMPPEvents/MessageEvent.h" -#include "Swift/Controllers/XMPPEvents/ErrorEvent.h" -#include "Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h" -#include "Swift/Controllers/XMPPEvents/MUCInviteEvent.h" +#include <Swift/Controllers/XMPPEvents/MessageEvent.h> +#include <Swift/Controllers/XMPPEvents/ErrorEvent.h> +#include <Swift/Controllers/XMPPEvents/SubscriptionRequestEvent.h> +#include <Swift/Controllers/XMPPEvents/MUCInviteEvent.h> namespace Swift { @@ -31,6 +31,19 @@ void EventController::handleIncomingEvent(boost::shared_ptr<StanzaEvent> sourceE boost::shared_ptr<SubscriptionRequestEvent> subscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(sourceEvent); boost::shared_ptr<ErrorEvent> errorEvent = boost::dynamic_pointer_cast<ErrorEvent>(sourceEvent); boost::shared_ptr<MUCInviteEvent> mucInviteEvent = boost::dynamic_pointer_cast<MUCInviteEvent>(sourceEvent); + + /* If it's a duplicate subscription request, remove the previous request first */ + if (subscriptionEvent) { + foreach(boost::shared_ptr<StanzaEvent> existingEvent, events_) { + boost::shared_ptr<SubscriptionRequestEvent> existingSubscriptionEvent = boost::dynamic_pointer_cast<SubscriptionRequestEvent>(existingEvent); + if (existingSubscriptionEvent) { + if (existingSubscriptionEvent->getJID() == subscriptionEvent->getJID()) { + existingEvent->conclude(); + } + } + } + } + if ((messageEvent && messageEvent->isReadable()) || subscriptionEvent || errorEvent || mucInviteEvent) { events_.push_back(sourceEvent); sourceEvent->onConclusion.connect(boost::bind(&EventController::handleEventConcluded, this, sourceEvent)); |