[Messaging] Show file path if attachment is loaded.
authorTomasz Marciniak <t.marciniak@samsung.com>
Wed, 4 Feb 2015 07:38:24 +0000 (08:38 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 4 Feb 2015 08:14:46 +0000 (17:14 +0900)
[Verification] Code compiles without errors.

Change-Id: Iac52889c500de47e1fb6067492f2ddf11b9177e9
Signed-off-by: Tomasz Marciniak <t.marciniak@samsung.com>
src/messaging/messaging_api.js

index d2a4927d1eae2ced5cdb1aadbbd86c2a77e4df23..be6af1619306e037f72d6c1346cc24185ddc184c 100644 (file)
@@ -584,6 +584,8 @@ function MessageBody(data) {
     );
 };
 
+var messageAttachmentsLoaded = {};
+
 function MessageAttachment(first, second) {
     validator_.isConstructorCall(this, MessageAttachment);
     if (!this instanceof MessageAttachment) {
@@ -639,7 +641,13 @@ function MessageAttachment(first, second) {
         this,
         'filePath',
         {
-            get: function () {return _internal.filePath;},
+            get: function () {
+                if (_internal.id && !messageAttachmentsLoaded[_internal.id]) {
+                    return null;
+                }
+
+                return _internal.filePath;
+            },
             set: function (value) {
                 if (value instanceof InternalValues_) _internal.filePath = value.filePath;
             },
@@ -783,6 +791,11 @@ MessageService.prototype.loadMessageAttachment = function () {
     ]);
 
     var self = this;
+    var firstCall = false;
+    if (!messageAttachmentsLoaded[args.attachment.id]) {
+        firstCall = true;
+        messageAttachmentsLoaded[args.attachment.id] = true;
+    }
 
     bridge.async({
         cmd: 'MessageService_loadMessageAttachment',
@@ -793,13 +806,21 @@ MessageService.prototype.loadMessageAttachment = function () {
     }).then({
         success: function (data) {
             if (args.successCallback) {
+                var messageAttachment = data.messageAttachment;
+                if (messageAttachment) {
+                    updateInternal_(args.attachment, messageAttachment);
+                }
+
                 args.successCallback.call(
                     null,
-                    new MessageAttachment(new InternalValues_(data.messageAttachment))
+                    args.attachment
                 );
             }
         },
         error: function (e) {
+            if (firstCall) {
+                messageAttachmentsLoaded[args.attachment.id] = false;
+            }
             if (args.errorCallback) {
                 args.errorCallback.call(
                     null,
@@ -931,6 +952,12 @@ MessageStorage.prototype.addDraftMessage = function () {
                     updateInternal_(args.message.body, body)
                     delete message.body;
                 }
+                var attachments = message.attachments;
+                if (attachments) {
+                    for (var i = 0; i < attachments.length; i++) {
+                        messageAttachmentsLoaded[attachments[i].id] = true;
+                    }
+                }
                 updateInternal_(args.message, message);
             }
 
@@ -1483,4 +1510,4 @@ tizen.Message = Message;
 
 tizen.MessageAttachment = MessageAttachment;
 
-exports = new Messaging();
+exports = new Messaging();
\ No newline at end of file