Bug 499265 - "Activity manager should coalesce mail move/copy/delete events." [r=Standard8]
authorBlake Winton <bwinton@latte.ca>
Thu, 02 Jul 2009 18:57:53 +0100
changeset 2995 d971def57e3c8a6760b1a7744d933c153d155b9a
parent 2994 e347074037b062fd847f0fb167f6b69cd4679b65
child 2996 818dd2a4bb6cd55dc52d0310744a71f1ccd2e655
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs499265
Bug 499265 - "Activity manager should coalesce mail move/copy/delete events." [r=Standard8]
mail/components/activity/modules/moveCopy.js
mail/locales/en-US/chrome/messenger/activity.properties
--- a/mail/components/activity/modules/moveCopy.js
+++ b/mail/components/activity/modules/moveCopy.js
@@ -55,16 +55,17 @@ Components.utils.import("resource://gre/
 Components.utils.import("resource://app/modules/gloda/log4moz.js");
 
 
 
 // This module provides a link between the move/copy code and the activity
 // manager.
 let moveCopyModule =
 {
+  lastMessage: {},
 
   get log() {
     delete this.log;
     return this.log = Log4Moz.getConfiguredLogger("moveCopyModule");
   },
 
   get activityMgr() {
     delete this.activityMgr;
@@ -95,92 +96,126 @@ let moveCopyModule =
 
   msgsDeleted : function(aMsgList) {
     this.log.info("in msgsDeleted");
 
     let count = aMsgList.length;
     if (count <= 0)
       return;
 
+    let displayCount = count;
     // get the folder of the deleted messages
     let folder = aMsgList.queryElementAt(0, Components.interfaces.nsIMsgDBHdr).folder;
 
-    let displayText = PluralForm.get(count, this.getString("deletedMessages"));
-    displayText = displayText.replace("#1", count)
+    let activities = this.activityMgr.getActivities({})
+    if (activities.length > 0 &&
+        activities[activities.length-1].id == this.lastMessage.id &&
+        this.lastMessage.type == "deleteMail" &&
+        this.lastMessage.folder == folder.prettiestName)
+    {
+      displayCount += this.lastMessage.count;
+      this.activityMgr.removeActivity(this.lastMessage.id);
+    }
+
+    this.lastMessage = {};
+    let displayText = PluralForm.get(displayCount, this.getString("deletedMessages2"));
+    displayText = displayText.replace("#1", displayCount)
+    this.lastMessage.count = displayCount;
     displayText = displayText.replace("#2", folder.prettiestName)
+    this.lastMessage.folder = folder.prettiestName;
 
     let statusText = folder.server.prettyName;
 
     // create an activity event
     let event = new nsActEvent(displayText,
                                folder,
                                statusText,
                                Date.now(),  // start time
                                Date.now()); // completion time
 
     event.iconClass = "deleteMail";
-          
+    this.lastMessage.type = event.iconClass;
+
     for (let i = 0; i < count; i++)
     {
       let msgHdr = aMsgList.queryElementAt(i, Components.interfaces.nsIMsgDBHdr);
       event.addSubject(msgHdr.messageId);
     }
 
-    this.activityMgr.addActivity(event);
+    this.lastMessage.id = this.activityMgr.addActivity(event);
   },
 
   msgsMoveCopyCompleted : function(aMove, aSrcMsgList, aDestFolder) {
     try {
       this.log.info("in msgsMoveCopyCompleted");
 
       let count = aSrcMsgList.length;
       if (count <= 0)
         return;
 
       // get the folder of the moved/copied messages
       let folder = aSrcMsgList.queryElementAt(0, Components.interfaces.nsIMsgDBHdr).folder;
       this.log.info("got folder");
 
+      let displayCount = count;
+
+      let activities = this.activityMgr.getActivities({})
+      if (activities.length > 0 &&
+          activities[activities.length-1].id == this.lastMessage.id &&
+          this.lastMessage.type == aMove ? "moveMail" : "copyMail" &&
+          this.lastMessage.sourceFolder == folder.prettiestName &&
+          this.lastMessage.destFolder == aDestFolder.prettiestName)
+      {
+        displayCount += this.lastMessage.count;
+        this.activityMgr.removeActivity(this.lastMessage.id);
+      }
+
       let statusText = '';
-      // TODO: localize this string
       if (folder.server != aDestFolder.server)
       {
         statusText = this.getString("fromServerToServer");
         statusText = statusText.replace("#1", folder.server.prettyName);
         statusText = statusText.replace("#2", aDestFolder.server.prettyName);
       }
       else
       {
         statusText = folder.server.prettyName;
       }
 
+      this.lastMessage = {};
       let displayText;
       if (aMove)
-        displayText = PluralForm.get(count, this.getString("movedMessages"));
+        displayText = PluralForm.get(displayCount,
+                                     this.getString("movedMessages"));
       else
-        displayText = PluralForm.get(count, this.getString("copiedMessages"));
+        displayText = PluralForm.get(displayCount,
+                                     this.getString("copiedMessages"));
 
-      displayText = displayText.replace("#1", count)
+      displayText = displayText.replace("#1", displayCount)
+      this.lastMessage.count = displayCount;
       displayText = displayText.replace("#2", folder.prettiestName)
+      this.lastMessage.sourceFolder = folder.prettiestName;
       displayText = displayText.replace("#3", aDestFolder.prettiestName)
+      this.lastMessage.destFolder = aDestFolder.prettiestName;
 
       // create an activity event
       let event = new nsActEvent(displayText,
                                  folder,
                                  statusText,
                                  Date.now(),    // start time
                                  Date.now());   // completion time
       event.iconClass = aMove ? "moveMail" : "copyMail";
+      this.lastMessage.type = event.iconClass;
 
       for (let i = 0; i < count; i++)
       {
         let msgHdr = aSrcMsgList.queryElementAt(i, Components.interfaces.nsIMsgDBHdr);
         event.addSubject(msgHdr.messageId);
       }
-      this.activityMgr.addActivity(event);
+      this.lastMessage.id = this.activityMgr.addActivity(event);
     } catch (e) {
       this.log.error("Exception: " + e)
     }
   },
 
   folderAdded: function(aFolder) {
   },
 
--- a/mail/locales/en-US/chrome/messenger/activity.properties
+++ b/mail/locales/en-US/chrome/messenger/activity.properties
@@ -40,18 +40,18 @@ autosyncProcessDisplayText=Bringing fold
 autosyncEventDisplayText=%S is up to date
 # LOCALIZATION NOTE (autosyncEventStatusText): %S will be replaced by total number of downloaded messages
 autosyncEventStatusText=Total number of messages downloaded: %S
 autosyncEventStatusTextNoMsgs=No messages downloaded
 # LOCALIZATION NOTE (autosyncContextDisplayText): %S will be replaced by the account name
 autosyncContextDisplayText=Synchronizing: %S
 
 # Message actions that show up in activity manager
-# LOCALIZATION NOTE (deletedMessages): #1 number of messages
-deletedMessages=Deleted #1 message;Deleted #1 messages
+# LOCALIZATION NOTE (deletedMessages2): #1 number of messages, #2 folder name
+deletedMessages2=Deleted #1 message from #2;Deleted #1 messages from #2
 # LOCALIZATION NOTE (movedMessages): #1 number of messages, #2 and #3: folder names
 movedMessages=Moved #1 message from #2 to #3;Moved #1 messages from #2 to #3
 # LOCALIZATION NOTE (copiedMessages): #1 number of messages, #2 and #3: folder names
 copiedMessages=Copied #1 message from #2 to #3;Copied #1 messages from #2 to #3
 # LOCALIZATION NOTE (fromServerToServer): #1 source server, #2 destination server
 fromServerToServer=from #1 to #2
 # LOCALIZATION NOTE (deletedFolder): #1 folder name
 deletedFolder=Deleted folder #1