From: Michal Michalski Date: Fri, 6 Dec 2019 10:42:03 +0000 (+0100) Subject: [messaging] Remove MessageFolder constructor. X-Git-Tag: accepted/tizen/unified/20200108.131505~7^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3916f7fd8633352d232f2041d9884f72dd48460a;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [messaging] Remove MessageFolder constructor. + Removed MessageFolder constructor from attributes. + MessageFolder(json) constructor is used to create folders. + Add createMessageFolder() -> json function. [Verification] tct-messaging-*-tizen-tests 100% pass. Signed-off-by: Michal Michalski Change-Id: I17442348d4f91c8ac275787adfe7ca8fb8ae88ff --- diff --git a/src/messaging/DBus/MessageProxy.cpp b/src/messaging/DBus/MessageProxy.cpp index 8ae3eb2..eb6ac72 100644 --- a/src/messaging/DBus/MessageProxy.cpp +++ b/src/messaging/DBus/MessageProxy.cpp @@ -251,8 +251,10 @@ PlatformResult MessageProxy::handleMailboxEvent(int account_id, int mailbox_id, EventFolders* eventFolder = new EventFolders(); eventFolder->service_type = MessageType::EMAIL; eventFolder->service_id = account_id; - auto folder = - std::make_shared(std::to_string(mailbox_id), "", "", "", "", "", "", false); + + auto jsonFolder = createMessageFolder(std::to_string(mailbox_id)); + auto folder = std::make_shared(jsonFolder); + if (event != NOTI_MAILBOX_DELETE) { auto ret = native::EmailGetMailboxById(mailbox_id, *folder); if (ret.IsError()) { diff --git a/src/messaging/email_manager.cc b/src/messaging/email_manager.cc index 167ed1f..dd5dedf 100644 --- a/src/messaging/email_manager.cc +++ b/src/messaging/email_manager.cc @@ -14,9 +14,6 @@ * limitations under the License. */ -//#include -//#include -//#include #include #include #include @@ -25,7 +22,6 @@ #include "common/logger.h" #include "common/platform_exception.h" #include "common/scope_exit.h" -//#include #include "MsgCommon/AbstractFilter.h" @@ -34,28 +30,20 @@ #include #include +#include "conversation_callback_data.h" #include "email_manager.h" +#include "find_msg_callback_user_data.h" #include "message.h" #include "message_conversation.h" -#include "message_service.h" -#include "messaging_util.h" -//#include "MessageCallbackUserData.h" -//#include "MessagesCallbackUserData.h" -#include "conversation_callback_data.h" -#include "find_msg_callback_user_data.h" #include "message_email.h" +#include "message_service.h" #include "messaging_database_manager.h" - -//#include "JSMessage.h" -//#include "JSMessageConversation.h" -//#include "JSMessageFolder.h" +#include "messaging_util.h" #include #include -//#include "DBus/SyncProxy.h" #include "DBus/LoadBodyProxy.h" -//#include "DBus/LoadAttachmentProxy.h" #include @@ -137,16 +125,6 @@ PlatformResult EmailManager::InitializeEmailService() { } m_proxy_load_body->signalSubscribe(); - // ret = DBus::LoadAttachmentProxy::create(DBus::Proxy::DBUS_PATH_NETWORK_STATUS, - // DBus::Proxy::DBUS_IFACE_NETWORK_STATUS, - // &m_proxy_load_attachment); - // CHECK_ERROR(ret, "create load attachment proxy failed"); - // if (!m_proxy_load_attachment) { - // LoggerE("Load attachment proxy is null"); - // return PlatformResult(ErrorCode::UNKNOWN_ERR, "Load attachment proxy is null"); - // } - // m_proxy_load_attachment->signalSubscribe(); - ret = DBus::MessageProxy::create(*this, &m_proxy_messageStorage); CHECK_ERROR(ret, "create message proxy failed"); if (!m_proxy_messageStorage) { diff --git a/src/messaging/message_folder.cc b/src/messaging/message_folder.cc index 8ec6e1c..8f19ea1 100644 --- a/src/messaging/message_folder.cc +++ b/src/messaging/message_folder.cc @@ -27,8 +27,6 @@ const char* MessageFolderTypeStr[] = { "INBOX", "OUTBOX", "DRAFTS", "SENTBOX", }; -namespace { - const char* MESSAGE_FOLDER_ATTRIBUTE_ID = "id"; const char* MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID = "parentId"; const char* MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID = "serviceId"; @@ -38,21 +36,21 @@ const char* MESSAGE_FOLDER_ATTRIBUTE_PATH = "path"; const char* MESSAGE_FOLDER_ATTRIBUTE_TYPE = "type"; const char* MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE = "synchronizable"; -} // namespace - -MessageFolder::MessageFolder(const std::string& id, const std::string& parent_id, - const std::string& service_id, const std::string& content_type, - const std::string& name, const std::string& path, - const std::string& type, bool synchronizable) { - ScopeLogger(); - attributes[MESSAGE_FOLDER_ATTRIBUTE_ID] = picojson::value(id); - attributes[MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID] = picojson::value(parent_id); - attributes[MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID] = picojson::value(service_id); - attributes[MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE] = picojson::value(content_type); - attributes[MESSAGE_FOLDER_ATTRIBUTE_NAME] = picojson::value(name); - attributes[MESSAGE_FOLDER_ATTRIBUTE_PATH] = picojson::value(path); - attributes[MESSAGE_FOLDER_ATTRIBUTE_TYPE] = picojson::value(type); - attributes[MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE] = picojson::value(synchronizable); +picojson::value createMessageFolder(const std::string& id, const std::string& name, + const std::string& service_id, const std::string& content_type, + const std::string& type, bool synchronizable, + const std::string& path, const std::string& parent_id) { + auto json = picojson::value(picojson::object()); + auto& folder = json.get(); + folder[MESSAGE_FOLDER_ATTRIBUTE_ID] = picojson::value(id); + folder[MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID] = picojson::value(parent_id); + folder[MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID] = picojson::value(service_id); + folder[MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE] = picojson::value(content_type); + folder[MESSAGE_FOLDER_ATTRIBUTE_NAME] = picojson::value(name); + folder[MESSAGE_FOLDER_ATTRIBUTE_PATH] = picojson::value(path); + folder[MESSAGE_FOLDER_ATTRIBUTE_TYPE] = picojson::value(type); + folder[MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE] = picojson::value(synchronizable); + return json; } MessageFolder::MessageFolder(const picojson::value& json) { diff --git a/src/messaging/message_folder.h b/src/messaging/message_folder.h index d9fa949..5dda3a6 100644 --- a/src/messaging/message_folder.h +++ b/src/messaging/message_folder.h @@ -38,10 +38,14 @@ enum MessageFolderType { }; extern const char* MessageFolderTypeStr[MESSAGE_FOLDER_TYPE_NOTSTANDARD]; +picojson::value createMessageFolder(const std::string& id, const std::string& name = "", + const std::string& service_id = "", + const std::string& content_type = "", + const std::string& type = "", bool synchronizable = false, + const std::string& path = "", + const std::string& parent_id = ""); + struct MessageFolder { - MessageFolder(const std::string& id, const std::string& parent_id, const std::string& service_id, - const std::string& content_type, const std::string& name, const std::string& path, - const std::string& type, bool synchronizable); MessageFolder(const picojson::value& json); picojson::object attributes; }; diff --git a/src/messaging/message_storage_short_msg.cc b/src/messaging/message_storage_short_msg.cc index c84c28f..3f87db2 100644 --- a/src/messaging/message_storage_short_msg.cc +++ b/src/messaging/message_storage_short_msg.cc @@ -208,22 +208,23 @@ static gboolean findFoldersCB(void* data) { ScopeLogger(); std::unique_ptr params(static_cast(data)); - std::string content_type = params->message_type; - picojson::object response; - picojson::array array; for (std::string type : MessageFolderTypeStr) { auto id = std::to_string(array.size() + 1); auto service_id = std::to_string(params->account_id); - MessageFolder folder(id, "", service_id, content_type, type, "", type, false); - if (params->filter->isMatching(picojson::value(folder.attributes))) { - array.push_back(picojson::value(folder.attributes)); + auto json = createMessageFolder(id, type, service_id, params->message_type, type); + if (params->filter->isMatching(json)) { + array.push_back(json); } } - response[JSON_CALLBACK_ID] = picojson::value(static_cast(params->callback_id)); - ReportSuccess(picojson::value(array), response); - Instance::PostMessage(params->instance, picojson::value(response)); + auto response = picojson::value(picojson::object()); + auto& responseObj = response.get(); + + responseObj[JSON_CALLBACK_ID] = picojson::value(static_cast(params->callback_id)); + ReportSuccess(picojson::value(array), responseObj); + + Instance::PostMessage(params->instance, response); return FALSE; } diff --git a/src/messaging/messaging_native.cc b/src/messaging/messaging_native.cc index 880a76e..d8aeebf 100644 --- a/src/messaging/messaging_native.cc +++ b/src/messaging/messaging_native.cc @@ -26,14 +26,9 @@ #include #include -using extension::messaging::MessageFolder; -using extension::messaging::MessagingUtil; -using extension::messaging::MESSAGE_FOLDER_TYPE_INBOX; -using extension::messaging::MESSAGE_FOLDER_TYPE_SENTBOX; -using extension::messaging::MESSAGE_FOLDER_TYPE_DRAFTS; -using extension::messaging::MESSAGE_FOLDER_TYPE_OUTBOX; -using extension::messaging::EMAIL; -using extension::messaging::MessageFolderTypeStr; +namespace extension { +namespace messaging { + using common::PlatformResult; using common::ErrorCode; @@ -55,12 +50,12 @@ std::string convertPlatformFolderType(email_mailbox_type_e folderType) { } } -MessageFolder createMessageFolderFromMailbox(email_mailbox_t mailbox) { +picojson::value ConvertMailboxToJson(email_mailbox_t mailbox) { ScopeLogger(); - return MessageFolder(std::to_string(mailbox.mailbox_id), "", std::to_string(mailbox.account_id), - MessagingUtil::messageTypeToString(EMAIL), mailbox.alias, - mailbox.mailbox_name, convertPlatformFolderType(mailbox.mailbox_type), - mailbox.local == 0); + return createMessageFolder( + std::to_string(mailbox.mailbox_id), mailbox.alias, std::to_string(mailbox.account_id), + MessagingUtil::messageTypeToString(EMAIL), convertPlatformFolderType(mailbox.mailbox_type), + mailbox.local == 0, mailbox.mailbox_name); } } // namespace @@ -78,6 +73,7 @@ PlatformResult EmailGetMailboxList(int account_id, email_mailbox_t** mailboxes, } PlatformResult EmailGetMailboxList(int account_id, std::vector& folders) { + ScopeLogger(); email_mailbox_t* mailboxes = nullptr; int count = 0; @@ -91,7 +87,8 @@ PlatformResult EmailGetMailboxList(int account_id, std::vector& f } for (int i = 0; i < count; ++i) { - folders.push_back(createMessageFolderFromMailbox(mailboxes[i])); + auto json = ConvertMailboxToJson(mailboxes[i]); + folders.push_back(MessageFolder(json)); } return PlatformResult(); @@ -106,7 +103,7 @@ PlatformResult EmailGetMailboxById(int mailbox_id, MessageFolder& folder) { return PlatformResult(ErrorCode::UNKNOWN_ERR, "email_get_mailbox_by_mailbox_id() failed."); } - folder = createMessageFolderFromMailbox(*mailbox); + folder = MessageFolder(ConvertMailboxToJson(*mailbox)); if (EMAIL_ERROR_NONE != email_free_mailbox(&mailbox, 1)) { LoggerW("Calling email_free_mailbox() failed."); } @@ -115,3 +112,5 @@ PlatformResult EmailGetMailboxById(int mailbox_id, MessageFolder& folder) { } } // namespace native +} // namespace messaging +} // namespace extension diff --git a/src/messaging/messaging_native.h b/src/messaging/messaging_native.h index e4e0b6f..24b26f4 100644 --- a/src/messaging/messaging_native.h +++ b/src/messaging/messaging_native.h @@ -30,13 +30,15 @@ #include "common/platform_result.h" #include "message_folder.h" -using extension::messaging::MessageFolder; - +namespace extension { +namespace messaging { namespace native { common::PlatformResult EmailGetMailboxList(int account_id, std::vector& folders); common::PlatformResult EmailGetMailboxById(int mailbox_id, MessageFolder& folder); } // namespace native +} // namespace messaging +} // namespace extension #endif // MESSAGING_NATIVE_H_