From 8bc426460d010db91f0cb6493cb1ad70d8821b52 Mon Sep 17 00:00:00 2001 From: feco Date: Thu, 26 Nov 2026 13:02:38 +0000 Subject: [PATCH] Forum: whom a reply answers, icon badges, the new features on the pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL --- crates/db/migrations/0042_forum_reply_to.sql | 4 + docs/kozosseg.md | 26 +- services/backend/src/routes/account.rs | 13 +- services/forum/src/routes/threads.rs | 26 +- services/forum/src/tests.rs | 4 +- .../frontend/src/app/adatvedelem/page.tsx | 25 +- services/frontend/src/app/aszf/page.tsx | 5 +- .../frontend/src/app/forum/[tema]/page.tsx | 12 +- .../src/app/forum/beallitasok/ProfileForm.tsx | 125 ++++++++- services/frontend/src/app/forum/forum.css | 64 ++++- services/frontend/src/app/forum/layout.tsx | 1 + .../src/app/forum/moderalas/TopicsAdmin.tsx | 238 ++++++++++++++++++ .../frontend/src/app/forum/moderalas/page.tsx | 44 +++- services/frontend/src/app/forum/page.tsx | 114 ++++++--- .../src/app/forum/tag/[nev]/BanPanel.tsx | 15 +- .../frontend/src/app/forum/tag/[nev]/page.tsx | 13 +- .../src/app/forum/uzenetek/[id]/Chat.tsx | 3 +- services/frontend/src/app/privacy/page.tsx | 22 +- .../src/components/forum/AuthorLine.tsx | 7 +- .../frontend/src/components/forum/Avatar.tsx | 12 + .../frontend/src/components/forum/Badges.tsx | 128 ++++++++++ .../src/components/forum/Composer.tsx | 79 +++++- .../src/components/forum/ForumNav.tsx | 15 +- .../src/components/forum/JoinTopic.tsx | 70 ++++++ .../src/components/forum/PostBody.tsx | 34 ++- .../src/components/forum/ThreadList.tsx | 2 +- .../src/components/forum/ThreadView.tsx | 69 ++++- services/frontend/src/lib/forum.ts | 42 ++++ 28 files changed, 1112 insertions(+), 100 deletions(-) create mode 100644 crates/db/migrations/0042_forum_reply_to.sql create mode 100644 services/frontend/src/app/forum/moderalas/TopicsAdmin.tsx create mode 100644 services/frontend/src/components/forum/Badges.tsx create mode 100644 services/frontend/src/components/forum/JoinTopic.tsx diff --git a/crates/db/migrations/0042_forum_reply_to.sql b/crates/db/migrations/0042_forum_reply_to.sql new file mode 100644 index 0000000..659f0da --- /dev/null +++ b/crates/db/migrations/0042_forum_reply_to.sql @@ -0,0 +1,4 @@ +-- Replies stay two levels deep (a reply to a reply goes under the same +-- first-level post, `parent_id`); `reply_to_id` keeps which post it answered, +-- so the page can say whom it is for ("↪ Holdfény"). +ALTER TABLE forum.posts ADD COLUMN reply_to_id bigint REFERENCES forum.posts ON DELETE SET NULL; diff --git a/docs/kozosseg.md b/docs/kozosseg.md index 6f90b2d..baa08b0 100644 --- a/docs/kozosseg.md +++ b/docs/kozosseg.md @@ -149,21 +149,34 @@ Jelölés: ami mellett **(javaslat)** áll, azt még nem hagytuk jóvá, a több - Csak az önálló kód alakul át, így a linkek változatlanok maradnak. - **Színes emojik:** a fórum betűtípus-sorában ott vannak a rendszer színes emojibetűi (Apple, Segoe, Noto Color Emoji). +### Ami elkészült (6. kör) + +- **Új dizájn:** saját reakcióikonok, tömörebb hozzászólások, a kérdés (a nyitó hozzászólás) külön kártyán, a válaszok a lapon. A szövegdoboz feletti meghallgatós emlékeztető kikerült; a cím alatti „Csak meghallgatást kér” jelzés maradt. +- **Jelvények ikonnal:** minden rangnak saját ikonja van (Vándor: ösvény, Kereső: iránytű, Fonó: orsó, Csillagfonó: csillag fonallal, Sorsfonó: a sorsfonal köre; a magasabb rangoké arany). Ikont kapott a Moderátor (pajzs), a Meghallgató (fül), a Támogató (drágakő), a Szálindító (toll) és a napi égbolt (holdsarló) is. +- **Kinek válaszolsz:** a válaszok legfeljebb két szint mélyek (az eredeti hozzászólás és alatta a válaszok). Ha valaki egy válaszra válaszol, az ugyanoda kerül, de a neve mellett látszik, kinek szól: „↪ Holdfény” (`posts.reply_to_id`, 0042). +- **Napi „Mai égbolt” szál:** a worker reggel 5 órától nyitja meg az „Égbolt és képletek” témában, a backend nyilvános égboltjából (a Hold jegye és fázisa, jegyváltás, retrográd bolygók, a következő holdfázis), kötött magyar mondatokkal, AI nélkül. Egy napig ki van tűzve; a szerzője „Sorsfonalak”. +- **Önkéntes meghallgatók** (a Kereső rangtól): „Meghallgató” jelvény; a Fórum fülön szám jelzi a válaszra váró meghallgatós szálakat; e-mail, ha egy szál két órája vár (ha kérik, legfeljebb hatóránként egy). +- **Említés:** „@Holdfény” (szóközös álnévvel is). Az említett tag követni kezdi a szálat, élőben és (ha kéri) e-mailben is értesül. Gépelés közben ajánló segít, az említés link a profilra. +- **Saját avatar** a Kereső rangtól: 256×256-os JPEG lesz belőle, a kép rejtett adatai (EXIF) nélkül, a backenddel közös tárolóban (`crates/object-storage`, `forum-avatars/`). A moderátor visszaállíthatja a kezdő avatart. A fiók törlésekor a kép is törlődik. +- **„Támogató” jelvény:** csak vásárlóknak, és csak ha bekapcsolják. Rangot nem ad. +- **Zárt témák:** az admin a Moderálás → Témák fülön hoz létre és szerkeszt témát. A zárt témába a tag pár szóval jelentkezik, egy moderátor jóváhagyja vagy elutasítja, és később el is távolíthatja. Az elutasított jelentkezés azonnal törlődik (a moderálási naplóban marad nyoma). +- **Csak tagoknak szóló témák:** a téma oldalán és a szál morzsamenüjében belépve is látszik, hogy kívülről és a keresőkből nem olvasható. +- **„Most itt vannak”** a főoldal oldalsávjában (a láthatatlan módú tagok nélkül). +- **Heti összefoglaló e-mail:** vasárnap este, a hét legélénkebb szálaival és a válaszra várókkal. Alapból ki van kapcsolva, az e-mail-értesítések között kapcsolható be. +- **Jogi szövegek:** az adatkezelési tájékoztató (magyar és angol) és az ÁSZF 8.1 pontja kiegészült (saját kép, jelvények, említések, zárt témák, heti összefoglaló). Az adatexport ezeket is tartalmazza. + ### Élesítéskor - `FORUM_URL=http://forum:8083` az éles `.env`-be. - Az adatvédelmi tájékoztató dátumát (`PRIVACY_UPDATED` és `PRIVACY_UPDATED_EN` a `legal.ts`-ben) szintén az élesítés napjára kell írni. - Az ÁSZF hatálybalépési dátumát (`TERMS_UPDATED` a `services/frontend/src/lib/legal.ts`-ben és `TERMS_VERSION` a `services/backend/src/routes/payments.rs`-ben) az élesítés napjára kell átírni, ha az nem 2026. november 26. -- Ha közben a `main`-re új migráció került, a fórumé (0038–0040) ütközhet vele, és át kell számozni. +- Ha közben a `main`-re új migráció került, a fórumé (0038–0042) ütközhet vele, és át kell számozni. +- A fórum szolgáltatásnak kell az `S3_ENDPOINT`, `S3_BUCKET`, `S3_REGION` (az éles `.env`-ben, ugyanaz, mint a backendé) és a kulcsok (`.env.secrets`); a workernek a `BACKEND_URL` (a compose fájlban már benne van). ### Ami még hátravan - - **Hírlevél:** az oldalnak még nincs hírlevele. Ha lesz, külön, kifejezett hozzájárulással, nem a fórum beállításai között. -- **Napi „Mai égbolt” szál:** a worker nyitná meg automatikusan. -- **AI-funkciók:** előszűrés, lelki krízis jelzése, az AI-összefoglaló kártya a főoldalon. -- **Saját avatar feltöltése** (Spaces), és a „Támogató” jelvény. -- **Zárt témák** jóváhagyással (a séma tudja, a felület még nem). +- **AI-funkciók:** egyelőre nem kellenek (előszűrés, krízisjelzés, összefoglaló a főoldalon). ## Cél @@ -390,7 +403,6 @@ A fórummotor **külön szolgáltatás**, hogy később, például Kubernetesen, - **Képlettestvérek:** szálak azonos Hold-jegyűektől vagy Aszcendensűektől. - **Csillagszülinap:** az oldal felköszönti a tagot a Nap-visszatérésén. **Csak kifejezett engedéllyel,** mert elárulja a születésnapot. - **Élő Tranzit-szoba:** időhöz kötött élő beszélgetés újholdkor és teliholdkor, ha már elég ember van hozzá. -- **Támogató tagság** jelvénnyel. ## AI-szereplők? (bizonytalan) diff --git a/services/backend/src/routes/account.rs b/services/backend/src/routes/account.rs index 2763951..8e59cad 100644 --- a/services/backend/src/routes/account.rs +++ b/services/backend/src/routes/account.rs @@ -180,7 +180,8 @@ pub async fn export(State(state): St, auth: AuthUser) -> ApiResult = sqlx::query_scalar("SELECT avatar FROM forum.members WHERE user_id = $1") + .bind(auth.id()) + .fetch_optional(&mut *tx) + .await?; sqlx::query("DELETE FROM users WHERE id = $1").bind(auth.id()).execute(&mut *tx).await?; tx.commit().await?; + if let (Some(file), Some(storage)) = (avatar.as_deref().and_then(|a| a.strip_prefix("upload:")), &state.storage) + && let Err(e) = storage.delete(&format!("forum-avatars/{file}")).await + { + tracing::warn!(error = %e, "removing a deleted account's forum avatar"); + } tracing::info!(user = %auth.id(), "account deleted"); Ok((StatusCode::NO_CONTENT, jar.add(removal_cookie(&state.config)))) } diff --git a/services/forum/src/routes/threads.rs b/services/forum/src/routes/threads.rs index 852f211..81ddb74 100644 --- a/services/forum/src/routes/threads.rs +++ b/services/forum/src/routes/threads.rs @@ -92,10 +92,12 @@ pub struct PostRow { pub delete_reason: Option, /// 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, } 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 = posts.iter().filter_map(|p| p.reply_to_id).collect(); + let answered: HashMap> = sqlx::query_as::<_, (i64, Option)>( + "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?; diff --git a/services/forum/src/tests.rs b/services/forum/src/tests.rs index 8d7eeb5..8bdb183 100644 --- a/services/forum/src/tests.rs +++ b/services/forum/src/tests.rs @@ -253,7 +253,9 @@ async fn threads_replies_and_what_is_new(pool: PgPool) { assert_eq!(first["author"]["nickname"], "Holdfény"); let second = app.reply(&anna, heart, "Köszönöm.", first["id"].as_i64()).await; let third = app.reply(&bea, heart, "Szívesen.", second["id"].as_i64()).await; - assert_eq!(third["parent_id"], first["id"]); + assert_eq!(third["parent_id"], first["id"], "two levels at most"); + assert_eq!(third["reply_to"], json!({"id": second["id"], "nickname": "Csendesvíz"}), "but it says whom it answers"); + assert!(first["reply_to"].is_null()); // Anna follows her thread: one new reply from Bea since she last read. let home = app.get("/v1/forum/home", Some(&anna)).await; diff --git a/services/frontend/src/app/adatvedelem/page.tsx b/services/frontend/src/app/adatvedelem/page.tsx index 1bfc191..f53acc0 100644 --- a/services/frontend/src/app/adatvedelem/page.tsx +++ b/services/frontend/src/app/adatvedelem/page.tsx @@ -149,21 +149,28 @@ export default async function PrivacyPage() { - Fórumprofilod: az álneved (a korábbiakat 90 napig, hogy más ne vehesse fel), az avatarod, a - bemutatkozásod, a képletedből megosztott jegyek, a láthatatlan mód és az e-mail-értesítések + 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 meghallgató 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 - Részvétel a fórumon; a jegyek megosztása a saját döntésed + 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 A fórumon írt szálaid és hozzászólásaid, a reakcióid és „Ez segített” jelöléseid, a pontjaid és a - rangod; hogy mit olvastál el, és mely szálakat követed + rangod; kiket említettél (@álnév); hogy mit olvastál el, és mely szálakat követed A fórum működése, a rangok, az újdonságok jelzése Szerződés teljesítése + + Zárt témákba küldött jelentkezéseid (a pár szavas indoklással) és a tagságaid + A zárt témák: a moderátorok döntenek a felvételről + Szerződés teljesítése + Mikor jártál utoljára a fórumon Az online jelzés (zöld pötty); a láthatatlan móddal kikapcsolhatod @@ -212,8 +219,9 @@ export default async function PrivacyPage() {

Fórum: amit a nyilvános témákban írsz, bárki láthatja, a keresők is; a csak tagoknak szóló - témákat csak belépett felhasználók látják. A hozzászólásaid mellett az álneved, az avatarod, a rangod és az - általad megosztott jegyek látszanak; a valódi neved, az e-mail-címed és a születési adataid nem, és a + témákat csak belépett felhasználók látják, a zárt témákat csak a jóváhagyott tagjaik. A hozzászólásaid + mellett az álneved, az avatarod, a rangod, az általad megosztott jegyek és a bekapcsolt jelvényeid + (Meghallgató, Támogató) látszanak; a valódi neved, az e-mail-címed és a születési adataid nem, és a képletedből soha nem mutatunk fokokat. A privát üzeneteidet csak a beszélgetés két résztvevője látja; a moderátorok csak akkor, ha valaki egy üzenetet jelent, és akkor is csak a jelentett üzenetet és az előtte lévő néhányat. A moderátorok (az üzemeltető által kijelölt tagok) a valódi nevedet és az e-mail-címedet nem @@ -236,7 +244,7 @@ export default async function PrivacyPage() {

Mire használjuk: a fiókod létrehozására és arra, hogy belépéskor felismerjünk; az e-mail-címedet a rendszerlevelekhez (például ha elkészült egy elemzésed, elfogadták a meghívódat, vagy - válasz érkezett a fórumon, ha ezt kérted); a + válasz érkezett vagy megemlítettek a fórumon, illetve a fórum heti összefoglalója, ha ezeket kérted); a nevedet a megjelenítéshez; a nyelvet az oldal és az elemzések nyelvéhez.

@@ -354,7 +362,8 @@ export default async function PrivacyPage() {

  • A számlázáshoz szükséges adatokat a számviteli törvény szerinti ideig (8 évig) őrizzük.
  • - A fórumprofilodat, a privát beszélgetéseidet, a reakcióidat és a követéseidet a fiókod törléséig. A fiók + A fórumprofilodat (a saját képeddel együtt), a privát beszélgetéseidet, a reakcióidat, a követéseidet és + a zárt témák tagságát a fiókod törléséig; az elutasított jelentkezést azonnal töröljük. A fiók törlésekor a privát beszélgetéseid a másik fél számára is törlődnek. A szálaid és a hozzászólásaid „Törölt tag” néven megmaradnak, hogy a beszélgetések érthetők maradjanak; ha a törlésüket is kéred, írj a fenti e-mail-címre. diff --git a/services/frontend/src/app/aszf/page.tsx b/services/frontend/src/app/aszf/page.tsx index c728bb3..82b853f 100644 --- a/services/frontend/src/app/aszf/page.tsx +++ b/services/frontend/src/app/aszf/page.tsx @@ -148,11 +148,14 @@ export default async function TermsPage() {

    8.1. Olvasás, írás, álnév

    A nyilvános témákat bárki olvashatja, és a keresők is megjeleníthetik. A csak tagoknak szóló témákat - (például „Ami a szívemen van”) csak belépve lehet olvasni, és a keresők nem látják. Írni, reagálni és üzenni + (például „Ami a szívemen van”) csak belépve lehet olvasni, és a keresők nem látják. A zárt témákat csak a jóváhagyott tagjaik olvashatják; a + csatlakozásról egy moderátor dönt. Írni, reagálni és üzenni belépve, egy választott álnévvel lehet. Az álnév ne legyen a valódi neved, ha nem szeretnéd, hogy felismerjenek; nem lehet sértő vagy megtévesztő, és nem utánozhat más tagot, moderátort vagy a Sorsfonalakat. A valódi neved, az e-mail-címed és a születési adataid a fórumon nem jelennek meg; a képletedből csak annyi látszik, amennyit a fórumprofilodban megosztasz, fokok nélkül. + A Kereső rangtól saját képet is feltölthetsz avatarnak: csak olyat, amelyhez jogod van, és amelyen más nem + ismerhető fel a hozzájárulása nélkül; a moderátorok a nem odaillő képet eltávolíthatják.

    8.2. Házirend

    diff --git a/services/frontend/src/app/forum/[tema]/page.tsx b/services/frontend/src/app/forum/[tema]/page.tsx index 003af12..6281daa 100644 --- a/services/frontend/src/app/forum/[tema]/page.tsx +++ b/services/frontend/src/app/forum/[tema]/page.tsx @@ -49,9 +49,15 @@ export default async function TopicPageView({ params, searchParams }: Props) {

    {topic.name}

    {topic.description}

    - {topic.listening && ( -

    - Meghallgatós téma: itt nincs ⌄, és a szálak alapból meghallgatást kérnek, nem tanácsot. + {topic.visibility !== "public" && ( +

    + + {topic.visibility === "members" + ? "Ezt a témát csak belépett tagok látják: amit itt írsz, kívülről és a keresőkből nem olvasható." + : "Zárt kör: ezt a témát csak a jóváhagyott tagjai látják."}

    )}
    diff --git a/services/frontend/src/app/forum/beallitasok/ProfileForm.tsx b/services/frontend/src/app/forum/beallitasok/ProfileForm.tsx index c4e7f47..7d190c7 100644 --- a/services/frontend/src/app/forum/beallitasok/ProfileForm.tsx +++ b/services/frontend/src/app/forum/beallitasok/ProfileForm.tsx @@ -26,8 +26,19 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null }) const [share, setShare] = useState(member?.chart_share ?? "none"); const [invisible, setInvisible] = useState(member?.invisible ?? false); const [email, setEmail] = useState( - member?.email ?? { replies: "daily", followed: "off", messages: "instant" }, + member?.email ?? { + replies: "daily", + followed: "off", + messages: "instant", + mentions: "instant", + listener: "off", + weekly: false, + }, ); + const [listener, setListener] = useState(member?.listener ?? false); + const [supporter, setSupporter] = useState(member?.supporter_badge ?? false); + const [uploading, setUploading] = useState(false); + const uploaded = avatar.startsWith("upload:"); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [saved, setSaved] = useState(false); @@ -55,7 +66,16 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null }) try { const res = await api("/forum/me", { method: "PUT", - body: { nickname, avatar: avatar || null, bio, chart_share: share, invisible, email }, + body: { + nickname, + avatar: avatar || null, + bio, + chart_share: share, + invisible, + email, + listener, + supporter_badge: supporter, + }, }); if (back) { router.push(back); @@ -135,6 +155,47 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null }) )} {!avatar && Ha nem választasz, az álneved alapján kapsz egyet.} + {member?.can_upload_avatar && ( +
    + {uploaded && } + + + JPEG, PNG vagy WebP, legfeljebb 8 MB. Négyzetre vágjuk és kicsinyítjük, a kép adatait (hely, gép) + eltávolítjuk. Ha egy kezdő avatart választasz, a saját kép törlődik. + +
    + )}
    @@ -183,6 +244,31 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null }) + {member?.can_listen && ( + + )} + + {me.can_supporter && ( + + )} +
    Értesítések e-mailben
    @@ -217,7 +303,42 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null }) + + + {listener && ( + <> + + + + )}
    + Ha éppen itt vagy a fórumon, nem küldünk levelet: a menü jelzi az újdonságot. A privát üzenetek szövege nem kerül bele a levélbe. diff --git a/services/frontend/src/app/forum/forum.css b/services/frontend/src/app/forum/forum.css index 874c15b..f5e3b22 100644 --- a/services/frontend/src/app/forum/forum.css +++ b/services/frontend/src/app/forum/forum.css @@ -154,6 +154,14 @@ body:has(.forum[data-theme="light"]) .site-footer { background: #0d1220; } .fa-name:hover { color: var(--gold); } .fa-rank { font-size: 12px; color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 0 6px; } .fa-badge { font-size: 12px; border-radius: 6px; padding: 0 6px; } +.fa-rank, .fa-badge { display: inline-flex; align-items: center; gap: 3px; line-height: 18px; white-space: nowrap; } +.fa-icon { + width: 12px; height: 12px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; + stroke-linecap: round; stroke-linejoin: round; +} +.fa-badge-new .fa-icon { display: none; } +/* The higher ranks: a golden icon. */ +.fa-rank-fono .fa-icon, .fa-rank-csillagfono .fa-icon, .fa-rank-sorsfono .fa-icon { color: var(--gold); } .fa-badge-mod { color: var(--ok); background: var(--f-green-tint); } .fa-badge-starter { color: var(--gold); border: 1px solid var(--line-2); } .fa-badge-new { color: var(--gold-ink); background: var(--gold); font-weight: 600; } @@ -333,7 +341,13 @@ body:has(.forum[data-theme="light"]) .site-footer { background: #0d1220; } .fp-content { grid-area: body; min-width: 0; display: flex; flex-direction: column; gap: 8px; } .fp-actions { grid-area: actions; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; } .fp-report { grid-area: report; } -.fp-opening { padding-top: 10px; padding-bottom: 14px; } +/* The question (the opening post) stands apart: a card; the replies sit on the page. */ +.fp.fp-opening { + margin: 6px 0 10px; padding: 16px 18px 14px; border: 1px solid var(--line); border-radius: 16px; + background: var(--panel); +} +.forum[data-theme="light"] .fp.fp-opening { box-shadow: 0 1px 3px rgba(27, 34, 54, 0.06); } +.fp-opening .fp-body { font-size: 17px; } .fp-opening .fp-names .fa-name { font-size: 16px; } .ftv-children .fp:last-child { border-bottom: 0; } .fp-nested { padding: 8px 0; row-gap: 4px; } @@ -543,3 +557,51 @@ body:has(.forum[data-theme="light"]) .site-footer { background: #0d1220; } @media (prefers-reduced-motion: reduce) { .ftyping-dots span { animation: none; opacity: 0.6; } } .fp-link { min-height: 32px; padding: 0 8px; border: 0; background: none; color: var(--gold); font: 500 15px var(--font-body); cursor: pointer; } .fp-link:hover { color: var(--gold-hover); } + +/* --- whom a reply answers, mentions, badges --- */ +.fp-replyto { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; color: var(--muted); } +.fp-replyto svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; } +.fp-mention { color: var(--gold); font-weight: 500; text-decoration: none; background: var(--f-tint); border-radius: 4px; padding: 0 2px; } +.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); } + +/* --- own pictures and the site's mark --- */ +.av-picture img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; } +.av-site { --av-bg: #1c2540; } +.av-site-mark { stroke: #d9b46a; } +.forum[data-theme="light"] .av-site { --av-bg: #f5ead7; } +.forum[data-theme="light"] .av-site-mark { stroke: #8a6a24; } + +/* --- "@" suggestions while typing --- */ +.fc-suggest { + display: flex; flex-direction: column; align-self: flex-start; min-width: 220px; max-width: 320px; padding: 4px; + background: var(--panel); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--f-shadow); +} +.fc-suggest-item { + display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 10px; border: 0; border-radius: 8px; + background: none; color: var(--ink); font: 400 15px var(--font-body); text-align: left; cursor: pointer; +} +.fc-suggest-item:hover, .fc-suggest-item:focus-visible { background: var(--f-hover); } + +/* --- who is here, restricted topics --- */ +.fh-online { display: flex; flex-direction: column; gap: 10px; } +.forum .fh-online-title { font-family: var(--font-body); font-size: 15px; font-weight: 600; color: var(--ink-2); } +.fh-online-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 12px; } +.fh-online-item { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); text-decoration: none; } +a.fh-online-item:hover { color: var(--gold); } +.fh-topic-closed { flex-wrap: wrap; } +.fjoin { flex-basis: 100%; display: flex; flex-direction: column; gap: 8px; } + +/* --- profile form extras, the topics tab --- */ +.fprof-upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px; } +.fprof-upload-btn { cursor: pointer; } +.fprof-check-plain { border: 0; padding: 6px 0 0; background: none; } +.fmodlog li.ftop-member { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; } +.ftop-vis { width: auto; min-height: 36px; } + +/* --- members-only and restricted topics: said plainly, also to members --- */ +.ftopic-private { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; color: var(--ink-2); } +.ftopic-private svg, .ftv-private svg { width: 15px; height: 15px; flex: none; margin-top: 2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; } +.ftv-private { display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; font-size: 13px; color: var(--muted); } +.ftv-private svg { margin-top: 0; width: 13px; height: 13px; } diff --git a/services/frontend/src/app/forum/layout.tsx b/services/frontend/src/app/forum/layout.tsx index 6e0aead..8cf3d97 100644 --- a/services/frontend/src/app/forum/layout.tsx +++ b/services/frontend/src/app/forum/layout.tsx @@ -45,6 +45,7 @@ export default async function ForumLayout({ children }: { children: React.ReactN unread: nav.ok ? (nav.data.followed?.new_replies ?? 0) : 0, messages: nav.ok ? (nav.data.messages ?? 0) : 0, reports: nav.ok ? (nav.data.reports ?? 0) : 0, + waiting: nav.ok ? (nav.data.waiting ?? 0) : 0, }} wsUrl={process.env.FORUM_WS_URL || "/api/v1/forum/ws"} /> diff --git a/services/frontend/src/app/forum/moderalas/TopicsAdmin.tsx b/services/frontend/src/app/forum/moderalas/TopicsAdmin.tsx new file mode 100644 index 0000000..687167e --- /dev/null +++ b/services/frontend/src/app/forum/moderalas/TopicsAdmin.tsx @@ -0,0 +1,238 @@ +"use client"; + +import { useRouter } from "next/navigation"; +import { useState } from "react"; + +import { Avatar } from "@/components/forum/Avatar"; +import { RankBadge } from "@/components/forum/Badges"; +import { api, errorText } from "@/lib/api"; +import { type ForumTopic, type TopicRequest, ago } from "@/lib/forum"; + +const VISIBILITY: Record = { + public: "Nyilvános (a keresők is látják)", + members: "Csak tagoknak", + restricted: "Zárt (jóváhagyással)", +}; + +/** Moderators: requests to join restricted topics. Admins also: opening and editing topics. */ +export function TopicsAdmin({ + requests, + topics, + admin, +}: { + requests: TopicRequest[]; + topics: ForumTopic[]; + admin: boolean; +}) { + const router = useRouter(); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(null); + const [form, setForm] = useState({ name: "", description: "", visibility: "restricted", listening: false }); + + async function act(work: () => Promise) { + setBusy(true); + setError(null); + try { + await work(); + router.refresh(); + } catch (e) { + setError(errorText(e)); + } finally { + setBusy(false); + } + } + + const decide = (r: TopicRequest, action: "approve" | "reject" | "remove") => + act(() => + api("/forum/mod/topic-requests", { + body: { topic: r.topic.slug, nickname: r.member?.nickname ?? "", action }, + }), + ); + + const pending = requests.filter((r) => r.status === "pending"); + const approved = requests.filter((r) => r.status === "approved"); + + return ( + <> + {error && ( +

    + {error} +

    + )} +
    +

    + Jelentkezések zárt témákba ({pending.length}) +

    + {pending.length === 0 ? ( +

    Nincs várakozó jelentkezés.

    + ) : ( + pending.map((r) => ( +
    +
    + + + {r.member?.nickname ?? "?"} + {r.member && } + + + {r.topic.name} ·{" "} + + +
    + {r.note &&

    „{r.note}”

    } +
    + + +
    +
    + )) + )} +
    + + {approved.length > 0 && ( +
    +

    + Zárt témák tagjai +

    +
      + {approved.map((r) => ( +
    • + + + {r.member?.nickname ?? "?"} + · {r.topic.name} + + +
    • + ))} +
    +
    + )} + + {admin && ( +
    +

    + Témák (admin) +

    +
      + {topics.map((t) => ( +
    • + + {t.name} · {VISIBILITY[t.visibility] ?? t.visibility} + + +
    • + ))} +
    +
    { + e.preventDefault(); + void act(async () => { + await api("/forum/topics", { body: form }); + setForm({ name: "", description: "", visibility: "restricted", listening: false }); + }); + }} + > + Új téma +
    + + setForm({ ...form, name: e.target.value })} + required + /> +
    +
    + + setForm({ ...form, description: e.target.value })} + required + /> +
    +
    + + +
    + + +
    +
    + )} + + ); +} diff --git a/services/frontend/src/app/forum/moderalas/page.tsx b/services/frontend/src/app/forum/moderalas/page.tsx index dc3770b..560a3ce 100644 --- a/services/frontend/src/app/forum/moderalas/page.tsx +++ b/services/frontend/src/app/forum/moderalas/page.tsx @@ -1,10 +1,20 @@ import Link from "next/link"; import { notFound } from "next/navigation"; -import { type ModLogEntry, type ReportEntry, banText, memberHref, threadHref } from "@/lib/forum"; +import { + type ForumTopic, + type ModLogEntry, + type ReportEntry, + type TopicRequest, + banText, + memberHref, + threadHref, +} from "@/lib/forum"; import { forumGet } from "@/lib/forumServer"; +import { getMe } from "@/lib/server"; import { ReportsList } from "./ReportsList"; +import { TopicsAdmin } from "./TopicsAdmin"; export const metadata = { title: "Moderálás", robots: { index: false } }; @@ -21,25 +31,35 @@ const ACTIONS: Record = { unpin: "levette a kitűzést", resolve_report: "lezárt egy jelentést", dismiss_report: "alaptalannak ítélt egy jelentést", + approve_member: "felvette egy zárt témába", + reject_member: "elutasította a jelentkezését", + remove_member: "eltávolította egy zárt témából", + reset_avatar: "eltávolította a saját képét", + topic: "témát kezelt", }; type Props = { searchParams: Promise<{ nezet?: string }> }; /** Moderators: the open reports, and the log of every moderation step. */ export default async function ModerationPage({ searchParams }: Props) { - const log = (await searchParams).nezet === "naplo"; + const view = (await searchParams).nezet; + const log = view === "naplo"; + const topics = view === "temak"; return (

    Moderálás

    - {log ? : } + {log ? : topics ? : }
    ); } @@ -50,6 +70,22 @@ async function ReportsView() { return ; } +async function TopicsView() { + const [requests, list, me] = await Promise.all([ + forumGet<{ requests: TopicRequest[] }>("/v1/forum/mod/topic-requests"), + forumGet<{ topics: ForumTopic[] }>("/v1/forum/topics"), + getMe(), + ]); + if (!requests.ok) notFound(); + return ( + + ); +} + async function LogView() { const res = await forumGet<{ entries: ModLogEntry[] }>("/v1/forum/mod/log"); if (!res.ok) notFound(); diff --git a/services/frontend/src/app/forum/page.tsx b/services/frontend/src/app/forum/page.tsx index 856a3a0..5b1b417 100644 --- a/services/frontend/src/app/forum/page.tsx +++ b/services/frontend/src/app/forum/page.tsx @@ -2,6 +2,8 @@ import Link from "next/link"; import { notFound } from "next/navigation"; import { Avatar } from "@/components/forum/Avatar"; +import { RankBadge } from "@/components/forum/Badges"; +import { JoinTopic } from "@/components/forum/JoinTopic"; import { ThreadList, WaitingCard } from "@/components/forum/ThreadList"; import { MoonPhaseIcon } from "@/components/MoonChip"; import { MOON_PHASES, SIGNS } from "@/lib/astro"; @@ -161,47 +163,72 @@ export default async function ForumHomePage() {

    Témák

      - {topics.map((t) => ( -
    • - - - - - - - {t.name} - {t.visibility !== "public" && ( - + {topics.map((t) => + t.visibility === "restricted" && !t.readable ? ( +
    • +
      + + + + + + {t.name} + - )} + + {t.description} + Zárt kör: jóváhagyás után olvasható - {t.description} - {t.readable && t.last && ( - - {t.last.author && ( - + {viewer.member && } +
      +
    • + ) : ( +
    • + + + + + + + {t.name} + {t.visibility !== "public" && ( + + + + )} - {t.last.author?.nickname ?? "Törölt tag"},{" "} - + + {t.description} + {t.readable && t.last && ( + + {t.last.author && ( + + )} + {t.last.author?.nickname ?? "Törölt tag"},{" "} + + + )} + {!t.readable && Belépés után olvasható} + + {t.readable && ( + + {t.thread_count ?? 0} szál )} - {!t.readable && Belépés után olvasható} - - {t.readable && ( - - {t.thread_count ?? 0} szál - - )} - {t.readable && t.new_count ? ( - {t.new_count > 99 ? "99+" : t.new_count} új - ) : null} - -
    • - ))} + {t.readable && t.new_count ? ( + {t.new_count > 99 ? "99+" : t.new_count} új + ) : null} + + + ), + )}
    @@ -212,6 +239,23 @@ export default async function ForumHomePage() { )} + {home.data.online.length > 0 && ( +
    +

    + Most itt vannak ({home.data.online.length}) +

    +
      + {home.data.online.map((m) => ( +
    • + + + {m.nickname} + +
    • + ))} +
    +
    + )} {viewer.member && (
    @@ -220,7 +264,7 @@ export default async function ForumHomePage() { {viewer.member.nickname} - {viewer.member.rank_name} +
    diff --git a/services/frontend/src/app/forum/tag/[nev]/BanPanel.tsx b/services/frontend/src/app/forum/tag/[nev]/BanPanel.tsx index a3845cb..bed013e 100644 --- a/services/frontend/src/app/forum/tag/[nev]/BanPanel.tsx +++ b/services/frontend/src/app/forum/tag/[nev]/BanPanel.tsx @@ -15,7 +15,7 @@ const DURATIONS: { hours: number | null; label: string }[] = [ ]; /** Moderators: ban a member for a while or for good (they may still read), or lift it. */ -export function BanPanel({ nickname, banned }: { nickname: string; banned: boolean }) { +export function BanPanel({ nickname, banned, ownPicture }: { nickname: string; banned: boolean; ownPicture: boolean }) { const router = useRouter(); const [hours, setHours] = useState("24"); const [reason, setReason] = useState(""); @@ -40,6 +40,19 @@ export function BanPanel({ nickname, banned }: { nickname: string; banned: boole
    Moderálás
    + {ownPicture && ( + + )} {banned && (
    @@ -68,7 +71,11 @@ export default async function MemberPage({ params }: Props) { )} {viewer.moderator && !member.own && !a.moderator && ( - + )}
    diff --git a/services/frontend/src/app/forum/uzenetek/[id]/Chat.tsx b/services/frontend/src/app/forum/uzenetek/[id]/Chat.tsx index 3d75cc9..fc4a5ea 100644 --- a/services/frontend/src/app/forum/uzenetek/[id]/Chat.tsx +++ b/services/frontend/src/app/forum/uzenetek/[id]/Chat.tsx @@ -5,6 +5,7 @@ import { useRouter } from "next/navigation"; import { useCallback, useEffect, useRef, useState } from "react"; import { Avatar } from "@/components/forum/Avatar"; +import { RankBadge } from "@/components/forum/Badges"; import { Composer } from "@/components/forum/Composer"; import { PostBody } from "@/components/forum/PostBody"; import type { LiveNotice } from "@/components/forum/ForumNav"; @@ -130,7 +131,7 @@ export function Chat({ initial }: { initial: ConversationPage }) { ) : ( {other} )} - {c.other && {c.other.rank_name}} + {c.other && } {c.state === "accepted" && (
    diff --git a/services/frontend/src/app/privacy/page.tsx b/services/frontend/src/app/privacy/page.tsx index 67ddfcc..fa2698a 100644 --- a/services/frontend/src/app/privacy/page.tsx +++ b/services/frontend/src/app/privacy/page.tsx @@ -85,15 +85,20 @@ 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), avatar, introduction, the signs of your chart you share, the invisible mode and your e-mail notification settings", - "Taking part in the forum; sharing the signs is your choice", + "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 listener, 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", + "Taking part in the forum; sharing the signs and the badges is your choice", "Performance of the contract", ], [ - "Your forum threads and posts, your reactions and “Ez segített” (it helped) marks, your points and rank; what you have read, and the threads you follow", + "Your forum threads and posts, your reactions and “Ez segített” (it helped) marks, your points and rank; whom you mentioned (@nickname); what you have read, and the threads you follow", "Running the forum, the ranks, showing what is new", "Performance of the contract", ], + [ + "Your requests to join restricted topics (with the few words you add) and your memberships", + "Restricted topics: the moderators decide who joins", + "Performance of the contract", + ], [ "When you were last on the forum", "The online indicator (green dot); you can turn it off with the invisible mode", @@ -184,8 +189,9 @@ export default async function PrivacyPolicyPage() {

    Forum: what you write in the public topics can be seen by anyone, including search engines; - the members-only topics are seen only by logged-in users. Next to your posts we show your nickname, avatar, - rank and the signs you chose to share; never your real name, e-mail address or birth data, and never the + the members-only topics are seen only by logged-in users, and the restricted ones only by their approved + members. Next to your posts we show your nickname, avatar, rank, the signs you chose to share and the badges + you switched on (Meghallgató – listener, Támogató – supporter); never your real name, e-mail address or birth data, and never the degrees of your chart. Your private messages are seen only by the two people in the conversation; moderators see a message only when someone reports it, and then only that message and the few before it. Moderators (members appointed by the operator) do not see your real name or e-mail address. The forum rules are in @@ -208,7 +214,8 @@ export default async function PrivacyPolicyPage() {

    How we use it: to create your account and recognise you when you sign in; your e-mail address for service e-mails (for example when a reading is ready, an invitation was accepted, or someone replied on the - forum, if you asked for it); your name for display; + forum, when someone mentions you there, or the forum's weekly summary, if you asked for these); your name for + display; your language for the language of the site and your readings.

    @@ -326,7 +333,8 @@ export default async function PrivacyPolicyPage() {

  • Data needed for invoicing: for the period required by accounting law (8 years).
  • - Your forum profile, private conversations, reactions and followed threads: until you delete your account. + Your forum profile (with your own picture), private conversations, reactions, followed threads and + restricted topic memberships: until you delete your account; a declined request is deleted at once. When you delete it, your private conversations are deleted for the other person too. Your threads and posts stay, shown as “Törölt tag” (deleted member), so that the conversations remain readable; to have them deleted as well, write to the e-mail address above. diff --git a/services/frontend/src/components/forum/AuthorLine.tsx b/services/frontend/src/components/forum/AuthorLine.tsx index 25319a5..8a4d7d2 100644 --- a/services/frontend/src/components/forum/AuthorLine.tsx +++ b/services/frontend/src/components/forum/AuthorLine.tsx @@ -4,6 +4,7 @@ import { POINTS, SIGNS } from "@/lib/astro"; import { type ForumAuthor, ago, memberHref } from "@/lib/forum"; import { Avatar } from "./Avatar"; +import { Badge, RankBadge } from "./Badges"; /** "☉ Halak · ☽ Rák · Asz Szűz": the signs a member chose to share. */ export function signsText(signs: Record | null | undefined): string | null { @@ -100,8 +101,10 @@ export function AuthorLine({ {author.nickname} {author.online && (online)} - {author.rank_name} - {author.moderator && Moderátor} + + {author.moderator && } + {author.listener && } + {author.supporter && } {badges} {(shown || time) && ( diff --git a/services/frontend/src/components/forum/Avatar.tsx b/services/frontend/src/components/forum/Avatar.tsx index ffb5fb4..93ca444 100644 --- a/services/frontend/src/components/forum/Avatar.tsx +++ b/services/frontend/src/components/forum/Avatar.tsx @@ -3,6 +3,8 @@ // a pale tint in the light one (forum.css: .av-). With `online`, the // green dot. +import { uploadedAvatar } from "@/lib/forum"; + export const AVATAR_GLYPHS = ["hold", "csillag", "nap", "hullam", "level", "lotusz", "kristaly", "toll"] as const; export const AVATAR_COLOURS = ["ejkek", "lila", "tenger", "borostyan", "rozsa", "erdo"] as const; @@ -78,6 +80,16 @@ export function Avatar({ size?: number; online?: boolean; }) { + const picture = uploadedAvatar(avatar); + if (picture) { + return ( + + {/* A member's own picture, served by the forum (already small and square). */} + + {online && } + + ); + } const [glyph, colour] = (avatar ?? "hold-ejkek").split("-"); const known = (AVATAR_COLOURS as readonly string[]).includes(colour) ? colour : "ejkek"; return ( diff --git a/services/frontend/src/components/forum/Badges.tsx b/services/frontend/src/components/forum/Badges.tsx new file mode 100644 index 0000000..1dab27f --- /dev/null +++ b/services/frontend/src/components/forum/Badges.tsx @@ -0,0 +1,128 @@ +// The small labels next to a nickname, each with its own line icon: the rank +// (from Vándor to Sorsfonó, a thread being spun), and the badges. + +import type { Rank } from "@/lib/forum"; + +const RANK_ICONS: Record = { + // Vándor: on the way (a path from a starting point). + vandor: ( + <> + + + + ), + // Kereső: a compass. + kereso: ( + <> + + + + ), + // Fonó: a spool with thread. + fono: ( + <> + + + + + ), + // Csillagfonó: a star with a thread from it. + csillagfono: ( + <> + + + + ), + // Sorsfonó: the thread of fate around the circle (the site's mark). + sorsfono: ( + <> + + + + + ), +}; + +export type BadgeKind = "mod" | "listener" | "supporter" | "starter" | "sky"; + +const BADGES: Record = { + // A shield with a tick. + mod: { + label: "Moderátor", + title: "A fórum moderátora", + icon: ( + <> + + + + ), + }, + // An ear. + listener: { + label: "Meghallgató", + title: "Önkéntes meghallgató: szívesen meghallgat", + icon: ( + <> + + + + ), + }, + // A gem. + supporter: { + label: "Támogató", + title: "Vásárlásával támogatja a Sorsfonalakat", + icon: ( + <> + + + + ), + }, + // A quill. + starter: { + label: "Szálindító", + title: "Ő indította a szálat", + icon: ( + <> + + + + ), + }, + // A crescent Moon. + sky: { + label: "napi égbolt", + title: "A Sorsfonalak napi szála az égboltról", + icon: , + }, +}; + +function Icon({ children }: { children: React.ReactNode }) { + return ( + + ); +} + +/** The member's rank, with its icon. */ +export function RankBadge({ rank, name }: { rank: Rank; name: string }) { + return ( + + {RANK_ICONS[rank] ?? RANK_ICONS.vandor} + {name} + + ); +} + +/** A badge (Moderátor, Meghallgató, Támogató, Szálindító, napi égbolt), with its icon. */ +export function Badge({ kind }: { kind: BadgeKind }) { + const b = BADGES[kind]; + return ( + + {b.icon} + {b.label} + + ); +} diff --git a/services/frontend/src/components/forum/Composer.tsx b/services/frontend/src/components/forum/Composer.tsx index 184f183..edd6e19 100644 --- a/services/frontend/src/components/forum/Composer.tsx +++ b/services/frontend/src/components/forum/Composer.tsx @@ -1,13 +1,26 @@ "use client"; -import { useState } from "react"; +import { useEffect, useRef, useState } from "react"; +import { api } from "@/lib/api"; import { convertEmoticons, withEmoji } from "@/lib/emoticons"; +import type { ForumAuthor } from "@/lib/forum"; + +import { Avatar } from "./Avatar"; + +/** "@Ho" right before the caret: what was typed after the "@", and where it starts. */ +function mentionAt(text: string, caret: number): { query: string; start: number } | null { + const before = text.slice(0, caret); + const match = /(?:^|\s)@([^\s@]{1,24})$/.exec(before); + if (!match) return null; + return { query: match[1], start: caret - match[1].length - 1 }; +} /** * The text box and the send button. Character smileys (`:)`, `<3`) turn into * emoji as they are typed; phones bring their own emoji keyboard. * `onTyping`: called on every keystroke (the "… gépel" notice). + * `mentions`: typing "@Ho" offers the members whose nickname starts so. */ export function Composer({ id, @@ -19,6 +32,7 @@ export function Composer({ onSubmit, onCancel, onTyping, + mentions = false, rows = 3, autoFocus = false, }: { @@ -31,16 +45,54 @@ export function Composer({ onSubmit: (text: string) => Promise; onCancel?: () => void; onTyping?: () => void; + mentions?: boolean; rows?: number; autoFocus?: boolean; }) { const [text, setText] = useState(initial); + const [suggest, setSuggest] = useState<{ query: string; start: number; members: ForumAuthor[] } | null>(null); + const area = useRef(null); + const timer = useRef(undefined); + + useEffect(() => () => window.clearTimeout(timer.current), []); + + function lookUp(value: string, caret: number) { + window.clearTimeout(timer.current); + const at = mentions ? mentionAt(value, caret) : null; + if (!at) { + setSuggest(null); + return; + } + timer.current = window.setTimeout(() => { + api<{ members: ForumAuthor[] }>(`/forum/members/search?q=${encodeURIComponent(at.query)}`) + .then((res) => setSuggest(res.members.length ? { ...at, members: res.members } : null)) + .catch(() => setSuggest(null)); + }, 200); + } + + function pick(nickname: string) { + if (!suggest) return; + const el = area.current; + const caret = el?.selectionStart ?? text.length; + const inserted = `@${nickname} `; + const next = text.slice(0, suggest.start) + inserted + text.slice(caret); + setText(next); + setSuggest(null); + requestAnimationFrame(() => { + el?.focus(); + const at = suggest.start + inserted.length; + el?.setSelectionRange(at, at); + }); + } async function submit(e: React.FormEvent) { e.preventDefault(); if (!text.trim() || busy) return; const final = convertEmoticons(text, text.length, true).text; - if (await onSubmit(final)) setText(""); + if (await onSubmit(final)) { + setText(""); + setSuggest(null); + } } return ( @@ -50,17 +102,40 @@ export function Composer({