From 9ca3f478be4e4cf0578d1604f65d86dc799faf57 Mon Sep 17 00:00:00 2001
From: feco
Date: Thu, 26 Nov 2026 14:31:05 +0000
Subject: [PATCH] Forum: search, muting members, archived topics, the public
threads in the sitemap
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 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
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
---
...0043_forum_search_mutes_archive_charts.sql | 52 +++++++
services/forum/src/auth.rs | 19 ++-
services/forum/src/mail.rs | 3 +
services/forum/src/routes/home.rs | 28 ++--
services/forum/src/routes/members.rs | 1 +
services/forum/src/routes/mod.rs | 19 ++-
services/forum/src/routes/mutes.rs | 67 +++++++++
services/forum/src/routes/replies.rs | 1 +
services/forum/src/routes/search.rs | 139 +++++++++++++++++
services/forum/src/routes/threads.rs | 29 ++--
services/forum/src/routes/topics.rs | 15 +-
services/forum/src/tests.rs | 79 ++++++++++
.../frontend/src/app/forum/[tema]/page.tsx | 23 ++-
.../src/app/forum/beallitasok/MutedList.tsx | 46 ++++++
.../src/app/forum/beallitasok/ProfileForm.tsx | 4 +
services/frontend/src/app/forum/forum.css | 27 ++++
.../frontend/src/app/forum/kereses/page.tsx | 103 +++++++++++++
services/frontend/src/app/forum/layout.tsx | 10 +-
.../src/app/forum/moderalas/TopicsAdmin.tsx | 15 ++
services/frontend/src/app/forum/page.tsx | 142 +++++++++++-------
.../src/app/forum/tag/[nev]/MuteButton.tsx | 49 ++++++
.../frontend/src/app/forum/tag/[nev]/page.tsx | 2 +
services/frontend/src/app/forum/uj/page.tsx | 2 +-
services/frontend/src/app/robots.ts | 19 ++-
services/frontend/src/app/sitemap.ts | 17 ++-
.../src/components/forum/ThreadView.tsx | 40 ++++-
services/frontend/src/lib/forum.ts | 10 +-
services/frontend/src/lib/forumServer.ts | 15 ++
services/worker/src/forum_digest.rs | 6 +-
services/worker/src/forum_sky.rs | 2 +-
30 files changed, 879 insertions(+), 105 deletions(-)
create mode 100644 crates/db/migrations/0043_forum_search_mutes_archive_charts.sql
create mode 100644 services/forum/src/routes/mutes.rs
create mode 100644 services/forum/src/routes/search.rs
create mode 100644 services/frontend/src/app/forum/beallitasok/MutedList.tsx
create mode 100644 services/frontend/src/app/forum/kereses/page.tsx
create mode 100644 services/frontend/src/app/forum/tag/[nev]/MuteButton.tsx
diff --git a/crates/db/migrations/0043_forum_search_mutes_archive_charts.sql b/crates/db/migrations/0043_forum_search_mutes_archive_charts.sql
new file mode 100644
index 0000000..72f382e
--- /dev/null
+++ b/crates/db/migrations/0043_forum_search_mutes_archive_charts.sql
@@ -0,0 +1,52 @@
+-- Forum: archived topics, muted members, search, and charts attached to a
+-- question.
+
+-- An archived topic stays readable at its address, but takes no new threads
+-- or replies, and leaves the front page lists.
+ALTER TABLE forum.topics ADD COLUMN archived_at timestamptz;
+
+-- "Némítás": the muted member's threads leave the lists, their posts fold
+-- up, and their replies and mentions no longer notify. They are not told.
+CREATE TABLE forum.mutes (
+ user_id uuid NOT NULL REFERENCES users ON DELETE CASCADE,
+ muted_id uuid NOT NULL REFERENCES users ON DELETE CASCADE,
+ created_at timestamptz NOT NULL DEFAULT now(),
+ PRIMARY KEY (user_id, muted_id),
+ CHECK (user_id <> muted_id)
+);
+
+-- Search: Hungarian stems (szálak → szál), and the words without accents
+-- too, so "alvas" finds "alvás".
+CREATE EXTENSION IF NOT EXISTS unaccent;
+CREATE TEXT SEARCH CONFIGURATION forum.plain (COPY = simple);
+ALTER TEXT SEARCH CONFIGURATION forum.plain ALTER MAPPING FOR hword, hword_part, word WITH unaccent, simple;
+
+ALTER TABLE forum.threads ADD COLUMN search tsvector GENERATED ALWAYS AS (
+ to_tsvector('hungarian'::regconfig, title) || to_tsvector('forum.plain'::regconfig, title)
+) STORED;
+ALTER TABLE forum.posts ADD COLUMN search tsvector GENERATED ALWAYS AS (
+ to_tsvector('hungarian'::regconfig, body) || to_tsvector('forum.plain'::regconfig, body)
+) STORED;
+CREATE INDEX threads_search_idx ON forum.threads USING gin (search);
+CREATE INDEX posts_search_idx ON forum.posts USING gin (search);
+
+-- A question about one's own chart, forecast or synastry: the opening post
+-- carries a share made for the forum (see below), shown to members only.
+ALTER TABLE forum.posts ADD COLUMN share_id uuid REFERENCES shares ON DELETE SET NULL;
+
+-- Shares made for the forum: never birth data, and the public view leaves
+-- out the chart names (they may be real names next to a nickname).
+ALTER TABLE shares ADD COLUMN for_forum boolean NOT NULL DEFAULT false;
+
+-- A yearly forecast can be shared too (its calculation, and the detailed
+-- text if there is one), without the place of the birthday.
+ALTER TABLE shares ADD COLUMN forecast_id uuid REFERENCES forecasts ON DELETE CASCADE;
+ALTER TABLE shares DROP CONSTRAINT shares_kind_check;
+ALTER TABLE shares ADD CONSTRAINT shares_kind_check CHECK (kind IN ('chart', 'synastry', 'analysis', 'forecast'));
+ALTER TABLE shares DROP CONSTRAINT shares_target;
+ALTER TABLE shares ADD CONSTRAINT shares_target CHECK (
+ (kind = 'chart' AND chart_id IS NOT NULL AND synastry_id IS NULL AND analysis_id IS NULL AND forecast_id IS NULL)
+ OR (kind = 'synastry' AND synastry_id IS NOT NULL AND chart_id IS NULL AND analysis_id IS NULL AND forecast_id IS NULL)
+ OR (kind = 'analysis' AND analysis_id IS NOT NULL AND chart_id IS NULL AND synastry_id IS NULL AND forecast_id IS NULL)
+ OR (kind = 'forecast' AND forecast_id IS NOT NULL AND chart_id IS NULL AND synastry_id IS NULL AND analysis_id IS NULL)
+);
diff --git a/services/forum/src/auth.rs b/services/forum/src/auth.rs
index 645a647..8d34536 100644
--- a/services/forum/src/auth.rs
+++ b/services/forum/src/auth.rs
@@ -66,6 +66,8 @@ pub struct Viewer {
pub member: Option,
/// The restricted topics the member was approved into.
pub topics: Vec,
+ /// The members they muted.
+ pub mutes: Vec,
}
impl Viewer {
@@ -137,15 +139,22 @@ impl FromRequestParts> for Viewer {
.execute(&state.db)
.await?;
}
- let topics = if member.is_some() {
- sqlx::query_scalar("SELECT topic_id FROM forum.topic_members WHERE user_id = $1 AND status = 'approved'")
+ let (topics, mutes) = if member.is_some() {
+ let topics = sqlx::query_scalar(
+ "SELECT topic_id FROM forum.topic_members WHERE user_id = $1 AND status = 'approved'",
+ )
+ .bind(user.id)
+ .fetch_all(&state.db)
+ .await?;
+ let mutes = sqlx::query_scalar("SELECT muted_id FROM forum.mutes WHERE user_id = $1")
.bind(user.id)
.fetch_all(&state.db)
- .await?
+ .await?;
+ (topics, mutes)
} else {
- Vec::new()
+ (Vec::new(), Vec::new())
};
- Ok(Viewer { user: Some(user), member, topics })
+ Ok(Viewer { user: Some(user), member, topics, mutes })
}
}
diff --git a/services/forum/src/mail.rs b/services/forum/src/mail.rs
index d7b6303..fe42318 100644
--- a/services/forum/src/mail.rs
+++ b/services/forum/src/mail.rs
@@ -78,6 +78,7 @@ async fn reply_mails(
WHERE m.email_replies = 'instant' AND m.user_id <> $1 AND {OFFLINE} \
AND m.user_id IN (SELECT author_id FROM forum.threads WHERE id = $2 \
UNION SELECT author_id FROM forum.posts WHERE id = $3) \
+ AND NOT EXISTS (SELECT 1 FROM forum.mutes mu WHERE mu.user_id = m.user_id AND mu.muted_id = $1) \
AND NOT EXISTS (SELECT 1 FROM email_outbox e \
WHERE e.user_id = m.user_id AND e.template = 'forum_reply' \
AND e.payload->>'thread_id' = $2::text AND e.created_at > now() - interval '1 hour')"
@@ -226,12 +227,14 @@ pub async fn after_mention(state: &AppState, thread_id: i64, post_id: i64, autho
"SELECT m.user_id, u.email, u.locale, m.nickname, m.email_token \
FROM forum.members m JOIN users u ON u.id = m.user_id \
WHERE m.user_id = ANY($1) AND m.email_mentions = 'instant' AND {OFFLINE} \
+ AND NOT EXISTS (SELECT 1 FROM forum.mutes mu WHERE mu.user_id = m.user_id AND mu.muted_id = $3) \
AND NOT EXISTS (SELECT 1 FROM email_outbox e WHERE e.user_id = m.user_id \
AND e.template IN ('forum_mention', 'forum_reply') \
AND e.payload->>'thread_id' = $2::text AND e.created_at > now() - interval '1 hour')"
))
.bind(users)
.bind(thread_id)
+ .bind(author)
.fetch_all(&state.db)
.await?;
if recipients.is_empty() {
diff --git a/services/forum/src/routes/home.rs b/services/forum/src/routes/home.rs
index 140fe11..9f6215b 100644
--- a/services/forum/src/routes/home.rs
+++ b/services/forum/src/routes/home.rs
@@ -27,6 +27,7 @@ struct TopicRow {
description: String,
visibility: String,
listening: bool,
+ archived: bool,
thread_count: i64,
new_count: Option,
last_author: Option,
@@ -39,6 +40,7 @@ async fn topic_list(state: &St, viewer: &Viewer) -> ApiResult> {
let (me, since) = card_params(viewer);
let rows: Vec = 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> {
"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> {
let followed = followed_counts(&state, &viewer).await?;
let unanswered: Vec = 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> {
"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> {
.fetch_all(&state.db)
.await?;
let people = super::authors(&state.db, present.iter().copied()).await?;
- let online: Vec = present.iter().filter_map(|id| people.get(id).cloned()).collect();
+ let online: Vec =
+ 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
)}
+ {topic.archived && (
+
+
+ Archivált téma: a szálak olvashatók, de új szál és hozzászólás már nem írható.
+
Ez a szál le van zárva, új hozzászólás nem írható.
+
+ {thread.topic.archived
+ ? "Ez a téma archivált: olvasható, de új hozzászólás nem írható."
+ : "Ez a szál le van zárva, új hozzászólás nem írható."}
+
) : (
<>
(path: string): Promise> {
if (!res.ok) throw new BackendError(res.status, `${path}: HTTP ${res.status}`);
return { ok: true, data: (await res.json()) as T };
}
+
+/** The public forum pages for the sitemap (nothing when the forum is off or does not answer). */
+export async function forumSitemap(): Promise<{
+ topics: { slug: string; updated: string | null }[];
+ threads: { id: number; slug: string; updated: string }[];
+}> {
+ const empty = { topics: [], threads: [] };
+ if (!forumEnabled()) return empty;
+ try {
+ const res = await fetch(`${FORUM_URL}/v1/forum/sitemap`, { next: { revalidate: 3600 } });
+ return res.ok ? await res.json() : empty;
+ } catch {
+ return empty;
+ }
+}
diff --git a/services/worker/src/forum_digest.rs b/services/worker/src/forum_digest.rs
index ea29fda..719d820 100644
--- a/services/worker/src/forum_digest.rs
+++ b/services/worker/src/forum_digest.rs
@@ -130,7 +130,7 @@ pub async fn listeners_once(db: &PgPool, base_url: &str) -> Result)> = sqlx::query_as(&format!(
"SELECT th.id, th.title, th.author_id FROM forum.threads th JOIN forum.topics tp ON tp.id = th.topic_id \
WHERE th.reply_count = 0 AND NOT th.locked AND th.deleted_at IS NULL AND NOT th.system \
- AND th.listeners_notified_at IS NULL AND tp.visibility <> 'restricted' \
+ AND th.listeners_notified_at IS NULL AND tp.visibility <> 'restricted' AND tp.archived_at IS NULL \
AND (th.intent = 'listen' OR tp.listening) \
AND th.created_at < now() - interval '{LISTENER_AFTER}' AND th.created_at > now() - interval '3 days' \
ORDER BY th.created_at LIMIT 20 FOR UPDATE OF th SKIP LOCKED"
@@ -190,7 +190,7 @@ pub async fn weekly_once(db: &PgPool, base_url: &str, any_time: bool) -> Result<
let busy: Vec<(i64, String, i64)> = sqlx::query_as(
"SELECT th.id, th.title, count(p.id) FROM forum.threads th JOIN forum.topics tp ON tp.id = th.topic_id \
JOIN forum.posts p ON p.thread_id = th.id AND p.deleted_at IS NULL AND p.created_at > now() - interval '7 days' \
- WHERE th.deleted_at IS NULL AND tp.visibility <> 'restricted' \
+ WHERE th.deleted_at IS NULL AND tp.visibility <> 'restricted' AND tp.archived_at IS NULL \
GROUP BY th.id, th.title ORDER BY count(p.id) DESC, max(p.id) DESC LIMIT 5",
)
.fetch_all(db)
@@ -198,7 +198,7 @@ pub async fn weekly_once(db: &PgPool, base_url: &str, any_time: bool) -> Result<
let waiting: Vec = sqlx::query_scalar(
"SELECT th.title FROM forum.threads th JOIN forum.topics tp ON tp.id = th.topic_id \
WHERE th.reply_count = 0 AND th.deleted_at IS NULL AND NOT th.locked AND NOT th.system \
- AND tp.visibility <> 'restricted' AND th.created_at > now() - interval '7 days' \
+ AND tp.visibility <> 'restricted' AND tp.archived_at IS NULL AND th.created_at > now() - interval '7 days' \
ORDER BY th.created_at LIMIT 3",
)
.fetch_all(db)
diff --git a/services/worker/src/forum_sky.rs b/services/worker/src/forum_sky.rs
index 9c26747..5e8944e 100644
--- a/services/worker/src/forum_sky.rs
+++ b/services/worker/src/forum_sky.rs
@@ -224,7 +224,7 @@ pub async fn run_once(db: &PgPool, http: &reqwest::Client, backend_url: &str, an
let mut tx = db.begin().await?;
let thread: Option = sqlx::query_scalar(
"INSERT INTO forum.threads (topic_id, author_id, title, system, pinned, daily_date) \
- SELECT id, NULL, $2, true, true, (now() AT TIME ZONE 'Europe/Budapest')::date FROM forum.topics WHERE slug = $1 \
+ SELECT id, NULL, $2, true, true, (now() AT TIME ZONE 'Europe/Budapest')::date FROM forum.topics WHERE slug = $1 AND archived_at IS NULL \
ON CONFLICT (daily_date) DO NOTHING RETURNING id",
)
.bind(TOPIC)