From: Tomasz Marciniak Date: Mon, 25 May 2015 13:43:17 +0000 (+0200) Subject: [Callhistory] Fix for setting direction attribute. X-Git-Tag: submit/tizen_mobile/20150612.133019^2~2^2~128^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8824d15f73b72a5d5605caadbbcad3fa49eca7f;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Callhistory] Fix for setting direction attribute. [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 --- diff --git a/src/callhistory/callhistory.cc b/src/callhistory/callhistory.cc index 699c761e..a73fab15 100644 --- a/src/callhistory/callhistory.cc +++ b/src/callhistory/callhistory.cc @@ -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"); diff --git a/src/callhistory/callhistory.h b/src/callhistory/callhistory.h index 31a3961f..e37c217c 100644 --- a/src/callhistory/callhistory.h +++ b/src/callhistory/callhistory.h @@ -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); diff --git a/src/callhistory/callhistory_api.js b/src/callhistory/callhistory_api.js index 199c95b4..3d7c794c 100644 --- a/src/callhistory/callhistory_api.js +++ b/src/callhistory/callhistory_api.js @@ -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, { diff --git a/src/callhistory/callhistory_instance.cc b/src/callhistory/callhistory_instance.cc index 4956be7c..086326f4 100644 --- a/src/callhistory/callhistory_instance.cc +++ b/src/callhistory/callhistory_instance.cc @@ -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().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); diff --git a/src/callhistory/callhistory_instance.h b/src/callhistory/callhistory_instance.h index 7e506204..a7e9f30d 100644 --- a/src/callhistory/callhistory_instance.h +++ b/src/callhistory/callhistory_instance.h @@ -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_; };