From: Tomasz Marciniak Date: Mon, 5 Oct 2015 09:02:44 +0000 (+0200) Subject: [Messaging] Added functionality for messageStatus attribute. X-Git-Tag: submit/tizen/20151026.073646^2^2~64^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=194f6348d9fde9251069e71a3ef1a210b3330033;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Messaging] Added functionality for messageStatus attribute. [Verification] Code compiles. TCT pass rate 100% messageStatus is properly displayed now. Change-Id: I2ac9a5c41f7bdcb6be6b79c2c76c26bb18f9ae0a Signed-off-by: Tomasz Marciniak --- diff --git a/src/messaging/email_manager.cc b/src/messaging/email_manager.cc index 2833d993..84bd13ac 100755 --- a/src/messaging/email_manager.cc +++ b/src/messaging/email_manager.cc @@ -1487,5 +1487,43 @@ void EmailManager::removeConversations(ConversationCallbackData* callback) callback = NULL; } +std::string EmailManager::getMessageStatus(int id) { + LoggerD("Entered"); + + email_mail_data_t *mail = nullptr; + MessageStatus status = MessageStatus::STATUS_UNDEFINED; + + int ret = email_get_mail_data(id, &mail); + if (EMAIL_ERROR_NONE != ret ) { + LoggerD("Failed to get data."); + return ""; + } + + switch(mail->save_status) { + case EMAIL_MAIL_STATUS_SENT: + status = MessageStatus::STATUS_SENT; + break; + case EMAIL_MAIL_STATUS_SENDING: + status = MessageStatus::STATUS_SENDING; + break; + case EMAIL_MAIL_STATUS_SAVED: + status = MessageStatus::STATUS_DRAFT; + break; + case EMAIL_MAIL_STATUS_SEND_FAILURE: + status = MessageStatus::STATUS_FAILED; + break; + default: + status = MessageStatus::STATUS_UNDEFINED; + break; + } + + ret = email_free_mail_data(&mail, 1); + if (EMAIL_ERROR_NONE != ret ) { + LoggerD("Failed to free mail data."); + } + + return MessagingUtil::messageStatusToString(status); +} + } // Messaging } // DeviceAPI diff --git a/src/messaging/email_manager.h b/src/messaging/email_manager.h index a2f752de..d38ef798 100755 --- a/src/messaging/email_manager.h +++ b/src/messaging/email_manager.h @@ -67,6 +67,7 @@ public: void findConversations(ConversationCallbackData* callback); void findFolders(FoldersCallbackData* callback); void removeConversations(ConversationCallbackData* callback); + std::string getMessageStatus(int id); common::PlatformResult sendMessage(MessageRecipientsCallbackData* callback); void sendStatusCallback(int mail_id, email_noti_on_network_event status, diff --git a/src/messaging/messaging_api.js b/src/messaging/messaging_api.js index 4ce117e2..984e60ee 100755 --- a/src/messaging/messaging_api.js +++ b/src/messaging/messaging_api.js @@ -388,16 +388,13 @@ function Message(type, data) { { get: function () { if (_internal.id) { - // TODO create CPP layer - /* - *return bridge.sync({ - * cmd: 'Message_messageStatus', - * args: { - * id: _internal.id - * } - *}); - */ - return _internal.messageStatus; + return bridge.sync({ + cmd: 'Message_messageStatus', + args: { + id: _internal.id, + type: _internal.type + } + }); } else { return ''; } diff --git a/src/messaging/messaging_instance.cc b/src/messaging/messaging_instance.cc index 9d891820..3f9053e9 100755 --- a/src/messaging/messaging_instance.cc +++ b/src/messaging/messaging_instance.cc @@ -32,6 +32,8 @@ #include "messaging_util.h" #include "message_storage.h" #include "message.h" +#include "short_message_manager.h" +#include "email_manager.h" using common::ErrorCode; using common::PlatformResult; @@ -100,6 +102,8 @@ const char* FUN_MESSAGE_STORAGE_REMOVE_CHANGE_LISTENER = "MessageStorage_removeC const char* REMOVE_CHANGE_LISTENER_ARGS_WATCHID = "watchId"; const char* FUNCTIONS_HIDDEN_ARGS_SERVICE_ID = "serviceId"; +const char* FUN_MESSAGE_GET_MESSAGE_STATUS = "Message_messageStatus"; +const char* FUN_MESSAGE_MESSAGING_EMAIL = "messaging.email"; auto getServiceIdFromJSON = [](picojson::object& data) -> int { std::string serviceStrId; @@ -145,6 +149,7 @@ MessagingInstance::MessagingInstance(): REGISTER_SYNC(FUN_MESSAGE_STORAGE_ADD_CONVERSATIONS_CHANGE_LISTENER, MessageStorageAddConversationsChangeListener); REGISTER_SYNC(FUN_MESSAGE_STORAGE_ADD_FOLDER_CHANGE_LISTENER, MessageStorageAddFolderChangeListener); REGISTER_SYNC(FUN_MESSAGE_STORAGE_REMOVE_CHANGE_LISTENER, MessageStorageRemoveChangeListener); + REGISTER_SYNC(FUN_MESSAGE_GET_MESSAGE_STATUS, MessageGetMessageStatus); #undef REGISTER_SYNC } @@ -866,6 +871,31 @@ void MessagingInstance::MessageStorageRemoveChangeListener(const picojson::value ReportSuccess(out); } +void MessagingInstance::MessageGetMessageStatus(const picojson::value& args, + picojson::object& out) +{ + LoggerD("Entered"); + + if (!args.contains(JSON_DATA)) { + LoggerE("json is incorrect - missing required member"); + ReportSuccess(picojson::value(""), out); + return; + } + + picojson::object data = args.get(JSON_DATA).get(); + const int id = stoi(data.at("id").get()); + const std::string& type = data.at("type").get(); + + std::string status; + if (FUN_MESSAGE_MESSAGING_EMAIL == type) { + status = EmailManager::getInstance().getMessageStatus(id); + } else { + status = ShortMsgManager::getInstance().getMessageStatus(id); + } + + ReportSuccess(picojson::value(status), out); +} + } // namespace messaging } // namespace extension diff --git a/src/messaging/messaging_instance.h b/src/messaging/messaging_instance.h index c5f0b51f..09b88d0a 100755 --- a/src/messaging/messaging_instance.h +++ b/src/messaging/messaging_instance.h @@ -66,6 +66,8 @@ private: picojson::object& out); void MessageStorageRemoveChangeListener(const picojson::value& args, picojson::object& out); + void MessageGetMessageStatus(const picojson::value& args, + picojson::object& out); MessagingManager manager_; PostQueue queue_; diff --git a/src/messaging/messaging_util.cc b/src/messaging/messaging_util.cc index f1a7aa5e..3bdff170 100755 --- a/src/messaging/messaging_util.cc +++ b/src/messaging/messaging_util.cc @@ -605,9 +605,6 @@ picojson::value MessagingUtil::messageToJson(std::shared_ptr message) ? picojson::value(std::to_string(message->getInResponseTo())) : picojson::value(); - // TODO MessageStatus has type MessageStatus - //o[MESSAGE_ATTRIBUTE_MESSAGE_STATUS] = picojson::value(message->getMessageStatus()); - std::shared_ptr body = message->getBody(); o[MESSAGE_ATTRIBUTE_BODY] = MessagingUtil::messageBodyToJson(body); diff --git a/src/messaging/short_message_manager.cc b/src/messaging/short_message_manager.cc index 3d017d06..88e040a1 100755 --- a/src/messaging/short_message_manager.cc +++ b/src/messaging/short_message_manager.cc @@ -21,6 +21,7 @@ #include "common/platform_exception.h" #include "common/logger.h" +#include "common/scope_exit.h" #include "messaging_util.h" #include "messaging_instance.h" @@ -1272,6 +1273,78 @@ ShortMsgManager::~ShortMsgManager() LoggerD("m_mms_removed_conv_id_object_map.size() = %d", m_mms_removed_conv_id_object_map.size()); } +std::string ShortMsgManager::getMessageStatus(int id) { + LoggerD("Entered"); + + msg_struct_t send_opt = nullptr; + msg_struct_t msg = nullptr; + + SCOPE_EXIT { + if (send_opt) { + msg_release_struct(&send_opt); + } + if (msg) { + msg_release_struct(&msg); + } + }; + + send_opt = msg_create_struct(MSG_STRUCT_SENDOPT); + msg = msg_create_struct(MSG_STRUCT_MESSAGE_INFO); + if (!msg || !send_opt) { + LoggerD("Failed to create message struct"); + return ""; + } + + int ret = msg_get_message(m_msg_handle, id, msg, send_opt); + if (MSG_SUCCESS != ret) { + LoggerE("Couldn't retrieve message from service, id: %d, error:%d", id, ret); + return ""; + } + + int status_int; + MessageStatus status = MessageStatus::STATUS_UNDEFINED; + + ret = msg_get_int_value(msg, MSG_MESSAGE_FOLDER_ID_INT, &status_int); + if (MSG_SUCCESS == ret) { + switch (status_int) { + case MSG_OUTBOX_ID: + status = MessageStatus::STATUS_SENDING; + break; + case MSG_SENTBOX_ID: + status = MessageStatus::STATUS_SENT; + break; + case MSG_DRAFT_ID: + status = MessageStatus::STATUS_DRAFT; + break; + default: + status = MessageStatus::STATUS_UNDEFINED; + break; + } + } else { + ret = msg_get_int_value(msg, MSG_SENT_STATUS_NETWORK_STATUS_INT, &status_int); + if (MSG_SUCCESS == ret) { + switch(status_int) { + case MSG_NETWORK_SEND_SUCCESS: + status = MessageStatus::STATUS_SENT; + break; + case MSG_NETWORK_SENDING: + status = MessageStatus::STATUS_SENDING; + break; + case MSG_NETWORK_NOT_SEND: + status = MessageStatus::STATUS_DRAFT; + break; + case MSG_NETWORK_SEND_FAIL: + status = MessageStatus::STATUS_FAILED; + break; + default: + status = MessageStatus::STATUS_UNDEFINED; + break; + } + } + } + + return MessagingUtil::messageStatusToString(status); +} } // messaging } // extension diff --git a/src/messaging/short_message_manager.h b/src/messaging/short_message_manager.h index 2c206954..dcdf05bd 100755 --- a/src/messaging/short_message_manager.h +++ b/src/messaging/short_message_manager.h @@ -55,6 +55,7 @@ public: void removeMessages(MessagesCallbackUserData* callback); void updateMessages(MessagesCallbackUserData* callback); common::PlatformResult getMessage(int msg_id, msg_struct_t* out_msg); + std::string getMessageStatus(int id); private: ShortMsgManager(); ShortMsgManager(const ShortMsgManager &);