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:
@@ -5,13 +5,16 @@
|
||||
//! role. A thread in a topic the viewer may not read answers 404, so its
|
||||
//! existence is not revealed.
|
||||
|
||||
mod avatars;
|
||||
mod home;
|
||||
mod members;
|
||||
mod mentions;
|
||||
mod messages;
|
||||
mod moderation;
|
||||
mod posts;
|
||||
mod reports;
|
||||
mod threads;
|
||||
mod topics;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
@@ -40,8 +43,10 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.route("/healthz", get(health))
|
||||
.route("/v1/forum/home", get(home::home))
|
||||
.route("/v1/forum/nav", get(home::nav))
|
||||
.route("/v1/forum/topics", get(home::topics))
|
||||
.route("/v1/forum/topics/{slug}", get(home::topic))
|
||||
.route("/v1/forum/topics", get(home::topics).post(topics::create))
|
||||
.route("/v1/forum/topics/{slug}", get(home::topic).patch(topics::update))
|
||||
.route("/v1/forum/topics/{slug}/join", post(topics::join).delete(topics::leave))
|
||||
.route("/v1/forum/mod/topic-requests", get(topics::requests).post(topics::decide))
|
||||
.route("/v1/forum/followed", get(home::followed))
|
||||
.route("/v1/forum/threads", post(threads::create))
|
||||
.route("/v1/forum/threads/{id}", get(threads::show).patch(threads::update).delete(threads::remove))
|
||||
@@ -63,10 +68,17 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
.route("/v1/forum/conversations/{id}/messages", post(messages::send))
|
||||
.route("/v1/forum/conversations/{id}/read", post(messages::read))
|
||||
.route("/v1/forum/me", get(members::me).put(members::save_me))
|
||||
.route(
|
||||
"/v1/forum/me/avatar",
|
||||
put(avatars::upload).layer(axum::extract::DefaultBodyLimit::max(avatars::MAX_UPLOAD + 1024)),
|
||||
)
|
||||
.route("/v1/forum/avatars/{file}", get(avatars::serve))
|
||||
.route("/v1/forum/members/{nickname}/avatar-reset", post(avatars::reset))
|
||||
.route("/v1/forum/nickname-check", get(members::nickname_check))
|
||||
.route("/v1/forum/presence", post(members::presence))
|
||||
.route("/v1/forum/unsubscribe", post(members::unsubscribe))
|
||||
.route("/v1/forum/ws", get(crate::live::connect))
|
||||
.route("/v1/forum/members/search", get(mentions::search))
|
||||
.route("/v1/forum/members/{nickname}", get(members::profile))
|
||||
.route("/v1/forum/members/{nickname}/ban", post(moderation::ban).delete(moderation::unban))
|
||||
.route("/v1/forum/mod/log", get(moderation::log))
|
||||
@@ -83,23 +95,30 @@ async fn health(State(state): St) -> Result<Json<Value>, ApiError> {
|
||||
}
|
||||
|
||||
/// The topics the viewer may read, as an SQL condition on `tp` (forum.topics).
|
||||
/// Built from the viewer's flags only, never from input.
|
||||
pub fn visible_topics(viewer: &Viewer) -> &'static str {
|
||||
/// Built from the viewer's flags and their approved topic ids only, never
|
||||
/// from input.
|
||||
pub fn visible_topics(viewer: &Viewer) -> String {
|
||||
if viewer.is_moderator() {
|
||||
"TRUE"
|
||||
"TRUE".into()
|
||||
} else if viewer.logged_in() {
|
||||
"tp.visibility IN ('public', 'members')"
|
||||
let mut sql = "tp.visibility IN ('public', 'members')".to_string();
|
||||
if !viewer.topics.is_empty() {
|
||||
let ids: Vec<String> = viewer.topics.iter().map(|id| id.to_string()).collect();
|
||||
sql.push_str(&format!(" OR tp.id IN ({})", ids.join(", ")));
|
||||
}
|
||||
sql
|
||||
} else {
|
||||
"tp.visibility = 'public'"
|
||||
"tp.visibility = 'public'".into()
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the viewer may read a topic of this visibility.
|
||||
pub fn may_read(viewer: &Viewer, visibility: &str) -> bool {
|
||||
/// Whether the viewer may read a topic of this visibility (restricted: only
|
||||
/// moderators and the approved members).
|
||||
pub fn may_read(viewer: &Viewer, visibility: &str, topic: i16) -> bool {
|
||||
match visibility {
|
||||
"public" => true,
|
||||
"members" => viewer.logged_in(),
|
||||
_ => viewer.is_moderator(),
|
||||
_ => viewer.is_moderator() || viewer.topics.contains(&topic),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +139,8 @@ pub struct CardRow {
|
||||
pub participants: i64,
|
||||
/// Posts by others the member has not read; `None` for visitors.
|
||||
pub unread: Option<i64>,
|
||||
/// The site's own thread (the daily sky).
|
||||
pub system: bool,
|
||||
}
|
||||
|
||||
/// `SELECT` of [`CardRow`]s over the threads the viewer may read; `$1` is
|
||||
@@ -136,7 +157,8 @@ pub fn card_sql(viewer: &Viewer) -> String {
|
||||
WHERE p.thread_id = th.id AND p.deleted_at IS NULL AND p.author_id IS DISTINCT FROM $1 \
|
||||
AND p.created_at > $2::timestamptz \
|
||||
AND p.id > COALESCE((SELECT r.last_post_id FROM forum.reads r \
|
||||
WHERE r.user_id = $1 AND r.thread_id = th.id), 0)) END AS unread \
|
||||
WHERE r.user_id = $1 AND r.thread_id = th.id), 0)) END AS unread, \
|
||||
th.system \
|
||||
FROM forum.threads th JOIN forum.topics tp ON tp.id = th.topic_id \
|
||||
WHERE th.deleted_at IS NULL AND ({})",
|
||||
visible_topics(viewer)
|
||||
@@ -170,6 +192,7 @@ pub async fn cards_json(db: &PgPool, rows: Vec<CardRow>) -> Result<Vec<Value>, s
|
||||
"pinned": r.pinned,
|
||||
"locked": r.locked,
|
||||
"unread": r.unread,
|
||||
"system": r.system,
|
||||
})
|
||||
})
|
||||
.collect())
|
||||
@@ -186,6 +209,8 @@ struct AuthorRow {
|
||||
last_seen_at: Option<OffsetDateTime>,
|
||||
chart_share: String,
|
||||
roles: Vec<String>,
|
||||
listener: bool,
|
||||
supporter: bool,
|
||||
}
|
||||
|
||||
/// How members appear next to what they wrote: nickname, avatar, rank,
|
||||
@@ -199,7 +224,9 @@ pub async fn authors(db: &PgPool, ids: impl IntoIterator<Item = Uuid>) -> Result
|
||||
}
|
||||
let rows: Vec<AuthorRow> = sqlx::query_as(
|
||||
"SELECT m.user_id, m.nickname, m.avatar, m.points, m.created_at, m.invisible, m.last_seen_at, \
|
||||
m.chart_share, u.roles \
|
||||
m.chart_share, u.roles, m.listener, \
|
||||
m.supporter_badge AND EXISTS (SELECT 1 FROM package_orders o \
|
||||
WHERE o.user_id = m.user_id AND o.source = 'stripe') AS supporter \
|
||||
FROM forum.members m JOIN users u ON u.id = m.user_id WHERE m.user_id = ANY($1)",
|
||||
)
|
||||
.bind(&ids)
|
||||
@@ -222,6 +249,8 @@ pub async fn authors(db: &PgPool, ids: impl IntoIterator<Item = Uuid>) -> Result
|
||||
"moderator": moderator,
|
||||
"online": online(r.invisible, r.last_seen_at, now),
|
||||
"signs": shown,
|
||||
"listener": r.listener,
|
||||
"supporter": r.supporter,
|
||||
});
|
||||
(r.user_id, value)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user