forge
Explore
Log in

Don't you dare go Hollow

The discussion list and each discussion page update live

Browse files at this commit

8122bc8891b1872ca85eb119ebdaf5cb820edbefAhmet Kaan GümüşParent: a2b0fed
  • feat
    • the discussion list and each discussion page update live
Show full message
⚡ feat: the discussion list and each discussion page update live
crates/forge-web/src/boot.rsmodified+1 -0
@@ -169,6 +169,7 @@ pub async fn serve(
169 .layer(crate::pages::settings_profile::avatar_body_limit())169 .layer(crate::pages::settings_profile::avatar_body_limit())
170 .layer(crate::pages::repo_ctx::RepoMovedLayer)170 .layer(crate::pages::repo_ctx::RepoMovedLayer)
171 .layer(crate::pages::pull_live::PullWriteLayer)171 .layer(crate::pages::pull_live::PullWriteLayer)
172+ .layer(crate::pages::discussion_live::DiscussionWriteLayer)
172 .layer(crate::pages::not_found_page::NotFoundLayer)173 .layer(crate::pages::not_found_page::NotFoundLayer)
173 .layer(TowerLayer::new(crate::compression::ResponseCompression))174 .layer(TowerLayer::new(crate::compression::ResponseCompression))
174 .compression(Compression::off())175 .compression(Compression::off())
crates/forge-web/src/live.rsmodified+7 -0
@@ -63,6 +63,13 @@ pub enum Topic {
63 Inbox(String),63 Inbox(String),
64 /// The public repo listing: a public repo was added, changed, or starred. Global.64 /// The public repo listing: a public repo was added, changed, or starred. Global.
65 Explore,65 Explore,
66+ /// The discussions of a repo as a list: a discussion was opened, or any discussion of the repo
67+ /// changed (a comment, a reaction, an answer, a lock, a category). Keyed by repo id. Bumped by
68+ /// [`crate::pages::discussion_live`].
69+ Discussions(String),
70+ /// One discussion: its body, comments, reactions, answer and lock state. Keyed by discussion
71+ /// id. Bumped by [`crate::pages::discussion_live`].
72+ Discussion(String),
66 }73 }
67 74
68 /// The open topics, each with the counter its subscribers wait on.75 /// The open topics, each with the counter its subscribers wait on.
crates/forge-web/src/pages/discussion_live.rsadded+155 -0
@@ -0,0 +1,155 @@
1+//! Live discussions. The discussion list (`/{o}/{r}/discussions`) follows [`Topic::Discussions`];
2+//! a discussion page follows [`Topic::Discussion`]. Both pages render `data-live` with the URL of
3+//! their stream, and a `changed` event re-renders them in place (see `nav.js`). The reply box and
4+//! the other fields keep what was typed, since `nav.js` captures the fields before the swap.
5+//!
6+//! Every discussion write is a POST under `/{o}/{r}/discussions/...`, or the discussions toggle in
7+//! the repo settings. [`DiscussionWriteLayer`] bumps after the handler ran, so no route calls a
8+//! bump itself. The topics are resolved before the handler, so a write that deletes the discussion
9+//! still wakes its page, which then shows the 404 the page now gives.
10+//!
11+//! Both streams take the page's own read check: the repo read check, and the discussions toggle
12+//! (a repo with discussions off is 404 on every page). The item stream also 404s on a discussion
13+//! that is not there.
14+
15+use topcoat::Result;
16+use topcoat::context::{Cx, app_context};
17+use topcoat::router::request::{method, uri};
18+use topcoat::router::response::Response;
19+use topcoat::router::{Body, Layer, LayerFuture, Method, Next, Path, path_param, route};
20+
21+use crate::live::{Topic, stream_wakes};
22+use crate::pages::discussions::{discussion_by_number, ensure_enabled};
23+use crate::pages::repo_ctx::load_repo;
24+use crate::state::AppState;
25+
26+path_param!(owner);
27+path_param!(repo);
28+path_param!(number);
29+
30+/// The stream URL of the discussion list of `owner/repo`.
31+pub fn list_live_url(owner: &str, repo: &str) -> String {
32+ format!("/{owner}/{repo}/discussions/live")
33+}
34+
35+/// The stream URL of one discussion, for its page.
36+pub fn item_live_url(owner: &str, repo: &str, number: i64) -> String {
37+ format!("/{owner}/{repo}/discussions/{number}/live")
38+}
39+
40+/// The change stream of the discussion list.
41+#[route(GET "/{owner}/{repo}/discussions/live")]
42+async fn discussions_live(cx: &Cx) -> Result<Response> {
43+ let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
44+ let state = app_context::<AppState>(cx);
45+ ensure_enabled(state, &ctx).await?;
46+ stream_wakes(cx, &state.live, &[Topic::Discussions(ctx.repo.id.clone())])
47+}
48+
49+/// The change stream of one discussion page.
50+#[route(GET "/{owner}/{repo}/discussions/{number}/live")]
51+async fn discussion_live(cx: &Cx) -> Result<Response> {
52+ let ctx = load_repo(cx, path_param::<Owner>(cx), path_param::<Repo>(cx)).await?;
53+ let state = app_context::<AppState>(cx);
54+ ensure_enabled(state, &ctx).await?;
55+ let discussion = discussion_by_number(state, &ctx, path_param::<Number>(cx)).await?;
56+ stream_wakes(cx, &state.live, &[Topic::Discussion(discussion.id.clone())])
57+}
58+
59+// The write layer
60+
61+/// Which topics a discussion write reaches.
62+enum Written {
63+ /// A new discussion, or the discussions toggle of the repo settings: the list.
64+ List { owner: String, repo: String },
65+ /// A write to one discussion (`/{o}/{r}/discussions/{n}/...`): the list and the discussion.
66+ Discussion {
67+ owner: String,
68+ repo: String,
69+ number: String,
70+ },
71+}
72+
73+/// The write a request makes to the discussion side, when it is a POST that can change one.
74+fn written(cx: &Cx) -> Option<Written> {
75+ if *method(cx) != Method::POST {
76+ return None;
77+ }
78+ let path = uri(cx).path().to_owned();
79+ let parts: Vec<&str> = path.trim_start_matches('/').split('/').collect();
80+ let [owner, repo, kind, rest @ ..] = parts.as_slice() else {
81+ return None;
82+ };
83+ let (owner, repo) = ((*owner).to_owned(), (*repo).to_owned());
84+ match (*kind, rest) {
85+ ("discussions", ["new"]) => Some(Written::List { owner, repo }),
86+ ("discussions", [number, ..]) => Some(Written::Discussion {
87+ owner,
88+ repo,
89+ number: (*number).to_owned(),
90+ }),
91+ ("settings", ["discussions"]) => Some(Written::List { owner, repo }),
92+ _ => None,
93+ }
94+}
95+
96+/// The topics a write reaches, looked up before the handler runs. A repo or discussion that does
97+/// not exist yields nothing, and a failed lookup is logged.
98+async fn topics_of(state: &AppState, target: Written) -> Vec<Topic> {
99+ let (owner, name) = match &target {
100+ Written::List { owner, repo } | Written::Discussion { owner, repo, .. } => {
101+ (owner.as_str(), repo.as_str())
102+ }
103+ };
104+ let repo = match state.store.repo_by_owner_and_name(owner, name).await {
105+ Ok(Some(repo)) => repo,
106+ Ok(None) => return Vec::new(),
107+ Err(e) => {
108+ tracing::error!(error = %e, owner, name, "live: loading the repo to bump failed");
109+ return Vec::new();
110+ }
111+ };
112+ let mut topics = vec![Topic::Discussions(repo.id.clone())];
113+ if let Written::Discussion { number, .. } = target
114+ && let Ok(number) = number.parse::<i64>()
115+ {
116+ match state.store.discussion_by_number(&repo.id, number).await {
117+ Ok(Some(discussion)) => topics.push(Topic::Discussion(discussion.id)),
118+ Ok(None) => {}
119+ Err(e) => {
120+ tracing::error!(error = %e, number, "live: loading the discussion to bump failed")
121+ }
122+ }
123+ }
124+ topics
125+}
126+
127+/// Bumps the topics a write reaches, once the handler has run. The handler's result passes
128+/// through unchanged, so a refused write (an error or a redirect) bumps too: the page re-reads and
129+/// agrees.
130+async fn bump_after_write(cx: &Cx, body: Body, next: Next<'_>) -> topcoat::Result<Response> {
131+ let state = app_context::<AppState>(cx);
132+ let topics = match written(cx) {
133+ Some(target) => topics_of(state, target).await,
134+ None => Vec::new(),
135+ };
136+ let result = next.run(cx, body).await;
137+ for topic in &topics {
138+ state.live.bump(topic);
139+ }
140+ result
141+}
142+
143+/// Wraps every request. Only a POST under the discussions paths, or the discussions settings
144+/// toggle, does anything. Registered on the public router in `boot.rs`, next to the other layers.
145+pub struct DiscussionWriteLayer;
146+
147+impl Layer for DiscussionWriteLayer {
148+ fn path(&self) -> Option<&Path> {
149+ None
150+ }
151+
152+ fn handle<'a>(&'a self, cx: &'a Cx, body: Body, next: Next<'a>) -> LayerFuture<'a> {
153+ Box::pin(bump_after_write(cx, body, next))
154+ }
155+}
crates/forge-web/src/pages/discussion_live_tests.rsadded+249 -0
@@ -0,0 +1,249 @@
1+//! Router-level tests for the discussion live streams: a write bumps the topics it reaches, and a
2+//! viewer without read access (or a repo with discussions off) gets 404 from a stream.
3+
4+use std::sync::Arc;
5+
6+use forge_core::discussions::DiscussionCategory;
7+use forge_core::{Store, Visibility};
8+use topcoat::router::request::Request;
9+use topcoat::router::{Body, Router, to_bytes};
10+
11+use crate::auth::SESSION_COOKIE;
12+use crate::live::{LiveHub, Topic};
13+
14+const CSRF: &str = "discussion-live-csrf";
15+
16+struct Site {
17+ router: Router,
18+ store: Store,
19+ live: Arc<LiveHub>,
20+ _dir: tempfile::TempDir,
21+}
22+
23+async fn site() -> Site {
24+ let dir = tempfile::tempdir().expect("tempdir");
25+ let state = crate::test_support::test_state(dir.path()).await;
26+ let store = state.store.clone();
27+ let live = state.live.clone();
28+ let router = crate::test_support::app_router(state);
29+ Site {
30+ router,
31+ store,
32+ live,
33+ _dir: dir,
34+ }
35+}
36+
37+async fn sign_in(store: &Store, user_id: &str, token: &str) -> String {
38+ crate::test_support::create_session(store, user_id, token, CSRF).await;
39+ format!("__Host-{SESSION_COOKIE}={token}")
40+}
41+
42+/// Sends a form POST and returns its status. The body is read, so the write has finished.
43+async fn post(site: &Site, uri: &str, cookie: &str, fields: &[(&str, &str)]) -> u16 {
44+ let body = Body::from(
45+ form_urlencoded::Serializer::new(String::new())
46+ .extend_pairs(fields)
47+ .finish(),
48+ );
49+ let request = Request::builder()
50+ .method("POST")
51+ .uri(uri)
52+ .header("cookie", cookie)
53+ .header("content-type", "application/x-www-form-urlencoded")
54+ .body(body)
55+ .expect("request");
56+ let res = site.router.handle(request).await;
57+ let status = res.status().as_u16();
58+ to_bytes(res.into_body(), usize::MAX).await.expect("body");
59+ status
60+}
61+
62+/// The status of a stream request. The stream body is not read: it never ends on its own.
63+async fn stream_status(site: &Site, uri: &str, cookie: Option<&str>) -> u16 {
64+ let mut builder = Request::builder().method("GET").uri(uri);
65+ if let Some(cookie) = cookie {
66+ builder = builder.header("cookie", cookie);
67+ }
68+ let res = site
69+ .router
70+ .handle(builder.body(Body::empty()).expect("request"))
71+ .await;
72+ res.status().as_u16()
73+}
74+
75+struct Seed {
76+ site: Site,
77+ owner_cookie: String,
78+ bob_cookie: String,
79+ repo_id: String,
80+ discussion_id: String,
81+}
82+
83+/// Tahinli owns `tahinli/forge` with discussions on and one discussion, number 1. Bob signs in
84+/// with no role on the repo.
85+async fn seeded(visibility: Visibility) -> Seed {
86+ let site = site().await;
87+ let store = site.store.clone();
88+ let tahinli = store
89+ .create_user("tahinli", None, "unused", false)
90+ .await
91+ .expect("tahinli");
92+ let bob = store
93+ .create_user("bob", None, "unused", false)
94+ .await
95+ .expect("bob");
96+ let repo = store
97+ .create_repo(&tahinli.id, "forge", "", visibility, "main")
98+ .await
99+ .expect("repo");
100+ store
101+ .set_discussions_enabled(&repo.id, true)
102+ .await
103+ .expect("enable");
104+ let discussion = store
105+ .create_discussion(
106+ &repo.id,
107+ &tahinli.id,
108+ DiscussionCategory::General,
109+ "Hello",
110+ "Body",
111+ )
112+ .await
113+ .expect("discussion");
114+ let owner_cookie = sign_in(&store, &tahinli.id, "owner-token").await;
115+ let bob_cookie = sign_in(&store, &bob.id, "bob-token").await;
116+ Seed {
117+ site,
118+ owner_cookie,
119+ bob_cookie,
120+ repo_id: repo.id,
121+ discussion_id: discussion.id,
122+ }
123+}
124+
125+#[tokio::test]
126+async fn a_comment_bumps_the_list_and_the_discussion_only() {
127+ let seed = seeded(Visibility::Public).await;
128+ let site = &seed.site;
129+ let list = site
130+ .live
131+ .subscribe(&Topic::Discussions(seed.repo_id.clone()));
132+ let item = site
133+ .live
134+ .subscribe(&Topic::Discussion(seed.discussion_id.clone()));
135+ let other = site.live.subscribe(&Topic::Discussion("other".to_owned()));
136+
137+ let status = post(
138+ site,
139+ "/tahinli/forge/discussions/1/comments",
140+ &seed.owner_cookie,
141+ &[("csrf", CSRF), ("body", "A reply")],
142+ )
143+ .await;
144+
145+ assert_ne!(status, 404, "the comment was refused");
146+ let comments = site
147+ .store
148+ .list_discussion_comments(&seed.discussion_id)
149+ .await
150+ .expect("comments");
151+ assert_eq!(comments.len(), 1, "the comment was stored");
152+ assert!(list.has_changed().expect("open"), "the list was bumped");
153+ assert!(
154+ item.has_changed().expect("open"),
155+ "the discussion was bumped"
156+ );
157+ assert!(!other.has_changed().expect("open"));
158+}
159+
160+#[tokio::test]
161+async fn a_new_discussion_bumps_the_list() {
162+ let seed = seeded(Visibility::Public).await;
163+ let site = &seed.site;
164+ let list = site
165+ .live
166+ .subscribe(&Topic::Discussions(seed.repo_id.clone()));
167+ let category = DiscussionCategory::General.as_str();
168+
169+ let status = post(
170+ site,
171+ "/tahinli/forge/discussions/new",
172+ &seed.owner_cookie,
173+ &[
174+ ("csrf", CSRF),
175+ ("category", category),
176+ ("title", "Another"),
177+ ("body", "Text"),
178+ ],
179+ )
180+ .await;
181+
182+ assert_ne!(status, 404, "the discussion was refused");
183+ assert!(list.has_changed().expect("open"), "the list was bumped");
184+}
185+
186+#[tokio::test]
187+async fn a_refused_write_still_bumps_so_the_page_reads_the_truth() {
188+ let seed = seeded(Visibility::Public).await;
189+ let site = &seed.site;
190+ let item = site
191+ .live
192+ .subscribe(&Topic::Discussion(seed.discussion_id.clone()));
193+
194+ // A blank comment is refused by the handler. The write layer bumps after the handler either way.
195+ let status = post(
196+ site,
197+ "/tahinli/forge/discussions/1/comments",
198+ &seed.bob_cookie,
199+ &[("csrf", CSRF), ("body", "")],
200+ )
201+ .await;
202+
203+ assert_ne!(status, 404, "the discussion page answered");
204+ assert!(
205+ item.has_changed().expect("open"),
206+ "the discussion was bumped"
207+ );
208+}
209+
210+#[tokio::test]
211+async fn streams_follow_the_page_read_check() {
212+ let seed = seeded(Visibility::Private).await;
213+ let site = &seed.site;
214+ let list = "/tahinli/forge/discussions/live";
215+ let item = "/tahinli/forge/discussions/1/live";
216+
217+ assert_eq!(stream_status(site, list, None).await, 404, "anonymous list");
218+ assert_eq!(stream_status(site, item, None).await, 404, "anonymous item");
219+ assert_eq!(
220+ stream_status(site, list, Some(&seed.bob_cookie)).await,
221+ 404,
222+ "bob, no access, list"
223+ );
224+ assert_eq!(
225+ stream_status(site, item, Some(&seed.bob_cookie)).await,
226+ 404,
227+ "bob, no access, item"
228+ );
229+ assert_eq!(
230+ stream_status(site, list, Some(&seed.owner_cookie)).await,
231+ 200,
232+ "owner, list"
233+ );
234+ assert_eq!(
235+ stream_status(site, item, Some(&seed.owner_cookie)).await,
236+ 200,
237+ "owner, item"
238+ );
239+ assert_eq!(
240+ stream_status(
241+ site,
242+ "/tahinli/forge/discussions/9/live",
243+ Some(&seed.owner_cookie)
244+ )
245+ .await,
246+ 404,
247+ "a discussion that is not there"
248+ );
249+}
crates/forge-web/src/pages/discussion_view.rsmodified+3 -1
@@ -14,6 +14,7 @@ use topcoat::view::{Unescaped, View, component, view};
14 14
15 use crate::i18n::community::{self as g, K};15 use crate::i18n::community::{self as g, K};
16 use crate::i18n::{self, Lang};16 use crate::i18n::{self, Lang};
17+use crate::pages::discussion_live::item_live_url;
17 use crate::pages::discussions::{18 use crate::pages::discussions::{
18 discussion_by_number, discussions_href, ensure_enabled, is_author, may_converse,19 discussion_by_number, discussions_href, ensure_enabled, is_author, may_converse,
19 };20 };
@@ -395,13 +396,14 @@ async fn discussion_page(
395 let page_title = format!("{} {number_label} \u{b7} {owner}/{name}", discussion.title);396 let page_title = format!("{} {number_label} \u{b7} {owner}/{name}", discussion.title);
396 let login_href = "/login".to_owned();397 let login_href = "/login".to_owned();
397 let lock_notice = g::t(lang, K::LockedNotice);398 let lock_notice = g::t(lang, K::LockedNotice);
399+ let live_href = item_live_url(&owner, &name, number);
398 let header = ctx.head(state, "discussions").await?;400 let header = ctx.head(state, "discussions").await?;
399 401
400 let comments_label = g::comments_total(lang, discussion.comment_count);402 let comments_label = g::comments_total(lang, discussion.comment_count);
401 Ok(view! { cx =>403 Ok(view! { cx =>
402 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),404 shell(title: page_title.as_str(), viewer: ctx.viewer.as_ref(),
403 repo_head(head: header)405 repo_head(head: header)
404- <section class="issue-head">406+ <section class="issue-head" data-live=(live_href.as_str()) data-live-now="">
405 <h1 class="issue-heading">(discussion.title.as_str()) " " <span class="issue-number">(number_label.as_str())</span></h1>407 <h1 class="issue-heading">(discussion.title.as_str()) " " <span class="issue-number">(number_label.as_str())</span></h1>
406 <p class="issue-byline">408 <p class="issue-byline">
407 <span class="discussion-category">(category)</span>409 <span class="discussion-category">(category)</span>
crates/forge-web/src/pages/discussions.rsmodified+3 -1
@@ -19,6 +19,7 @@ use crate::audit::{self, Actor, Target};
19 use crate::auth::{require_csrf, require_user};19 use crate::auth::{require_csrf, require_user};
20 use crate::i18n::community::{self as g, K};20 use crate::i18n::community::{self as g, K};
21 use crate::i18n::{self, Lang};21 use crate::i18n::{self, Lang};
22+use crate::pages::discussion_live::list_live_url;
22 use crate::pages::issue_meta::{can_triage, form_field, form_pairs, refusal_message};23 use crate::pages::issue_meta::{can_triage, form_field, form_pairs, refusal_message};
23 use crate::pages::issue_parts::When;24 use crate::pages::issue_parts::When;
24 use crate::pages::issues_list::{list_href, state_tab_class};25 use crate::pages::issues_list::{list_href, state_tab_class};
@@ -286,6 +287,7 @@ async fn discussions_list_page(cx: &Cx) -> Result<impl View> {
286 let page_label = g::page_number(lang, page);287 let page_label = g::page_number(lang, page);
287 288
288 let can_start = ctx.viewer.is_some() && !ctx.repo.archived;289 let can_start = ctx.viewer.is_some() && !ctx.repo.archived;
290+ let live_href = list_live_url(&owner_name, &repo_name);
289 let new_href = discussions_href(&owner_name, &repo_name, "new");291 let new_href = discussions_href(&owner_name, &repo_name, "new");
290 let title = format!(292 let title = format!(
291 "{owner_name}/{repo_name} \u{b7} {}",293 "{owner_name}/{repo_name} \u{b7} {}",
@@ -301,7 +303,7 @@ async fn discussions_list_page(cx: &Cx) -> Result<impl View> {
301 Ok(view! {303 Ok(view! {
302 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),304 shell(title: title.as_str(), viewer: ctx.viewer.as_ref(),
303 repo_head(head: header)305 repo_head(head: header)
304- <div class="issue-toolbar">306+ <div class="issue-toolbar" data-live=(live_href.as_str()) data-live-now="">
305 <nav class="issue-tabs" aria-label=(nav_label)>307 <nav class="issue-tabs" aria-label=(nav_label)>
306 <a class=(all_class) href=(all_href.as_str())>(all_label)</a>308 <a class=(all_class) href=(all_href.as_str())>(all_label)</a>
307 for tab in tabs.iter() {309 for tab in tabs.iter() {
crates/forge-web/src/pages/mod.rsmodified+3 -0
@@ -35,6 +35,9 @@ pub mod commits;
35 pub mod compare;35 pub mod compare;
36 pub mod dashboard;36 pub mod dashboard;
37 pub mod discussion_actions;37 pub mod discussion_actions;
38+pub mod discussion_live;
39+#[cfg(test)]
40+mod discussion_live_tests;
38 pub mod discussion_settings;41 pub mod discussion_settings;
39 pub mod discussion_view;42 pub mod discussion_view;
40 pub mod discussions;43 pub mod discussions;
crates/forge-web/src/test_support.rsmodified+1 -0
@@ -101,6 +101,7 @@ pub fn app_router(state: AppState) -> Router {
101 .layer(avatar_body_limit())101 .layer(avatar_body_limit())
102 .layer(RepoMovedLayer)102 .layer(RepoMovedLayer)
103 .layer(crate::pages::pull_live::PullWriteLayer)103 .layer(crate::pages::pull_live::PullWriteLayer)
104+ .layer(crate::pages::discussion_live::DiscussionWriteLayer)
104 .layer(TowerLayer::new(crate::compression::ResponseCompression))105 .layer(TowerLayer::new(crate::compression::ResponseCompression))
105 .compression(Compression::off())106 .compression(Compression::off())
106 .build()107 .build()
docs/architecture.mdmodified+1 -0
@@ -516,6 +516,7 @@ Known gaps:
516 - Merge strategies: merge commit (`commit-tree` from merge-tree output), squash, rebase, fast-forward only.516 - Merge strategies: merge commit (`commit-tree` from merge-tree output), squash, rebase, fast-forward only.
517 - `range-diff` for "what changed since the last review." AGit (`refs/for/<branch>`) is considered later.517 - `range-diff` for "what changed since the last review." AGit (`refs/for/<branch>`) is considered later.
518 - Live pages: the pull list and every pull tab (conversation, commits, files) update while open. Each has an event stream (`/{o}/{r}/pulls/events`, `/{o}/{r}/pulls/{n}/events`) that sends `changed` when a write changes what the page shows. A POST under the pulls paths, a push, a commit status for the head, and a mergeability or auto-merge run each wake it. The page re-reads in place and keeps typed text, focus and open inline forms; the Files tab keeps the file in view at the same offset. Streams are in-process, event driven, and never poll. Topics live in `live.rs`; the bump helpers are in `pages/pull_live.rs`.518 - Live pages: the pull list and every pull tab (conversation, commits, files) update while open. Each has an event stream (`/{o}/{r}/pulls/events`, `/{o}/{r}/pulls/{n}/events`) that sends `changed` when a write changes what the page shows. A POST under the pulls paths, a push, a commit status for the head, and a mergeability or auto-merge run each wake it. The page re-reads in place and keeps typed text, focus and open inline forms; the Files tab keeps the file in view at the same offset. Streams are in-process, event driven, and never poll. Topics live in `live.rs`; the bump helpers are in `pages/pull_live.rs`.
519+- Live discussions: the discussion list and each discussion page update while open. Each has an event stream (`/{o}/{r}/discussions/live`, `/{o}/{r}/discussions/{n}/live`) that sends `changed` when a comment, reply, reaction, answer, edit, lock, category change or new discussion changes what the page shows. A POST under the discussions paths and the discussions toggle in the repo settings wake them. Topics are `Discussions` (per repo) and `Discussion` (per discussion); the write layer is in `pages/discussion_live.rs`. The reply box keeps its typed text across an update.
519 520
520 ### Webhooks, push mirrors, replication, backups, export521 ### Webhooks, push mirrors, replication, backups, export
521 522