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)
})
+23
View File
@@ -1314,3 +1314,26 @@ async fn a_question_about_ones_chart(pool: PgPool) {
.unwrap();
assert!(revoked);
}
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn the_first_hundred_are_founders(pool: PgPool) {
let app = TestApp::new(pool);
let anna = app.member("anna@example.com", "Csendesvíz", &["user"]).await;
// Ninety-nine more founders already (made up), then Bea comes too late.
sqlx::query(
"WITH u AS (INSERT INTO users (id, email, display_name) \
SELECT gen_random_uuid(), 'f' || n || '@example.invalid', 'F' FROM generate_series(1, 99) n \
RETURNING id, email) \
INSERT INTO forum.members (user_id, nickname, nickname_key, avatar, founder) \
SELECT id, 'Alapito ' || email, 'alapito ' || email, 'hold-ejkek', true FROM u",
)
.execute(&app.pool)
.await
.unwrap();
let bea = app.member("bea@example.com", "Holdfény", &["user"]).await;
let thread = app.thread(&anna, "torzsasztal", "Sziasztok").await;
app.reply(&bea, thread, "Szia!", None).await;
let shown = app.get(&format!("/v1/forum/threads/{thread}"), None).await;
assert_eq!(shown["posts"][0]["author"]["founder"], true);
assert_eq!(shown["posts"][1]["author"]["founder"], false);
}