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:
@@ -58,15 +58,34 @@ async fn topic_list(state: &St, viewer: &Viewer) -> ApiResult<Vec<Value>> {
|
||||
.bind(since)
|
||||
.fetch_all(&state.db)
|
||||
.await?;
|
||||
let readable: Vec<bool> = rows.iter().map(|r| may_read(viewer, &r.visibility)).collect();
|
||||
let readable: Vec<bool> = rows.iter().map(|r| may_read(viewer, &r.visibility, r.id)).collect();
|
||||
let people =
|
||||
super::authors(&state.db, rows.iter().zip(&readable).filter(|(_, ok)| **ok).filter_map(|(r, _)| r.last_author))
|
||||
.await?;
|
||||
// A restricted topic shows by name to members, who may ask to join.
|
||||
let pending: Vec<i16> = match viewer.user_id() {
|
||||
Some(me) => {
|
||||
sqlx::query_scalar("SELECT topic_id FROM forum.topic_members WHERE user_id = $1 AND status = 'pending'")
|
||||
.bind(me)
|
||||
.fetch_all(&state.db)
|
||||
.await?
|
||||
}
|
||||
None => Vec::new(),
|
||||
};
|
||||
Ok(rows
|
||||
.into_iter()
|
||||
.zip(readable)
|
||||
.filter(|(r, _)| r.visibility != "restricted" || viewer.is_moderator())
|
||||
.filter(|(r, _)| r.visibility != "restricted" || viewer.member.is_some() || viewer.is_moderator())
|
||||
.map(|(r, readable)| {
|
||||
let membership = (r.visibility == "restricted").then(|| {
|
||||
if viewer.topics.contains(&r.id) {
|
||||
"approved"
|
||||
} else if pending.contains(&r.id) {
|
||||
"pending"
|
||||
} else {
|
||||
"none"
|
||||
}
|
||||
});
|
||||
let mut topic = json!({
|
||||
"id": r.id,
|
||||
"slug": r.slug,
|
||||
@@ -75,6 +94,7 @@ async fn topic_list(state: &St, viewer: &Viewer) -> ApiResult<Vec<Value>> {
|
||||
"visibility": r.visibility,
|
||||
"listening": r.listening,
|
||||
"readable": readable,
|
||||
"membership": membership,
|
||||
});
|
||||
if readable {
|
||||
topic["thread_count"] = json!(r.thread_count);
|
||||
@@ -143,9 +163,21 @@ pub async fn home(state: St, viewer: Viewer) -> ApiResult<Json<Value>> {
|
||||
.fetch_all(&state.db)
|
||||
.await?;
|
||||
|
||||
// "Most itt vannak": members seen in the last few minutes (not the invisible ones).
|
||||
let present: Vec<Uuid> = sqlx::query_scalar(
|
||||
"SELECT user_id FROM forum.members WHERE NOT invisible \
|
||||
AND last_seen_at > now() - make_interval(mins => $1) ORDER BY last_seen_at DESC LIMIT 24",
|
||||
)
|
||||
.bind(crate::auth::ONLINE_MINUTES as i32)
|
||||
.fetch_all(&state.db)
|
||||
.await?;
|
||||
let people = super::authors(&state.db, present.iter().copied()).await?;
|
||||
let online: Vec<Value> = present.iter().filter_map(|id| people.get(id).cloned()).collect();
|
||||
|
||||
Ok(Json(json!({
|
||||
"viewer": viewer_json(&viewer),
|
||||
"followed": followed,
|
||||
"online": online,
|
||||
"topics": topics,
|
||||
"unanswered": cards_json(&state.db, unanswered).await?,
|
||||
"hot": cards_json(&state.db, hot).await?,
|
||||
@@ -170,18 +202,49 @@ async fn followed_counts(state: &St, viewer: &Viewer) -> ApiResult<Option<Value>
|
||||
Ok(Some(json!({ "new_replies": replies, "threads": threads })))
|
||||
}
|
||||
|
||||
/// Threads asking to be heard (or in a listening topic) that have waited an
|
||||
/// hour without a reply (two weeks at most), not the listener's own.
|
||||
pub const WAITING_SQL: &str = "th.reply_count = 0 AND NOT th.locked AND th.deleted_at IS NULL AND NOT th.system \
|
||||
AND th.created_at < now() - interval '1 hour' AND th.created_at > now() - interval '14 days' \
|
||||
AND (th.intent = 'listen' OR tp.listening)";
|
||||
|
||||
async fn waiting_count(state: &St, viewer: &Viewer) -> ApiResult<i64> {
|
||||
let me = viewer.user_id();
|
||||
Ok(sqlx::query_scalar(&format!(
|
||||
"SELECT count(*) FROM forum.threads th JOIN forum.topics tp ON tp.id = th.topic_id \
|
||||
WHERE {WAITING_SQL} AND th.author_id IS DISTINCT FROM $1 AND ({})",
|
||||
super::visible_topics(viewer)
|
||||
))
|
||||
.bind(me)
|
||||
.fetch_one(&state.db)
|
||||
.await?)
|
||||
}
|
||||
|
||||
/// For the forum's menu on every page: who the viewer is, and the badge.
|
||||
pub async fn nav(state: St, viewer: Viewer) -> ApiResult<Json<Value>> {
|
||||
let messages = match &viewer.member {
|
||||
Some(m) => Some(super::messages::unread_count(&state.db, m.user_id).await?),
|
||||
None => None,
|
||||
};
|
||||
let reports = if viewer.is_moderator() { Some(super::reports::open_count(&state.db).await?) } else { None };
|
||||
let reports = if viewer.is_moderator() {
|
||||
let requests: i64 = sqlx::query_scalar("SELECT count(*) FROM forum.topic_members WHERE status = 'pending'")
|
||||
.fetch_one(&state.db)
|
||||
.await?;
|
||||
Some(super::reports::open_count(&state.db).await? + requests)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
// Volunteer listeners: threads asking to be heard, still without a reply.
|
||||
let waiting = match &viewer.member {
|
||||
Some(m) if m.listener => Some(waiting_count(&state, &viewer).await?),
|
||||
_ => None,
|
||||
};
|
||||
Ok(Json(json!({
|
||||
"viewer": viewer_json(&viewer),
|
||||
"followed": followed_counts(&state, &viewer).await?,
|
||||
"messages": messages,
|
||||
"reports": reports,
|
||||
"waiting": waiting,
|
||||
})))
|
||||
}
|
||||
|
||||
@@ -208,7 +271,7 @@ pub async fn topic(
|
||||
.fetch_optional(&state.db)
|
||||
.await?;
|
||||
let (id, name, description, visibility, listening) = topic.ok_or(ApiError::NotFound("topic"))?;
|
||||
if !may_read(&viewer, &visibility) {
|
||||
if !may_read(&viewer, &visibility, id) {
|
||||
// A members-only topic asks for a login; a restricted one stays hidden.
|
||||
return Err(if visibility == "members" { ApiError::Unauthorized } else { ApiError::NotFound("topic") });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user