forked from janek/mostr
1
0
Fork 0

feat: filter tasks by state change time

This commit is contained in:
xeruf 2024-08-28 21:56:15 +03:00
parent 9eaf10006b
commit 1a1f23007b
2 changed files with 9 additions and 5 deletions

View File

@ -444,10 +444,10 @@ async fn main() -> Result<()> {
match arg { match arg {
None => { None => {
let today = Timestamp::now() - 80_000; 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.set_filter(
tasks.filtered_tasks(tasks.get_position_ref()) 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) .map(|t| t.event.id)
.collect() .collect()
); );
@ -475,11 +475,11 @@ async fn main() -> Result<()> {
parse_hour(arg, 1) parse_hour(arg, 1)
.or_else(|| parse_date(arg).map(|utc| utc.with_timezone(&Local))) .or_else(|| parse_date(arg).map(|utc| utc.with_timezone(&Local)))
.map(|time| { .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(); let threshold = time.to_utc().timestamp();
tasks.set_filter( tasks.set_filter(
tasks.filtered_tasks(tasks.get_position_ref()) 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) .map(|t| t.event.id)
.collect() .collect()
); );

View File

@ -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<TaskState> { pub(crate) fn state(&self) -> Option<TaskState> {
self.states().max_by_key(|t| t.time) self.states().last()
} }
pub(crate) fn pure_state(&self) -> State { pub(crate) fn pure_state(&self) -> State {