get: function () {return _internal.isHighPriority;},
set: function (value) {
if (value instanceof InternalValues_) value = value.isHighPriority;
- _internal.isHighPriority = value;
+ _internal.isHighPriority = !!value;
},
enumerable: true
}
get: function () {return _internal.subject;},
set: function (value) {
if (value instanceof InternalValues_) value = value.subject;
- if (typeof value !== 'string') return;
- _internal.subject = value;
+ _internal.subject = String(value);
},
enumerable: true
}
if (!this.messageId) {
propertyFactory_(this, 'messageId', null, Property.E);
}
- propertyFactory_(this, 'mimeType', mimeType || '', Property.E);
+ propertyFactory_(this, 'mimeType', mimeType || null, Property.E);
propertyFactory_(this, 'filePath', filePath || '', Property.E);
return this;
};
function MessageFolder(data) {
- propertyFactory_(this, 'id' , data.id || null , Property.E );
- propertyFactory_(this, 'parentId' , data.parentId || null , Property.E );
- propertyFactory_(this, 'serviceId' , data.serviceId || '' , Property.E );
- propertyFactory_(this, 'contentType' , data.contentType || '' , Property.E );
- propertyFactory_(this, 'name' , data.name || '' , Property.E | Property.W); // TODO: setraises
- propertyFactory_(this, 'path' , data.path || '' , Property.E );
- propertyFactory_(this, 'type' , data.type || '' , Property.E );
- propertyFactory_(this, 'synchronizable', data.synchronizable || false, Property.E | Property.W); // TODO: setraises
+ var _internal = {
+ id: data.id || null,
+ parentId: data.parentId || null,
+ serviceId: data.serviceId || '',
+ contentType: data.contentType || '',
+ name: data.name || '',
+ path: data.path || '',
+ type: data.type || '',
+ synchronizable: data.synchronizable || false
+ };
+
+ Object.defineProperty(
+ this,
+ 'id',
+ {
+ get: function () {return _internal.id;},
+ enumerable: true
+ }
+ );
+
+ Object.defineProperty(
+ this,
+ 'parentId',
+ {
+ get: function () {return _internal.parentId;},
+ enumerable: true
+ }
+ );
+
+ Object.defineProperty(
+ this,
+ 'serviceId',
+ {
+ get: function () {return _internal.serviceId;},
+ enumerable: true
+ }
+ );
+
+ Object.defineProperty(
+ this,
+ 'contentType',
+ {
+ get: function () {return _internal.contentType;},
+ enumerable: true
+ }
+ );
+
+ Object.defineProperty(
+ this,
+ 'name',
+ {
+ get: function () {return _internal.name;},
+ set: function (value) { if (value) _internal.name = value;},
+ enumerable: true
+ }
+ );
+
+ Object.defineProperty(
+ this,
+ 'path',
+ {
+ get: function () {return _internal.path;},
+ enumerable: true
+ }
+ );
+
+ Object.defineProperty(
+ this,
+ 'type',
+ {
+ get: function () {return _internal.type;},
+ enumerable: true
+ }
+ );
+
+ Object.defineProperty(
+ this,
+ 'synchronizable',
+ {
+ get: function () {return _internal.synchronizable;},
+ set: function (value) { if (value) _internal.synchronizable = value;},
+ enumerable: true
+ }
+ );
};
tizen.Message = Message;
#include "messaging_instance.h"
#include <sstream>
+#include <stdexcept>
#include "common/logger.h"
const char* REMOVE_CHANGE_LISTENER_ARGS_WATCHID = "watchId";
const char* FUNCTIONS_HIDDEN_ARGS_SERVICE_ID = "serviceId";
+
+auto getServiceIdFromJSON = [](picojson::object& data) -> int {
+ std::string serviceStrId;
+ try {
+ serviceStrId =
+ MessagingUtil::getValueFromJSONObject<std::string>(data,FUNCTIONS_HIDDEN_ARGS_SERVICE_ID);
+ return std::stoi(serviceStrId);
+ }
+ catch(...) {
+ return -1;
+ }
+};
+
}
MessagingInstance& MessagingInstance::getInstance()
MessagingManager::getInstance().getMessageServices(serviceTag.to_str(), callbackId);
}
-/* Code used to testing in node.js console
- // Define the success callback.
- function serviceListCB(services) {
- if (services.length > 0) {
- var initDictionary = {
- subject: "Testing subject",
- to: ["r.klepaczko.testmail@gmail.com"],
- cc: ["r.klepaczko.testmail@gmail.com"],
- bcc: ["r.klepaczko.testmail@gmail.com"],
- plainBody: "simple plain body",
- htmlBody: "simle html body",
- isHightPriority: false
- }
- msg = new tizen.Message("messaging.email", initDictionary);
- msg.attachments = [new tizen.MessageAttachment("images/myimage.png", "image/png")];
- services[0].sendMessage(msg, function(data){
- console.log("Send email success");
- console.dir(data);
- }, function(){
- console.log("Send email failed");
- });
- }
- }
- tizen.messaging.getMessageServices("messaging.email", serviceListCB);
- */
void MessagingInstance::MessageServiceSendMessage(const picojson::value& args,
picojson::object& out)
{
MessageRecipientsCallbackData* callback = new MessageRecipientsCallbackData();
callback->setMessage(MessagingUtil::jsonToMessage(v_message));
- auto serviceId = static_cast<int>
- (MessagingUtil::getValueFromJSONObject<double>(data,FUNCTIONS_HIDDEN_ARGS_SERVICE_ID));
+ int serviceId = getServiceIdFromJSON(data);
callback->setAccountId(serviceId);
auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
MessageBodyCallbackData* callback = new MessageBodyCallbackData();
callback->setMessage(MessagingUtil::jsonToMessage(message));
- auto serviceId = static_cast<int>(
- MessagingUtil::getValueFromJSONObject<double>(data, FUNCTIONS_HIDDEN_ARGS_SERVICE_ID));
-
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);
callback->setJson(json);
- auto service = MessagingManager::getInstance().getMessageService(serviceId);
+ auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data));
service->loadMessageBody(callback);
}
MessageAttachmentCallbackData* callback = new MessageAttachmentCallbackData();
callback->setMessageAttachment(MessagingUtil::jsonToMessageAttachment(attachment));
- int serviceId = static_cast<int>(
- MessagingUtil::getValueFromJSONObject<double>(data, FUNCTIONS_HIDDEN_ARGS_SERVICE_ID));
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);
callback->setJson(json);
- auto service = MessagingManager::getInstance().getMessageService(serviceId);
+ auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data));
service->loadMessageAttachment(callback);
}
picojson::value v_limit = data.at(SYNC_ARGS_LIMIT);
const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
- int id = static_cast<int>(v_id.get<double>());
+ int id = -1;
+ try{
+ id = std::stoi(v_id.get<std::string>());
+ } catch(...) {
+ LoggerE("Problem with MessageService");
+ throw common::UnknownException("Problem with MessageService");
+ }
long limit = 0;
if (v_limit.is<double>()) {
limit = static_cast<long>(v_limit.get<double>());
picojson::value v_limit = data.at(SYNC_FOLDER_ARGS_LIMIT);
const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
- int id = static_cast<int>(v_id.get<double>());
+ int id = -1;
+ try{
+ id = std::stoi(v_id.get<std::string>());
+ } catch(...) {
+ LoggerE("Problem with MessageService");
+ throw common::UnknownException("Problem with MessageService");
+ }
+
long limit = 0;
if (v_limit.is<double>()) {
limit = static_cast<long>(v_limit.get<double>());
LoggerD("Entered");
picojson::object data = args.get(JSON_DATA).get<picojson::object>();
- picojson::value v_id = data.at(STOP_SYNC_ARGS_ID);
- picojson::value v_op_id = data.at(STOP_SYNC_ARGS_OPID);
-
- int id = static_cast<int>(v_id.get<double>());
- long op_id = 0;
- if (v_op_id.is<double>()) {
- op_id = static_cast<long>(v_op_id.get<double>());
+ if(data.find(STOP_SYNC_ARGS_ID) != data.end()){
+ picojson::value v_id = data.at(STOP_SYNC_ARGS_ID);
+ picojson::value v_op_id = data.at(STOP_SYNC_ARGS_OPID);
+
+ int id = -1;
+ try{
+ id = std::stoi(v_id.get<std::string>());
+ } catch(...){
+ LoggerD("Problem with MessageService");
+ throw common::UnknownException("Problem with MessageService");
+ }
+
+ long op_id = 0;
+ if (v_op_id.is<double>()) {
+ op_id = static_cast<long>(v_op_id.get<double>());
+ }
+ MessagingManager::getInstance().getMessageService(id)->stopSync(op_id);
+ } else {
+ LoggerE("Unknown error");
+ throw common::UnknownException("Unknown error");
}
- MessagingManager::getInstance().getMessageService(id)->stopSync(op_id);
-
ReportSuccess(out);
}
-/* Code used to testing in node.js console
- // Define the success callback.
- function serviceListCB(services) {
- if (services.length > 0) {
- var initDictionary = {
- subject: "Testing subject",
- to: ["a.jacak.testmail@gmail.com", "r.klepaczko.testmail@gmail.com"],
- cc: ["a.jacak.testmail@gmail.com", "r.klepaczko.testmail@gmail.com"],
- bcc: ["a.jacak.testmail@gmail.com", "r.klepaczko.testmail@gmail.com"],
- plainBody: "simple plain body",
- htmlBody: "simle html body",
- isHightPriority: false
- }
- msg = new tizen.Message("messaging.email", initDictionary);
- msg.attachments = [new tizen.MessageAttachment("images/myimage.png", "image/png")];
- services[0].messageStorage.addDraftMessage(msg, function(){
- console.log("Add draft success");
- }, function(){
- console.log("Add draft failed");
- });
- }
- }
- tizen.messaging.getMessageServices("messaging.email", serviceListCB);
- */
void MessagingInstance::MessageStorageAddDraft(const picojson::value& args,
picojson::object& out)
{
MessageCallbackUserData* callback = new MessageCallbackUserData();
callback->setMessage(MessagingUtil::jsonToMessage(v_message));
- auto serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
+ int serviceId = getServiceIdFromJSON(data);
callback->setAccountId(serviceId);
auto json = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
long offset = static_cast<long>
(MessagingUtil::getValueFromJSONObject<double>(data, FIND_FOLDERS_ARGS_OFFSET));
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
+ int serviceId = getServiceIdFromJSON(data);
auto storage = MessagingManager::getInstance().getMessageService(serviceId)->getMsgStorage();
FindMsgCallbackUserData* callback = new FindMsgCallbackUserData();
obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
callback->setJson(json);
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
- auto service = MessagingManager::getInstance().getMessageService(serviceId);
+ auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data));
service->getMsgStorage()->removeMessages(callback);
}
obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
callback->setJson(json);
- int serviceId = static_cast<int>
- (MessagingUtil::getValueFromJSONObject<double>(data,FUNCTIONS_HIDDEN_ARGS_SERVICE_ID));
- auto service = MessagingManager::getInstance().getMessageService(serviceId);
+ auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data));
service->getMsgStorage()->updateMessages(callback);
}
(MessagingUtil::getValueFromJSONObject<double>(data, FIND_CONVERSATIONS_ARGS_LIMIT));
long offset = static_cast<long>
(MessagingUtil::getValueFromJSONObject<double>(data, FIND_CONVERSATIONS_ARGS_OFFSET));
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
+
+ int serviceId = getServiceIdFromJSON(data);
ConversationCallbackData* callback = new ConversationCallbackData();
callback->setFilter(filter);
obj[JSON_CALLBACK_ID] = picojson::value(callbackId);
callback->setJson(json);
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
- auto service = MessagingManager::getInstance().getMessageService(serviceId);
+ auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data));
service->getMsgStorage()->removeConversations(callback);
}
picojson::object data = args.get(JSON_DATA).get<picojson::object>();
const double callbackId = args.get(JSON_CALLBACK_ID).get<double>();
-
// TODO add support to CompositeFilter
auto filter = MessagingUtil::jsonToAbstractFilter(data);
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
FoldersCallbackData* callback = new FoldersCallbackData();
callback->setFilter(filter);
-
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);
callback->setJson(json);
-
- auto storage = MessagingManager::getInstance().getMessageService(serviceId)->getMsgStorage();
- storage->findFolders(callback);
+ auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data));
+ service->getMsgStorage()->findFolders(callback);
}
void MessagingInstance::MessageStorageAddMessagesChangeListener(const picojson::value& args,
picojson::object data = args.get(JSON_DATA).get<picojson::object>();
const long callbackId = static_cast<long>(args.get(JSON_CALLBACK_ID).get<double>());
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
+ int serviceId = getServiceIdFromJSON(data);
+
auto service = MessagingManager::getInstance().getMessageService(serviceId);
std::shared_ptr<MessagesChangeCallback> callback(new MessagesChangeCallback(
picojson::object data = args.get(JSON_DATA).get<picojson::object>();
const long callbackId = static_cast<long>(args.get(JSON_CALLBACK_ID).get<double>());
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
+ int serviceId = getServiceIdFromJSON(data);
+
auto service = MessagingManager::getInstance().getMessageService(serviceId);
std::shared_ptr<ConversationsChangeCallback> callback(new ConversationsChangeCallback(
picojson::object data = args.get(JSON_DATA).get<picojson::object>();
const long callbackId = static_cast<long>(args.get(JSON_CALLBACK_ID).get<double>());
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
+ int serviceId = getServiceIdFromJSON(data);
+
auto service = MessagingManager::getInstance().getMessageService(serviceId);
std::shared_ptr<FoldersChangeCallback> callback(new FoldersChangeCallback(
const long watchId = static_cast<long>(
data.at(REMOVE_CHANGE_LISTENER_ARGS_WATCHID).get<double>());
- int serviceId = static_cast<int>(data.at(FUNCTIONS_HIDDEN_ARGS_SERVICE_ID).get<double>());
- auto service = MessagingManager::getInstance().getMessageService(serviceId);
+ auto service = MessagingManager::getInstance().getMessageService(getServiceIdFromJSON(data));
service->getMsgStorage()->removeChangeListener(watchId);
ReportSuccess(out);