Permalink
Browse files

Bug 820310 - [B2G SMS] Multiple markMessageRead() calls causes signif…

…icant performance issues. r=borjasalguero

Fixing typo

Addressing feedback and marking thread as read
  • Loading branch information...
1 parent 185cccd commit b9358df4a06c522733dbeaca81b426ed402851f9 @ferjm ferjm committed Dec 21, 2012
Showing with 25 additions and 21 deletions.
  1. +25 −21 apps/sms/js/sms.js
View
@@ -40,7 +40,7 @@ var MessageManager = {
break;
if (num == sender) {
//Append message and mark as unread
- MessageManager.markMessageRead(event.message.id, true, function() {
+ MessageManager.markMessagesRead([event.message.id], true, function() {
MessageManager.getMessages(ThreadListUI.renderThreads);
});
ThreadUI.appendMessage(event.message, function() {
@@ -122,6 +122,11 @@ var MessageManager = {
messageInput.focus();
} else {
+ // As soon as we click in the thread, we visually mark it
+ // as read.
+ document.getElementById('thread_' + num)
+ .getElementsByTagName('a')[0].classList
+ .remove('unread');
this.getMessages(ThreadUI.renderMessages,
filter, true, function() {
MessageManager.slide(function() {
@@ -251,30 +256,29 @@ var MessageManager = {
callback();
},
- markMessageRead: function mm_markMessageRead(id, value, callback) {
- if (navigator.mozSms) {
- var req = navigator.mozSms.markMessageRead(id, value);
- req.onsuccess = function onsuccess() {
+ markMessagesRead: function mm_markMessagesRead(list, value, callback) {
+ if (!navigator.mozSms || !list.length) {
+ return;
+ }
+
+ // We chain the calls to the API in a way that we make no call to
+ // 'markMessageRead' until a previous call is completed. This way any
+ // other potential call to the API, like the one for getting a message
+ // list, could be done within the calls to mark the messages as read.
+ var req = navigator.mozSms.markMessageRead(list.pop(), value);
+ req.onsuccess = (function onsuccess() {
+ if (!list.length && callback) {
callback(req.result);
- };
+ return;
+ }
+ this.markMessagesRead(list, value, callback);
+ }).bind(this);
- req.onerror = function onerror() {
- var msg = 'Mark message error in the database. Error: ' + req.errorCode;
- console.log(msg);
+ req.onerror = function onerror() {
+ if (callback) {
callback(null);
- };
- }
- },
-
- markMessagesRead: function mm_markMessagesRead(list, value, callback) {
- // TODO Will be fixed in https://bugzilla.mozilla.org/show_bug.cgi?id=771463
- for (var i = 0; i < list.length; i++) {
- if (i == list.length - 1) {
- MessageManager.markMessageRead(list[i], value, callback);
- } else {
- MessageManager.markMessageRead(list[i], value);
}
- }
+ };
}
};

0 comments on commit b9358df

Please sign in to comment.