forge
Explore
Log in

Don't you dare go Hollow

iz-core: rule mail times use the recipient's timezone

Browse files at this commit

6b354af1773643e92abc3a724d6462d79d869763Ahmet Kaan GümüşParent: 074b2fd
Compose and batch compose format the crossing with moment_label_in in
the recipient's stored offset, same as reminders. Drop the UTC-suffixed
day_and_time helper.
crates/iz-core/src/mail.rsmodified+18 -33
@@ -25,10 +25,10 @@
2525 use std::sync::Arc;
2626
2727 use async_trait::async_trait;
28-use time::{Duration, OffsetDateTime};
28+use time::{Duration, OffsetDateTime, UtcOffset};
2929
3030 use crate::board::Transition;
31-use crate::detail::ActivityKind;
31+use crate::detail::{ActivityKind, moment_label_in, parse_zone};
3232 use crate::store::{
3333 ActivityEvent, Audience, ClaimedSend, Event, Freeing, MailOutcome, MailRule, MailSend,
3434 SendKind, Store, Trigger,
@@ -837,6 +837,20 @@ impl Engine {
837837 Ok(())
838838 }
839839
840+ /// The recipient's stored display offset. No account, or no workspace
841+ /// yet, reads as UTC — the same fallback `parse_zone` uses on junk.
842+ async fn zone_for(&self, email: &str) -> crate::store::Result<UtcOffset> {
843+ let Some(workspace) = self.store.workspace().await? else {
844+ return Ok(UtcOffset::UTC);
845+ };
846+ Ok(
847+ match self.store.user_by_email(&workspace.id, email).await? {
848+ Some(user) => parse_zone(&user.timezone),
849+ None => UtcOffset::UTC,
850+ },
851+ )
852+ }
853+
840854 /// The mail itself, built from the facts as they were committed.
841855 async fn compose(
842856 &self,
@@ -955,7 +969,7 @@ impl Engine {
955969 "{key} — {title}\n\n{happened}\n\n{when}\n\n{base}/?task={id}\n",
956970 key = facts.row.task_key,
957971 title = facts.row.title,
958- when = day_and_time(event.at()),
972+ when = moment_label_in(event.at(), self.zone_for(&send.recipient).await?),
959973 id = facts.row.id,
960974 );
961975 if rule.include_task_details {
@@ -1048,7 +1062,7 @@ impl Engine {
10481062 "{key} — {title}\n\nColumn: {column}\nDeadline: {deadline}\nAssignees: {assignees}\n\n{when}\n\n{base}/?task={id}\n",
10491063 key = facts.row.task_key,
10501064 title = facts.row.title,
1051- when = day_and_time(newest_event.at()),
1065+ when = moment_label_in(newest_event.at(), self.zone_for(&send.recipient).await?,),
10521066 id = facts.row.id,
10531067 );
10541068 if details {
@@ -1101,35 +1115,6 @@ fn activity_kind_for(trigger: &Trigger) -> Option<ActivityKind> {
11011115 }
11021116 }
11031117
1104-/// `Aug 26 at 11:04 UTC` — the crossing's own clock, not the sender's.
1105-fn day_and_time(at: OffsetDateTime) -> String {
1106- format!(
1107- "{} {} at {:02}:{:02} UTC",
1108- month_name(at.month()),
1109- at.day(),
1110- at.hour(),
1111- at.minute()
1112- )
1113-}
1114-
1115-fn month_name(month: time::Month) -> &'static str {
1116- use time::Month::*;
1117- match month {
1118- January => "Jan",
1119- February => "Feb",
1120- March => "Mar",
1121- April => "Apr",
1122- May => "May",
1123- June => "Jun",
1124- July => "Jul",
1125- August => "Aug",
1126- September => "Sep",
1127- October => "Oct",
1128- November => "Nov",
1129- December => "Dec",
1130- }
1131-}
1132-
11331118 #[cfg(test)]
11341119 mod backoff_tests {
11351120 use super::{MAX_ATTEMPTS, backoff};
crates/iz-core/tests/store.rsmodified+47 -3
@@ -3414,14 +3414,58 @@ async fn a_mail_says_when_the_card_moved_not_when_it_was_sent() {
34143414 let delivered = engine.deliver_owed(later, 10).await.unwrap();
34153415 assert_eq!(delivered.sent, 1);
34163416 let body = mailer.sent()[0].body.clone();
3417- let moved_day = transition.at.day();
3417+ let when = iz_core::detail::moment_label(transition.at);
34183418 assert!(
3419- body.contains(&format!("{moved_day} at")),
3419+ body.contains(&when),
34203420 "the mail says when the card moved: {body}"
34213421 );
34223422 let _ = std::fs::remove_dir_all(&dir);
34233423 }
34243424
3425+#[tokio::test]
3426+async fn a_rule_mail_tells_the_crossing_in_its_own_recipients_clock() {
3427+ let (dir, store, workspace, admin) = shared().await;
3428+ let grace = member(&store, &workspace, "grace@iz.sh", "Grace").await;
3429+ let emre = member(&store, &workspace, "emre@iz.sh", "Emre").await;
3430+ store
3431+ .set_preferences(&emre, "UTC+03:00", "dark", "en", "default")
3432+ .await
3433+ .unwrap();
3434+ let task = add_task(&store, &workspace, "Backlog", "Ship it", None, &admin).await;
3435+ store.assign_task(&task, &grace).await.unwrap();
3436+ store.assign_task(&task, &emre).await.unwrap();
3437+ a_rule(&store, &workspace, "Done", "Task completed").await;
3438+
3439+ let mailer = Remembering::taking_everything();
3440+ let engine = Engine::new(store.clone(), mailer.clone(), "https://iz.sh");
3441+ let moved = moved_to(&store, &workspace, &task, "Backlog", "Done", &admin).await;
3442+ engine.on_transition(&moved).await.unwrap();
3443+
3444+ let sent = mailer.sent();
3445+ let grace_body = sent
3446+ .iter()
3447+ .find(|mail| mail.to == "grace@iz.sh")
3448+ .expect("grace was mailed")
3449+ .body
3450+ .clone();
3451+ let emre_body = sent
3452+ .iter()
3453+ .find(|mail| mail.to == "emre@iz.sh")
3454+ .expect("emre was mailed")
3455+ .body
3456+ .clone();
3457+ let grace_when = iz_core::detail::moment_label_in(moved.at, iz_core::detail::parse_zone("UTC"));
3458+ let emre_when =
3459+ iz_core::detail::moment_label_in(moved.at, iz_core::detail::parse_zone("UTC+03:00"));
3460+ assert_ne!(
3461+ grace_when, emre_when,
3462+ "the two clocks must disagree so the pin is not the same string twice"
3463+ );
3464+ assert!(grace_body.contains(&grace_when), "grace: {grace_body}");
3465+ assert!(emre_body.contains(&emre_when), "emre: {emre_body}");
3466+ let _ = std::fs::remove_dir_all(&dir);
3467+}
3468+
34253469 #[tokio::test]
34263470 async fn a_failing_send_is_retried_a_bounded_number_of_times_and_then_written_off() {
34273471 let (dir, store, workspace, admin) = shared().await;
@@ -3802,7 +3846,7 @@ async fn a_mail_owed_by_a_delete_is_rebuilt_from_the_delete_on_a_retry() {
38023846 "the retry still names the task that was deleted: {body}"
38033847 );
38043848 assert!(
3805- body.contains(&format!("{} at", freeing.at.day())),
3849+ body.contains(&iz_core::detail::moment_label(freeing.at)),
38063850 "and says when the delete happened, not when the mail went: {body}"
38073851 );
38083852 let _ = std::fs::remove_dir_all(&dir);