forked from Foundry376/Mailspring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-implement unsnooze action client-side, clean up lots of plugin code
- Loading branch information
Showing
12 changed files
with
137 additions
and
257 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
app/internal_packages/send-reminders/lib/send-reminders-headers.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,54 @@ | ||
import moment from 'moment'; | ||
import { | ||
Actions, | ||
Thread, | ||
Label, | ||
DateUtils, | ||
TaskFactory, | ||
CategoryStore, | ||
DatabaseStore, | ||
ChangeLabelsTask, | ||
ChangeFolderTask, | ||
TaskQueue, | ||
} from 'nylas-exports'; | ||
|
||
const {DATE_FORMAT_SHORT} = DateUtils | ||
export function snoozedUntilMessage(snoozeDate, now = moment()) { | ||
let message = 'Snoozed' | ||
if (snoozeDate) { | ||
let dateFormat = DateUtils.DATE_FORMAT_SHORT | ||
const date = moment(snoozeDate) | ||
const hourDifference = moment.duration(date.diff(now)).asHours() | ||
|
||
const SnoozeUtils = { | ||
snoozedUntilMessage(snoozeDate, now = moment()) { | ||
let message = 'Snoozed' | ||
if (snoozeDate) { | ||
let dateFormat = 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)}`; | ||
if (hourDifference < 24) { | ||
dateFormat = dateFormat.replace('MMM D, ', ''); | ||
} | ||
if (date.minutes() === 0) { | ||
dateFormat = dateFormat.replace(':mm', ''); | ||
} | ||
return message; | ||
}, | ||
|
||
moveThreads(threads, {snooze, description} = {}) { | ||
const tasks = TaskFactory.tasksForThreadsByAccountId(threads, (accountThreads, accountId) => { | ||
const snoozeCat = CategoryStore.getCategoryByRole(accountId, 'snoozed'); | ||
const inboxCat = CategoryStore.getInboxCategory(accountId); | ||
message += ` until ${DateUtils.format(date, dateFormat)}`; | ||
} | ||
return message; | ||
} | ||
|
||
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({ | ||
source: "Snooze Move", | ||
threads: accountThreads, | ||
taskDescription: description, | ||
labelsToAdd: snooze ? [snoozeCat] : [inboxCat], | ||
labelsToRemove: snooze ? [inboxCat] : [snoozeCat], | ||
}); | ||
} | ||
return new ChangeFolderTask({ | ||
if (snoozeCat instanceof Label) { | ||
return new ChangeLabelsTask({ | ||
source: "Snooze Move", | ||
threads: accountThreads, | ||
taskDescription: description, | ||
folder: snooze ? snoozeCat : inboxCat, | ||
labelsToAdd: snooze ? [snoozeCat] : [inboxCat], | ||
labelsToRemove: snooze ? [inboxCat] : [snoozeCat], | ||
}); | ||
} | ||
return new ChangeFolderTask({ | ||
source: "Snooze Move", | ||
threads: accountThreads, | ||
taskDescription: description, | ||
folder: snooze ? snoozeCat : inboxCat, | ||
}); | ||
}); | ||
|
||
Actions.queueTasks(tasks); | ||
const promises = tasks.map(task => TaskQueue.waitForPerformRemote(task)) | ||
|
||
// Resolve with the updated threads | ||
return ( | ||
Promise.all(promises).then(() => { | ||
return DatabaseStore.modelify(Thread, threads.map(t => t.id)) | ||
}) | ||
) | ||
}, | ||
|
||
moveThreadsToSnooze(threads, snoozeDate) { | ||
return SnoozeUtils.moveThreads(threads, { | ||
snooze: true, | ||
description: SnoozeUtils.snoozedUntilMessage(snoozeDate), | ||
}) | ||
}, | ||
|
||
moveThreadsFromSnooze(threads) { | ||
return SnoozeUtils.moveThreads(threads, { | ||
snooze: false, | ||
description: 'Unsnoozed', | ||
}) | ||
}, | ||
Actions.queueTasks(tasks); | ||
} | ||
|
||
export default SnoozeUtils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.