#include "conversations_change_callback.h"
#include "email_manager.h"
#include "find_msg_callback_user_data.h"
-#include "folders_callback_data.h"
#include "folders_change_callback.h"
#include "message.h"
#include "message_storage.h"
using common::ErrorCode;
using common::TypeMismatchException;
using common::PlatformResult;
+using common::tools::ReportError;
namespace extension {
namespace messaging {
namespace {
-const char* FUN_GET_MESSAGE_SERVICES = "Messaging_getMessageServices";
const char* GET_MESSAGE_SERVICES_ARGS_MESSAGE_SERVICE_TYPE = "messageServiceType";
-
-const char* FUN_MESSAGE_SERVICE_SEND_MESSAGE = "MessageService_sendMessage";
const char* SEND_MESSAGE_ARGS_MESSAGE = "message";
const char* SEND_MESSAGE_ARGS_SIMINDEX = "simIndex";
-
-const char* FUN_MESSAGE_SERVICE_LOAD_MESSAGE_BODY = "MessageService_loadMessageBody";
-
-const char* FUN_MESSAGE_SERVICE_LOAD_MESSAGE_ATTACHMENT = "MessageService_loadMessageAttachment";
const char* LOAD_MESSAGE_ATTACHMENT_ARGS_ATTACHMENT = "attachment";
-
-const char* FUN_MESSAGE_SERVICE_SYNC = "MessageService_sync";
const char* SYNC_ARGS_ID = "id";
const char* SYNC_ARGS_LIMIT = "limit";
-
-const char* FUN_MESSAGE_SERVICE_SYNC_FOLDER = "MessageService_syncFolder";
const char* SYNC_FOLDER_ARGS_ID = "id";
const char* SYNC_FOLDER_ARGS_FOLDER = "folder";
const char* SYNC_FOLDER_ARGS_LIMIT = "limit";
-
-const char* FUN_MESSAGE_SERVICE_STOP_SYNC = "MessageService_stopSync";
const char* STOP_SYNC_ARGS_ID = "id";
const char* STOP_SYNC_ARGS_OPID = "opId";
-
-const char* FUN_MESSAGE_STORAGE_ADD_DRAFT_MESSAGE = "MessageStorage_addDraftMessage";
const char* ADD_DRAFT_MESSAGE_ARGS_MESSAGE = "message";
-
-const char* FUN_MESSAGE_STORAGE_FIND_MESSAGES = "MessageStorage_findMessages";
-
-const char* FUN_MESSAGE_STORAGE_REMOVE_MESSAGES = "MessageStorage_removeMessages";
const char* REMOVE_MESSAGES_ARGS_MESSAGES = "messages";
-
-const char* FUN_MESSAGE_STORAGE_UPDATE_MESSAGES = "MessageStorage_updateMessages";
const char* UPDATE_MESSAGES_ARGS_MESSAGES = "messages";
-
-const char* FUN_MESSAGE_STORAGE_FIND_CONVERSATIONS = "MessageStorage_findConversations";
const char* FIND_CONVERSATIONS_ARGS_LIMIT = "limit";
const char* FIND_CONVERSATIONS_ARGS_OFFSET = "offset";
-
-const char* FUN_MESSAGE_STORAGE_REMOVE_CONVERSATIONS = "MessageStorage_removeConversations";
const char* REMOVE_CONVERSATIONS_ARGS_CONVERSATIONS = "conversations";
-
-const char* FUN_MESSAGE_STORAGE_FIND_FOLDERS = "MessageStorage_findFolders";
const char* FIND_FOLDERS_ARGS_LIMIT = "limit";
const char* FIND_FOLDERS_ARGS_OFFSET = "offset";
-
-const char* FUN_MESSAGE_STORAGE_ADD_MESSAGES_CHANGE_LISTENER =
- "MessageStorage_addMessagesChangeListener";
-
-const char* FUN_MESSAGE_STORAGE_ADD_CONVERSATIONS_CHANGE_LISTENER =
- "MessageStorage_addConversationsChangeListener";
-
-const char* FUN_MESSAGE_STORAGE_ADD_FOLDER_CHANGE_LISTENER =
- "MessageStorage_addFoldersChangeListener";
-
-const char* FUN_MESSAGE_STORAGE_REMOVE_CHANGE_LISTENER = "MessageStorage_removeChangeListener";
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;
+int getServiceIdFromJSON(const picojson::object& data) {
try {
- serviceStrId =
- MessagingUtil::getValueFromJSONObject<std::string>(data, FUNCTIONS_HIDDEN_ARGS_SERVICE_ID);
- return std::stoi(serviceStrId);
+ return std::stoi(
+ MessagingUtil::getValueFromJSONObject<std::string>(data, FUNCTIONS_HIDDEN_ARGS_SERVICE_ID));
} catch (...) {
return -1;
}
ScopeLogger();
using std::placeholders::_1;
using std::placeholders::_2;
-#define REGISTER_ASYNC(c, x) RegisterSyncHandler(c, std::bind(&MessagingInstance::x, this, _1, _2));
- REGISTER_ASYNC(FUN_GET_MESSAGE_SERVICES, GetMessageServices);
- REGISTER_ASYNC(FUN_MESSAGE_SERVICE_SEND_MESSAGE, MessageServiceSendMessage);
- REGISTER_ASYNC(FUN_MESSAGE_SERVICE_LOAD_MESSAGE_BODY, MessageServiceLoadMessageBody);
- REGISTER_ASYNC(FUN_MESSAGE_SERVICE_LOAD_MESSAGE_ATTACHMENT, MessageServiceLoadMessageAttachment);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_ADD_DRAFT_MESSAGE, MessageStorageAddDraft);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_FIND_MESSAGES, MessageStorageFindMessages);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_REMOVE_MESSAGES, MessageStorageRemoveMessages);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_UPDATE_MESSAGES, MessageStorageUpdateMessages);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_FIND_CONVERSATIONS, MessageStorageFindConversations);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_REMOVE_CONVERSATIONS, MessageStorageRemoveConversations);
- REGISTER_ASYNC(FUN_MESSAGE_STORAGE_FIND_FOLDERS, MessageStorageFindFolders);
-#undef REGISTER_ASYNC
-#define REGISTER_SYNC(c, x) RegisterSyncHandler(c, std::bind(&MessagingInstance::x, this, _1, _2));
- REGISTER_SYNC(FUN_MESSAGE_SERVICE_SYNC, MessageServiceSync);
- REGISTER_SYNC(FUN_MESSAGE_SERVICE_STOP_SYNC, MessageServiceStopSync);
- REGISTER_SYNC(FUN_MESSAGE_SERVICE_SYNC_FOLDER, MessageServiceSyncFolder);
- REGISTER_SYNC(FUN_MESSAGE_STORAGE_ADD_MESSAGES_CHANGE_LISTENER,
- MessageStorageAddMessagesChangeListener);
- 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
+
+#define REGISTER_METHOD(M) RegisterSyncHandler(#M, std::bind(&MessagingInstance::M, this, _1, _2))
+ REGISTER_METHOD(GetMessageServices);
+ REGISTER_METHOD(MessageServiceSendMessage);
+ REGISTER_METHOD(MessageServiceLoadMessageBody);
+ REGISTER_METHOD(MessageServiceLoadMessageAttachment);
+ REGISTER_METHOD(MessageStorageAddDraftMessage);
+ REGISTER_METHOD(MessageStorageFindMessages);
+ REGISTER_METHOD(MessageStorageRemoveMessages);
+ REGISTER_METHOD(MessageStorageUpdateMessages);
+ REGISTER_METHOD(MessageStorageFindConversations);
+ REGISTER_METHOD(MessageStorageRemoveConversations);
+ REGISTER_METHOD(MessageStorageFindFolders);
+
+ REGISTER_METHOD(MessageServiceSync);
+ REGISTER_METHOD(MessageServiceStopSync);
+ REGISTER_METHOD(MessageServiceSyncFolder);
+ REGISTER_METHOD(MessageStorageAddMessagesChangeListener);
+ REGISTER_METHOD(MessageStorageAddConversationsChangeListener);
+ REGISTER_METHOD(MessageStorageAddFolderChangeListener);
+ REGISTER_METHOD(MessageStorageRemoveChangeListener);
+ REGISTER_METHOD(MessageGetMessageStatus);
+#undef REGISTER_METHOD
}
MessagingInstance::~MessagingInstance() {
void MessagingInstance::GetMessageServices(const picojson::value& args, picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "GetMessageServices() is deprecated and will be removed from next "
+ "release without any alternatives.",
+ "8.0");
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageServiceSendMessage(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageServiceSendMessage() is deprecated and will be removed from next "
+ "release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageServiceLoadMessageBody(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageServiceLoadMessageBody() is deprecated and will be removed from "
+ "next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageServiceLoadMessageAttachment(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageServiceLoadMessageAttachment() is deprecated and will be removed "
+ "from next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageServiceSync(const picojson::value& args, picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageServiceSync() is deprecated and will be removed from next "
+ "release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageServiceSyncFolder(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageServiceSyncFolder() is deprecated and will be removed from next "
+ "release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
SyncFolderCallbackData* callback = new SyncFolderCallbackData(queue_, callbackId, *this);
callback->setAccountId(id);
- callback->setMessageFolder(MessagingUtil::jsonToMessageFolder(v_folder));
+ auto folder_ptr = std::make_shared<picojson::value>(v_folder);
+ callback->setMessageFolder(folder_ptr);
callback->setLimit(limit);
callback->AddToQueue();
void MessagingInstance::MessageServiceStopSync(const picojson::value& args, picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageServiceStopSync() is deprecated and will be removed from next "
+ "release without any alternatives.",
+ "8.0");
CHECK_EXIST(args, STOP_SYNC_ARGS_OPID, out);
picojson::object data = args.get<picojson::object>();
}
}
-void MessagingInstance::MessageStorageAddDraft(const picojson::value& args, picojson::object& out) {
+void MessagingInstance::MessageStorageAddDraftMessage(const picojson::value& args,
+ picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageAddDraftMessage() is deprecated and will be removed from "
+ "next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageStorageFindMessages(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageFindMessages() is deprecated and will be removed from "
+ "next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingRead, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageStorageRemoveMessages(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageRemoveMessages() is deprecated and will be removed from "
+ "next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageStorageUpdateMessages(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageUpdateMessages() is deprecated and will be removed from "
+ "next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageStorageFindConversations(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageFindConversations() is deprecated and will be removed "
+ "from next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingRead, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageStorageRemoveConversations(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageRemoveConversations() is deprecated and will be removed "
+ "from next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingWrite, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
void MessagingInstance::MessageStorageFindFolders(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageFindFolders() is deprecated and will be removed from next "
+ "release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingRead, &out);
CHECK_EXIST(args, JSON_CALLBACK_ID, out);
- picojson::object data = args.get<picojson::object>();
- const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
+ const auto& data = args.get<picojson::object>();
+ auto service = manager_.getMessageService(getServiceIdFromJSON(data));
- auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
- picojson::object& obj = json->get<picojson::object>();
- obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
+ auto task_params = new FindFoldersTaskParams();
+ task_params->instance = this;
+ task_params->callback_id = args.get(JSON_CALLBACK_ID).get<double>();
+ task_params->account_id = service->getMsgServiceId();
+ task_params->message_type = service->getMsgServiceTypeString();
- AbstractFilterPtr filter;
- PlatformResult ret = MessagingUtil::jsonToAbstractFilter(data, &filter);
+ PlatformResult ret = MessagingUtil::jsonToAbstractFilter(data, &(task_params->filter));
if (ret.IsError()) {
- POST_AND_RETURN(ret, json, obj)
+ LoggerE("Cannot convert json to AbstractFilter: %s", args.serialize().c_str());
+ ReportError(ret, &out);
+ delete task_params;
+ return;
}
- FoldersCallbackData* callback = new FoldersCallbackData(queue_, callbackId, *this);
- callback->setFilter(filter);
-
- callback->AddToQueue();
- auto service = manager_.getMessageService(getServiceIdFromJSON(data));
- service->getMsgStorage()->findFolders(callback);
+ service->getMsgStorage()->findFolders(task_params);
}
void MessagingInstance::MessageStorageAddMessagesChangeListener(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageAddMessagesChangeListener() is deprecated and will be "
+ "removed from next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingRead, &out);
void MessagingInstance::MessageStorageAddConversationsChangeListener(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageAddConversationsChangeListener() is deprecated and will "
+ "be removed from next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingRead, &out);
void MessagingInstance::MessageStorageAddFolderChangeListener(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageAddFolderChangeListener() is deprecated and will be "
+ "removed from next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingRead, &out);
auto service = manager_.getMessageService(serviceId);
- std::shared_ptr<FoldersChangeCallback> callback(new FoldersChangeCallback(
- static_cast<long>(-1), serviceId, service->getMsgServiceType(), queue_, *this));
+ std::shared_ptr<FoldersChangeCallback> callback(
+ new FoldersChangeCallback(serviceId, service->getMsgServiceType(), *this));
callback->setFilter(filter);
void MessagingInstance::MessageStorageRemoveChangeListener(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageStorageRemoveChangeListener() is deprecated and will be removed "
+ "from next release without any alternatives.",
+ "8.0");
CHECK_PRIVILEGE_ACCESS(kPrivilegeMessagingRead, &out);
void MessagingInstance::MessageGetMessageStatus(const picojson::value& args,
picojson::object& out) {
ScopeLogger();
+ DEPRECATION_WARN(
+ "MessageGetMessageStatus() is deprecated and will be removed from next "
+ "release without any alternatives.",
+ "8.0");
picojson::object data = args.get<picojson::object>();
const int id = stoi(data.at("id").get<std::string>());