Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
Delete message action #161
Browse files Browse the repository at this point in the history
  • Loading branch information
mkiol committed Apr 15, 2017
1 parent 13b3b59 commit 21bbab2
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 55 deletions.
143 changes: 88 additions & 55 deletions source/lib/thunderbird.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ function showNewEmailNotification(message) {
showNotification(title, text, message);
}

function deleteMessage(message) {
try {
const win = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator).getMostRecentWindow("mail:3pane").msgWindow;
let messages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
message.markRead(true);
message.folder.msgDatabase = null;
messages.appendElement(message, false);
message.folder.deleteMessages(messages, win, false, false, null, true);
message.folder.msgDatabase = null;
} catch (e) {
console.error("Unable to delete messages. Exception: " + e);
return false;
}
return true;
}

function showNotification(title, text, message){
const notifications = require("sdk/notifications");

Expand All @@ -112,76 +129,92 @@ function showNotification(title, text, message){
return;
}

// Doing notification with buttons if Linux and buttons are supported in
// the notify server
if (sps.engine === 1 && system.platform === "linux") {
const notifApi = require("./linux.js");

let id = null;
let actions = null;
if (message) {
if (sps.clickOptionNewEmail === 0) {
actions = [{
label: _("open"),
handler: ()=>{
display(message);
notifApi.close(id);
}
}, {
label: _("Mark_as_read"),
handler: ()=>{
message.markRead(true);
notifApi.close(id);
}
}];
} else {
actions = [{
label: _("Mark_as_read"),
handler: ()=>{
message.markRead(true);
notifApi.close(id);
}
}, {
label: _("open"),
handler: ()=>{
display(message);
notifApi.close(id);
}
}];
if (message) {
let id = 0; // Notification ID from libnotify (Linux only).
let notifApi = null; // Notification API for libnotify (Linux only).
let actions = [];

let openAction = {
label: _("open"),
handler: ()=>{
display(message);
if (notifApi)
notifApi.close(id);
}
};
let markReadAction = {
label: _("Mark_as_read"),
handler: ()=>{
message.markRead(true);
message.folder.msgDatabase = null;
if (notifApi)
notifApi.close(id);
}
};
let deleteAction = {
label: _("Delete"),
handler: ()=>{
deleteMessage(message);
if (notifApi)
notifApi.close(id);
}
};

switch(sps.clickOptionNewEmail) {
case 0:
actions.push(openAction);
actions.push(markReadAction);
actions.push(deleteAction);
break;
case 1:
actions.push(markReadAction);
actions.push(openAction);
actions.push(deleteAction);
break;
case 2:
actions.push(deleteAction);
actions.push(openAction);
actions.push(markReadAction);
break;
}

// Do notification with buttons if Linux and
// buttons are supported in the notify server
if (sps.engine === 1 && system.platform === "linux") {
notifApi = require("./linux.js");
if (notifApi.checkButtonsSupported()) {
/* eslint-disable no-unused-vars */
/* eslint-disable no-unused-vars */
id = notifApi.notifyWithActions(utils.getIcon(), title, text,
system.name, reason=>{}, actions);
/* eslint-enable no-unused-vars */
/* eslint-enable no-unused-vars */
console.log("notifyWithActions, id: " + id);
if (message && id)
message.setStringProperty("gnotifier-notification-id", id);
return;
} else {
/* eslint-disable no-unused-vars */
id = notifApi.notify(utils.getIcon(), title, text, system.name,
reason=>{}, data=>{
// Call first top action (default action) on click
actions[0].handler();
});
/* eslint-enable no-unused-vars */
console.log("notify, id: " + id);
if (message && id)
message.setStringProperty("gnotifier-notification-id", id);
return;
}

/* eslint-disable no-unused-vars */
id = notifApi.notify(utils.getIcon(), title, text, system.name,
reason=>{}, data=>{
display(message);
notifApi.close(id);
});
/* eslint-enable no-unused-vars */
console.log("notify, id: " + id);
if (message && id)
message.setStringProperty("gnotifier-notification-id", id);
return;
}
}

if (message) {
notifications.notify({
title: title,
text: text,
iconURL: utils.getIcon(),
/* eslint-disable no-unused-vars */
onClick: data=>{display(message);}
onClick: data=>{
// Call first top action (default action) on click
actions[0].handler();
}
/* eslint-enable no-unused-vars */
});
return;
Expand All @@ -197,15 +230,15 @@ function showNotification(title, text, message){
function showClickableNotification(title, text, clickHandler) {
if (sps.engine === 1 && system.platform === "linux") {
const notifApi = require("./linux.js");
/* eslint-disable no-unused-vars */
/* eslint-disable no-unused-vars */
let id = notifApi.notify(utils.getIcon(), title, text, system.name,
reason=>{}, data=>{
if (clickHandler) {
clickHandler();
notifApi.close(id);
}
});
/* eslint-enable no-unused-vars */
/* eslint-enable no-unused-vars */
} else {
const notifications = require("sdk/notifications");
if (clickHandler) {
Expand Down
1 change: 1 addition & 0 deletions source/locale/de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=Datei
Folder=Ordner
Empty_subject=[Empty subject]
Empty_body=[Empty body]
Delete=Delete
1 change: 1 addition & 0 deletions source/locale/en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=File
Folder=Folder
Empty_subject=[Empty subject]
Empty_body=[Empty body]
Delete=Delete
1 change: 1 addition & 0 deletions source/locale/es-ES.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=Archivo
Folder=Carpeta
Empty_subject=[Empty subject]
Empty_body=[Empty body]
Delete=Delete
1 change: 1 addition & 0 deletions source/locale/fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=Fichier
Folder=Dossier
Empty_subject=[Empty subject]
Empty_body=[Empty body]
Delete=Delete
1 change: 1 addition & 0 deletions source/locale/it-IT.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=File
Folder=Cartella
Empty_subject=[Empty subject]
Empty_body=[Empty body]
Delete=Delete
1 change: 1 addition & 0 deletions source/locale/nl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=File
Folder=Folder
Empty_subject=[Empty subject]
Empty_body=[Empty body]
Delete=Delete
1 change: 1 addition & 0 deletions source/locale/pl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=Plik
Folder=Folder
Empty_subject=[Brak tematu]
Empty_body=[Brak treści]
Delete=Usuń
1 change: 1 addition & 0 deletions source/locale/ru-RU.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ File=Файл
Folder=Папка
Empty_subject=[Empty subject]
Empty_body=[Empty body]
Delete=Delete
4 changes: 4 additions & 0 deletions source/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
{
"value": "1",
"label": "Mark as read"
},
{
"value": "2",
"label": "Delete"
}
]
},
Expand Down

0 comments on commit 21bbab2

Please sign in to comment.