diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-31 09:12:51 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2014-08-10 10:29:59 (GMT) |
commit | cdc8e88963e2f12cf0a6398a4dd6bb787b456b46 (patch) | |
tree | 4f3593b4551e96cfa94a5c606c2388bf43f1a936 | |
parent | b3c5aaea2fe185378d340ad1cdfe7ef502c1ab24 (diff) | |
download | swift-contrib-cdc8e88963e2f12cf0a6398a4dd6bb787b456b46.zip swift-contrib-cdc8e88963e2f12cf0a6398a4dd6bb787b456b46.tar.bz2 |
Fix blocklist not being requested on reconnect.
Test-Information:
Connect client and confirm that blocklist is requested only once. Reconnect client and confirm that blocklist is requested again.
Change-Id: Iebf38c9f3c1ff9749c239b6cf785feb7a539a9b1
-rw-r--r-- | Swift/Controllers/Roster/RosterController.cpp | 2 | ||||
-rw-r--r-- | Swiften/Client/ClientBlockListManager.cpp | 20 | ||||
-rw-r--r-- | Swiften/Client/ClientBlockListManager.h | 6 | ||||
-rw-r--r-- | Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp | 2 |
4 files changed, 19 insertions, 11 deletions
diff --git a/Swift/Controllers/Roster/RosterController.cpp b/Swift/Controllers/Roster/RosterController.cpp index e823a1c..43623d5 100644 --- a/Swift/Controllers/Roster/RosterController.cpp +++ b/Swift/Controllers/Roster/RosterController.cpp @@ -255,71 +255,71 @@ void RosterController::handleUIEvent(boost::shared_ptr<UIEvent> event) { foreach(XMPPRosterItem& item, items) { std::vector<std::string> groups = item.getGroups(); if ( (group.empty() && groups.empty()) || std::find(groups.begin(), groups.end(), group) != groups.end()) { groups.erase(std::remove(groups.begin(), groups.end(), group), groups.end()); if (std::find(groups.begin(), groups.end(), renameGroupEvent->getNewName()) == groups.end()) { groups.push_back(renameGroupEvent->getNewName()); } item.setGroups(groups); updateItem(item); } } } else if (boost::shared_ptr<SendFileUIEvent> sendFileEvent = boost::dynamic_pointer_cast<SendFileUIEvent>(event)) { //TODO add send file dialog to ChatView of receipient jid ftOverview_->sendFile(sendFileEvent->getJID(), sendFileEvent->getFilename()); } } void RosterController::setContactGroups(const JID& jid, const std::vector<std::string>& groups) { updateItem(XMPPRosterItem(jid, xmppRoster_->getNameForJID(jid), groups, xmppRoster_->getSubscriptionStateForJID(jid))); } void RosterController::updateItem(const XMPPRosterItem& item) { RosterItemPayload itemPayload(item.getJID(), item.getName(), item.getSubscription()); itemPayload.setGroups(item.getGroups()); RosterPayload::ref roster = boost::make_shared<RosterPayload>(); roster->addItem(itemPayload); SetRosterRequest::ref request = SetRosterRequest::create(roster, iqRouter_); request->onResponse.connect(boost::bind(&RosterController::handleRosterItemUpdated, this, _1, roster)); request->send(); } void RosterController::initBlockingCommand() { - boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList(); + boost::shared_ptr<BlockList> blockList = clientBlockListManager_->requestBlockList(); blockingOnStateChangedConnection_ = blockList->onStateChanged.connect(boost::bind(&RosterController::handleBlockingStateChanged, this)); blockingOnItemAddedConnection_ = blockList->onItemAdded.connect(boost::bind(&RosterController::handleBlockingItemAdded, this, _1)); blockingOnItemRemovedConnection_ = blockList->onItemRemoved.connect(boost::bind(&RosterController::handleBlockingItemRemoved, this, _1)); roster_->setBlockingSupported(true); if (blockList->getState() == BlockList::Available) { foreach(const JID& jid, blockList->getItems()) { roster_->applyOnItems(SetBlockingState(jid, ContactRosterItem::IsBlocked)); } } } void RosterController::handleRosterItemUpdated(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload) { if (!!error) { handleRosterSetError(error, rosterPayload); } boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList(); std::vector<RosterItemPayload> items = rosterPayload->getItems(); if (blockList->getState() == BlockList::Available && items.size() > 0) { std::vector<JID> jids = blockList->getItems(); if (std::find(jids.begin(), jids.end(), items[0].getJID()) != jids.end()) { roster_->applyOnItems(SetBlockingState(items[0].getJID(), ContactRosterItem::IsBlocked)); } } } void RosterController::handleRosterSetError(ErrorPayload::ref error, boost::shared_ptr<RosterPayload> rosterPayload) { if (!error) { return; } std::string text = str(format(QT_TRANSLATE_NOOP("", "Server %1% rejected contact list change to item '%2%'")) % myJID_.getDomain() % rosterPayload->getItems()[0].getJID().toString()); if (!error->getText().empty()) { text += ": " + error->getText(); } boost::shared_ptr<ErrorEvent> errorEvent(new ErrorEvent(JID(myJID_.getDomain()), text)); diff --git a/Swiften/Client/ClientBlockListManager.cpp b/Swiften/Client/ClientBlockListManager.cpp index 6646a5c..d446315 100644 --- a/Swiften/Client/ClientBlockListManager.cpp +++ b/Swiften/Client/ClientBlockListManager.cpp @@ -42,84 +42,88 @@ namespace { UnblockResponder(boost::shared_ptr<BlockListImpl> blockList, IQRouter* iqRouter) : SetResponder<UnblockPayload>(iqRouter), blockList(blockList) { } virtual bool handleSetRequest(const JID& from, const JID&, const std::string& id, boost::shared_ptr<UnblockPayload> payload) { if (getIQRouter()->isAccountJID(from)) { if (payload) { if (payload->getItems().empty()) { blockList->removeAllItems(); } else { blockList->removeItems(payload->getItems()); } } sendResponse(from, id, boost::shared_ptr<UnblockPayload>()); } else { sendError(from, id, ErrorPayload::NotAuthorized, ErrorPayload::Cancel); } return true; } private: boost::shared_ptr<BlockListImpl> blockList; }; } ClientBlockListManager::ClientBlockListManager(IQRouter* iqRouter) : iqRouter(iqRouter) { } ClientBlockListManager::~ClientBlockListManager() { if (blockList && blockList->getState() == BlockList::Available) { unblockResponder->stop(); blockResponder->stop(); } - if (getRequest) { - getRequest->onResponse.disconnect(boost::bind(&ClientBlockListManager::handleBlockListReceived, this, _1, _2)); - } } boost::shared_ptr<BlockList> ClientBlockListManager::getBlockList() { if (!blockList) { blockList = boost::make_shared<BlockListImpl>(); - blockList->setState(BlockList::Requesting); - assert(!getRequest); - getRequest = boost::make_shared< GenericRequest<BlockListPayload> >(IQ::Get, JID(), boost::make_shared<BlockListPayload>(), iqRouter); - getRequest->onResponse.connect(boost::bind(&ClientBlockListManager::handleBlockListReceived, this, _1, _2)); - getRequest->send(); + blockList->setState(BlockList::Init); + } + return blockList; +} + +boost::shared_ptr<BlockList> ClientBlockListManager::requestBlockList() { + if (!blockList) { + blockList = boost::make_shared<BlockListImpl>(); } + blockList->setState(BlockList::Requesting); + boost::shared_ptr<GenericRequest<BlockListPayload> > getRequest = boost::make_shared< GenericRequest<BlockListPayload> >(IQ::Get, JID(), boost::make_shared<BlockListPayload>(), iqRouter); + getRequest->onResponse.connect(boost::bind(&ClientBlockListManager::handleBlockListReceived, this, _1, _2)); + getRequest->send(); return blockList; } GenericRequest<BlockPayload>::ref ClientBlockListManager::createBlockJIDRequest(const JID& jid) { return createBlockJIDsRequest(std::vector<JID>(1, jid)); } GenericRequest<BlockPayload>::ref ClientBlockListManager::createBlockJIDsRequest(const std::vector<JID>& jids) { boost::shared_ptr<BlockPayload> payload = boost::make_shared<BlockPayload>(jids); return boost::make_shared< GenericRequest<BlockPayload> >(IQ::Set, JID(), payload, iqRouter); } GenericRequest<UnblockPayload>::ref ClientBlockListManager::createUnblockJIDRequest(const JID& jid) { return createUnblockJIDsRequest(std::vector<JID>(1, jid)); } GenericRequest<UnblockPayload>::ref ClientBlockListManager::createUnblockJIDsRequest(const std::vector<JID>& jids) { boost::shared_ptr<UnblockPayload> payload = boost::make_shared<UnblockPayload>(jids); return boost::make_shared< GenericRequest<UnblockPayload> >(IQ::Set, JID(), payload, iqRouter); } GenericRequest<UnblockPayload>::ref ClientBlockListManager::createUnblockAllRequest() { return createUnblockJIDsRequest(std::vector<JID>()); } void ClientBlockListManager::handleBlockListReceived(boost::shared_ptr<BlockListPayload> payload, ErrorPayload::ref error) { if (error || !payload) { blockList->setState(BlockList::Error); } else { blockList->setItems(payload->getItems()); blockList->setState(BlockList::Available); blockResponder = boost::make_shared<BlockResponder>(blockList, iqRouter); blockResponder->start(); diff --git a/Swiften/Client/ClientBlockListManager.h b/Swiften/Client/ClientBlockListManager.h index e8d4ac6..e715737 100644 --- a/Swiften/Client/ClientBlockListManager.h +++ b/Swiften/Client/ClientBlockListManager.h @@ -1,52 +1,56 @@ /* * Copyright (c) 2011 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <boost/shared_ptr.hpp> #include <Swiften/Base/boost_bsignals.h> #include <Swiften/Elements/BlockPayload.h> #include <Swiften/Elements/BlockListPayload.h> #include <Swiften/Elements/UnblockPayload.h> #include <Swiften/Elements/DiscoInfo.h> #include <Swiften/Queries/SetResponder.h> #include <Swiften/Queries/GenericRequest.h> #include <Swiften/Client/BlockList.h> #include <Swiften/Client/BlockListImpl.h> namespace Swift { class IQRouter; class ClientBlockListManager { public: ClientBlockListManager(IQRouter *iqRouter); ~ClientBlockListManager(); /** * Returns the blocklist. */ boost::shared_ptr<BlockList> getBlockList(); + /** + * Get the blocklist from the server. + */ + boost::shared_ptr<BlockList> requestBlockList(); + GenericRequest<BlockPayload>::ref createBlockJIDRequest(const JID& jid); GenericRequest<BlockPayload>::ref createBlockJIDsRequest(const std::vector<JID>& jids); GenericRequest<UnblockPayload>::ref createUnblockJIDRequest(const JID& jid); GenericRequest<UnblockPayload>::ref createUnblockJIDsRequest(const std::vector<JID>& jids); GenericRequest<UnblockPayload>::ref createUnblockAllRequest(); private: void handleBlockListReceived(boost::shared_ptr<BlockListPayload> payload, ErrorPayload::ref); private: IQRouter* iqRouter; - boost::shared_ptr<GenericRequest<BlockListPayload> > getRequest; boost::shared_ptr<SetResponder<BlockPayload> > blockResponder; boost::shared_ptr<SetResponder<UnblockPayload> > unblockResponder; boost::shared_ptr<BlockListImpl> blockList; }; } diff --git a/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp b/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp index 9010042..dd6c95d 100644 --- a/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp +++ b/Swiften/Client/UnitTest/ClientBlockListManagerTest.cpp @@ -120,71 +120,71 @@ class ClientBlockListManagerTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), clientBlockListManager_->getBlockList()->getItems().size()); CPPUNIT_ASSERT_EQUAL(BlockList::Available, clientBlockListManager_->getBlockList()->getState()); GenericRequest<UnblockPayload>::ref unblockRequest = clientBlockListManager_->createUnblockAllRequest(); unblockRequest->send(); IQ::ref request = stanzaChannel_->getStanzaAtIndex<IQ>(2); CPPUNIT_ASSERT(request.get() != NULL); boost::shared_ptr<UnblockPayload> unblockPayload = request->getPayload<UnblockPayload>(); CPPUNIT_ASSERT(unblockPayload.get() != NULL); CPPUNIT_ASSERT_EQUAL(true, unblockPayload->getItems().empty()); IQ::ref unblockRequestResponse = IQ::createResult(request->getFrom(), JID(), request->getID()); stanzaChannel_->sendIQ(unblockRequestResponse); stanzaChannel_->onIQReceived(unblockRequestResponse); CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), clientBlockListManager_->getBlockList()->getItems().size()); // send block push boost::shared_ptr<UnblockPayload> pushPayload = boost::make_shared<UnblockPayload>(); IQ::ref unblockPush = IQ::createRequest(IQ::Set, ownJID_, "push1", pushPayload); stanzaChannel_->sendIQ(unblockPush); stanzaChannel_->onIQReceived(unblockPush); CPPUNIT_ASSERT_EQUAL(true, clientBlockListManager_->getBlockList()->getItems().empty()); } void tearDown() { delete clientBlockListManager_; delete iqRouter_; delete stanzaChannel_; } private: void helperInitialBlockListFetch(const std::vector<JID>& blockedJids) { - boost::shared_ptr<BlockList> blockList = clientBlockListManager_->getBlockList(); + boost::shared_ptr<BlockList> blockList = clientBlockListManager_->requestBlockList(); CPPUNIT_ASSERT(blockList); // check for IQ request IQ::ref request = stanzaChannel_->getStanzaAtIndex<IQ>(0); CPPUNIT_ASSERT(request.get() != NULL); boost::shared_ptr<BlockListPayload> requestPayload = request->getPayload<BlockListPayload>(); CPPUNIT_ASSERT(requestPayload.get() != NULL); CPPUNIT_ASSERT_EQUAL(BlockList::Requesting, blockList->getState()); CPPUNIT_ASSERT_EQUAL(BlockList::Requesting, clientBlockListManager_->getBlockList()->getState()); // build IQ response boost::shared_ptr<BlockListPayload> responsePayload = boost::make_shared<BlockListPayload>(); foreach(const JID& jid, blockedJids) { responsePayload->addItem(jid); } IQ::ref response = IQ::createResult(ownJID_, JID(), request->getID(), responsePayload); stanzaChannel_->sendIQ(response); stanzaChannel_->onIQReceived(response); CPPUNIT_ASSERT_EQUAL(BlockList::Available, clientBlockListManager_->getBlockList()->getState()); CPPUNIT_ASSERT(responsePayload->getItems() == clientBlockListManager_->getBlockList()->getItems()); } private: JID ownJID_; IQRouter* iqRouter_; DummyStanzaChannel* stanzaChannel_; ClientBlockListManager* clientBlockListManager_; }; CPPUNIT_TEST_SUITE_REGISTRATION(ClientBlockListManagerTest); |