From 4b50f70d10862a0420478a94a40ed16a30f3c484 Mon Sep 17 00:00:00 2001 From: Chuck Lee Date: Thu, 25 Apr 2013 18:02:36 +0800 Subject: [PATCH] Bug 771458 - 0003. delete message in DB by array. r=vicamo --- .../nsIMobileMessageDatabaseService.idl | 5 +- .../src/ril/MobileMessageDatabaseService.js | 53 ++++++++++--------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/dom/mobilemessage/interfaces/nsIMobileMessageDatabaseService.idl b/dom/mobilemessage/interfaces/nsIMobileMessageDatabaseService.idl index de06c761f8e..16051b2cfba 100644 --- a/dom/mobilemessage/interfaces/nsIMobileMessageDatabaseService.idl +++ b/dom/mobilemessage/interfaces/nsIMobileMessageDatabaseService.idl @@ -16,14 +16,15 @@ interface nsIDOMMozSmsFilter; interface nsIMobileMessageCallback; interface nsIMobileMessageCursorCallback; -[scriptable, uuid(ec1ca45f-e621-4c67-9c50-74c16842e780)] +[scriptable, uuid(ea6f49ae-3a4c-47eb-a489-15578e634100)] interface nsIMobileMessageDatabaseService : nsISupports { [binaryname(GetMessageMoz)] void getMessage(in long messageId, in nsIMobileMessageCallback request); - void deleteMessage(in long messageId, + void deleteMessage([array, size_is(count)] in long messageIds, + in uint32_t count, in nsIMobileMessageCallback request); nsICursorContinueCallback createMessageCursor(in nsIDOMMozSmsFilter filter, diff --git a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js index 91433a50f57..33d796b5966 100644 --- a/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js +++ b/dom/mobilemessage/src/ril/MobileMessageDatabaseService.js @@ -1417,9 +1417,9 @@ MobileMessageDatabaseService.prototype = { }; }, - deleteMessage: function deleteMessage(messageId, aRequest) { - if (DEBUG) debug("deleteMessage: message id " + messageId); - let deleted = false; + deleteMessage: function deleteMessage(messageIds, length, aRequest) { + if (DEBUG) debug("deleteMessage: message ids " + JSON.stringify(messageIds)); + let deleted = []; let self = this; this.newTxn(READ_WRITE, function (error, txn, stores) { if (error) { @@ -1436,34 +1436,37 @@ MobileMessageDatabaseService.prototype = { const messageStore = stores[0]; const threadStore = stores[1]; - let deleted = false; - txn.oncomplete = function oncomplete(event) { if (DEBUG) debug("Transaction " + txn + " completed."); - aRequest.notifyMessageDeleted(deleted); + aRequest.notifyMessageDeleted(deleted, length); }; - messageStore.get(messageId).onsuccess = function(event) { - let messageRecord = event.target.result; - if (messageRecord) { - if (DEBUG) debug("Deleting message id " + messageId); + for (let i = 0; i < length; i++) { + let messageId = messageIds[i]; + deleted[i] = false; + messageStore.get(messageId).onsuccess = function(messageIndex, event) { + let messageRecord = event.target.result; + let messageId = messageIds[messageIndex]; + if (messageRecord) { + if (DEBUG) debug("Deleting message id " + messageId); - // First actually delete the message. - messageStore.delete(messageId).onsuccess = function(event) { - if (DEBUG) debug("Message id " + messageId + " deleted"); - deleted = true; + // First actually delete the message. + messageStore.delete(messageId).onsuccess = function(event) { + if (DEBUG) debug("Message id " + messageId + " deleted"); + deleted[messageIndex] = true; - // Then update unread count and most recent message. - self.updateThreadByMessageChange(messageStore, - threadStore, - messageRecord.threadId, - messageId, - messageRecord.read); - }; - } else if (DEBUG) { - debug("Message id " + messageId + " does not exist"); - } - }; + // Then update unread count and most recent message. + self.updateThreadByMessageChange(messageStore, + threadStore, + messageRecord.threadId, + messageId, + messageRecord.read); + }; + } else if (DEBUG) { + debug("Message id " + messageId + " does not exist"); + } + }.bind(null, i); + } }, [MESSAGE_STORE_NAME, THREAD_STORE_NAME]); },