diff options
Diffstat (limited to 'Swiften/Client/ClientBlockListManager.cpp')
-rw-r--r-- | Swiften/Client/ClientBlockListManager.cpp | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/Swiften/Client/ClientBlockListManager.cpp b/Swiften/Client/ClientBlockListManager.cpp index 7222cea..de43631 100644 --- a/Swiften/Client/ClientBlockListManager.cpp +++ b/Swiften/Client/ClientBlockListManager.cpp @@ -67,11 +67,11 @@ namespace { 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)); } } @@ -80,13 +80,43 @@ boost::shared_ptr<BlockList> ClientBlockListManager::getBlockList() { if (!blockList) { blockList = boost::make_shared<BlockListImpl>(); + blockList->setState(BlockList::Init); + } + return blockList; +} + +boost::shared_ptr<BlockList> ClientBlockListManager::requestBlockList() { + 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); + 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) { @@ -94,11 +124,15 @@ void ClientBlockListManager::handleBlockListReceived(boost::shared_ptr<BlockList } else { - blockList->setState(BlockList::Available); blockList->setItems(payload->getItems()); + blockList->setState(BlockList::Available); + if (!blockResponder) { blockResponder = boost::make_shared<BlockResponder>(blockList, iqRouter); blockResponder->start(); + } + if (!unblockResponder) { unblockResponder = boost::make_shared<UnblockResponder>(blockList, iqRouter); unblockResponder->start(); } } +} |