From 708eecbabb94cdccb694a16413dbc6a4dec39e39 Mon Sep 17 00:00:00 2001 From: Maciek Blim Date: Tue, 13 Jan 2015 10:57:37 +0100 Subject: [PATCH] [Messaging] findMessages for sms Change-Id: I0a981d4e045bf74d2b78becb773e76bec52eb08c Signed-off-by: Maciek Blim --- src/messaging/message_storage_short_msg.cc | 3 +-- src/messaging/messaging_api.js | 8 ++++---- src/messaging/messaging_util.cc | 5 +++-- src/messaging/short_message_manager.cc | 21 ++++++++++++++------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/messaging/message_storage_short_msg.cc b/src/messaging/message_storage_short_msg.cc index 78c94cf..77535fd 100644 --- a/src/messaging/message_storage_short_msg.cc +++ b/src/messaging/message_storage_short_msg.cc @@ -109,8 +109,7 @@ static gboolean findMessagesTask(void* data) { LoggerD("Entered"); FindMsgCallbackUserData *callback = static_cast(data); - // TODO - //ShortMsgManager::getInstance().findMessages(callback); + ShortMsgManager::getInstance().findMessages(callback); return false; } diff --git a/src/messaging/messaging_api.js b/src/messaging/messaging_api.js index 87e0e01..a64dc3d 100644 --- a/src/messaging/messaging_api.js +++ b/src/messaging/messaging_api.js @@ -812,10 +812,10 @@ MessageStorage.prototype.findMessages = function () { bridge.async({ cmd: 'MessageStorage_findMessages', args: { - filter: args.filter, - sort: args.sort, - limit: args.limit, - offset: args.offset, + filter: args.filter || null, + sort: args.sort || null, + limit: args.limit || null, + offset: args.offset || null, serviceId: self.service.id, type: self.service.type } diff --git a/src/messaging/messaging_util.cc b/src/messaging/messaging_util.cc index 3fa07b1..de62c77 100644 --- a/src/messaging/messaging_util.cc +++ b/src/messaging/messaging_util.cc @@ -644,9 +644,10 @@ tizen::SortModePtr MessagingUtil::jsonToSortMode(const picojson::object& json) LoggerD("Entered"); using namespace tizen; - picojson::value value; try{ - value = json.at(JSON_TO_SORT); + if (json.at(JSON_TO_SORT).is()) { + return SortModePtr(); + } } catch(const std::out_of_range& e){ return SortModePtr(); } diff --git a/src/messaging/short_message_manager.cc b/src/messaging/short_message_manager.cc index 35a5bc6..e0c83d1 100644 --- a/src/messaging/short_message_manager.cc +++ b/src/messaging/short_message_manager.cc @@ -962,16 +962,23 @@ void ShortMsgManager::findMessages(FindMsgCallbackUserData* callback) try { if (callback->isError()) { LoggerD("Calling error callback"); - // TODO call error - //JSObjectRef errobj = JSWebAPIErrorFactory::makeErrorObject(context, - //callback->getErrorName(), callback->getErrorMessage()); - //callback->callErrorCallback(errobj); + MessagingInstance::getInstance().PostMessage(callback->getJson()->serialize().c_str()); } else { LoggerD("Calling success callback with %d messages:", callback->getMessages().size()); - // TODO call success - //callback->callSuccessCallback(JSMessage::messageVectorToJSObjectArray(context, - //callback->getMessages())); + + auto json = callback->getJson(); + picojson::object& obj = json->get(); + + std::vector response; + auto messages = callback->getMessages(); + std::for_each(messages.begin(), messages.end(), [&response](MessagePtr &message){ + response.push_back(MessagingUtil::messageToJson(message)); + }); + + obj[JSON_DATA] = picojson::value(response); + obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS); + MessagingInstance::getInstance().PostMessage(json->serialize().c_str()); } } catch (const common::PlatformException& err) { LoggerE("Error while calling findMessages callback: %s (%s)", -- 2.7.4