Skip to content

Commit

Permalink
Enable opt-out of resend message warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jperryhouts committed Nov 23, 2020
1 parent d072254 commit 06af150
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 9 deletions.
28 changes: 19 additions & 9 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,25 @@ const SendLater = {

if (lock[originalMsgId]) {
const msgSubject = SLStatic.getHeader(rawContent, 'subject');
SLStatic.error(`Attempted to resend message "${msgSubject}" ${originalMsgId}.`)
const err = browser.i18n.getMessage("CorruptFolderError", [msgHdr.folder.path]) +
`\n\nSpecifically, it appears that message "${msgSubject}" ${originalMsgId} ` +
`has been sent before, but still exists in the Drafts folder. This may or may ` +
`not be indicative of a more serious problem. You might simply try deleting ` +
`(or re-scheduling) the message in question.` +
`\n\nSend Later will skip this message, but continue processing your other ` +
`scheduled draft messages when you close this alert.`;
await browser.SL3U.alert("", err);
if (preferences.optOutResendWarning === true) {
SLStatic.debug(`Encountered previously sent message "${msgSubject}" ${originalMsgId}.`);
} else {
SLStatic.error(`Attempted to resend message "${msgSubject}" ${originalMsgId}.`);
const confirmation = await browser.SL3U.confirmCheck(
browser.i18n.getMessage("ScheduledMessagesWarningTitle"),
browser.i18n.getMessage("CorruptFolderError", [msgHdr.folder.path]) +
`\n\nSpecifically, it appears that message "${msgSubject}" ${originalMsgId} ` +
`has been sent before, but still exists in the Drafts folder. This may or may ` +
`not be indicative of a more serious problem. You might simply try deleting ` +
`(or re-scheduling) the message in question.` +
`\n\nSend Later will skip this message, but continue processing your other ` +
`scheduled draft messages when you close this alert.`,
browser.i18n.getMessage("ConfirmAgain"),
true
);
preferences.optOutResendWarning = (confirmation === false);
await browser.storage.local.set({ preferences });
}
return;
}

Expand Down
15 changes: 15 additions & 0 deletions experiments/sl3u.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,21 @@ var SL3U = class extends ExtensionCommon.ExtensionAPI {
return Services.prompt.alert(window, (title || ""), (text || ""));
},

async confirmCheck(title, message, checkMessage, state) {
function doConfirmCheck(resolve, reject) {
try {
let checkbox = { value: state };
let okToProceed = Services.prompt.confirmCheck(
null, title, message, checkMessage, checkbox
);
resolve(okToProceed && checkbox.value);
} catch (err) {
reject(`An error occurred in SL3U.doConfirmCheck: ${err}`);
}
}
return new Promise(doConfirmCheck.bind(this));
},

async setLegacyPref(name, dtype, value) {
const prefName = `extensions.sendlater3.${name}`;

Expand Down
23 changes: 23 additions & 0 deletions experiments/sl3u.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,29 @@
}
]
},
{
"name":"confirmCheck",
"type":"function",
"async":true,
"parameters":[
{
"name":"title",
"type":"string"
},
{
"name":"message",
"type":"string"
},
{
"name": "checkMessage",
"type": "string"
},
{
"name": "state",
"type": "boolean"
}
]
},
{
"name": "generateMsgId",
"type": "function",
Expand Down

0 comments on commit 06af150

Please sign in to comment.