feat: can_stale and periodicity
This commit is contained in:
parent
3ffdf8f0d7
commit
b361c1ab58
4 changed files with 108 additions and 17 deletions
|
|
@ -134,7 +134,11 @@ pub mod get {
|
|||
let mut freshens: Vec<ContactFreshness> = contacts
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|contact| {
|
||||
.filter_map(|contact| {
|
||||
if !contact.can_stale || !contact.active {
|
||||
return None;
|
||||
}
|
||||
|
||||
let zero = jiff::civil::Date::ZERO;
|
||||
let fresh_date = std::cmp::max(
|
||||
contact
|
||||
|
|
@ -144,17 +148,17 @@ pub mod get {
|
|||
contact.last_mention_date.unwrap_or(zero),
|
||||
);
|
||||
if fresh_date == zero {
|
||||
ContactFreshness {
|
||||
Some(ContactFreshness {
|
||||
contact_id: contact.id,
|
||||
display: contact.display_name(),
|
||||
fresh_date,
|
||||
fresh_str: "never".to_string(),
|
||||
elapsed_str: "".to_string(),
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let utc = TimeZone::UTC;
|
||||
let todate = Timestamp::now().to_zoned(utc.clone()).date();
|
||||
let duration = todate
|
||||
let elapsed = todate
|
||||
.since(&fresh_date.to_zoned(utc).unwrap())
|
||||
.unwrap()
|
||||
.round(
|
||||
|
|
@ -165,19 +169,25 @@ pub mod get {
|
|||
)
|
||||
.unwrap();
|
||||
|
||||
let elapsed_str = if duration.is_zero() {
|
||||
if let Some(cmp) = elapsed.compare((contact.periodicity, todate)).ok() {
|
||||
if cmp == std::cmp::Ordering::Less {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
let elapsed_str = if elapsed.is_zero() {
|
||||
"today".to_string()
|
||||
} else {
|
||||
format!("{:#}", duration)
|
||||
format!("{:#}", elapsed)
|
||||
};
|
||||
|
||||
ContactFreshness {
|
||||
Some(ContactFreshness {
|
||||
contact_id: contact.id,
|
||||
display: contact.display_name(),
|
||||
fresh_date,
|
||||
fresh_str: fresh_date.to_string(),
|
||||
elapsed_str,
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue