From f90378a9114c14b70953ff5f964c3328fe85d840 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 8 Mar 2025 21:15:35 +0200 Subject: [PATCH] record all opened/closed history, change sort order to DESC --- src/profile/history/item.rs | 12 ++++++------ src/profile/history/memory.rs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/profile/history/item.rs b/src/profile/history/item.rs index f0d0d09a..8a954dcd 100644 --- a/src/profile/history/item.rs +++ b/src/profile/history/item.rs @@ -5,8 +5,8 @@ pub struct Item { pub id: i64, pub request: GString, pub created: DateTime, - pub opened: DateTime, - pub closed: Option, + pub opened: Vec, + pub closed: Vec, } impl Item { @@ -17,19 +17,19 @@ impl Item { id, request, created: now(), - opened: now(), - closed: None, + opened: vec![now()], + closed: vec![], } } // Actions pub fn open(&mut self) { - self.opened = now() + self.opened.push(now()) } pub fn close(&mut self) { - self.closed = Some(now()) + self.closed.push(now()) } } diff --git a/src/profile/history/memory.rs b/src/profile/history/memory.rs index 590282af..44b5b4f0 100644 --- a/src/profile/history/memory.rs +++ b/src/profile/history/memory.rs @@ -42,14 +42,14 @@ impl Memory { // Getters - /// Get recent Items vector sorted by `closed` ASC + /// Get recent Items vector sorted by `closed` DESC pub fn recently_closed(&self, limit: Option) -> Vec { let mut recent: Vec = Vec::new(); for (i, item) in self .0 .iter() - .filter(|x| x.closed.is_some()) - .sorted_by(|a, b| Ord::cmp(&a.closed, &b.closed)) + .filter(|x| !x.closed.is_empty()) + .sorted_by(|a, b| Ord::cmp(&b.closed.last(), &a.closed.last())) .enumerate() { if limit.is_some_and(|l| i > l) { @@ -60,13 +60,13 @@ impl Memory { recent } - /// Get recent Items vector sorted by `opened` ASC + /// Get recent Items vector sorted by `opened` DESC pub fn recently_opened(&self, limit: Option) -> Vec { let mut recent: Vec = Vec::new(); for (i, item) in self .0 .iter() - .sorted_by(|a, b| Ord::cmp(&a.opened, &b.opened)) + .sorted_by(|a, b| Ord::cmp(&b.opened.last(), &a.opened.last())) .enumerate() { if limit.is_some_and(|l| i > l) {