[Messaging] Added functionality for messageStatus attribute.
authorTomasz Marciniak <t.marciniak@samsung.com>
Mon, 5 Oct 2015 09:02:44 +0000 (11:02 +0200)
committerTomasz Marciniak <t.marciniak@samsung.com>
Mon, 5 Oct 2015 10:05:52 +0000 (12:05 +0200)
[Verification] Code compiles. TCT pass rate 100%
messageStatus is properly displayed now.

Change-Id: I2ac9a5c41f7bdcb6be6b79c2c76c26bb18f9ae0a
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/messaging/email_manager.cc
src/messaging/email_manager.h
src/messaging/messaging_api.js
src/messaging/messaging_instance.cc
src/messaging/messaging_instance.h
src/messaging/messaging_util.cc
src/messaging/short_message_manager.cc
src/messaging/short_message_manager.h

index 2833d993f8de1a5c5debc78cdb826026f402a9c6..84bd13accb8b48b8f0be1575f9990c66a066d67c 100755 (executable)
@@ -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
index a2f752de415baaa56ec63e3d88653d89ac42a718..d38ef7986cf7a38f1dd116a6bb55a6fe74dda1f7 100755 (executable)
@@ -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,
index 4ce117e29238002f6c4177dbd2b4b471c6d81232..984e60eea5cb8c3038901cc5badc9969564ba5ae 100755 (executable)
@@ -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 '';
                 }
index 9d8918202fbee7a867a38ba6fb1fd8602d7bedee..3f9053e908519b7953fbcb44340cfc910170622f 100755 (executable)
@@ -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<picojson::object>();
+    const int id = stoi(data.at("id").get<std::string>());
+    const std::string& type = data.at("type").get<std::string>();
+
+    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
 
index c5f0b51f92815b63e529640641a4cded32adae05..09b88d0a30cb331dc54419116f6251984f285d0f 100755 (executable)
@@ -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_;
index f1a7aa5ec0bdfb5c79dbeba1cc94ba31b1ddb587..3bdff170d21f080c9e2965c67f580806629eb497 100755 (executable)
@@ -605,9 +605,6 @@ picojson::value MessagingUtil::messageToJson(std::shared_ptr<Message> 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<MessageBody> body = message->getBody();
     o[MESSAGE_ATTRIBUTE_BODY] = MessagingUtil::messageBodyToJson(body);
 
index 3d017d067994ff3c5d1e16d58fc63de91b076ee6..88e040a1e07216d60777e5e9e3bae9b1c62d3343 100755 (executable)
@@ -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
index 2c206954df156a04e3035dac8edcf1378ca1fdf5..dcdf05bd7c7dbc47b9b208cc5fbf37e05cd98ccc 100755 (executable)
@@ -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 &);