2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 * @author Pawel Misiak (p.misiak@samsung.com)
27 #include <dpl/assert.h>
28 #include <API/Messaging/MessageFactory.h>
29 #include <API/Messaging/MessagePriority.h>
30 #include <CommonsJavaScript/JSCallbackManager.h>
31 #include <CommonsJavaScript/JSUtils.h>
32 #include <CommonsJavaScript/Utils.h>
33 #include "ConverterMessage.h"
34 #include "JSMessage.h"
35 #include "JSRecipientArray.h"
36 #include "JSMessagePrivateObject.h"
37 #include "JSMessagingListener.h"
38 #include <API/Messaging/ReqReceiverMessage.h>
40 #include <Tizen/Common/JSTizenExceptionFactory.h>
41 #include <Tizen/Common/JSTizenException.h>
42 #include <Tizen/Common/SecurityExceptions.h>
44 #include <CommonsJavaScript/ScopedJSStringRef.h>
46 #include "MessagingErrorMsg.h"
47 #include "JSMessageAttachment.h"
48 #include "plugin_config.h"
50 #include <Messaging/Sms.h>
54 using namespace TizenApis::Api::Messaging;
55 using namespace TizenApis::Commons;
56 using namespace WrtDeviceApis::Commons;
57 using namespace TizenApis::Platform::Messaging;
58 using namespace WrtDeviceApis::CommonsJavaScript;
62 JSClassRef JSMessage::m_jsClassRef = NULL;
64 JSClassDefinition JSMessage::m_classInfo = {
66 kJSClassAttributeNone,
76 NULL, //deleteProperty,
77 NULL, //getPropertyNames,
78 NULL, //callAsFunction,
79 constructor, //callAsConstructor,
81 NULL, //convertToType,
84 // JSMessage properties
85 JSStaticValue JSMessage::m_property[] = {
86 { "id", getMessageId, NULL, kJSPropertyAttributeReadOnly },
87 { "serviceId", getAccountID, NULL, kJSPropertyAttributeReadOnly},
88 { "conversationId", getConversationId, NULL, kJSPropertyAttributeReadOnly },
89 { "folderId", getFolder, NULL, kJSPropertyAttributeReadOnly },
90 { "type", getMessageType, NULL, kJSPropertyAttributeReadOnly },
91 { "timestamp", getTime, NULL, kJSPropertyAttributeReadOnly },
92 { "from", getSourceAddress, NULL, kJSPropertyAttributeReadOnly },
93 { "to", getDestinationAddress, setDestinationAddress, kJSPropertyAttributeNone },
94 { "cc", getCcAddress, setCcAddress, kJSPropertyAttributeNone },
95 { "bcc", getBccAddress, setBccAddress, kJSPropertyAttributeNone },
96 { "body", getMessageBody, setMessageBody, kJSPropertyAttributeNone },
97 { "isRead", getIsRead, setIsRead, kJSPropertyAttributeNone },
98 //{ "hasAttachment", getAttachmentExistence, NULL, kJSPropertyAttributeReadOnly },
99 { "priority", getMessagePriority, setMessagePriority, kJSPropertyAttributeNone },
100 { "subject", getSubject, setSubject, kJSPropertyAttributeNone },
101 { "inResponseTo", getInResponseTo, NULL, kJSPropertyAttributeNone },
102 { "messageStatus", getMessageStatus, NULL, kJSPropertyAttributeReadOnly},
103 { "attachments", getAttachments, setAttachments, kJSPropertyAttributeNone },
104 { "hasAttachment", hasAttachment, NULL, kJSPropertyAttributeReadOnly},
105 //{ "uid", getUID, NULL, kJSPropertyAttributeReadOnly},
109 JSValueRef JSMessage::createJSObject(JSContextRef context,
110 Api::Messaging::EmailAccountInfo& account,
111 Api::Messaging::MessageType msgType,
112 const std::string& msgId)
114 Api::Messaging::IMessagePtr msg;
115 LogDebug("createJSObject with account ");
119 if (msgType == Api::Messaging::EMAIL) {
120 LogDebug("Account Address:" << &account);
121 LogDebug("Account Data ,ID" << account.getId() << "name:" << account.getName() << " Account:" << account.getAddress());
123 msg = Api::Messaging::MessageFactory::createMessage(msgType, account, msgId);
125 return JSValueMakeUndefined(context);
127 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
130 Catch(WrtDeviceApis::Commons::UnknownException) {
131 LogError("wrong message type, object not created");
132 return JSValueMakeUndefined(context);
135 return createJSObject(context, msg);
138 JSValueRef JSMessage::createJSObject(JSContextRef context,
139 Api::Messaging::EventUpdateMessageAnswerReceiver* listener,
140 Api::Messaging::MessageType msgType,
143 Api::Messaging::IMessagePtr msg;
146 // create message depending on type
147 if (msgType == Api::Messaging::SMS || msgType == Api::Messaging::MMS || msgType == Api::Messaging::EMAIL) {
148 msg = Api::Messaging::MessageFactory::createMessage(msgType, msgId);
150 return JSValueMakeUndefined(context);
152 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
155 Catch(WrtDeviceApis::Commons::UnknownException) {
156 LogError("wrong message type, object not created");
157 return JSValueMakeUndefined(context);
159 return createJSObject(context, msg, listener);
162 JSValueRef JSMessage::createJSObject(JSContextRef context,
163 const Api::Messaging::IMessagePtr& msg,
164 Api::Messaging::EventUpdateMessageAnswerReceiver* listener)
166 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
167 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
168 priv->setUpdateMsgReceiver(listener);
169 JSObjectRef jsValueRef =
170 JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
171 JSClassRelease(jsClassRef);
172 if (NULL == jsValueRef) {
173 LogError("object creation error");
174 return JSValueMakeUndefined(context);
179 JSValueRef JSMessage::createJSObject(JSContextRef context,
180 const Api::Messaging::IMessagePtr& msg)
182 LogDebug("createJSObject");
183 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
184 LogDebug("jsClassRef success");
185 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
186 LogDebug("priv success");
188 JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
189 LogDebug("JSObjectMake success");
190 JSClassRelease(jsClassRef);
191 if (NULL == jsValueRef) {
192 LogError("object creation error");
193 return JSValueMakeUndefined(context);
198 JSValueRef JSMessage::createJSObject(JSContextRef context,
199 Api::Messaging::MessageType msgType,
202 Api::Messaging::IMessagePtr msg;
205 // create message depending on type
206 if (msgType == Api::Messaging::SMS || msgType == Api::Messaging::MMS || msgType == Api::Messaging::EMAIL) {
207 msg = Api::Messaging::MessageFactory::createMessage(msgType, msgId);
209 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
212 Catch(WrtDeviceApis::Commons::UnknownException) {
213 LogError("wrong message type, object not created");
214 return JSValueMakeUndefined(context);
216 return createJSObject(context, msg, NULL);
219 JSValueRef JSMessage::createDummyMessageJSObject(JSContextRef context,
220 Api::Messaging::MessageType msgType)
222 Api::Messaging::IMessagePtr msg;
224 if (msgType == Api::Messaging::EMAIL )
226 msg = Api::Messaging::MessageFactory::createEmailMessage();
230 LogError("message type is invalid");
231 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
234 return createJSObject(context, msg);
237 void JSMessage::initialize(JSContextRef context,
243 if (!JSObjectGetPrivate(object)) {
244 IMessagePtr msg(new Sms());
245 JSMessagePrivateObject *priv = new JSMessagePrivateObject(context, msg);
246 if (!JSObjectSetPrivate(object, priv)) {
247 LogInfo("set Private Failed...");
254 void JSMessage::finalize(JSObjectRef object)
256 JSMessagePrivateObject* priv =
257 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
259 LogDebug("deleting private object");
261 JSObjectSetPrivate(object, NULL);
265 bool JSMessage::hasProperty(JSContextRef context,
267 JSStringRef propertyName)
272 JSValueRef JSMessage::getProperty(JSContextRef context,
274 JSStringRef propertyName,
275 JSValueRef* exception)
277 LogError("should not enter");
278 return JSValueMakeUndefined(context);
281 bool JSMessage::setProperty(JSContextRef context,
283 JSStringRef propertyName,
285 JSValueRef* exception)
287 LogError("should not enter");
291 bool JSMessage::deleteProperty(JSContextRef context,
293 JSStringRef propertyName,
294 JSValueRef* exception)
300 void JSMessage::getPropertyNames(JSContextRef context,
302 JSPropertyNameAccumulatorRef propertyNames)
307 JSValueRef JSMessage::callAsFunction(JSContextRef context,
309 JSObjectRef thisObject,
310 size_t argumentCount,
311 const JSValueRef arguments[],
312 JSValueRef* exception)
315 return JSValueMakeUndefined(context);
318 bool JSMessage::hasInstance(JSContextRef context,
319 JSObjectRef constructor,
320 JSValueRef possibleInstance,
321 JSValueRef* exception)
327 JSObjectRef JSMessage::constructor(JSContextRef context,
328 JSObjectRef constructor,
329 size_t argumentCount,
330 const JSValueRef arguments[],
331 JSValueRef* exception)
335 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(constructor));
336 JSContextRef globalContext = priv ? priv->getContext() : context;
343 if ( argumentCount < 1 || argumentCount > 2) {
344 LogError("Wrong argument count");
345 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong Message argumentCount");
349 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
351 JSValueRef objMsg = NULL;
352 Api::Messaging::MessageType msgType = converter->toMessageType(arguments[0]);
354 //objMsg = JSMessage::createDummyMessageJSObject(globalContext, msgType); //make message JSValueRef.
356 Api::Messaging::IMessagePtr msg;
358 if ( msgType == Api::Messaging::EMAIL )
360 msg = Api::Messaging::MessageFactory::createEmailMessage();
362 else if (msgType == Api::Messaging::MMS || msgType == Api::Messaging::SMS)
364 msg = Api::Messaging::MessageFactory::createMessage(msgType); //create message
368 LogError("message type is invalid");
369 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
374 if ( argumentCount == 2 )
376 LogDebug ("##### msg type is " << msgType);
378 const ScopedJSStringRef subjectStr(JSStringCreateWithUTF8CString("subject"));
379 const ScopedJSStringRef toStr(JSStringCreateWithUTF8CString("to"));
380 const ScopedJSStringRef ccStr(JSStringCreateWithUTF8CString("cc"));
381 const ScopedJSStringRef bccStr(JSStringCreateWithUTF8CString("bcc"));
382 const ScopedJSStringRef plainBodyStr(JSStringCreateWithUTF8CString("plainBody"));
383 const ScopedJSStringRef htmlBodyStr(JSStringCreateWithUTF8CString("htmlBody"));
384 const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("priority"));
386 JSObjectRef arg = converter->toJSObjectRef(arguments[1]); //get dictionary
387 JSValueRef subjectData = JSObjectGetProperty(globalContext, arg, subjectStr.get(), NULL);
388 JSValueRef toData = JSObjectGetProperty(globalContext, arg, toStr.get(), NULL);
389 JSValueRef ccData = JSObjectGetProperty(globalContext, arg, ccStr.get(), NULL);
390 JSValueRef bccData = JSObjectGetProperty(globalContext, arg, bccStr.get(), NULL);
391 JSValueRef plainBodyData = JSObjectGetProperty(globalContext, arg, plainBodyStr.get(), NULL);
392 JSValueRef htmlBodyData = JSObjectGetProperty(globalContext, arg, htmlBodyStr.get(), NULL);
393 JSValueRef priorityData = JSObjectGetProperty(globalContext, arg, priorityStr.get(), NULL);
396 if (!JSValueIsUndefined(globalContext, subjectData) )
398 LogDebug ( " Subject : " << converter->toString(subjectData) );
399 std::string subject = converter->toString(subjectData);
402 case Api::Messaging::MMS:
404 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
405 mms->setSubject(subject);
408 case Api::Messaging::EMAIL:
410 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
411 email->setSubject(subject);
416 LogError("message not supported");
417 //Throw(WrtDeviceApis::Commons::UnsupportedException);
423 if (!JSValueIsUndefined(globalContext, toData) )
425 Api::Messaging::Recipients to = converter->toRecipients(toData);
426 LogDebug("setting to field, size=" << to.getRecipientSize());
427 msg->setToRecipients(to);
430 if (msgType == Api::Messaging::EMAIL )
432 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
433 if (!JSValueIsUndefined(globalContext, ccData))
435 Api::Messaging::Recipients cc = converter->toRecipients(ccData);
436 email->setCcRecipients(cc);
439 if (!JSValueIsUndefined(globalContext, bccData))
441 Api::Messaging::Recipients bcc = converter->toRecipients(bccData);
442 email->setBccRecipients(bcc);
445 if (!JSValueIsUndefined(globalContext, htmlBodyData))
447 std::string body = converter->toString(htmlBodyData);
448 LogDebug("html body : " << body);
449 email->setHtmlBody(body);
452 if (!JSValueIsUndefined(globalContext, priorityData))
454 email->setPriority(converter->toMessagePriority(priorityData));
459 if (!JSValueIsUndefined(globalContext, plainBodyData) )
461 std::string body = converter->toString(plainBodyData);
462 LogDebug("plain body : " << body);
469 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
470 LogDebug("jsClassRef success");
471 JSMessagePrivateObject* priv = new JSMessagePrivateObject(globalContext, msg);
472 LogDebug("priv success");
474 JSObjectRef jsObjRef = JSObjectMake(globalContext, jsClassRef, static_cast<void*>(priv));
475 LogDebug("JSObjectMake success");
476 JSClassRelease(jsClassRef);
477 if (NULL == jsObjRef) {
478 LogError("object creation error");
479 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "JSObject make error");
486 LogDebug("Message Creation failed");
487 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "message has been not created");
493 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
494 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
497 Catch(WrtDeviceApis::Commons::ConversionException) {
498 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
501 Catch(WrtDeviceApis::Commons::PlatformException) {
502 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
509 LogDebug(" globalContext is NULL ");
510 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
517 JSValueRef JSMessage::convertToType(JSContextRef context,
520 JSValueRef* exception)
523 return JSValueMakeUndefined(context);
526 JSValueRef JSMessage::getAttachments(JSContextRef context,
528 JSStringRef propertyName,
529 JSValueRef* exception)
534 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
536 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
538 JSContextRef globalContext = priv->getContext();
540 ConverterMessageFactory::ConverterType converter =
541 ConverterMessageFactory::getConverter(context);
542 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
543 Api::Messaging::MessageType msgType = msg->getMessageType();
544 LogInfo("msgType=" << msgType);
545 // prepare common values
546 JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(
547 converter->toJSGlobalContext(object),
552 case Api::Messaging::MMS:
553 case Api::Messaging::EMAIL:
556 std::vector<IAttachmentPtr> attachments;
557 std::vector<IAttachmentPtr>::iterator it;
559 if ( msgType == Api::Messaging::MMS )
561 Api::Messaging::AttachmentsPtr mmsAttachments =
562 DPL::StaticPointerCast<Api::Messaging::Attachments>(Api::Messaging::MessageFactory::convertToMms(msg));
563 attachments = mmsAttachments->getAttachments();
567 Api::Messaging::AttachmentsPtr emailAttachments =
568 DPL::StaticPointerCast<Api::Messaging::Attachments>(Api::Messaging::MessageFactory::convertToEmail(msg));
569 attachments = emailAttachments->getAttachments();
572 int count = attachments.size();
573 LogDebug( "count : " << count);
575 JSObjectRef jsMessageAttachmentObject[count]; //make
577 for (int index = 0 ; index < attachments.size(); index++ )
579 LogDebug( "Attachment ID : " << attachments[index]->getAttachmentID());
580 jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(globalContext, attachments[index] );
582 JSObjectRef result = JSObjectMakeArray(globalContext, count, jsMessageAttachmentObject, NULL);
587 case Api::Messaging::SMS:
588 return JSValueMakeUndefined(context); // ignore
591 LogError("not supported message type");
592 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
595 Catch(WrtDeviceApis::Commons::ConversionException) {
596 LogError("Error on conversion");
597 return JSTizenExceptionFactory::postException(context, exception,
598 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
600 Catch(WrtDeviceApis::Commons::NullPointerException) {
601 LogError("Error on pointer, null value");
602 return JSTizenExceptionFactory::postException(context, exception,
603 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
605 return JSValueMakeUndefined(context);
609 JSValueRef JSMessage::getBccAddress(JSContextRef context,
611 JSStringRef propertyName,
612 JSValueRef* exception)
616 ConverterMessageFactory::ConverterType converter =
617 ConverterMessageFactory::getConverter(context);
618 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
619 Api::Messaging::MessageType msgType = msg->getMessageType();
622 case Api::Messaging::EMAIL:
624 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
625 Api::Messaging::RecipientsPtr recipient = email->getBccRecipientsPtr();
626 return JSRecipientArray::createArray(converter->toJSGlobalContext(
629 case Api::Messaging::SMS:
630 case Api::Messaging::MMS:
631 return JSValueMakeUndefined(context); // ignore
634 LogError("not supported message type");
635 return JSTizenExceptionFactory::postException(context, exception,
636 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
640 Catch(WrtDeviceApis::Commons::ConversionException) {
641 LogError("Error on conversion");
642 return JSTizenExceptionFactory::postException(context, exception,
643 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
645 Catch(WrtDeviceApis::Commons::NullPointerException) {
646 LogError("Error on pointer, null value");
647 return JSTizenExceptionFactory::postException(context, exception,
648 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
651 return JSValueMakeUndefined(context);
654 JSValueRef JSMessage::getBody(JSContextRef context,
656 JSStringRef propertyName,
657 JSValueRef* exception)
661 ConverterMessageFactory::ConverterType converter =
662 ConverterMessageFactory::getConverter(context);
663 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
664 string body = msg->getBody();
665 return converter->toJSValueRef(body);
667 Catch(WrtDeviceApis::Commons::ConversionException) {
668 LogError("Error on conversion");
669 return JSTizenExceptionFactory::postException(context, exception,
670 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
672 Catch(WrtDeviceApis::Commons::NullPointerException) {
673 LogError("Error on pointer, null value");
674 return JSTizenExceptionFactory::postException(context, exception,
675 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
678 return JSValueMakeUndefined(context);
681 JSValueRef JSMessage::getCcAddress(JSContextRef context,
683 JSStringRef propertyName,
684 JSValueRef* exception)
688 ConverterMessageFactory::ConverterType converter =
689 ConverterMessageFactory::getConverter(context);
690 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
691 Api::Messaging::MessageType msgType = msg->getMessageType();
694 case Api::Messaging::EMAIL:
696 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
697 Api::Messaging::RecipientsPtr recipient = email->getCcRecipientsPtr();
698 return JSRecipientArray::createArray(converter->toJSGlobalContext(
701 case Api::Messaging::MMS:
702 case Api::Messaging::SMS:
703 return JSValueMakeUndefined(context); // ignore
706 LogError("not supported message type");
707 return JSTizenExceptionFactory::postException(context, exception,
708 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
713 Catch(WrtDeviceApis::Commons::ConversionException) {
714 LogError("Error on conversion");
715 return JSTizenExceptionFactory::postException(context, exception,
716 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
718 Catch(WrtDeviceApis::Commons::NullPointerException) {
719 LogError("Error on pointer, null value");
720 return JSTizenExceptionFactory::postException(context, exception,
721 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
724 return JSValueMakeUndefined(context);
727 JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
729 JSStringRef propertyName,
730 JSValueRef* exception)
735 ConverterMessageFactory::ConverterType converter =
736 ConverterMessageFactory::getConverter(context);
737 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
738 Api::Messaging::RecipientsPtr recipient = msg->getToRecipientsPtr();
739 return JSRecipientArray::createArray(converter->toJSGlobalContext(
742 Catch(WrtDeviceApis::Commons::ConversionException) {
743 LogError("Error on conversion");
744 return JSTizenExceptionFactory::postException(context, exception,
745 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
747 Catch(WrtDeviceApis::Commons::NullPointerException) {
748 LogError("Error on pointer, null value");
749 return JSTizenExceptionFactory::postException(context, exception,
750 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
753 return JSValueMakeUndefined(context);
756 JSValueRef JSMessage::getIsRead(JSContextRef context,
758 JSStringRef propertyName,
759 JSValueRef* exception)
763 ConverterMessageFactory::ConverterType converter =
764 ConverterMessageFactory::getConverter(context);
765 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
766 bool isRead = msg->isRead();
767 return converter->toJSValueRef(isRead);
769 Catch(WrtDeviceApis::Commons::ConversionException) {
770 LogError("Error on conversion");
771 return JSTizenExceptionFactory::postException(context, exception,
772 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
774 Catch(WrtDeviceApis::Commons::NullPointerException) {
775 LogError("Error on pointer, null value");
776 return JSTizenExceptionFactory::postException(context, exception,
777 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
780 return JSValueMakeUndefined(context);
783 JSValueRef JSMessage::getMessageId(JSContextRef context,
785 JSStringRef propertyName,
786 JSValueRef* exception)
790 ConverterMessageFactory::ConverterType converter =
791 ConverterMessageFactory::getConverter(context);
792 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
793 const string& id = msg->getIdRef();
794 LogDebug("msgId=" << id);
795 return converter->toJSValueRef(id);
797 Catch(WrtDeviceApis::Commons::ConversionException) {
798 LogError("Error on conversion");
799 return JSTizenExceptionFactory::postException(context, exception,
800 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
802 Catch(WrtDeviceApis::Commons::NullPointerException) {
803 LogError("Error on pointer, null value");
804 return JSTizenExceptionFactory::postException(context, exception,
805 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
808 return JSValueMakeUndefined(context);
811 JSValueRef JSMessage::getMessagePriority(JSContextRef context,
813 JSStringRef propertyName,
814 JSValueRef* exception)
818 ConverterMessageFactory::ConverterType converter =
819 ConverterMessageFactory::getConverter(context);
820 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
821 Api::Messaging::MessageType msgType = msg->getMessageType();
824 case Api::Messaging::SMS:
825 case Api::Messaging::MMS:
826 return JSValueMakeUndefined(context);
828 case Api::Messaging::EMAIL:
830 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
831 return converter->toJSValueRef(static_cast<Api::Messaging::MessagePriority>(*
836 LogError("unsupported message type");
837 return JSTizenExceptionFactory::postException(context, exception,
838 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
842 Catch(WrtDeviceApis::Commons::ConversionException) {
843 LogError("Error on conversion");
844 return JSTizenExceptionFactory::postException(context, exception,
845 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
847 Catch(WrtDeviceApis::Commons::NullPointerException) {
848 LogError("Error on pointer, null value");
849 return JSTizenExceptionFactory::postException(context, exception,
850 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
853 return JSValueMakeUndefined(context);
856 JSValueRef JSMessage::getMessageType(JSContextRef context,
858 JSStringRef propertyName,
859 JSValueRef* exception)
863 ConverterMessageFactory::ConverterType converter =
864 ConverterMessageFactory::getConverter(context);
865 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
866 Api::Messaging::MessageType msgType = msg->getMessageType();
868 return converter->toJSValueRef(converter->toMessageType(msgType));
870 Catch(WrtDeviceApis::Commons::ConversionException) {
871 LogError("Error on conversion");
872 return JSTizenExceptionFactory::postException(context, exception,
873 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
875 Catch(WrtDeviceApis::Commons::NullPointerException) {
876 LogError("Error on pointer, null value");
877 return JSTizenExceptionFactory::postException(context, exception,
878 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
881 return JSValueMakeUndefined(context);
884 JSValueRef JSMessage::getSourceAddress(JSContextRef context,
886 JSStringRef propertyName,
887 JSValueRef* exception)
891 ConverterMessageFactory::ConverterType converter =
892 ConverterMessageFactory::getConverter(context);
893 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
895 //This property is set up by the device or the web runtime environment.
896 //This property should only be taken into account for Email.
897 // TODO Verify with Tizen.
898 // if (msg->getMessageType() != Api::Messaging::EMAIL && msg->getMessageType() != Api::VIRTUAL_MESSAGE) {
899 // return JSValueMakeUndefined(context);
901 return converter->toJSValueRef(msg->getSourceAddress());
903 Catch(WrtDeviceApis::Commons::ConversionException) {
904 LogError("Error on conversion");
905 return JSTizenExceptionFactory::postException(context, exception,
906 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
908 Catch(WrtDeviceApis::Commons::NullPointerException) {
909 LogError("Error on pointer, null value");
910 return JSTizenExceptionFactory::postException(context, exception,
911 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
914 return JSValueMakeUndefined(context);
917 JSValueRef JSMessage::getSubject(JSContextRef context,
919 JSStringRef propertyName,
920 JSValueRef* exception)
924 ConverterMessageFactory::ConverterType converter =
925 ConverterMessageFactory::getConverter(context);
926 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
927 Api::Messaging::MessageType msgType = msg->getMessageType();
930 case Api::Messaging::MMS:
932 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
933 return converter->toJSValueRef(mms->getSubject());
935 case Api::Messaging::EMAIL:
937 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
938 return converter->toJSValueRef(email->getSubject());
940 case Api::Messaging::SMS:
941 return JSValueMakeUndefined(context); // ignore
943 LogError("message not support subject");
944 return JSTizenExceptionFactory::postException(context, exception,
945 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
949 Catch(WrtDeviceApis::Commons::ConversionException) {
950 LogError("Error on conversion");
951 return JSTizenExceptionFactory::postException(context, exception,
952 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
954 Catch(WrtDeviceApis::Commons::NullPointerException) {
955 LogError("Error on pointer, null value");
956 return JSTizenExceptionFactory::postException(context, exception,
957 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
959 Catch(WrtDeviceApis::Commons::UnsupportedException) {
960 return JSTizenExceptionFactory::postException(context, exception,
961 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
963 return JSValueMakeUndefined(context);
966 JSValueRef JSMessage::getTime(JSContextRef context,
968 JSStringRef propertyName,
969 JSValueRef* exception)
973 ConverterMessageFactory::ConverterType converter =
974 ConverterMessageFactory::getConverter(context);
975 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
976 struct tm dateTime = msg->getDateTime();
977 return converter->toJSValueRef(dateTime);
979 Catch(WrtDeviceApis::Commons::ConversionException) {
980 LogError("Error on conversion");
981 return JSTizenExceptionFactory::postException(context, exception,
982 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
984 Catch(WrtDeviceApis::Commons::NullPointerException) {
985 LogError("Error on pointer, null value");
986 return JSTizenExceptionFactory::postException(context, exception,
987 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
989 return JSValueMakeUndefined(context);
992 JSValueRef JSMessage::getFolder(JSContextRef context,
994 JSStringRef propertyName,
995 JSValueRef* exception)
999 ConverterMessageFactory::ConverterType converter =
1000 ConverterMessageFactory::getConverter(context);
1001 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1002 Api::Messaging::FolderType folder = msg->getCurrentFolder();
1003 return converter->toJSValueRef(folder);
1005 Catch(WrtDeviceApis::Commons::ConversionException) {
1006 LogError("Error on conversion");
1007 return JSTizenExceptionFactory::postException(context, exception,
1008 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1010 Catch(WrtDeviceApis::Commons::NullPointerException) {
1011 LogError("Error on pointer, null value");
1012 return JSTizenExceptionFactory::postException(context, exception,
1013 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1015 return JSValueMakeUndefined(context);
1018 JSValueRef JSMessage::getMessageBody(JSContextRef context,
1020 JSStringRef propertyName,
1021 JSValueRef* exception)
1023 LogInfo("getMessageBody");
1027 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1028 Assert(priv && "Private object is NULL.");
1030 JSContextRef globalContext = priv->getContext();
1032 ConverterMessageFactory::ConverterType converter =
1033 ConverterMessageFactory::getConverter(globalContext);
1035 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1036 LogInfo("create JS");
1038 return JSMessageBody::createJS(globalContext, msg);
1040 Catch(WrtDeviceApis::Commons::ConversionException) {
1041 LogError("Error on conversion");
1042 return JSTizenExceptionFactory::postException(context, exception,
1043 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1045 Catch(WrtDeviceApis::Commons::NullPointerException) {
1046 LogError("Error on pointer, null value");
1047 return JSTizenExceptionFactory::postException(context, exception,
1048 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1050 return JSValueMakeUndefined(context);
1053 JSValueRef JSMessage::getAccountID(JSContextRef context,
1055 JSStringRef propertyName,
1056 JSValueRef* exception)
1058 LogInfo("getAccountID");
1062 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1063 Assert(priv && "Private object is NULL.");
1065 JSContextRef globalContext = priv->getContext();
1067 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1069 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1071 LogInfo("create JS");
1073 if (msg->getMessageType() == Api::Messaging::EMAIL)
1075 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1077 std::stringstream stream;
1078 stream << email->getAccountID();
1079 if (stream.fail()) {
1080 ThrowMsg(WrtDeviceApis::Commons::UnknownException,
1081 "Couldn't convert e-mail account id");
1084 return converter->toJSValueRef(stream.str());
1088 return JSValueMakeUndefined(context);
1091 Catch(WrtDeviceApis::Commons::ConversionException) {
1092 LogError("Error on conversion");
1093 return JSTizenExceptionFactory::postException(context, exception,
1094 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1096 Catch(WrtDeviceApis::Commons::NullPointerException) {
1097 LogError("Error on pointer, null value");
1098 return JSTizenExceptionFactory::postException(context, exception,
1099 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1101 return JSValueMakeUndefined(context);
1104 JSValueRef JSMessage::getUID(JSContextRef context,
1106 JSStringRef propertyName,
1107 JSValueRef* exception)
1113 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1114 Assert(priv && "Private object is NULL.");
1116 JSContextRef globalContext = priv->getContext();
1118 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1120 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1122 LogInfo("create JS");
1124 if (msg->getMessageType() == Api::Messaging::EMAIL)
1126 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1127 return converter->toJSValueRef(email->getUID());
1131 return JSValueMakeUndefined(context);
1134 Catch(WrtDeviceApis::Commons::ConversionException) {
1135 LogError("Error on conversion");
1136 return JSTizenExceptionFactory::postException(context, exception,
1137 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1139 Catch(WrtDeviceApis::Commons::NullPointerException) {
1140 LogError("Error on pointer, null value");
1141 return JSTizenExceptionFactory::postException(context, exception,
1142 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1144 return JSValueMakeUndefined(context);
1147 bool JSMessage::setAttachments(JSContextRef context,
1149 JSStringRef propertyName,
1151 JSValueRef* exception)
1157 JSMessagePrivateObject* priv =
1158 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1161 JSContextRef globalContext = priv->getContext();
1164 LogDebug("globalContext is NULL");
1165 globalContext = context;
1167 ConverterMessageFactory::ConverterType converter =
1168 ConverterMessageFactory::getConverter(context);
1170 vector<IAttachmentPtr> attachments;
1171 if (JSIsArrayValue(context, value)) {
1172 JSObjectRef valueObj = converter->toJSObjectRef(value);
1173 unsigned int len = JSGetArrayLength(context, valueObj);
1174 LogDebug("Array Length = " << len);
1175 for (unsigned int i = 0; i < len; ++i) {
1177 JSValueRef att = JSGetArrayElement(context, valueObj, i);
1178 if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
1179 LogWarning("Invalid array element. Skipping.");
1182 Api::Messaging::IAttachmentPtr attachment = converter->toIAttachment(att);
1184 LogDebug("Adding attachment , shotname: " << attachment->getShortName());
1185 attachments.push_back(attachment);
1190 Api::Messaging::IAttachmentPtr attachment = converter->toIAttachment(value);
1191 LogDebug("Adding attachment , shotname: " << attachment->getShortName());
1192 attachments.push_back(attachment);
1195 LogDebug("Attachment Size =" << attachments.size());
1196 if ( attachments.size() > 0)
1198 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1201 Api::Messaging::MessageType msgType = msg->getMessageType();
1203 case Api::Messaging::MMS:
1205 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
1206 mms->setAttachments(attachments);
1209 case Api::Messaging::EMAIL:
1211 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1212 email->setAttachments(attachments);
1216 LogError("not supported message type");
1217 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1224 LogError("Message converter failed...");
1225 Throw(WrtDeviceApis::Commons::NullPointerException);
1232 Catch(WrtDeviceApis::Commons::ConversionException) {
1233 LogError("Error on conversion");
1234 return JSTizenExceptionFactory::postException(context, exception,
1235 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1237 Catch(WrtDeviceApis::Commons::NullPointerException) {
1238 LogError("Error on pointer, null value");
1239 return JSTizenExceptionFactory::postException(context, exception,
1240 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1242 Catch(WrtDeviceApis::Commons::UnsupportedException) {
1243 return JSTizenExceptionFactory::postException(context, exception,
1244 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1251 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
1252 bool JSMessage::setAttachments(JSContextRef context,
1254 JSStringRef propertyName,
1256 JSValueRef* exception)
1262 JSMessagePrivateObject* priv =
1263 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1266 return JSTizenExceptionFactory::postException(context, exception,
1267 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1270 Catch(WrtDeviceApis::Commons::NullPointerException) {
1271 LogError("Error on pointer, null value");
1272 return JSTizenExceptionFactory::postException(context, exception,
1273 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1276 vector<string> attachments;
1279 ConverterMessageFactory::ConverterType converter =
1280 ConverterMessageFactory::getConverter(context);
1281 if (JSIsArrayValue(context, value)) {
1282 JSObjectRef valueObj = converter->toJSObjectRef(value);
1284 // extract path from each JSFile object
1285 unsigned int len = JSGetArrayLength(context, valueObj);
1286 for (unsigned int i = 0; i < len; ++i) {
1287 JSValueRef att = JSGetArrayElement(context, valueObj, i);
1288 if (JSValueIsUndefined(context,
1289 att) || JSValueIsNull(context, att)) {
1290 LogWarning("Invalid array element. Skipping.");
1293 Api::Filesystem::INodePtr node = converter->toFilesystemNode(
1296 LogDebug("Adding attachment: " << node->getPath()->getFullPath());
1297 attachments.push_back(node->getPath()->getFullPath());
1300 LogWarning("Invalid or null element passed as attachment array." <<
1301 "Setting empty vector.");
1304 // set up new attachments list
1305 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1306 Api::Messaging::MessageType msgType = msg->getMessageType();
1308 case Api::Messaging::MMS:
1310 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
1311 mms->setAttachments(attachments, true);
1314 case Api::Messaging::EMAIL:
1316 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1317 email->setAttachments(attachments, true);
1320 case Api::Messaging::SMS:
1322 return false; // ignore
1325 LogError("not supported message type");
1326 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1330 Catch(WrtDeviceApis::Commons::ConversionException) {
1331 LogError("Error on conversion");
1332 return JSTizenExceptionFactory::postException(context, exception,
1333 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1335 Catch(WrtDeviceApis::Commons::NullPointerException) {
1336 LogError("Error on pointer, null value");
1337 return JSTizenExceptionFactory::postException(context, exception,
1338 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1340 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1341 LogError("Invalid argument");
1342 return JSTizenExceptionFactory::postException(context, exception,
1343 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1349 bool JSMessage::setBccAddress(JSContextRef context,
1351 JSStringRef propertyName,
1353 JSValueRef* exception)
1357 ConverterMessageFactory::ConverterType converter =
1358 ConverterMessageFactory::getConverter(context);
1359 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1360 Api::Messaging::Recipients bcc = converter->toRecipients(value);
1361 LogDebug("setting bcc field, size=" << bcc.getRecipientSize());
1363 Api::Messaging::MessageType msgType = msg->getMessageType();
1365 case Api::Messaging::SMS:
1366 case Api::Messaging::MMS:
1367 return false; // ignore
1369 case Api::Messaging::EMAIL:
1371 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1372 email->setBccRecipients(bcc);
1376 LogError("unsupported message type");
1377 return JSTizenExceptionFactory::postException(context, exception,
1378 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
1382 Catch(WrtDeviceApis::Commons::ConversionException) {
1383 LogError("Error on conversion");
1384 return JSTizenExceptionFactory::postException(context, exception,
1385 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1387 Catch(WrtDeviceApis::Commons::NullPointerException) {
1388 LogError("Error on pointer, null value");
1389 return JSTizenExceptionFactory::postException(context, exception,
1390 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1392 Catch(WrtDeviceApis::Commons::PlatformException) {
1393 LogError("Platform execution");
1394 return JSTizenExceptionFactory::postException(context, exception,
1395 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1401 bool JSMessage::setBody(JSContextRef context,
1403 JSStringRef propertyName,
1405 JSValueRef* exception)
1409 ConverterMessageFactory::ConverterType converter =
1410 ConverterMessageFactory::getConverter(context);
1411 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1412 string body = converter->toString(value);
1416 Catch(WrtDeviceApis::Commons::ConversionException) {
1417 LogError("Error on conversion");
1418 return JSTizenExceptionFactory::postException(context, exception,
1419 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1421 Catch(WrtDeviceApis::Commons::NullPointerException) {
1422 LogError("Error on pointer, null value");
1423 return JSTizenExceptionFactory::postException(context, exception,
1424 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1426 Catch(WrtDeviceApis::Commons::PlatformException) {
1427 LogError("Platform execution");
1428 return JSTizenExceptionFactory::postException(context, exception,
1429 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1434 bool JSMessage::setCcAddress(JSContextRef context,
1436 JSStringRef propertyName,
1438 JSValueRef* exception)
1442 ConverterMessageFactory::ConverterType converter =
1443 ConverterMessageFactory::getConverter(context);
1444 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1445 Api::Messaging::Recipients cc = converter->toRecipients(value);
1446 LogDebug("setting cc field, size=" << cc.getRecipientSize());
1448 Api::Messaging::MessageType msgType = msg->getMessageType();
1450 case Api::Messaging::SMS:
1451 case Api::Messaging::MMS:
1452 return false; // ignore
1454 case Api::Messaging::EMAIL:
1456 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1457 email->setCcRecipients(cc);
1461 LogError("unsuported message type");
1462 return JSTizenExceptionFactory::postException(context, exception,
1463 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
1469 Catch(WrtDeviceApis::Commons::ConversionException) {
1470 LogError("Error on conversion");
1471 return JSTizenExceptionFactory::postException(context, exception,
1472 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1474 Catch(WrtDeviceApis::Commons::NullPointerException) {
1475 LogError("Error on pointer, null value");
1476 return JSTizenExceptionFactory::postException(context, exception,
1477 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1479 Catch(WrtDeviceApis::Commons::PlatformException) {
1480 LogError("Platform execution");
1481 return JSTizenExceptionFactory::postException(context, exception,
1482 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1488 bool JSMessage::setDestinationAddress(JSContextRef context,
1490 JSStringRef propertyName,
1492 JSValueRef * exception)
1497 ConverterMessageFactory::ConverterType converter =
1498 ConverterMessageFactory::getConverter(context);
1499 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1500 Api::Messaging::Recipients to = converter->toRecipients(value);
1501 LogDebug("setting to field, size=" << to.getRecipientSize());
1502 msg->setToRecipients(to);
1505 Catch(WrtDeviceApis::Commons::ConversionException) {
1506 LogError("Error on conversion");
1507 return JSTizenExceptionFactory::postException(context, exception,
1508 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1510 Catch(WrtDeviceApis::Commons::NullPointerException) {
1511 LogError("Error on pointer, null value");
1512 return JSTizenExceptionFactory::postException(context, exception,
1513 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1515 Catch(WrtDeviceApis::Commons::PlatformException) {
1516 LogError("Platform execution");
1517 return JSTizenExceptionFactory::postException(context, exception,
1518 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1524 bool JSMessage::setIsRead(JSContextRef context,
1526 JSStringRef propertyName,
1528 JSValueRef * exception)
1532 ConverterMessageFactory::ConverterType converter =
1533 ConverterMessageFactory::getConverter(context);
1534 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1535 msg->setReadStatus(converter->toBool(value));
1536 msg->setisReadChangeStatus(converter->toBool(value));
1539 Catch(WrtDeviceApis::Commons::ConversionException) {
1540 LogError("Error on conversion");
1541 return JSTizenExceptionFactory::postException(context, exception,
1542 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1544 Catch(WrtDeviceApis::Commons::NullPointerException) {
1545 LogError("Error on pointer, null value");
1546 return JSTizenExceptionFactory::postException(context, exception,
1547 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1553 bool JSMessage::setMessagePriority(JSContextRef context,
1555 JSStringRef propertyName,
1557 JSValueRef * exception)
1561 ConverterMessageFactory::ConverterType converter =
1562 ConverterMessageFactory::getConverter(context);
1563 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1564 Api::Messaging::MessageType msgType = msg->getMessageType();
1566 case Api::Messaging::MMS:
1567 case Api::Messaging::SMS:
1568 return false; // ignore
1570 case Api::Messaging::EMAIL:
1571 msg->setPriority(converter->toMessagePriority(value));
1575 LogError("unsuported message type");
1576 Throw(WrtDeviceApis::Commons::ConversionException);
1581 Catch(WrtDeviceApis::Commons::ConversionException) {
1582 LogError("Error on conversion");
1583 return JSTizenExceptionFactory::postException(context, exception,
1584 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1586 Catch(WrtDeviceApis::Commons::NullPointerException) {
1587 LogError("Error on pointer, null value");
1588 return JSTizenExceptionFactory::postException(context, exception,
1589 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1591 Catch(WrtDeviceApis::Commons::PlatformException) {
1592 LogError("Platform execution");
1593 return JSTizenExceptionFactory::postException(context, exception,
1594 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1600 bool JSMessage::setSubject(JSContextRef context,
1602 JSStringRef propertyName,
1604 JSValueRef * exception)
1608 ConverterMessageFactory::ConverterType converter =
1609 ConverterMessageFactory::getConverter(context);
1610 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1611 Api::Messaging::MessageType msgType = msg->getMessageType();
1612 string subject = converter->toString(value);
1614 case Api::Messaging::MMS:
1616 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
1617 mms->setSubject(subject);
1620 case Api::Messaging::EMAIL:
1622 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1623 email->setSubject(subject);
1626 case Api::Messaging::SMS:
1627 return false; // ignore
1630 LogError("message not supported");
1631 Throw(WrtDeviceApis::Commons::UnsupportedException);
1636 Catch(WrtDeviceApis::Commons::ConversionException) {
1637 LogError("Error on conversion");
1638 return JSTizenExceptionFactory::postException(context, exception,
1639 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1641 Catch(WrtDeviceApis::Commons::NullPointerException) {
1642 LogError("Error on pointer, null value");
1643 return JSTizenExceptionFactory::postException(context, exception,
1644 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1646 Catch(WrtDeviceApis::Commons::PlatformException) {
1647 LogError("Platform execution");
1648 return JSTizenExceptionFactory::postException(context, exception,
1649 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1651 Catch(WrtDeviceApis::Commons::UnsupportedException) {
1652 return JSTizenExceptionFactory::postException(context, exception,
1653 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1659 bool JSMessage::setMessageBody(JSContextRef context,
1661 JSStringRef propertyName,
1663 JSValueRef* exception)
1667 LogDebug("Set Message Body.");
1670 Catch(WrtDeviceApis::Commons::ConversionException) {
1671 LogError("Error on conversion");
1672 return JSTizenExceptionFactory::postException(context, exception,
1673 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1675 Catch(WrtDeviceApis::Commons::NullPointerException) {
1676 LogError("Error on pointer, null value");
1677 return JSTizenExceptionFactory::postException(context, exception,
1678 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1680 Catch(WrtDeviceApis::Commons::PlatformException) {
1681 LogError("Platform execution");
1682 return JSTizenExceptionFactory::postException(context, exception,
1683 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1689 JSValueRef JSMessage::getConversationId(JSContextRef context,
1691 JSStringRef propertyName,
1692 JSValueRef* exception)
1694 LogDebug("getConversationId");
1698 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1700 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1701 Api::Messaging::EventGetConversationIdPtr event(new Api::Messaging::EventGetConversationId());
1702 event->setConversationMsgPtr(msg);
1703 event->setForSynchronousCall();
1704 Api::Messaging::ReqReceiverMessageSingleton::Instance().getConversationId(event);
1706 convId = event->getConversationId();
1708 return converter->toJSValueRef(convId);
1710 Catch(WrtDeviceApis::Commons::ConversionException) {
1711 LogError("Error on conversion");
1712 return JSTizenExceptionFactory::postException(context, exception,
1713 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1715 Catch(WrtDeviceApis::Commons::NullPointerException) {
1716 LogError("Error on pointer, null value");
1717 return JSTizenExceptionFactory::postException(context, exception,
1718 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1720 Catch(WrtDeviceApis::Commons::PlatformException) {
1721 LogError("Platform execution");
1722 return JSTizenExceptionFactory::postException(context, exception,
1723 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1726 return JSValueMakeUndefined(context);
1729 JSValueRef JSMessage::getInResponseTo(JSContextRef context,
1731 JSStringRef propertyName,
1732 JSValueRef* exception)
1734 LogDebug("getInResponseTo");
1738 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1741 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1742 if (msg->getMessageType() == EMAIL)
1744 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1745 msgId = email->getUID();
1747 Api::Messaging::EventGetConversationIdPtr event(new Api::Messaging::EventGetConversationId());
1748 event->setConversationMsgPtr(msg);
1749 event->setForSynchronousCall();
1750 Api::Messaging::ReqReceiverMessageSingleton::Instance().getConversationId(event);
1751 convId = event->getConversationId();
1753 if (convId == msgId)
1754 convId = -1; // error case, original message
1761 return converter->toJSValueRef(convId);
1763 Catch(WrtDeviceApis::Commons::ConversionException) {
1764 LogError("Error on conversion");
1765 return JSTizenExceptionFactory::postException(context, exception,
1766 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1768 Catch(WrtDeviceApis::Commons::NullPointerException) {
1769 LogError("Error on pointer, null value");
1770 return JSTizenExceptionFactory::postException(context, exception,
1771 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1773 Catch(WrtDeviceApis::Commons::PlatformException) {
1774 LogError("Platform execution");
1775 return JSTizenExceptionFactory::postException(context, exception,
1776 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1779 return JSValueMakeUndefined(context);
1782 JSValueRef JSMessage::getMessageStatus(JSContextRef context,
1784 JSStringRef propertyName,
1785 JSValueRef* exception)
1787 LogInfo("getMessageStatus");
1791 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1792 Assert(priv && "Private object is NULL.");
1794 JSContextRef globalContext = priv->getContext();
1796 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1798 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1800 LogInfo("create JS");
1801 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1804 Catch(WrtDeviceApis::Commons::ConversionException) {
1805 LogError("Error on conversion");
1806 return JSTizenExceptionFactory::postException(context, exception,
1807 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1809 Catch(WrtDeviceApis::Commons::NullPointerException) {
1810 LogError("Error on pointer, null value");
1811 return JSTizenExceptionFactory::postException(context, exception,
1812 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1815 return JSValueMakeUndefined(context);
1819 JSValueRef JSMessage::hasAttachment(JSContextRef context,
1821 JSStringRef propertyName,
1822 JSValueRef* exception)
1824 LogInfo("hasAttachment");
1828 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1829 Assert(priv && "Private object is NULL.");
1831 JSContextRef globalContext = priv->getContext();
1833 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1835 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1837 bool hasAttachmentFlag = false;
1839 if ( msg->getMessageType() == EMAIL)
1841 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1843 if (email->hasAttachment())
1844 hasAttachmentFlag = true;
1846 else if ( msg->getMessageType() == MMS)
1848 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
1850 if (mms->hasAttachment())
1851 hasAttachmentFlag = true;
1855 return JSTizenExceptionFactory::postException(context, exception,
1856 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1859 return converter->toJSValueRef(hasAttachmentFlag);
1862 Catch(WrtDeviceApis::Commons::ConversionException) {
1863 LogError("Error on conversion");
1864 return JSTizenExceptionFactory::postException(context, exception,
1865 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1867 Catch(WrtDeviceApis::Commons::NullPointerException) {
1868 LogError("Error on pointer, null value");
1869 return JSTizenExceptionFactory::postException(context, exception,
1870 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1873 return JSValueMakeUndefined(context);
1877 JSValueRef JSMessage::getAttachmentExistence(JSContextRef context,
1879 JSStringRef propertyName,
1880 JSValueRef* exception)
1882 LogInfo("getAttachmentExistence");
1886 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1887 Assert(priv && "Private object is NULL.");
1889 JSContextRef globalContext = priv->getContext();
1891 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1893 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1895 LogInfo("create JS");
1896 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1899 Catch(WrtDeviceApis::Commons::ConversionException) {
1900 LogError("Error on conversion");
1901 return JSTizenExceptionFactory::postException(context, exception,
1902 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1904 Catch(WrtDeviceApis::Commons::NullPointerException) {
1905 LogError("Error on pointer, null value");
1906 return JSTizenExceptionFactory::postException(context, exception,
1907 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1910 return JSValueMakeUndefined(context);