Bug 853752 - B2G MMS: after retrieving MMS, delete the thread containing the previous notification indication (follow-up fix). r=vicamo a=leo+
authorGene Lian <clian@mozilla.com>
Thu, 25 Apr 2013 19:47:44 +0800
changeset 140803 0e8b99f4d0b30a078e8aaf983481c36b91a1224f
parent 140802 7b13433d8d0c4552dbd35d2cf4c085cf6d6d86ee
child 140804 02bc24b84712c86d52af1a21e8e2d4ae5027ba7f
push id2579
push userakeybl@mozilla.com
push dateMon, 24 Jun 2013 18:52:47 +0000
treeherdermozilla-beta@b69b7de8a05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvicamo, leo
bugs853752
milestone23.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 853752 - B2G MMS: after retrieving MMS, delete the thread containing the previous notification indication (follow-up fix). r=vicamo a=leo+
dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
--- a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
+++ b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
@@ -850,20 +850,23 @@ MobileMessageDatabaseService.prototype =
         }
         aCallback(threadRecord, participantIds);
       };
     });
   },
 
   saveRecord: function saveRecord(aMessageRecord, aAddresses, aCallback) {
     let isOverriding = (aMessageRecord.id !== undefined);
+    let oldThreadId = 0;
     if (!isOverriding) {
       // Assign a new id.
       this.lastMessageId += 1;
       aMessageRecord.id = this.lastMessageId;
+    } else {
+      oldThreadId = aMessageRecord.threadId;
     }
     if (DEBUG) debug("Going to store " + JSON.stringify(aMessageRecord));
 
     let self = this;
     function notifyResult(rv) {
       if (!aCallback) {
         return;
       }
@@ -893,39 +896,38 @@ MobileMessageDatabaseService.prototype =
                                           aAddresses, true,
                                           function (threadRecord,
                                                     participantIds) {
         if (!participantIds) {
           notifyResult(Cr.NS_ERROR_FAILURE);
           return;
         }
 
-        // If the overriding message is going to be saved into another
-        // thread which is different from the original one containing the
-        // overrided message, we need to update the original thread info.
-        if (isOverriding &&
-            (!threadRecord || threadRecord.id != aMessageRecord.threadId)) {
-          self.updateThreadByMessageChange(messageStore,
-                                           threadStore,
-                                           aMessageRecord.threadId,
-                                           aMessageRecord.id,
-                                           aMessageRecord.read);
-        }
-
         let insertMessageRecord = function (threadId) {
           // Setup threadId & threadIdIndex.
           aMessageRecord.threadId = threadId;
           aMessageRecord.threadIdIndex = [threadId, timestamp];
           // Setup participantIdsIndex.
           aMessageRecord.participantIdsIndex = [];
           for each (let id in participantIds) {
             aMessageRecord.participantIdsIndex.push([id, timestamp]);
           }
           // Really add to message store.
           messageStore.put(aMessageRecord);
+
+          // If the overriding message is going to be saved into another
+          // thread which is different from the original one containing the
+          // overrided message, we need to update the original thread info.
+          if (isOverriding && threadId != oldThreadId) {
+            self.updateThreadByMessageChange(messageStore,
+                                             threadStore,
+                                             oldThreadId,
+                                             aMessageRecord.id,
+                                             aMessageRecord.read);
+          }
         };
 
         let timestamp = aMessageRecord.timestamp;
         if (threadRecord) {
           let needsUpdate = false;
 
           if (threadRecord.lastTimestamp <= timestamp) {
             threadRecord.lastTimestamp = timestamp;