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:
@@ -42,11 +42,13 @@ pub struct ThreadRow {
|
||||
pub deleted_at: Option<OffsetDateTime>,
|
||||
pub delete_reason: Option<String>,
|
||||
pub system: bool,
|
||||
/// Its topic is archived: readable, but takes nothing new.
|
||||
pub archived: bool,
|
||||
}
|
||||
|
||||
const THREAD_SELECT: &str = "SELECT th.id, th.topic_id, tp.slug AS topic_slug, tp.name AS topic_name, tp.visibility, \
|
||||
tp.listening, th.author_id, th.title, th.intent, th.created_at, th.locked, th.pinned, th.deleted_at, \
|
||||
th.delete_reason, th.system \
|
||||
th.delete_reason, th.system, tp.archived_at IS NOT NULL AS archived \
|
||||
FROM forum.threads th JOIN forum.topics tp ON tp.id = th.topic_id";
|
||||
|
||||
/// A thread the viewer may read (deleted ones too): 404 when it does not
|
||||
@@ -63,13 +65,16 @@ pub async fn readable_thread(db: &PgPool, viewer: &Viewer, id: i64) -> ApiResult
|
||||
Ok(thread)
|
||||
}
|
||||
|
||||
/// A thread that can take new posts and reactions: not removed, and not
|
||||
/// locked (moderators may still write in a locked one).
|
||||
/// A thread that can take new posts and reactions: not removed, not in an
|
||||
/// archived topic, and not locked (moderators may still write in a locked one).
|
||||
pub async fn open_thread(db: &PgPool, viewer: &Viewer, id: i64) -> ApiResult<ThreadRow> {
|
||||
let thread = readable_thread(db, viewer, id).await?;
|
||||
if thread.deleted_at.is_some() {
|
||||
return Err(ApiError::NotFound("thread"));
|
||||
}
|
||||
if thread.archived {
|
||||
return Err(ApiError::Forbidden("Ez a téma archivált: olvasható, de új hozzászólás nem írható.".into()));
|
||||
}
|
||||
if thread.locked && !viewer.is_moderator() {
|
||||
return Err(ApiError::Forbidden("Ez a szál le van zárva.".into()));
|
||||
}
|
||||
@@ -180,6 +185,8 @@ pub async fn posts_json(db: &PgPool, viewer: &Viewer, posts: &[PostRow]) -> ApiR
|
||||
"mentions": mentions,
|
||||
"system": p.system,
|
||||
"reply_to": reply_to,
|
||||
// The viewer muted the author: the page folds it up.
|
||||
"muted": p.author_id.is_some_and(|a| viewer.mutes.contains(&a)),
|
||||
});
|
||||
if moderator {
|
||||
post["down"] = json!(down);
|
||||
@@ -229,7 +236,7 @@ pub async fn show(State(state): St, viewer: Viewer, WithRejection(Path(id), _):
|
||||
None => (false, None),
|
||||
};
|
||||
let writer = viewer.member.as_ref().filter(|m| !m.banned(now));
|
||||
let open = thread.deleted_at.is_none() && (!thread.locked || moderator);
|
||||
let open = thread.deleted_at.is_none() && !thread.archived && (!thread.locked || moderator);
|
||||
out["access"] = json!({
|
||||
"can_reply": open && (writer.is_some() || !viewer.logged_in() || viewer.member.is_none()),
|
||||
"can_downvote": !thread.listening && writer.is_some_and(|m| m.rank(now).may_downvote()),
|
||||
@@ -248,7 +255,7 @@ fn thread_json(thread: &ThreadRow, author: Option<Value>) -> Value {
|
||||
"intent": thread.intent,
|
||||
"topic": {
|
||||
"slug": thread.topic_slug, "name": thread.topic_name,
|
||||
"visibility": thread.visibility, "listening": thread.listening,
|
||||
"visibility": thread.visibility, "listening": thread.listening, "archived": thread.archived,
|
||||
},
|
||||
"author": author,
|
||||
"created_at": rfc3339(thread.created_at),
|
||||
@@ -317,12 +324,15 @@ pub async fn create(
|
||||
WithRejection(Json(req), _): Body<CreateThread>,
|
||||
) -> ApiResult<(StatusCode, Json<Value>)> {
|
||||
let member = viewer.require_writer()?;
|
||||
let topic: Option<(i16, String, bool)> =
|
||||
sqlx::query_as("SELECT id, visibility, listening FROM forum.topics WHERE slug = $1")
|
||||
let topic: Option<(i16, String, bool, bool)> =
|
||||
sqlx::query_as("SELECT id, visibility, listening, archived_at IS NOT NULL FROM forum.topics WHERE slug = $1")
|
||||
.bind(&req.topic)
|
||||
.fetch_optional(&state.db)
|
||||
.await?;
|
||||
let (topic_id, visibility, listening) = topic.ok_or_else(|| ApiError::bad("Ismeretlen téma."))?;
|
||||
let (topic_id, visibility, listening, archived) = topic.ok_or_else(|| ApiError::bad("Ismeretlen téma."))?;
|
||||
if archived {
|
||||
return Err(ApiError::bad("Ez a téma archivált, új szál nem nyitható benne."));
|
||||
}
|
||||
if !may_read(&viewer, &visibility, topic_id) {
|
||||
return Err(ApiError::bad("Ismeretlen téma."));
|
||||
}
|
||||
@@ -458,7 +468,8 @@ pub async fn reply(
|
||||
.await?;
|
||||
after_post(&mut tx, member.user_id, id, post.id).await?;
|
||||
tx.commit().await?;
|
||||
crate::mail::after_reply(&state, id, post.id, member.user_id, post.parent_id, &body).await;
|
||||
// The one answered hears of it (on the second level, not the branch's first post).
|
||||
crate::mail::after_reply(&state, id, post.id, member.user_id, post.reply_to_id.or(post.parent_id), &body).await;
|
||||
super::mentions::after_post(&state, id, post.id, member.user_id, &body).await;
|
||||
let followers = crate::live::followers(&state.db, id, member.user_id).await;
|
||||
crate::live::emit(&state.db, crate::live::Event { thread: Some(id), ..Default::default() }.for_users(followers))
|
||||
|
||||
Reference in New Issue
Block a user