Bug 833291 - Part 5/7: fix markMessageRead(). r=hsinyi

This commit is contained in:
Vicamo Yang 2013-03-08 00:12:49 +08:00
parent 85dbb3cff2
commit 1ab924d37a

View File

@ -1309,7 +1309,7 @@ MobileMessageDatabaseService.prototype = {
} 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);
}
@ -1671,7 +1671,7 @@ MobileMessageDatabaseService.prototype = {
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) {
@ -1704,26 +1704,27 @@ MobileMessageDatabaseService.prototype = {
}
// 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) {