From 73193764ce31861677283c719d74c58ad2189b36 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 14 Sep 2021 13:24:55 +0300 Subject: [PATCH] Bug 1718317 - Remove always set group-by-day option in chat logging infrastructure. r=freaktechnik --- chat/components/public/imILogger.idl | 13 ++++--- chat/components/src/logger.jsm | 37 ++++++-------------- chat/components/src/test/test_logger.js | 14 +------- mail/components/im/content/chat-messenger.js | 6 ++-- 4 files changed, 21 insertions(+), 49 deletions(-) diff --git a/chat/components/public/imILogger.idl b/chat/components/public/imILogger.idl index 65f4c0f891..46f21fe9ba 100644 --- a/chat/components/public/imILogger.idl +++ b/chat/components/public/imILogger.idl @@ -63,13 +63,12 @@ interface imILogger: nsISupports { // Below methods return promises that resolve to {imILog[]}. - jsval getLogsForContact(in imIContact aContact, - [optional] in boolean aGroupByDay); - - jsval getLogsForConversation(in prplIConversation aConversation, - [optional] in boolean aGroupByDay); - jsval getSimilarLogs(in imILog aLog, - [optional] in boolean aGroupByDay); + // Get logs for a contact. + jsval getLogsForContact(in imIContact aContact); + // Get logs for a conversation. + jsval getLogsForConversation(in prplIConversation aConversation); + // Get logs that are from the same conversation. + jsval getSimilarLogs(in imILog aLog); // Asynchronously iterates through log folders for all prpls and accounts and // invokes the callback on every log file. Returns a promise that resolves when diff --git a/chat/components/src/logger.jsm b/chat/components/src/logger.jsm index c84a9e4257..f1e502de76 100644 --- a/chat/components/src/logger.jsm +++ b/chat/components/src/logger.jsm @@ -602,6 +602,10 @@ Log.prototype = { * @returns {imILog[]} Logs, ordered by day. */ function logsGroupedByDay(aEntries) { + if (!Array.isArray(aEntries)) { + return []; + } + let entries = {}; for (let path of aEntries) { let [logDate, logFormat] = getDateFromFilename(PathUtils.filename(path)); @@ -696,25 +700,6 @@ Logger.prototype = { return new Log(relevantEntries); }, - /** - * Helper to produce array of imILog objects from directory entries. - * - * @param {string[]} entries - Array of paths of log files to be parsed. - * @param {boolean} groupByDay - If true, order by day (rather than by filename). - * @returns {imILog[]} Logs, ordered by day. - */ - _toLogArray(entries, groupByDay) { - if (!Array.isArray(entries)) { - return []; - } - if (groupByDay) { - return logsGroupedByDay(entries); - } - // Default - sort by filename. - entries.sort((a, b) => PathUtils.filename(a) > PathUtils.filename(b)); - return entries.map(path => new Log(path)); - }, - async getLogPathsForConversation(aConversation) { let writer = gLogWritersById.get(aConversation.id); // Resolve to null if we haven't created a LogWriter yet for this conv, or @@ -730,7 +715,7 @@ Logger.prototype = { } return paths; }, - async getLogsForContact(aContact, aGroupByDay) { + async getLogsForContact(aContact) { let entries = []; for (let buddy of aContact.getBuddies()) { for (let accountBuddy of buddy.getAccountBuddies()) { @@ -742,19 +727,19 @@ Logger.prototype = { ); } } - return this._toLogArray(entries, aGroupByDay); + return logsGroupedByDay(entries); }, - getLogsForConversation(aConversation, aGroupByDay) { + getLogsForConversation(aConversation) { let name = aConversation.normalizedName; if (aConversation.isChat) { name += ".chat"; } - return this._getLogEntries(aConversation.account, name).then(aEntries => - this._toLogArray(aEntries, aGroupByDay) + return this._getLogEntries(aConversation.account, name).then(entries => + logsGroupedByDay(entries) ); }, - async getSimilarLogs(aLog, aGroupByDay) { + async getSimilarLogs(aLog) { let entries; try { entries = await IOUtils.getChildren(PathUtils.parent(aLog.path)); @@ -764,7 +749,7 @@ Logger.prototype = { ); } // If there was an error, this will return an empty array. - return this._toLogArray(entries, aGroupByDay); + return logsGroupedByDay(entries); }, getLogFolderPathForAccount(aAccount) { diff --git a/chat/components/src/test/test_logger.js b/chat/components/src/test/test_logger.js index 4f17d1761f..3dacc3954e 100644 --- a/chat/components/src/test/test_logger.js +++ b/chat/components/src/test/test_logger.js @@ -393,18 +393,6 @@ var test_logging = async function() { } }; - let logs = await logger.getLogsForConversation(dummyConv); - let allLogMsgs = []; - for (let log of logs) { - let conv = await log.getConversation(); - if (!conv) { - continue; - } - allLogMsgs = allLogMsgs.concat(conv.getMessages()); - } - // Two session messages, one for each valid log file. - testMsgs(allLogMsgs, firstDayMsgs.concat(secondDayMsgs), 2); - // Accepts time in seconds, reduces it to a date, and returns the value in millis. let reduceTimeToDate = function(aTime) { let date = new Date(aTime * 1000); @@ -419,7 +407,7 @@ var test_logging = async function() { messagesByDay.set(reduceTimeToDate(firstDayMsgs[0].time), firstDayMsgs); messagesByDay.set(reduceTimeToDate(secondDayMsgs[0].time), secondDayMsgs); - logs = await logger.getLogsForConversation(dummyConv, true); + let logs = await logger.getLogsForConversation(dummyConv); for (let log of logs) { let conv = await log.getConversation(); let date = reduceTimeToDate(log.time); diff --git a/mail/components/im/content/chat-messenger.js b/mail/components/im/content/chat-messenger.js index 2ba84072b0..a22870d4af 100644 --- a/mail/components/im/content/chat-messenger.js +++ b/mail/components/im/content/chat-messenger.js @@ -887,7 +887,7 @@ var chatHandler = { ...path.split("/") ); imServices.logs.getLogFromFile(path, true).then(aLog => { - imServices.logs.getSimilarLogs(aLog, true).then(aSimilarLogs => { + imServices.logs.getSimilarLogs(aLog).then(aSimilarLogs => { if (contactlistbox.selectedItem != item) { return; } @@ -947,7 +947,7 @@ var chatHandler = { ChatEncryption.updateEncryptionButton(document, item.conv); - imServices.logs.getLogsForConversation(item.conv, true).then(aLogs => { + imServices.logs.getLogsForConversation(item.conv).then(aLogs => { if (contactlistbox.selectedItem != item) { return; } @@ -993,7 +993,7 @@ var chatHandler = { e.setAttribute("hidden", "true"); }); - imServices.logs.getLogsForContact(contact, true).then(aLogs => { + imServices.logs.getLogsForContact(contact).then(aLogs => { if (contactlistbox.selectedItem != item) { return; }