From c9a65a3d138de84b498cd165e99d965561458b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 9 Sep 2026 07:27:04 +0300 Subject: [PATCH] =?UTF-8?q?the=20clock=20follows=20the=20face:=20im's=20ti?= =?UTF-8?q?mezone=20rides=20the=20directory=20onto=20the=20user=20row=20?= =?UTF-8?q?=E2=80=94=20sync=5Fmember=20stamps=20it=20on=20insert=20and=20u?= =?UTF-8?q?pdate=20and=20a=20changed=20zone=20announces=20Members=20like?= =?UTF-8?q?=20a=20changed=20photo=20does=20=E2=80=94=20and=20iz's=20own=20?= =?UTF-8?q?timezone=20editor=20is=20gone:=20the=20profile=20form=20carries?= =?UTF-8?q?=20only=20theme,=20interface=20and=20language,=20a=20posted=20z?= =?UTF-8?q?one=20is=20not=20read=20(never=20refused,=20never=20saved),=20t?= =?UTF-8?q?he=20save=20path=20carries=20the=20row's=20im-given=20zone=20th?= =?UTF-8?q?rough=20untouched,=20the=20dead=20bad-zone=20refusal=20and=20it?= =?UTF-8?q?s=20wording=20leave=20with=20the=20field,=20and=20the=20stamp-s?= =?UTF-8?q?hift=20tests=20set=20the=20viewer's=20zone=20the=20one=20way=20?= =?UTF-8?q?it=20still=20changes=20=E2=80=94=20through=20the=20mirror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/iz-core/src/store/mod.rs | 6 +- crates/iz-core/src/store/turso_store.rs | 16 ++- crates/iz-core/tests/store.rs | 74 +++++++++--- crates/iz-web/src/i18n.rs | 3 - crates/iz-web/src/main.rs | 1 + crates/iz-web/src/server.rs | 6 - crates/iz-web/src/settings.rs | 39 +----- crates/iz-web/tests/http.rs | 154 +++++++++--------------- 10 files changed, 137 insertions(+), 166 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a46bda3..ca0fa35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1771,7 +1771,7 @@ dependencies = [ [[package]] name = "im-client" version = "0.1.0" -source = "git+https://github.com/DizeyLab/im?rev=f7b2081#f7b208171820ca309b10043c6e86de12b81f3826" +source = "git+https://github.com/DizeyLab/im?rev=509d0e7#509d0e7b19104ad3ae2e1dc82c65e1f38dfe7d9b" dependencies = [ "base64 0.22.1", "chacha20poly1305", diff --git a/Cargo.toml b/Cargo.toml index 786ab2e..12e72cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/DizeyLab/iz" [workspace.dependencies] iz-core = { path = "crates/iz-core", default-features = false } iz-client = { path = "crates/iz-client" } -im-client = { git = "https://github.com/DizeyLab/im", rev = "f7b2081", default-features = false } +im-client = { git = "https://github.com/DizeyLab/im", rev = "509d0e7", default-features = false } serde = { version = "1.0.229", features = ["derive"] } serde_json = "1.0.145" thiserror = "2.0.20" diff --git a/crates/iz-core/src/store/mod.rs b/crates/iz-core/src/store/mod.rs index eed96f0..8d8e338 100644 --- a/crates/iz-core/src/store/mod.rs +++ b/crates/iz-core/src/store/mod.rs @@ -789,8 +789,9 @@ pub trait Store: BoardReads + DetailReads + 'static { /// gets a row born linked — assignable, mailable and avatar-able before /// their first visit. An unclaimed row with a matching address is /// claimed (sub stamped, id/role/preferences/history kept), a known row - /// follows the provider's address, name, admin flag and photo version, - /// and a row that already agrees is left alone. Unlike + /// follows the provider's address, name, admin flag, photo version and + /// timezone — the provider owns the clock now — and a row that already + /// agrees is left alone. Unlike /// [`Store::provision_user`] this is not a sign-in: `last_signed_in_at` /// is never stamped, and an empty database grows no workspace (the first /// sign-in builds it; the next beat mirrors everyone). The admin flag @@ -803,6 +804,7 @@ pub trait Store: BoardReads + DetailReads + 'static { display_name: &str, im_admin: bool, photo_version: u64, + timezone: &str, ) -> Result; async fn user(&self, id: &str) -> Result>; diff --git a/crates/iz-core/src/store/turso_store.rs b/crates/iz-core/src/store/turso_store.rs index e45bc70..e454045 100644 --- a/crates/iz-core/src/store/turso_store.rs +++ b/crates/iz-core/src/store/turso_store.rs @@ -1465,6 +1465,7 @@ impl Store for TursoStore { display_name: &str, im_admin: bool, photo_version: u64, + timezone: &str, ) -> Result { let email = fold_email(email); // IMMEDIATE like provision_user: a beat racing a first sign-in over @@ -1491,17 +1492,19 @@ impl Store for TursoStore { && user.display_name == display_name && role == user.role && user.photo_version == photo_version + && user.timezone == timezone { Some((user.id, MemberSync::Untouched)) } else { tx.execute( "UPDATE user SET email = ?1, display_name = ?2, role = ?3, \ - photo_version = ?4 WHERE id = ?5", + photo_version = ?4, timezone = ?5 WHERE id = ?6", params![ email.clone(), display_name, role.as_str(), photo_version as i64, + timezone, user.id.clone() ], ) @@ -1525,13 +1528,14 @@ impl Store for TursoStore { let role = synced_role(user.role, im_admin); tx.execute( "UPDATE user SET oidc_sub = ?1, email = ?2, display_name = ?3, role = ?4, \ - photo_version = ?5 WHERE id = ?6", + photo_version = ?5, timezone = ?6 WHERE id = ?7", params![ sub, email.clone(), display_name, role.as_str(), photo_version as i64, + timezone, user.id.clone() ], ) @@ -1561,8 +1565,9 @@ impl Store for TursoStore { let role = if im_admin { Role::Admin } else { Role::Member }; tx.execute( "INSERT INTO user (id, workspace_id, oidc_sub, email, display_name, \ - role, disabled, created_at, last_signed_in_at, photo_version) \ - VALUES (?1, ?2, ?3, ?4, ?5, ?6, 0, ?7, NULL, ?8)", + role, disabled, created_at, last_signed_in_at, photo_version, \ + timezone) \ + VALUES (?1, ?2, ?3, ?4, ?5, ?6, 0, ?7, NULL, ?8, ?9)", params![ id.clone(), workspace_id, @@ -1571,7 +1576,8 @@ impl Store for TursoStore { display_name, role.as_str(), now.clone(), - photo_version as i64 + photo_version as i64, + timezone ], ) .await diff --git a/crates/iz-core/tests/store.rs b/crates/iz-core/tests/store.rs index f4659f5..442175e 100644 --- a/crates/iz-core/tests/store.rs +++ b/crates/iz-core/tests/store.rs @@ -8407,7 +8407,7 @@ async fn set_user_disabled_round_trips() { async fn a_synced_member_is_born_linked_and_never_signed_in() { let (scratch, workspace, _admin) = workspace_with_admin().await; let sync = scratch - .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0) + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0, "UTC+03:00") .await .unwrap(); assert_eq!(sync, iz_core::store::MemberSync::Inserted); @@ -8422,7 +8422,7 @@ async fn a_synced_member_is_born_linked_and_never_signed_in() { assert!(row.last_signed_in_at.is_none()); // An im admin the workspace has never met is Admin from the first beat. scratch - .store.sync_member("sub-boss", "boss@iz.sh", "Boss", true, 0) + .store.sync_member("sub-boss", "boss@iz.sh", "Boss", true, 0, "UTC+03:00") .await .unwrap(); let boss = scratch @@ -8443,7 +8443,7 @@ async fn a_sync_claims_an_unclaimed_row_without_touching_its_sign_in_fact() { .await .unwrap(); let sync = scratch - .store.sync_member("sub-mert", "MERT@iz.sh", "Mert Yılmaz", false, 0) + .store.sync_member("sub-mert", "MERT@iz.sh", "Mert Yılmaz", false, 0, "UTC+03:00") .await .unwrap(); assert_eq!(sync, iz_core::store::MemberSync::Claimed); @@ -8460,11 +8460,11 @@ async fn a_sync_claims_an_unclaimed_row_without_touching_its_sign_in_fact() { #[tokio::test] async fn a_sync_follows_provider_drift_but_not_the_sign_in_fact() { - let (scratch, workspace, admin_id) = workspace_with_admin().await; + let (scratch, _workspace, admin_id) = workspace_with_admin().await; let before = scratch.store.user(&admin_id).await.unwrap().unwrap(); let seen = before.last_signed_in_at.clone(); let sync = scratch - .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", true, 0) + .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", true, 0, "UTC+03:00") .await .unwrap(); assert_eq!(sync, iz_core::store::MemberSync::Refreshed); @@ -8473,7 +8473,7 @@ async fn a_sync_follows_provider_drift_but_not_the_sign_in_fact() { assert_eq!(after.last_signed_in_at, seen); // Losing the flag in the directory drops an Admin to Member. scratch - .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", false, 0) + .store.sync_member("sub-ada", "ada@iz.sh", "Ada Lovelace", false, 0, "UTC+03:00") .await .unwrap(); let demoted = scratch.store.user(&admin_id).await.unwrap().unwrap(); @@ -8485,7 +8485,7 @@ async fn an_agreeing_sync_is_untouched_and_silent() { let (scratch, _, _) = workspace_with_admin().await; let mut rx = scratch.store.subscribe(); let sync = scratch - .store.sync_member("sub-ada", "ada@iz.sh", "Ada", true, 0) + .store.sync_member("sub-ada", "ada@iz.sh", "Ada", true, 0, "UTC") .await .unwrap(); assert_eq!(sync, iz_core::store::MemberSync::Untouched); @@ -8496,7 +8496,7 @@ async fn an_agreeing_sync_is_untouched_and_silent() { async fn a_sync_without_a_workspace_skips_and_writes_nothing() { let scratch = Scratch::open().await; let sync = scratch - .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0) + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 0, "UTC+03:00") .await .unwrap(); assert_eq!(sync, iz_core::store::MemberSync::Skipped); @@ -8512,8 +8512,7 @@ async fn a_photo_version_bump_refreshes_and_announces() { let (scratch, workspace, _admin) = workspace_with_admin().await; let mut rx = scratch.store.subscribe(); let sync = scratch - .store - .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2) + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2, "UTC+03:00") .await .unwrap(); assert_eq!(sync, iz_core::store::MemberSync::Inserted); @@ -8528,8 +8527,7 @@ async fn a_photo_version_bump_refreshes_and_announces() { // The same version again: the row agrees, and silence is the answer. let again = scratch - .store - .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2) + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 2, "UTC+03:00") .await .unwrap(); assert_eq!(again, iz_core::store::MemberSync::Untouched); @@ -8537,8 +8535,7 @@ async fn a_photo_version_bump_refreshes_and_announces() { // im counted another upload: the stamp moves and the move is news. let bumped = scratch - .store - .sync_member("sub-mert", "mert@iz.sh", "Mert", false, 3) + .store.sync_member("sub-mert", "mert@iz.sh", "Mert", false, 3, "UTC+03:00") .await .unwrap(); assert_eq!(bumped, iz_core::store::MemberSync::Refreshed); @@ -8552,6 +8549,55 @@ async fn a_photo_version_bump_refreshes_and_announces() { assert_eq!(announced(&mut rx), vec!["members".to_string()]); } +/// The clock is the provider's fact now: a sync that hears of a member's +/// timezone stamps it and says Refreshed (so the live channel hears), one +/// that already agrees says Untouched, and a row born from the directory +/// opens on the timezone im holds — never on iz's own old default. +#[tokio::test] +async fn a_timezone_change_refreshes_and_announces() { + let (scratch, workspace, _admin) = workspace_with_admin().await; + let mut rx = scratch.store.subscribe(); + let sync = scratch + .store + .sync_member("sub-deniz", "deniz@iz.sh", "Deniz", false, 0, "UTC-05:00") + .await + .unwrap(); + assert_eq!(sync, iz_core::store::MemberSync::Inserted); + let row = scratch + .store + .user_by_email(&workspace, "deniz@iz.sh") + .await + .unwrap() + .unwrap(); + assert_eq!(row.timezone, "UTC-05:00"); + assert_eq!(announced(&mut rx), vec!["members".to_string()]); + + // The same timezone again: the row agrees, and silence is the answer. + let again = scratch + .store + .sync_member("sub-deniz", "deniz@iz.sh", "Deniz", false, 0, "UTC-05:00") + .await + .unwrap(); + assert_eq!(again, iz_core::store::MemberSync::Untouched); + assert!(announced(&mut rx).is_empty()); + + // im recorded a move: the next sync carries it and the move is news. + let moved = scratch + .store + .sync_member("sub-deniz", "deniz@iz.sh", "Deniz", false, 0, "UTC+03:00") + .await + .unwrap(); + assert_eq!(moved, iz_core::store::MemberSync::Refreshed); + let row = scratch + .store + .user_by_email(&workspace, "deniz@iz.sh") + .await + .unwrap() + .unwrap(); + assert_eq!(row.timezone, "UTC+03:00"); + assert_eq!(announced(&mut rx), vec!["members".to_string()]); +} + /// The app-level setting drawer: a key never set reads as absent, one set /// reads back, and setting it again replaces rather than duplicates — the /// family mirror rewrites its key every beat, and two rows for one key diff --git a/crates/iz-web/src/i18n.rs b/crates/iz-web/src/i18n.rs index 8648c6d..d06a183 100644 --- a/crates/iz-web/src/i18n.rs +++ b/crates/iz-web/src/i18n.rs @@ -132,7 +132,6 @@ pub enum Key { ConnectionLastPass, ConnectionNever, EmailLabel, - TimezoneLabel, ThemeLabel, LightOption, DarkOption, @@ -568,8 +567,6 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (ConnectionNever, Tr) => "hiç", (EmailLabel, En) => "EMAIL", (EmailLabel, Tr) => "E-POSTA", - (TimezoneLabel, En) => "TIMEZONE", - (TimezoneLabel, Tr) => "SAAT DİLİMİ", (ThemeLabel, En) => "THEME", (ThemeLabel, Tr) => "TEMA", (UiLabel, En) => "INTERFACE", diff --git a/crates/iz-web/src/main.rs b/crates/iz-web/src/main.rs index eedd751..82d604a 100644 --- a/crates/iz-web/src/main.rs +++ b/crates/iz-web/src/main.rs @@ -437,6 +437,7 @@ async fn apply_member( &member.name, member.admin, member.photo_version, + &member.timezone, ) .await { diff --git a/crates/iz-web/src/server.rs b/crates/iz-web/src/server.rs index 6f5797f..c0ed1e2 100644 --- a/crates/iz-web/src/server.rs +++ b/crates/iz-web/src/server.rs @@ -349,7 +349,6 @@ pub enum Refusal { /// and days. BadPolicy, /// The timezone field was not one of the offsets the form offers. - BadZone, /// The theme field was not one of the values the form offers. BadTheme, /// The ui field was not one of the values the form offers. @@ -426,7 +425,6 @@ impl Refusal { "A limit has to be at least 1 MB, and no wider than 500 MB per file.".to_string() } Refusal::BadPolicy => "A security number is out of range.".to_string(), - Refusal::BadZone => "That is not a timezone.".to_string(), Refusal::BadTheme => "That is not a theme.".to_string(), Refusal::BadUi => "That is not an interface.".to_string(), Refusal::BadLanguage => "That is not a language.".to_string(), @@ -494,7 +492,6 @@ impl Refusal { "Limit en az 1 MB, dosya başına en çok 500 MB olabilir.".to_string() } Refusal::BadPolicy => "Güvenlik sayısı aralığın dışında.".to_string(), - Refusal::BadZone => "Bu bir saat dilimi değil.".to_string(), Refusal::BadTheme => "Bu bir tema değil.".to_string(), Refusal::BadUi => "Bu bir arayüz değil.".to_string(), Refusal::BadLanguage => "Bu bir dil değil.".to_string(), @@ -527,7 +524,6 @@ impl Refusal { "empty-name" => Refusal::EmptyName, "bad-limit" => Refusal::BadLimit, "bad-policy" => Refusal::BadPolicy, - "bad-zone" => Refusal::BadZone, "bad-theme" => Refusal::BadTheme, "bad-ui" => Refusal::BadUi, "bad-language" => Refusal::BadLanguage, @@ -575,7 +571,6 @@ impl Refusal { Refusal::EmptyName => "empty-name", Refusal::BadLimit => "bad-limit", Refusal::BadPolicy => "bad-policy", - Refusal::BadZone => "bad-zone", Refusal::BadTheme => "bad-theme", Refusal::BadUi => "bad-ui", Refusal::BadLanguage => "bad-language", @@ -927,7 +922,6 @@ mod refusal_message_tests { Refusal::FileTypeNotAllowed, Refusal::BadDeadline, Refusal::BadClock, - Refusal::BadZone, Refusal::BadTheme, Refusal::BadLanguage, Refusal::BadEmail, diff --git a/crates/iz-web/src/settings.rs b/crates/iz-web/src/settings.rs index 3eb91e6..c0014f8 100644 --- a/crates/iz-web/src/settings.rs +++ b/crates/iz-web/src/settings.rs @@ -634,7 +634,6 @@ async fn send_test_mail(cx: &Cx) -> Result<(StatusCode, HeaderMap, Vec)> { #[derive(serde::Deserialize)] struct SaveProfileForm { - timezone: String, theme: String, language: String, ui: String, @@ -649,31 +648,6 @@ const UI_OPTIONS: [&str; 2] = ["instrument", "ledger"]; /// The values the language field offers. const LANGUAGE_OPTIONS: [&str; 2] = ["en", "tr"]; -/// The offsets the timezone field offers, `"UTC-12:00"` through `"UTC+14:00"`. -/// -/// Decision: `time` (already a dependency) has no tz-database, and this -/// workspace has no other crate that carries one — adding one just for a -/// display label is a new dependency for what "show logs in my timezone" -/// does not need. Fixed offsets satisfy it; `"UTC"` stands for +00:00. -fn zone_options() -> Vec { - (-12..=14) - .map(|hour: i32| { - if hour == 0 { - "UTC".to_string() - } else { - format!( - "UTC{}{:02}:00", - if hour > 0 { "+" } else { "-" }, - hour.abs() - ) - } - }) - .collect() -} - -/// Writes the person asking's display-only preferences. Nobody touches -/// anybody else here: the id comes from the session, never from the form. -/// Name and address are im's to vouch and are not written here at all. #[route(POST "/api/save_profile")] async fn save_profile( cx: &Cx, @@ -683,9 +657,6 @@ async fn save_profile( Ok(user) => user, Err(refusal) => return Ok(saved_or_refused("save_profile", Some(refusal))), }; - if !zone_options().contains(&input.timezone) { - return Ok(saved_or_refused("save_profile", Some(Refusal::BadZone))); - } if !THEME_OPTIONS.contains(&input.theme.as_str()) { return Ok(saved_or_refused("save_profile", Some(Refusal::BadTheme))); } @@ -699,7 +670,7 @@ async fn save_profile( let refusal = match store .set_preferences( &user.id, - &input.timezone, + &user.timezone, &input.theme, &input.language, &input.ui, @@ -1326,14 +1297,6 @@ async fn settings_page(cx: &Cx) -> Result {

(t(lang, Key::IdentityFromIm))

-