diff options
| author | Tobias Markmann <tm@ayena.de> | 2013-03-08 15:17:30 (GMT) | 
|---|---|---|
| committer | Tobias Markmann <tm@ayena.de> | 2013-03-27 14:12:26 (GMT) | 
| commit | 497b647fe034a3d2cdc6d75ce0ff70e3df3aaf04 (patch) | |
| tree | dc81e56199f54cf20f834c78bda7fc26ffbc38f9 /Swiften/Client/BlockListImpl.cpp | |
| parent | 20ead0a84fdd8c9e870e98ee6a2712bfa263d7fb (diff) | |
| download | swift-contrib-497b647fe034a3d2cdc6d75ce0ff70e3df3aaf04.zip swift-contrib-497b647fe034a3d2cdc6d75ce0ff70e3df3aaf04.tar.bz2 | |
Adding support for Blocking Command (XEP-0191) to Swift(-en).
Change-Id: I7c92518dc389474d520d4cf96f96a11459f73d26
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Diffstat (limited to 'Swiften/Client/BlockListImpl.cpp')
| -rw-r--r-- | Swiften/Client/BlockListImpl.cpp | 32 | 
1 files changed, 24 insertions, 8 deletions
| diff --git a/Swiften/Client/BlockListImpl.cpp b/Swiften/Client/BlockListImpl.cpp index dfaaaf1..5950233 100644 --- a/Swiften/Client/BlockListImpl.cpp +++ b/Swiften/Client/BlockListImpl.cpp @@ -8,30 +8,47 @@  #include <Swiften/Base/foreach.h> +#include <algorithm> +  using namespace Swift; -BlockListImpl::BlockListImpl() { +BlockListImpl::BlockListImpl() : state(Init) {  }  void BlockListImpl::setItems(const std::vector<JID>& items) { -	this->items = std::set<JID>(items.begin(), items.end()); +	foreach (const JID& jid, this->items) { +		if (std::find(items.begin(), items.end(), jid) != items.end()) { +			onItemRemoved(jid); +		} +	} + +	foreach (const JID& jid, items) { +		if (std::find(this->items.begin(), this->items.end(), jid) != this->items.end()) { +			onItemAdded(jid); +		} +	} +	this->items = items;  }  void BlockListImpl::addItem(const JID& item) { -	if (items.insert(item).second) { +	if (std::find(items.begin(), items.end(), item) == items.end()) { +		items.push_back(item);  		onItemAdded(item);  	}  }  void BlockListImpl::removeItem(const JID& item) { -	if (items.erase(item)) { +	size_t oldSize = items.size(); +	items.erase(std::remove(items.begin(), items.end(), item), items.end()); +	if (items.size() != oldSize) {  		onItemRemoved(item);  	}  }  void BlockListImpl::setState(State state) {  	if (this->state != state) { +		this->state = state;  		onStateChanged();  	}  } @@ -43,14 +60,13 @@ void BlockListImpl::addItems(const std::vector<JID>& items) {  }  void BlockListImpl::removeItems(const std::vector<JID>& items) { -	foreach (const JID& item, items) { +	std::vector<JID> itemsToRemove = items; +	foreach (const JID& item, itemsToRemove) {  		removeItem(item);  	}  }  void BlockListImpl::removeAllItems() { -	foreach (const JID& item, items) { -		removeItem(item); -	} +	removeItems(items);  } | 
 Swift
 Swift