Forum: search, muting members, archived topics, the public threads in the sitemap

- Search (/forum/kereses, the magnifier in the forum bar): thread titles
  and posts the viewer may read, Hungarian stems and word beginnings
  without accents ("alvas" finds "alvásban"), one result per thread with
  the matching words marked.
- Muting a member (post menu, profile; the list in the settings): their
  threads leave the lists, their posts fold up, their replies and mentions
  no longer count or send e-mails. They are not told.
- The admin archives a topic (Moderálás → Témák): it stays readable but
  takes no new threads or replies, and folds away on the front page.
- The public topics and threads are in the sitemap; the forum's own pages
  are kept from robots.
- A reply e-mail goes to the one answered, also on the second level.
- Migration 0043 also prepares charts attached to a forum question.

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 14:31:05 +00:00
co-authored by Claude Opus 5.5
parent 4800a30e6d
commit 9ca3f478be
30 changed files with 879 additions and 105 deletions
+17 -11
View File
@@ -27,6 +27,7 @@ struct TopicRow {
description: String,
visibility: String,
listening: bool,
archived: bool,
thread_count: i64,
new_count: Option<i64>,
last_author: Option<Uuid>,
@@ -39,6 +40,7 @@ async fn topic_list(state: &St, viewer: &Viewer) -> ApiResult<Vec<Value>> {
let (me, since) = card_params(viewer);
let rows: Vec<TopicRow> = sqlx::query_as(
"SELECT tp.id, tp.slug, tp.name, tp.description, tp.visibility, tp.listening, \
tp.archived_at IS NOT NULL AS archived, \
(SELECT count(*) FROM forum.threads th WHERE th.topic_id = tp.id AND th.deleted_at IS NULL) AS thread_count, \
CASE WHEN $1::uuid IS NULL THEN NULL ELSE \
(SELECT count(*) FROM forum.posts p JOIN forum.threads th ON th.id = p.thread_id \
@@ -93,6 +95,7 @@ async fn topic_list(state: &St, viewer: &Viewer) -> ApiResult<Vec<Value>> {
"description": r.description,
"visibility": r.visibility,
"listening": r.listening,
"archived": r.archived,
"readable": readable,
"membership": membership,
});
@@ -138,7 +141,7 @@ pub async fn home(state: St, viewer: Viewer) -> ApiResult<Json<Value>> {
let followed = followed_counts(&state, &viewer).await?;
let unanswered: Vec<CardRow> = sqlx::query_as(&format!(
"{} AND th.reply_count = 0 AND NOT th.locked AND th.author_id IS DISTINCT FROM $1 \
"{} AND th.reply_count = 0 AND NOT th.locked AND th.author_id IS DISTINCT FROM $1 AND tp.archived_at IS NULL \
AND th.created_at > now() - make_interval(days => $3) \
ORDER BY th.created_at LIMIT 3",
card_sql(&viewer)
@@ -153,7 +156,7 @@ pub async fn home(state: St, viewer: Viewer) -> ApiResult<Json<Value>> {
"WITH recent AS (SELECT thread_id, count(*) AS n FROM forum.posts \
WHERE created_at > now() - interval '24 hours' AND deleted_at IS NULL AND NOT is_opening \
GROUP BY thread_id HAVING count(*) >= $3) \
{} AND th.id IN (SELECT thread_id FROM recent) \
{} AND th.id IN (SELECT thread_id FROM recent) AND tp.archived_at IS NULL \
ORDER BY (SELECT n FROM recent WHERE recent.thread_id = th.id) DESC, th.last_post_at DESC LIMIT 5",
card_sql(&viewer)
))
@@ -172,7 +175,8 @@ pub async fn home(state: St, viewer: Viewer) -> ApiResult<Json<Value>> {
.fetch_all(&state.db)
.await?;
let people = super::authors(&state.db, present.iter().copied()).await?;
let online: Vec<Value> = present.iter().filter_map(|id| people.get(id).cloned()).collect();
let online: Vec<Value> =
present.iter().filter(|id| !viewer.mutes.contains(id)).filter_map(|id| people.get(id).cloned()).collect();
// Volunteer listeners: threads asking to be heard, still without a reply.
let waiting = match &viewer.member {
@@ -203,6 +207,7 @@ async fn followed_counts(state: &St, viewer: &Viewer) -> ApiResult<Option<Value>
JOIN forum.threads th ON th.id = f.thread_id AND th.deleted_at IS NULL \
JOIN forum.posts p ON p.thread_id = f.thread_id AND p.deleted_at IS NULL \
WHERE f.user_id = $1 AND p.author_id IS DISTINCT FROM $1 AND p.created_at > $2 \
AND NOT EXISTS (SELECT 1 FROM forum.mutes mu WHERE mu.user_id = $1 AND mu.muted_id = p.author_id) \
AND p.id > COALESCE((SELECT r.last_post_id FROM forum.reads r \
WHERE r.user_id = $1 AND r.thread_id = f.thread_id), 0)",
)
@@ -217,7 +222,7 @@ async fn followed_counts(state: &St, viewer: &Viewer) -> ApiResult<Option<Value>
/// hour without a reply (two weeks at most), not the listener's own.
pub const WAITING_SQL: &str = "th.reply_count = 0 AND NOT th.locked AND th.deleted_at IS NULL AND NOT th.system \
AND th.created_at < now() - interval '1 hour' AND th.created_at > now() - interval '14 days' \
AND (th.intent = 'listen' OR tp.listening)";
AND (th.intent = 'listen' OR tp.listening) AND tp.archived_at IS NULL";
async fn waiting_count(state: &St, viewer: &Viewer) -> ApiResult<i64> {
let me = viewer.user_id();
@@ -275,12 +280,13 @@ pub async fn topic(
WithRejection(Path(slug), _): WithRejection<Path<String>, ApiError>,
WithRejection(Query(q), _): WithRejection<Query<PageQuery>, ApiError>,
) -> ApiResult<Json<Value>> {
let topic: Option<(i16, String, String, String, bool)> =
sqlx::query_as("SELECT id, name, description, visibility, listening FROM forum.topics WHERE slug = $1")
.bind(&slug)
.fetch_optional(&state.db)
.await?;
let (id, name, description, visibility, listening) = topic.ok_or(ApiError::NotFound("topic"))?;
let topic: Option<(i16, String, String, String, bool, bool)> = sqlx::query_as(
"SELECT id, name, description, visibility, listening, archived_at IS NOT NULL FROM forum.topics WHERE slug = $1",
)
.bind(&slug)
.fetch_optional(&state.db)
.await?;
let (id, name, description, visibility, listening, archived) = topic.ok_or(ApiError::NotFound("topic"))?;
if !may_read(&viewer, &visibility, id) {
// A members-only topic asks for a login; a restricted one stays hidden.
return Err(if visibility == "members" { ApiError::Unauthorized } else { ApiError::NotFound("topic") });
@@ -304,7 +310,7 @@ pub async fn topic(
"viewer": viewer_json(&viewer),
"topic": {
"slug": slug, "name": name, "description": description,
"visibility": visibility, "listening": listening,
"visibility": visibility, "listening": listening, "archived": archived,
},
"threads": cards_json(&state.db, rows).await?,
"page": page,