Add Snooze messages until a chosen time and show a follow-up reminder when they return. Bump version V0.1.17
This commit is contained in:
@@ -159,6 +159,49 @@ class EpMailPlugin : Plugin() {
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun setSnooze(call: PluginCall) {
|
||||
try {
|
||||
val account = AndroidAccountVault.account()
|
||||
?: throw IllegalStateException("Add a mail account before setting a reminder.")
|
||||
val uid = call.getLong("uid") ?: throw IllegalArgumentException("That message could not be identified.")
|
||||
require(uid > 0) { "That message could not be identified." }
|
||||
val folder = call.getString("sourceFolder") ?: call.getString("folder") ?: "Inbox"
|
||||
require(folder in setOf("Inbox", "Sent", "Archive", "Trash")) { "That mailbox cannot be snoozed." }
|
||||
val dueAt = call.getLong("dueAt")
|
||||
if (dueAt != null && dueAt <= System.currentTimeMillis()) {
|
||||
throw IllegalArgumentException("Choose a reminder time in the future.")
|
||||
}
|
||||
AndroidAccountVault.setSnooze(
|
||||
account.optString("id"),
|
||||
uid,
|
||||
folder,
|
||||
dueAt,
|
||||
call.getString("subject").orEmpty()
|
||||
)
|
||||
val update = JSONObject()
|
||||
.put("accountId", account.optString("id"))
|
||||
.put("foldersChanged", JSONArray().put("Snoozed").put(folder))
|
||||
context.sendBroadcast(Intent(MailIdleService.ACTION_MAIL_SYNC)
|
||||
.setPackage(context.packageName)
|
||||
.putExtra(MailIdleService.EXTRA_SYNC_UPDATE, update.toString()))
|
||||
MailIdleService.start(context)
|
||||
call.resolve(JSObject().put("ok", true).put("snoozed", dueAt != null))
|
||||
} catch (error: Exception) {
|
||||
call.reject(error.message ?: "Could not set the reminder.")
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun checkSnoozeReminders(call: PluginCall) {
|
||||
try {
|
||||
MailIdleService.checkSnoozeReminders(context)
|
||||
call.resolve()
|
||||
} catch (error: Exception) {
|
||||
call.reject(error.message ?: "Could not check mail reminders.")
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun saveAttachment(call: PluginCall) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user