2016-02-26 02:37:03 +08:00
|
|
|
import moment from 'moment';
|
2016-02-19 02:00:11 +08:00
|
|
|
import {
|
|
|
|
Actions,
|
2017-06-28 02:31:22 +08:00
|
|
|
Label,
|
fix(sync-status): Change old per model status, in favor of per folder
Summary:
Addresses T7275
Previously, we kept track of the sync status of each API model, and the progress
we'd made syncing all available models (e.g. all threads, messages, events, etc)
Given K2's set up, we are now keeping track of sync status per folder, i.e. what
percent of the folder's messages we've synced. This status is now reported from K2
to N1 via folder object deltas, and this commit rewrites the
NylasSyncStatusStore (in ES6) to reflect that.
The new Store keeps the sync state per account, which is the merged state of
per folder sync state, and delta connections state.
We also got rid of `CategoryStore.whenCategoriesReady` in favor of
`whenCategoryListSynced`, which is derived from the fact hat as long as we've
started syncing one folder, we've already synced the entire list of of folders/labels.
There are a couple of TODOs to be addressed in upcoming diffs:
- T7329 Restore the sidebar component to show sync progress, which was previously removed
- T7330 Figure out how to report sync progress per label, specifically, we are interested in knowing how much of the inbox we've synced, which is a label in Gmail. (This might be a non-issue if we sync the inbox very fast, first)
Depends on D3514
Test Plan: Manual
Reviewers: mark, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D3515
2016-12-16 03:07:11 +08:00
|
|
|
DateUtils,
|
|
|
|
TaskFactory,
|
2016-02-19 02:00:11 +08:00
|
|
|
CategoryStore,
|
2017-06-28 02:31:22 +08:00
|
|
|
ChangeLabelsTask,
|
|
|
|
ChangeFolderTask,
|
2017-10-31 08:02:05 +08:00
|
|
|
DraftFactory,
|
|
|
|
SendDraftTask,
|
2017-09-27 02:42:18 +08:00
|
|
|
} from 'mailspring-exports';
|
2016-03-07 08:55:28 +08:00
|
|
|
|
2017-09-14 16:10:46 +08:00
|
|
|
export function snoozedUntilMessage(snoozeDate, now = moment()) {
|
2017-09-27 02:33:08 +08:00
|
|
|
let message = 'Snoozed';
|
2017-09-14 16:10:46 +08:00
|
|
|
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();
|
2016-02-19 02:00:11 +08:00
|
|
|
|
2017-09-14 16:10:46 +08:00
|
|
|
if (hourDifference < 24) {
|
|
|
|
dateFormat = dateFormat.replace('MMM D, ', '');
|
|
|
|
}
|
|
|
|
if (date.minutes() === 0) {
|
|
|
|
dateFormat = dateFormat.replace(':mm', '');
|
2016-03-04 04:37:20 +08:00
|
|
|
}
|
2016-02-19 02:00:11 +08:00
|
|
|
|
2017-09-14 16:10:46 +08:00
|
|
|
message += ` until ${DateUtils.format(date, dateFormat)}`;
|
|
|
|
}
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2017-09-27 02:33:08 +08:00
|
|
|
export function moveThreads(threads, { snooze, description } = {}) {
|
2017-09-14 16:10:46 +08:00
|
|
|
const tasks = TaskFactory.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => {
|
|
|
|
const snoozeCat = CategoryStore.getCategoryByRole(accountId, 'snoozed');
|
|
|
|
const inboxCat = CategoryStore.getInboxCategory(accountId);
|
2017-08-23 12:49:45 +08:00
|
|
|
|
2017-09-14 16:10:46 +08:00
|
|
|
if (snoozeCat instanceof Label) {
|
|
|
|
return new ChangeLabelsTask({
|
2017-09-27 02:33:08 +08:00
|
|
|
source: 'Snooze Move',
|
2017-06-28 02:31:22 +08:00
|
|
|
threads: accountThreads,
|
|
|
|
taskDescription: description,
|
2017-09-14 16:10:46 +08:00
|
|
|
labelsToAdd: snooze ? [snoozeCat] : [inboxCat],
|
|
|
|
labelsToRemove: snooze ? [inboxCat] : [snoozeCat],
|
2017-10-31 08:02:05 +08:00
|
|
|
canBeUndone: snooze ? true : false,
|
2017-06-28 02:31:22 +08:00
|
|
|
});
|
2017-09-14 16:10:46 +08:00
|
|
|
}
|
|
|
|
return new ChangeFolderTask({
|
2017-09-27 02:33:08 +08:00
|
|
|
source: 'Snooze Move',
|
2017-09-14 16:10:46 +08:00
|
|
|
threads: accountThreads,
|
|
|
|
taskDescription: description,
|
|
|
|
folder: snooze ? snoozeCat : inboxCat,
|
2017-10-31 08:02:05 +08:00
|
|
|
canBeUndone: snooze ? true : false,
|
2017-06-28 02:31:22 +08:00
|
|
|
});
|
2017-09-14 16:10:46 +08:00
|
|
|
});
|
2016-02-19 02:00:11 +08:00
|
|
|
|
2017-09-14 16:10:46 +08:00
|
|
|
Actions.queueTasks(tasks);
|
2016-02-19 02:00:11 +08:00
|
|
|
}
|
2017-10-30 08:35:16 +08:00
|
|
|
|
2017-10-31 08:02:05 +08:00
|
|
|
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 }));
|
2017-10-31 08:02:05 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// just mark the threads as unread (unless they're all already unread)
|
|
|
|
if (!threads.some(t => !t.unread)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-30 08:35:16 +08:00
|
|
|
Actions.queueTask(
|
|
|
|
TaskFactory.taskForSettingUnread({
|
|
|
|
unread: true,
|
|
|
|
threads: threads,
|
|
|
|
source: source,
|
2017-10-31 08:02:05 +08:00
|
|
|
canBeUndone: false,
|
2017-10-30 08:35:16 +08:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|