Forum: daily sky thread, listeners, mentions, own avatars, restricted topics

- The worker opens a "Mai égbolt" thread every morning from the day's sky
  (no AI), pinned for the day.
- Volunteer listeners (from the Kereső rank) get a badge, a count of the
  threads asking to be heard that still wait for a reply, and, if they ask,
  an e-mail after two hours of waiting.
- "@Holdfény" names a member (nicknames with spaces too): they follow the
  thread, hear of it live and, if they asked, by e-mail; a search helps
  typing it.
- From the Kereső rank a member may upload an own avatar: a small square
  JPEG without metadata in the object storage (now a shared crate with the
  backend), served by the forum; moderators can put the starter back.
- The "Támogató" badge for buyers who switch it on.
- The admin creates and edits topics; restricted ones are read by their
  approved members, who ask to join and moderators decide.
- "Most itt vannak" on the front page; the weekly summary e-mail on Sunday
  evening for those who ask (off by default).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 12:37:52 +00:00
co-authored by Claude Opus 5.5
parent 0a2308c491
commit 564c22176f
31 changed files with 2226 additions and 320 deletions
+156 -2
View File
@@ -35,6 +35,7 @@ impl TestApp {
flood_secs: 0,
base_url: "https://sorsfonalak.test".into(),
hub: crate::live::Hub::default(),
storage: None,
};
Self { router: routes::router(Arc::new(state)), pool }
}
@@ -744,7 +745,11 @@ async fn instant_mails_and_unsubscribe(pool: PgPool) {
let bea = app.member("bea@example.com", "Holdfény", &["user"]).await;
let cili = app.member("cili@example.com", "Zöldág", &["user"]).await;
let me = app.get("/v1/forum/me", Some(&anna)).await;
assert_eq!(me["member"]["email"], json!({"replies": "daily", "followed": "off", "messages": "instant"}));
assert_eq!(
me["member"]["email"],
json!({"replies": "daily", "followed": "off", "messages": "instant", "mentions": "instant",
"listener": "off", "weekly": false})
);
let (status, _) = app
.call(
"PUT",
@@ -845,7 +850,11 @@ async fn instant_mails_and_unsubscribe(pool: PgPool) {
let (status, _) = app.call("POST", &format!("/v1/forum/unsubscribe?token={token}"), None, Value::Null).await;
assert_eq!(status, StatusCode::OK);
let me = app.get("/v1/forum/me", Some(&anna)).await;
assert_eq!(me["member"]["email"], json!({"replies": "off", "followed": "off", "messages": "off"}));
assert_eq!(
me["member"]["email"],
json!({"replies": "off", "followed": "off", "messages": "off", "mentions": "off",
"listener": "off", "weekly": false})
);
}
#[sqlx::test(migrator = "db::MIGRATOR")]
@@ -857,6 +866,7 @@ async fn live_doorbell_over_websocket(pool: PgPool) {
flood_secs: 0,
base_url: "https://sorsfonalak.test".into(),
hub: crate::live::Hub::default(),
storage: None,
});
tokio::spawn(crate::live::listen(pool.clone(), state.hub.clone()));
let router = routes::router(state.clone());
@@ -924,3 +934,147 @@ async fn futures_next(
}
}
}
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn restricted_topics_by_approval(pool: PgPool) {
let app = TestApp::new(pool);
let admin = app.member("admin@example.com", "Gondnok", &["admin"]).await;
let moderator = app.member("mod@example.com", "Őrangyal", &["moderator"]).await;
let anna = app.member("anna@example.com", "Csendesvíz", &["user"]).await;
let bea = app.member("bea@example.com", "Holdfény", &["user"]).await;
// Only the admin opens topics.
let body =
json!({ "name": "Gyászolók köre", "description": "Akik elveszítettek valakit", "visibility": "restricted" });
assert_eq!(app.call("POST", "/v1/forum/topics", Some(&moderator), body.clone()).await.0, StatusCode::FORBIDDEN);
let (status, created) = app.call("POST", "/v1/forum/topics", Some(&admin), body).await;
assert_eq!(status, StatusCode::CREATED, "{created}");
assert_eq!(created["slug"], "gyaszolok-kore");
// Members see it by name and may ask to join; visitors do not see it.
let home = app.get("/v1/forum/home", Some(&anna)).await;
let topic = home["topics"].as_array().unwrap().iter().find(|t| t["slug"] == "gyaszolok-kore").unwrap().clone();
assert_eq!((topic["readable"].as_bool(), topic["membership"].as_str()), (Some(false), Some("none")));
assert!(
app.get("/v1/forum/home", None).await["topics"]
.as_array()
.unwrap()
.iter()
.all(|t| t["slug"] != "gyaszolok-kore")
);
let (status, _) = app.call("GET", "/v1/forum/topics/gyaszolok-kore", Some(&anna), Value::Null).await;
assert_eq!(status, StatusCode::NOT_FOUND);
let (status, _) = app
.call(
"POST",
"/v1/forum/threads",
Some(&anna),
json!({ "topic": "gyaszolok-kore", "title": "Apukám", "body": "x" }),
)
.await;
assert_eq!(status, StatusCode::BAD_REQUEST);
let (status, _) = app
.call(
"POST",
"/v1/forum/topics/gyaszolok-kore/join",
Some(&anna),
json!({ "note": "Tavaly vesztettem el anyukámat." }),
)
.await;
assert_eq!(status, StatusCode::NO_CONTENT);
assert_eq!(app.get("/v1/forum/nav", Some(&moderator)).await["reports"], 1, "the request shows for moderators");
// A moderator approves: now Anna reads and writes there, Bea still not.
let requests = app.get("/v1/forum/mod/topic-requests", Some(&moderator)).await;
assert_eq!(requests["requests"][0]["member"]["nickname"], "Csendesvíz");
assert_eq!(requests["requests"][0]["note"], "Tavaly vesztettem el anyukámat.");
let (status, _) = app
.call(
"POST",
"/v1/forum/mod/topic-requests",
Some(&moderator),
json!({ "topic": "gyaszolok-kore", "nickname": "Csendesvíz", "action": "approve" }),
)
.await;
assert_eq!(status, StatusCode::NO_CONTENT);
let thread = app.thread(&anna, "gyaszolok-kore", "Apukám emléke").await;
app.get(&format!("/v1/forum/threads/{thread}"), Some(&anna)).await;
let (status, _) = app.call("GET", &format!("/v1/forum/threads/{thread}"), Some(&bea), Value::Null).await;
assert_eq!(status, StatusCode::NOT_FOUND);
app.get(&format!("/v1/forum/threads/{thread}"), Some(&moderator)).await;
assert_eq!(app.get("/v1/forum/mod/log", Some(&moderator)).await["entries"][0]["action"], "approve_member");
// The admin renames it; the address stays.
let (status, _) = app
.call("PATCH", "/v1/forum/topics/gyaszolok-kore", Some(&admin), json!({ "name": "Gyász és emlékezés" }))
.await;
assert_eq!(status, StatusCode::NO_CONTENT);
assert_eq!(app.get("/v1/forum/topics/gyaszolok-kore", Some(&anna)).await["topic"]["name"], "Gyász és emlékezés");
}
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn mentions_listeners_supporters_and_who_is_here(pool: PgPool) {
let app = TestApp::new(pool);
let anna = app.member("anna@example.com", "Csendesvíz", &["user"]).await;
let bea = app.member("bea@example.com", "Hold fény", &["user"]).await;
let cili = app.member("cili@example.com", "Zöldág", &["user"]).await;
// "@Hold fény" (with its space) names Bea: she follows the thread, it is new for her.
let thread = app.thread(&anna, "torzsasztal", "Téli levesek").await;
let post = app.reply(&cili, thread, "Szerinted, @Hold fény, mi a legjobb? És @Senki?", None).await;
assert_eq!(post["mentions"], json!(["Hold fény"]));
let followed = app.get("/v1/forum/followed", Some(&bea)).await;
assert_eq!(followed["threads"][0]["id"], thread);
let found = app.get("/v1/forum/members/search?q=hold", Some(&anna)).await;
assert_eq!(found["members"][0]["nickname"], "Hold fény");
// Listening volunteers: from the Kereső rank; they see what waits for a reply.
let (status, _) =
app.call("PUT", "/v1/forum/me", Some(&bea), json!({ "nickname": "Hold fény", "listener": true })).await;
assert_eq!(status, StatusCode::FORBIDDEN);
app.season(&bea, 5, 10).await;
let (status, _) =
app.call("PUT", "/v1/forum/me", Some(&bea), json!({ "nickname": "Hold fény", "listener": true })).await;
assert_eq!(status, StatusCode::OK);
let waiting = app.thread(&anna, "ami-a-szivemen-van", "Nehéz napok").await;
sqlx::query("UPDATE forum.threads SET created_at = now() - interval '2 hours' WHERE id = $1")
.bind(waiting)
.execute(&app.pool)
.await
.unwrap();
assert_eq!(app.get("/v1/forum/nav", Some(&bea)).await["waiting"], 1);
assert!(app.get("/v1/forum/nav", Some(&cili)).await["waiting"].is_null());
let shown = app.get(&format!("/v1/forum/threads/{thread}"), Some(&anna)).await;
assert!(shown["posts"].as_array().unwrap().iter().all(|p| p["author"]["supporter"] == false));
// The supporter badge: buyers only, and only when they switch it on.
let (status, _) =
app.call("PUT", "/v1/forum/me", Some(&cili), json!({ "nickname": "Zöldág", "supporter_badge": true })).await;
assert_eq!(status, StatusCode::FORBIDDEN);
sqlx::query("INSERT INTO package_orders (id, user_id, package, source, price_huf) VALUES ($1, $2, 'egyeni', 'stripe', 4900)")
.bind(Uuid::now_v7())
.bind(cili.id)
.execute(&app.pool)
.await
.unwrap();
assert_eq!(app.get("/v1/forum/me", Some(&cili)).await["can_supporter"], true);
let (status, _) =
app.call("PUT", "/v1/forum/me", Some(&cili), json!({ "nickname": "Zöldág", "supporter_badge": true })).await;
assert_eq!(status, StatusCode::OK);
let profile = app.get("/v1/forum/members/Zöldág", None).await;
assert_eq!(
(profile["member"]["author"]["supporter"].as_bool(), profile["member"]["author"]["listener"].as_bool()),
(Some(true), Some(false))
);
assert_eq!(app.get("/v1/forum/members/hold%20f%C3%A9ny", None).await["member"]["author"]["listener"], true);
// Who is here: the members seen in the last minutes, not the invisible.
app.call("PUT", "/v1/forum/me", Some(&anna), json!({ "nickname": "Csendesvíz", "invisible": true })).await;
let here: Vec<String> = app.get("/v1/forum/home", None).await["online"]
.as_array()
.unwrap()
.iter()
.map(|m| m["nickname"].as_str().unwrap().to_string())
.collect();
assert!(here.contains(&"Zöldág".to_string()) && !here.contains(&"Csendesvíz".to_string()));
}