#include "Ecore_File.h"
#include "message_email.h"
#include "message_sms.h"
+#include "short_message_manager.h"
#include "messaging_util.h"
namespace extension {
{
m_id = id;
m_id_set = true;
-// m_body->setMessageId(m_id);
+ m_body->setMessageId(m_id);
}
void Message::setConversationId(int id)
return message;
}
+std::shared_ptr<Message> Message::findShortMessageById(const int id) {
+
+ msg_struct_t msg = ShortMsgManager::getInstance().getMessage(id);
+ std::shared_ptr<Message> message(
+ Message::convertPlatformShortMessageToObject(msg));
+
+ return message;
+}
+
std::vector<std::string> Message::split(const std::string& input,
char delimiter)
{
int type);
// function for filling Message attributes
static Message* convertPlatformShortMessageToObject(msg_struct_t msg);
+ static std::shared_ptr<Message> findShortMessageById(const int id);
static void addMMSBodyAndAttachmentsToStruct(const AttachmentPtrVector attach,
msg_struct_t &mms_struct,
Message* message);
//
#include "message_service_short_msg.h"
+#include "messaging_instance.h"
#include "common/logger.h"
#include "common/platform_exception.h"
}
try {
- // TODO call success callback
- //JSContextRef context = callback->getContext();
- //JSObjectRef jsMessage = JSMessage::makeJSObject(context, callback->getMessage());
- //callback->callSuccessCallback(jsMessage);
+ std::shared_ptr<MessageBody> body = callback->getMessage()->getBody();
+ body->setLoaded(true);
+ auto json = callback->getJson();
+ picojson::object& obj = json->get<picojson::object>();
+ obj[JSON_ACTION] = picojson::value(JSON_CALLBACK_SUCCCESS);
+
+ picojson::object args;
+ args[JSON_DATA_MESSAGE_BODY] = MessagingUtil::messageBodyToJson(body);
+ obj[JSON_DATA] = picojson::value(args);
+
+ MessagingInstance::getInstance().PostMessage(json->serialize().c_str());
} catch (...) {
LoggerE("Couldn't create JSMessage object!");
- // TODO call error callback
- //callback->callErrorCallback();
+ common::UnknownException e("Loade message body failed");
+ callback->setError(e.name(), e.message());
+ MessagingInstance::getInstance().PostMessage(callback->getJson()->serialize().c_str());
}
return FALSE;
{
get: function () {return _internal.body;},
set: function (value) {
- if (value instanceof InternalValues_) value = value.body;
+ if (value instanceof InternalValues_) _internal.body = new MessageBody(value.body);
if (value instanceof MessageBody) _internal.body = value;
},
enumerable: true
success: function (data) {
var body = data.messageBody;
if (body) {
- args.message.body = new MessageBody(data.messageBody);
+ args.message.body = new MessageBody(body);
}
args.successCallback.call(
switch (mtype) {
case MessageType::SMS:
LoggerD("SMS type");
- message = std::shared_ptr<Message>(new MessageSMS());
- // TODO check if id exists
+ if (!data.at(MESSAGE_ATTRIBUTE_ID).is<picojson::null>()) {
+ std::string mid = data.at(MESSAGE_ATTRIBUTE_ID).get<std::string>();
+ int message_id = std::atoi(mid.c_str());
+ message = Message::findShortMessageById(message_id);
+ } else {
+ message = std::shared_ptr<Message>(new MessageSMS());
+ }
break;
case MessageType::MMS:
LoggerD("Currently unsupported");
MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY);
message->setIsHighPriority(priority);
- std::shared_ptr<MessageBody> body = std::shared_ptr<MessageBody>(new MessageBody());
- picojson::object mb = MessagingUtil::getValueFromJSONObject<picojson::object>(
- data, MESSAGE_ATTRIBUTE_MESSAGE_BODY);
-
- bool loaded = MessagingUtil::getValueFromJSONObject<bool>(mb,
- MESSAGE_BODY_ATTRIBUTE_LOADED);
- body->setLoaded(loaded);
-
- std::string html = MessagingUtil::getValueFromJSONObject<std::string>(mb,
- MESSAGE_BODY_ATTRIBUTE_HTML_BODY);
- body->setHtmlBody(html);
-
- std::string plain = MessagingUtil::getValueFromJSONObject<std::string>(mb,
- MESSAGE_BODY_ATTRIBUTE_PLAIN_BODY);
- body->setPlainBody(plain);
-
+ std::shared_ptr<MessageBody> body = MessagingUtil::jsonToMessageBody(
+ data[MESSAGE_ATTRIBUTE_MESSAGE_BODY]);
message->setBody(body);
AttachmentPtrVector attachments;
}
+std::shared_ptr<MessageBody> MessagingUtil::jsonToMessageBody(const picojson::value& json)
+{
+ LoggerD("Entered");
+
+ std::shared_ptr<MessageBody> body = std::shared_ptr<MessageBody>(new MessageBody());
+ picojson::object data = json.get<picojson::object>();
+
+ bool loaded = MessagingUtil::getValueFromJSONObject<bool>(data,
+ MESSAGE_BODY_ATTRIBUTE_LOADED);
+ body->setLoaded(loaded);
+
+ std::string html = MessagingUtil::getValueFromJSONObject<std::string>(data,
+ MESSAGE_BODY_ATTRIBUTE_HTML_BODY);
+ body->setHtmlBody(html);
+
+ std::string plain = MessagingUtil::getValueFromJSONObject<std::string>(data,
+ MESSAGE_BODY_ATTRIBUTE_PLAIN_BODY);
+ body->setPlainBody(plain);
+
+ if (!data.at(MESSAGE_BODY_ATTRIBUTE_MESSAGE_ID).is<picojson::null>()) {
+ int messageId = std::atoi(MessagingUtil::getValueFromJSONObject<std::string>(data,
+ MESSAGE_BODY_ATTRIBUTE_MESSAGE_ID).c_str());
+ body->setMessageId(messageId);
+ }
+
+ return body;
+}
+
std::shared_ptr<MessageFolder> MessagingUtil::jsonToMessageFolder(const picojson::value& json)
{
LoggerD("Entered");
static picojson::value conversationToJson(std::shared_ptr<MessageConversation> conversation);
static picojson::value folderToJson(std::shared_ptr<MessageFolder> folder);
static std::shared_ptr<Message> jsonToMessage(const picojson::value& json);
+ static std::shared_ptr<MessageBody> jsonToMessageBody(const picojson::value& json);
static std::shared_ptr<MessageFolder> jsonToMessageFolder(const picojson::value& json);
static tizen::SortModePtr jsonToSortMode(const picojson::object& json);
static tizen::AttributeFilterPtr jsonToAttributeFilter(const picojson::object& json);