Bug 771458 - 0003. delete message in DB by array. r=vicamo

This commit is contained in:
Chuck Lee 2013-04-25 18:02:36 +08:00
parent 45838030bc
commit 4b50f70d10
2 changed files with 31 additions and 27 deletions

View File

@ -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,

View File

@ -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]);
},