From 1a1f23007ba60ecacd44f7c926ce849e92189bf1 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Wed, 28 Aug 2024 21:56:15 +0300 Subject: [PATCH] feat: filter tasks by state change time --- src/main.rs | 8 ++++---- src/task.rs | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1da4a0a..6f81cbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -444,10 +444,10 @@ async fn main() -> Result<()> { match arg { None => { let today = Timestamp::now() - 80_000; - info!("Filtering for tasks created in the last 22 hours"); + info!("Filtering for tasks opened in the last 22 hours"); tasks.set_filter( tasks.filtered_tasks(tasks.get_position_ref()) - .filter(|t| t.event.created_at > today) + .filter(|t| t.last_state_update() > today) .map(|t| t.event.id) .collect() ); @@ -475,11 +475,11 @@ async fn main() -> Result<()> { parse_hour(arg, 1) .or_else(|| parse_date(arg).map(|utc| utc.with_timezone(&Local))) .map(|time| { - info!("Filtering for tasks created after {}", format_datetime_relative(time)); + info!("Filtering for tasks opened after {}", format_datetime_relative(time)); let threshold = time.to_utc().timestamp(); tasks.set_filter( tasks.filtered_tasks(tasks.get_position_ref()) - .filter(|t| t.event.created_at.as_u64() as i64 > threshold) + .filter(|t| t.last_state_update().as_u64() as i64 > threshold) .map(|t| t.event.id) .collect() ); diff --git a/src/task.rs b/src/task.rs index bfbfa76..25f4b61 100644 --- a/src/task.rs +++ b/src/task.rs @@ -105,8 +105,12 @@ impl Task { }) } + pub(crate) fn last_state_update(&self) -> Timestamp { + self.state().map(|s| s.time).unwrap_or(self.event.created_at) + } + pub(crate) fn state(&self) -> Option { - self.states().max_by_key(|t| t.time) + self.states().last() } pub(crate) fn pure_state(&self) -> State {