diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /comm/mail/base/content/selectionsummaries.js | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | comm/mail/base/content/selectionsummaries.js | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/comm/mail/base/content/selectionsummaries.js b/comm/mail/base/content/selectionsummaries.js new file mode 100644 index 0000000000..75461e3a54 --- /dev/null +++ b/comm/mail/base/content/selectionsummaries.js @@ -0,0 +1,103 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* globals gSummaryFrameManager */ // From messenger.js + +/** + * Summarize a set of selected messages. This can either be a single thread or + * multiple threads. + * + * @param aMessageDisplay The MessageDisplayWidget object responsible for + * showing messages. + */ +function summarizeSelection(aMessageDisplay) { + // Figure out if we're looking at one thread or more than one thread. We want + // the view's version of threading, not the database's version, in order to + // thread together cross-folder messages. XXX: This falls apart for group by + // sort; what we really want is a way to specify only the cross-folder view. + let folderDisplay = aMessageDisplay.folderDisplay; + let selectedIndices = folderDisplay.selectedIndices; + let dbView = folderDisplay.view.dbView; + + let getThreadId = function (index) { + return dbView.getThreadContainingIndex(index).getRootHdr().messageKey; + }; + + let firstThreadId = getThreadId(selectedIndices[0]); + let oneThread = true; + for (let i = 1; i < selectedIndices.length; i++) { + if (getThreadId(selectedIndices[i]) != firstThreadId) { + oneThread = false; + break; + } + } + + let selectedMessages = folderDisplay.selectedMessages; + if (oneThread) { + summarizeThread(selectedMessages, aMessageDisplay); + } else { + summarizeMultipleSelection(selectedMessages, aMessageDisplay); + } +} + +/** + * Given an array of messages which are all in the same thread, summarize them. + * + * @param aSelectedMessages Array of message headers. + * @param aMessageDisplay The MessageDisplayWidget object responsible for + * showing messages. + */ +function summarizeThread(aSelectedMessages, aMessageDisplay) { + const kSummaryURL = "chrome://messenger/content/multimessageview.xhtml"; + + aMessageDisplay.singleMessageDisplay = false; + gSummaryFrameManager.loadAndCallback(kSummaryURL, function () { + let childWindow = gSummaryFrameManager.iframe.contentWindow; + try { + childWindow.gMessageSummary.summarize( + "thread", + aSelectedMessages, + aMessageDisplay.folderDisplay.view.dbView, + aMessageDisplay.folderDisplay.selectMessages.bind( + aMessageDisplay.folderDisplay + ), + aMessageDisplay + ); + } catch (e) { + console.error(e); + throw e; + } + }); +} + +/** + * Given an array of message URIs, cause the message panel to display a summary + * of them. + * + * @param aSelectedMessages Array of message headers. + * @param aMessageDisplay The MessageDisplayWidget object responsible for + * showing messages. + */ +function summarizeMultipleSelection(aSelectedMessages, aMessageDisplay) { + const kSummaryURL = "chrome://messenger/content/multimessageview.xhtml"; + + aMessageDisplay.singleMessageDisplay = false; + gSummaryFrameManager.loadAndCallback(kSummaryURL, function () { + let childWindow = gSummaryFrameManager.iframe.contentWindow; + try { + childWindow.gMessageSummary.summarize( + "multipleselection", + aSelectedMessages, + aMessageDisplay.folderDisplay.view.dbView, + aMessageDisplay.folderDisplay.selectMessages.bind( + aMessageDisplay.folderDisplay + ), + aMessageDisplay + ); + } catch (e) { + console.error(e); + throw e; + } + }); +} |