summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Client/BlockListImpl.cpp')
-rw-r--r--Swiften/Client/BlockListImpl.cpp76
1 files changed, 38 insertions, 38 deletions
diff --git a/Swiften/Client/BlockListImpl.cpp b/Swiften/Client/BlockListImpl.cpp
index 5950233..54dcdf5 100644
--- a/Swiften/Client/BlockListImpl.cpp
+++ b/Swiften/Client/BlockListImpl.cpp
@@ -1,13 +1,11 @@
/*
- * Copyright (c) 2011 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
+ * Copyright (c) 2011-2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
*/
#include <Swiften/Client/BlockListImpl.h>
-#include <Swiften/Base/foreach.h>
-
#include <algorithm>
using namespace Swift;
@@ -16,57 +14,59 @@ BlockListImpl::BlockListImpl() : state(Init) {
}
-void BlockListImpl::setItems(const std::vector<JID>& items) {
- foreach (const JID& jid, this->items) {
- if (std::find(items.begin(), items.end(), jid) != items.end()) {
- onItemRemoved(jid);
- }
- }
+void BlockListImpl::setItems(const std::vector<JID>& newItems) {
+ // JIDs which are in the current list but not in the new list, are removed.
+ for (const auto& jid : items) {
+ if (std::find(newItems.begin(), newItems.end(), jid) == newItems.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;
+ // JIDs which are in the new list but not in the current list, are added.
+ for (const auto& jid : newItems) {
+ if (std::find(items.begin(), items.end(), jid) == items.end()) {
+ onItemAdded(jid);
+ }
+ }
+ items = newItems;
}
void BlockListImpl::addItem(const JID& item) {
- if (std::find(items.begin(), items.end(), item) == items.end()) {
- items.push_back(item);
- onItemAdded(item);
- }
+ if (std::find(items.begin(), items.end(), item) == items.end()) {
+ items.push_back(item);
+ onItemAdded(item);
+ }
}
void BlockListImpl::removeItem(const JID& item) {
- size_t oldSize = items.size();
- items.erase(std::remove(items.begin(), items.end(), item), items.end());
- if (items.size() != oldSize) {
- onItemRemoved(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();
- }
+ if (this->state != state) {
+ this->state = state;
+ onStateChanged();
+ }
}
void BlockListImpl::addItems(const std::vector<JID>& items) {
- foreach (const JID& item, items) {
- addItem(item);
- }
+ for (const auto& item : items) {
+ addItem(item);
+ }
}
void BlockListImpl::removeItems(const std::vector<JID>& items) {
- std::vector<JID> itemsToRemove = items;
- foreach (const JID& item, itemsToRemove) {
- removeItem(item);
- }
+ std::vector<JID> itemsToRemove = items;
+ for (const auto& item : itemsToRemove) {
+ removeItem(item);
+ }
}
void BlockListImpl::removeAllItems() {
- removeItems(items);
+ removeItems(items);
}