summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-09-12 23:22:12 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-09-18 09:38:54 (GMT)
commit4455c20085834098f6d9aa872db3115d466e7004 (patch)
treee5e61ec0880f4001bc76340cd13670cd49628e7c /Swiften/Client/BlockListImpl.cpp
parent909ecaea63618e9b94c9063c94cd51aa69654b00 (diff)
downloadswift-4455c20085834098f6d9aa872db3115d466e7004.zip
swift-4455c20085834098f6d9aa872db3115d466e7004.tar.bz2
Fix notification logic for signals in BlockListImpl
The logic for calling onItemAdded and onItemRemoved signals when setting a new list of block items using BlockListImpl::setItems used to be broken. This commit fixes and documents the correct signal notification behavior Test-Information: Added a unit test which verifies the notification behavior in case of added block list items, removed block list items and a complete change of the block list. Change-Id: I3061545e25ddfc2d9d1a3c987045a58e5c9230ac
Diffstat (limited to 'Swiften/Client/BlockListImpl.cpp')
-rw-r--r--Swiften/Client/BlockListImpl.cpp20
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,34 +1,36 @@
/*
- * Copyright (c) 2011 Isode Limited.
+ * Copyright (c) 2011-2015 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <Swiften/Client/BlockListImpl.h>
-#include <Swiften/Base/foreach.h>
-
#include <algorithm>
+#include <Swiften/Base/foreach.h>
+
using namespace Swift;
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()) {
+void BlockListImpl::setItems(const std::vector<JID>& newItems) {
+ // JIDs which are in the current list but not in the new list, are removed.
+ foreach (const JID& 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()) {
+ // JIDs which are in the new list but not in the current list, are added.
+ foreach (const JID& jid, newItems) {
+ if (std::find(items.begin(), items.end(), jid) == items.end()) {
onItemAdded(jid);
}
}
- this->items = items;
+ items = newItems;
}
void BlockListImpl::addItem(const JID& item) {