Relative times are live on token, session, key, passkey, security, health and review pages
Browse files at this commit0a2c24cd7a5d7f5bc68c202309069e809ff07ceeParent: 4867bd3- feat
- relative times are live on token, session, key, passkey, security, health and review pages
12 changed files +227 -223
- crates/forge-web/assets/nav.js +22 -3
- crates/forge-web/src/i18n/alerts.rs +0 -8
- crates/forge-web/src/i18n/mod.rs +44 -119
- crates/forge-web/src/pages/admin_health.rs +39 -20
- crates/forge-web/src/pages/passkeys.rs +9 -17
- crates/forge-web/src/pages/review_requests.rs +3 -5
- crates/forge-web/src/pages/settings_gpg.rs +3 -3
- crates/forge-web/src/pages/settings_keys.rs +3 -3
- crates/forge-web/src/pages/settings_security.rs +22 -30
- crates/forge-web/src/pages/settings_sessions.rs +3 -3
- crates/forge-web/src/pages/settings_tokens.rs +3 -3
- crates/forge-web/src/views/mod.rs +76 -9
crates/forge-web/assets/nav.jsmodified+22 -3
| @@ -1572,10 +1572,22 @@ | |||
| 1572 | return { idx: 1 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, next: next }; | 1572 | return { idx: 1 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, next: next }; |
| 1573 | } | 1573 | } |
| 1574 | 1574 | ||
| 1575 | + // The wording for a time still ahead, `secs` whole seconds away. Under a minute reads "in 1 minute". | ||
| 1576 | + // The wording holds until the gap drops below `from`, the start of its unit's count. | ||
| 1577 | + function relAhead(secs) { | ||
| 1578 | + var units = [[60, 0], [3600, 1], [86400, 2], [2592000, 3], [31536000, 4]]; | ||
| 1579 | + var u = 0; | ||
| 1580 | + while (u < 4 && secs >= units[u + 1][0]) { u++; } | ||
| 1581 | + var size = units[u][0]; | ||
| 1582 | + var n = Math.max(1, Math.floor(secs / size)); | ||
| 1583 | + var from = secs < 60 ? 0 : n * size; | ||
| 1584 | + return { idx: 11 + 2 * units[u][1] + (n === 1 ? 0 : 1), n: n, from: from }; | ||
| 1585 | + } | ||
| 1586 | + | ||
| 1575 | function relUpdate() { | 1587 | function relUpdate() { |
| 1576 | relTimer = null; | 1588 | relTimer = null; |
| 1577 | var words = (document.documentElement.getAttribute('data-rel-words') || '').split('|'); | 1589 | var words = (document.documentElement.getAttribute('data-rel-words') || '').split('|'); |
| 1578 | - if (words.length < 11) { return; } // no wording from the server: nothing to re-word | 1590 | + if (words.length < 21) { return; } // no wording from the server: nothing to re-word |
| 1579 | var nowSec = (Date.now() + relSkew) / 1000; | 1591 | var nowSec = (Date.now() + relSkew) / 1000; |
| 1580 | var soonest = Infinity; | 1592 | var soonest = Infinity; |
| 1581 | Array.prototype.forEach.call(document.querySelectorAll('time[data-rel]'), function (el) { | 1593 | Array.prototype.forEach.call(document.querySelectorAll('time[data-rel]'), function (el) { |
| @@ -1583,10 +1595,17 @@ | |||
| 1583 | if (isNaN(at)) { return; } | 1595 | if (isNaN(at)) { return; } |
| 1584 | var unix = Math.floor(at / 1000); | 1596 | var unix = Math.floor(at / 1000); |
| 1585 | var age = nowSec - unix; | 1597 | var age = nowSec - unix; |
| 1586 | - var w = relWording(Math.max(0, Math.floor(age))); | 1598 | + var w, changeAt; // changeAt: the moment, in seconds, when the wording next changes |
| 1599 | + if (age < 0) { | ||
| 1600 | + w = relAhead(Math.floor(-age)); | ||
| 1601 | + changeAt = unix - w.from; | ||
| 1602 | + } else { | ||
| 1603 | + w = relWording(Math.floor(age)); | ||
| 1604 | + changeAt = unix + w.next; | ||
| 1605 | + } | ||
| 1587 | var label = words[w.idx].replace('{n}', w.n); | 1606 | var label = words[w.idx].replace('{n}', w.n); |
| 1588 | if (el.textContent !== label) { el.textContent = label; } | 1607 | if (el.textContent !== label) { el.textContent = label; } |
| 1589 | - soonest = Math.min(soonest, unix + w.next - nowSec); | 1608 | + soonest = Math.min(soonest, changeAt - nowSec); |
| 1590 | }); | 1609 | }); |
| 1591 | if (soonest !== Infinity) { | 1610 | if (soonest !== Infinity) { |
| 1592 | relTimer = setTimeout(relUpdate, Math.max(0, Math.ceil(soonest * 1000)) + 50); | 1611 | relTimer = setTimeout(relUpdate, Math.max(0, Math.ceil(soonest * 1000)) + 50); |
crates/forge-web/src/i18n/alerts.rsmodified+0 -8
| @@ -167,14 +167,6 @@ pub fn settings_link(lang: Lang) -> &'static str { | |||
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | -/// "since <time>" on the banner. | ||
| 171 | -pub fn since(lang: Lang, when: &str) -> String { | ||
| 172 | - match lang { | ||
| 173 | - Lang::En => format!("since {when}"), | ||
| 174 | - Lang::Tr => format!("{when} tarihinden beri"), | ||
| 175 | - } | ||
| 176 | -} | ||
| 177 | - | ||
| 178 | /// Email subject: the title, tagged with the instance. | 170 | /// Email subject: the title, tagged with the instance. |
| 179 | pub fn mail_subject(lang: Lang, title: &str) -> String { | 171 | pub fn mail_subject(lang: Lang, title: &str) -> String { |
| 180 | match lang { | 172 | match lang { |
crates/forge-web/src/i18n/mod.rsmodified+44 -119
| @@ -1122,28 +1122,38 @@ pub fn just_now(lang: Lang) -> &'static str { | |||
| 1122 | /// "3 days ago", or "3 gün önce". Turkish nouns stay singular after a number. | 1122 | /// "3 days ago", or "3 gün önce". Turkish nouns stay singular after a number. |
| 1123 | pub fn ago(lang: Lang, n: i64, unit: TimeUnit) -> String { | 1123 | pub fn ago(lang: Lang, n: i64, unit: TimeUnit) -> String { |
| 1124 | match lang { | 1124 | match lang { |
| 1125 | - Lang::En => { | 1125 | + Lang::En => format!("{n} {}{} ago", unit_name(lang, unit), plural(n)), |
| 1126 | - let word = match unit { | 1126 | + Lang::Tr => format!("{n} {} önce", unit_name(lang, unit)), |
| 1127 | - TimeUnit::Minute => "minute", | 1127 | + } |
| 1128 | - TimeUnit::Hour => "hour", | 1128 | +} |
| 1129 | - TimeUnit::Day => "day", | 1129 | + |
| 1130 | - TimeUnit::Month => "month", | 1130 | +/// "in 3 days", or "3 gün sonra": a time still to come. |
| 1131 | - TimeUnit::Year => "year", | 1131 | +pub fn from_now(lang: Lang, n: i64, unit: TimeUnit) -> String { |
| 1132 | - }; | 1132 | + match lang { |
| 1133 | - let plural = if n == 1 { "" } else { "s" }; | 1133 | + Lang::En => format!("in {n} {}{}", unit_name(lang, unit), plural(n)), |
| 1134 | - format!("{n} {word}{plural} ago") | 1134 | + Lang::Tr => format!("{n} {} sonra", unit_name(lang, unit)), |
| 1135 | - } | ||
| 1136 | - Lang::Tr => { | ||
| 1137 | - let word = match unit { | ||
| 1138 | - TimeUnit::Minute => "dakika", | ||
| 1139 | - TimeUnit::Hour => "saat", | ||
| 1140 | - TimeUnit::Day => "gün", | ||
| 1141 | - TimeUnit::Month => "ay", | ||
| 1142 | - TimeUnit::Year => "yıl", | ||
| 1143 | - }; | ||
| 1144 | - format!("{n} {word} önce") | ||
| 1145 | } | 1135 | } |
| 1146 | } | 1136 | } |
| 1137 | + | ||
| 1138 | +/// The English plural suffix for a count. | ||
| 1139 | +fn plural(n: i64) -> &'static str { | ||
| 1140 | + if n == 1 { "" } else { "s" } | ||
| 1141 | +} | ||
| 1142 | + | ||
| 1143 | +/// The unit's word: "day" or "gün". Turkish nouns stay singular after a number. | ||
| 1144 | +fn unit_name(lang: Lang, unit: TimeUnit) -> &'static str { | ||
| 1145 | + match (lang, unit) { | ||
| 1146 | + (Lang::En, TimeUnit::Minute) => "minute", | ||
| 1147 | + (Lang::En, TimeUnit::Hour) => "hour", | ||
| 1148 | + (Lang::En, TimeUnit::Day) => "day", | ||
| 1149 | + (Lang::En, TimeUnit::Month) => "month", | ||
| 1150 | + (Lang::En, TimeUnit::Year) => "year", | ||
| 1151 | + (Lang::Tr, TimeUnit::Minute) => "dakika", | ||
| 1152 | + (Lang::Tr, TimeUnit::Hour) => "saat", | ||
| 1153 | + (Lang::Tr, TimeUnit::Day) => "gün", | ||
| 1154 | + (Lang::Tr, TimeUnit::Month) => "ay", | ||
| 1155 | + (Lang::Tr, TimeUnit::Year) => "yıl", | ||
| 1156 | + } | ||
| 1147 | } | 1157 | } |
| 1148 | 1158 | ||
| 1149 | /// The name shown for the ghost account that owns the content of deleted users. | 1159 | /// The name shown for the ghost account that owns the content of deleted users. |
| @@ -1164,69 +1174,12 @@ pub fn visibility_label(lang: Lang, visibility: forge_core::Visibility) -> &'sta | |||
| 1164 | } | 1174 | } |
| 1165 | } | 1175 | } |
| 1166 | 1176 | ||
| 1167 | -/// "Added 2026-01-02", with the last use appended when there is one. | 1177 | +/// The label before a date in a dated line: "Created", or "Oluşturuldu:" in Turkish, where the |
| 1168 | -pub fn added_line(lang: Lang, created: &str, last_used: Option<&str>) -> String { | 1178 | +/// colon sets it apart from the date. |
| 1169 | - let added = match lang { | 1179 | +pub fn dated_label(lang: Lang, key: Key) -> String { |
| 1170 | - Lang::En => format!("{} {created}", t(lang, Key::Added)), | ||
| 1171 | - Lang::Tr => format!("{created} tarihinde {}", t(lang, Key::Added)), | ||
| 1172 | - }; | ||
| 1173 | - match last_used { | ||
| 1174 | - None => added, | ||
| 1175 | - Some(used) => match lang { | ||
| 1176 | - Lang::En => format!("{added} · {} {used}", t(lang, Key::LastUsed)), | ||
| 1177 | - Lang::Tr => format!("{added} · {}: {used}", t(lang, Key::LastUsed)), | ||
| 1178 | - }, | ||
| 1179 | - } | ||
| 1180 | -} | ||
| 1181 | - | ||
| 1182 | -/// A token's dates: "Created X · last used Y · expires Z". A missing use or expiry reads "never". | ||
| 1183 | -pub fn token_meta( | ||
| 1184 | - lang: Lang, | ||
| 1185 | - created: &str, | ||
| 1186 | - last_used: Option<&str>, | ||
| 1187 | - expires: Option<&str>, | ||
| 1188 | -) -> String { | ||
| 1189 | - let used = last_used.unwrap_or(t(lang, Key::Never)); | ||
| 1190 | - let expiry = expires.unwrap_or(t(lang, Key::Never)); | ||
| 1191 | - dated_line( | ||
| 1192 | - lang, | ||
| 1193 | - (Key::Created, created), | ||
| 1194 | - (Key::LastUsed, used), | ||
| 1195 | - (Key::ExpiresLabel, expiry), | ||
| 1196 | - ) | ||
| 1197 | -} | ||
| 1198 | - | ||
| 1199 | -/// A web session's dates: "Signed in X · last seen Y · expires Z". | ||
| 1200 | -pub fn session_meta(lang: Lang, signed_in: &str, last_seen: &str, expires: &str) -> String { | ||
| 1201 | - dated_line( | ||
| 1202 | - lang, | ||
| 1203 | - (Key::SignedIn, signed_in), | ||
| 1204 | - (Key::LastSeen, last_seen), | ||
| 1205 | - (Key::ExpiresLabel, expires), | ||
| 1206 | - ) | ||
| 1207 | -} | ||
| 1208 | - | ||
| 1209 | -/// Three labelled dates joined with " · ". English reads "Label value"; Turkish reads "Etiket: value". | ||
| 1210 | -fn dated_line(lang: Lang, a: (Key, &str), b: (Key, &str), c: (Key, &str)) -> String { | ||
| 1211 | match lang { | 1180 | match lang { |
| 1212 | - Lang::En => format!( | 1181 | + Lang::En => t(lang, key).to_owned(), |
| 1213 | - "{} {} · {} {} · {} {}", | 1182 | + Lang::Tr => format!("{}:", t(lang, key)), |
| 1214 | - t(lang, a.0), | ||
| 1215 | - a.1, | ||
| 1216 | - t(lang, b.0), | ||
| 1217 | - b.1, | ||
| 1218 | - t(lang, c.0), | ||
| 1219 | - c.1 | ||
| 1220 | - ), | ||
| 1221 | - Lang::Tr => format!( | ||
| 1222 | - "{}: {} · {}: {} · {}: {}", | ||
| 1223 | - t(lang, a.0), | ||
| 1224 | - a.1, | ||
| 1225 | - t(lang, b.0), | ||
| 1226 | - b.1, | ||
| 1227 | - t(lang, c.0), | ||
| 1228 | - c.1 | ||
| 1229 | - ), | ||
| 1230 | } | 1183 | } |
| 1231 | } | 1184 | } |
| 1232 | 1185 | ||
| @@ -1238,22 +1191,17 @@ pub fn unsupported_key_type(lang: Lang, algorithm: &str) -> String { | |||
| 1238 | } | 1191 | } |
| 1239 | } | 1192 | } |
| 1240 | 1193 | ||
| 1241 | -/// "Last changed 3 days ago", with the relative time already rendered. | 1194 | +/// The label before the password's change time: "Last changed", or "Son değişiklik:" in Turkish. |
| 1242 | -pub fn last_changed_line(lang: Lang, when: &str) -> String { | 1195 | +pub fn last_changed_label(lang: Lang) -> &'static str { |
| 1243 | match lang { | 1196 | match lang { |
| 1244 | - Lang::En => format!("Last changed {when}"), | 1197 | + Lang::En => "Last changed", |
| 1245 | - Lang::Tr => format!("Son değişiklik: {when}"), | 1198 | + Lang::Tr => "Son değişiklik:", |
| 1246 | } | 1199 | } |
| 1247 | } | 1200 | } |
| 1248 | 1201 | ||
| 1249 | -/// The state of the latest verification mail on the Email row, such as "verification mail sent | 1202 | +/// The state of the latest verification mail on the Email row, such as "verification mail sent". |
| 1250 | -/// 5 minutes ago". `sent_ago` is the relative time of the send, when known. | 1203 | +/// The send time, when known, follows it as a live relative time. |
| 1251 | -pub fn email_mail_line( | 1204 | +pub fn email_mail_line(lang: Lang, state: forge_core::mail::MailState, attempts: u32) -> String { |
| 1252 | - lang: Lang, | ||
| 1253 | - state: forge_core::mail::MailState, | ||
| 1254 | - attempts: u32, | ||
| 1255 | - sent_ago: Option<&str>, | ||
| 1256 | -) -> String { | ||
| 1257 | use forge_core::mail::MailState; | 1205 | use forge_core::mail::MailState; |
| 1258 | match (state, lang) { | 1206 | match (state, lang) { |
| 1259 | (MailState::Queued | MailState::Sending, _) => t(lang, Key::EmailMailQueued).to_owned(), | 1207 | (MailState::Queued | MailState::Sending, _) => t(lang, Key::EmailMailQueued).to_owned(), |
| @@ -1267,32 +1215,9 @@ pub fn email_mail_line( | |||
| 1267 | attempts + 1 | 1215 | attempts + 1 |
| 1268 | ) | 1216 | ) |
| 1269 | } | 1217 | } |
| 1270 | - (MailState::Sent, Lang::En) => match sent_ago { | 1218 | + (MailState::Sent, Lang::En) => "verification mail sent".to_owned(), |
| 1271 | - Some(ago) => format!("verification mail sent {ago}"), | 1219 | + (MailState::Sent, Lang::Tr) => "doğrulama iletisi gönderildi".to_owned(), |
| 1272 | - None => "verification mail sent".to_owned(), | ||
| 1273 | - }, | ||
| 1274 | - (MailState::Sent, Lang::Tr) => match sent_ago { | ||
| 1275 | - Some(ago) => format!("doğrulama iletisi {ago} gönderildi"), | ||
| 1276 | - None => "doğrulama iletisi gönderildi".to_owned(), | ||
| 1277 | - }, | ||
| 1278 | - } | ||
| 1279 | -} | ||
| 1280 | - | ||
| 1281 | -/// The device's "Added 2026-10-18 · Last used 5 minutes ago" line. A part without a stamp is | ||
| 1282 | -/// left out. | ||
| 1283 | -pub fn device_line(lang: Lang, added: Option<&str>, used: Option<&str>) -> String { | ||
| 1284 | - let (added_word, used_word) = match lang { | ||
| 1285 | - Lang::En => ("Added", "Last used"), | ||
| 1286 | - Lang::Tr => ("Eklendi", "Son kullanım"), | ||
| 1287 | - }; | ||
| 1288 | - let mut parts = Vec::new(); | ||
| 1289 | - if let Some(day) = added { | ||
| 1290 | - parts.push(format!("{added_word} {day}")); | ||
| 1291 | - } | ||
| 1292 | - if let Some(when) = used { | ||
| 1293 | - parts.push(format!("{used_word} {when}")); | ||
| 1294 | } | 1220 | } |
| 1295 | - parts.join(" · ") | ||
| 1296 | } | 1221 | } |
| 1297 | 1222 | ||
| 1298 | /// "7 of 10 recovery codes unused". | 1223 | /// "7 of 10 recovery codes unused". |
crates/forge-web/src/pages/admin_health.rsmodified+39 -20
| @@ -23,13 +23,15 @@ use crate::i18n::{self, Lang}; | |||
| 23 | use crate::live::{Topic, stream_changes}; | 23 | use crate::live::{Topic, stream_changes}; |
| 24 | use crate::pages::admin_users::admin_only; | 24 | use crate::pages::admin_users::admin_only; |
| 25 | use crate::state::AppState; | 25 | use crate::state::AppState; |
| 26 | -use crate::views::{human_size, now_unix, relative_time, shell}; | 26 | +use crate::views::{human_size, now_unix, rel_time, shell}; |
| 27 | 27 | ||
| 28 | /// One cell of the grid. | 28 | /// One cell of the grid. |
| 29 | struct Tile { | 29 | struct Tile { |
| 30 | title: &'static str, | 30 | title: &'static str, |
| 31 | big: String, | 31 | big: String, |
| 32 | sub: String, | 32 | sub: String, |
| 33 | + /// A stamp shown after `sub` as a live relative time. | ||
| 34 | + stamp: Option<String>, | ||
| 33 | /// `""`, `ok` or `bad`. | 35 | /// `""`, `ok` or `bad`. |
| 34 | tone: &'static str, | 36 | tone: &'static str, |
| 35 | /// Percent of a meter to fill, for disk tiles. | 37 | /// Percent of a meter to fill, for disk tiles. |
| @@ -41,6 +43,7 @@ fn tile(title: &'static str, big: impl Into<String>, sub: impl Into<String>) -> | |||
| 41 | title, | 43 | title, |
| 42 | big: big.into(), | 44 | big: big.into(), |
| 43 | sub: sub.into(), | 45 | sub: sub.into(), |
| 46 | + stamp: None, | ||
| 44 | tone: "", | 47 | tone: "", |
| 45 | meter: None, | 48 | meter: None, |
| 46 | } | 49 | } |
| @@ -113,6 +116,7 @@ fn disk_tile(lang: Lang, title: &'static str, space: Option<(u64, u64)>, label: | |||
| 113 | at(lang, A::Free), | 116 | at(lang, A::Free), |
| 114 | human_size(lang, total) | 117 | human_size(lang, total) |
| 115 | ), | 118 | ), |
| 119 | + stamp: None, | ||
| 116 | tone: if pct >= 90 { "bad" } else { "" }, | 120 | tone: if pct >= 90 { "bad" } else { "" }, |
| 117 | meter: Some(pct), | 121 | meter: Some(pct), |
| 118 | } | 122 | } |
| @@ -220,12 +224,9 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> { | |||
| 220 | Some(false) => at(lang, A::Failed), | 224 | Some(false) => at(lang, A::Failed), |
| 221 | None => at(lang, A::Pending), | 225 | None => at(lang, A::Pending), |
| 222 | }, | 226 | }, |
| 223 | - format!( | ||
| 224 | - "{} ({})", | ||
| 225 | format_in_tz(at_unix, tz), | 227 | format_in_tz(at_unix, tz), |
| 226 | - relative_time(lang, at_unix, now) | ||
| 227 | - ), | ||
| 228 | ); | 228 | ); |
| 229 | + t.stamp = Some(run.started_at.clone()); | ||
| 229 | t.tone = match run.ok { | 230 | t.tone = match run.ok { |
| 230 | Some(true) => "ok", | 231 | Some(true) => "ok", |
| 231 | Some(false) => "bad", | 232 | Some(false) => "bad", |
| @@ -254,11 +255,13 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> { | |||
| 254 | } else { | 255 | } else { |
| 255 | at(lang, A::Ok) | 256 | at(lang, A::Ok) |
| 256 | }, | 257 | }, |
| 257 | - ok_unix.map_or_else( | 258 | + if ok_unix.is_some() { |
| 258 | - || at(lang, A::Never).to_owned(), | 259 | + "" |
| 259 | - |t| relative_time(lang, t, now), | 260 | + } else { |
| 260 | - ), | 261 | + at(lang, A::Never) |
| 262 | + }, | ||
| 261 | ); | 263 | ); |
| 264 | + t.stamp = status.last_ok_at.clone(); | ||
| 262 | t.tone = if errored || lagging { "bad" } else { "ok" }; | 265 | t.tone = if errored || lagging { "bad" } else { "ok" }; |
| 263 | t | 266 | t |
| 264 | } | 267 | } |
| @@ -289,7 +292,9 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> { | |||
| 289 | struct AlertRow { | 292 | struct AlertRow { |
| 290 | title: String, | 293 | title: String, |
| 291 | body: String, | 294 | body: String, |
| 292 | - since: String, | 295 | + /// The raised time as the server formats it, and its stamp for the live relative time. |
| 296 | + date: String, | ||
| 297 | + stamp: String, | ||
| 293 | } | 298 | } |
| 294 | 299 | ||
| 295 | /// The alerts active now, worded for the viewer. | 300 | /// The alerts active now, worded for the viewer. |
| @@ -305,19 +310,25 @@ async fn alert_rows(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<AlertR | |||
| 305 | AlertRow { | 310 | AlertRow { |
| 306 | title: alert_text::title(lang, &alert.kind, &alert.subject, false), | 311 | title: alert_text::title(lang, &alert.kind, &alert.subject, false), |
| 307 | body: alert_text::body(lang, &alert.kind, &alert.subject, &alert.detail, false), | 312 | body: alert_text::body(lang, &alert.kind, &alert.subject, &alert.detail, false), |
| 308 | - since: alert_text::since( | 313 | + date: format_in_tz(raised, tz), |
| 309 | - lang, | 314 | + stamp: alert.raised_at.clone(), |
| 310 | - &format!( | ||
| 311 | - "{} ({})", | ||
| 312 | - format_in_tz(raised, tz), | ||
| 313 | - relative_time(lang, raised, now) | ||
| 314 | - ), | ||
| 315 | - ), | ||
| 316 | } | 315 | } |
| 317 | }) | 316 | }) |
| 318 | .collect()) | 317 | .collect()) |
| 319 | } | 318 | } |
| 320 | 319 | ||
| 320 | +/// The alert's raised time: "since <date> · <live time>", worded per language. | ||
| 321 | +#[component] | ||
| 322 | +async fn since_line(lang: Lang, date: &str, stamp: &str) -> Result<impl View> { | ||
| 323 | + Ok(view! { | ||
| 324 | + if matches!(lang, Lang::Tr) { | ||
| 325 | + (date) " · " rel_time(lang: lang, stamp: stamp) " tarihinden beri" | ||
| 326 | + } else { | ||
| 327 | + "since " (date) " · " rel_time(lang: lang, stamp: stamp) | ||
| 328 | + } | ||
| 329 | + }) | ||
| 330 | +} | ||
| 331 | + | ||
| 321 | #[component] | 332 | #[component] |
| 322 | async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Result<impl View> { | 333 | async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Result<impl View> { |
| 323 | let count = alerts.len(); | 334 | let count = alerts.len(); |
| @@ -334,7 +345,7 @@ async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Res | |||
| 334 | for a in alerts.into_iter() { | 345 | for a in alerts.into_iter() { |
| 335 | <li> | 346 | <li> |
| 336 | <strong>(a.title.as_str())</strong> | 347 | <strong>(a.title.as_str())</strong> |
| 337 | - <span class="muted small">(a.since.as_str())</span> | 348 | + <span class="muted small">since_line(lang: lang, date: a.date.as_str(), stamp: a.stamp.as_str())</span> |
| 338 | if !a.body.is_empty() { | 349 | if !a.body.is_empty() { |
| 339 | <div class="small">(a.body.as_str())</div> | 350 | <div class="small">(a.body.as_str())</div> |
| 340 | } | 351 | } |
| @@ -349,8 +360,16 @@ async fn health_view(lang: Lang, tiles: Vec<Tile>, alerts: Vec<AlertRow>) -> Res | |||
| 349 | <section class=(format!("tile {}", t.tone))> | 360 | <section class=(format!("tile {}", t.tone))> |
| 350 | <h2>(t.title)</h2> | 361 | <h2>(t.title)</h2> |
| 351 | <div class="big">(t.big.as_str())</div> | 362 | <div class="big">(t.big.as_str())</div> |
| 363 | + if !t.sub.is_empty() || t.stamp.is_some() { | ||
| 364 | + <div class="sub"> | ||
| 365 | + (t.sub.as_str()) | ||
| 366 | + if let Some(stamp) = t.stamp.as_deref() { | ||
| 352 | if !t.sub.is_empty() { | 367 | if !t.sub.is_empty() { |
| 353 | - <div class="sub">(t.sub.as_str())</div> | 368 | + " · " |
| 369 | + } | ||
| 370 | + rel_time(lang: lang, stamp: stamp) | ||
| 371 | + } | ||
| 372 | + </div> | ||
| 354 | } | 373 | } |
| 355 | if let Some(pct) = t.meter { | 374 | if let Some(pct) = t.meter { |
| 356 | <progress class="meter" max="100" value=(pct.to_string())></progress> | 375 | <progress class="meter" max="100" value=(pct.to_string())></progress> |
crates/forge-web/src/pages/passkeys.rsmodified+9 -17
| @@ -14,7 +14,6 @@ use base64::Engine; | |||
| 14 | use base64::engine::general_purpose::URL_SAFE_NO_PAD; | 14 | use base64::engine::general_purpose::URL_SAFE_NO_PAD; |
| 15 | use forge_core::session::new_csrf_token; | 15 | use forge_core::session::new_csrf_token; |
| 16 | use forge_core::store::passkeys::{MAX_PASSKEYS, PasskeyRow, clean_name}; | 16 | use forge_core::store::passkeys::{MAX_PASSKEYS, PasskeyRow, clean_name}; |
| 17 | -use forge_core::time::stamp_to_unix; | ||
| 18 | use forge_core::{AuditAction, User}; | 17 | use forge_core::{AuditAction, User}; |
| 19 | use http::header::{HeaderValue, RETRY_AFTER}; | 18 | use http::header::{HeaderValue, RETRY_AFTER}; |
| 20 | use serde::Deserialize; | 19 | use serde::Deserialize; |
| @@ -36,14 +35,14 @@ use webauthn_rs_proto::ResidentKeyRequirement; | |||
| 36 | use crate::api; | 35 | use crate::api; |
| 37 | use crate::audit::{self, Actor, Target}; | 36 | use crate::audit::{self, Actor, Target}; |
| 38 | use crate::auth::{ | 37 | use crate::auth::{ |
| 39 | - check_pre_csrf, clear_pending_login, clear_pre_csrf, login, require_csrf, safe_next, unix_now, | 38 | + check_pre_csrf, clear_pending_login, clear_pre_csrf, login, require_csrf, safe_next, |
| 40 | }; | 39 | }; |
| 41 | use crate::client_ip::client_ip; | 40 | use crate::client_ip::client_ip; |
| 42 | use crate::i18n::{self, Key, Lang, t}; | 41 | use crate::i18n::{self, Key, Lang, t}; |
| 43 | use crate::mail::account::{PasskeyChange, send_passkey_notice}; | 42 | use crate::mail::account::{PasskeyChange, send_passkey_notice}; |
| 44 | use crate::state::AppState; | 43 | use crate::state::AppState; |
| 45 | use crate::throttle::{self, LOGIN_IP_LIMIT}; | 44 | use crate::throttle::{self, LOGIN_IP_LIMIT}; |
| 46 | -use crate::views::relative_time; | 45 | +use crate::views::added_status; |
| 47 | 46 | ||
| 48 | /// How long a started ceremony stays valid. | 47 | /// How long a started ceremony stays valid. |
| 49 | const CEREMONY_TTL: Duration = Duration::from_secs(5 * 60); | 48 | const CEREMONY_TTL: Duration = Duration::from_secs(5 * 60); |
| @@ -626,8 +625,9 @@ async fn audit_failed(cx: &Cx, state: &AppState, user: Option<&User>, reason: &s | |||
| 626 | pub struct PasskeyItem { | 625 | pub struct PasskeyItem { |
| 627 | pub id: String, | 626 | pub id: String, |
| 628 | pub name: String, | 627 | pub name: String, |
| 629 | - /// "Added 2026-10-18 · Last used 5 minutes ago". | 628 | + /// The stamps behind the "Added … · Last used …" line. |
| 630 | - pub status: String, | 629 | + pub created_at: String, |
| 630 | + pub last_used_at: Option<String>, | ||
| 631 | } | 631 | } |
| 632 | 632 | ||
| 633 | /// What the passkey section of the security page needs. | 633 | /// What the passkey section of the security page needs. |
| @@ -639,24 +639,16 @@ pub struct PasskeyPanel { | |||
| 639 | 639 | ||
| 640 | pub async fn build_panel( | 640 | pub async fn build_panel( |
| 641 | state: &AppState, | 641 | state: &AppState, |
| 642 | - lang: Lang, | ||
| 643 | user_id: &str, | 642 | user_id: &str, |
| 644 | ) -> forge_core::Result<PasskeyPanel> { | 643 | ) -> forge_core::Result<PasskeyPanel> { |
| 645 | - let now = i64::try_from(unix_now()).unwrap_or(i64::MAX); | ||
| 646 | let rows = state.store.list_passkeys(user_id).await?; | 644 | let rows = state.store.list_passkeys(user_id).await?; |
| 647 | let items = rows | 645 | let items = rows |
| 648 | .into_iter() | 646 | .into_iter() |
| 649 | - .map(|row| { | 647 | + .map(|row| PasskeyItem { |
| 650 | - let ago = row | ||
| 651 | - .last_used_at | ||
| 652 | - .as_deref() | ||
| 653 | - .and_then(stamp_to_unix) | ||
| 654 | - .map(|unix| relative_time(lang, unix, now)); | ||
| 655 | - PasskeyItem { | ||
| 656 | - status: i18n::device_line(lang, row.created_at.get(..10), ago.as_deref()), | ||
| 657 | id: row.id, | 648 | id: row.id, |
| 658 | name: row.name, | 649 | name: row.name, |
| 659 | - } | 650 | + created_at: row.created_at, |
| 651 | + last_used_at: row.last_used_at, | ||
| 660 | }) | 652 | }) |
| 661 | .collect(); | 653 | .collect(); |
| 662 | Ok(PasskeyPanel { | 654 | Ok(PasskeyPanel { |
| @@ -702,7 +694,7 @@ pub async fn passkeys_panel(lang: Lang, csrf: &str, panel: PasskeyPanel) -> Resu | |||
| 702 | <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="9" cy="8" r="4"/><path d="M2 21v-1a6 6 0 0 1 6-6h2"/><circle cx="18" cy="14" r="2.5"/></svg> | 694 | <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><circle cx="9" cy="8" r="4"/><path d="M2 21v-1a6 6 0 0 1 6-6h2"/><circle cx="18" cy="14" r="2.5"/></svg> |
| 703 | <div class="security-row-main"> | 695 | <div class="security-row-main"> |
| 704 | <p class="security-row-title">(item.name.as_str())</p> | 696 | <p class="security-row-title">(item.name.as_str())</p> |
| 705 | - <p class="security-row-status">(item.status.as_str())</p> | 697 | + <p class="security-row-status">added_status(lang: lang, added: Some(item.created_at.as_str()), used: item.last_used_at.as_deref())</p> |
| 706 | </div> | 698 | </div> |
| 707 | <details class="security-action"> | 699 | <details class="security-action"> |
| 708 | <summary>(s(lang, "Rename", "Yeniden adlandır"))</summary> | 700 | <summary>(s(lang, "Rename", "Yeniden adlandır"))</summary> |
crates/forge-web/src/pages/review_requests.rsmodified+3 -5
| @@ -21,7 +21,7 @@ use crate::notify; | |||
| 21 | use crate::pages::issue_parts::{ItemKind, check_write, may_change, parse_number}; | 21 | use crate::pages::issue_parts::{ItemKind, check_write, may_change, parse_number}; |
| 22 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; | 22 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| 23 | use crate::state::AppState; | 23 | use crate::state::AppState; |
| 24 | -use crate::views::{now_unix, relative_time, repo_href, shell}; | 24 | +use crate::views::{rel_time, repo_href, shell}; |
| 25 | 25 | ||
| 26 | path_param!(owner); | 26 | path_param!(owner); |
| 27 | path_param!(repo); | 27 | path_param!(repo); |
| @@ -208,7 +208,6 @@ async fn review_requests(cx: &Cx) -> Result<impl View> { | |||
| 208 | let user = &viewer.0; | 208 | let user = &viewer.0; |
| 209 | let lang = i18n::lang(cx, Some(user)); | 209 | let lang = i18n::lang(cx, Some(user)); |
| 210 | let items = state.store.review_requests_for_user(&user.id).await?; | 210 | let items = state.store.review_requests_for_user(&user.id).await?; |
| 211 | - let now = now_unix(); | ||
| 212 | let mut rows = Vec::new(); | 211 | let mut rows = Vec::new(); |
| 213 | for item in items { | 212 | for item in items { |
| 214 | // A repo the viewer can no longer read is not listed. | 213 | // A repo the viewer can no longer read is not listed. |
| @@ -227,7 +226,6 @@ async fn review_requests(cx: &Cx) -> Result<impl View> { | |||
| 227 | if authorize(Some(user), &repo, role, org_role, Action::Read).is_err() { | 226 | if authorize(Some(user), &repo, role, org_role, Action::Read).is_err() { |
| 228 | continue; | 227 | continue; |
| 229 | } | 228 | } |
| 230 | - let unix = crate::pages::issue_parts::stamp_unix(&item.created_at); | ||
| 231 | rows.push(( | 229 | rows.push(( |
| 232 | format!("{}/{}", item.repo_owner, item.repo_name), | 230 | format!("{}/{}", item.repo_owner, item.repo_name), |
| 233 | repo_href( | 231 | repo_href( |
| @@ -238,7 +236,7 @@ async fn review_requests(cx: &Cx) -> Result<impl View> { | |||
| 238 | ), | 236 | ), |
| 239 | format!("#{} {}", item.number, item.title), | 237 | format!("#{} {}", item.number, item.title), |
| 240 | ga::requested_by(lang, &item.requested_by), | 238 | ga::requested_by(lang, &item.requested_by), |
| 241 | - relative_time(lang, unix, now), | 239 | + item.created_at.clone(), |
| 242 | )); | 240 | )); |
| 243 | } | 241 | } |
| 244 | let heading = ga::t(lang, AK::ReviewRequests); | 242 | let heading = ga::t(lang, AK::ReviewRequests); |
| @@ -259,7 +257,7 @@ async fn review_requests(cx: &Cx) -> Result<impl View> { | |||
| 259 | <span class="muted small">(row.0.as_str())</span> | 257 | <span class="muted small">(row.0.as_str())</span> |
| 260 | <a class="notif-title" href=(row.1.as_str())>(row.2.as_str())</a> | 258 | <a class="notif-title" href=(row.1.as_str())>(row.2.as_str())</a> |
| 261 | <span class="muted small">(row.3.as_str())</span> | 259 | <span class="muted small">(row.3.as_str())</span> |
| 262 | - <span class="muted small">(row.4.as_str())</span> | 260 | + <span class="muted small">rel_time(lang: lang, stamp: row.4.as_str())</span> |
| 263 | </li> | 261 | </li> |
| 264 | } | 262 | } |
| 265 | </ul> | 263 | </ul> |
crates/forge-web/src/pages/settings_gpg.rsmodified+3 -3
| @@ -13,10 +13,10 @@ use topcoat::view::{View, component, view}; | |||
| 13 | 13 | ||
| 14 | use crate::audit::{self, Actor, Target}; | 14 | use crate::audit::{self, Actor, Target}; |
| 15 | use crate::auth::{require_csrf, require_user}; | 15 | use crate::auth::{require_csrf, require_user}; |
| 16 | -use crate::i18n::{self, Key, Lang, added_line, t}; | 16 | +use crate::i18n::{self, Key, Lang, t}; |
| 17 | use crate::signatures; | 17 | use crate::signatures; |
| 18 | use crate::state::AppState; | 18 | use crate::state::AppState; |
| 19 | -use crate::views::{alert, shell, user_facing_message}; | 19 | +use crate::views::{added_status, alert, shell, user_facing_message}; |
| 20 | 20 | ||
| 21 | #[derive(Deserialize)] | 21 | #[derive(Deserialize)] |
| 22 | struct AddKeyForm { | 22 | struct AddKeyForm { |
| @@ -60,7 +60,7 @@ async fn gpg_view( | |||
| 60 | <div class="item-main"> | 60 | <div class="item-main"> |
| 61 | <code class="small">(key.fingerprint.clone())</code> | 61 | <code class="small">(key.fingerprint.clone())</code> |
| 62 | <span class="muted small">(key.emails.join(", "))</span> | 62 | <span class="muted small">(key.emails.join(", "))</span> |
| 63 | - <span class="muted small">(added_line(lang, key.created_at.as_str(), None))</span> | 63 | + <span class="muted small">added_status(lang: lang, added: Some(key.created_at.as_str()), used: None)</span> |
| 64 | </div> | 64 | </div> |
| 65 | <form method="post" action="/settings/gpg/delete"> | 65 | <form method="post" action="/settings/gpg/delete"> |
| 66 | <input type="hidden" name="csrf" value=(csrf)> | 66 | <input type="hidden" name="csrf" value=(csrf)> |
crates/forge-web/src/pages/settings_keys.rsmodified+3 -3
| @@ -13,9 +13,9 @@ use topcoat::view::{View, component, view}; | |||
| 13 | 13 | ||
| 14 | use crate::audit::{self, Actor, Target}; | 14 | use crate::audit::{self, Actor, Target}; |
| 15 | use crate::auth::{require_csrf, require_user}; | 15 | use crate::auth::{require_csrf, require_user}; |
| 16 | -use crate::i18n::{self, Key, Lang, added_line, t, unsupported_key_type}; | 16 | +use crate::i18n::{self, Key, Lang, t, unsupported_key_type}; |
| 17 | use crate::state::AppState; | 17 | use crate::state::AppState; |
| 18 | -use crate::views::{alert, shell, user_facing_message}; | 18 | +use crate::views::{added_status, alert, shell, user_facing_message}; |
| 19 | 19 | ||
| 20 | /// Algorithms accepted for web-registered keys. `ssh-rsa` is rejected with its own message. | 20 | /// Algorithms accepted for web-registered keys. `ssh-rsa` is rejected with its own message. |
| 21 | const ACCEPTED: &[&str] = &[ | 21 | const ACCEPTED: &[&str] = &[ |
| @@ -158,7 +158,7 @@ async fn keys_view( | |||
| 158 | <strong>(key.title.clone())</strong> | 158 | <strong>(key.title.clone())</strong> |
| 159 | <span class="muted small">(key.algorithm.clone())</span> | 159 | <span class="muted small">(key.algorithm.clone())</span> |
| 160 | <code class="small">(key.fingerprint.clone())</code> | 160 | <code class="small">(key.fingerprint.clone())</code> |
| 161 | - <span class="muted small">(added_line(lang, key.created_at.as_str(), key.last_used_at.as_deref()))</span> | 161 | + <span class="muted small">added_status(lang: lang, added: Some(key.created_at.as_str()), used: key.last_used_at.as_deref())</span> |
| 162 | </div> | 162 | </div> |
| 163 | <form method="post" action="/settings/keys/delete"> | 163 | <form method="post" action="/settings/keys/delete"> |
| 164 | <input type="hidden" name="csrf" value=(csrf)> | 164 | <input type="hidden" name="csrf" value=(csrf)> |
crates/forge-web/src/pages/settings_security.rsmodified+22 -30
| @@ -6,7 +6,6 @@ use std::time::{Duration, Instant}; | |||
| 6 | 6 | ||
| 7 | use forge_core::mail::MailKind; | 7 | use forge_core::mail::MailKind; |
| 8 | use forge_core::names::normalize_name; | 8 | use forge_core::names::normalize_name; |
| 9 | -use forge_core::time::stamp_to_unix; | ||
| 10 | use forge_core::totp; | 9 | use forge_core::totp; |
| 11 | use forge_core::{AuditAction, Session, User, secret}; | 10 | use forge_core::{AuditAction, Session, User, secret}; |
| 12 | use http::header::{HeaderValue, RETRY_AFTER}; | 11 | use http::header::{HeaderValue, RETRY_AFTER}; |
| @@ -29,7 +28,7 @@ use crate::i18n::{self, Key, Lang, password_too_long, password_too_short, t}; | |||
| 29 | use crate::pages::passkeys::{PasskeyPanel, build_panel, passkeys_panel, s}; | 28 | use crate::pages::passkeys::{PasskeyPanel, build_panel, passkeys_panel, s}; |
| 30 | use crate::state::AppState; | 29 | use crate::state::AppState; |
| 31 | use crate::throttle::{self, LOGIN_USER_LIMIT, TWO_FACTOR_USER_LIMIT}; | 30 | use crate::throttle::{self, LOGIN_USER_LIMIT, TWO_FACTOR_USER_LIMIT}; |
| 32 | -use crate::views::{alert, relative_time, shell, user_facing_message}; | 31 | +use crate::views::{added_status, alert, rel_time, shell, user_facing_message}; |
| 33 | 32 | ||
| 34 | /// Shortest and longest new passwords, in characters. | 33 | /// Shortest and longest new passwords, in characters. |
| 35 | const MIN_PASSWORD_CHARS: usize = 10; | 34 | const MIN_PASSWORD_CHARS: usize = 10; |
| @@ -145,8 +144,9 @@ enum TwoFactorPanel { | |||
| 145 | /// The enabled authenticator device, with the recovery code count, as the page shows it. | 144 | /// The enabled authenticator device, with the recovery code count, as the page shows it. |
| 146 | struct DeviceView { | 145 | struct DeviceView { |
| 147 | name: String, | 146 | name: String, |
| 148 | - /// "Added 2026-10-18 · Last used 5 minutes ago". | 147 | + /// The stamps behind the "Added … · Last used …" line. |
| 149 | - status: String, | 148 | + added: Option<String>, |
| 149 | + used: Option<String>, | ||
| 150 | /// "7 of 10 recovery codes unused". | 150 | /// "7 of 10 recovery codes unused". |
| 151 | codes_line: String, | 151 | codes_line: String, |
| 152 | /// True when few recovery codes are left, so the line warns. | 152 | /// True when few recovery codes are left, so the line warns. |
| @@ -164,6 +164,8 @@ struct SecurityPage { | |||
| 164 | stored_email: String, | 164 | stored_email: String, |
| 165 | /// The Email row's state: "Verified", or "Not verified" with the verification mail's state. | 165 | /// The Email row's state: "Verified", or "Not verified" with the verification mail's state. |
| 166 | email_status: String, | 166 | email_status: String, |
| 167 | + /// When the latest verification mail went out, shown after the state as a live time. | ||
| 168 | + email_sent: Option<String>, | ||
| 167 | notice: Option<&'static str>, | 169 | notice: Option<&'static str>, |
| 168 | password_error: Option<String>, | 170 | password_error: Option<String>, |
| 169 | email_error: Option<String>, | 171 | email_error: Option<String>, |
| @@ -172,7 +174,7 @@ struct SecurityPage { | |||
| 172 | codes: Option<Vec<String>>, | 174 | codes: Option<Vec<String>>, |
| 173 | /// Secret (base32) and `otpauth://` URI while enrollment is waiting for a code. | 175 | /// Secret (base32) and `otpauth://` URI while enrollment is waiting for a code. |
| 174 | pending: Option<(String, String)>, | 176 | pending: Option<(String, String)>, |
| 175 | - /// "Last changed 3 days ago", when the change time is known. | 177 | + /// When the password last changed, shown as a live time, when known. |
| 176 | password_changed: Option<String>, | 178 | password_changed: Option<String>, |
| 177 | /// The enabled device. `None` when two-factor is off. | 179 | /// The enabled device. `None` when two-factor is off. |
| 178 | two_factor: Option<DeviceView>, | 180 | two_factor: Option<DeviceView>, |
| @@ -191,6 +193,7 @@ async fn security_body(page: SecurityPage) -> Result<impl View> { | |||
| 191 | email_verified, | 193 | email_verified, |
| 192 | stored_email, | 194 | stored_email, |
| 193 | email_status, | 195 | email_status, |
| 196 | + email_sent, | ||
| 194 | notice, | 197 | notice, |
| 195 | password_error, | 198 | password_error, |
| 196 | email_error, | 199 | email_error, |
| @@ -262,8 +265,8 @@ async fn security_body(page: SecurityPage) -> Result<impl View> { | |||
| 262 | <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg> | 265 | <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/></svg> |
| 263 | <div class="security-row-main"> | 266 | <div class="security-row-main"> |
| 264 | <h2 class="security-row-title">(t(lang, Key::Password))</h2> | 267 | <h2 class="security-row-title">(t(lang, Key::Password))</h2> |
| 265 | - if let Some(line) = password_changed { | 268 | + if let Some(stamp) = password_changed { |
| 266 | - <p class="security-row-status">(line.as_str())</p> | 269 | + <p class="security-row-status">(i18n::last_changed_label(lang)) " " rel_time(lang: lang, stamp: stamp.as_str())</p> |
| 267 | } | 270 | } |
| 268 | </div> | 271 | </div> |
| 269 | <details class="security-action" open=(password_open)> | 272 | <details class="security-action" open=(password_open)> |
| @@ -299,7 +302,7 @@ async fn security_body(page: SecurityPage) -> Result<impl View> { | |||
| 299 | if stored_email.is_empty() { | 302 | if stored_email.is_empty() { |
| 300 | <p class="security-row-status">(t(lang, Key::EmailNoAddress))</p> | 303 | <p class="security-row-status">(t(lang, Key::EmailNoAddress))</p> |
| 301 | } else { | 304 | } else { |
| 302 | - <p class="security-row-status"><span class="security-email">(stored_email.as_str())</span> (" · ")(email_status.as_str())</p> | 305 | + <p class="security-row-status"><span class="security-email">(stored_email.as_str())</span> (" · ")(email_status.as_str()) if let Some(stamp) = email_sent { " " rel_time(lang: lang, stamp: stamp.as_str()) }</p> |
| 303 | } | 306 | } |
| 304 | </div> | 307 | </div> |
| 305 | if show_resend { | 308 | if show_resend { |
| @@ -378,7 +381,7 @@ async fn security_body(page: SecurityPage) -> Result<impl View> { | |||
| 378 | <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="3" width="10" height="18" rx="2"/><path d="M11 18h2"/></svg> | 381 | <svg class="security-icon" viewBox="0 0 24 24" aria-hidden="true"><rect x="7" y="3" width="10" height="18" rx="2"/><path d="M11 18h2"/></svg> |
| 379 | <div class="security-row-main"> | 382 | <div class="security-row-main"> |
| 380 | <p class="security-row-title">(device.name.as_str())</p> | 383 | <p class="security-row-title">(device.name.as_str())</p> |
| 381 | - <p class="security-row-status">(device.status.as_str())</p> | 384 | + <p class="security-row-status">added_status(lang: lang, added: device.added.as_deref(), used: device.used.as_deref())</p> |
| 382 | </div> | 385 | </div> |
| 383 | </li> | 386 | </li> |
| 384 | <li class="security-row security-device"> | 387 | <li class="security-row security-device"> |
| @@ -519,12 +522,6 @@ async fn build_page( | |||
| 519 | shown: Shown, | 522 | shown: Shown, |
| 520 | ) -> forge_core::Result<SecurityPage> { | 523 | ) -> forge_core::Result<SecurityPage> { |
| 521 | // Relative times are rendered against one `now`, so every line on the page agrees. | 524 | // Relative times are rendered against one `now`, so every line on the page agrees. |
| 522 | - let now = i64::try_from(unix_now()).unwrap_or(i64::MAX); | ||
| 523 | - let ago = |stamp: Option<&str>| { | ||
| 524 | - stamp | ||
| 525 | - .and_then(stamp_to_unix) | ||
| 526 | - .map(|unix| relative_time(lang, unix, now)) | ||
| 527 | - }; | ||
| 528 | let totp_state = state.store.totp_state(&viewer.0.id).await?; | 525 | let totp_state = state.store.totp_state(&viewer.0.id).await?; |
| 529 | let (pending, two_factor) = match totp_state { | 526 | let (pending, two_factor) = match totp_state { |
| 530 | Some(totp) if totp.enabled => { | 527 | Some(totp) if totp.enabled => { |
| @@ -533,11 +530,8 @@ async fn build_page( | |||
| 533 | name: totp | 530 | name: totp |
| 534 | .name | 531 | .name |
| 535 | .unwrap_or_else(|| t(lang, Key::AuthenticatorApp).to_owned()), | 532 | .unwrap_or_else(|| t(lang, Key::AuthenticatorApp).to_owned()), |
| 536 | - status: i18n::device_line( | 533 | + added: totp.created_at.clone(), |
| 537 | - lang, | 534 | + used: totp.last_used_at.clone(), |
| 538 | - totp.created_at.as_deref().and_then(|stamp| stamp.get(..10)), | ||
| 539 | - ago(totp.last_used_at.as_deref()).as_deref(), | ||
| 540 | - ), | ||
| 541 | codes_line: i18n::codes_left_line(lang, unused, RECOVERY_CODE_COUNT as u64), | 535 | codes_line: i18n::codes_left_line(lang, unused, RECOVERY_CODE_COUNT as u64), |
| 542 | codes_low: unused <= LOW_RECOVERY_CODES, | 536 | codes_low: unused <= LOW_RECOVERY_CODES, |
| 543 | }; | 537 | }; |
| @@ -556,13 +550,7 @@ async fn build_page( | |||
| 556 | }, | 550 | }, |
| 557 | None => (None, None), | 551 | None => (None, None), |
| 558 | }; | 552 | }; |
| 559 | - let password_changed = state | 553 | + let password_changed = state.store.password_changed_at(&viewer.0.id).await?; |
| 560 | - .store | ||
| 561 | - .password_changed_at(&viewer.0.id) | ||
| 562 | - .await? | ||
| 563 | - .as_deref() | ||
| 564 | - .and_then(|stamp| ago(Some(stamp))) | ||
| 565 | - .map(|when| i18n::last_changed_line(lang, &when)); | ||
| 566 | let owned_repos = state | 554 | let owned_repos = state |
| 567 | .store | 555 | .store |
| 568 | .list_repos_by_owner(&viewer.0.id) | 556 | .list_repos_by_owner(&viewer.0.id) |
| @@ -572,6 +560,7 @@ async fn build_page( | |||
| 572 | .collect(); | 560 | .collect(); |
| 573 | let stored_email = viewer.0.email.clone().unwrap_or_default(); | 561 | let stored_email = viewer.0.email.clone().unwrap_or_default(); |
| 574 | let email_verified = state.store.email_is_verified(&viewer.0.id).await?; | 562 | let email_verified = state.store.email_is_verified(&viewer.0.id).await?; |
| 563 | + let mut email_sent = None; | ||
| 575 | let email_status = if stored_email.is_empty() { | 564 | let email_status = if stored_email.is_empty() { |
| 576 | String::new() | 565 | String::new() |
| 577 | } else if email_verified { | 566 | } else if email_verified { |
| @@ -583,9 +572,11 @@ async fn build_page( | |||
| 583 | .latest_mail_for(&viewer.0.id, MailKind::Verification) | 572 | .latest_mail_for(&viewer.0.id, MailKind::Verification) |
| 584 | .await? | 573 | .await? |
| 585 | { | 574 | { |
| 586 | - let sent_ago = ago(mail.sent_at.as_deref()); | 575 | + let line = i18n::email_mail_line(lang, mail.state, mail.attempts); |
| 587 | - let line = i18n::email_mail_line(lang, mail.state, mail.attempts, sent_ago.as_deref()); | ||
| 588 | status = format!("{status} · {line}"); | 576 | status = format!("{status} · {line}"); |
| 577 | + if matches!(mail.state, forge_core::mail::MailState::Sent) { | ||
| 578 | + email_sent = mail.sent_at; | ||
| 579 | + } | ||
| 589 | } | 580 | } |
| 590 | status | 581 | status |
| 591 | }; | 582 | }; |
| @@ -593,11 +584,12 @@ async fn build_page( | |||
| 593 | lang, | 584 | lang, |
| 594 | csrf: viewer.1.csrf_token.clone(), | 585 | csrf: viewer.1.csrf_token.clone(), |
| 595 | delete_error: shown.delete_error, | 586 | delete_error: shown.delete_error, |
| 596 | - passkeys: build_panel(state, lang, &viewer.0.id).await?, | 587 | + passkeys: build_panel(state, &viewer.0.id).await?, |
| 597 | owned_repos, | 588 | owned_repos, |
| 598 | email_verified, | 589 | email_verified, |
| 599 | stored_email, | 590 | stored_email, |
| 600 | email_status, | 591 | email_status, |
| 592 | + email_sent, | ||
| 601 | email: shown | 593 | email: shown |
| 602 | .email_draft | 594 | .email_draft |
| 603 | .unwrap_or_else(|| viewer.0.email.clone().unwrap_or_default()), | 595 | .unwrap_or_else(|| viewer.0.email.clone().unwrap_or_default()), |
crates/forge-web/src/pages/settings_sessions.rsmodified+3 -3
| @@ -11,9 +11,9 @@ use topcoat::view::{View, component, view}; | |||
| 11 | 11 | ||
| 12 | use crate::audit::{self, Actor, Target}; | 12 | use crate::audit::{self, Actor, Target}; |
| 13 | use crate::auth::{logout, require_csrf, require_user}; | 13 | use crate::auth::{logout, require_csrf, require_user}; |
| 14 | -use crate::i18n::{self, Key, Lang, session_meta, t}; | 14 | +use crate::i18n::{self, Key, Lang, t}; |
| 15 | use crate::state::AppState; | 15 | use crate::state::AppState; |
| 16 | -use crate::views::shell; | 16 | +use crate::views::{rel_time, shell}; |
| 17 | 17 | ||
| 18 | #[derive(Deserialize)] | 18 | #[derive(Deserialize)] |
| 19 | struct RevokeForm { | 19 | struct RevokeForm { |
| @@ -47,7 +47,7 @@ async fn sessions_view( | |||
| 47 | <li class="item"> | 47 | <li class="item"> |
| 48 | <div class="item-main"> | 48 | <div class="item-main"> |
| 49 | <strong>(session.user_agent.clone().unwrap_or_else(|| t(lang, Key::UnknownBrowser).into()))</strong> | 49 | <strong>(session.user_agent.clone().unwrap_or_else(|| t(lang, Key::UnknownBrowser).into()))</strong> |
| 50 | - <span class="muted small">(session_meta(lang, session.created_at.as_str(), session.last_seen.as_str(), session.expires_at.as_str()))</span> | 50 | + <span class="muted small">(i18n::dated_label(lang, Key::SignedIn)) " " rel_time(lang: lang, stamp: session.created_at.as_str()) " · " (i18n::dated_label(lang, Key::LastSeen)) " " rel_time(lang: lang, stamp: session.last_seen.as_str()) " · " (i18n::dated_label(lang, Key::ExpiresLabel)) " " rel_time(lang: lang, stamp: session.expires_at.as_str())</span> |
| 51 | if session.id == current_id { | 51 | if session.id == current_id { |
| 52 | <span class="badge public">(t(lang, Key::ThisSession))</span> | 52 | <span class="badge public">(t(lang, Key::ThisSession))</span> |
| 53 | } | 53 | } |
crates/forge-web/src/pages/settings_tokens.rsmodified+3 -3
| @@ -21,10 +21,10 @@ use crate::audit::{self, Actor, Target}; | |||
| 21 | use crate::auth::{require_csrf, require_user}; | 21 | use crate::auth::{require_csrf, require_user}; |
| 22 | use crate::i18n::packages::{self as pk, K as PK}; | 22 | use crate::i18n::packages::{self as pk, K as PK}; |
| 23 | use crate::i18n::releases_ci::{self as rc, K as RC}; | 23 | use crate::i18n::releases_ci::{self as rc, K as RC}; |
| 24 | -use crate::i18n::{self, Key, Lang, t, token_meta, token_name_length}; | 24 | +use crate::i18n::{self, Key, Lang, t, token_name_length}; |
| 25 | use crate::pages::admin_runners::confirm_post; | 25 | use crate::pages::admin_runners::confirm_post; |
| 26 | use crate::state::AppState; | 26 | use crate::state::AppState; |
| 27 | -use crate::views::{alert, shell}; | 27 | +use crate::views::{alert, rel_time, rel_time_or_never, shell}; |
| 28 | 28 | ||
| 29 | /// Scopes are fixed to `repo` for M1. | 29 | /// Scopes are fixed to `repo` for M1. |
| 30 | const SCOPES: &[&str] = &["repo"]; | 30 | const SCOPES: &[&str] = &["repo"]; |
| @@ -109,7 +109,7 @@ async fn tokens_view( | |||
| 109 | <li class="item"> | 109 | <li class="item"> |
| 110 | <div class="item-main"> | 110 | <div class="item-main"> |
| 111 | <strong>(token.name.clone())</strong> | 111 | <strong>(token.name.clone())</strong> |
| 112 | - <span class="muted small">(token_meta(lang, token.created_at.as_str(), token.last_used_at.as_deref(), token.expires_at.as_deref()))</span> | 112 | + <span class="muted small">(i18n::dated_label(lang, Key::Created)) " " rel_time(lang: lang, stamp: token.created_at.as_str()) " · " (i18n::dated_label(lang, Key::LastUsed)) " " rel_time_or_never(lang: lang, stamp: token.last_used_at.as_deref()) " · " (i18n::dated_label(lang, Key::ExpiresLabel)) " " rel_time_or_never(lang: lang, stamp: token.expires_at.as_deref())</span> |
| 113 | </div> | 113 | </div> |
| 114 | confirm_post(lang: lang, csrf: csrf, action: "/settings/tokens/delete", label: t(lang, Key::Delete), message: delete_message(lang, token.name.as_str()), confirm: delete_confirm(lang), danger: true, fields: vec![("id", token.id.clone())]) | 114 | confirm_post(lang: lang, csrf: csrf, action: "/settings/tokens/delete", label: t(lang, Key::Delete), message: delete_message(lang, token.name.as_str()), confirm: delete_confirm(lang), danger: true, fields: vec![("id", token.id.clone())]) |
| 115 | </li> | 115 | </li> |
crates/forge-web/src/views/mod.rsmodified+76 -9
| @@ -962,11 +962,18 @@ fn civil_from_days(days: i64) -> (i64, i64, i64) { | |||
| 962 | } | 962 | } |
| 963 | 963 | ||
| 964 | /// "just now", "5 minutes ago", "1 day ago", relative to `now`; Turkish reads "az önce" and | 964 | /// "just now", "5 minutes ago", "1 day ago", relative to `now`; Turkish reads "az önce" and |
| 965 | -/// "5 dakika önce". | 965 | +/// "5 dakika önce". A time still to come reads "in 3 months", or "3 ay sonra"; under a minute |
| 966 | +/// ahead it reads "in 1 minute". | ||
| 966 | pub fn relative_time(lang: Lang, unix: i64, now: i64) -> String { | 967 | pub fn relative_time(lang: Lang, unix: i64, now: i64) -> String { |
| 967 | use i18n::TimeUnit; | 968 | use i18n::TimeUnit; |
| 968 | - let secs = now.saturating_sub(unix).max(0); | 969 | + let ahead = unix > now; |
| 970 | + let secs = if ahead { | ||
| 971 | + unix.saturating_sub(now) | ||
| 972 | + } else { | ||
| 973 | + now.saturating_sub(unix) | ||
| 974 | + }; | ||
| 969 | let (n, unit) = match secs { | 975 | let (n, unit) = match secs { |
| 976 | + 0..60 if ahead => (1, TimeUnit::Minute), | ||
| 970 | 0..60 => return i18n::just_now(lang).to_owned(), | 977 | 0..60 => return i18n::just_now(lang).to_owned(), |
| 971 | 60..3_600 => (secs / 60, TimeUnit::Minute), | 978 | 60..3_600 => (secs / 60, TimeUnit::Minute), |
| 972 | 3_600..86_400 => (secs / 3_600, TimeUnit::Hour), | 979 | 3_600..86_400 => (secs / 3_600, TimeUnit::Hour), |
| @@ -974,29 +981,87 @@ pub fn relative_time(lang: Lang, unix: i64, now: i64) -> String { | |||
| 974 | 2_592_000..31_536_000 => (secs / 2_592_000, TimeUnit::Month), | 981 | 2_592_000..31_536_000 => (secs / 2_592_000, TimeUnit::Month), |
| 975 | _ => (secs / 31_536_000, TimeUnit::Year), | 982 | _ => (secs / 31_536_000, TimeUnit::Year), |
| 976 | }; | 983 | }; |
| 984 | + if ahead { | ||
| 985 | + i18n::from_now(lang, n, unit) | ||
| 986 | + } else { | ||
| 977 | i18n::ago(lang, n, unit) | 987 | i18n::ago(lang, n, unit) |
| 978 | } | 988 | } |
| 989 | +} | ||
| 979 | 990 | ||
| 980 | /// The wording `relative_time` uses, for nav.js to re-word a `<time data-rel>` as the clock moves: | 991 | /// The wording `relative_time` uses, for nav.js to re-word a `<time data-rel>` as the clock moves: |
| 981 | -/// "just now", then the singular and the plural of each unit with `{n}` for the number, joined by `|`. | 992 | +/// "just now", then the singular and the plural of each past unit with `{n}` for the number, then |
| 982 | -/// The order is fixed: minute, hour, day, month, year. | 993 | +/// the singular and the plural of each future unit, all joined by `|`. The order is fixed: minute, |
| 994 | +/// hour, day, month, year. | ||
| 983 | pub fn rel_words(lang: Lang) -> String { | 995 | pub fn rel_words(lang: Lang) -> String { |
| 984 | use i18n::TimeUnit; | 996 | use i18n::TimeUnit; |
| 985 | - let mut words = vec![i18n::just_now(lang).to_owned()]; | 997 | + let units = [ |
| 986 | - for unit in [ | ||
| 987 | TimeUnit::Minute, | 998 | TimeUnit::Minute, |
| 988 | TimeUnit::Hour, | 999 | TimeUnit::Hour, |
| 989 | TimeUnit::Day, | 1000 | TimeUnit::Day, |
| 990 | TimeUnit::Month, | 1001 | TimeUnit::Month, |
| 991 | TimeUnit::Year, | 1002 | TimeUnit::Year, |
| 992 | - ] { | 1003 | + ]; |
| 1004 | + let mut words = vec![i18n::just_now(lang).to_owned()]; | ||
| 1005 | + for unit in units { | ||
| 993 | for n in [1, 2] { | 1006 | for n in [1, 2] { |
| 994 | words.push(i18n::ago(lang, n, unit).replacen(&n.to_string(), "{n}", 1)); | 1007 | words.push(i18n::ago(lang, n, unit).replacen(&n.to_string(), "{n}", 1)); |
| 995 | } | 1008 | } |
| 996 | } | 1009 | } |
| 1010 | + for unit in units { | ||
| 1011 | + for n in [1, 2] { | ||
| 1012 | + words.push(i18n::from_now(lang, n, unit).replacen(&n.to_string(), "{n}", 1)); | ||
| 1013 | + } | ||
| 1014 | + } | ||
| 997 | words.join("|") | 1015 | words.join("|") |
| 998 | } | 1016 | } |
| 999 | 1017 | ||
| 1018 | +/// A live relative time for an RFC 3339 stamp: a `<time data-rel>` that nav.js re-words as the | ||
| 1019 | +/// clock moves. A stamp that does not parse renders empty. | ||
| 1020 | +#[component] | ||
| 1021 | +pub async fn rel_time(lang: Lang, stamp: &str) -> Result<impl View> { | ||
| 1022 | + let label = forge_core::time::stamp_to_unix(stamp) | ||
| 1023 | + .map_or_else(String::new, |unix| relative_time(lang, unix, now_unix())); | ||
| 1024 | + Ok(view! { | ||
| 1025 | + <time data-rel="true" datetime=(stamp)>(label)</time> | ||
| 1026 | + }) | ||
| 1027 | +} | ||
| 1028 | + | ||
| 1029 | +/// A live relative time, or "never" when there is no stamp. | ||
| 1030 | +#[component] | ||
| 1031 | +pub async fn rel_time_or_never(lang: Lang, stamp: Option<&str>) -> Result<impl View> { | ||
| 1032 | + Ok(view! { | ||
| 1033 | + if let Some(stamp) = stamp { | ||
| 1034 | + rel_time(lang: lang, stamp: stamp) | ||
| 1035 | + } else { | ||
| 1036 | + (t(lang, Key::Never)) | ||
| 1037 | + } | ||
| 1038 | + }) | ||
| 1039 | +} | ||
| 1040 | + | ||
| 1041 | +/// A key's or device's dates: "Added 3 days ago · Last used 5 minutes ago". A part without a | ||
| 1042 | +/// stamp is left out. | ||
| 1043 | +#[component] | ||
| 1044 | +pub async fn added_status( | ||
| 1045 | + lang: Lang, | ||
| 1046 | + added: Option<&str>, | ||
| 1047 | + used: Option<&str>, | ||
| 1048 | +) -> Result<impl View> { | ||
| 1049 | + let sep = if added.is_some() && used.is_some() { | ||
| 1050 | + " · " | ||
| 1051 | + } else { | ||
| 1052 | + "" | ||
| 1053 | + }; | ||
| 1054 | + Ok(view! { | ||
| 1055 | + if let Some(stamp) = added { | ||
| 1056 | + (i18n::dated_label(lang, Key::Added)) " " rel_time(lang: lang, stamp: stamp) | ||
| 1057 | + } | ||
| 1058 | + (sep) | ||
| 1059 | + if let Some(stamp) = used { | ||
| 1060 | + (i18n::dated_label(lang, Key::LastUsed)) " " rel_time(lang: lang, stamp: stamp) | ||
| 1061 | + } | ||
| 1062 | + }) | ||
| 1063 | +} | ||
| 1064 | + | ||
| 1000 | /// First seven characters of an object id. | 1065 | /// First seven characters of an object id. |
| 1001 | pub fn short_oid(oid: &str) -> &str { | 1066 | pub fn short_oid(oid: &str) -> &str { |
| 1002 | oid.get(..7).unwrap_or(oid) | 1067 | oid.get(..7).unwrap_or(oid) |
| @@ -1297,7 +1362,7 @@ mod tests { | |||
| 1297 | assert_eq!(relative_time(Lang::En, 0, 120), "2 minutes ago"); | 1362 | assert_eq!(relative_time(Lang::En, 0, 120), "2 minutes ago"); |
| 1298 | assert_eq!(relative_time(Lang::En, 0, 3_600), "1 hour ago"); | 1363 | assert_eq!(relative_time(Lang::En, 0, 3_600), "1 hour ago"); |
| 1299 | assert_eq!(relative_time(Lang::En, 0, 2 * 86_400), "2 days ago"); | 1364 | assert_eq!(relative_time(Lang::En, 0, 2 * 86_400), "2 days ago"); |
| 1300 | - assert_eq!(relative_time(Lang::En, 10, 0), "just now"); | 1365 | + assert_eq!(relative_time(Lang::En, 0, 10), "just now"); |
| 1301 | assert_eq!(relative_time(Lang::En, 0, 30 * 86_400), "1 month ago"); | 1366 | assert_eq!(relative_time(Lang::En, 0, 30 * 86_400), "1 month ago"); |
| 1302 | assert_eq!(relative_time(Lang::En, 0, 365 * 86_400), "1 year ago"); | 1367 | assert_eq!(relative_time(Lang::En, 0, 365 * 86_400), "1 year ago"); |
| 1303 | assert_eq!(relative_time(Lang::En, 0, 2 * 365 * 86_400), "2 years ago"); | 1368 | assert_eq!(relative_time(Lang::En, 0, 2 * 365 * 86_400), "2 years ago"); |
| @@ -1312,7 +1377,9 @@ mod tests { | |||
| 1312 | assert_eq!( | 1377 | assert_eq!( |
| 1313 | rel_words(Lang::En), | 1378 | rel_words(Lang::En), |
| 1314 | "just now|{n} minute ago|{n} minutes ago|{n} hour ago|{n} hours ago|{n} day ago|\ | 1379 | "just now|{n} minute ago|{n} minutes ago|{n} hour ago|{n} hours ago|{n} day ago|\ |
| 1315 | - {n} days ago|{n} month ago|{n} months ago|{n} year ago|{n} years ago" | 1380 | + {n} days ago|{n} month ago|{n} months ago|{n} year ago|{n} years ago|\ |
| 1381 | + in {n} minute|in {n} minutes|in {n} hour|in {n} hours|in {n} day|in {n} days|\ | ||
| 1382 | + in {n} month|in {n} months|in {n} year|in {n} years" | ||
| 1316 | ); | 1383 | ); |
| 1317 | assert_eq!(rel_words(Lang::Tr).split('|').nth(4), Some("{n} saat önce")); | 1384 | assert_eq!(rel_words(Lang::Tr).split('|').nth(4), Some("{n} saat önce")); |
| 1318 | } | 1385 | } |