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 /Swiften/Client/ClientBlockListManager.cpp | |
| 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
Diffstat (limited to 'Swiften/Client/ClientBlockListManager.cpp')
| -rw-r--r-- | Swiften/Client/ClientBlockListManager.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
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(); |
Swift