From 9a34412bef9992d97d2d2094f5e42a3cc9470262 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Thu, 26 Apr 2012 11:33:06 +0100 Subject: Avoid duplicate subscription requests. Resolves: #1040 Resolves: #876 diff --git a/Swift/Controllers/EventWindowController.cpp b/Swift/Controllers/EventWindowController.cpp index 47554ce..32b9c76 100644 --- a/Swift/Controllers/EventWindowController.cpp +++ b/Swift/Controllers/EventWindowController.cpp @@ -1,11 +1,12 @@ /* - * 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/EventWindowController.h" +#include +#include #include namespace Swift { @@ -37,7 +38,14 @@ void EventWindowController::handleEventQueueEventAdded(boost::shared_ptr event) { window_->removeEvent(event); - window_->addEvent(event, false); + bool includeAsCompleted = true; + /* Because subscription requests get duplicated, don't add them back */ + if (boost::dynamic_pointer_cast(event)) { + includeAsCompleted = false; + } + if (includeAsCompleted) { + window_->addEvent(event, false); + } event->onConclusion.disconnect(boost::bind(&EventWindowController::handleEventConcluded, this, event)); } 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 #include #include #include -#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 +#include +#include +#include namespace Swift { @@ -31,6 +31,19 @@ void EventController::handleIncomingEvent(boost::shared_ptr sourceE boost::shared_ptr subscriptionEvent = boost::dynamic_pointer_cast(sourceEvent); boost::shared_ptr errorEvent = boost::dynamic_pointer_cast(sourceEvent); boost::shared_ptr mucInviteEvent = boost::dynamic_pointer_cast(sourceEvent); + + /* If it's a duplicate subscription request, remove the previous request first */ + if (subscriptionEvent) { + foreach(boost::shared_ptr existingEvent, events_) { + boost::shared_ptr existingSubscriptionEvent = boost::dynamic_pointer_cast(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)); -- cgit v0.10.2-6-g49f6