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 "MessagingErrorMsg.h"
45 #include "JSMessageAttachment.h"
46 #include "plugin_config.h"
49 using namespace TizenApis::Api::Messaging;
50 using namespace TizenApis::Commons;
51 using namespace WrtDeviceApis::Commons;
52 using namespace WrtDeviceApis::CommonsJavaScript;
56 JSClassRef JSMessage::m_jsClassRef = NULL;
58 JSClassDefinition JSMessage::m_classInfo = {
60 kJSClassAttributeNone,
70 NULL, //deleteProperty,
71 NULL, //getPropertyNames,
72 NULL, //callAsFunction,
73 NULL, //callAsConstructor,
75 NULL, //convertToType,
78 // JSMessage properties
79 JSStaticValue JSMessage::m_property[] = {
80 { "id", getMessageId, NULL, kJSPropertyAttributeReadOnly },
81 { "serviceId", getAccountID, NULL, kJSPropertyAttributeReadOnly},
82 { "conversationId", getConversationId, NULL, kJSPropertyAttributeReadOnly },
83 { "folderId", getFolder, NULL, kJSPropertyAttributeReadOnly },
84 { "type", getMessageType, NULL, kJSPropertyAttributeReadOnly },
85 { "timestamp", getTime, NULL, kJSPropertyAttributeReadOnly },
86 { "from", getSourceAddress, NULL, kJSPropertyAttributeReadOnly },
87 { "to", getDestinationAddress, setDestinationAddress, kJSPropertyAttributeNone },
88 { "cc", getCcAddress, setCcAddress, kJSPropertyAttributeNone },
89 { "bcc", getBccAddress, setBccAddress, kJSPropertyAttributeNone },
90 { "body", getMessageBody, setMessageBody, kJSPropertyAttributeNone },
91 { "isRead", getIsRead, setIsRead, kJSPropertyAttributeNone },
92 //{ "hasAttachment", getAttachmentExistence, NULL, kJSPropertyAttributeReadOnly },
93 { "priority", getMessagePriority, setMessagePriority, kJSPropertyAttributeNone },
94 { "subject", getSubject, setSubject, kJSPropertyAttributeNone },
95 { "inResponseTo", getInResponseTo, NULL, kJSPropertyAttributeNone },
96 { "messageStatus", getMessageStatus, NULL, kJSPropertyAttributeReadOnly},
97 { "attachments", getAttachments, NULL, kJSPropertyAttributeReadOnly },
98 //{ "uid", getUID, NULL, kJSPropertyAttributeReadOnly},
102 JSValueRef JSMessage::createJSObject(JSContextRef context,
103 Api::Messaging::EmailAccountInfo& account,
104 Api::Messaging::MessageType msgType,
105 const std::string& msgId)
107 Api::Messaging::IMessagePtr msg;
108 LogDebug("createJSObject with account ");
112 if (msgType == Api::Messaging::EMAIL) {
113 LogDebug("Account Address:" << &account);
114 LogDebug("Account Data ,ID" << account.getId() << "name:" << account.getName() << " Account:" << account.getAddress());
116 msg = Api::Messaging::MessageFactory::createMessage(msgType, account, msgId);
118 return JSValueMakeUndefined(context);
120 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
123 Catch(WrtDeviceApis::Commons::UnknownException) {
124 LogError("wrong message type, object not created");
125 return JSValueMakeUndefined(context);
128 return createJSObject(context, msg);
131 JSValueRef JSMessage::createJSObject(JSContextRef context,
132 Api::Messaging::EventUpdateMessageAnswerReceiver* listener,
133 Api::Messaging::MessageType msgType,
136 Api::Messaging::IMessagePtr msg;
139 // create message depending on type
140 if (msgType == Api::Messaging::SMS || msgType == Api::Messaging::MMS || msgType == Api::Messaging::EMAIL) {
141 msg = Api::Messaging::MessageFactory::createMessage(msgType, msgId);
143 return JSValueMakeUndefined(context);
145 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
148 Catch(WrtDeviceApis::Commons::UnknownException) {
149 LogError("wrong message type, object not created");
150 return JSValueMakeUndefined(context);
152 return createJSObject(context, msg, listener);
155 JSValueRef JSMessage::createJSObject(JSContextRef context,
156 const Api::Messaging::IMessagePtr& msg,
157 Api::Messaging::EventUpdateMessageAnswerReceiver* listener)
159 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
160 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
161 priv->setUpdateMsgReceiver(listener);
162 JSObjectRef jsValueRef =
163 JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
164 JSClassRelease(jsClassRef);
165 if (NULL == jsValueRef) {
166 LogError("object creation error");
167 return JSValueMakeUndefined(context);
172 JSValueRef JSMessage::createJSObject(JSContextRef context,
173 const Api::Messaging::IMessagePtr& msg)
175 LogDebug("createJSObject");
176 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
177 LogDebug("jsClassRef success");
178 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
179 LogDebug("priv success");
181 JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
182 LogDebug("JSObjectMake success");
183 JSClassRelease(jsClassRef);
184 if (NULL == jsValueRef) {
185 LogError("object creation error");
186 return JSValueMakeUndefined(context);
191 JSValueRef JSMessage::createJSObject(JSContextRef context,
192 Api::Messaging::MessageType msgType,
195 Api::Messaging::IMessagePtr msg;
198 // create message depending on type
199 if (msgType == Api::Messaging::SMS || msgType == Api::Messaging::MMS || msgType == Api::Messaging::EMAIL) {
200 msg = Api::Messaging::MessageFactory::createMessage(msgType, msgId);
202 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
205 Catch(WrtDeviceApis::Commons::UnknownException) {
206 LogError("wrong message type, object not created");
207 return JSValueMakeUndefined(context);
209 return createJSObject(context, msg, NULL);
212 void JSMessage::initialize(JSContextRef context,
216 JSMessagePrivateObject* priv =
217 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
218 LogDebug("priv=" << priv);
220 LogWarning("empty jsObject creation");
224 void JSMessage::finalize(JSObjectRef object)
226 JSMessagePrivateObject* priv =
227 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
229 LogDebug("deleting private object");
231 JSObjectSetPrivate(object, NULL);
235 bool JSMessage::hasProperty(JSContextRef context,
237 JSStringRef propertyName)
242 JSValueRef JSMessage::getProperty(JSContextRef context,
244 JSStringRef propertyName,
245 JSValueRef* exception)
247 LogError("should not enter");
248 return JSValueMakeUndefined(context);
251 bool JSMessage::setProperty(JSContextRef context,
253 JSStringRef propertyName,
255 JSValueRef* exception)
257 LogError("should not enter");
261 bool JSMessage::deleteProperty(JSContextRef context,
263 JSStringRef propertyName,
264 JSValueRef* exception)
270 void JSMessage::getPropertyNames(JSContextRef context,
272 JSPropertyNameAccumulatorRef propertyNames)
277 JSValueRef JSMessage::callAsFunction(JSContextRef context,
279 JSObjectRef thisObject,
280 size_t argumentCount,
281 const JSValueRef arguments[],
282 JSValueRef* exception)
285 return JSValueMakeUndefined(context);
288 bool JSMessage::hasInstance(JSContextRef context,
289 JSObjectRef constructor,
290 JSValueRef possibleInstance,
291 JSValueRef* exception)
297 JSValueRef JSMessage::convertToType(JSContextRef context,
300 JSValueRef* exception)
303 return JSValueMakeUndefined(context);
306 JSValueRef JSMessage::getAttachments(JSContextRef context,
308 JSStringRef propertyName,
309 JSValueRef* exception)
314 ConverterMessageFactory::ConverterType converter =
315 ConverterMessageFactory::getConverter(context);
316 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
317 Api::Messaging::MessageType msgType = msg->getMessageType();
319 // prepare common values
320 JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(
321 converter->toJSGlobalContext(object),
326 case Api::Messaging::MMS:
327 case Api::Messaging::EMAIL:
330 std::vector<IAttachmentPtr> attachments;
331 std::vector<IAttachmentPtr>::iterator it;
333 if ( msgType == Api::Messaging::MMS )
335 Api::Messaging::AttachmentsPtr mmsAttachments =
336 DPL::StaticPointerCast<Api::Messaging::Attachments>(Api::Messaging::MessageFactory::convertToEmail(msg));
337 attachments = mmsAttachments->getAttachments();
341 Api::Messaging::AttachmentsPtr emailAttachments =
342 DPL::StaticPointerCast<Api::Messaging::Attachments>(Api::Messaging::MessageFactory::convertToEmail(msg));
343 attachments = emailAttachments->getAttachments();
346 int count = attachments.size();
347 LogDebug( "count : " << count);
349 JSObjectRef jsMessageAttachmentObject[count]; //make
351 for (int index = 0 ; index < attachments.size(); index++ )
353 LogDebug( "Attachment ID : " << attachments[index]->getAttachmentID());
354 jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(context, attachments[index] );
356 JSObjectRef result = JSObjectMakeArray(context, count, jsMessageAttachmentObject, NULL);
361 case Api::Messaging::SMS:
362 return JSValueMakeUndefined(context); // ignore
365 LogError("not supported message type");
366 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
369 Catch(WrtDeviceApis::Commons::ConversionException) {
370 LogError("Error on conversion");
371 return JSTizenExceptionFactory::postException(context, exception,
372 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
374 Catch(WrtDeviceApis::Commons::NullPointerException) {
375 LogError("Error on pointer, null value");
376 return JSTizenExceptionFactory::postException(context, exception,
377 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
379 return JSValueMakeUndefined(context);
383 JSValueRef JSMessage::getBccAddress(JSContextRef context,
385 JSStringRef propertyName,
386 JSValueRef* exception)
390 ConverterMessageFactory::ConverterType converter =
391 ConverterMessageFactory::getConverter(context);
392 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
393 Api::Messaging::MessageType msgType = msg->getMessageType();
396 case Api::Messaging::EMAIL:
398 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
399 Api::Messaging::RecipientsPtr recipient = email->getBccRecipientsPtr();
400 return JSRecipientArray::createArray(converter->toJSGlobalContext(
403 case Api::Messaging::SMS:
404 case Api::Messaging::MMS:
405 return JSValueMakeUndefined(context); // ignore
408 LogError("not supported message type");
409 return JSTizenExceptionFactory::postException(context, exception,
410 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
414 Catch(WrtDeviceApis::Commons::ConversionException) {
415 LogError("Error on conversion");
416 return JSTizenExceptionFactory::postException(context, exception,
417 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
419 Catch(WrtDeviceApis::Commons::NullPointerException) {
420 LogError("Error on pointer, null value");
421 return JSTizenExceptionFactory::postException(context, exception,
422 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
425 return JSValueMakeUndefined(context);
428 JSValueRef JSMessage::getBody(JSContextRef context,
430 JSStringRef propertyName,
431 JSValueRef* exception)
435 ConverterMessageFactory::ConverterType converter =
436 ConverterMessageFactory::getConverter(context);
437 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
438 string body = msg->getBody();
439 return converter->toJSValueRef(body);
441 Catch(WrtDeviceApis::Commons::ConversionException) {
442 LogError("Error on conversion");
443 return JSTizenExceptionFactory::postException(context, exception,
444 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
446 Catch(WrtDeviceApis::Commons::NullPointerException) {
447 LogError("Error on pointer, null value");
448 return JSTizenExceptionFactory::postException(context, exception,
449 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
452 return JSValueMakeUndefined(context);
455 JSValueRef JSMessage::getCcAddress(JSContextRef context,
457 JSStringRef propertyName,
458 JSValueRef* exception)
462 ConverterMessageFactory::ConverterType converter =
463 ConverterMessageFactory::getConverter(context);
464 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
465 Api::Messaging::MessageType msgType = msg->getMessageType();
468 case Api::Messaging::EMAIL:
470 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
471 Api::Messaging::RecipientsPtr recipient = email->getCcRecipientsPtr();
472 return JSRecipientArray::createArray(converter->toJSGlobalContext(
475 case Api::Messaging::MMS:
476 case Api::Messaging::SMS:
477 return JSValueMakeUndefined(context); // ignore
480 LogError("not supported message type");
481 return JSTizenExceptionFactory::postException(context, exception,
482 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
487 Catch(WrtDeviceApis::Commons::ConversionException) {
488 LogError("Error on conversion");
489 return JSTizenExceptionFactory::postException(context, exception,
490 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
492 Catch(WrtDeviceApis::Commons::NullPointerException) {
493 LogError("Error on pointer, null value");
494 return JSTizenExceptionFactory::postException(context, exception,
495 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
498 return JSValueMakeUndefined(context);
501 JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
503 JSStringRef propertyName,
504 JSValueRef* exception)
509 ConverterMessageFactory::ConverterType converter =
510 ConverterMessageFactory::getConverter(context);
511 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
512 Api::Messaging::RecipientsPtr recipient = msg->getToRecipientsPtr();
513 return JSRecipientArray::createArray(converter->toJSGlobalContext(
516 Catch(WrtDeviceApis::Commons::ConversionException) {
517 LogError("Error on conversion");
518 return JSTizenExceptionFactory::postException(context, exception,
519 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
521 Catch(WrtDeviceApis::Commons::NullPointerException) {
522 LogError("Error on pointer, null value");
523 return JSTizenExceptionFactory::postException(context, exception,
524 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
527 return JSValueMakeUndefined(context);
530 JSValueRef JSMessage::getIsRead(JSContextRef context,
532 JSStringRef propertyName,
533 JSValueRef* exception)
537 ConverterMessageFactory::ConverterType converter =
538 ConverterMessageFactory::getConverter(context);
539 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
540 bool isRead = msg->isRead();
541 return converter->toJSValueRef(isRead);
543 Catch(WrtDeviceApis::Commons::ConversionException) {
544 LogError("Error on conversion");
545 return JSTizenExceptionFactory::postException(context, exception,
546 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
548 Catch(WrtDeviceApis::Commons::NullPointerException) {
549 LogError("Error on pointer, null value");
550 return JSTizenExceptionFactory::postException(context, exception,
551 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
554 return JSValueMakeUndefined(context);
557 JSValueRef JSMessage::getMessageId(JSContextRef context,
559 JSStringRef propertyName,
560 JSValueRef* exception)
564 ConverterMessageFactory::ConverterType converter =
565 ConverterMessageFactory::getConverter(context);
566 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
567 const string& id = msg->getIdRef();
568 LogDebug("msgId=" << id);
569 return converter->toJSValueRef(id);
571 Catch(WrtDeviceApis::Commons::ConversionException) {
572 LogError("Error on conversion");
573 return JSTizenExceptionFactory::postException(context, exception,
574 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
576 Catch(WrtDeviceApis::Commons::NullPointerException) {
577 LogError("Error on pointer, null value");
578 return JSTizenExceptionFactory::postException(context, exception,
579 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
582 return JSValueMakeUndefined(context);
585 JSValueRef JSMessage::getMessagePriority(JSContextRef context,
587 JSStringRef propertyName,
588 JSValueRef* exception)
592 ConverterMessageFactory::ConverterType converter =
593 ConverterMessageFactory::getConverter(context);
594 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
595 Api::Messaging::MessageType msgType = msg->getMessageType();
598 case Api::Messaging::SMS:
599 case Api::Messaging::MMS:
600 return JSValueMakeUndefined(context);
602 case Api::Messaging::EMAIL:
604 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
605 return converter->toJSValueRef(static_cast<Api::Messaging::MessagePriority>(*
610 LogError("unsupported message type");
611 return JSTizenExceptionFactory::postException(context, exception,
612 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
616 Catch(WrtDeviceApis::Commons::ConversionException) {
617 LogError("Error on conversion");
618 return JSTizenExceptionFactory::postException(context, exception,
619 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
621 Catch(WrtDeviceApis::Commons::NullPointerException) {
622 LogError("Error on pointer, null value");
623 return JSTizenExceptionFactory::postException(context, exception,
624 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
627 return JSValueMakeUndefined(context);
630 JSValueRef JSMessage::getMessageType(JSContextRef context,
632 JSStringRef propertyName,
633 JSValueRef* exception)
637 ConverterMessageFactory::ConverterType converter =
638 ConverterMessageFactory::getConverter(context);
639 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
640 Api::Messaging::MessageType msgType = msg->getMessageType();
642 return converter->toJSValueRef(converter->toMessageType(msgType));
644 Catch(WrtDeviceApis::Commons::ConversionException) {
645 LogError("Error on conversion");
646 return JSTizenExceptionFactory::postException(context, exception,
647 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
649 Catch(WrtDeviceApis::Commons::NullPointerException) {
650 LogError("Error on pointer, null value");
651 return JSTizenExceptionFactory::postException(context, exception,
652 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
655 return JSValueMakeUndefined(context);
658 JSValueRef JSMessage::getSourceAddress(JSContextRef context,
660 JSStringRef propertyName,
661 JSValueRef* exception)
665 ConverterMessageFactory::ConverterType converter =
666 ConverterMessageFactory::getConverter(context);
667 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
669 //This property is set up by the device or the web runtime environment.
670 //This property should only be taken into account for Email.
671 // TODO Verify with Tizen.
672 // if (msg->getMessageType() != Api::Messaging::EMAIL && msg->getMessageType() != Api::VIRTUAL_MESSAGE) {
673 // return JSValueMakeUndefined(context);
675 return converter->toJSValueRef(msg->getSourceAddress());
677 Catch(WrtDeviceApis::Commons::ConversionException) {
678 LogError("Error on conversion");
679 return JSTizenExceptionFactory::postException(context, exception,
680 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
682 Catch(WrtDeviceApis::Commons::NullPointerException) {
683 LogError("Error on pointer, null value");
684 return JSTizenExceptionFactory::postException(context, exception,
685 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
688 return JSValueMakeUndefined(context);
691 JSValueRef JSMessage::getSubject(JSContextRef context,
693 JSStringRef propertyName,
694 JSValueRef* exception)
698 ConverterMessageFactory::ConverterType converter =
699 ConverterMessageFactory::getConverter(context);
700 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
701 Api::Messaging::MessageType msgType = msg->getMessageType();
704 case Api::Messaging::MMS:
706 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
707 return converter->toJSValueRef(mms->getSubject());
709 case Api::Messaging::EMAIL:
711 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
712 return converter->toJSValueRef(email->getSubject());
714 case Api::Messaging::SMS:
715 return JSValueMakeUndefined(context); // ignore
717 LogError("message not support subject");
718 return JSTizenExceptionFactory::postException(context, exception,
719 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
723 Catch(WrtDeviceApis::Commons::ConversionException) {
724 LogError("Error on conversion");
725 return JSTizenExceptionFactory::postException(context, exception,
726 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
728 Catch(WrtDeviceApis::Commons::NullPointerException) {
729 LogError("Error on pointer, null value");
730 return JSTizenExceptionFactory::postException(context, exception,
731 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
733 Catch(WrtDeviceApis::Commons::UnsupportedException) {
734 return JSTizenExceptionFactory::postException(context, exception,
735 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
737 return JSValueMakeUndefined(context);
740 JSValueRef JSMessage::getTime(JSContextRef context,
742 JSStringRef propertyName,
743 JSValueRef* exception)
747 ConverterMessageFactory::ConverterType converter =
748 ConverterMessageFactory::getConverter(context);
749 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
750 struct tm dateTime = msg->getDateTime();
751 return converter->toJSValueRef(dateTime);
753 Catch(WrtDeviceApis::Commons::ConversionException) {
754 LogError("Error on conversion");
755 return JSTizenExceptionFactory::postException(context, exception,
756 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
758 Catch(WrtDeviceApis::Commons::NullPointerException) {
759 LogError("Error on pointer, null value");
760 return JSTizenExceptionFactory::postException(context, exception,
761 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
763 return JSValueMakeUndefined(context);
766 JSValueRef JSMessage::getFolder(JSContextRef context,
768 JSStringRef propertyName,
769 JSValueRef* exception)
773 ConverterMessageFactory::ConverterType converter =
774 ConverterMessageFactory::getConverter(context);
775 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
776 Api::Messaging::FolderType folder = msg->getCurrentFolder();
777 return converter->toJSValueRef(folder);
779 Catch(WrtDeviceApis::Commons::ConversionException) {
780 LogError("Error on conversion");
781 return JSTizenExceptionFactory::postException(context, exception,
782 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
784 Catch(WrtDeviceApis::Commons::NullPointerException) {
785 LogError("Error on pointer, null value");
786 return JSTizenExceptionFactory::postException(context, exception,
787 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
789 return JSValueMakeUndefined(context);
792 JSValueRef JSMessage::getMessageBody(JSContextRef context,
794 JSStringRef propertyName,
795 JSValueRef* exception)
797 LogInfo("getMessageBody");
801 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
802 Assert(priv && "Private object is NULL.");
804 JSContextRef globalContext = priv->getContext();
806 ConverterMessageFactory::ConverterType converter =
807 ConverterMessageFactory::getConverter(globalContext);
809 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
810 LogInfo("create JS");
812 return JSMessageBody::createJS(globalContext, msg);
814 Catch(WrtDeviceApis::Commons::ConversionException) {
815 LogError("Error on conversion");
816 return JSTizenExceptionFactory::postException(context, exception,
817 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
819 Catch(WrtDeviceApis::Commons::NullPointerException) {
820 LogError("Error on pointer, null value");
821 return JSTizenExceptionFactory::postException(context, exception,
822 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
824 return JSValueMakeUndefined(context);
827 JSValueRef JSMessage::getAccountID(JSContextRef context,
829 JSStringRef propertyName,
830 JSValueRef* exception)
832 LogInfo("getAccountID");
836 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
837 Assert(priv && "Private object is NULL.");
839 JSContextRef globalContext = priv->getContext();
841 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
843 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
845 LogInfo("create JS");
847 if (msg->getMessageType() == Api::Messaging::EMAIL)
849 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
851 std::stringstream stream;
852 stream << email->getAccountID();
854 ThrowMsg(WrtDeviceApis::Commons::UnknownException,
855 "Couldn't convert e-mail account id");
858 return converter->toJSValueRef(stream.str());
862 return JSValueMakeUndefined(context);
865 Catch(WrtDeviceApis::Commons::ConversionException) {
866 LogError("Error on conversion");
867 return JSTizenExceptionFactory::postException(context, exception,
868 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
870 Catch(WrtDeviceApis::Commons::NullPointerException) {
871 LogError("Error on pointer, null value");
872 return JSTizenExceptionFactory::postException(context, exception,
873 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
875 return JSValueMakeUndefined(context);
878 JSValueRef JSMessage::getUID(JSContextRef context,
880 JSStringRef propertyName,
881 JSValueRef* exception)
887 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
888 Assert(priv && "Private object is NULL.");
890 JSContextRef globalContext = priv->getContext();
892 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
894 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
896 LogInfo("create JS");
898 if (msg->getMessageType() == Api::Messaging::EMAIL)
900 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
901 return converter->toJSValueRef(email->getUID());
905 return JSValueMakeUndefined(context);
908 Catch(WrtDeviceApis::Commons::ConversionException) {
909 LogError("Error on conversion");
910 return JSTizenExceptionFactory::postException(context, exception,
911 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
913 Catch(WrtDeviceApis::Commons::NullPointerException) {
914 LogError("Error on pointer, null value");
915 return JSTizenExceptionFactory::postException(context, exception,
916 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
918 return JSValueMakeUndefined(context);
921 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
922 bool JSMessage::setAttachments(JSContextRef context,
924 JSStringRef propertyName,
926 JSValueRef* exception)
932 JSMessagePrivateObject* priv =
933 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
936 return JSTizenExceptionFactory::postException(context, exception,
937 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
940 Catch(WrtDeviceApis::Commons::NullPointerException) {
941 LogError("Error on pointer, null value");
942 return JSTizenExceptionFactory::postException(context, exception,
943 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
946 vector<string> attachments;
949 ConverterMessageFactory::ConverterType converter =
950 ConverterMessageFactory::getConverter(context);
951 if (JSIsArrayValue(context, value)) {
952 JSObjectRef valueObj = converter->toJSObjectRef(value);
954 // extract path from each JSFile object
955 unsigned int len = JSGetArrayLength(context, valueObj);
956 for (unsigned int i = 0; i < len; ++i) {
957 JSValueRef att = JSGetArrayElement(context, valueObj, i);
958 if (JSValueIsUndefined(context,
959 att) || JSValueIsNull(context, att)) {
960 LogWarning("Invalid array element. Skipping.");
963 Api::Filesystem::INodePtr node = converter->toFilesystemNode(
966 LogDebug("Adding attachment: " << node->getPath()->getFullPath());
967 attachments.push_back(node->getPath()->getFullPath());
970 LogWarning("Invalid or null element passed as attachment array." <<
971 "Setting empty vector.");
974 // set up new attachments list
975 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
976 Api::Messaging::MessageType msgType = msg->getMessageType();
978 case Api::Messaging::MMS:
980 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
981 mms->setAttachments(attachments, true);
984 case Api::Messaging::EMAIL:
986 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
987 email->setAttachments(attachments, true);
990 case Api::Messaging::SMS:
992 return false; // ignore
995 LogError("not supported message type");
996 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1000 Catch(WrtDeviceApis::Commons::ConversionException) {
1001 LogError("Error on conversion");
1002 return JSTizenExceptionFactory::postException(context, exception,
1003 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1005 Catch(WrtDeviceApis::Commons::NullPointerException) {
1006 LogError("Error on pointer, null value");
1007 return JSTizenExceptionFactory::postException(context, exception,
1008 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1010 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1011 LogError("Invalid argument");
1012 return JSTizenExceptionFactory::postException(context, exception,
1013 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1019 bool JSMessage::setBccAddress(JSContextRef context,
1021 JSStringRef propertyName,
1023 JSValueRef* exception)
1027 ConverterMessageFactory::ConverterType converter =
1028 ConverterMessageFactory::getConverter(context);
1029 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1030 Api::Messaging::Recipients bcc = converter->toRecipients(value);
1031 LogDebug("setting bcc field, size=" << bcc.getRecipientSize());
1033 Api::Messaging::MessageType msgType = msg->getMessageType();
1035 case Api::Messaging::SMS:
1036 case Api::Messaging::MMS:
1037 return false; // ignore
1039 case Api::Messaging::EMAIL:
1041 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1042 email->setBccRecipients(bcc);
1046 LogError("unsupported message type");
1047 return JSTizenExceptionFactory::postException(context, exception,
1048 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
1052 Catch(WrtDeviceApis::Commons::ConversionException) {
1053 LogError("Error on conversion");
1054 return JSTizenExceptionFactory::postException(context, exception,
1055 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1057 Catch(WrtDeviceApis::Commons::NullPointerException) {
1058 LogError("Error on pointer, null value");
1059 return JSTizenExceptionFactory::postException(context, exception,
1060 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1062 Catch(WrtDeviceApis::Commons::PlatformException) {
1063 LogError("Platform execution");
1064 return JSTizenExceptionFactory::postException(context, exception,
1065 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1071 bool JSMessage::setBody(JSContextRef context,
1073 JSStringRef propertyName,
1075 JSValueRef* exception)
1079 ConverterMessageFactory::ConverterType converter =
1080 ConverterMessageFactory::getConverter(context);
1081 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1082 string body = converter->toString(value);
1086 Catch(WrtDeviceApis::Commons::ConversionException) {
1087 LogError("Error on conversion");
1088 return JSTizenExceptionFactory::postException(context, exception,
1089 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1091 Catch(WrtDeviceApis::Commons::NullPointerException) {
1092 LogError("Error on pointer, null value");
1093 return JSTizenExceptionFactory::postException(context, exception,
1094 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1096 Catch(WrtDeviceApis::Commons::PlatformException) {
1097 LogError("Platform execution");
1098 return JSTizenExceptionFactory::postException(context, exception,
1099 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1104 bool JSMessage::setCcAddress(JSContextRef context,
1106 JSStringRef propertyName,
1108 JSValueRef* exception)
1112 ConverterMessageFactory::ConverterType converter =
1113 ConverterMessageFactory::getConverter(context);
1114 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1115 Api::Messaging::Recipients cc = converter->toRecipients(value);
1116 LogDebug("setting cc field, size=" << cc.getRecipientSize());
1118 Api::Messaging::MessageType msgType = msg->getMessageType();
1120 case Api::Messaging::SMS:
1121 case Api::Messaging::MMS:
1122 return false; // ignore
1124 case Api::Messaging::EMAIL:
1126 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1127 email->setCcRecipients(cc);
1131 LogError("unsuported message type");
1132 return JSTizenExceptionFactory::postException(context, exception,
1133 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
1139 Catch(WrtDeviceApis::Commons::ConversionException) {
1140 LogError("Error on conversion");
1141 return JSTizenExceptionFactory::postException(context, exception,
1142 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1144 Catch(WrtDeviceApis::Commons::NullPointerException) {
1145 LogError("Error on pointer, null value");
1146 return JSTizenExceptionFactory::postException(context, exception,
1147 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1149 Catch(WrtDeviceApis::Commons::PlatformException) {
1150 LogError("Platform execution");
1151 return JSTizenExceptionFactory::postException(context, exception,
1152 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1158 bool JSMessage::setDestinationAddress(JSContextRef context,
1160 JSStringRef propertyName,
1162 JSValueRef * exception)
1167 ConverterMessageFactory::ConverterType converter =
1168 ConverterMessageFactory::getConverter(context);
1169 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1170 Api::Messaging::Recipients to = converter->toRecipients(value);
1171 LogDebug("setting to field, size=" << to.getRecipientSize());
1172 msg->setToRecipients(to);
1175 Catch(WrtDeviceApis::Commons::ConversionException) {
1176 LogError("Error on conversion");
1177 return JSTizenExceptionFactory::postException(context, exception,
1178 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1180 Catch(WrtDeviceApis::Commons::NullPointerException) {
1181 LogError("Error on pointer, null value");
1182 return JSTizenExceptionFactory::postException(context, exception,
1183 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1185 Catch(WrtDeviceApis::Commons::PlatformException) {
1186 LogError("Platform execution");
1187 return JSTizenExceptionFactory::postException(context, exception,
1188 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1194 bool JSMessage::setIsRead(JSContextRef context,
1196 JSStringRef propertyName,
1198 JSValueRef * exception)
1202 ConverterMessageFactory::ConverterType converter =
1203 ConverterMessageFactory::getConverter(context);
1204 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1205 msg->setReadStatus(converter->toBool(value));
1206 msg->setisReadChangeStatus(converter->toBool(value));
1209 Catch(WrtDeviceApis::Commons::ConversionException) {
1210 LogError("Error on conversion");
1211 return JSTizenExceptionFactory::postException(context, exception,
1212 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1214 Catch(WrtDeviceApis::Commons::NullPointerException) {
1215 LogError("Error on pointer, null value");
1216 return JSTizenExceptionFactory::postException(context, exception,
1217 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1223 bool JSMessage::setMessagePriority(JSContextRef context,
1225 JSStringRef propertyName,
1227 JSValueRef * exception)
1231 ConverterMessageFactory::ConverterType converter =
1232 ConverterMessageFactory::getConverter(context);
1233 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1234 Api::Messaging::MessageType msgType = msg->getMessageType();
1236 case Api::Messaging::MMS:
1237 case Api::Messaging::SMS:
1238 return false; // ignore
1240 case Api::Messaging::EMAIL:
1241 msg->setPriority(converter->toMessagePriority(value));
1245 LogError("unsuported message type");
1246 Throw(WrtDeviceApis::Commons::ConversionException);
1251 Catch(WrtDeviceApis::Commons::ConversionException) {
1252 LogError("Error on conversion");
1253 return JSTizenExceptionFactory::postException(context, exception,
1254 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1256 Catch(WrtDeviceApis::Commons::NullPointerException) {
1257 LogError("Error on pointer, null value");
1258 return JSTizenExceptionFactory::postException(context, exception,
1259 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1261 Catch(WrtDeviceApis::Commons::PlatformException) {
1262 LogError("Platform execution");
1263 return JSTizenExceptionFactory::postException(context, exception,
1264 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1270 bool JSMessage::setSubject(JSContextRef context,
1272 JSStringRef propertyName,
1274 JSValueRef * exception)
1278 ConverterMessageFactory::ConverterType converter =
1279 ConverterMessageFactory::getConverter(context);
1280 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1281 Api::Messaging::MessageType msgType = msg->getMessageType();
1282 string subject = converter->toString(value);
1284 case Api::Messaging::MMS:
1286 Api::Messaging::IMmsPtr mms = Api::Messaging::MessageFactory::convertToMms(msg);
1287 mms->setSubject(subject);
1290 case Api::Messaging::EMAIL:
1292 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1293 email->setSubject(subject);
1296 case Api::Messaging::SMS:
1297 return false; // ignore
1300 LogError("message not supported");
1301 Throw(WrtDeviceApis::Commons::UnsupportedException);
1306 Catch(WrtDeviceApis::Commons::ConversionException) {
1307 LogError("Error on conversion");
1308 return JSTizenExceptionFactory::postException(context, exception,
1309 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1311 Catch(WrtDeviceApis::Commons::NullPointerException) {
1312 LogError("Error on pointer, null value");
1313 return JSTizenExceptionFactory::postException(context, exception,
1314 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1316 Catch(WrtDeviceApis::Commons::PlatformException) {
1317 LogError("Platform execution");
1318 return JSTizenExceptionFactory::postException(context, exception,
1319 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1321 Catch(WrtDeviceApis::Commons::UnsupportedException) {
1322 return JSTizenExceptionFactory::postException(context, exception,
1323 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1329 bool JSMessage::setMessageBody(JSContextRef context,
1331 JSStringRef propertyName,
1333 JSValueRef* exception)
1337 LogDebug("Set Message Body.");
1340 Catch(WrtDeviceApis::Commons::ConversionException) {
1341 LogError("Error on conversion");
1342 return JSTizenExceptionFactory::postException(context, exception,
1343 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1345 Catch(WrtDeviceApis::Commons::NullPointerException) {
1346 LogError("Error on pointer, null value");
1347 return JSTizenExceptionFactory::postException(context, exception,
1348 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1350 Catch(WrtDeviceApis::Commons::PlatformException) {
1351 LogError("Platform execution");
1352 return JSTizenExceptionFactory::postException(context, exception,
1353 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1359 JSValueRef JSMessage::getConversationId(JSContextRef context,
1361 JSStringRef propertyName,
1362 JSValueRef* exception)
1364 LogDebug("getConversationId");
1368 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1370 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1371 Api::Messaging::EventGetConversationIdPtr event(new Api::Messaging::EventGetConversationId());
1372 event->setConversationMsgPtr(msg);
1373 event->setForSynchronousCall();
1374 Api::Messaging::ReqReceiverMessageSingleton::Instance().getConversationId(event);
1376 convId = event->getConversationId();
1378 return converter->toJSValueRef(convId);
1380 Catch(WrtDeviceApis::Commons::ConversionException) {
1381 LogError("Error on conversion");
1382 return JSTizenExceptionFactory::postException(context, exception,
1383 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1385 Catch(WrtDeviceApis::Commons::NullPointerException) {
1386 LogError("Error on pointer, null value");
1387 return JSTizenExceptionFactory::postException(context, exception,
1388 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1390 Catch(WrtDeviceApis::Commons::PlatformException) {
1391 LogError("Platform execution");
1392 return JSTizenExceptionFactory::postException(context, exception,
1393 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1396 return JSValueMakeUndefined(context);
1399 JSValueRef JSMessage::getInResponseTo(JSContextRef context,
1401 JSStringRef propertyName,
1402 JSValueRef* exception)
1404 LogDebug("getInResponseTo");
1408 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1411 Api::Messaging::IMessagePtr msg = converter->toIMessage(object);
1412 if (msg->getMessageType() == EMAIL)
1414 Api::Messaging::IEmailPtr email = Api::Messaging::MessageFactory::convertToEmail(msg);
1415 msgId = email->getUID();
1417 Api::Messaging::EventGetConversationIdPtr event(new Api::Messaging::EventGetConversationId());
1418 event->setConversationMsgPtr(msg);
1419 event->setForSynchronousCall();
1420 Api::Messaging::ReqReceiverMessageSingleton::Instance().getConversationId(event);
1421 convId = event->getConversationId();
1423 if (convId == msgId)
1424 convId = -1; // error case, original message
1431 return converter->toJSValueRef(convId);
1433 Catch(WrtDeviceApis::Commons::ConversionException) {
1434 LogError("Error on conversion");
1435 return JSTizenExceptionFactory::postException(context, exception,
1436 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1438 Catch(WrtDeviceApis::Commons::NullPointerException) {
1439 LogError("Error on pointer, null value");
1440 return JSTizenExceptionFactory::postException(context, exception,
1441 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1443 Catch(WrtDeviceApis::Commons::PlatformException) {
1444 LogError("Platform execution");
1445 return JSTizenExceptionFactory::postException(context, exception,
1446 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1449 return JSValueMakeUndefined(context);
1452 JSValueRef JSMessage::getMessageStatus(JSContextRef context,
1454 JSStringRef propertyName,
1455 JSValueRef* exception)
1457 LogInfo("getMessageStatus");
1461 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1462 Assert(priv && "Private object is NULL.");
1464 JSContextRef globalContext = priv->getContext();
1466 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1468 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1470 LogInfo("create JS");
1471 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1474 Catch(WrtDeviceApis::Commons::ConversionException) {
1475 LogError("Error on conversion");
1476 return JSTizenExceptionFactory::postException(context, exception,
1477 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1479 Catch(WrtDeviceApis::Commons::NullPointerException) {
1480 LogError("Error on pointer, null value");
1481 return JSTizenExceptionFactory::postException(context, exception,
1482 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1485 return JSValueMakeUndefined(context);
1489 JSValueRef JSMessage::getAttachmentExistence(JSContextRef context,
1491 JSStringRef propertyName,
1492 JSValueRef* exception)
1494 LogInfo("getAttachmentExistence");
1498 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1499 Assert(priv && "Private object is NULL.");
1501 JSContextRef globalContext = priv->getContext();
1503 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1505 Api::Messaging::IMessagePtr msg = converter->toIMessage(object); //get message point
1507 LogInfo("create JS");
1508 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1511 Catch(WrtDeviceApis::Commons::ConversionException) {
1512 LogError("Error on conversion");
1513 return JSTizenExceptionFactory::postException(context, exception,
1514 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1516 Catch(WrtDeviceApis::Commons::NullPointerException) {
1517 LogError("Error on pointer, null value");
1518 return JSTizenExceptionFactory::postException(context, exception,
1519 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1522 return JSValueMakeUndefined(context);