Bug 833291 - Part 5/7: fix markMessageRead(). r=hsinyi
authorVicamo Yang <vyang@mozilla.com>
Fri, 08 Mar 2013 00:12:49 +0800
changeset 124115 28bd1c831210ad70fcf5d4a3567753c2b71fda8e
parent 124114 23d5f8aff7c5c38ac9f59cc86d353a81aed45bf1
child 124116 917a2c1cad20a2957d067116cdd9bc42e230b0f9
push id24408
push userryanvm@gmail.com
push dateFri, 08 Mar 2013 04:58:11 +0000
treeherdermozilla-central@cb432984d5ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsinyi
bugs833291
milestone22.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 833291 - Part 5/7: fix markMessageRead(). r=hsinyi
dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
--- a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
+++ b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js
@@ -1304,17 +1304,17 @@ MobileMessageDatabaseService.prototype =
                     debug("Updating mru entry: " +
                           JSON.stringify(threadRecord));
                   }
                   threadStore.put(threadRecord);
                 };
               } else if (!messageRecord.read) {
                 // Shortcut, just update the unread count.
                 if (DEBUG) {
-                  debug("Updating unread count for number '" + number + "': " +
+                  debug("Updating unread count for thread id " + threadId + ": " +
                         (threadRecord.unreadCount + 1) + " -> " +
                         threadRecord.unreadCount);
                 }
                 threadStore.put(threadRecord);
               }
             };
           };
         } else if (DEBUG) {
@@ -1666,17 +1666,17 @@ MobileMessageDatabaseService.prototype =
         aRequest.notifyMarkMessageReadFailed(Ci.nsISmsRequest.INTERNAL_ERROR);
         return;
       }
       txn.onerror = function onerror(event) {
         if (DEBUG) debug("Caught error on transaction ", event.target.errorCode);
         aRequest.notifyMarkMessageReadFailed(Ci.nsISmsRequest.INTERNAL_ERROR);
       };
       let messageStore = stores[0];
-      let mostRecentStore = stores[1];
+      let threadStore = stores[1];
       messageStore.get(messageId).onsuccess = function onsuccess(event) {
         let messageRecord = event.target.result;
         if (!messageRecord) {
           if (DEBUG) debug("Message ID " + messageId + " not found");
           aRequest.notifyMarkMessageReadFailed(Ci.nsISmsRequest.NOT_FOUND_ERROR);
           return;
         }
         if (messageRecord.id != messageId) {
@@ -1699,36 +1699,37 @@ MobileMessageDatabaseService.prototype =
         if (DEBUG) debug("Message.read set to: " + value);
         messageStore.put(messageRecord).onsuccess = function onsuccess(event) {
           if (DEBUG) {
             debug("Update successfully completed. Message: " +
                   JSON.stringify(event.target.result));
           }
 
           // Now update the unread count.
-          let number = getNumberFromRecord(messageRecord);
+          let threadId = messageRecord.threadId;
 
-          mostRecentStore.get(number).onsuccess = function(event) {
-            let mostRecentRecord = event.target.result;
-            mostRecentRecord.unreadCount += value ? -1 : 1;
+          threadStore.get(threadId).onsuccess = function(event) {
+            let threadRecord = event.target.result;
+            threadRecord.unreadCount += value ? -1 : 1;
             if (DEBUG) {
-              debug("Updating unreadCount for '" + number + "': " +
+              debug("Updating unreadCount for thread id " + threadId + ": " +
                     (value ?
-                     mostRecentRecord.unreadCount + 1 :
-                     mostRecentRecord.unreadCount - 1) +
-                    " -> " + mostRecentRecord.unreadCount);
+                     threadRecord.unreadCount + 1 :
+                     threadRecord.unreadCount - 1) +
+                     " -> " + threadRecord.unreadCount);
             }
-            mostRecentStore.put(mostRecentRecord).onsuccess = function(event) {
+            threadStore.put(threadRecord).onsuccess = function(event) {
               aRequest.notifyMessageMarkedRead(messageRecord.read);
             };
           };
         };
       };
-    }, [MESSAGE_STORE_NAME, MOST_RECENT_STORE_NAME]);
+    }, [MESSAGE_STORE_NAME, THREAD_STORE_NAME]);
   },
+
   getThreadList: function getThreadList(aRequest) {
     if (DEBUG) debug("Getting thread list");
     this.newTxn(READ_ONLY, function (error, txn, mostRecentStore) {
       if (error) {
         if (DEBUG) debug(error);
         aRequest.notifyThreadListFailed(Ci.nsISmsRequest.INTERNAL_ERROR);
         return;
       }