Bug 955410 - Concatenated logs don't work for buddies and contacts, r=florian.
authoraleth <aleth@instantbird.org>
Sun, 23 Jun 2013 18:49:52 +0200
changeset 22661 ad4ff37b0a1a83788fb770a4c57f79c5c03debd2
parent 22660 f125bf018af2766c2dc72b6f6c7554d0d11d4109
child 22662 6382b153ac35277b3c61e9267823122496299b3a
push id1225
push userflorian@queze.net
push dateSat, 11 Jan 2014 23:24:55 +0000
treeherdertry-comm-central@1d7aa08cb2d7 [default view] [failures only]
reviewersflorian
bugs955410
Bug 955410 - Concatenated logs don't work for buddies and contacts, r=florian.
chat/components/public/imILogger.idl
chat/components/src/logger.js
--- a/chat/components/public/imILogger.idl
+++ b/chat/components/public/imILogger.idl
@@ -42,17 +42,27 @@ interface imILog: nsISupports {
   // Will return null if the log format isn't json.
   imILogConversation getConversation();
 };
 
 [scriptable, uuid(327ba58c-ee9c-4d1c-9216-fd505c45a3e0)]
 interface imILogger: nsISupports {
   imILog getLogFromFile(in nsIFile aFile, [optional] in boolean aGroupByDay);
   nsIFile getLogFileForOngoingConversation(in prplIConversation aConversation);
-  nsISimpleEnumerator getLogsForAccountBuddy(in imIAccountBuddy aAccountBuddy);
-  nsISimpleEnumerator getLogsForBuddy(in imIBuddy aBuddy);
-  nsISimpleEnumerator getLogsForContact(in imIContact aContact);
+
+  // Get logs for a username that may not be in the contact list.
+  nsISimpleEnumerator getLogsForAccountAndName(in imIAccount aAccount,
+                                               in string aNormalizedName,
+                                               [optional] in boolean aGroupByDay);
+
+  nsISimpleEnumerator getLogsForAccountBuddy(in imIAccountBuddy aAccountBuddy,
+                                             [optional] in boolean aGroupByDay);
+  nsISimpleEnumerator getLogsForBuddy(in imIBuddy aBuddy
+                                      [optional] in boolean aGroupByDay);
+  nsISimpleEnumerator getLogsForContact(in imIContact aContact
+                                        [optional] in boolean aGroupByDay);
+
   nsISimpleEnumerator getLogsForConversation(in prplIConversation aConversation,
                                              [optional] in boolean aGroupByDay);
   nsISimpleEnumerator getSystemLogsForAccount(in imIAccount aAccount);
   nsISimpleEnumerator getSimilarLogs(in imILog aLog,
                                      [optional] in boolean aGroupByDay);
 };
--- a/chat/components/src/logger.js
+++ b/chat/components/src/logger.js
@@ -607,26 +607,23 @@ LogCluster.prototype = {
       // LogConversation constructor will throw.
       return null;
     }
   }
 };
 
 function Logger() { }
 Logger.prototype = {
-  _enumerateLogs: function logger__enumerateLogs(aAccount, aNormalizedName,
-                                                 aGroupByDay) {
+  _getLogArray: function logger__getLogArray(aAccount, aNormalizedName) {
+    let entries = [];
     let file = getLogFolderForAccount(aAccount);
     file.append(encodeName(aNormalizedName));
-    if (!file.exists())
-      return EmptyEnumerator;
-
-    let enumerator = aGroupByDay ? DailyLogEnumerator : LogEnumerator;
-
-    return new enumerator([file.directoryEntries]);
+    if (file.exists())
+      entries.push(file.directoryEntries);
+    return entries;
   },
   getLogFromFile: function logger_getLogFromFile(aFile, aGroupByDay) {
     if (aGroupByDay)
       return this._getDailyLogFromFile(aFile);
 
     return new Log(aFile);
   },
   _getDailyLogFromFile: function logger_getDailyLogsForFile(aFile) {
@@ -655,55 +652,62 @@ Logger.prototype = {
           file: file,
           time: logTime
         });
       }
     }
 
     return new LogCluster(relevantEntries);
   },
+  _getEnumerator: function logger__getEnumerator(aLogArray, aGroupByDay) {
+    let enumerator = aGroupByDay ? DailyLogEnumerator : LogEnumerator;
+    return aLogArray.length ? new enumerator(aLogArray) : EmptyEnumerator;
+  },
   getLogFileForOngoingConversation: function logger_getLogFileForOngoingConversation(aConversation)
     getLogForConversation(aConversation).file,
-  getLogsForContact: function logger_getLogsForContact(aContact) {
-    let entries = [];
-    aContact.getBuddies().forEach(function (aBuddy) {
-      aBuddy.getAccountBuddies().forEach(function (aAccountBuddy) {
-        let file = getLogFolderForAccount(aAccountBuddy.account);
-        file.append(encodeName(aAccountBuddy.normalizedName));
-        if (file.exists())
-          entries.push(file.directoryEntries);
-      });
-    });
-    return new LogEnumerator(entries);
+  getLogsForAccountAndName: function logger_getLogsForAccountAndName(aAccount,
+                                       aNormalizedName, aGroupByDay) {
+    let entries = this._getLogArray(aAccount, aNormalizedName);
+    return this._getEnumerator(entries, aGroupByDay);
+  },
+  getLogsForAccountBuddy: function logger_getLogsForAccountBuddy(aAccountBuddy,
+                                                                 aGroupByDay) {
+    return this.getLogsForAccountAndName(aAccountBuddy.account,
+                                         aAccountBuddy.normalizedName, aGroupByDay);
   },
-  getLogsForBuddy: function logger_getLogsForBuddy(aBuddy) {
+  getLogsForBuddy: function logger_getLogsForBuddy(aBuddy, aGroupByDay) {
     let entries = [];
-    aBuddy.getAccountBuddies().forEach(function (aAccountBuddy) {
-      let file = getLogFolderForAccount(aAccountBuddy.account);
-      file.append(encodeName(aAccountBuddy.normalizedName));
-      if (file.exists())
-        entries.push(file.directoryEntries);
-    });
-    return new LogEnumerator(entries);
+    for (let accountBuddy of aBuddy.getAccountBuddies()) {
+      entries = entries.concat(this._getLogArray(accountBuddy.account,
+                                                 accountBuddy.normalizedName));
+    }
+    return this._getEnumerator(entries, aGroupByDay);
   },
-  getLogsForAccountBuddy: function logger_getLogsForAccountBuddy(aAccountBuddy)
-    this._enumerateLogs(aAccountBuddy.account, aAccountBuddy.normalizedName),
+  getLogsForContact: function logger_getLogsForContact(aContact, aGroupByDay) {
+    let entries = [];
+    for (let buddy of aContact.getBuddies()) {
+      for (let accountBuddy of buddy.getAccountBuddies()) {
+        entries = entries.concat(this._getLogArray(accountBuddy.account,
+                                                   accountBuddy.normalizedName));
+      }
+    }
+    return this._getEnumerator(entries, aGroupByDay);
+  },
   getLogsForConversation: function logger_getLogsForConversation(aConversation,
                                                                  aGroupByDay) {
     let name = aConversation.normalizedName;
     if (convIsRealMUC(aConversation))
       name += ".chat";
-
-    return this._enumerateLogs(aConversation.account, name, aGroupByDay);
+    return this.getLogsForAccountAndName(aConversation.account, name, aGroupByDay);
   },
   getSystemLogsForAccount: function logger_getSystemLogsForAccount(aAccount)
-    this._enumerateLogs(aAccount, ".system"),
+    this.getLogsForAccountAndName(aAccount, ".system"),
   getSimilarLogs: function(aLog, aGroupByDay) {
-    let enumerator = aGroupByDay ? DailyLogEnumerator : LogEnumerator;
-    return new enumerator([new LocalFile(aLog.path).parent.directoryEntries]);
+    return this._getEnumerator([new LocalFile(aLog.path).parent.directoryEntries],
+                               aGroupByDay);
   },
 
   observe: function logger_observe(aSubject, aTopic, aData) {
     switch (aTopic) {
     case "profile-after-change":
       Services.obs.addObserver(this, "final-ui-startup", false);
       break;
     case "final-ui-startup":