[Callhistory] Fix for setting direction attribute.
authorTomasz Marciniak <t.marciniak@samsung.com>
Mon, 25 May 2015 13:43:17 +0000 (15:43 +0200)
committerTomasz Marciniak <t.marciniak@samsung.com>
Tue, 26 May 2015 11:19:23 +0000 (20:19 +0900)
[Verification] Code compiles without errors.
Manual test CallHistoryEntry_direction_attribute passes.
TCT pass rate:
Auto: 100% (80/80/0/0/0)
Manual: 92.59% (27/25/2/0/0)

Change-Id: I20df77585f61d0d15de9d55306a3482da95859e8
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/callhistory/callhistory.cc
src/callhistory/callhistory.h
src/callhistory/callhistory_api.js
src/callhistory/callhistory_instance.cc
src/callhistory/callhistory_instance.h

index 699c761eab5dbc646215d1c9925d773c977be715..a73fab155fe849317b77802d8735b102060a2a96 100644 (file)
@@ -572,6 +572,54 @@ PlatformResult CallHistory::stopCallHistoryChangeListener()
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult CallHistory::setMissedDirection(int uid)
+{
+  LoggerD("Entered");
+
+  contacts_record_h record = nullptr;
+  SCOPE_EXIT {
+    contacts_record_destroy(record, true);
+  };
+
+  int ret = CONTACTS_ERROR_NONE;
+  int log_type = CONTACTS_PLOG_TYPE_NONE;
+
+  ret = contacts_db_get_record(_contacts_phone_log._uri, uid, &record);
+  if (CONTACTS_ERROR_NONE != ret) {
+    LoggerE("Failed to get record [%d]", ret);
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get record");
+  }
+
+  ret = contacts_record_get_int(record, _contacts_phone_log.log_type, &log_type);
+  if (CONTACTS_ERROR_NONE != ret) {
+    LoggerE("Failed to get log type [%d]", ret);
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to get log type");
+  }
+
+  if (CONTACTS_PLOG_TYPE_VOICE_INCOMMING_UNSEEN == log_type) {
+    ret = contacts_record_set_int(
+        record, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_VOICE_INCOMMING_SEEN);
+  } else if (CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_UNSEEN == log_type) {
+    ret = contacts_record_set_int(
+        record, _contacts_phone_log.log_type, CONTACTS_PLOG_TYPE_VIDEO_INCOMMING_SEEN);
+  } else {
+    return PlatformResult(ErrorCode::NO_ERROR);
+  }
+
+  if (CONTACTS_ERROR_NONE != ret) {
+    LoggerE("Failed to set direction [%d]", ret);
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to set direction");
+  }
+
+  ret = contacts_db_update_record(record);
+  if (CONTACTS_ERROR_NONE != ret) {
+    LoggerE("Failed to update record [%d]", ret);
+    return PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to update record");
+  }
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
 void CallHistory::loadPhoneNumbers()
 {
   LoggerD("Entered");
index 31a3961fff5f0af6de3fb0c62133867ba24b6daf..e37c217ce7b7af3cee80c9ed403bd350adc21894 100644 (file)
@@ -36,6 +36,7 @@ class CallHistory
   void removeAll(const picojson::object& args);
   common::PlatformResult startCallHistoryChangeListener();
   common::PlatformResult stopCallHistoryChangeListener();
+  common::PlatformResult setMissedDirection(int uid);
 
  private:
   static void changeListenerCB(const char* view_uri, char *changes, void* user_data);
index 199c95b4e0e3d4ab8b4bb6d4da1495267fdddcdb..3d7c794c89d7e8389ebef816053d60a49aa909f0 100644 (file)
@@ -291,9 +291,13 @@ function RemoteParty(data) {
 };
 
 function CallHistoryEntry(data) {
-
     function directionSetter(val) {
-        direction = converter_.toString(val, false);
+        if (direction === 'MISSEDNEW' && val === 'MISSED') {
+            var result = native_.callSync('CallHistory_setMissedDirection', {uid : this.uid});
+            if (native_.isSuccess(result)) {
+                direction = 'MISSED';
+            }
+        }
     }
 
     function createRemoteParties(parties) {
@@ -306,7 +310,7 @@ function CallHistoryEntry(data) {
 
     var direction;
     if (data) {
-        directionSetter(data.direction);
+        direction = converter_.toString(data.direction, false);
     }
 
     Object.defineProperties(this, {
index 4956be7cb4eb90723b64db5c5176be4c1ed13959..086326f4436dc1aaca57b6331c2fa3ffeba3fae1 100644 (file)
@@ -22,6 +22,7 @@ CallHistoryInstance::CallHistoryInstance() : history_(*this) {
   REGISTER_SYNC("CallHistory_remove", Remove);
   REGISTER_SYNC("CallHistory_addChangeListener", AddChangeListener);
   REGISTER_SYNC("CallHistory_removeChangeListener", RemoveChangeListener);
+  REGISTER_SYNC("CallHistory_setMissedDirection", SetMissedDirection);
 #undef REGISTER_SYNC
 #define REGISTER_ASYNC(c,x) \
     RegisterSyncHandler(c, std::bind(&CallHistoryInstance::x, this, _1, _2));
@@ -86,6 +87,25 @@ void CallHistoryInstance::RemoveChangeListener(const picojson::value& args, pico
   }
 }
 
+void CallHistoryInstance::SetMissedDirection(const picojson::value& args, picojson::object& out) {
+  LoggerD("Entered");
+
+  if (!args.contains("uid")) {
+    LoggerD("args doesn't contain attribute 'uid'");
+    ReportError(out);
+    return;
+  }
+
+  int uid = std::atoi(args.get("uid").get<std::string>().c_str());
+
+  PlatformResult result = history_.setMissedDirection(uid);
+  if (result.IsSuccess()) {
+    ReportSuccess(out);
+  } else {
+    ReportError(out);
+  }
+}
+
 void CallHistoryInstance::CallHistoryChange(picojson::object& data) {
   LoggerD("Entered");
   picojson::value event = picojson::value(data);
index 7e506204e99076bf0ff19ffe5fa8ee3ad5e7faff..a7e9f30d1a798c6d5f4c1ea1e5de383e6573bc51 100644 (file)
@@ -24,6 +24,7 @@ class CallHistoryInstance : public common::ParsedInstance {
   void RemoveAll(const picojson::value& args, picojson::object& out);
   void AddChangeListener (const picojson::value& args, picojson::object& out);
   void RemoveChangeListener(const picojson::value& args, picojson::object& out);
+  void SetMissedDirection(const picojson::value& args, picojson::object& out);
 
   CallHistory history_;
 };