diff --git a/crates/db/migrations/0044_forum_founders.sql b/crates/db/migrations/0044_forum_founders.sql new file mode 100644 index 0000000..45a56ad --- /dev/null +++ b/crates/db/migrations/0044_forum_founders.sql @@ -0,0 +1,5 @@ +-- "Alapító tag": the first hundred members (in the order they chose a +-- nickname) keep the badge for good, however many come after them. +ALTER TABLE forum.members ADD COLUMN founder boolean NOT NULL DEFAULT false; +UPDATE forum.members SET founder = true +WHERE user_id IN (SELECT user_id FROM forum.members ORDER BY created_at, user_id LIMIT 100); diff --git a/services/forum/src/routes/members.rs b/services/forum/src/routes/members.rs index 2cc34a2..77d3629 100644 --- a/services/forum/src/routes/members.rs +++ b/services/forum/src/routes/members.rs @@ -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) diff --git a/services/forum/src/routes/mod.rs b/services/forum/src/routes/mod.rs index 5cec032..b16cae0 100644 --- a/services/forum/src/routes/mod.rs +++ b/services/forum/src/routes/mod.rs @@ -230,6 +230,7 @@ struct AuthorRow { roles: Vec, 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) -> Result } let rows: Vec = 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) -> Result "signs": shown, "listener": r.listener, "supporter": r.supporter, + "founder": r.founder, }); (r.user_id, value) }) diff --git a/services/forum/src/tests.rs b/services/forum/src/tests.rs index 9d315b6..7a62c24 100644 --- a/services/forum/src/tests.rs +++ b/services/forum/src/tests.rs @@ -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); +} diff --git a/services/frontend/src/app/adatvedelem/page.tsx b/services/frontend/src/app/adatvedelem/page.tsx index b223d3c..abb069d 100644 --- a/services/frontend/src/app/adatvedelem/page.tsx +++ b/services/frontend/src/app/adatvedelem/page.tsx @@ -152,8 +152,8 @@ export default async function PrivacyPage() { Fórumprofilod: az álneved (a korábbiakat 90 napig, hogy más ne vehesse fel), az avatarod vagy a feltöltött saját képed (kicsinyítve, a kép rejtett adatai, például a helyszín nélkül), a bemutatkozásod, a képletedből megosztott jegyek, hogy önkéntes kísérő vagy-e, a Támogató - jelvény (ha bekapcsolod, mások látják, hogy vásároltál), a láthatatlan mód és az e-mail-értesítések - beállítása + jelvény (ha bekapcsolod, mások látják, hogy vásároltál), hogy az első száz tag közé tartozol-e + (Alapító tag), a láthatatlan mód és az e-mail-értesítések beállítása Részvétel a fórumon; a jegyek megosztása és a jelvények a saját döntésed Szerződés teljesítése diff --git a/services/frontend/src/app/forum/forum.css b/services/frontend/src/app/forum/forum.css index ced2533..9b235dc 100644 --- a/services/frontend/src/app/forum/forum.css +++ b/services/frontend/src/app/forum/forum.css @@ -567,6 +567,7 @@ body:has(.forum[data-theme="light"]) .site-footer { background: #0d1220; } .fp-mention:hover { color: var(--gold-hover); } .fa-badge-listener { color: var(--harmonic); background: var(--f-blue-tint); } .fa-badge-supporter { color: var(--gold); background: var(--f-tint); } +.fa-badge-founder { color: var(--ok); border: 1px solid var(--line-2); } /* --- own pictures and the site's mark --- */ .av-picture img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; } diff --git a/services/frontend/src/app/forum/tag/[nev]/page.tsx b/services/frontend/src/app/forum/tag/[nev]/page.tsx index 6fe2055..92d407b 100644 --- a/services/frontend/src/app/forum/tag/[nev]/page.tsx +++ b/services/frontend/src/app/forum/tag/[nev]/page.tsx @@ -49,6 +49,7 @@ export default async function MemberPage({ params }: Props) { {a.moderator && } + {a.founder && } {a.listener && } {a.supporter && } diff --git a/services/frontend/src/app/privacy/page.tsx b/services/frontend/src/app/privacy/page.tsx index 0b84271..e9d884d 100644 --- a/services/frontend/src/app/privacy/page.tsx +++ b/services/frontend/src/app/privacy/page.tsx @@ -85,7 +85,7 @@ const DATA: [string, string, string][] = [ "Legitimate interest (Art. 6(1)(f))", ], [ - "Your forum profile: your nickname (earlier ones for 90 days, so nobody else can take them), your avatar or the picture you uploaded (made smaller, without its hidden data such as the location), introduction, the signs of your chart you share, whether you are a volunteer companion (Kísérő), the Támogató (supporter) badge (if you switch it on, others see that you bought something), the invisible mode and your e-mail notification settings", + "Your forum profile: your nickname (earlier ones for 90 days, so nobody else can take them), your avatar or the picture you uploaded (made smaller, without its hidden data such as the location), introduction, the signs of your chart you share, whether you are a volunteer companion (Kísérő), the Támogató (supporter) badge (if you switch it on, others see that you bought something), whether you were among the first hundred members (Alapító tag – founder), the invisible mode and your e-mail notification settings", "Taking part in the forum; sharing the signs and the badges is your choice", "Performance of the contract", ], diff --git a/services/frontend/src/components/forum/AuthorLine.tsx b/services/frontend/src/components/forum/AuthorLine.tsx index 8a4d7d2..9ce46b8 100644 --- a/services/frontend/src/components/forum/AuthorLine.tsx +++ b/services/frontend/src/components/forum/AuthorLine.tsx @@ -103,6 +103,7 @@ export function AuthorLine({ {author.online && (online)} {author.moderator && } + {author.founder && } {author.listener && } {author.supporter && } {badges} diff --git a/services/frontend/src/components/forum/Badges.tsx b/services/frontend/src/components/forum/Badges.tsx index 54d5c01..0ddf139 100644 --- a/services/frontend/src/components/forum/Badges.tsx +++ b/services/frontend/src/components/forum/Badges.tsx @@ -43,7 +43,7 @@ const RANK_ICONS: Record = { ), }; -export type BadgeKind = "mod" | "listener" | "supporter" | "starter" | "sky"; +export type BadgeKind = "mod" | "founder" | "listener" | "supporter" | "starter" | "sky"; const BADGES: Record = { // A shield with a tick. @@ -57,6 +57,19 @@ const BADGES: Record ), }, + // A sprout: there from the beginning. + founder: { + label: "Alapító tag", + title: "A fórum első száz tagja közül való", + icon: ( + <> + + + + + + ), + }, // Two walking side by side. listener: { label: "Kísérő", @@ -118,7 +131,7 @@ export function RankBadge({ rank, name }: { rank: Rank; name: string }) { ); } -/** A badge (Moderátor, Kísérő, Támogató, Szálindító, napi égbolt), with its icon. */ +/** A badge (Moderátor, Alapító tag, Kísérő, Támogató, Szálindító, napi égbolt), with its icon. */ export function Badge({ kind }: { kind: BadgeKind }) { const b = BADGES[kind]; return ( diff --git a/services/frontend/src/components/forum/ThreadView.tsx b/services/frontend/src/components/forum/ThreadView.tsx index 94e0ba4..fa8f279 100644 --- a/services/frontend/src/components/forum/ThreadView.tsx +++ b/services/frontend/src/components/forum/ThreadView.tsx @@ -285,6 +285,7 @@ function PostCard({ {author && } {post.system && } {author?.moderator && } + {author?.founder && !nested && } {author?.listener && } {author?.supporter && } {starter && !post.is_opening && } diff --git a/services/frontend/src/lib/forum.ts b/services/frontend/src/lib/forum.ts index 4d97a23..f541f47 100644 --- a/services/frontend/src/lib/forum.ts +++ b/services/frontend/src/lib/forum.ts @@ -23,6 +23,8 @@ export interface ForumAuthor { listener?: boolean; /** Bought a package and shows the "Támogató" badge. */ supporter?: boolean; + /** One of the first hundred members ("Alapító tag"). */ + founder?: boolean; } export interface ForumViewer {