diff --git a/crates/izlek-core/src/board.rs b/crates/izlek-core/src/board.rs index 70c8a82..47817d5 100644 --- a/crates/izlek-core/src/board.rs +++ b/crates/izlek-core/src/board.rs @@ -300,6 +300,22 @@ impl BoardView { .retain(|card| card.tag.as_ref().is_some_and(|tag| tag.id == tag_id)); } } + + /// Keeps only the cards carrying `assignee` — a member id — or, for the + /// literal `none`, only the cards carrying nobody. `None` (no filter) + /// leaves the board alone, riding the same narrowing pass as + /// [`BoardView::searching`]. + pub fn assigned(&mut self, assignee: Option<&str>) { + let Some(assignee) = assignee else { + return; + }; + for column in &mut self.columns { + column.cards.retain(|card| match assignee { + "none" => card.assignees.is_empty(), + id => card.assignees.iter().any(|person| &person.id == id), + }); + } + } } /// Folds text for search: Turkish letters collapse to their ASCII stems diff --git a/crates/izlek-core/src/store/mod.rs b/crates/izlek-core/src/store/mod.rs index 899547b..7bb70b2 100644 --- a/crates/izlek-core/src/store/mod.rs +++ b/crates/izlek-core/src/store/mod.rs @@ -1367,26 +1367,6 @@ pub trait Store: BoardReads + DetailReads + 'static { cursor: Option<&FeedCursor>, ) -> Result; - /// Puts `user_id` on a task's watchers. Idempotent: watching twice is - /// watching once. - async fn watch_task(&self, task_id: &str, user_id: &str) -> Result<()>; - - /// Takes `user_id` off a task's watchers. Absent watch, absent row: no - /// error. - async fn unwatch_task(&self, task_id: &str, user_id: &str) -> Result<()>; - - /// The "what changed for me" feed: activity events on the tasks the user - /// watches, plus events that name them (`subject_id` — an assignment - /// outlives the watch it created), minus the user's own actions. Newest - /// first, capped at `limit`. - async fn feed_for_user(&self, user_id: &str, limit: u32) -> Result>; - - /// How many feed lines have landed since the user last read the feed. - async fn count_feed_unseen(&self, user_id: &str) -> Result; - - /// Reads the feed to `at`: the unseen count resets, the history stays. - async fn mark_feed_seen(&self, user_id: &str, at: OffsetDateTime) -> Result<()>; - // -- who gets mailed --------------------------------------------------- /// The people a task points at. Viewers cannot be assigned, so none appear. diff --git a/crates/izlek-core/src/store/reconcile.rs b/crates/izlek-core/src/store/reconcile.rs index bcfb343..0808487 100644 --- a/crates/izlek-core/src/store/reconcile.rs +++ b/crates/izlek-core/src/store/reconcile.rs @@ -737,23 +737,6 @@ async fn copy_data(old_conn: &Connection, new_conn: &Connection, path: &str) -> })?; } - // Backfills the watches the feed reads: a watch for every task somebody - // created, was assigned, or commented on, including all history. This - // runs exactly once per database — the rebuild only happens on a schema - // mismatch — so watches removed by an unassign after the deploy stand, - // and the pass cannot fight the transactional auto-watch in the store's - // own writes: nothing is being served while the rebuild runs. - new_conn - .execute( - "INSERT OR IGNORE INTO task_watcher (task_id, user_id) \ - SELECT t.id, t.created_by FROM task t WHERE t.created_by IS NOT NULL \ - UNION SELECT task_id, user_id FROM task_assignee \ - UNION SELECT task_id, author_id FROM comment", - (), - ) - .await - .map_err(|e| StoreError::Backend(format!("seed watches: {e}")))?; - new_conn .execute("DETACH DATABASE old", ()) .await @@ -835,30 +818,11 @@ async fn verify(old_conn: &Connection, new_conn: &Connection) -> Result<()> { for table in tables { let old_count = count_rows(old_conn, table).await?; let new_count = count_rows(new_conn, table).await?; - // task_watcher: the rebuild backfills watches from history — every - // task somebody created, was assigned, or commented on — so the new - // count is that derived set (every old watch is in it by - // construction), not the old count. - let expected = if table == "task_watcher" { - Some(count_rows(new_conn, "(SELECT t.id, t.created_by AS user_id FROM task t WHERE t.created_by IS NOT NULL UNION SELECT task_id, user_id FROM task_assignee UNION SELECT task_id, author_id FROM comment)").await?) - } else { - None - }; - match expected { - Some(want) if new_count != want => { - return Err(StoreError::Backend(format!( - "task_watcher count {} does not match the backfilled set {}", - new_count, want - ))); - } - Some(_) => {} - None if old_count != new_count => { - return Err(StoreError::Backend(format!( - "row count mismatch for {}: old {} new {}", - table, old_count, new_count - ))); - } - None => {} + if old_count != new_count { + return Err(StoreError::Backend(format!( + "row count mismatch for {}: old {} new {}", + table, old_count, new_count + ))); } } diff --git a/crates/izlek-core/src/store/turso_store.rs b/crates/izlek-core/src/store/turso_store.rs index 6347b92..1aacf06 100644 --- a/crates/izlek-core/src/store/turso_store.rs +++ b/crates/izlek-core/src/store/turso_store.rs @@ -1964,13 +1964,6 @@ impl Store for TursoStore { ], ) .await?; - // The maker watches what they made: its changes concern them - // until they say otherwise. - tx.execute( - "INSERT OR IGNORE INTO task_watcher (task_id, user_id) VALUES (?1, ?2)", - params![id.clone(), new.created_by], - ) - .await?; Ok::<_, turso::Error>(Ok((task_key, position))) } .await; @@ -1997,7 +1990,7 @@ impl Store for TursoStore { }; tx.commit().await.map_err(backend)?; - // Task birth touches the board, the task page and the feed at once. + // Task birth touches the board and the task page at once. let mut topics = vec![ Topic::Board, Topic::Task(id.clone()), @@ -2166,15 +2159,6 @@ impl Store for TursoStore { ) .await .map_err(backend)?; - // Being assigned is being concerned: the assignee watches the task - // until an unassign takes the watch back off. Idempotent, so a - // no-change assign leaves the watch exactly as it is. - tx.execute( - "INSERT OR IGNORE INTO task_watcher (task_id, user_id) VALUES (?1, ?2)", - params![task_id, user_id], - ) - .await - .map_err(backend)?; // A no-change assign changes no facts, so the reminders stand as // they are. let reminded = if n > 0 { @@ -2214,14 +2198,6 @@ impl Store for TursoStore { ) .await .map_err(backend)?; - // Leaving the task takes the watch back off: its changes stop - // concerning the person who left. - tx.execute( - "DELETE FROM task_watcher WHERE task_id = ?1 AND user_id = ?2", - params![task_id, user_id], - ) - .await - .map_err(backend)?; let reminded = if n > 0 { match self.sync_task_reminders(&tx, task_id, OffsetDateTime::now_utc()).await { Ok(reminded) => reminded, @@ -2425,11 +2401,6 @@ impl Store for TursoStore { ], ) .await?; - tx.execute( - "INSERT OR IGNORE INTO task_watcher (task_id, user_id) VALUES (?1, ?2)", - params![task_id, author_id], - ) - .await?; Ok::<_, turso::Error>(()) } .await; @@ -4080,122 +4051,6 @@ impl Store for TursoStore { row.as_ref().map(count_of).unwrap_or(Ok(0)) } - async fn watch_task(&self, task_id: &str, user_id: &str) -> Result<()> { - let conn = self.conn.lock().await; - conn.execute( - "INSERT OR IGNORE INTO task_watcher (task_id, user_id) VALUES (?1, ?2)", - params![task_id, user_id], - ) - .await - .map_err(backend)?; - drop(conn); - self.announce([Topic::Activity]); - Ok(()) - } - - async fn unwatch_task(&self, task_id: &str, user_id: &str) -> Result<()> { - let conn = self.conn.lock().await; - conn.execute( - "DELETE FROM task_watcher WHERE task_id = ?1 AND user_id = ?2", - params![task_id, user_id], - ) - .await - .map_err(backend)?; - drop(conn); - self.announce([Topic::Activity]); - Ok(()) - } - - async fn feed_for_user(&self, user_id: &str, limit: u32) -> Result> { - const SELECT: &str = "SELECT a.id, a.task_id, t.title, u.display_name, a.kind, a.detail, \ - a.created_at, t.task_key FROM activity a \ - JOIN task t ON t.id = a.task_id \ - LEFT JOIN user u ON u.id = a.actor_id"; - // Two ways an event can concern somebody, unioned: it happened on a - // task they watch, or it names them. An event arriving both ways is - // one row — UNION, not UNION ALL — and a person's own actions are - // nobody's news, not even their own (`IS NOT`, so the system's rows - // with no actor still pass). - let conn = self.conn.lock().await; - let sql = format!( - "{SELECT} JOIN task_watcher w ON w.task_id = a.task_id AND w.user_id = ?1 \ - WHERE a.actor_id IS NOT ?2 \ - UNION {SELECT} WHERE a.subject_id = ?3 AND a.actor_id IS NOT ?4 \ - ORDER BY created_at DESC, id DESC LIMIT ?5" - ); - let mut rows = conn - .query( - &sql, - params![user_id, user_id, user_id, user_id, i64::from(limit)], - ) - .await - .map_err(backend)?; - let mut out = Vec::new(); - while let Some(row) = rows.next().await.map_err(backend)? { - out.push(ActivityLine { - id: text(&row, 0)?, - task_id: opt_text(&row, 1)?, - title: opt_text(&row, 2)?, - actor_name: opt_text(&row, 3)?, - kind: ActivityKind::parse(&text(&row, 4)?), - detail: text(&row, 5)?, - at: parse_stamp(&text(&row, 6)?)?, - task_key: opt_text(&row, 7)?, - }); - } - Ok(out) - } - - async fn count_feed_unseen(&self, user_id: &str) -> Result { - const SELECT: &str = "SELECT a.id FROM activity a \ - JOIN task t ON t.id = a.task_id \ - LEFT JOIN user u ON u.id = a.actor_id"; - // Unseen is the same union as the feed, narrowed to rows that landed - // after the reader's marker. A reader who has never visited has no - // marker, and COALESCE with the empty string — which sorts before - // every stamp — reads the whole feed as news. - let conn = self.conn.lock().await; - let sql = format!( - "SELECT COUNT(*) FROM (\ - {SELECT} JOIN task_watcher w ON w.task_id = a.task_id AND w.user_id = ?1 \ - WHERE a.actor_id IS NOT ?2 \ - AND a.created_at > COALESCE((SELECT feed_seen_at FROM user WHERE id = ?3), '') \ - UNION \ - {SELECT} WHERE a.subject_id = ?4 AND a.actor_id IS NOT ?5 \ - AND a.created_at > COALESCE((SELECT feed_seen_at FROM user WHERE id = ?6), ''))" - ); - let mut rows = conn - .query( - &sql, - params![ - user_id, user_id, user_id, user_id, user_id, user_id, - ], - ) - .await - .map_err(backend)?; - let row = rows.next().await.map_err(backend)?; - match row { - Some(row) => { - let n: i64 = row.get(0).map_err(backend)?; - Ok(usize::try_from(n).unwrap_or(0) as u64) - } - None => Ok(0), - } - } - - async fn mark_feed_seen(&self, user_id: &str, at: OffsetDateTime) -> Result<()> { - let conn = self.conn.lock().await; - conn.execute( - "UPDATE user SET feed_seen_at = ?1 WHERE id = ?2", - params![stamp(at)?, user_id], - ) - .await - .map_err(backend)?; - drop(conn); - self.announce([Topic::Activity]); - Ok(()) - } - async fn count_activity_preceding( &self, filter: &ActivityFilter, diff --git a/crates/izlek-core/tests/store.rs b/crates/izlek-core/tests/store.rs index 4073e26..197a2b7 100644 --- a/crates/izlek-core/tests/store.rs +++ b/crates/izlek-core/tests/store.rs @@ -9188,118 +9188,6 @@ async fn reset_asks_are_rate_limited_per_client_and_silenced_per_address() { let _ = std::fs::remove_dir_all(&dir); } -/// Watches and the personal feed: creating, being assigned and commenting -/// each start a watch; an unassign ends it. The feed carries events on -/// watched tasks and events naming the reader, never the reader's own -/// actions; the unseen marker counts what landed since the last read. -#[tokio::test] -async fn the_personal_feed_follows_watches_names_and_the_marker() { - let (dir, store, workspace, admin) = shared().await; - let grace = member(&store, &workspace, "grace@izlek.sh", "Grace").await; - let now = OffsetDateTime::now_utc(); - let board = store.board(&workspace).await.unwrap().unwrap(); - let column_id = column_named(&store, &workspace, "Backlog").await; - let task = store - .create_task(NewTask { - board_id: &board.id, - column_id: &column_id, - parent_id: None, - title: "Feed me", - description: "", - deadline: None, - clock_at: None, - created_by: &admin, - }) - .await - .unwrap() - .row - .id; - - store.assign_task(&task, &grace).await.unwrap(); - - // Creating started Ada's watch; the assignment starts Grace's. Nobody's - // own actions are their own news: Ada's created line is Grace's news, - // and Grace's feed shows it while Ada's stays empty. - let grace_feed = store.feed_for_user(&grace, 50).await.unwrap(); - assert_eq!(grace_feed.len(), 1); - assert_eq!(grace_feed[0].kind, ActivityKind::Created); - assert_eq!(grace_feed[0].actor_name.as_deref(), Some("Ada")); - assert!(store.feed_for_user(&admin, 50).await.unwrap().is_empty()); - assert_eq!(store.count_feed_unseen(&grace).await.unwrap(), 1); - - // Grace's own comment is her own action: it is Ada's news, not hers. - store - .add_comment(&task, &grace, "Looking at it now", now) - .await - .unwrap(); - // Her feed keeps the created line; her own comment never comes back. - let grace_feed = store.feed_for_user(&grace, 50).await.unwrap(); - assert_eq!(grace_feed.len(), 1); - assert_eq!(grace_feed[0].kind, ActivityKind::Created); - let admin_feed = store.feed_for_user(&admin, 50).await.unwrap(); - assert_eq!(admin_feed.len(), 1); - assert_eq!(admin_feed[0].kind, ActivityKind::Commented); - assert_eq!(admin_feed[0].actor_name.as_deref(), Some("Grace")); - assert_eq!(store.count_feed_unseen(&admin).await.unwrap(), 1); - - // Reading the feed is reading it: the marker resets, the history stays. - store - .mark_feed_seen(&admin, now + Duration::seconds(5)) - .await - .unwrap(); - assert_eq!(store.count_feed_unseen(&admin).await.unwrap(), 0); - assert_eq!(store.feed_for_user(&admin, 50).await.unwrap().len(), 1); - - // Grace reads the feed too: her marker takes the created line off her - // unseen count, history included. - store - .mark_feed_seen(&grace, now + Duration::seconds(3)) - .await - .unwrap(); - assert_eq!(store.count_feed_unseen(&grace).await.unwrap(), 0); - assert_eq!(store.feed_for_user(&grace, 50).await.unwrap().len(), 1); - - // Ada's comment lands on a task Grace watches, after her marker: news. - store - .add_comment( - &task, - &admin, - "Thanks — ship it", - now + Duration::seconds(6), - ) - .await - .unwrap(); - assert_eq!(store.count_feed_unseen(&grace).await.unwrap(), 1); - let grace_feed = store.feed_for_user(&grace, 50).await.unwrap(); - assert_eq!(grace_feed.len(), 2, "{grace_feed:?}"); - assert_eq!(grace_feed[0].kind, ActivityKind::Commented); - assert_eq!(grace_feed[0].actor_name.as_deref(), Some("Ada")); - - // An unassign takes the watch back off: history on the task stops - // concerning the person who left. - store.unassign_task(&task, &grace).await.unwrap(); - assert!(store.feed_for_user(&grace, 50).await.unwrap().is_empty()); - assert_eq!(store.count_feed_unseen(&grace).await.unwrap(), 0); - - // An event that NAMES her concerns her with no watch at all — the - // second way into the feed. - store - .record_activity( - &task, - Some(&admin), - Some(&grace), - &ActivityKind::Assigned, - "Grace", - now + Duration::seconds(7), - ) - .await - .unwrap(); - let grace_feed = store.feed_for_user(&grace, 50).await.unwrap(); - assert_eq!(grace_feed.len(), 1); - assert_eq!(grace_feed[0].kind, ActivityKind::Assigned); - - let _ = std::fs::remove_dir_all(&dir); -} #[tokio::test] async fn a_delivered_reminder_writes_the_reminded_event() { let (dir, store, workspace, admin) = shared().await; @@ -9419,108 +9307,60 @@ async fn board_search_folds_turkish_case() { assert_eq!(card.id, is_plan); } -/// The watch backfill rides the reconcile rebuild: a database from before -/// the feed opens with a watch for every task somebody created, was -/// assigned, or commented on — soft-deleted tasks included, history -/// included. The pass can never run twice (it lives behind the fingerprint -/// gate), so an unassign after the deploy keeps its watch off across -/// restarts. +/// The assignee narrowing keeps the cards a member is on and, for `none`, +/// exactly the cards nobody is on — the same pass the tag filter rides. #[tokio::test] -async fn reconcile_backfills_watches_from_history_exactly_once() { - let (dir, path) = live_shaped_database().await; - - // A historical comment — the third watch-worthy fact — on a task that - // already carries creation and assignment history. - { - let db = turso::Builder::new_local(&path).build().await.unwrap(); - let conn = db.connect().unwrap(); - conn.execute( - "INSERT INTO comment (id, task_id, author_id, body, created_at) \ - VALUES ('CM1', 'T2', 'U1', 'on it', '2026-08-30T12:00:01Z')", - (), - ) +async fn board_assigned_narrows_to_a_member_or_to_nobody() { + let (scratch, workspace, admin) = workspace_with_admin().await; + let mate = member(&scratch.store, &workspace, "grace@izlek.sh", "Grace").await; + let assigned_task = add_task( + &scratch.store, + &workspace, + "Backlog", + "Assigned work", + None, + &admin, + ) + .await; + let loose_task = add_task( + &scratch.store, + &workspace, + "Backlog", + "Loose work", + None, + &admin, + ) + .await; + scratch + .store + .assign_task(&assigned_task, &mate) .await .unwrap(); - } - izlek_core::store::reconcile( - &path, - izlek_core::store::ReconcileOptions { - dry_run: false, - yes: true, - auto: true, - }, - ) - .await - .expect("reconcile refused the backfill"); - - // T1: created by U1, assigned to U2. T2: created U1, assigned U2, - // commented U1. T3: created U1, assigned U2. T4 (soft-deleted): created - // U1. Distinct (task, watcher) pairs: 2 + 2 + 2 + 1. - assert_eq!(scalar(&path, "SELECT COUNT(*) FROM task_watcher").await, 7); - assert_eq!( - scalar( - &path, - "SELECT COUNT(*) FROM task_watcher WHERE user_id = 'U2'" - ) - .await, - 3, - "the assignee watches every task they are on" - ); - assert_eq!( - scalar( - &path, - "SELECT COUNT(*) FROM task_watcher WHERE user_id = 'U1'" - ) - .await, - 4, - "the creator watches every task they made, soft-deleted included" - ); + let mut board = izlek_core::board::load(&scratch.store, &workspace) + .await + .unwrap() + .unwrap(); + board.assigned(Some(&mate)); + assert_eq!(board.task_count(), 1); + let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap(); + assert_eq!(card.id, assigned_task); - // The deploy happens; THEN Deniz unassigns — here, the same write the - // store makes. The pass never re-runs (the shape matches now), so the - // watch stays off across a restart and a second reconcile. - { - let db = turso::Builder::new_local(&path).build().await.unwrap(); - let conn = db.connect().unwrap(); - conn.execute( - "DELETE FROM task_watcher WHERE task_id = 'T1' AND user_id = 'U2'", - (), - ) + let mut board = izlek_core::board::load(&scratch.store, &workspace) .await + .unwrap() .unwrap(); - } - izlek_core::store::reconcile( - &path, - izlek_core::store::ReconcileOptions { - dry_run: false, - yes: true, - auto: true, - }, - ) - .await - .unwrap(); - assert_eq!( - scalar( - &path, - "SELECT COUNT(*) FROM task_watcher WHERE task_id = 'T1'" - ) - .await, - 1, - "the unassigned watch was resurrected" - ); - let _store = TursoStore::open(&path).await.unwrap(); - assert_eq!( - scalar( - &path, - "SELECT COUNT(*) FROM task_watcher WHERE task_id = 'T1'" - ) - .await, - 1, - "a restart resurrected the unassigned watch" - ); + board.assigned(Some("none")); + assert_eq!(board.task_count(), 1); + let card = board.columns.iter().flat_map(|c| &c.cards).next().unwrap(); + assert_eq!(card.id, loose_task); - let _ = std::fs::remove_dir_all(&dir); + let mut board = izlek_core::board::load(&scratch.store, &workspace) + .await + .unwrap() + .unwrap(); + board.assigned(None); + assert_eq!(board.task_count(), 2); } // --------------------------------------------------------------------------- diff --git a/crates/izlek-web/src/board.rs b/crates/izlek-web/src/board.rs index c9daef2..f342407 100644 --- a/crates/izlek-web/src/board.rs +++ b/crates/izlek-web/src/board.rs @@ -235,6 +235,16 @@ fn valid_tag(tag: Option<&str>, tags: &[izlek_core::store::Tag]) -> Option, members: &[User]) -> Option { + match assigned { + None | Some("") => None, + Some("none") => Some("none".to_string()), + Some(id) => members.iter().find(|m| m.id == id).map(|m| m.id.clone()), + } +} + /// The `?q=` search: the box's text trimmed, and an empty box is no search /// at all — clearing it restores the whole board. fn searched(query: Option<&str>) -> Option { @@ -261,6 +271,7 @@ async fn board_columns( cx: &Cx, sort: String, tag_filter: Option, + assigned: Option, search: Option, default_tag_id: Option<&str>, ) -> Result { @@ -288,6 +299,7 @@ async fn board_columns( view_data.searching(needle); } view_data.tagged(tag_filter.as_deref()); + view_data.assigned(assigned.as_deref()); for column in &mut view_data.columns { column.column.name = crate::i18n::column_name(lang, &column.column.name); sort_column_cards(&mut column.cards, &sort); @@ -609,6 +621,7 @@ struct BoardQuery { confirm: Option, new: Option, tag: Option, + assigned: Option, q: Option, } @@ -647,15 +660,21 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result { let store = accounts(cx).store().clone(); store.tags(&view_data.board.id).await? }; + let members = { + let store = accounts(cx).store().clone(); + store.users(&user.workspace_id).await? + }; // The whole filter pipeline narrows the board before anything counts or // renders it, so the chips, the columns and the empty state all describe // the same set. let search = searched(query.q.as_deref()); let tag_filter = valid_tag(query.tag.as_deref(), &tags); + let assigned_filter = valid_assigned(query.assigned.as_deref(), &members); if let Some(needle) = &search { view_data.searching(needle); } view_data.tagged(tag_filter.as_deref()); + view_data.assigned(assigned_filter.as_deref()); let today = OffsetDateTime::now_utc().date(); let overdue = view_data.overdue_count(today); let blocked = view_data.blocked_count(); @@ -709,6 +728,7 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result {
+ (t(lang, Key::Project)) + + + (t(lang, Key::Assignee)) + + +
+ (t(lang, Key::Sort)) + (t(lang, Key::Search))
@@ -755,7 +795,7 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result {

(t(lang, Key::NoMatches))

} else {
- (board_columns(cx, sort.clone(), tag_filter.clone(), search.clone(), default_tag_id).await?) + (board_columns(cx, sort.clone(), tag_filter.clone(), assigned_filter.clone(), search.clone(), default_tag_id).await?)
} diff --git a/crates/izlek-web/src/feed.rs b/crates/izlek-web/src/feed.rs deleted file mode 100644 index 0cf19ba..0000000 --- a/crates/izlek-web/src/feed.rs +++ /dev/null @@ -1,113 +0,0 @@ -//! "What changed for me": the events a signed-in person has a stake in. -//! -//! Every role gets it — a Viewer's feed is simply emptier, not hidden. Two -//! things put a line on someone's feed: it happened on a task they watch -//! (making a task, being assigned, commenting each start a watch; an -//! unassign ends it), or it names them. Nobody's own actions come back to -//! them — the store's feed query leaves those off. The watch and marker -//! mechanics live in the store (`feed_for_user`, `count_feed_unseen`, -//! `mark_feed_seen`); this page only reads and renders. -//! -//! Visiting is reading: the page marks the feed seen after fetching its -//! rows, so the badge on the next page anywhere — and on this one, which -//! renders after the mark — reads zero. New events announce on the live -//! channel like every other write, and the shell's refresh morph brings -//! both this page and the topbar badge back up to date. - -use time::OffsetDateTime; -use topcoat::Result; -use topcoat::context::Cx; -use topcoat::router::{error::not_found, page}; -use topcoat::view::view; - -use crate::i18n::{Key, Lang, t}; -use crate::server::{accounts, require_user}; - -/// How many lines one page draws, the same cap the logs page reads by: a -/// read a person can finish, panned inside the shell, never a document -/// growing past the viewport. -const LIMIT: u32 = 50; - -/// One rendered feed line — the same anatomy as the Logs page's activity -/// rows (`log-row`: stamp · actor · sentence · subject), with the subject -/// as the one link. The strings are decided here so the template stays a -/// list of facts rather than a chain of lookups. -struct FeedRow { - key: String, - title: String, - href: String, - actor: String, - sentence: String, - when: String, -} - -/// The person's feed. `/feed`. -#[page("/feed")] -async fn feed_page(cx: &Cx) -> Result { - let user = match require_user(cx).await { - Ok(user) => user, - Err(_) => return Err(not_found().into()), - }; - let lang = Lang::from_code(&user.language); - let store = accounts(cx).store().clone(); - let lines = store.feed_for_user(&user.id, LIMIT).await?; - // The visit is the marker, taken after the rows are read: the badge on - // the next page anywhere reads zero, and this page's own topbar — - // rendered after the mark — agrees with it. - store - .mark_feed_seen(&user.id, OffsetDateTime::now_utc()) - .await?; - let zone = izlek_core::detail::parse_zone(&user.timezone); - - let empty = lines.is_empty(); - let rows: Vec = lines - .iter() - .map(|line| FeedRow { - key: line.task_key.clone().unwrap_or_default(), - title: line.title.clone().unwrap_or_default(), - href: format!("/?task={}", line.task_id.as_deref().unwrap_or_default()), - actor: line - .actor_name - .clone() - .unwrap_or_else(|| t(lang, Key::TheSystem).to_string()), - sentence: crate::logs::activity_sentence(&line.kind, &line.detail, lang), - when: izlek_core::detail::moment_label_in(line.at, zone), - }) - .collect(); - - view! { - cx => -
- (crate::layout::mark(cx).await?) - (crate::layout::topbar_nav(cx, crate::layout::NavPage::Feed, user.role, lang).await?) -
- (crate::layout::user_menu(cx, &crate::detail::Me::from(&user), lang).await?) -
- -
-
-
-

(t(lang, Key::NavFeed))

-
-
-
- for row in rows { -
- (row.when) - (row.actor) - (row.sentence) - - (format!("({})", row.key)) - (row.title) - -
- } -
- if empty { -

(t(lang, Key::FeedEmpty))

- } -
-
-
- } -} diff --git a/crates/izlek-web/src/i18n.rs b/crates/izlek-web/src/i18n.rs index 4992989..e1aeab6 100644 --- a/crates/izlek-web/src/i18n.rs +++ b/crates/izlek-web/src/i18n.rs @@ -375,9 +375,9 @@ pub enum Key { ResetLinkDead, ActResetRequested, ActResetDone, - NavFeed, + Assignee, ActReminded, - FeedEmpty, + Nobody, } /// The lone templated phrase — a name in the middle reads worse as two @@ -1075,10 +1075,10 @@ pub fn t(lang: Lang, key: Key) -> &'static str { (ActResetDone, Tr) => "sıfırlama bağlantısıyla yeni parola aldı", (ActReminded, En) => "sent a reminder mail", (ActReminded, Tr) => "hatırlatma gönderdi", - (NavFeed, En) => "For me", - (NavFeed, Tr) => "Benim için", - (FeedEmpty, En) => "Nothing yet.", - (FeedEmpty, Tr) => "Henüz bir şey yok.", + (Assignee, En) => "Assignee", + (Assignee, Tr) => "Atanan", + (Nobody, En) => "Nobody", + (Nobody, Tr) => "Kimse", } } diff --git a/crates/izlek-web/src/layout.rs b/crates/izlek-web/src/layout.rs index fbd0288..0585164 100644 --- a/crates/izlek-web/src/layout.rs +++ b/crates/izlek-web/src/layout.rs @@ -137,7 +137,6 @@ pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result { #[derive(Clone, Copy, PartialEq)] pub enum NavPage { Board, - Feed, Rules, Logs, Tags, @@ -145,9 +144,8 @@ pub enum NavPage { } impl NavPage { - const ALL: [Self; 6] = [ + const ALL: [Self; 5] = [ Self::Board, - Self::Feed, Self::Rules, Self::Logs, Self::Tags, @@ -157,7 +155,6 @@ impl NavPage { fn href(self) -> &'static str { match self { Self::Board => "/", - Self::Feed => "/feed", Self::Rules => "/rules", Self::Logs => "/logs", Self::Tags => "/tags", @@ -168,7 +165,6 @@ impl NavPage { fn label(self) -> Key { match self { Self::Board => Key::NavBoard, - Self::Feed => Key::NavFeed, Self::Rules => Key::NavMailRules, Self::Logs => Key::NavLogs, Self::Tags => Key::NavTags, @@ -179,19 +175,9 @@ impl NavPage { /// The topbar's page nav, shared by every signed-in page: the pages with the /// current one marked, the admin-only ones (rules, logs, tags) shown only to -/// roles that can administer. The feed link carries the unread count — how -/// many lines have landed since the person last read their feed — as a chip -/// that disappears at zero. Plain ``s — the soft-nav forwarder swaps them +/// roles that can administer. Plain ``s — the soft-nav forwarder swaps them /// like any same-origin link, so `data-hard` stays off. pub async fn topbar_nav(cx: &Cx, active: NavPage, role: izlek_core::Role, lang: Lang) -> Result { - let unread = match current_user(cx).await { - Ok(Some(me)) => crate::server::accounts(cx) - .store() - .count_feed_unseen(&me.id) - .await - .unwrap_or(0), - _ => 0, - }; view! { cx =>