Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable trashing messages displayed in own tab #1

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 33 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,41 @@

const commandGtrash = 'gtrash';
const folderTypeTrash = 'trash';
const tabTypeMessage = 'messageDisplay';

messenger.commands.onCommand.addListener(async function(command) {
if (command === commandGtrash) {
try {
let messageList = await messenger.mailTabs.getSelectedMessages(),
let messageList,
tab,
moves = {};
try {
messageList = await messenger.mailTabs.getSelectedMessages();
}
catch (error) {
let tabs = await messenger.tabs.query({
active: true,
currentWindow: true
}),
displayed;
if (
tabs?.length
&& (tab = tabs[0])
&& tab.id !== TAB_ID_NONE
&& tab.type === tabTypeMessage
&& (displayed = await messenger.messageDisplay.getDisplayedMessage(tab.id))
Roy-Orbison marked this conversation as resolved.
Show resolved Hide resolved
) {
// synthesise for iteration
messageList = {
messages: [
displayed
]
};
}
else {
throw error;
}
}
do {
if (messageList?.messages?.length) {
for (let messageHeader of messageList.messages) {
Expand Down Expand Up @@ -53,6 +82,9 @@ messenger.commands.onCommand.addListener(async function(command) {
if (moves[accountId].trash || moves[accountId].ids.length) {
await messenger.messages.move(moves[accountId].ids, moves[accountId].trash);
moves[accountId].ids = [];
if (tab) {
messenger.tabs.remove(tab.id);
}
}
}
}
Expand Down