diff --git a/src/main.rs b/src/main.rs
index e7a429d..22cbfc4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,7 +17,7 @@ async fn run() -> anyhow::Result<()> {
scheduler::reschedule_recurring_tasks(&ctx, &tasks).await?;
- reminder::remind_due_tasks(&ctx, &tasks).await?;
+ reminder::remind_all_tasks(&ctx, &tasks).await?;
Ok(())
}
diff --git a/src/reminder.rs b/src/reminder.rs
index 6c28026..aba0f3c 100644
--- a/src/reminder.rs
+++ b/src/reminder.rs
@@ -10,7 +10,14 @@ enum BatchingInterval {
OnTheDay,
}
-pub async fn remind_due_tasks(ctx: &crate::Context, tasks: &[task::Task]) -> anyhow::Result<()> {
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+enum ReminderType {
+ Basic,
+ Urgent,
+}
+
+pub async fn remind_all_tasks(ctx: &crate::Context, tasks: &[task::Task]) -> anyhow::Result<()> {
+ let mut reminded = 0;
for task in tasks {
let Some(due_date) = task.state.due_date_if_open() else {
continue;
@@ -25,12 +32,139 @@ pub async fn remind_due_tasks(ctx: &crate::Context, tasks: &[task::Task]) -> any
}
if is_overdue(ctx, due_date) {
- log::info!("Task {task} is already overdue!");
+ log::debug!("Task {task} is already overdue!");
}
- log::warn!("TODO: Remind {task}");
+ if let Some((reminded_date, reminder_type)) = check_task_reminded(ctx, task).await? {
+ if reminder_type == ReminderType::Urgent {
+ log::debug!("Was already reminded urgently, skipping.");
+ } else if &reminded_date < due_date && is_overdue(ctx, due_date) {
+ log::info!("Task {task} is now overdue, reminding again urgently...");
+ remind_task(ctx, task, ReminderType::Urgent, batching_interval).await?;
+ } else {
+ log::debug!("Was already reminded, skipping.");
+ }
+ continue;
+ }
+
+ log::info!("Reminding {task} ...");
+ remind_task(ctx, task, ReminderType::Basic, batching_interval).await?;
+ reminded += 1;
}
+ if reminded == 0 {
+ log::info!("No tasks needed to be reminded.");
+ } else {
+ log::debug!("Reminded {reminded} tasks.");
+ }
+
+ Ok(())
+}
+
+const SIGNATURE_BASIC: &'static str = "\\[TaskBot Comment\\]";
+const SIGNATURE_URGENT: &'static str = "\\[TaskBot Comment (Urgent)\\]";
+
+async fn check_task_reminded(
+ ctx: &crate::Context,
+ task: &task::Task,
+) -> anyhow::Result