Inbox, dashboard, profiles and explore update live
Browse files at this commit7663f1e831af32108910aa88e2b0e35c7ff4a8a3Parent: c2161c4- feat
- inbox, dashboard, profiles and explore update live
25 changed files +604 -79
- crates/forge-web/src/i18n/code.rs +8 -0
- crates/forge-web/src/live.rs +58 -13
- crates/forge-web/src/notify_hub.rs +5 -3
- crates/forge-web/src/pages/blob.rs +5 -4
- crates/forge-web/src/pages/ci_job.rs +1 -1
- crates/forge-web/src/pages/ci_runs.rs +1 -1
- crates/forge-web/src/pages/code_live.rs +61 -21
- crates/forge-web/src/pages/dashboard.rs +51 -1
- crates/forge-web/src/pages/explore.rs +62 -6
- crates/forge-web/src/pages/fork.rs +2 -0
- crates/forge-web/src/pages/import.rs +4 -1
- crates/forge-web/src/pages/new_repo.rs +4 -1
- crates/forge-web/src/pages/notifications.rs +87 -2
- crates/forge-web/src/pages/profile.rs +70 -2
- crates/forge-web/src/pages/profile_pins.rs +3 -4
- crates/forge-web/src/pages/pull_live.rs +2 -2
- crates/forge-web/src/pages/repo.rs +11 -4
- crates/forge-web/src/pages/repo_ctx.rs +20 -0
- crates/forge-web/src/pages/repo_rename.rs +5 -1
- crates/forge-web/src/pages/repo_settings.rs +5 -1
- crates/forge-web/src/pages/star.rs +3 -0
- crates/forge-web/src/pages/tree.rs +9 -3
- crates/forge-web/src/post_update.rs +6 -0
- crates/forge-web/tests/browse_e2e.rs +105 -5
- docs/architecture.md +16 -3
crates/forge-web/src/i18n/code.rsmodified+8 -0
| @@ -486,6 +486,14 @@ pub fn watching_count(lang: Lang, watchers: u64) -> String { | |||
| 486 | } | 486 | } |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | +/// `<n> forks` in English, `<n> çatal` in Turkish. | ||
| 490 | +pub fn forks_count(lang: Lang, forks: u64) -> String { | ||
| 491 | + match lang { | ||
| 492 | + Lang::En => format!("{forks} forks"), | ||
| 493 | + Lang::Tr => format!("{forks} çatal"), | ||
| 494 | + } | ||
| 495 | +} | ||
| 496 | + | ||
| 489 | /// The mirror status after a successful sync. | 497 | /// The mirror status after a successful sync. |
| 490 | pub fn mirror_synced(lang: Lang, at: &str) -> String { | 498 | pub fn mirror_synced(lang: Lang, at: &str) -> String { |
| 491 | match lang { | 499 | match lang { |
crates/forge-web/src/live.rsmodified+58 -13
| @@ -9,7 +9,7 @@ | |||
| 9 | //! 1. Add a variant to [`Topic`], keyed by what the page is about (a repo id, a user id, ...). | 9 | //! 1. Add a variant to [`Topic`], keyed by what the page is about (a repo id, a user id, ...). |
| 10 | //! 2. Call `state.live.bump(&Topic::Variant(..))` after the write that changes the page. | 10 | //! 2. Call `state.live.bump(&Topic::Variant(..))` after the write that changes the page. |
| 11 | //! 3. In the page's own route (its auth check first), return | 11 | //! 3. In the page's own route (its auth check first), return |
| 12 | -//! `live::stream_changes(cx, &state.live, &topic, read)`. `read` returns a short fingerprint | 12 | +//! `live::stream_changes(cx, &state.live, &[topics], read)`. `read` returns a short fingerprint |
| 13 | //! of the state the page shows; a `changed` event is sent only when it differs from the last | 13 | //! of the state the page shows; a `changed` event is sent only when it differs from the last |
| 14 | //! one, so a bump that changes nothing visible sends nothing. | 14 | //! one, so a bump that changes nothing visible sends nothing. |
| 15 | //! 4. Render `data-live="<the route URL>"` on the page's element that the client follows. | 15 | //! 4. Render `data-live="<the route URL>"` on the page's element that the client follows. |
| @@ -17,6 +17,8 @@ | |||
| 17 | //! A page whose state is cheap to compare can use `stream_changes` (the fingerprint). A page | 17 | //! A page whose state is cheap to compare can use `stream_changes` (the fingerprint). A page |
| 18 | //! whose every bump is a visible change (the issue pages) uses [`stream_wakes`] instead: one | 18 | //! whose every bump is a visible change (the issue pages) uses [`stream_wakes`] instead: one |
| 19 | //! `changed` per wake, several bumps in a row coalesced into one. | 19 | //! `changed` per wake, several bumps in a row coalesced into one. |
| 20 | +//! A user's topics are keyed by the user id and streamed only to that user: the route takes the | ||
| 21 | +//! viewer from the session, never from the URL, so one user cannot follow another user's inbox. | ||
| 20 | //! | 22 | //! |
| 21 | //! The hub is in-process only, like [`crate::notify_hub::NotifyHub`]. [`crate::ci::CiLive`] keeps | 23 | //! The hub is in-process only, like [`crate::notify_hub::NotifyHub`]. [`crate::ci::CiLive`] keeps |
| 22 | //! its own counters for CI and is not on this hub. | 24 | //! its own counters for CI and is not on this hub. |
| @@ -25,6 +27,7 @@ use std::collections::HashMap; | |||
| 25 | use std::future::Future; | 27 | use std::future::Future; |
| 26 | use std::sync::{Mutex, MutexGuard, PoisonError}; | 28 | use std::sync::{Mutex, MutexGuard, PoisonError}; |
| 27 | 29 | ||
| 30 | +use futures_util::future::select_all; | ||
| 28 | use futures_util::stream; | 31 | use futures_util::stream; |
| 29 | use tokio::sync::watch; | 32 | use tokio::sync::watch; |
| 30 | use topcoat::Result; | 33 | use topcoat::Result; |
| @@ -50,6 +53,16 @@ pub enum Topic { | |||
| 50 | /// One pull request, its conversation, commits and files. Keyed by the pull's issue id. | 53 | /// One pull request, its conversation, commits and files. Keyed by the pull's issue id. |
| 51 | /// Bumped by [`crate::pages::pull_live`]. | 54 | /// Bumped by [`crate::pages::pull_live`]. |
| 52 | Pull(String), | 55 | Pull(String), |
| 56 | + /// A repo's own state that its header shows: stars, watchers, forks, and its name and | ||
| 57 | + /// description. Keyed by repo id. | ||
| 58 | + Repo(String), | ||
| 59 | + /// A user's repo listing, pins and contribution calendar. Keyed by user id (an organization | ||
| 60 | + /// is a user too). | ||
| 61 | + User(String), | ||
| 62 | + /// A user's inbox: a notification was added, read or marked read. Keyed by user id. | ||
| 63 | + Inbox(String), | ||
| 64 | + /// The public repo listing: a public repo was added, changed, or starred. Global. | ||
| 65 | + Explore, | ||
| 53 | } | 66 | } |
| 54 | 67 | ||
| 55 | /// The open topics, each with the counter its subscribers wait on. | 68 | /// The open topics, each with the counter its subscribers wait on. |
| @@ -99,11 +112,20 @@ impl LiveHub { | |||
| 99 | self.bump(&Topic::RepoIssues(repo_id.to_owned())); | 112 | self.bump(&Topic::RepoIssues(repo_id.to_owned())); |
| 100 | self.bump(&Topic::Issue(issue_id.to_owned())); | 113 | self.bump(&Topic::Issue(issue_id.to_owned())); |
| 101 | } | 114 | } |
| 115 | + | ||
| 116 | + /// A repo changed in a way its owner's pages, the explore list and its own header show: it | ||
| 117 | + /// was created, renamed, moved, re-described, starred, watched or forked. Call it once per | ||
| 118 | + /// owner whose listing changed (a transfer has two). | ||
| 119 | + pub fn bump_repo(&self, owner_id: &str, repo_id: &str) { | ||
| 120 | + self.bump(&Topic::User(owner_id.to_owned())); | ||
| 121 | + self.bump(&Topic::Explore); | ||
| 122 | + self.bump(&Topic::Repo(repo_id.to_owned())); } | ||
| 102 | } | 123 | } |
| 103 | 124 | ||
| 104 | -/// The state a stream follows between wakes: the fingerprint last sent or seen. | 125 | +/// The state a stream follows between wakes: the receivers of its topics, the read, and the |
| 126 | +/// fingerprint last sent or seen. | ||
| 105 | struct Follow<F> { | 127 | struct Follow<F> { |
| 106 | - wake: watch::Receiver<u64>, | 128 | + wakes: Vec<watch::Receiver<u64>>, |
| 107 | read: F, | 129 | read: F, |
| 108 | last: String, | 130 | last: String, |
| 109 | } | 131 | } |
| @@ -113,29 +135,34 @@ fn changed_event() -> Result<Event> { | |||
| 113 | Ok(Event::new().event("changed").data("1")) | 135 | Ok(Event::new().event("changed").data("1")) |
| 114 | } | 136 | } |
| 115 | 137 | ||
| 138 | +/// Waits until one of `wakes` is bumped. False when a topic is gone, which ends the stream. | ||
| 139 | +async fn wait_any(wakes: &mut [watch::Receiver<u64>]) -> bool { | ||
| 140 | + let waits = wakes.iter_mut().map(|rx| Box::pin(rx.changed())); | ||
| 141 | + let (woken, _, _) = select_all(waits).await; | ||
| 142 | + woken.is_ok() | ||
| 143 | +} | ||
| 144 | + | ||
| 116 | /// The response of a live stream for any of `topics`. It sends `changed` after each wake, with no | 145 | /// The response of a live stream for any of `topics`. It sends `changed` after each wake, with no |
| 117 | /// fingerprint: the caller bumps only after a write that changes the page. Nothing is sent on | 146 | /// fingerprint: the caller bumps only after a write that changes the page. Nothing is sent on |
| 118 | /// connect. The stream ends when a topic is gone, which cannot happen while the stream holds it. | 147 | /// connect. The stream ends when a topic is gone, which cannot happen while the stream holds it. |
| 119 | pub fn stream_wakes(cx: &Cx, hub: &LiveHub, topics: &[Topic]) -> Result<Response> { | 148 | pub fn stream_wakes(cx: &Cx, hub: &LiveHub, topics: &[Topic]) -> Result<Response> { |
| 120 | let wakes: Vec<watch::Receiver<u64>> = topics.iter().map(|t| hub.subscribe(t)).collect(); | 149 | let wakes: Vec<watch::Receiver<u64>> = topics.iter().map(|t| hub.subscribe(t)).collect(); |
| 121 | let events = stream::unfold(wakes, |mut wakes| async move { | 150 | let events = stream::unfold(wakes, |mut wakes| async move { |
| 122 | - // The futures of the topics not woken are dropped with this statement. | 151 | + if !wait_any(&mut wakes).await { |
| 123 | - let (woken, _, _) = | 152 | + return None; |
| 124 | - futures_util::future::select_all(wakes.iter_mut().map(|wake| Box::pin(wake.changed()))) | 153 | + } |
| 125 | - .await; | ||
| 126 | - woken.ok()?; | ||
| 127 | Some((changed_event(), wakes)) | 154 | Some((changed_event(), wakes)) |
| 128 | }); | 155 | }); |
| 129 | events_response(cx, events) | 156 | events_response(cx, events) |
| 130 | } | 157 | } |
| 131 | 158 | ||
| 132 | -/// The response of a live stream for `topic`. It sends `changed` after each wake whose | 159 | +/// The response of a live stream for `topics`. It sends `changed` after each wake whose |
| 133 | /// fingerprint differs from the last one. Nothing is sent on connect: the page already shows the | 160 | /// fingerprint differs from the last one. Nothing is sent on connect: the page already shows the |
| 134 | /// state the first read saw. The stream ends if the read fails. | 161 | /// state the first read saw. The stream ends if the read fails. |
| 135 | pub async fn stream_changes<F, Fut>( | 162 | pub async fn stream_changes<F, Fut>( |
| 136 | cx: &Cx, | 163 | cx: &Cx, |
| 137 | hub: &LiveHub, | 164 | hub: &LiveHub, |
| 138 | - topic: &Topic, | 165 | + topics: &[Topic], |
| 139 | read: F, | 166 | read: F, |
| 140 | ) -> Result<Response> | 167 | ) -> Result<Response> |
| 141 | where | 168 | where |
| @@ -143,11 +170,13 @@ where | |||
| 143 | Fut: Future<Output = Result<String>> + Send, | 170 | Fut: Future<Output = Result<String>> + Send, |
| 144 | { | 171 | { |
| 145 | // Subscribed before the first read, so a change in between wakes the stream. | 172 | // Subscribed before the first read, so a change in between wakes the stream. |
| 146 | - let wake = hub.subscribe(topic); | 173 | + let wakes = topics.iter().map(|topic| hub.subscribe(topic)).collect(); |
| 147 | let last = read().await?; | 174 | let last = read().await?; |
| 148 | - let events = stream::unfold(Follow { wake, read, last }, |mut follow| async move { | 175 | + let events = stream::unfold(Follow { wakes, read, last }, |mut follow| async move { |
| 149 | loop { | 176 | loop { |
| 150 | - follow.wake.changed().await.ok()?; | 177 | + if !wait_any(&mut follow.wakes).await { |
| 178 | + return None; | ||
| 179 | + } | ||
| 151 | let now = match (follow.read)().await { | 180 | let now = match (follow.read)().await { |
| 152 | Ok(now) => now, | 181 | Ok(now) => now, |
| 153 | Err(e) => { | 182 | Err(e) => { |
| @@ -198,4 +227,20 @@ mod tests { | |||
| 198 | hub.bump(&topic); | 227 | hub.bump(&topic); |
| 199 | assert!(hub.topics().is_empty()); | 228 | assert!(hub.topics().is_empty()); |
| 200 | } | 229 | } |
| 230 | + | ||
| 231 | + #[tokio::test] | ||
| 232 | + async fn bump_repo_wakes_the_owner_the_explore_list_and_the_repo() { | ||
| 233 | + let hub = LiveHub::default(); | ||
| 234 | + let owner = hub.subscribe(&Topic::User("owner".to_owned())); | ||
| 235 | + let explore = hub.subscribe(&Topic::Explore); | ||
| 236 | + let repo = hub.subscribe(&Topic::Repo("repo".to_owned())); | ||
| 237 | + let other = hub.subscribe(&Topic::User("someone".to_owned())); | ||
| 238 | + | ||
| 239 | + hub.bump_repo("owner", "repo"); | ||
| 240 | + | ||
| 241 | + assert!(owner.has_changed().expect("open")); | ||
| 242 | + assert!(explore.has_changed().expect("open")); | ||
| 243 | + assert!(repo.has_changed().expect("open")); | ||
| 244 | + assert!(!other.has_changed().expect("open")); | ||
| 245 | + } | ||
| 201 | } | 246 | } |
crates/forge-web/src/notify_hub.rsmodified+5 -3
| @@ -10,6 +10,7 @@ use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; | |||
| 10 | 10 | ||
| 11 | use tokio::sync::watch; | 11 | use tokio::sync::watch; |
| 12 | 12 | ||
| 13 | +use crate::live::Topic; | ||
| 13 | use crate::state::AppState; | 14 | use crate::state::AppState; |
| 14 | 15 | ||
| 15 | /// The users with an open stream, each with the channel that carries its unread count. | 16 | /// The users with an open stream, each with the channel that carries its unread count. |
| @@ -123,10 +124,11 @@ impl Drop for Subscription { | |||
| 123 | } | 124 | } |
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | -/// Publishes `user_id`'s current unread count to that user's open streams. Call it after a write | 127 | +/// Publishes `user_id`'s current unread count to that user's open streams, and wakes the inbox |
| 127 | -/// that changes the inbox. Skips the count query when nobody is listening. Never fails: problems | 128 | +/// page's live stream. Call it after a write that changes the inbox. Skips the count query when |
| 128 | -/// are logged. | 129 | +/// nobody is listening. Never fails: problems are logged. |
| 129 | pub async fn publish_unread(state: &AppState, user_id: &str) { | 130 | pub async fn publish_unread(state: &AppState, user_id: &str) { |
| 131 | + state.live.bump(&Topic::Inbox(user_id.to_owned())); | ||
| 130 | if !state.notify_hub.is_watched(user_id) { | 132 | if !state.notify_hub.is_watched(user_id) { |
| 131 | return; | 133 | return; |
| 132 | } | 134 | } |
crates/forge-web/src/pages/blob.rsmodified+5 -4
| @@ -14,7 +14,7 @@ use crate::i18n::code::{self as g, K}; | |||
| 14 | use crate::i18n::{self}; | 14 | use crate::i18n::{self}; |
| 15 | use crate::lfs::has_object; | 15 | use crate::lfs::has_object; |
| 16 | use crate::lfs_pointer; | 16 | use crate::lfs_pointer; |
| 17 | -use crate::pages::code_live::live_url; | 17 | +use crate::pages::code_live::{follows_branch, live_url}; |
| 18 | use crate::pages::finder::file_finder; | 18 | use crate::pages::finder::file_finder; |
| 19 | use crate::pages::media::media_url; | 19 | use crate::pages::media::media_url; |
| 20 | use crate::pages::refs::load_refs; | 20 | use crate::pages::refs::load_refs; |
| @@ -270,12 +270,13 @@ async fn blob_page(cx: &Cx) -> Result<impl View> { | |||
| 270 | let download_href = lfs_href.clone().unwrap_or_else(|| raw.clone()); | 270 | let download_href = lfs_href.clone().unwrap_or_else(|| raw.clone()); |
| 271 | 271 | ||
| 272 | let refs = load_refs(ctx.path.clone()).await?; | 272 | let refs = load_refs(ctx.path.clone()).await?; |
| 273 | - let live = live_url(&repo.owner_name, &repo.name, &refs, &ref_name); | 273 | + let follows = follows_branch(&refs, &ref_name); |
| 274 | - let header = ctx.head(state, "code").await?; | 274 | + let mut header = ctx.head(state, "code").await?; |
| 275 | + header.live = live_url(&repo.owner_name, &repo.name, &refs, &ref_name); | ||
| 275 | Ok(view! { | 276 | Ok(view! { |
| 276 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), | 277 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 277 | repo_head(head: header) | 278 | repo_head(head: header) |
| 278 | - <div class="browse-bar" data-live=(live.as_deref()) data-live-code=(live.is_some().then_some("true")) data-live-gone=(g::t(lang, K::LivePathGone))> | 279 | + <div class="browse-bar" data-live-code=(follows.then_some("true")) data-live-gone=(g::t(lang, K::LivePathGone))> |
| 279 | breadcrumb(lang: lang, crumbs: crumbs) | 280 | breadcrumb(lang: lang, crumbs: crumbs) |
| 280 | file_finder(lang: lang, owner: finder_owner, repo: finder_repo, ref_name: finder_ref) | 281 | file_finder(lang: lang, owner: finder_owner, repo: finder_repo, ref_name: finder_ref) |
| 281 | </div> | 282 | </div> |
crates/forge-web/src/pages/ci_job.rsmodified+1 -1
| @@ -297,7 +297,7 @@ async fn job_body( | |||
| 297 | live: Option<String>, | 297 | live: Option<String>, |
| 298 | ) -> Result<impl View> { | 298 | ) -> Result<impl View> { |
| 299 | Ok(view! { | 299 | Ok(view! { |
| 300 | - repo_head(head: head) | 300 | + repo_head(head: RepoHead { live: String::new(), ..head }) |
| 301 | <div data-live=(live.as_deref()) data-live-state=(job.status.as_str())> | 301 | <div data-live=(live.as_deref()) data-live-state=(job.status.as_str())> |
| 302 | <p class="muted small"><a href=(job.run_href.as_str())>(g::t(lang, K::RunNumber)) (job.run_number)</a></p> | 302 | <p class="muted small"><a href=(job.run_href.as_str())>(g::t(lang, K::RunNumber)) (job.run_number)</a></p> |
| 303 | <section class="card"> | 303 | <section class="card"> |
crates/forge-web/src/pages/ci_runs.rsmodified+1 -1
| @@ -1590,7 +1590,7 @@ async fn runs_body( | |||
| 1590 | } = list; | 1590 | } = list; |
| 1591 | let (fm, fs) = duration_templates(lang); | 1591 | let (fm, fs) = duration_templates(lang); |
| 1592 | Ok(view! { | 1592 | Ok(view! { |
| 1593 | - repo_head(head: head) | 1593 | + repo_head(head: RepoHead { live: String::new(), ..head }) |
| 1594 | if let Some((text, is_error)) = notice { | 1594 | if let Some((text, is_error)) = notice { |
| 1595 | if is_error { | 1595 | if is_error { |
| 1596 | alert(message: text) | 1596 | alert(message: text) |
crates/forge-web/src/pages/code_live.rsmodified+61 -21
| @@ -1,10 +1,14 @@ | |||
| 1 | -//! Live stream of the code view. A tree or blob page of a branch, and the repo home, render | 1 | +//! Live stream of a repo's pages, at `/{owner}/{repo}/events`. The repo header renders `data-live` |
| 2 | -//! `data-live` with the URL of this stream. It sends `changed` when the branch moves, or when a | 2 | +//! with this URL on every repo page (see `repo::repo_head`). A code view adds its branch to the |
| 3 | -//! branch or tag is created or deleted (the ref selector and the branch list depend on that). | 3 | +//! URL. The stream sends `changed` when the header changes: stars, watchers, forks, or the repo's |
| 4 | -//! Moves of other refs send nothing. Commits and tags are not followed: they do not move. | 4 | +//! name, description or visibility. On a code view of a branch it also sends `changed` when the |
| 5 | +//! branch moves, or when a branch or tag is created or deleted (the ref selector and the branch | ||
| 6 | +//! list depend on that). Moves of other refs send nothing. Commits and tags are not followed: they | ||
| 7 | +//! do not move. | ||
| 5 | 8 | ||
| 6 | use std::path::PathBuf; | 9 | use std::path::PathBuf; |
| 7 | 10 | ||
| 11 | +use forge_core::Visibility; | ||
| 8 | use forge_git::browse::{RefInfo, RefKind}; | 12 | use forge_git::browse::{RefInfo, RefKind}; |
| 9 | use topcoat::Result; | 13 | use topcoat::Result; |
| 10 | use topcoat::context::{Cx, app_context}; | 14 | use topcoat::context::{Cx, app_context}; |
| @@ -14,7 +18,7 @@ use topcoat::router::{path_param, query_params, route}; | |||
| 14 | use crate::auth::percent_encode; | 18 | use crate::auth::percent_encode; |
| 15 | use crate::live::{Topic, stream_changes}; | 19 | use crate::live::{Topic, stream_changes}; |
| 16 | use crate::pages::refs::load_refs; | 20 | use crate::pages::refs::load_refs; |
| 17 | -use crate::pages::repo_ctx::load_repo; | 21 | +use crate::pages::repo_ctx::{fork_count, load_repo}; |
| 18 | use crate::state::AppState; | 22 | use crate::state::AppState; |
| 19 | 23 | ||
| 20 | path_param!(owner); | 24 | path_param!(owner); |
| @@ -25,17 +29,22 @@ struct LiveQuery { | |||
| 25 | ref_name: Option<String>, | 29 | ref_name: Option<String>, |
| 26 | } | 30 | } |
| 27 | 31 | ||
| 28 | -/// The stream URL of a code view of `ref_name`, or None when the ref is not a branch. | 32 | +/// Whether a code view of `ref_name` follows the branch: the ref is a branch of the repo. |
| 29 | -pub fn live_url(owner: &str, repo: &str, refs: &[RefInfo], ref_name: &str) -> Option<String> { | 33 | +pub fn follows_branch(refs: &[RefInfo], ref_name: &str) -> bool { |
| 30 | - let branch = refs | 34 | + refs.iter() |
| 31 | - .iter() | 35 | + .any(|r| r.kind == RefKind::Branch && r.name == ref_name) |
| 32 | - .any(|r| r.kind == RefKind::Branch && r.name == ref_name); | 36 | +} |
| 33 | - branch.then(|| { | 37 | + |
| 38 | +/// The stream URL of a repo page. A code view of a branch adds the branch to it. | ||
| 39 | +pub fn live_url(owner: &str, repo: &str, refs: &[RefInfo], ref_name: &str) -> String { | ||
| 40 | + if follows_branch(refs, ref_name) { | ||
| 34 | format!( | 41 | format!( |
| 35 | - "/{owner}/{repo}/code/events?ref_name={}", | 42 | + "/{owner}/{repo}/events?ref_name={}", |
| 36 | percent_encode(ref_name) | 43 | percent_encode(ref_name) |
| 37 | ) | 44 | ) |
| 38 | - }) | 45 | + } else { |
| 46 | + format!("/{owner}/{repo}/events") | ||
| 47 | + } | ||
| 39 | } | 48 | } |
| 40 | 49 | ||
| 41 | /// The state the code view shows: every branch and tag name, and the commit `branch` points at. | 50 | /// The state the code view shows: every branch and tag name, and the commit `branch` points at. |
| @@ -54,10 +63,26 @@ async fn refs_fingerprint(path: PathBuf, branch: String) -> Result<String> { | |||
| 54 | Ok(format!("{}\n{at}", names.join("\n"))) | 63 | Ok(format!("{}\n{at}", names.join("\n"))) |
| 55 | } | 64 | } |
| 56 | 65 | ||
| 57 | -/// The code view's change stream. Auth is the repo read check of the page: a viewer who cannot | 66 | +/// The state the repo header shows. A repo that is gone reads as empty, which ends nothing: the |
| 58 | -/// read the repo gets the same 404 as the page. | 67 | +/// stream then sends `changed` once and the page's own re-read shows the 404. |
| 59 | -#[route(GET "/{owner}/{repo}/code/events")] | 68 | +async fn header_fingerprint(state: &AppState, repo_id: &str) -> Result<String> { |
| 60 | -async fn code_events(cx: &Cx) -> Result<Response> { | 69 | + let Some(repo) = state.store.repo_by_id(repo_id).await? else { |
| 70 | + return Ok(String::new()); | ||
| 71 | + }; | ||
| 72 | + let stars = state.store.star_count(repo_id).await?; | ||
| 73 | + let watchers = state.store.watchers(repo_id).await?.len(); | ||
| 74 | + let forks = fork_count(state, repo_id).await?; | ||
| 75 | + let public = repo.visibility == Visibility::Public; | ||
| 76 | + Ok(format!( | ||
| 77 | + "{}\n{}\n{public}\n{}\n{stars} {watchers} {forks}", | ||
| 78 | + repo.owner_name, repo.name, repo.description | ||
| 79 | + )) | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +/// The repo's live stream. Auth is the repo read check of the page: a viewer who cannot read the | ||
| 83 | +/// repo gets the same 404 as the page. | ||
| 84 | +#[route(GET "/{owner}/{repo}/events")] | ||
| 85 | +async fn repo_events(cx: &Cx) -> Result<Response> { | ||
| 61 | let owner = path_param::<Owner>(cx); | 86 | let owner = path_param::<Owner>(cx); |
| 62 | let name = path_param::<Repo>(cx); | 87 | let name = path_param::<Repo>(cx); |
| 63 | let branch = query_params::<LiveQuery>(cx)? | 88 | let branch = query_params::<LiveQuery>(cx)? |
| @@ -65,11 +90,26 @@ async fn code_events(cx: &Cx) -> Result<Response> { | |||
| 65 | .clone() | 90 | .clone() |
| 66 | .unwrap_or_default(); | 91 | .unwrap_or_default(); |
| 67 | let ctx = load_repo(cx, owner, name).await?; | 92 | let ctx = load_repo(cx, owner, name).await?; |
| 68 | - let state = app_context::<AppState>(cx); | 93 | + let state = app_context::<AppState>(cx).clone(); |
| 69 | - let topic = Topic::RepoRefs(ctx.repo.id.clone()); | 94 | + let mut topics = vec![Topic::Repo(ctx.repo.id.clone())]; |
| 95 | + if !branch.is_empty() { | ||
| 96 | + topics.push(Topic::RepoRefs(ctx.repo.id.clone())); | ||
| 97 | + } | ||
| 70 | let path = ctx.path.clone(); | 98 | let path = ctx.path.clone(); |
| 71 | - stream_changes(cx, &state.live, &topic, move || { | 99 | + let repo_id = ctx.repo.id.clone(); |
| 72 | - refs_fingerprint(path.clone(), branch.clone()) | 100 | + stream_changes(cx, &state.live.clone(), &topics, move || { |
| 101 | + let state = state.clone(); | ||
| 102 | + let repo_id = repo_id.clone(); | ||
| 103 | + let path = path.clone(); | ||
| 104 | + let branch = branch.clone(); | ||
| 105 | + async move { | ||
| 106 | + let header = header_fingerprint(&state, &repo_id).await?; | ||
| 107 | + if branch.is_empty() { | ||
| 108 | + return Ok(header); | ||
| 109 | + } | ||
| 110 | + let refs = refs_fingerprint(path, branch).await?; | ||
| 111 | + Ok(format!("{header}\n{refs}")) | ||
| 112 | + } | ||
| 73 | }) | 113 | }) |
| 74 | .await | 114 | .await |
| 75 | } | 115 | } |
crates/forge-web/src/pages/dashboard.rsmodified+51 -1
| @@ -9,13 +9,15 @@ use forge_core::{Notification, Repo, Visibility}; | |||
| 9 | use time::OffsetDateTime; | 9 | use time::OffsetDateTime; |
| 10 | use topcoat::Result; | 10 | use topcoat::Result; |
| 11 | use topcoat::context::{Cx, app_context}; | 11 | use topcoat::context::{Cx, app_context}; |
| 12 | -use topcoat::router::page; | 12 | +use topcoat::router::response::Response; |
| 13 | +use topcoat::router::{Body, StatusCode, page, route}; | ||
| 13 | use topcoat::view::{View, component, view}; | 14 | use topcoat::view::{View, component, view}; |
| 14 | 15 | ||
| 15 | use crate::auth::{current_user, percent_encode}; | 16 | use crate::auth::{current_user, percent_encode}; |
| 16 | use crate::i18n::misc::{self as m, K as MK}; | 17 | use crate::i18n::misc::{self as m, K as MK}; |
| 17 | use crate::i18n::orgs::{self as g, K}; | 18 | use crate::i18n::orgs::{self as g, K}; |
| 18 | use crate::i18n::{self, Lang}; | 19 | use crate::i18n::{self, Lang}; |
| 20 | +use crate::live::{Topic, stream_changes}; | ||
| 19 | use crate::pages::issue_parts::stamp_unix; | 21 | use crate::pages::issue_parts::stamp_unix; |
| 20 | use crate::pages::repo_settings::{notice_banner_for, take_notice}; | 22 | use crate::pages::repo_settings::{notice_banner_for, take_notice}; |
| 21 | use crate::state::AppState; | 23 | use crate::state::AppState; |
| @@ -73,6 +75,52 @@ async fn home(cx: &Cx) -> Result<impl View> { | |||
| 73 | }) | 75 | }) |
| 74 | } | 76 | } |
| 75 | 77 | ||
| 78 | +/// The dashboard's change stream for the viewer. It follows the viewer's own user topic (repo | ||
| 79 | +/// listing and contribution calendar, both moved by the viewer's pushes and repo changes) and | ||
| 80 | +/// their inbox. The viewer comes from the session only. | ||
| 81 | +#[route(GET "/dashboard/events")] | ||
| 82 | +async fn dashboard_events(cx: &Cx) -> Result<Response> { | ||
| 83 | + let Some((user, _)) = current_user(cx).await? else { | ||
| 84 | + let mut res = Response::new(Body::empty()); | ||
| 85 | + *res.status_mut() = StatusCode::UNAUTHORIZED; | ||
| 86 | + return Ok(res); | ||
| 87 | + }; | ||
| 88 | + let state = app_context::<AppState>(cx).clone(); | ||
| 89 | + let topics = [Topic::User(user.id.clone()), Topic::Inbox(user.id.clone())]; | ||
| 90 | + stream_changes(cx, &state.live.clone(), &topics, move || { | ||
| 91 | + let state = state.clone(); | ||
| 92 | + let user = user.clone(); | ||
| 93 | + async move { dashboard_fingerprint(&state, &user).await } | ||
| 94 | + }) | ||
| 95 | + .await | ||
| 96 | +} | ||
| 97 | + | ||
| 98 | +/// The state the dashboard shows: the repo list, the calendar counts and the attention rows. | ||
| 99 | +async fn dashboard_fingerprint(state: &AppState, user: &forge_core::User) -> Result<String> { | ||
| 100 | + let mut lines = Vec::new(); | ||
| 101 | + for repo in state.store.list_repos_by_owner(&user.id).await? { | ||
| 102 | + lines.push(format!( | ||
| 103 | + "repo {} {:?} {}", | ||
| 104 | + repo.name, repo.visibility, repo.description | ||
| 105 | + )); | ||
| 106 | + } | ||
| 107 | + let since = forge_core::time::stamp_ago(Duration::from_secs(CALENDAR_DAYS * 86_400)); | ||
| 108 | + for (day, count) in state.store.contribution_counts(&user.id, &since).await? { | ||
| 109 | + lines.push(format!("day {day} {count}")); | ||
| 110 | + } | ||
| 111 | + for note in state | ||
| 112 | + .store | ||
| 113 | + .list_notifications(&user.id, true, None, ATTENTION_ROWS) | ||
| 114 | + .await? | ||
| 115 | + { | ||
| 116 | + lines.push(format!( | ||
| 117 | + "note {} {} {} {}", | ||
| 118 | + note.id, note.updated_at, note.title, note.issue_state | ||
| 119 | + )); | ||
| 120 | + } | ||
| 121 | + Ok(lines.join("\n")) | ||
| 122 | +} | ||
| 123 | + | ||
| 76 | /// Reads the dashboard data for a signed-in user. | 124 | /// Reads the dashboard data for a signed-in user. |
| 77 | async fn load_dashboard( | 125 | async fn load_dashboard( |
| 78 | state: &AppState, | 126 | state: &AppState, |
| @@ -129,6 +177,7 @@ async fn dashboard(dash: Dashboard, lang: Lang) -> Result<impl View> { | |||
| 129 | let greeting = m::greeting(lang, dash.hour, &dash.name); | 177 | let greeting = m::greeting(lang, dash.hour, &dash.name); |
| 130 | let attention_empty = dash.attention.is_empty(); | 178 | let attention_empty = dash.attention.is_empty(); |
| 131 | Ok(view! { | 179 | Ok(view! { |
| 180 | + <div data-live="/dashboard/events"> | ||
| 132 | <h1 class="greet">(greeting)</h1> | 181 | <h1 class="greet">(greeting)</h1> |
| 133 | contribution_calendar(calendar: dash.calendar, lang: lang) | 182 | contribution_calendar(calendar: dash.calendar, lang: lang) |
| 134 | <div class="dash-cols"> | 183 | <div class="dash-cols"> |
| @@ -187,6 +236,7 @@ async fn dashboard(dash: Dashboard, lang: Lang) -> Result<impl View> { | |||
| 187 | <p class="small"><a href="/notifications">(m::t(lang, MK::ViewAllNotifications))</a></p> | 236 | <p class="small"><a href="/notifications">(m::t(lang, MK::ViewAllNotifications))</a></p> |
| 188 | </section> | 237 | </section> |
| 189 | </div> | 238 | </div> |
| 239 | + </div> | ||
| 190 | }) | 240 | }) |
| 191 | } | 241 | } |
| 192 | 242 | ||
crates/forge-web/src/pages/explore.rsmodified+62 -6
| @@ -6,12 +6,14 @@ | |||
| 6 | use forge_core::store::RepoSort; | 6 | use forge_core::store::RepoSort; |
| 7 | use topcoat::Result; | 7 | use topcoat::Result; |
| 8 | use topcoat::context::{Cx, app_context}; | 8 | use topcoat::context::{Cx, app_context}; |
| 9 | -use topcoat::router::{page, query_params}; | 9 | +use topcoat::router::response::Response; |
| 10 | +use topcoat::router::{page, query_params, route}; | ||
| 10 | use topcoat::view::{View, component, view}; | 11 | use topcoat::view::{View, component, view}; |
| 11 | 12 | ||
| 12 | use crate::auth::current_user; | 13 | use crate::auth::current_user; |
| 13 | use crate::i18n::orgs::{self as g, K}; | 14 | use crate::i18n::orgs::{self as g, K}; |
| 14 | use crate::i18n::{self, Lang}; | 15 | use crate::i18n::{self, Lang}; |
| 16 | +use crate::live::{Topic, stream_changes}; | ||
| 15 | use crate::state::AppState; | 17 | use crate::state::AppState; |
| 16 | use crate::views::repo_list::{ | 18 | use crate::views::repo_list::{ |
| 17 | PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips, | 19 | PageLink, RepoRow, SortLink, pager, pager_links, repo_rows, sort_chips, |
| @@ -58,9 +60,8 @@ fn sort_key(raw: Option<&str>) -> &'static str { | |||
| 58 | .unwrap_or(SORTS[0].0) | 60 | .unwrap_or(SORTS[0].0) |
| 59 | } | 61 | } |
| 60 | 62 | ||
| 61 | -#[page("/explore")] | 63 | +/// The search text, sort key and page the query asks for, with the defaults filled in. |
| 62 | -async fn explore_page(cx: &Cx) -> Result<impl View> { | 64 | +fn listing_args(query: &ExploreQuery) -> (String, &'static str, u64) { |
| 63 | - let query = query_params::<ExploreQuery>(cx)?; | ||
| 64 | let q: String = query | 65 | let q: String = query |
| 65 | .q | 66 | .q |
| 66 | .as_deref() | 67 | .as_deref() |
| @@ -76,6 +77,14 @@ async fn explore_page(cx: &Cx) -> Result<impl View> { | |||
| 76 | .and_then(|p| p.parse::<u64>().ok()) | 77 | .and_then(|p| p.parse::<u64>().ok()) |
| 77 | .unwrap_or(1) | 78 | .unwrap_or(1) |
| 78 | .max(1); | 79 | .max(1); |
| 80 | + (q, sort, page) | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +#[page("/explore")] | ||
| 84 | +async fn explore_page(cx: &Cx) -> Result<impl View> { | ||
| 85 | + let query = query_params::<ExploreQuery>(cx)?; | ||
| 86 | + let (q, sort, page) = listing_args(query); | ||
| 87 | + let live = explore_href(&q, sort, page).replacen("/explore?", "/explore/events?", 1); | ||
| 79 | let viewer = current_user(cx).await?; | 88 | let viewer = current_user(cx).await?; |
| 80 | let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u)); | 89 | let lang = i18n::lang(cx, viewer.as_ref().map(|(u, _)| u)); |
| 81 | let state = app_context::<AppState>(cx); | 90 | let state = app_context::<AppState>(cx); |
| @@ -120,10 +129,56 @@ async fn explore_page(cx: &Cx) -> Result<impl View> { | |||
| 120 | Ok(view! { cx => | 129 | Ok(view! { cx => |
| 121 | shell(title: title, viewer: viewer.as_ref(), | 130 | shell(title: title, viewer: viewer.as_ref(), |
| 122 | explore_body(q: q, sort: sort, sort_links: sort_links, rows: rows, | 131 | explore_body(q: q, sort: sort, sort_links: sort_links, rows: rows, |
| 123 | - total: total, page: page, pages: pages, nav: nav, orgs: orgs, lang: lang)) | 132 | + total: total, page: page, pages: pages, nav: nav, orgs: orgs, lang: lang, live: live)) |
| 124 | }) | 133 | }) |
| 125 | } | 134 | } |
| 126 | 135 | ||
| 136 | +/// The explore listing's change stream, for the same search, sort and page as the page. Only the | ||
| 137 | +/// public listing is in it, so no viewer check is needed. A new public repo, a changed one or a | ||
| 138 | +/// star moves it. | ||
| 139 | +#[route(GET "/explore/events")] | ||
| 140 | +async fn explore_events(cx: &Cx) -> Result<Response> { | ||
| 141 | + let query = query_params::<ExploreQuery>(cx)?; | ||
| 142 | + let (q, sort, page) = listing_args(query); | ||
| 143 | + let state = app_context::<AppState>(cx).clone(); | ||
| 144 | + stream_changes(cx, &state.live.clone(), &[Topic::Explore], move || { | ||
| 145 | + let state = state.clone(); | ||
| 146 | + let q = q.clone(); | ||
| 147 | + async move { explore_fingerprint(&state, &q, sort, page).await } | ||
| 148 | + }) | ||
| 149 | + .await | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +/// The state the explore listing shows: its total, each row with its stars, and the org names. | ||
| 153 | +async fn explore_fingerprint( | ||
| 154 | + state: &AppState, | ||
| 155 | + q: &str, | ||
| 156 | + sort: &'static str, | ||
| 157 | + page: u64, | ||
| 158 | +) -> Result<String> { | ||
| 159 | + let sort_kind = match sort { | ||
| 160 | + "stars" => RepoSort::MostStars, | ||
| 161 | + "name" => RepoSort::Name, | ||
| 162 | + _ => RepoSort::RecentlyUpdated, | ||
| 163 | + }; | ||
| 164 | + let search = (!q.is_empty()).then_some(q); | ||
| 165 | + let (listed, total) = state | ||
| 166 | + .store | ||
| 167 | + .list_public_repos(search, sort_kind, page, PER_PAGE) | ||
| 168 | + .await?; | ||
| 169 | + let mut lines = vec![total.to_string()]; | ||
| 170 | + for (repo, stars, activity) in listed { | ||
| 171 | + lines.push(format!( | ||
| 172 | + "{} {} {} {:?} {} {stars} {activity}", | ||
| 173 | + repo.owner_name, repo.name, repo.description, repo.visibility, repo.default_branch | ||
| 174 | + )); | ||
| 175 | + } | ||
| 176 | + for org in state.store.list_orgs().await? { | ||
| 177 | + lines.push(format!("org {}", org.username)); | ||
| 178 | + } | ||
| 179 | + Ok(lines.join("\n")) | ||
| 180 | +} | ||
| 181 | + | ||
| 127 | #[component] | 182 | #[component] |
| 128 | async fn explore_body( | 183 | async fn explore_body( |
| 129 | q: String, | 184 | q: String, |
| @@ -136,12 +191,13 @@ async fn explore_body( | |||
| 136 | nav: (Vec<PageLink>, Option<String>, Option<String>), | 191 | nav: (Vec<PageLink>, Option<String>, Option<String>), |
| 137 | orgs: Vec<String>, | 192 | orgs: Vec<String>, |
| 138 | lang: Lang, | 193 | lang: Lang, |
| 194 | + live: String, | ||
| 139 | ) -> Result<impl View> { | 195 | ) -> Result<impl View> { |
| 140 | let empty = rows.is_empty(); | 196 | let empty = rows.is_empty(); |
| 141 | let has_orgs = !orgs.is_empty(); | 197 | let has_orgs = !orgs.is_empty(); |
| 142 | let (links, prev, next) = nav; | 198 | let (links, prev, next) = nav; |
| 143 | Ok(view! { | 199 | Ok(view! { |
| 144 | - <section class="explore"> | 200 | + <section class="explore" data-live=(live.as_str())> |
| 145 | <h1>(g::t(lang, K::Explore))</h1> | 201 | <h1>(g::t(lang, K::Explore))</h1> |
| 146 | <p class="muted">(g::t(lang, K::PublicReposIntro))</p> | 202 | <p class="muted">(g::t(lang, K::PublicReposIntro))</p> |
| 147 | if has_orgs { | 203 | if has_orgs { |
crates/forge-web/src/pages/fork.rsmodified+2 -0
| @@ -69,6 +69,8 @@ async fn fork_post(cx: &Cx, Form(form): Form<ForkForm>) -> Result<SeeOther> { | |||
| 69 | let _ = state.store.delete_repo(&fork.id).await; | 69 | let _ = state.store.delete_repo(&fork.id).await; |
| 70 | return Err(e.into()); | 70 | return Err(e.into()); |
| 71 | } | 71 | } |
| 72 | + state.live.bump_repo(&fork.owner_id, &fork.id); | ||
| 73 | + state.live.bump_repo(&source_repo.owner_id, &source_repo.id); | ||
| 72 | // A fork gets the source's labels rather than the default set. The fork already exists, so a | 74 | // A fork gets the source's labels rather than the default set. The fork already exists, so a |
| 73 | // label failure is logged rather than failing the request. | 75 | // label failure is logged rather than failing the request. |
| 74 | match state.store.list_labels(&source_repo.id).await { | 76 | match state.store.list_labels(&source_repo.id).await { |
crates/forge-web/src/pages/import.rsmodified+4 -1
| @@ -512,7 +512,10 @@ async fn begin( | |||
| 512 | .create_repo(&target.id, &name, description, visibility, DEFAULT_BRANCH) | 512 | .create_repo(&target.id, &name, description, visibility, DEFAULT_BRANCH) |
| 513 | .await | 513 | .await |
| 514 | { | 514 | { |
| 515 | - Ok(repo) => repo, | 515 | + Ok(repo) => { |
| 516 | + state.live.bump_repo(&repo.owner_id, &repo.id); | ||
| 517 | + repo | ||
| 518 | + } | ||
| 516 | Err(e) => match user_facing_message(&e) { | 519 | Err(e) => match user_facing_message(&e) { |
| 517 | Some(message) => return Ok(Err(message)), | 520 | Some(message) => return Ok(Err(message)), |
| 518 | None => return Err(e.into()), | 521 | None => return Err(e.into()), |
crates/forge-web/src/pages/new_repo.rsmodified+4 -1
| @@ -338,7 +338,10 @@ async fn create_repo( | |||
| 338 | ) | 338 | ) |
| 339 | .await | 339 | .await |
| 340 | { | 340 | { |
| 341 | - Ok(repo) => repo, | 341 | + Ok(repo) => { |
| 342 | + state.live.bump_repo(&repo.owner_id, &repo.id); | ||
| 343 | + repo | ||
| 344 | + } | ||
| 342 | Err(e) => match user_facing_message(&e) { | 345 | Err(e) => match user_facing_message(&e) { |
| 343 | Some(message) => return Ok(Err(message)), | 346 | Some(message) => return Ok(Err(message)), |
| 344 | None => return Err(e.into()), | 347 | None => return Err(e.into()), |
crates/forge-web/src/pages/notifications.rsmodified+87 -2
| @@ -28,6 +28,7 @@ use crate::auth::{current_user, percent_encode, require_csrf, require_user}; | |||
| 28 | use crate::i18n::alerts as alert_text; | 28 | use crate::i18n::alerts as alert_text; |
| 29 | use crate::i18n::misc::{self as g, K}; | 29 | use crate::i18n::misc::{self as g, K}; |
| 30 | use crate::i18n::{self, Key, Lang}; | 30 | use crate::i18n::{self, Key, Lang}; |
| 31 | +use crate::live::{Topic, stream_changes}; | ||
| 31 | use crate::notify_hub::publish_unread; | 32 | use crate::notify_hub::publish_unread; |
| 32 | use crate::pages::issue_parts::{parse_number, stamp_unix}; | 33 | use crate::pages::issue_parts::{parse_number, stamp_unix}; |
| 33 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; | 34 | use crate::pages::repo_ctx::{RepoCtx, load_repo}; |
| @@ -451,13 +452,95 @@ async fn inbox(cx: &Cx) -> Result<impl View> { | |||
| 451 | let unread_count = state.store.unread_count(&user.id).await?; | 452 | let unread_count = state.store.unread_count(&user.id).await?; |
| 452 | let transfers = state.store.pending_transfers_for_user(&user.id).await?; | 453 | let transfers = state.store.pending_transfers_for_user(&user.id).await?; |
| 453 | let csrf = viewer.1.csrf_token.clone(); | 454 | let csrf = viewer.1.csrf_token.clone(); |
| 455 | + let live = inbox_live_url(all); | ||
| 454 | Ok(view! { | 456 | Ok(view! { |
| 455 | shell(title: i18n::t(lang, Key::Notifications), viewer: Some(&viewer), | 457 | shell(title: i18n::t(lang, Key::Notifications), viewer: Some(&viewer), |
| 456 | - inbox_list(lang: lang, all: all, unread_count: unread_count, groups: groups, more: more, csrf: csrf, transfers: transfers) | 458 | + inbox_list(lang: lang, all: all, unread_count: unread_count, groups: groups, more: more, csrf: csrf, transfers: transfers, live: live) |
| 457 | ) | 459 | ) |
| 458 | }) | 460 | }) |
| 459 | } | 461 | } |
| 460 | 462 | ||
| 463 | +/// The URL of the inbox's live stream for the tab the viewer is on. | ||
| 464 | +fn inbox_live_url(all: bool) -> String { | ||
| 465 | + if all { | ||
| 466 | + "/notifications/events?all=1".to_owned() | ||
| 467 | + } else { | ||
| 468 | + "/notifications/events".to_owned() | ||
| 469 | + } | ||
| 470 | +} | ||
| 471 | + | ||
| 472 | +/// The state the inbox list shows: the unread count, then each row of the first page with the | ||
| 473 | +/// fields a change to it moves (its read flag, its time and its title). Rows of the older pages | ||
| 474 | +/// are not in it. | ||
| 475 | +async fn inbox_fingerprint(state: &AppState, user: &User, all: bool) -> Result<String> { | ||
| 476 | + let unread_only = !all; | ||
| 477 | + let before = None; | ||
| 478 | + let mut lines = vec![state.store.unread_count(&user.id).await?.to_string()]; | ||
| 479 | + for note in state | ||
| 480 | + .store | ||
| 481 | + .list_notifications(&user.id, unread_only, before, PAGE_SIZE) | ||
| 482 | + .await? | ||
| 483 | + { | ||
| 484 | + lines.push(format!( | ||
| 485 | + "issue {} {} {} {} {}", | ||
| 486 | + note.id, note.unread, note.updated_at, note.title, note.issue_state | ||
| 487 | + )); | ||
| 488 | + } | ||
| 489 | + for note in state | ||
| 490 | + .store | ||
| 491 | + .list_discussion_notifications(&user.id, unread_only, before, PAGE_SIZE) | ||
| 492 | + .await? | ||
| 493 | + { | ||
| 494 | + lines.push(format!( | ||
| 495 | + "discussion {} {} {} {}", | ||
| 496 | + note.discussion_id, note.unread, note.updated_at, note.title | ||
| 497 | + )); | ||
| 498 | + } | ||
| 499 | + for note in state | ||
| 500 | + .store | ||
| 501 | + .list_advisory_notifications(&user.id, unread_only, before, PAGE_SIZE) | ||
| 502 | + .await? | ||
| 503 | + { | ||
| 504 | + lines.push(format!( | ||
| 505 | + "advisory {} {} {}", | ||
| 506 | + note.repo_id, note.unread, note.updated_at | ||
| 507 | + )); | ||
| 508 | + } | ||
| 509 | + if user.is_admin { | ||
| 510 | + for note in state | ||
| 511 | + .store | ||
| 512 | + .list_admin_notices(&user.id, unread_only, before, PAGE_SIZE) | ||
| 513 | + .await? | ||
| 514 | + { | ||
| 515 | + lines.push(format!( | ||
| 516 | + "admin {} {} {}", | ||
| 517 | + note.id, note.unread, note.updated_at | ||
| 518 | + )); | ||
| 519 | + } | ||
| 520 | + } | ||
| 521 | + Ok(lines.join("\n")) | ||
| 522 | +} | ||
| 523 | + | ||
| 524 | +/// The inbox's change stream for the viewer's own inbox. The viewer comes from the session only, | ||
| 525 | +/// so no URL can name another user's inbox. An anonymous viewer gets a bare 401. | ||
| 526 | +#[route(GET "/notifications/events")] | ||
| 527 | +async fn inbox_events(cx: &Cx) -> Result<Response> { | ||
| 528 | + let Some((user, _)) = current_user(cx).await? else { | ||
| 529 | + let mut res = Response::new(Body::empty()); | ||
| 530 | + *res.status_mut() = StatusCode::UNAUTHORIZED; | ||
| 531 | + return Ok(res); | ||
| 532 | + }; | ||
| 533 | + let all = query_params::<InboxQuery>(cx)?.all.as_deref() == Some("1"); | ||
| 534 | + let state = app_context::<AppState>(cx).clone(); | ||
| 535 | + let topic = Topic::Inbox(user.id.clone()); | ||
| 536 | + stream_changes(cx, &state.live.clone(), &[topic], move || { | ||
| 537 | + let state = state.clone(); | ||
| 538 | + let user = user.clone(); | ||
| 539 | + async move { inbox_fingerprint(&state, &user, all).await } | ||
| 540 | + }) | ||
| 541 | + .await | ||
| 542 | +} | ||
| 543 | + | ||
| 461 | /// Opens one inbox row: marks it read and sends the viewer to the issue or pull. Another user's | 544 | /// Opens one inbox row: marks it read and sends the viewer to the issue or pull. Another user's |
| 462 | /// row, or a repo the viewer can no longer read, is 404. | 545 | /// row, or a repo the viewer can no longer read, is 404. |
| 463 | #[route(GET "/notifications/{note}/open")] | 546 | #[route(GET "/notifications/{note}/open")] |
| @@ -748,6 +831,7 @@ async fn set_watch(cx: &Cx, Form(form): Form<WatchForm>) -> Result<SeeOther> { | |||
| 748 | }; | 831 | }; |
| 749 | let state = app_context::<AppState>(cx); | 832 | let state = app_context::<AppState>(cx); |
| 750 | state.store.set_watch(&user.id, &ctx.repo.id, level).await?; | 833 | state.store.set_watch(&user.id, &ctx.repo.id, level).await?; |
| 834 | + state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id); | ||
| 751 | Ok(see_other(repo_href( | 835 | Ok(see_other(repo_href( |
| 752 | &ctx.repo.owner_name, | 836 | &ctx.repo.owner_name, |
| 753 | &ctx.repo.name, | 837 | &ctx.repo.name, |
| @@ -888,13 +972,14 @@ async fn inbox_list( | |||
| 888 | more: Option<String>, | 972 | more: Option<String>, |
| 889 | csrf: String, | 973 | csrf: String, |
| 890 | transfers: Vec<PendingTransfer>, | 974 | transfers: Vec<PendingTransfer>, |
| 975 | + live: String, | ||
| 891 | ) -> Result<impl View> { | 976 | ) -> Result<impl View> { |
| 892 | let empty = groups.is_empty(); | 977 | let empty = groups.is_empty(); |
| 893 | let unread_class = if all { "" } else { "active" }; | 978 | let unread_class = if all { "" } else { "active" }; |
| 894 | let all_class = if all { "active" } else { "" }; | 979 | let all_class = if all { "active" } else { "" }; |
| 895 | let unread_text = format!("{} ({unread_count})", g::t(lang, K::Unread)); | 980 | let unread_text = format!("{} ({unread_count})", g::t(lang, K::Unread)); |
| 896 | Ok(view! { | 981 | Ok(view! { |
| 897 | - <section class="page-head"> | 982 | + <section class="page-head" data-live=(live.as_str())> |
| 898 | <h1>(i18n::t(lang, Key::Notifications))</h1> | 983 | <h1>(i18n::t(lang, Key::Notifications))</h1> |
| 899 | if !empty { | 984 | if !empty { |
| 900 | <form method="post" action="/notifications/mark_all_read" class="notif-inline-form"> | 985 | <form method="post" action="/notifications/mark_all_read" class="notif-inline-form"> |
crates/forge-web/src/pages/profile.rsmodified+70 -2
| @@ -15,13 +15,15 @@ use forge_core::{Repo, User, Visibility}; | |||
| 15 | use topcoat::Result; | 15 | use topcoat::Result; |
| 16 | use topcoat::context::{Cx, app_context}; | 16 | use topcoat::context::{Cx, app_context}; |
| 17 | use topcoat::router::error::not_found; | 17 | use topcoat::router::error::not_found; |
| 18 | -use topcoat::router::{page, path_param, query_params}; | 18 | +use topcoat::router::response::Response; |
| 19 | +use topcoat::router::{page, path_param, query_params, route}; | ||
| 19 | use topcoat::view::{Unescaped, View, component, view}; | 20 | use topcoat::view::{Unescaped, View, component, view}; |
| 20 | 21 | ||
| 21 | use crate::auth::current_user; | 22 | use crate::auth::current_user; |
| 22 | use crate::i18n::misc::{self as mi, K as MK}; | 23 | use crate::i18n::misc::{self as mi, K as MK}; |
| 23 | use crate::i18n::orgs::{self as g, K}; | 24 | use crate::i18n::orgs::{self as g, K}; |
| 24 | use crate::i18n::{self, Lang}; | 25 | use crate::i18n::{self, Lang}; |
| 26 | +use crate::live::{Topic, stream_changes}; | ||
| 25 | use crate::pages::dashboard::badge_class; | 27 | use crate::pages::dashboard::badge_class; |
| 26 | use crate::render::markdown::render_markdown; | 28 | use crate::render::markdown::render_markdown; |
| 27 | use crate::state::AppState; | 29 | use crate::state::AppState; |
| @@ -225,6 +227,72 @@ async fn profile_page(cx: &Cx) -> Result<impl View> { | |||
| 225 | }) | 227 | }) |
| 226 | } | 228 | } |
| 227 | 229 | ||
| 230 | +/// The profile's change stream. It follows the user's topic: repos created, changed or starred, | ||
| 231 | +/// pins, and pushes by the user. The stream is keyed by the username in the URL, but the viewer | ||
| 232 | +/// comes from the session, so what it sends is what that viewer may read. An unknown name is 404. | ||
| 233 | +#[route(GET "/users/{username}/events")] | ||
| 234 | +async fn profile_events(cx: &Cx) -> Result<Response> { | ||
| 235 | + let name = path_param::<Username>(cx); | ||
| 236 | + let state = app_context::<AppState>(cx).clone(); | ||
| 237 | + let Some(user) = state.store.user_by_username(name).await? else { | ||
| 238 | + return Err(not_found().into()); | ||
| 239 | + }; | ||
| 240 | + let actor = current_user(cx).await?.map(|(u, _)| u); | ||
| 241 | + let topic = Topic::User(user.id.clone()); | ||
| 242 | + stream_changes(cx, &state.live.clone(), &[topic], move || { | ||
| 243 | + let state = state.clone(); | ||
| 244 | + let user = user.clone(); | ||
| 245 | + let actor = actor.clone(); | ||
| 246 | + async move { profile_fingerprint(&state, &user, actor.as_ref()).await } | ||
| 247 | + }) | ||
| 248 | + .await | ||
| 249 | +} | ||
| 250 | + | ||
| 251 | +/// The state the profile shows: the tab counts, the pins with their stars, and the first page of | ||
| 252 | +/// the owner's repos as the default tab lists them. | ||
| 253 | +async fn profile_fingerprint( | ||
| 254 | + state: &AppState, | ||
| 255 | + user: &User, | ||
| 256 | + actor: Option<&User>, | ||
| 257 | +) -> Result<String> { | ||
| 258 | + let owned = RepoScope::OwnedBy(&user.id); | ||
| 259 | + let starred = RepoScope::StarredBy(&user.id); | ||
| 260 | + let mut lines = vec![ | ||
| 261 | + state | ||
| 262 | + .store | ||
| 263 | + .count_visible_repos(owned, actor) | ||
| 264 | + .await? | ||
| 265 | + .to_string(), | ||
| 266 | + state | ||
| 267 | + .store | ||
| 268 | + .count_visible_repos(starred, actor) | ||
| 269 | + .await? | ||
| 270 | + .to_string(), | ||
| 271 | + ]; | ||
| 272 | + let pins = readable( | ||
| 273 | + state, | ||
| 274 | + actor, | ||
| 275 | + state.store.profile_pins(&user.id).await?, | ||
| 276 | + MAX_PROFILE_PINS, | ||
| 277 | + ) | ||
| 278 | + .await?; | ||
| 279 | + for repo in pins { | ||
| 280 | + let stars = state.store.star_count(&repo.id).await?; | ||
| 281 | + lines.push(format!("pin {} {} {stars}", repo.name, repo.description)); | ||
| 282 | + } | ||
| 283 | + let (listed, _) = state | ||
| 284 | + .store | ||
| 285 | + .list_visible_repos(owned, actor, None, RepoSort::RecentlyUpdated, 1, PER_PAGE) | ||
| 286 | + .await?; | ||
| 287 | + for (repo, stars, activity) in listed { | ||
| 288 | + lines.push(format!( | ||
| 289 | + "repo {} {:?} {} {stars} {activity}", | ||
| 290 | + repo.name, repo.visibility, repo.description | ||
| 291 | + )); | ||
| 292 | + } | ||
| 293 | + Ok(lines.join("\n")) | ||
| 294 | +} | ||
| 295 | + | ||
| 228 | /// What an organization's profile adds: its member names and its team count. | 296 | /// What an organization's profile adds: its member names and its team count. |
| 229 | struct OrgSummary { | 297 | struct OrgSummary { |
| 230 | members: Vec<String>, | 298 | members: Vec<String>, |
| @@ -381,7 +449,7 @@ async fn profile_card( | |||
| 381 | } = listing; | 449 | } = listing; |
| 382 | let has_rows = !rows.is_empty(); | 450 | let has_rows = !rows.is_empty(); |
| 383 | Ok(view! { | 451 | Ok(view! { |
| 384 | - <article class="profile-page"> | 452 | + <article class="profile-page" data-live=(format!("/users/{}/events", user.username))> |
| 385 | <header class="profile-head"> | 453 | <header class="profile-head"> |
| 386 | <img class="profile-avatar" src=(src) alt="" width="256" height="256"> | 454 | <img class="profile-avatar" src=(src) alt="" width="256" height="256"> |
| 387 | <div class="profile-id"> | 455 | <div class="profile-id"> |
crates/forge-web/src/pages/profile_pins.rsmodified+3 -4
| @@ -133,10 +133,9 @@ async fn save_pins( | |||
| 133 | let error = g::t(lang, K::PinsTooMany); | 133 | let error = g::t(lang, K::PinsTooMany); |
| 134 | return pins_form(cx, viewer, owner, action, chosen, Some(error)).await; | 134 | return pins_form(cx, viewer, owner, action, chosen, Some(error)).await; |
| 135 | } | 135 | } |
| 136 | - app_context::<AppState>(cx) | 136 | + let state = app_context::<AppState>(cx); |
| 137 | - .store | 137 | + state.store.set_profile_pins(&owner.id, &chosen).await?; |
| 138 | - .set_profile_pins(&owner.id, &chosen) | 138 | + state.live.bump(&crate::live::Topic::User(owner.id.clone())); |
| 139 | - .await?; | ||
| 140 | Err(see_other(back).into()) | 139 | Err(see_other(back).into()) |
| 141 | } | 140 | } |
| 142 | 141 | ||
crates/forge-web/src/pages/pull_live.rsmodified+2 -2
| @@ -168,7 +168,7 @@ async fn pulls_events(cx: &Cx) -> Result<Response> { | |||
| 168 | let store = state.store.clone(); | 168 | let store = state.store.clone(); |
| 169 | let repo_id = ctx.repo.id.clone(); | 169 | let repo_id = ctx.repo.id.clone(); |
| 170 | let viewer = ctx.viewer.as_ref().map(|(user, _)| user.id.clone()); | 170 | let viewer = ctx.viewer.as_ref().map(|(user, _)| user.id.clone()); |
| 171 | - stream_changes(cx, &state.live, &topic, move || { | 171 | + stream_changes(cx, &state.live, &[topic], move || { |
| 172 | let store = store.clone(); | 172 | let store = store.clone(); |
| 173 | let repo_id = repo_id.clone(); | 173 | let repo_id = repo_id.clone(); |
| 174 | let viewer = viewer.clone(); | 174 | let viewer = viewer.clone(); |
| @@ -190,7 +190,7 @@ async fn pull_events(cx: &Cx) -> Result<Response> { | |||
| 190 | let store = state.store.clone(); | 190 | let store = state.store.clone(); |
| 191 | let repo_id = ctx.repo.id.clone(); | 191 | let repo_id = ctx.repo.id.clone(); |
| 192 | let viewer = ctx.viewer.as_ref().map(|(user, _)| user.id.clone()); | 192 | let viewer = ctx.viewer.as_ref().map(|(user, _)| user.id.clone()); |
| 193 | - stream_changes(cx, &state.live, &topic, move || { | 193 | + stream_changes(cx, &state.live, &[topic], move || { |
| 194 | let store = store.clone(); | 194 | let store = store.clone(); |
| 195 | let repo_id = repo_id.clone(); | 195 | let repo_id = repo_id.clone(); |
| 196 | let viewer = viewer.clone(); | 196 | let viewer = viewer.clone(); |
crates/forge-web/src/pages/repo.rsmodified+11 -4
| @@ -20,7 +20,7 @@ use topcoat::view::{View, component, view}; | |||
| 20 | 20 | ||
| 21 | use crate::i18n::code::{self as g, K}; | 21 | use crate::i18n::code::{self as g, K}; |
| 22 | use crate::i18n::{self, Lang}; | 22 | use crate::i18n::{self, Lang}; |
| 23 | -use crate::pages::code_live::live_url; | 23 | +use crate::pages::code_live::{follows_branch, live_url}; |
| 24 | use crate::pages::dashboard::badge_class; | 24 | use crate::pages::dashboard::badge_class; |
| 25 | use crate::pages::finder::file_finder; | 25 | use crate::pages::finder::file_finder; |
| 26 | use crate::pages::issue_parts::stamp_unix; | 26 | use crate::pages::issue_parts::stamp_unix; |
| @@ -81,6 +81,8 @@ pub async fn repo_head(head: RepoHead) -> Result<impl View> { | |||
| 81 | star, | 81 | star, |
| 82 | watchers, | 82 | watchers, |
| 83 | watch, | 83 | watch, |
| 84 | + forks, | ||
| 85 | + live, | ||
| 84 | mirror, | 86 | mirror, |
| 85 | discussions, | 87 | discussions, |
| 86 | wiki, | 88 | wiki, |
| @@ -127,6 +129,7 @@ pub async fn repo_head(head: RepoHead) -> Result<impl View> { | |||
| 127 | (repo_href(&owner, &name, "watch", ""), watch.csrf, level) | 129 | (repo_href(&owner, &name, "watch", ""), watch.csrf, level) |
| 128 | }); | 130 | }); |
| 129 | let watch_count = g::watching_count(lang, watchers); | 131 | let watch_count = g::watching_count(lang, watchers); |
| 132 | + let fork_count = g::forks_count(lang, forks); | ||
| 130 | let search_action = repo_href(&owner, &name, "search", ""); | 133 | let search_action = repo_href(&owner, &name, "search", ""); |
| 131 | let mirror_line = mirror.as_ref().map(|source| source.url.clone()); | 134 | let mirror_line = mirror.as_ref().map(|source| source.url.clone()); |
| 132 | let mirror_status = match mirror { | 135 | let mirror_status = match mirror { |
| @@ -137,8 +140,9 @@ pub async fn repo_head(head: RepoHead) -> Result<impl View> { | |||
| 137 | }, | 140 | }, |
| 138 | None => String::new(), | 141 | None => String::new(), |
| 139 | }; | 142 | }; |
| 143 | + let live_attr = (!live.is_empty()).then(|| live.clone()); | ||
| 140 | Ok(view! { | 144 | Ok(view! { |
| 141 | - <section class="page-head"> | 145 | + <section class="page-head" data-live=(live_attr.as_deref())> |
| 142 | <div> | 146 | <div> |
| 143 | <div class="repo-title-row"> | 147 | <div class="repo-title-row"> |
| 144 | <h1 class="repo-title">user_link(shown: title_owner.as_str(), login: title_owner.as_str()) "/" (title_name.as_str())</h1> | 148 | <h1 class="repo-title">user_link(shown: title_owner.as_str(), login: title_owner.as_str()) "/" (title_name.as_str())</h1> |
| @@ -163,6 +167,7 @@ pub async fn repo_head(head: RepoHead) -> Result<impl View> { | |||
| 163 | } else { | 167 | } else { |
| 164 | <span class="muted small">(watch_count.as_str())</span> | 168 | <span class="muted small">(watch_count.as_str())</span> |
| 165 | } | 169 | } |
| 170 | + <span class="muted small">(fork_count.as_str())</span> | ||
| 166 | <div class="star-control"> | 171 | <div class="star-control"> |
| 167 | if let Some((action, label, csrf)) = star_control { | 172 | if let Some((action, label, csrf)) = star_control { |
| 168 | <form method="post" action=(action.as_str()) class="star-form"> | 173 | <form method="post" action=(action.as_str()) class="star-form"> |
| @@ -449,6 +454,7 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | |||
| 449 | ctx.viewer_tz(), | 454 | ctx.viewer_tz(), |
| 450 | )); | 455 | )); |
| 451 | } | 456 | } |
| 457 | + let follows = follows_branch(&refs, &branch); | ||
| 452 | let live = live_url(&repo.owner_name, &repo.name, &refs, &branch); | 458 | let live = live_url(&repo.owner_name, &repo.name, &refs, &branch); |
| 453 | let branch_names: Vec<String> = refs | 459 | let branch_names: Vec<String> = refs |
| 454 | .into_iter() | 460 | .into_iter() |
| @@ -458,7 +464,8 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | |||
| 458 | 464 | ||
| 459 | let owner_name = repo.owner_name.clone(); | 465 | let owner_name = repo.owner_name.clone(); |
| 460 | let repo_name = repo.name.clone(); | 466 | let repo_name = repo.name.clone(); |
| 461 | - let header = ctx.head(state, "code").await?; | 467 | + let mut header = ctx.head(state, "code").await?; |
| 468 | + header.live = live; | ||
| 462 | let latest = crate::pages::releases::latest_release_for_home(state, &ctx).await?; | 469 | let latest = crate::pages::releases::latest_release_for_home(state, &ctx).await?; |
| 463 | let banners = recent_push_banners(state, &ctx, header.forked_from.clone()).await?; | 470 | let banners = recent_push_banners(state, &ctx, header.forked_from.clone()).await?; |
| 464 | let now = now_unix(); | 471 | let now = now_unix(); |
| @@ -472,7 +479,7 @@ async fn repo_page(cx: &Cx) -> Result<impl View> { | |||
| 472 | recent_pushes(banners: banners, now: now, lang: lang) | 479 | recent_pushes(banners: banners, now: now, lang: lang) |
| 473 | } | 480 | } |
| 474 | if let Some(rows) = tree { | 481 | if let Some(rows) = tree { |
| 475 | - <div class="browse-bar" data-live=(live.as_deref()) data-live-code=(live.is_some().then_some("true")) data-live-gone=(g::t(lang, K::LivePathGone))> | 482 | + <div class="browse-bar" data-live-code=(follows.then_some("true")) data-live-gone=(g::t(lang, K::LivePathGone))> |
| 476 | <span class="muted small">(g::t(lang, K::BranchLabel))</span> | 483 | <span class="muted small">(g::t(lang, K::BranchLabel))</span> |
| 477 | <code>(branch.clone())</code> | 484 | <code>(branch.clone())</code> |
| 478 | file_finder(lang: lang, owner: owner_name.clone(), repo: repo_name.clone(), | 485 | file_finder(lang: lang, owner: owner_name.clone(), repo: repo_name.clone(), |
crates/forge-web/src/pages/repo_ctx.rsmodified+20 -0
| @@ -78,6 +78,13 @@ pub struct RepoHead { | |||
| 78 | pub watchers: u64, | 78 | pub watchers: u64, |
| 79 | /// `None` for anonymous viewers, who see the count only. | 79 | /// `None` for anonymous viewers, who see the count only. |
| 80 | pub watch: Option<WatchButton>, | 80 | pub watch: Option<WatchButton>, |
| 81 | + /// Public forks of this repo, for the header count. Private forks are not counted, so their | ||
| 82 | + /// existence is not shown to viewers who cannot read them. | ||
| 83 | + pub forks: u64, | ||
| 84 | + /// The URL of the live stream the header follows (see `code_live`). A code view sets it to | ||
| 85 | + /// its branch's stream. Empty when the page has its own stream (a CI run or job), since the | ||
| 86 | + /// client follows the first stream on a page. | ||
| 87 | + pub live: String, | ||
| 81 | /// The pull mirror this repo follows, shown as the "Mirror of" line. `None` for other repos. | 88 | /// The pull mirror this repo follows, shown as the "Mirror of" line. `None` for other repos. |
| 82 | pub mirror: Option<MirrorSource>, | 89 | pub mirror: Option<MirrorSource>, |
| 83 | /// Whether the repo has discussions turned on, for the Discussions tab. | 90 | /// Whether the repo has discussions turned on, for the Discussions tab. |
| @@ -215,6 +222,7 @@ impl RepoCtx { | |||
| 215 | }), | 222 | }), |
| 216 | None => None, | 223 | None => None, |
| 217 | }; | 224 | }; |
| 225 | + let forks = fork_count(state, &self.repo.id).await?; | ||
| 218 | let discussions = state.store.discussions_enabled(&self.repo.id).await?; | 226 | let discussions = state.store.discussions_enabled(&self.repo.id).await?; |
| 219 | let wiki = state.store.wiki_enabled(&self.repo.id).await?; | 227 | let wiki = state.store.wiki_enabled(&self.repo.id).await?; |
| 220 | let security = | 228 | let security = |
| @@ -250,6 +258,8 @@ impl RepoCtx { | |||
| 250 | star, | 258 | star, |
| 251 | watchers, | 259 | watchers, |
| 252 | watch, | 260 | watch, |
| 261 | + forks, | ||
| 262 | + live: format!("/{}/{}/events", self.repo.owner_name, self.repo.name), | ||
| 253 | mirror, | 263 | mirror, |
| 254 | discussions, | 264 | discussions, |
| 255 | wiki, | 265 | wiki, |
| @@ -266,6 +276,16 @@ impl RepoCtx { | |||
| 266 | } | 276 | } |
| 267 | 277 | ||
| 268 | /// Load `owner/name` for the current viewer, or 404. | 278 | /// Load `owner/name` for the current viewer, or 404. |
| 279 | +/// The number of public forks of `repo_id`. Private forks are left out (see `RepoHead::forks`). | ||
| 280 | +pub async fn fork_count(state: &AppState, repo_id: &str) -> Result<u64> { | ||
| 281 | + let forks = state.store.list_forks(repo_id).await?; | ||
| 282 | + let public = forks | ||
| 283 | + .iter() | ||
| 284 | + .filter(|fork| fork.visibility == Visibility::Public) | ||
| 285 | + .count(); | ||
| 286 | + Ok(u64::try_from(public).unwrap_or(u64::MAX)) | ||
| 287 | +} | ||
| 288 | + | ||
| 269 | pub async fn load_repo(cx: &Cx, owner: &str, name: &str) -> Result<RepoCtx> { | 289 | pub async fn load_repo(cx: &Cx, owner: &str, name: &str) -> Result<RepoCtx> { |
| 270 | let state = app_context::<AppState>(cx); | 290 | let state = app_context::<AppState>(cx); |
| 271 | let viewer = current_user(cx).await?; | 291 | let viewer = current_user(cx).await?; |
crates/forge-web/src/pages/repo_rename.rsmodified+5 -1
| @@ -228,10 +228,12 @@ async fn rename_post(cx: &Cx, Form(form): Form<RenameForm>) -> Result<impl View> | |||
| 228 | .chars() | 228 | .chars() |
| 229 | .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-')) | 229 | .all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '_' | '-')) |
| 230 | { | 230 | { |
| 231 | - app_context::<AppState>(cx) | 231 | + let state = app_context::<AppState>(cx); |
| 232 | + state | ||
| 232 | .store | 233 | .store |
| 233 | .rename_repo(&ctx.repo.id, &new_name) | 234 | .rename_repo(&ctx.repo.id, &new_name) |
| 234 | .await | 235 | .await |
| 236 | + .inspect(|()| state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id)) | ||
| 235 | } else { | 237 | } else { |
| 236 | Err(CoreError::InvalidName(g::invalid_name(lang, &new_name))) | 238 | Err(CoreError::InvalidName(g::invalid_name(lang, &new_name))) |
| 237 | }; | 239 | }; |
| @@ -356,6 +358,8 @@ async fn transfer_post(cx: &Cx, Form(form): Form<TransferForm>) -> Result<impl V | |||
| 356 | } | 358 | } |
| 357 | match state.store.transfer_repo(&ctx.repo.id, &new_owner.id).await { | 359 | match state.store.transfer_repo(&ctx.repo.id, &new_owner.id).await { |
| 358 | Ok(()) => { | 360 | Ok(()) => { |
| 361 | + state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id); | ||
| 362 | + state.live.bump_repo(&new_owner.id, &ctx.repo.id); | ||
| 359 | tracing::info!( | 363 | tracing::info!( |
| 360 | actor_id = %user.id, | 364 | actor_id = %user.id, |
| 361 | repo_id = %ctx.repo.id, | 365 | repo_id = %ctx.repo.id, |
crates/forge-web/src/pages/repo_settings.rsmodified+5 -1
| @@ -802,6 +802,7 @@ async fn settings_general_save(cx: &Cx, Form(form): Form<GeneralForm>) -> Result | |||
| 802 | .store | 802 | .store |
| 803 | .update_repo_general(&ctx.repo.id, &description, &default_branch) | 803 | .update_repo_general(&ctx.repo.id, &description, &default_branch) |
| 804 | .await | 804 | .await |
| 805 | + .inspect(|()| state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id)) | ||
| 805 | { | 806 | { |
| 806 | if default_branch != ctx.repo.default_branch | 807 | if default_branch != ctx.repo.default_branch |
| 807 | && let Err(revert) = point_head(&state.git, &ctx.path, &ctx.repo.default_branch).await | 808 | && let Err(revert) = point_head(&state.git, &ctx.path, &ctx.repo.default_branch).await |
| @@ -851,6 +852,7 @@ async fn settings_visibility_save(cx: &Cx, Form(form): Form<VisibilityForm>) -> | |||
| 851 | .store | 852 | .store |
| 852 | .set_repo_visibility(&ctx.repo.id, target) | 853 | .set_repo_visibility(&ctx.repo.id, target) |
| 853 | .await?; | 854 | .await?; |
| 855 | + state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id); | ||
| 854 | tracing::info!( | 856 | tracing::info!( |
| 855 | actor_id = %user.id, | 857 | actor_id = %user.id, |
| 856 | repo_id = %ctx.repo.id, | 858 | repo_id = %ctx.repo.id, |
| @@ -982,7 +984,9 @@ async fn settings_delete(cx: &Cx, Form(form): Form<DeleteForm>) -> Result<impl V | |||
| 982 | }; | 984 | }; |
| 983 | // Release assets: their rows go with the repo, so their blob ids are read first. | 985 | // Release assets: their rows go with the repo, so their blob ids are read first. |
| 984 | let release_assets = state.store.repo_release_asset_ids(&repo.id).await?; | 986 | let release_assets = state.store.repo_release_asset_ids(&repo.id).await?; |
| 985 | - if let Err(e) = state.store.delete_repo(&repo.id).await { | 987 | + let deleted = state.store.delete_repo(&repo.id).await; |
| 988 | + state.live.bump_repo(&repo.owner_id, &repo.id); | ||
| 989 | + if let Err(e) = deleted { | ||
| 986 | if let Some(trash_path) = &trash_path | 990 | if let Some(trash_path) = &trash_path |
| 987 | && let Err(restore_err) = restore_from_trash(data_dir, trash_path, &repo.id).await | 991 | && let Err(restore_err) = restore_from_trash(data_dir, trash_path, &repo.id).await |
| 988 | { | 992 | { |
crates/forge-web/src/pages/star.rsmodified+3 -0
| @@ -47,6 +47,9 @@ async fn set_starred(cx: &Cx, csrf: &str, starred: bool) -> Result<SeeOther> { | |||
| 47 | } else { | 47 | } else { |
| 48 | state.store.unstar(&user.id, &ctx.repo.id).await?; | 48 | state.store.unstar(&user.id, &ctx.repo.id).await?; |
| 49 | } | 49 | } |
| 50 | + state.live.bump_repo(&ctx.repo.owner_id, &ctx.repo.id); | ||
| 51 | + // The starred tab of the starrer's profile counts the stars. | ||
| 52 | + state.live.bump(&crate::live::Topic::User(user.id.clone())); | ||
| 50 | let home = repo_href(&ctx.repo.owner_name, &ctx.repo.name, "", ""); | 53 | let home = repo_href(&ctx.repo.owner_name, &ctx.repo.name, "", ""); |
| 51 | Ok(see_other(return_path(cx).unwrap_or(home))) | 54 | Ok(see_other(return_path(cx).unwrap_or(home))) |
| 52 | } | 55 | } |
crates/forge-web/src/pages/tree.rsmodified+9 -3
| @@ -17,7 +17,7 @@ use topcoat::view::{Unescaped, View, component, view}; | |||
| 17 | 17 | ||
| 18 | use crate::i18n::code::{self as g, K}; | 18 | use crate::i18n::code::{self as g, K}; |
| 19 | use crate::i18n::{self, Lang}; | 19 | use crate::i18n::{self, Lang}; |
| 20 | -use crate::pages::code_live::live_url; | 20 | +use crate::pages::code_live::{follows_branch, live_url}; |
| 21 | use crate::pages::finder::file_finder; | 21 | use crate::pages::finder::file_finder; |
| 22 | use crate::pages::refs::{load_refs, ref_links}; | 22 | use crate::pages::refs::{load_refs, ref_links}; |
| 23 | use crate::pages::repo::repo_head; | 23 | use crate::pages::repo::repo_head; |
| @@ -548,14 +548,20 @@ async fn tree_page(cx: &Cx) -> Result<impl View> { | |||
| 548 | ctx.viewer_tz(), | 548 | ctx.viewer_tz(), |
| 549 | ); | 549 | ); |
| 550 | let (branches, tags) = ref_links(&refs, &ref_name, &repo.default_branch, repo); | 550 | let (branches, tags) = ref_links(&refs, &ref_name, &repo.default_branch, repo); |
| 551 | - let live = live_url(&repo.owner_name, &repo.name, &refs, &ref_name); | 551 | + let live = follows_branch(&refs, &ref_name) |
| 552 | + .then(|| live_url(&repo.owner_name, &repo.name, &refs, &ref_name)); | ||
| 552 | 553 | ||
| 553 | let title = format!("{}/{}", repo.owner_name, repo.name); | 554 | let title = format!("{}/{}", repo.owner_name, repo.name); |
| 554 | let crumbs = path_crumbs(repo, &ref_name, "tree", &dir); | 555 | let crumbs = path_crumbs(repo, &ref_name, "tree", &dir); |
| 555 | let finder_owner = repo.owner_name.clone(); | 556 | let finder_owner = repo.owner_name.clone(); |
| 556 | let finder_repo = repo.name.clone(); | 557 | let finder_repo = repo.name.clone(); |
| 557 | let finder_ref = ref_name.clone(); | 558 | let finder_ref = ref_name.clone(); |
| 558 | - let header = ctx.head(state, "code").await?; | 559 | + let mut header = ctx.head(state, "code").await?; |
| 560 | + // The header and the browse bar share the branch's stream: the client follows the first | ||
| 561 | + // [data-live] on the page, which is the header. | ||
| 562 | + if let Some(url) = &live { | ||
| 563 | + header.live = url.clone(); | ||
| 564 | + } | ||
| 559 | Ok(view! { | 565 | Ok(view! { |
| 560 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), | 566 | shell(title: title.as_str(), viewer: ctx.viewer.as_ref(), |
| 561 | repo_head(head: header) | 567 | repo_head(head: header) |
crates/forge-web/src/post_update.rsmodified+6 -0
| @@ -45,6 +45,12 @@ pub async fn after_ref_update( | |||
| 45 | state | 45 | state |
| 46 | .live | 46 | .live |
| 47 | .bump(&crate::live::Topic::RepoRefs(repo.id.clone())); | 47 | .bump(&crate::live::Topic::RepoRefs(repo.id.clone())); |
| 48 | + // The pusher's contribution calendar (dashboard and profile) counts the push. | ||
| 49 | + if !actor_id.is_empty() { | ||
| 50 | + state | ||
| 51 | + .live | ||
| 52 | + .bump(&crate::live::Topic::User(actor_id.to_owned())); | ||
| 53 | + } | ||
| 48 | crate::ci::on_ref_update(state, repo, actor_id, refname, new).await; | 54 | crate::ci::on_ref_update(state, repo, actor_id, refname, new).await; |
| 49 | if (refname.starts_with("refs/heads/") || refname.starts_with("refs/tags/")) | 55 | if (refname.starts_with("refs/heads/") || refname.starts_with("refs/tags/")) |
| 50 | && let Err(e) = crate::mirrors::enqueue_push_mirrors(state, &repo.id).await | 56 | && let Err(e) = crate::mirrors::enqueue_push_mirrors(state, &repo.id).await |
crates/forge-web/tests/browse_e2e.rsmodified+105 -5
| @@ -688,7 +688,7 @@ async fn code_view_stream_follows_pushes() { | |||
| 688 | assert!( | 688 | assert!( |
| 689 | branch_page | 689 | branch_page |
| 690 | .body() | 690 | .body() |
| 691 | - .contains(r#"data-live="/tahinli/pub/code/events?ref_name=main""#), | 691 | + .contains(r#"data-live="/tahinli/pub/events?ref_name=main""#), |
| 692 | "branch page follows main" | 692 | "branch page follows main" |
| 693 | ); | 693 | ); |
| 694 | let commit_page = http | 694 | let commit_page = http |
| @@ -696,12 +696,18 @@ async fn code_view_stream_follows_pushes() { | |||
| 696 | .await; | 696 | .await; |
| 697 | assert_eq!(commit_page.status, 200); | 697 | assert_eq!(commit_page.status, 200); |
| 698 | assert!( | 698 | assert!( |
| 699 | - !commit_page.body().contains("data-live="), | 699 | + commit_page |
| 700 | - "a commit page does not follow" | 700 | + .body() |
| 701 | + .contains(r#"data-live="/tahinli/pub/events""#), | ||
| 702 | + "a commit page follows the repo header" | ||
| 703 | + ); | ||
| 704 | + assert!( | ||
| 705 | + !commit_page.body().contains("events?ref_name="), | ||
| 706 | + "a commit page does not follow a branch" | ||
| 701 | ); | 707 | ); |
| 702 | 708 | ||
| 703 | // Anyone can follow a public branch. | 709 | // Anyone can follow a public branch. |
| 704 | - let mut stream = open_stream(&http, "/tahinli/pub/code/events?ref_name=main", None).await; | 710 | + let mut stream = open_stream(&http, "/tahinli/pub/events?ref_name=main", None).await; |
| 705 | assert_eq!(stream.status().as_u16(), 200); | 711 | assert_eq!(stream.status().as_u16(), 200); |
| 706 | assert_eq!( | 712 | assert_eq!( |
| 707 | stream.headers().get(CONTENT_TYPE).unwrap(), | 713 | stream.headers().get(CONTENT_TYPE).unwrap(), |
| @@ -752,7 +758,7 @@ async fn code_view_stream_follows_pushes() { | |||
| 752 | assert!(deleted.contains("event: changed"), "{deleted}"); | 758 | assert!(deleted.contains("event: changed"), "{deleted}"); |
| 753 | 759 | ||
| 754 | // A private repo streams only to a viewer who can read it. | 760 | // A private repo streams only to a viewer who can read it. |
| 755 | - let private = "/tahinli/priv/code/events?ref_name=main"; | 761 | + let private = "/tahinli/priv/events?ref_name=main"; |
| 756 | let anonymous = open_stream(&http, private, None).await; | 762 | let anonymous = open_stream(&http, private, None).await; |
| 757 | assert_eq!( | 763 | assert_eq!( |
| 758 | anonymous.status().as_u16(), | 764 | anonymous.status().as_u16(), |
| @@ -914,3 +920,97 @@ async fn issue_streams_follow_writes() { | |||
| 914 | let member = open_stream(&http, "/tahinli/priv/issues/live", Some(tahinli.as_str())).await; | 920 | let member = open_stream(&http, "/tahinli/priv/issues/live", Some(tahinli.as_str())).await; |
| 915 | assert_eq!(member.status().as_u16(), 200, "private list for its owner"); | 921 | assert_eq!(member.status().as_u16(), 200, "private list for its owner"); |
| 916 | } | 922 | } |
| 923 | + | ||
| 924 | + | ||
| 925 | +#[tokio::test] | ||
| 926 | +async fn browsing_pages_stream_their_changes() { | ||
| 927 | + if !tool_on_path("git") { | ||
| 928 | + eprintln!("SKIP browse_e2e: `git` was not found on PATH, so the stream test is skipped"); | ||
| 929 | + return; | ||
| 930 | + } | ||
| 931 | + | ||
| 932 | + let root = tempfile::Builder::new() | ||
| 933 | + .prefix("flive") | ||
| 934 | + .tempdir_in("/tmp") | ||
| 935 | + .expect("temp dir"); | ||
| 936 | + let dir = root.path().to_path_buf(); | ||
| 937 | + let ports = pick_ports(); | ||
| 938 | + let config = write_config(&dir, ports); | ||
| 939 | + run_admin(&config, "tahinli", &["--admin"], TAHINLI_PW); | ||
| 940 | + let (_server, ports) = launch(&dir, ports).await; | ||
| 941 | + let http = Http::new(ports.http); | ||
| 942 | + | ||
| 943 | + let tahinli = login(&http, "tahinli", TAHINLI_PW).await; | ||
| 944 | + let token = create_token(&http, &tahinli, "live-pages-token").await; | ||
| 945 | + create_repo(&http, &tahinli, "pub", "public").await; | ||
| 946 | + let pub_url = format!( | ||
| 947 | + "http://tahinli:{token}@127.0.0.1:{}/tahinli/pub.git", | ||
| 948 | + ports.http | ||
| 949 | + ); | ||
| 950 | + let pushed = push_fixtures(&dir, &pub_url, &dir.join("pub-pages")); | ||
| 951 | + | ||
| 952 | + // The inbox, the dashboard and the header need a session. Without one they refuse, and no URL | ||
| 953 | + // names another user's inbox: the viewer always comes from the session. | ||
| 954 | + for path in [ | ||
| 955 | + "/notifications/events", | ||
| 956 | + "/notifications/events?all=1&user=tahinli", | ||
| 957 | + "/dashboard/events", | ||
| 958 | + ] { | ||
| 959 | + let anonymous = open_stream(&http, path, None).await; | ||
| 960 | + assert_eq!(anonymous.status().as_u16(), 401, "anonymous {path}"); | ||
| 961 | + } | ||
| 962 | + let inbox = open_stream(&http, "/notifications/events", Some(tahinli.as_str())).await; | ||
| 963 | + assert_eq!(inbox.status().as_u16(), 200, "inbox stream for its owner"); | ||
| 964 | + | ||
| 965 | + // The header of a public repo streams to anyone. A star moves its count for every viewer. | ||
| 966 | + let mut header = open_stream(&http, "/tahinli/pub/events", None).await; | ||
| 967 | + assert_eq!(header.status().as_u16(), 200); | ||
| 968 | + let page = http.get("/tahinli/pub", Some(&tahinli)).await; | ||
| 969 | + let csrf = input_value(&page.body(), "csrf"); | ||
| 970 | + let star = http | ||
| 971 | + .post_form("/tahinli/pub/star", &[("csrf", &csrf)], Some(&tahinli)) | ||
| 972 | + .await; | ||
| 973 | + assert_eq!(star.status, 303, "star: {}", star.body()); | ||
| 974 | + let event = next_chunk(&mut header).await.expect("event for a star"); | ||
| 975 | + assert!(event.contains("event: changed"), "{event}"); | ||
| 976 | + let shown = http.get("/tahinli/pub", None).await; | ||
| 977 | + assert!( | ||
| 978 | + shown.body().contains("\u{2605} 1"), | ||
| 979 | + "the header shows the star" | ||
| 980 | + ); | ||
| 981 | + | ||
| 982 | + // A push moves the pusher's calendar on the dashboard. The dashboard streams to its owner only. | ||
| 983 | + let mut dashboard = open_stream(&http, "/dashboard/events", Some(tahinli.as_str())).await; | ||
| 984 | + assert_eq!(dashboard.status().as_u16(), 200); | ||
| 985 | + let work = dir.join("pub-pages"); | ||
| 986 | + // push_fixtures leaves the clone on feature/x, so the new commit must go on main. | ||
| 987 | + ok(&git(&work, &["checkout", "-q", "main"]), "checkout main"); | ||
| 988 | + fs::write(work.join("PUSH.txt"), "pushed again\n").expect("write PUSH.txt"); | ||
| 989 | + commit_all(&work, "a second push"); | ||
| 990 | + ok(&git(&work, &["push", "-q", "origin", "main"]), "push main"); | ||
| 991 | + let pushed_event = next_chunk(&mut dashboard) | ||
| 992 | + .await | ||
| 993 | + .expect("event for the push"); | ||
| 994 | + assert!(pushed_event.contains("event: changed"), "{pushed_event}"); | ||
| 995 | + assert_ne!(pushed, head_sha(&work), "the second push moved main"); | ||
| 996 | + | ||
| 997 | + // The explore listing streams to anyone, and a new public repo changes it. | ||
| 998 | + let mut explore = open_stream(&http, "/explore/events", None).await; | ||
| 999 | + assert_eq!(explore.status().as_u16(), 200); | ||
| 1000 | + create_repo(&http, &tahinli, "lib", "public").await; | ||
| 1001 | + let listed = next_chunk(&mut explore) | ||
| 1002 | + .await | ||
| 1003 | + .expect("event for a new public repo"); | ||
| 1004 | + assert!(listed.contains("event: changed"), "{listed}"); | ||
| 1005 | + | ||
| 1006 | + // The profile streams to anyone, and an unknown name is not found. | ||
| 1007 | + let mut profile = open_stream(&http, "/users/tahinli/events", None).await; | ||
| 1008 | + assert_eq!(profile.status().as_u16(), 200); | ||
| 1009 | + create_repo(&http, &tahinli, "tools", "public").await; | ||
| 1010 | + let changed = next_chunk(&mut profile) | ||
| 1011 | + .await | ||
| 1012 | + .expect("event for a new repo of the profile"); | ||
| 1013 | + assert!(changed.contains("event: changed"), "{changed}"); | ||
| 1014 | + let missing = open_stream(&http, "/users/nobody/events", None).await; | ||
| 1015 | + assert_eq!(missing.status().as_u16(), 404, "profile of an unknown user"); | ||
| 1016 | +} | ||
docs/architecture.mdmodified+16 -3
| @@ -246,9 +246,22 @@ Topcoat's builder-wide compression is off on the public router, so it cannot com | |||
| 246 | 246 | ||
| 247 | Content types outside the list (`application/x-git-*`, `application/octet-stream`, archives, images) are never compressed. The raw user-content listener has compression off because its ETag and Content-Length must match the stored bytes. | 247 | Content types outside the list (`application/x-git-*`, `application/octet-stream`, archives, images) are never compressed. The raw user-content listener has compression off because its ETag and Content-Length must match the stored bytes. |
| 248 | 248 | ||
| 249 | -### Live pages | 249 | +### 5.7 Live pages |
| 250 | - | 250 | + |
| 251 | -A page that shows changing state renders `data-live="<stream URL>"`. The browser opens one EventSource for it (`assets/nav.js`). The server bumps a topic in `LiveHub` (`crates/forge-web/src/live.rs`) after each successful write, and the stream sends one `changed` event per wake. The page then re-renders in place, with the scroll, open dropdowns and the text and caret of every edited field kept. Nothing polls. Issue pages follow two topics: the repo's issues (the list, labels, milestones and tabs) and the one issue. A stream checks the same read permission as its page, so a private repo answers 404 to a viewer who cannot read it. The code view follows its branch and the refs of its repo. Pull request pages do not follow yet. | 251 | +Pages update without a reload. A write that changes what a page shows calls `LiveHub::bump` on a topic (`crates/forge-web/src/live.rs`). The page's stream sends one `changed` event, and `nav.js` re-fetches the page in place. The event carries no data and nothing polls. Each stream re-reads a short fingerprint of its page on a wake and sends only when it differs. |
| 252 | + | ||
| 253 | +| Page | Stream | Topics it follows | | ||
| 254 | +| --- | --- | --- | | ||
| 255 | +| Every repo page (header counts) | `/{owner}/{repo}/events`, with `?ref_name=` on a branch code view | the repo (stars, watchers, forks, name, description, visibility); on a branch, the repo's refs | | ||
| 256 | +| Inbox `/notifications` | `/notifications/events`, with `?all=1` on the All tab | the viewer's inbox | | ||
| 257 | +| Dashboard `/` | `/dashboard/events` | the viewer's user topic (repos, pushes, repo changes) and inbox | | ||
| 258 | +| Profile `/{username}` | `/users/{username}/events` | the owner's user topic (repos, stars, pins, pushes by the owner) | | ||
| 259 | +| Code view `/{owner}/{repo}/...` | `/{owner}/{repo}/events`, with `?ref_name=` on a branch code view | the repo (header counts); on a branch, the repo refs | | ||
| 260 | +| Issues `/{owner}/{repo}/issues` and an issue | `/{owner}/{repo}/issues/live`, `/{owner}/{repo}/issues/{number}/live` | the repo issues (list, labels, milestones, tabs) and the one issue | | ||
| 261 | +| Pull requests `/{owner}/{repo}/pulls` and a pull | `/{owner}/{repo}/pulls/events`, `/{owner}/{repo}/pulls/{number}/events` | the repo pull list, and the one pull (conversation, commits, files) | | ||
| 262 | +| Explore `/explore` | `/explore/events`, with the search, sort and page | the public listing | | ||
| 263 | + | ||
| 264 | +The user topics are keyed by user id, and their streams take the viewer from the session, so no URL names another user's inbox. Repo streams follow the same visibility as the repo page (a private repo answers 404 to a viewer who cannot read it). Explore lists public repos only. | ||
| 252 | 265 | ||
| 253 | ## 6. Authorization model | 266 | ## 6. Authorization model |
| 254 | 267 | ||