[Messaging] Fixed update of messageId
authorPiotr Kosko <p.kosko@samsung.com>
Fri, 30 Jan 2015 08:44:15 +0000 (09:44 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 30 Jan 2015 09:45:04 +0000 (10:45 +0100)
[Bug] Updating messageId for messages with attachment not succeed.

[Verification] Code compiles without errors.
  TCT MessageStorage_email_updateMessages pass.

Change-Id: I406e673d303f2b5ff39f3c0a8f65778395d80cf2
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/messaging/email_manager.cc
src/messaging/message.cc
src/messaging/message.h
src/messaging/messaging_api.js
src/messaging/messaging_util.cc

index 1474cda298457404c9fe00420fcafa3945fce2a9..ef63611a431e95e43da590ee7f0c375c84396eef 100644 (file)
@@ -1004,6 +1004,8 @@ void EmailManager::updateMessages(MessagesCallbackUserData* callback)
                 addDraftMessagePlatform(mail->account_id, (*it));
                 LoggerD("mail added - new id = [%d]\n", (*it)->getId());
 
+                //storing old message id
+                (*it)->setOldId(mail->mail_id);
                 //deleting old mail
                 LoggerD("mail deleted = [%d]\n", mail->mail_id);
                 error = email_delete_mail(mail->mailbox_id,&mail->mail_id,1,1);
index efd5ad0e4f6344624d34ae5f96f36bb7af0dcb05..fa4753bf7d62fd7a10cd14d84d7bc6a612725276 100644 (file)
@@ -23,7 +23,7 @@ namespace messaging {
 
 // *** constructor
 Message::Message():
-    m_id(-1), m_id_set(false), m_conversation_id(-1),
+    m_id(-1), m_old_id(-1), m_id_set(false), m_conversation_id(-1),
     m_conversation_id_set(false), m_folder_id(-1), m_folder_id_set(false),
     m_type(UNDEFINED), m_timestamp_set(false), m_from_set(false),
     m_body(new(std::nothrow) MessageBody()),
@@ -46,6 +46,14 @@ int Message::getId() const
     return m_id;
 }
 
+int Message::getOldId() const
+{
+    if (-1 == m_old_id) {
+        return m_id;
+    }
+    return m_old_id;
+}
+
 int Message::getConversationId() const
 {
     return m_conversation_id;
@@ -150,6 +158,13 @@ void Message::setId(int id)
     }
 }
 
+void Message::setOldId(int id)
+{
+    LoggerD("Entered");
+    m_old_id = id;
+}
+
+
 void Message::setConversationId(int id)
 {
     LoggerD("Entered");
index ce6269a725f4c5cee671e7784b986a8d3bd115d7..0ef73cda2260dcf208c7c2043376bad394e3f26f 100644 (file)
@@ -48,6 +48,7 @@ public:
 
 // attributes getters
     int getId() const;
+    int getOldId() const;
     int getConversationId() const;
     int getFolderId() const;
     MessageType getType() const;
@@ -70,6 +71,7 @@ public:
 
 // attributes setters (virtual because some of them can be overriden in sub classes)
     virtual void setId(int id);
+    virtual void setOldId(int id);
     virtual void setConversationId(int id);
     virtual void setFolderId(int id);
     // type setting not allowed so no setter provided
@@ -156,6 +158,8 @@ public:
 protected:
     //! Message id
     int m_id;
+    //! Old Message id - for email update hack
+    int m_old_id;
     //! Flag for checking if id is set (false means: not set)
     bool m_id_set;
     //! Conversation id
index f2e9735a13a7ebc8811008eac6d64c1a6a7fc14e..d2a4927d1eae2ced5cdb1aadbbd86c2a77e4df23 100644 (file)
@@ -1041,21 +1041,28 @@ MessageStorage.prototype.updateMessages = function () {
         }
     }).then({
         success: function (data) {
-            var originals = {};
-            args.messages.forEach(function (m) {
+            var originals = {},
+                    i = args.messages.length,
+                    m;
+            while (i--) {
+                m = args.messages[i];
                 if (m.id) {
                     originals[m.id] = m;
                 }
-            });
-            data.forEach(function (message) {
-                if (!originals[message.id]) {return;}
-                var body = message.body;
-                if (body) {
-                    updateInternal_(originals[message.id].body, body)
-                    delete message.body;
+            }
+
+            i = data.length;
+            while (i--) {
+                m = data[i];
+                if (originals[m.oldId]) {
+                    var body = m.body;
+                    if (body) {
+                        updateInternal_(originals[m.oldId].body, body)
+                        delete m.body;
+                    }
+                    updateInternal_(originals[m.oldId], m);
                 }
-                updateInternal_(originals[message.id], message);
-            });
+            }
 
             if (args.successCallback) {
                 args.successCallback.call(null);
index 5d19c11b049f3185215f7cd9b5e77a2397ab1563..00bb3f9eef2e9b00f2581f321c942b2b49b94ca8 100644 (file)
@@ -38,6 +38,7 @@ const char* JSON_ERROR_MESSAGE = "message";
 const char* JSON_ERROR_NAME = "name";
 
 const char* MESSAGE_ATTRIBUTE_ID = "id";
+const char* MESSAGE_ATTRIBUTE_OLD_ID = "oldId";
 const char* MESSAGE_ATTRIBUTE_CONVERSATION_ID = "conversationId";
 const char* MESSAGE_ATTRIBUTE_FOLDER_ID = "folderId";
 const char* MESSAGE_ATTRIBUTE_TYPE = "type";
@@ -333,6 +334,7 @@ picojson::value MessagingUtil::messageToJson(std::shared_ptr<Message> message)
         o[MESSAGE_ATTRIBUTE_HAS_ATTACHMENT] = picojson::value(message->getHasAttachment());
         o[MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY] = picojson::value(message->getIsHighPriority());
         o[MESSAGE_ATTRIBUTE_SUBJECT] = picojson::value(message->getSubject());
+        o[MESSAGE_ATTRIBUTE_OLD_ID] = picojson::value(std::to_string(message->getOldId()));
 
         break;
     }