Mailspring/app/internal_packages/thread-snooze/lib/snooze-utils.es6

88 lines
2.6 KiB
Plaintext
Raw Normal View History

import moment from 'moment';
import {
Actions,
Label,
DateUtils,
TaskFactory,
CategoryStore,
ChangeLabelsTask,
ChangeFolderTask,
DraftFactory,
SendDraftTask,
} from 'mailspring-exports';
export function snoozedUntilMessage(snoozeDate, now = moment()) {
2017-09-27 02:33:08 +08:00
let message = 'Snoozed';
if (snoozeDate) {
2017-09-27 02:33:08 +08:00
let dateFormat = DateUtils.DATE_FORMAT_SHORT;
const date = moment(snoozeDate);
const hourDifference = moment.duration(date.diff(now)).asHours();
if (hourDifference < 24) {
dateFormat = dateFormat.replace('MMM D, ', '');
}
if (date.minutes() === 0) {
dateFormat = dateFormat.replace(':mm', '');
}
message += ` until ${DateUtils.format(date, dateFormat)}`;
}
return message;
}
2017-09-27 02:33:08 +08:00
export function moveThreads(threads, { snooze, description } = {}) {
const tasks = TaskFactory.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => {
const snoozeCat = CategoryStore.getCategoryByRole(accountId, 'snoozed');
const inboxCat = CategoryStore.getInboxCategory(accountId);
if (snoozeCat instanceof Label) {
return new ChangeLabelsTask({
2017-09-27 02:33:08 +08:00
source: 'Snooze Move',
threads: accountThreads,
taskDescription: description,
labelsToAdd: snooze ? [snoozeCat] : [inboxCat],
labelsToRemove: snooze ? [inboxCat] : [snoozeCat],
canBeUndone: snooze ? true : false,
});
}
return new ChangeFolderTask({
2017-09-27 02:33:08 +08:00
source: 'Snooze Move',
threads: accountThreads,
taskDescription: description,
folder: snooze ? snoozeCat : inboxCat,
canBeUndone: snooze ? true : false,
});
});
Actions.queueTasks(tasks);
}
export async function markUnreadOrResurfaceThreads(threads, source) {
if (AppEnv.config.get('core.notifications.unsnoozeToTop')) {
// send a hidden email that will mark the thread as unread and bring it
// to the top of your inbox in any mail client
const body = `
<strong>Mailspring Reminder:</strong> This thread has been moved to the top of
your inbox by Mailspring.</p>
<p>--The Mailspring Team</p>`;
for (const thread of threads) {
const draft = await DraftFactory.createDraftForResurfacing(thread, null, body);
Totally overhauled composer based on Slate (#524) * Remove the composer contenteditable, replace with basic <textarea> * Beginning broader cleanup of draft session * DraftJS composer with color, style support * Serialization/unserialization of basic styles, toolbar working * WIP * Switch to draft-js-plugins approach, need to revisit HTML * Move HTML conversion functionality into plugins * Add spellcheck context menu to editor * Initial work on quoted text * Further work on quoted text * BLOCK approach * Entity approach - better, does not bump out to top level * Hiding and showing quoted text via CSS * Get rid of ability to inject another subject line component * Clean up specs, DraftFactory to ES6 * Remove old initial focus hack * Fix focusing, initial text selection * Remove participant “collapsing” support, it can be confusing * Correctly terminate links on carriage returns * Initial signature support, allow removal of uneditable blocks * Sync body string with body editorstate * Simplify draft editor session, finish signatures * Templates * Minor fixes * Simplify link/open tracking, ensure it works * Reorg composer, rework template editor * Omg the slowness is all the stupid emoji button * Polish and small fixes * Performance improvements, new templates UI * Don’t assume nodes are elements * Fix for sending drafts twice due to back-to-back saves * Fix order of operations on app quit to save drafts reliably * Improve DraftJS-Convert whitespace handling * Use contentID throughout attachment lifecycle * Try to fix images * Switch to Slate instead of DraftJS… much better * Fix newline handling * Bug fixes * Cleanup * Finish templates plugin * Clean up text editing / support for Gmail email styles * Support for color + size on the same node, clean trailing whitespace * Restore emoji typeahead / emoji picker * Fix scrolling in template editor * Fix specs * Fix newlines * Re-implement spellcheck to be faster * Make spellcheck decorator changes invisible to the undo/redo stack * Remove comment * Polish themplates panel * Fix #521
2018-01-12 07:55:56 +08:00
Actions.queueTask(SendDraftTask.forSending(draft, { silent: true }));
}
} else {
// just mark the threads as unread (unless they're all already unread)
if (!threads.some(t => !t.unread)) {
return;
}
Actions.queueTask(
TaskFactory.taskForSettingUnread({
unread: true,
threads: threads,
source: source,
canBeUndone: false,
})
);
}
}