From: Pawel Andruszkiewicz
Date: Tue, 19 May 2015 09:43:19 +0000 (+0200)
Subject: [Contact] Added filtering in ContactManagerListenerCallback callback.
X-Git-Tag: submit/tizen_tv/20150603.064601^2~7
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5103e320f42f527cc1d1d68ee222b58b4369aea2;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Contact] Added filtering in ContactManagerListenerCallback callback.
[Verification] PersonsChangeCallback_onpersonsadded passes, TCT pass rate: 441/442.
Change-Id: I290617bd2e5a9df944b98832e0d1403f0584c6b5
Signed-off-by: Pawel Andruszkiewicz
---
diff --git a/src/contact/contact_manager.cc b/src/contact/contact_manager.cc
index bf965c45..95452c20 100755
--- a/src/contact/contact_manager.cc
+++ b/src/contact/contact_manager.cc
@@ -16,6 +16,7 @@
#include "contact/contact_manager.h"
#include
+#include
#include "common/converter.h"
#include "common/picojson.h"
@@ -833,6 +834,9 @@ void ContactManagerListenerCallback(const char* view_uri, char* changes,
return;
}
+ SLoggerD("view_uri: %s", view_uri);
+ SLoggerD("changes: %s", changes);
+
JsonValue result{JsonObject{}};
JsonObject& result_obj = result.get();
result_obj.insert(std::make_pair(std::string("listenerId"),
@@ -847,6 +851,11 @@ void ContactManagerListenerCallback(const char* view_uri, char* changes,
std::unique_ptr tmp(strdup(changes),
[](char* p) { free(p); });
+ // 'changes' may contain repeated values, we need to filter it
+ std::set added_ids;
+ std::set updated_ids;
+ std::set removed_ids;
+
char* token = strtok(tmp.get(), kTokenDelimiter);
while (token) {
if (IsNumeric(token)) {
@@ -859,35 +868,45 @@ void ContactManagerListenerCallback(const char* view_uri, char* changes,
int person_id = atoi(token);
switch (type) {
case CONTACTS_CHANGE_INSERTED: {
- added.push_back(JsonValue{JsonObject{}});
- PlatformResult status = ContactManagerGetInternal(
- person_id, &added.back().get());
- if (status.IsError()) {
- LoggerE("Caught exception in listener callback: %s",
- status.message().c_str());
- return;
+ if (added_ids.find(person_id) == added_ids.end()) {
+ added.push_back(JsonValue{JsonObject{}});
+ PlatformResult status = ContactManagerGetInternal(
+ person_id, &added.back().get());
+ if (status.IsError()) {
+ LoggerE("Caught exception in listener callback: %s",
+ status.message().c_str());
+ return;
+ }
+ added_ids.insert(person_id);
}
break;
}
case CONTACTS_CHANGE_UPDATED: {
- updated.push_back(JsonValue{JsonObject{}});
- PlatformResult status = ContactManagerGetInternal(
- person_id, &updated.back().get());
- if (status.IsError()) {
- LoggerE("Caught exception in listener callback: %s",
- status.message().c_str());
- return;
+ if (updated_ids.find(person_id) == updated_ids.end()) {
+ updated.push_back(JsonValue{JsonObject{}});
+ PlatformResult status = ContactManagerGetInternal(
+ person_id, &updated.back().get());
+ if (status.IsError()) {
+ LoggerE("Caught exception in listener callback: %s",
+ status.message().c_str());
+ return;
+ }
+ updated_ids.insert(person_id);
}
break;
}
case CONTACTS_CHANGE_DELETED: {
- std::string id_str{std::to_string(person_id)};
- removed.push_back(JsonValue{id_str.c_str()});
+ if (removed_ids.find(person_id) == removed_ids.end()) {
+ removed.push_back(JsonValue{std::to_string(person_id)});
+ removed_ids.insert(person_id);
+ }
+ break;
+ }
+ default: {
break;
}
- default: {}
}
}
}