Forum: whom a reply answers, icon badges, the new features on the pages
- Replies stay two levels deep, but a reply to a reply says whom it is
for ("↪ Holdfény"): posts.reply_to_id.
- The question stands apart on its own card; the listening reminder above
the reply box is gone.
- Every rank and badge has its own line icon (Vándor, Kereső, Fonó,
Csillagfonó, Sorsfonó; Moderátor, Meghallgató, Támogató, Szálindító).
- Pages for the new features: own avatar upload and the moderator's reset,
the listener and supporter switches, mention and weekly summary e-mails
(the weekly one off by default), "@" suggestions and mention links, the
daily sky thread by "Sorsfonalak", "Most itt vannak", joining restricted
topics, and the moderators' Témák tab (requests; topics for the admin).
- Members-only topics say so to members too.
- The privacy notice (HU, EN) and point 8.1 of the terms cover own
pictures, badges, mentions, restricted topics and the weekly summary;
the data export and account deletion include them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -92,10 +92,12 @@ pub struct PostRow {
|
||||
pub delete_reason: Option<String>,
|
||||
/// Written by the site itself (the daily sky thread).
|
||||
pub system: bool,
|
||||
/// The post this one answered (which may sit on the same level).
|
||||
pub reply_to_id: Option<i64>,
|
||||
}
|
||||
|
||||
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, system";
|
||||
delete_reason, system, reply_to_id";
|
||||
|
||||
/// Posts as the thread page shows them: authors, reactions, the viewer's own
|
||||
/// reaction. A removed post keeps its place with the reason; only
|
||||
@@ -131,10 +133,23 @@ pub async fn posts_json(db: &PgPool, viewer: &Viewer, posts: &[PostRow]) -> ApiR
|
||||
.bind(&ids)
|
||||
.fetch_all(db)
|
||||
.await?;
|
||||
// Whom each reply answers: the author of the post it replied to.
|
||||
let answered: Vec<i64> = posts.iter().filter_map(|p| p.reply_to_id).collect();
|
||||
let answered: HashMap<i64, Option<String>> = sqlx::query_as::<_, (i64, Option<String>)>(
|
||||
"SELECT p.id, m.nickname FROM forum.posts p LEFT JOIN forum.members m ON m.user_id = p.author_id \
|
||||
WHERE p.id = ANY($1)",
|
||||
)
|
||||
.bind(&answered)
|
||||
.fetch_all(db)
|
||||
.await?
|
||||
.into_iter()
|
||||
.collect();
|
||||
let moderator = viewer.is_moderator();
|
||||
Ok(posts
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let reply_to =
|
||||
p.reply_to_id.map(|id| json!({ "id": id, "nickname": answered.get(&id).cloned().flatten() }));
|
||||
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();
|
||||
@@ -164,6 +179,7 @@ pub async fn posts_json(db: &PgPool, viewer: &Viewer, posts: &[PostRow]) -> ApiR
|
||||
"mine": mine.get(&p.id),
|
||||
"mentions": mentions,
|
||||
"system": p.system,
|
||||
"reply_to": reply_to,
|
||||
});
|
||||
if moderator {
|
||||
post["down"] = json!(down);
|
||||
@@ -401,6 +417,9 @@ pub async fn reply(
|
||||
let member = viewer.require_writer()?;
|
||||
open_thread(&state.db, &viewer, id).await?;
|
||||
let body = text::body(&req.body)?;
|
||||
// The post answered (shown as "↪ Holdfény"), and where the reply goes:
|
||||
// under the first-level post (two levels at most).
|
||||
let reply_to = req.parent_id;
|
||||
let parent = match req.parent_id {
|
||||
None => None,
|
||||
Some(parent_id) => {
|
||||
@@ -418,15 +437,18 @@ pub async fn reply(
|
||||
if is_opening { None } else { Some(grandparent.unwrap_or(parent_id)) }
|
||||
}
|
||||
};
|
||||
let reply_to = reply_to.filter(|_| parent.is_some());
|
||||
check_limits(&state, &viewer, member, false).await?;
|
||||
|
||||
let mut tx = state.db.begin().await?;
|
||||
let post: PostRow = sqlx::query_as(&format!(
|
||||
"INSERT INTO forum.posts (thread_id, author_id, parent_id, body) VALUES ($1, $2, $3, $4) RETURNING {POST_COLUMNS}"
|
||||
"INSERT INTO forum.posts (thread_id, author_id, parent_id, reply_to_id, body) VALUES ($1, $2, $3, $4, $5) \
|
||||
RETURNING {POST_COLUMNS}"
|
||||
))
|
||||
.bind(id)
|
||||
.bind(member.user_id)
|
||||
.bind(parent)
|
||||
.bind(reply_to)
|
||||
.bind(&body)
|
||||
.fetch_one(&mut *tx)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user