Forum: the "Alapító tag" badge for the first hundred members

The first hundred members (in the order they chose a nickname) keep it for
good; joining is serialised so there are never more than a hundred. Shown
next to the nickname in posts, author lines and profiles; the privacy
notice mentions it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 15:43:24 +00:00
co-authored by Claude Opus 5.5
parent 863002c1e7
commit 8fc550662e
12 changed files with 64 additions and 10 deletions
+9 -4
View File
@@ -16,6 +16,9 @@ use crate::auth::{self, Viewer};
use crate::error::{ApiError, ApiResult};
use crate::text;
/// The first this many members get the "Alapító tag" badge for good.
const FOUNDERS: i64 = 100;
/// A nickname may change once in this many days (spelling fixes that keep the
/// same folded form any time).
const NICKNAME_CHANGE_DAYS: i64 = 30;
@@ -177,10 +180,12 @@ pub async fn save_me(
let mut tx = state.db.begin().await?;
let result = match &viewer.member {
None => {
sqlx::query(
"INSERT INTO forum.members (user_id, nickname, nickname_key, avatar, bio, chart_share, invisible) \
VALUES ($1, $2, $3, $4, $5, $6, $7)",
)
// One newcomer at a time, so the hundredth founder is the last.
sqlx::query("SELECT pg_advisory_xact_lock(hashtext('forum_founders'))").execute(&mut *tx).await?;
sqlx::query(&format!(
"INSERT INTO forum.members (user_id, nickname, nickname_key, avatar, bio, chart_share, invisible, founder) \
VALUES ($1, $2, $3, $4, $5, $6, $7, (SELECT count(*) < {FOUNDERS} FROM forum.members WHERE founder))"
))
.bind(user.id)
.bind(&nickname)
.bind(&key)
+3 -1
View File
@@ -230,6 +230,7 @@ struct AuthorRow {
roles: Vec<String>,
listener: bool,
supporter: bool,
founder: bool,
}
/// How members appear next to what they wrote: nickname, avatar, rank,
@@ -243,7 +244,7 @@ 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.listener, \
m.chart_share, u.roles, m.listener, m.founder, \
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)",
@@ -270,6 +271,7 @@ pub async fn authors(db: &PgPool, ids: impl IntoIterator<Item = Uuid>) -> Result
"signs": shown,
"listener": r.listener,
"supporter": r.supporter,
"founder": r.founder,
});
(r.user_id, value)
})