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

feat: Added a notification for each operation #212

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,24 @@
},
"partialMatchFullPath": {
"message": "Search for keywords within the entire folder path"
},
"operation_action_move": {
"message": "Moved"
},
"operation_action_copy": {
"message": "Copied"
},
"operation_action_tag": {
"message": "Tagged"
},
"operation_message_pluralforms": {
"message": "message;messages",
"description": "List all plural forms for the word 'message', separated by ';', following your language's plural rules. The order must match the language's pluralization pattern: singular first, then all plural variations. Example: 'apple;apples' (English), 'pomme;pommes' (French), 'jabłko;jabłka;jabłek' (Polish), 'تفاح;تفاحة;تفاحتان;تفاحات;تفاحة;تفاح' (Arabic)."
},
"notificationActive": {
"message": "Show a notification for each operation"
},
"Folder": {
"message": "Folder"
}
}
24 changes: 21 additions & 3 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* Portions Copyright (C) Philipp Kewisch */

import { createNotificationText } from "../common/util.js";
import { DEFAULT_PREFERENCES } from "./common/util.js";

const DEFAULT_ACTION_URL = "/popup/popup.html?action=move&allowed=move,copy,goto,tag";

// Manifest v3: this needs to go into state memory or be queried for
Expand Down Expand Up @@ -42,7 +45,7 @@ async function spinWith(func, ...args) {
}

async function processSelectedMessages(folder, operation="move", goToFolder=false) {
let { markAsRead } = await browser.storage.local.get({ markAsRead: true });
let { markAsRead, notificationActive, operationCounters } = await browser.storage.local.get({ markAsRead: true, notificationActive: DEFAULT_PREFERENCES.notificationActive, operationCounters: DEFAULT_PREFERENCES.operationCounters });

let ops = [];

Expand All @@ -53,6 +56,7 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals

let folderId = folder.id;
let messagePages;
let numMessages = 0;
if (tab.type == "messageDisplay") {
messagePages = [browser.messageDisplay.getDisplayedMessages(tab.id)];
} else if (tab.type == "mail") {
Expand All @@ -67,6 +71,8 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals

for await (let messages of messagePages) {
let ids = messages.map(message => message.id);
numMessages += messages.length;
operationCounters[operation] += messages.length;
let op = Promise.resolve();
if (markAsRead) {
op = op.then(() => Promise.all(ids.map(id => browser.messages.update(id, { read: true }))));
Expand All @@ -81,6 +87,7 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals
ops.push(op);
}

await browser.storage.local.set({ operationCounters });
await Promise.all(ops);

if (majorVersion < 137) {
Expand All @@ -91,14 +98,20 @@ async function processSelectedMessages(folder, operation="move", goToFolder=fals
if (goToFolder) {
await browser.mailTabs.update(tab.id, { displayedFolder: folderId }).catch(() => {});
}

if (operation != "goto" && notificationActive) {
createNotificationText(operation, numMessages, folderId);
}
}
async function applyTags(tag) {
let { markAsRead } = await browser.storage.local.get({ markAsRead: true });

let { markAsRead, notificationActive, operationCounters } = await browser.storage.local.get({ markAsRead: true, notificationActive: DEFAULT_PREFERENCES.notificationActive, operationCounters: DEFAULT_PREFERENCES.operationCounters });
let ops = [];
let numMessages = 0;

for await (let messages of selectedMessagePages()) {
let ids = messages.map(message => message.id);
numMessages += messages.length;
operationCounters.tag += messages.length;
ops.push(Promise.all(ids.map(async (id) => {
let msg = await browser.messages.get(id);
let tagset = new Set(msg.tags);
Expand All @@ -114,10 +127,15 @@ async function applyTags(tag) {
if (markAsRead) {
data.read = true;
}
if (notificationActive) {
createNotificationText("tag", numMessages, tag);
}

return browser.messages.update(id, data);
})));
}

await browser.storage.local.set({ operationCounters });
await Promise.all(ops);
}

Expand Down
Loading