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:
@@ -28,6 +28,7 @@ pub const REACTIONS: [&str; 4] = ["with_you", "thanks", "me_too", "insight"];
|
||||
#[derive(Debug, Clone, sqlx::FromRow)]
|
||||
pub struct ThreadRow {
|
||||
pub id: i64,
|
||||
pub topic_id: i16,
|
||||
pub topic_slug: String,
|
||||
pub topic_name: String,
|
||||
pub visibility: String,
|
||||
@@ -40,11 +41,12 @@ pub struct ThreadRow {
|
||||
pub pinned: bool,
|
||||
pub deleted_at: Option<OffsetDateTime>,
|
||||
pub delete_reason: Option<String>,
|
||||
pub system: bool,
|
||||
}
|
||||
|
||||
const THREAD_SELECT: &str = "SELECT th.id, tp.slug AS topic_slug, tp.name AS topic_name, tp.visibility, \
|
||||
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.delete_reason, th.system \
|
||||
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
|
||||
@@ -55,7 +57,7 @@ pub async fn readable_thread(db: &PgPool, viewer: &Viewer, id: i64) -> ApiResult
|
||||
.fetch_optional(db)
|
||||
.await?
|
||||
.ok_or(ApiError::NotFound("thread"))?;
|
||||
if !may_read(viewer, &thread.visibility) {
|
||||
if !may_read(viewer, &thread.visibility, thread.topic_id) {
|
||||
return Err(if thread.visibility == "members" { ApiError::Unauthorized } else { ApiError::NotFound("thread") });
|
||||
}
|
||||
Ok(thread)
|
||||
@@ -88,10 +90,12 @@ pub struct PostRow {
|
||||
pub deleted_at: Option<OffsetDateTime>,
|
||||
pub deleted_by: Option<Uuid>,
|
||||
pub delete_reason: Option<String>,
|
||||
/// Written by the site itself (the daily sky thread).
|
||||
pub system: bool,
|
||||
}
|
||||
|
||||
pub const POST_COLUMNS: &str = "id, thread_id, parent_id, is_opening, author_id, body, created_at, edited_at, helped_at, deleted_at, deleted_by, \
|
||||
delete_reason";
|
||||
delete_reason, system";
|
||||
|
||||
/// Posts as the thread page shows them: authors, reactions, the viewer's own
|
||||
/// reaction. A removed post keeps its place with the reason; only
|
||||
@@ -120,10 +124,18 @@ pub async fn posts_json(db: &PgPool, viewer: &Viewer, posts: &[PostRow]) -> ApiR
|
||||
}
|
||||
None => HashMap::new(),
|
||||
};
|
||||
let named: Vec<(i64, String)> = sqlx::query_as(
|
||||
"SELECT mn.post_id, m.nickname FROM forum.mentions mn JOIN forum.members m ON m.user_id = mn.user_id \
|
||||
WHERE mn.post_id = ANY($1)",
|
||||
)
|
||||
.bind(&ids)
|
||||
.fetch_all(db)
|
||||
.await?;
|
||||
let moderator = viewer.is_moderator();
|
||||
Ok(posts
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let mentions: Vec<&String> = named.iter().filter(|(id, _)| *id == p.id).map(|(_, n)| n).collect();
|
||||
let counts = by_post.remove(&p.id).unwrap_or_default();
|
||||
let positive: i64 = REACTIONS.iter().map(|k| counts.get(*k).copied().unwrap_or(0)).sum();
|
||||
let down = counts.get("down").copied().unwrap_or(0);
|
||||
@@ -150,6 +162,8 @@ pub async fn posts_json(db: &PgPool, viewer: &Viewer, posts: &[PostRow]) -> ApiR
|
||||
"score": score,
|
||||
"collapsed": score <= COLLAPSE_SCORE,
|
||||
"mine": mine.get(&p.id),
|
||||
"mentions": mentions,
|
||||
"system": p.system,
|
||||
});
|
||||
if moderator {
|
||||
post["down"] = json!(down);
|
||||
@@ -225,6 +239,7 @@ fn thread_json(thread: &ThreadRow, author: Option<Value>) -> Value {
|
||||
"locked": thread.locked,
|
||||
"pinned": thread.pinned,
|
||||
"deleted": thread.deleted_at.map(|_| json!({ "reason": thread.delete_reason })),
|
||||
"system": thread.system,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -292,7 +307,7 @@ pub async fn create(
|
||||
.fetch_optional(&state.db)
|
||||
.await?;
|
||||
let (topic_id, visibility, listening) = topic.ok_or_else(|| ApiError::bad("Ismeretlen téma."))?;
|
||||
if !may_read(&viewer, &visibility) {
|
||||
if !may_read(&viewer, &visibility, topic_id) {
|
||||
return Err(ApiError::bad("Ismeretlen téma."));
|
||||
}
|
||||
let title = text::title(&req.title)?;
|
||||
@@ -325,6 +340,7 @@ pub async fn create(
|
||||
after_post(&mut tx, member.user_id, thread_id, post_id).await?;
|
||||
tx.commit().await?;
|
||||
tracing::info!(thread = thread_id, topic = %req.topic, "thread started");
|
||||
super::mentions::after_post(&state, thread_id, post_id, member.user_id, &body).await;
|
||||
Ok((StatusCode::CREATED, Json(json!({ "id": thread_id, "slug": text::slug(&title) }))))
|
||||
}
|
||||
|
||||
@@ -421,6 +437,7 @@ pub async fn reply(
|
||||
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;
|
||||
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))
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user