[Messaging] Deprecated whole module
[platform/core/api/webapi-plugins.git] / src / messaging / messaging_api.js
index c1adc51..5f796de 100755 (executable)
@@ -20,14 +20,10 @@ var T_ = xwalk.utils.type;
 var native = new xwalk.utils.NativeManager(extension);
 var privUtils_ = xwalk.utils;
 
-function throwException_(err) {
-    throw new WebAPIException(err.code, err.name, err.message);
-}
-
 var Property = {
-    W: 1 << 0, // WRITABLE
-    E: 1 << 1, // ENUMERABLE
-    C: 1 << 2 // CONFIGURABLE
+    WRITEABLE: 1 << 0,
+    ENUMERABLE: 1 << 1,
+    CONFIGURABLE: 1 << 2
 };
 
 function addTypeToFilter_(data) {
@@ -55,26 +51,6 @@ function addTypeToFilter_(data) {
     return filter;
 }
 
-/**
- * Example usage:
- * function Messaging () {
- *     propertyFactory_(this, 'ids', [2,3,4], Property.W | Property.E | Property.C);
- *     propertyFactory_(this, 'name', 'Name', Property.E);
- *     propertyFactory_(this, 'age', 25, Property.W);
- *     propertyFactory_(this, 'something', 1);
- *     propertyFactory_(this, 'getSomething', Property.E, {get: function(){return 100;}});
- * }
- * Will produce:
- * var m = new Messaging();
- * {
- *     id: [2,3,4],
- *     name: 'Name',
- *     age: 25
- * }
- *
- * m.name = 'A brand new name';
- * privUtils_.log(m.name); // Name
- */
 function propertyFactory_(that, name, value, flags, options) {
     flags = flags || 0;
     if (options === null || typeof options !== 'object') {
@@ -83,13 +59,13 @@ function propertyFactory_(that, name, value, flags, options) {
     if (!options.get && !options.set) {
         options.value = value;
     }
-    if ((flags & Property.W) != 0) {
+    if ((flags & Property.WRITEABLE) != 0) {
         options.writable = true;
     }
-    if ((flags & Property.E) != 0) {
+    if ((flags & Property.ENUMERABLE) != 0) {
         options.enumerable = true;
     }
-    if ((flags & Property.C) != 0) {
+    if ((flags & Property.CONFIGURABLE) != 0) {
         options.configurable = true;
     }
     Object.defineProperty(that, name, options);
@@ -115,24 +91,28 @@ function updateInternal_(internal, data) {
     }
 }
 
-/**
- * Specifies the Messaging service tags.
- */
-var MessageServiceTag = ['messaging.sms', 'messaging.mms', 'messaging.email'];
+var MessageServiceTag = {
+    SMS: 'messaging.sms',
+    MMS: 'messaging.mms',
+    EMAIL: 'messaging.email'
+};
 
 function Message(type, data) {
-    if (!(this instanceof Message)) {
-        throw new TypeError('Constructor called like a function');
-    }
-    if (MessageServiceTag.indexOf(type) === -1) {
+    privUtils_.deprecationWarn(
+        'Message() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
+    validator_.isConstructorCall(this, Message);
+
+    if (Object.values(MessageServiceTag).indexOf(type) == -1) {
         throw new WebAPIException(WebAPIException.TYPE_MISMATCH_ERR);
     }
+
     if (!data || typeof data !== 'object') {
-        // 'data' is optional
         data = {};
     }
 
-    // set initial data from internal MessageInit_ object or to default values
     var internal = data instanceof MessageInit_,
         id = internal ? data.id : null,
         conversationId = internal ? data.conversationId : null,
@@ -142,26 +122,28 @@ function Message(type, data) {
         hasAttachment = internal ? data.hasAttachment : false,
         isRead = internal ? data.isRead : false,
         inResponseTo = internal ? data.inResponseTo : null;
-    // create MessageBody object
+
     var body = new MessageBody({
         messageId: id,
         plainBody: data.plainBody,
         htmlBody: data.htmlBody
     });
-    // check 'to', 'cc' and 'bcc' fields
+
     var to = data.to;
     if (!(to instanceof Array)) {
         to = [];
     }
+
     var cc = data.cc;
     if (!(cc instanceof Array)) {
         cc = [];
     }
+
     var bcc = data.bcc;
     if (!(bcc instanceof Array)) {
         bcc = [];
     }
-    // 'attachments' private variable, getter and setter
+
     var attachments = (internal ? data.attachments : []) || [];
 
     var _internal = {
@@ -182,7 +164,7 @@ function Message(type, data) {
         inResponseTo: inResponseTo || null,
         attachments: attachments
     };
-    // id
+
     Object.defineProperty(this, 'id', {
         get: function() {
             return _internal.id;
@@ -193,7 +175,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    //conversationId
     Object.defineProperty(this, 'conversationId', {
         get: function() {
             return _internal.conversationId;
@@ -205,7 +186,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // folderId
     Object.defineProperty(this, 'folderId', {
         get: function() {
             return _internal.folderId;
@@ -216,7 +196,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // type
     Object.defineProperty(this, 'type', {
         get: function() {
             return _internal.type;
@@ -227,7 +206,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // timestamp
     Object.defineProperty(this, 'timestamp', {
         get: function() {
             return _internal.timestamp
@@ -242,7 +220,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // from
     Object.defineProperty(this, 'from', {
         get: function() {
             return _internal.from;
@@ -253,7 +230,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // to
     Object.defineProperty(this, 'to', {
         get: function() {
             return _internal.to;
@@ -265,7 +241,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // cc
     Object.defineProperty(this, 'cc', {
         get: function() {
             return _internal.cc;
@@ -277,7 +252,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // bcc
     Object.defineProperty(this, 'bcc', {
         get: function() {
             return _internal.bcc;
@@ -289,7 +263,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // body
     Object.defineProperty(this, 'body', {
         get: function() {
             return _internal.body;
@@ -302,7 +275,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // isRead
     Object.defineProperty(this, 'isRead', {
         get: function() {
             return _internal.isRead;
@@ -316,7 +288,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // hasAttachment
     Object.defineProperty(this, 'hasAttachment', {
         get: function() {
             return _internal.attachments.length > 0;
@@ -328,7 +299,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // isHighPriority
     Object.defineProperty(this, 'isHighPriority', {
         get: function() {
             return _internal.isHighPriority;
@@ -340,7 +310,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // subject
     Object.defineProperty(this, 'subject', {
         get: function() {
             return _internal.subject;
@@ -352,7 +321,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // inResponseTo
     Object.defineProperty(this, 'inResponseTo', {
         get: function() {
             return _internal.inResponseTo;
@@ -364,7 +332,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // messageStatus
     Object.defineProperty(this, 'messageStatus', {
         get: function() {
             if (_internal.id) {
@@ -385,7 +352,6 @@ function Message(type, data) {
         enumerable: true
     });
 
-    // attachments
     Object.defineProperty(this, 'attachments', {
         get: function() {
             return _internal.attachments;
@@ -423,27 +389,6 @@ function Message(type, data) {
     });
 }
 
-function MessageInit(data) {
-    if (!(this instanceof MessageInit)) {
-        return new MessageInit(data);
-    }
-    if (data === null || typeof data !== 'object') {
-        data = {};
-    }
-    propertyFactory_(this, 'subject', data.subject || '', Property.E | Property.W);
-    propertyFactory_(this, 'to', data.to || [], Property.E | Property.W);
-    propertyFactory_(this, 'cc', data.cc || [], Property.E | Property.W);
-    propertyFactory_(this, 'bcc', data.bcc || [], Property.E | Property.W);
-    propertyFactory_(this, 'plainBody', data.plainBody || '', Property.E | Property.W);
-    propertyFactory_(this, 'htmlBody', data.htmlBody || '', Property.E | Property.W);
-    propertyFactory_(
-        this,
-        'isHighPriority',
-        data.isHighPriority || false,
-        Property.E | Property.W
-    );
-}
-
 function MessageInit_(data) {
     if (!(this instanceof MessageInit_)) {
         return new MessageInit_(data);
@@ -498,7 +443,6 @@ function MessageBody(data) {
         inlineAttachments: data.inlineAttachments || []
     };
 
-    // messageId
     Object.defineProperty(this, 'messageId', {
         get: function() {
             return _internal.messageId;
@@ -509,7 +453,6 @@ function MessageBody(data) {
         enumerable: true
     });
 
-    // loaded
     Object.defineProperty(this, 'loaded', {
         get: function() {
             return _internal.loaded;
@@ -520,7 +463,6 @@ function MessageBody(data) {
         enumerable: true
     });
 
-    // plainBody
     Object.defineProperty(this, 'plainBody', {
         get: function() {
             return _internal.plainBody;
@@ -535,7 +477,6 @@ function MessageBody(data) {
         enumerable: true
     });
 
-    // htmlBody
     Object.defineProperty(this, 'htmlBody', {
         get: function() {
             return _internal.htmlBody;
@@ -550,7 +491,6 @@ function MessageBody(data) {
         enumerable: true
     });
 
-    // inlineAttachments
     Object.defineProperty(this, 'inlineAttachments', {
         get: function() {
             return _internal.inlineAttachments;
@@ -569,6 +509,11 @@ function MessageBody(data) {
 var messageAttachmentsLoaded = {};
 
 function MessageAttachment(first, second) {
+    privUtils_.deprecationWarn(
+        'MessageAttachment() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     validator_.isConstructorCall(this, MessageAttachment);
     if (!this instanceof MessageAttachment) {
         return new MessageAttachment(data);
@@ -586,7 +531,6 @@ function MessageAttachment(first, second) {
         filePath: internalConstructor ? first.filePath : first
     };
 
-    // messageId
     Object.defineProperty(this, 'messageId', {
         get: function() {
             return _internal.messageId;
@@ -596,7 +540,7 @@ function MessageAttachment(first, second) {
         },
         enumerable: true
     });
-    // id
+
     Object.defineProperty(this, 'id', {
         get: function() {
             return _internal.id;
@@ -606,7 +550,7 @@ function MessageAttachment(first, second) {
         },
         enumerable: true
     });
-    // mimeType
+
     Object.defineProperty(this, 'mimeType', {
         get: function() {
             return _internal.mimeType;
@@ -616,7 +560,7 @@ function MessageAttachment(first, second) {
         },
         enumerable: true
     });
-    // filePath
+
     Object.defineProperty(this, 'filePath', {
         get: function() {
             if (_internal.id && !messageAttachmentsLoaded[_internal.id]) {
@@ -634,17 +578,18 @@ function MessageAttachment(first, second) {
 
 function Messaging() {}
 
-/**
- * Gets the messaging service of a given type for a given account.
- * @param {!MessageServiceTag} messageServiceType Type of the services to be retrieved.
- * @param {!MessageServiceArraySuccessCallback} successCallback Callback function that
- *      is called when the services are successfully retrieved.
- * @param {ErrorCallback} errorCallback Callback function that is called when
- *      an error occurs.
- */
 Messaging.prototype.getMessageServices = function() {
+    privUtils_.deprecationWarn(
+        'getMessageServices() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
-        { name: 'messageServiceType', type: types_.ENUM, values: MessageServiceTag },
+        {
+            name: 'messageServiceType',
+            type: types_.ENUM,
+            values: Object.values(MessageServiceTag)
+        },
         { name: 'successCallback', type: types_.FUNCTION },
         { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
     ]);
@@ -670,13 +615,23 @@ Messaging.prototype.getMessageServices = function() {
 
 function MessageStorage() {}
 function MessageService(data) {
-    propertyFactory_(this, 'id', data.id, Property.E);
-    propertyFactory_(this, 'type', data.type, Property.E);
-    propertyFactory_(this, 'name', data.name, Property.E);
-    propertyFactory_(this, 'messageStorage', new MessageStorage(this), Property.E);
+    propertyFactory_(this, 'id', data.id, Property.ENUMERABLE);
+    propertyFactory_(this, 'type', data.type, Property.ENUMERABLE);
+    propertyFactory_(this, 'name', data.name, Property.ENUMERABLE);
+    propertyFactory_(
+        this,
+        'messageStorage',
+        new MessageStorage(this),
+        Property.ENUMERABLE
+    );
 }
 
 MessageService.prototype.sendMessage = function() {
+    privUtils_.deprecationWarn(
+        'sendMessage() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'message', type: types_.PLATFORM_OBJECT, values: tizen.Message },
         {
@@ -724,6 +679,11 @@ MessageService.prototype.sendMessage = function() {
 };
 
 MessageService.prototype.loadMessageBody = function() {
+    privUtils_.deprecationWarn(
+        'loadMessageBody() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'message', type: types_.PLATFORM_OBJECT, values: tizen.Message },
         { name: 'successCallback', type: types_.FUNCTION },
@@ -762,6 +722,11 @@ MessageService.prototype.loadMessageBody = function() {
     }
 };
 MessageService.prototype.loadMessageAttachment = function() {
+    privUtils_.deprecationWarn(
+        'loadMessageAttachment() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'attachment', type: types_.PLATFORM_OBJECT, values: MessageAttachment },
         { name: 'successCallback', type: types_.FUNCTION },
@@ -802,6 +767,11 @@ MessageService.prototype.loadMessageAttachment = function() {
 };
 
 MessageService.prototype.sync = function() {
+    privUtils_.deprecationWarn(
+        'sync() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'successCallback',
@@ -838,6 +808,11 @@ MessageService.prototype.sync = function() {
 };
 
 MessageService.prototype.syncFolder = function() {
+    privUtils_.deprecationWarn(
+        'syncFolder() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'folder', type: types_.PLATFORM_OBJECT, values: MessageFolder },
         {
@@ -876,6 +851,11 @@ MessageService.prototype.syncFolder = function() {
 };
 
 MessageService.prototype.stopSync = function() {
+    privUtils_.deprecationWarn(
+        'stopSync() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [{ name: 'opId', type: types_.LONG }]);
 
     var self = this;
@@ -894,6 +874,11 @@ function MessageStorage(service) {
 }
 
 MessageStorage.prototype.addDraftMessage = function() {
+    privUtils_.deprecationWarn(
+        'addDraftMessage() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'message', type: types_.PLATFORM_OBJECT, values: tizen.Message },
         {
@@ -945,6 +930,11 @@ MessageStorage.prototype.addDraftMessage = function() {
 };
 
 MessageStorage.prototype.findMessages = function() {
+    privUtils_.deprecationWarn(
+        'findMessages() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'filter',
@@ -997,6 +987,11 @@ MessageStorage.prototype.findMessages = function() {
 };
 
 MessageStorage.prototype.removeMessages = function() {
+    privUtils_.deprecationWarn(
+        'removeMessages() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'messages', type: types_.ARRAY, values: Message },
         {
@@ -1035,6 +1030,11 @@ MessageStorage.prototype.removeMessages = function() {
 };
 
 MessageStorage.prototype.updateMessages = function() {
+    privUtils_.deprecationWarn(
+        'updateMessages() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'messages', type: types_.ARRAY, values: Message },
         {
@@ -1096,6 +1096,11 @@ MessageStorage.prototype.updateMessages = function() {
 };
 
 MessageStorage.prototype.findConversations = function() {
+    privUtils_.deprecationWarn(
+        'findConversations() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'filter',
@@ -1147,6 +1152,11 @@ MessageStorage.prototype.findConversations = function() {
 };
 
 MessageStorage.prototype.removeConversations = function() {
+    privUtils_.deprecationWarn(
+        'removeConversations() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'conversations', type: types_.ARRAY },
         {
@@ -1185,6 +1195,11 @@ MessageStorage.prototype.removeConversations = function() {
 };
 
 MessageStorage.prototype.findFolders = function() {
+    privUtils_.deprecationWarn(
+        'findFolders() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'filter',
@@ -1277,6 +1292,11 @@ native.addListener(
 );
 
 MessageStorage.prototype.addMessagesChangeListener = function() {
+    privUtils_.deprecationWarn(
+        'addMessagesChangeListener() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'messagesChangeCallback',
@@ -1313,6 +1333,11 @@ MessageStorage.prototype.addMessagesChangeListener = function() {
 };
 
 MessageStorage.prototype.addConversationsChangeListener = function() {
+    privUtils_.deprecationWarn(
+        'addConversationsChangeListener() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'conversationsChangeCallback',
@@ -1352,6 +1377,11 @@ MessageStorage.prototype.addConversationsChangeListener = function() {
 };
 
 MessageStorage.prototype.addFoldersChangeListener = function() {
+    privUtils_.deprecationWarn(
+        'addFoldersChangeListener() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'foldersChangeCallback',
@@ -1388,6 +1418,11 @@ MessageStorage.prototype.addFoldersChangeListener = function() {
 };
 
 MessageStorage.prototype.removeChangeListener = function() {
+    privUtils_.deprecationWarn(
+        'removeChangeListener() is deprecated and will be ' +
+        'removed from next release without any alternatives. ',
+        '8.0'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'watchId', type: types_.LONG }
     ]);
@@ -1413,24 +1448,34 @@ MessageStorage.prototype.removeChangeListener = function() {
 };
 
 function MessageConversation(data) {
-    propertyFactory_(this, 'id', data.id || null, Property.E);
-    propertyFactory_(this, 'type', data.type || '', Property.E);
+    propertyFactory_(this, 'id', data.id || null, Property.ENUMERABLE);
+    propertyFactory_(this, 'type', data.type || '', Property.ENUMERABLE);
     propertyFactory_(
         this,
         'timestamp',
         data.timestamp ? new Date(data.timestamp * 1000) : null,
-        Property.E
+        Property.ENUMERABLE
+    );
+    propertyFactory_(this, 'messageCount', data.messageCount || 0, Property.ENUMERABLE);
+    propertyFactory_(
+        this,
+        'unreadMessages',
+        data.unreadMessages || 0,
+        Property.ENUMERABLE
+    );
+    propertyFactory_(this, 'preview', data.preview || '', Property.ENUMERABLE);
+    propertyFactory_(this, 'subject', data.subject || '', Property.ENUMERABLE);
+    propertyFactory_(this, 'isRead', data.isRead || false, Property.ENUMERABLE);
+    propertyFactory_(this, 'from', data.from || null, Property.ENUMERABLE);
+    propertyFactory_(this, 'to', data.to || [], Property.ENUMERABLE);
+    propertyFactory_(this, 'cc', data.cc || [], Property.ENUMERABLE);
+    propertyFactory_(this, 'bcc', data.bcc || [], Property.ENUMERABLE);
+    propertyFactory_(
+        this,
+        'lastMessageId',
+        data.lastMessageId || null,
+        Property.ENUMERABLE
     );
-    propertyFactory_(this, 'messageCount', data.messageCount || 0, Property.E);
-    propertyFactory_(this, 'unreadMessages', data.unreadMessages || 0, Property.E);
-    propertyFactory_(this, 'preview', data.preview || '', Property.E);
-    propertyFactory_(this, 'subject', data.subject || '', Property.E);
-    propertyFactory_(this, 'isRead', data.isRead || false, Property.E);
-    propertyFactory_(this, 'from', data.from || null, Property.E);
-    propertyFactory_(this, 'to', data.to || [], Property.E);
-    propertyFactory_(this, 'cc', data.cc || [], Property.E);
-    propertyFactory_(this, 'bcc', data.bcc || [], Property.E);
-    propertyFactory_(this, 'lastMessageId', data.lastMessageId || null, Property.E);
 }
 
 function MessageFolder(data) {