diff options
Diffstat (limited to 'Swiften/Client/BlockListImpl.cpp')
| -rw-r--r-- | Swiften/Client/BlockListImpl.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Swiften/Client/BlockListImpl.cpp b/Swiften/Client/BlockListImpl.cpp index 02c1c18..4abaa37 100644 --- a/Swiften/Client/BlockListImpl.cpp +++ b/Swiften/Client/BlockListImpl.cpp | |||
| @@ -1,36 +1,38 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2011 Isode Limited. | 2 | * Copyright (c) 2011-2015 Isode Limited. |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * See the COPYING file for more information. | 4 | * See the COPYING file for more information. |
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | #include <Swiften/Client/BlockListImpl.h> | 7 | #include <Swiften/Client/BlockListImpl.h> |
| 8 | 8 | ||
| 9 | #include <Swiften/Base/foreach.h> | ||
| 10 | |||
| 11 | #include <algorithm> | 9 | #include <algorithm> |
| 12 | 10 | ||
| 11 | #include <Swiften/Base/foreach.h> | ||
| 12 | |||
| 13 | using namespace Swift; | 13 | using namespace Swift; |
| 14 | 14 | ||
| 15 | BlockListImpl::BlockListImpl() : state(Init) { | 15 | BlockListImpl::BlockListImpl() : state(Init) { |
| 16 | 16 | ||
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | void BlockListImpl::setItems(const std::vector<JID>& items) { | 19 | void BlockListImpl::setItems(const std::vector<JID>& newItems) { |
| 20 | foreach (const JID& jid, this->items) { | 20 | // JIDs which are in the current list but not in the new list, are removed. |
| 21 | if (std::find(items.begin(), items.end(), jid) != items.end()) { | 21 | foreach (const JID& jid, items) { |
| 22 | if (std::find(newItems.begin(), newItems.end(), jid) == newItems.end()) { | ||
| 22 | onItemRemoved(jid); | 23 | onItemRemoved(jid); |
| 23 | } | 24 | } |
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | foreach (const JID& jid, items) { | 27 | // JIDs which are in the new list but not in the current list, are added. |
| 27 | if (std::find(this->items.begin(), this->items.end(), jid) != this->items.end()) { | 28 | foreach (const JID& jid, newItems) { |
| 29 | if (std::find(items.begin(), items.end(), jid) == items.end()) { | ||
| 28 | onItemAdded(jid); | 30 | onItemAdded(jid); |
| 29 | } | 31 | } |
| 30 | } | 32 | } |
| 31 | this->items = items; | 33 | items = newItems; |
| 32 | } | 34 | } |
| 33 | 35 | ||
| 34 | void BlockListImpl::addItem(const JID& item) { | 36 | void BlockListImpl::addItem(const JID& item) { |
| 35 | if (std::find(items.begin(), items.end(), item) == items.end()) { | 37 | if (std::find(items.begin(), items.end(), item) == items.end()) { |
| 36 | items.push_back(item); | 38 | items.push_back(item); |
Swift