diff --git a/crates/in-web/src/i18n.rs b/crates/in-web/src/i18n.rs index 5cd197d..285649c 100644 --- a/crates/in-web/src/i18n.rs +++ b/crates/in-web/src/i18n.rs @@ -171,6 +171,8 @@ pub enum Key { ConnectionConnected, ConnectionReconnecting, ConnectionLastEvent, + ConnectionLastPass, + Never, DisplayName, EmailAddress, QuotaUsage, @@ -349,6 +351,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { ConnectionConnected => "Connected", ConnectionReconnecting => "Reconnecting…", ConnectionLastEvent => "Last event", + ConnectionLastPass => "Last pass", + Never => "never", QuotaUsage => "Storage used", QuotaOf => "of", AdminPanel => "Everyone", @@ -520,6 +524,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { ConnectionConnected => "Bağlı", ConnectionReconnecting => "Yeniden bağlanıyor…", ConnectionLastEvent => "Son etkinlik", + ConnectionLastPass => "Son tarama", + Never => "hiç", AdminPanel => "Herkes", AllUsers => "Herkes", SetQuota => "Kotayı ayarla", diff --git a/crates/in-web/src/main.rs b/crates/in-web/src/main.rs index f5cd589..affd1d9 100644 --- a/crates/in-web/src/main.rs +++ b/crates/in-web/src/main.rs @@ -409,6 +409,8 @@ async fn identity_sync( for member in &members { mirror_member(&store, member, default_quota_bytes).await; } + // The roster pass committed: the card's healer heartbeat. + health.note_pass(); match client.open_stream().await { Ok(mut stream) => { health.connected(); diff --git a/crates/in-web/src/server.rs b/crates/in-web/src/server.rs index 08d379b..d9f5a97 100644 --- a/crates/in-web/src/server.rs +++ b/crates/in-web/src/server.rs @@ -63,6 +63,11 @@ pub struct DirectoryHealth { /// never. The age a card shows is derived at read time, so a stale /// moment ages honestly without a ticking task behind it. last_event: Arc, + /// Unix seconds of the last full `/directory` pass that committed — + /// the healer's heartbeat. It ticks slowly (boot, every stream end), + /// which is why a card shows it: a feed gone quiet and a mirror + /// stopped healing are two different silences. + last_pass: Arc, } impl DirectoryHealth { @@ -70,6 +75,7 @@ impl DirectoryHealth { Self { stream: Arc::new(std::sync::atomic::AtomicU8::new(0)), last_event: Arc::new(std::sync::atomic::AtomicI64::new(0)), + last_pass: Arc::new(std::sync::atomic::AtomicI64::new(0)), } } @@ -93,6 +99,13 @@ impl DirectoryHealth { self.last_event.store(now_unix(), Relaxed); } + /// A full roster pass committed: the mirror healed (or was already + /// true), however quiet the live feed has been. + pub fn note_pass(&self) { + use std::sync::atomic::Ordering::Relaxed; + self.last_pass.store(now_unix(), Relaxed); + } + /// Whether the card shows the green dot. pub fn stream_connected(&self) -> bool { use std::sync::atomic::Ordering::Relaxed; @@ -105,6 +118,14 @@ impl DirectoryHealth { let at = self.last_event.load(Relaxed); (at > 0).then(|| (now_unix() - at).max(0)) } + + /// Seconds since the last full roster pass, or `None` before the + /// first one — a boot whose pass has not landed yet. + pub fn last_pass_age_secs(&self) -> Option { + use std::sync::atomic::Ordering::Relaxed; + let at = self.last_pass.load(Relaxed); + (at > 0).then(|| (now_unix() - at).max(0)) + } } fn now_unix() -> i64 { diff --git a/crates/in-web/src/settings.rs b/crates/in-web/src/settings.rs index bea78b7..c16e937 100644 --- a/crates/in-web/src/settings.rs +++ b/crates/in-web/src/settings.rs @@ -25,7 +25,7 @@ use crate::server::{ Refusal, app, back_to, require_admin, require_user, share_link_url, share_origin, }; use crate::share::{refusal_banner, refusal_of, share_copy_script}; -use crate::i18n::{Key, lang, t}; +use crate::i18n::{Key, Lang, lang, t}; use crate::layout::{NavPage, topbar}; /// Bytes in human units: `512 B`, `1.5 KiB`, `2.0 GiB`. One decimal past @@ -45,6 +45,16 @@ pub fn human_bytes(bytes: u64) -> String { } } +/// The value half of a Connection card's age line: the seconds when the +/// moment is known, the `never` wording before its first occurrence — +/// a card that went silent and a card that never spoke read differently. +fn age_text(age: Option, language: Lang) -> String { + match age { + Some(age) => format!("{age}s"), + None => t(language, Key::Never).to_string(), + } +} + /// The share of the quota already held, for the usage bar's width. fn quota_percent(user: &User) -> u8 { if user.quota_bytes == 0 { @@ -308,6 +318,10 @@ async fn settings(cx: &Cx) -> Result { // any path that reaches this render. let connected = app.health.stream_connected(); let last_event = app.health.last_event_age_secs(); + let last_pass = app.health.last_pass_age_secs(); + // Both ages share one shape: the seconds when the moment is known, + // the `never` wording before the first occurrence — a card that went + // silent and a card that never spoke read differently. // Re-read the row so the quota bar never shows a stale number. let fresh = store.user(&user.id).await?.unwrap_or_else(|| user.clone()); let administers = fresh.admin; @@ -469,10 +483,13 @@ async fn settings(cx: &Cx) -> Result { } else { (t(language, Key::ConnectionReconnecting)) } - if let Some(age) = last_event { - (format!("{} · {}s", t(language, Key::ConnectionLastEvent), age)) - } +
+ (format!("{} · {}", t(language, Key::ConnectionLastEvent), age_text(last_event, language))) +
+
+ (format!("{} · {}", t(language, Key::ConnectionLastPass), age_text(last_pass, language))) +