Forum: whom a reply answers, icon badges, the new features on the pages

- 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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 13:02:38 +00:00
co-authored by Claude Opus 5.5
parent 564c22176f
commit 8bc426460d
28 changed files with 1112 additions and 100 deletions
+12 -1
View File
@@ -180,7 +180,8 @@ pub async fn export(State(state): St, auth: AuthUser) -> ApiResult<impl IntoResp
"credit_ledger": rows("SELECT json_build_object('unit', unit, 'delta', delta, 'reason', reason, 'note', note, 'created_at', created_at) FROM credit_ledger WHERE user_id = $1 ORDER BY created_at").await?,
"shares": rows("SELECT json_build_object('slug', slug, 'kind', kind, 'title', title, 'show_birth_data', show_birth_data, 'view_count', view_count, 'created_at', created_at, 'revoked_at', revoked_at) FROM shares WHERE owner_id = $1").await?,
// The forum (services/forum): what the user wrote and set there.
"forum_profile": rows("SELECT json_build_object('nickname', nickname, 'avatar', avatar, 'bio', bio, 'chart_share', chart_share, 'invisible', invisible, 'points', points, 'post_count', post_count, 'created_at', created_at, 'email_replies', email_replies, 'email_followed', email_followed, 'email_messages', email_messages, 'banned_until', banned_until, 'ban_reason', ban_reason) FROM forum.members WHERE user_id = $1").await?,
"forum_profile": rows("SELECT json_build_object('nickname', nickname, 'avatar', avatar, 'bio', bio, 'chart_share', chart_share, 'invisible', invisible, 'points', points, 'post_count', post_count, 'created_at', created_at, 'email_replies', email_replies, 'email_followed', email_followed, 'email_messages', email_messages, 'email_mentions', email_mentions, 'email_listener', email_listener, 'email_weekly', email_weekly, 'listener', listener, 'supporter_badge', supporter_badge, 'banned_until', banned_until, 'ban_reason', ban_reason) FROM forum.members WHERE user_id = $1").await?,
"forum_topic_memberships": rows("SELECT json_build_object('topic', tp.name, 'status', tm.status, 'note', tm.note, 'requested_at', tm.requested_at) FROM forum.topic_members tm JOIN forum.topics tp ON tp.id = tm.topic_id WHERE tm.user_id = $1").await?,
"forum_posts": rows("SELECT json_build_object('id', p.id, 'thread_id', p.thread_id, 'thread_title', th.title, 'opening', p.is_opening, 'body', p.body, 'created_at', p.created_at, 'edited_at', p.edited_at, 'removed_at', p.deleted_at, 'removal_reason', p.delete_reason) FROM forum.posts p JOIN forum.threads th ON th.id = p.thread_id WHERE p.author_id = $1 ORDER BY p.id").await?,
"forum_reactions": rows("SELECT json_build_object('post_id', post_id, 'kind', kind, 'created_at', created_at) FROM forum.reactions WHERE user_id = $1 ORDER BY created_at").await?,
"forum_followed_threads": rows("SELECT json_build_object('thread_id', thread_id, 'since', created_at) FROM forum.follows WHERE user_id = $1").await?,
@@ -257,8 +258,18 @@ pub async fn delete_me(
.bind(auth.id())
.execute(&mut *tx)
.await?;
// The forum's own avatar picture (in the object storage) goes too.
let avatar: Option<String> = 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))))
}
+24 -2
View File
@@ -92,10 +92,12 @@ pub struct PostRow {
pub delete_reason: Option<String>,
/// 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<i64>,
}
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<i64> = posts.iter().filter_map(|p| p.reply_to_id).collect();
let answered: HashMap<i64, Option<String>> = sqlx::query_as::<_, (i64, Option<String>)>(
"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?;
+3 -1
View File
@@ -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;
+17 -8
View File
@@ -149,21 +149,28 @@ export default async function PrivacyPage() {
</tr>
<tr>
<td>
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
</td>
<td>Részvétel a fórumon; a jegyek megosztása a saját döntésed</td>
<td>Részvétel a fórumon; a jegyek megosztása és a jelvények a saját döntésed</td>
<td>Szerződés teljesítése</td>
</tr>
<tr>
<td>
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
</td>
<td>A fórum működése, a rangok, az újdonságok jelzése</td>
<td>Szerződés teljesítése</td>
</tr>
<tr>
<td>Zárt témákba küldött jelentkezéseid (a pár szavas indoklással) és a tagságaid</td>
<td>A zárt témák: a moderátorok döntenek a felvételről</td>
<td>Szerződés teljesítése</td>
</tr>
<tr>
<td>Mikor jártál utoljára a fórumon</td>
<td>Az online jelzés (zöld pötty); a láthatatlan móddal kikapcsolhatod</td>
@@ -212,8 +219,9 @@ export default async function PrivacyPage() {
</p>
<p>
<strong>Fórum:</strong> 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() {
<p>
<strong>Mire használjuk:</strong> 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.
</p>
<p>
@@ -354,7 +362,8 @@ export default async function PrivacyPage() {
</li>
<li>A számlázáshoz szükséges adatokat a számviteli törvény szerinti ideig (8 évig) őrizzük.</li>
<li>
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.
+4 -1
View File
@@ -148,11 +148,14 @@ export default async function TermsPage() {
<h3>8.1. Olvasás, írás, álnév</h3>
<p>
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.
</p>
<h3>8.2. Házirend</h3>
@@ -49,9 +49,15 @@ export default async function TopicPageView({ params, searchParams }: Props) {
<div>
<h1>{topic.name}</h1>
<p className="muted">{topic.description}</p>
{topic.listening && (
<p className="hint">
Meghallgatós téma: itt nincs ⌄, és a szálak alapból meghallgatást kérnek, nem tanácsot.
{topic.visibility !== "public" && (
<p className="ftopic-private">
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</svg>
{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."}
</p>
)}
</div>
@@ -26,8 +26,19 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
const [share, setShare] = useState<ChartShare>(member?.chart_share ?? "none");
const [invisible, setInvisible] = useState(member?.invisible ?? false);
const [email, setEmail] = useState<EmailSettings>(
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<string | null>(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<ForumMe>("/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 })
)}
</div>
{!avatar && <span className="hint">Ha nem választasz, az álneved alapján kapsz egyet.</span>}
{member?.can_upload_avatar && (
<div className="fprof-upload">
{uploaded && <Avatar avatar={avatar} size={56} />}
<label className="btn btn-sm fprof-upload-btn">
{uploading ? "Feltöltés…" : uploaded ? "Másik kép" : "Saját kép feltöltése"}
<input
type="file"
accept="image/jpeg,image/png,image/webp"
className="sr-only"
disabled={uploading}
onChange={async (e) => {
const file = e.target.files?.[0];
e.target.value = "";
if (!file) return;
setUploading(true);
setError(null);
try {
const res = await fetch("/api/v1/forum/me/avatar", {
method: "PUT",
body: file,
headers: { "content-type": file.type || "application/octet-stream" },
credentials: "same-origin",
});
const data = await res.json().catch(() => null);
if (!res.ok) throw new Error(data?.error?.message ?? "A feltöltés nem sikerült.");
setAvatar(data.avatar);
router.refresh();
} catch (err) {
setError(err instanceof Error ? err.message : errorText(err));
} finally {
setUploading(false);
}
}}
/>
</label>
<span className="hint">
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.
</span>
</div>
)}
</fieldset>
<div className="field">
@@ -183,6 +244,31 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
</span>
</label>
{member?.can_listen && (
<label className="fprof-check">
<input type="checkbox" checked={listener} onChange={(e) => setListener(e.target.checked)} />
<span>
<strong>Önkéntes meghallgató vagyok</strong>
<span className="hint">
A nevem mellett megjelenik a „Meghallgató” jelvény, és a menü jelzi, ha egy meghallgatást kérő szál válasz
nélkül vár. E-mailt is kérhetsz róla lent.
</span>
</span>
</label>
)}
{me.can_supporter && (
<label className="fprof-check">
<input type="checkbox" checked={supporter} onChange={(e) => setSupporter(e.target.checked)} />
<span>
<strong>Támogató jelvény</strong>
<span className="hint">
Vásároltál csomagot: ha szeretnéd, a neved mellett megjelenik a „Támogató” jelvény. Rangot nem ad.
</span>
</span>
</label>
)}
<fieldset className="fnew-set">
<legend>Értesítések e-mailben</legend>
<div className="fprof-mail">
@@ -217,7 +303,42 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
<option value="instant">Azonnal</option>
<option value="off">Ne küldjetek</option>
</select>
<label htmlFor="fprof-mail-mentions">Ha valaki megemlít (@{nickname || "álnév"})</label>
<select
id="fprof-mail-mentions"
className="inp"
value={email.mentions}
onChange={(e) => setEmail({ ...email, mentions: e.target.value as EmailSettings["mentions"] })}
>
<option value="instant">Azonnal</option>
<option value="off">Ne küldjetek</option>
</select>
{listener && (
<>
<label htmlFor="fprof-mail-listener">Meghallgatóként: ha egy szál két órája válasz nélkül vár</label>
<select
id="fprof-mail-listener"
className="inp"
value={email.listener}
onChange={(e) => setEmail({ ...email, listener: e.target.value as EmailSettings["listener"] })}
>
<option value="off">Ne küldjetek</option>
<option value="instant">Azonnal (hat óránként legfeljebb egy levél)</option>
</select>
</>
)}
</div>
<label className="fprof-check fprof-check-plain">
<input
type="checkbox"
checked={email.weekly}
onChange={(e) => setEmail({ ...email, weekly: e.target.checked })}
/>
<span>
<strong>Heti összefoglaló</strong>
<span className="hint">Vasárnap este: a hét legélénkebb szálai, és ami még válaszra vár.</span>
</span>
</label>
<span className="hint">
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.
+63 -1
View File
@@ -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; }
@@ -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"}
/>
@@ -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<string, string> = {
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<string | null>(null);
const [form, setForm] = useState({ name: "", description: "", visibility: "restricted", listening: false });
async function act(work: () => Promise<unknown>) {
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 && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
<section className="fh-section" aria-labelledby="ftop-pending">
<h2 id="ftop-pending" className="fmsg-h">
Jelentkezések zárt témákba ({pending.length})
</h2>
{pending.length === 0 ? (
<p className="fh-card fh-empty">Nincs várakozó jelentkezés.</p>
) : (
pending.map((r) => (
<article key={`${r.topic.slug}-${r.member?.nickname}`} className="fh-card fmod-report">
<div className="fmod-report-head">
<span className="fh-online-item">
<Avatar avatar={r.member?.avatar} size={28} />
<strong>{r.member?.nickname ?? "?"}</strong>
{r.member && <RankBadge rank={r.member.rank} name={r.member.rank_name} />}
</span>
<span className="hint">
{r.topic.name} ·{" "}
<time suppressHydrationWarning dateTime={r.requested_at}>
{ago(r.requested_at)}
</time>
</span>
</div>
{r.note && <p className="fmod-note">„{r.note}”</p>}
<div className="fmsg-actions">
<button
type="button"
className="btn btn-sm btn-primary"
disabled={busy}
onClick={() => decide(r, "approve")}
>
Jóváhagyom
</button>
<button
type="button"
className="btn btn-sm btn-ghost"
disabled={busy}
onClick={() => decide(r, "reject")}
>
Elutasítom
</button>
</div>
</article>
))
)}
</section>
{approved.length > 0 && (
<section className="fh-section" aria-labelledby="ftop-members">
<h2 id="ftop-members" className="fmsg-h">
Zárt témák tagjai
</h2>
<ul className="fh-card fh-flush fmodlog">
{approved.map((r) => (
<li key={`${r.topic.slug}-${r.member?.nickname}`} className="ftop-member">
<span className="fh-online-item">
<Avatar avatar={r.member?.avatar} size={24} />
{r.member?.nickname ?? "?"}
<span className="hint">· {r.topic.name}</span>
</span>
<button
type="button"
className="btn btn-sm btn-ghost"
disabled={busy}
onClick={() =>
window.confirm(`Eltávolítod ${r.member?.nickname} tagot a(z) „${r.topic.name}” témából?`) &&
decide(r, "remove")
}
>
Eltávolítom
</button>
</li>
))}
</ul>
</section>
)}
{admin && (
<section className="fh-section" aria-labelledby="ftop-admin">
<h2 id="ftop-admin" className="fmsg-h">
Témák (admin)
</h2>
<ul className="fh-card fh-flush fmodlog">
{topics.map((t) => (
<li key={t.slug} className="ftop-member">
<span>
<strong>{t.name}</strong> <span className="hint">· {VISIBILITY[t.visibility] ?? t.visibility}</span>
</span>
<select
className="inp ftop-vis"
aria-label={`${t.name} láthatósága`}
value={t.visibility}
disabled={busy}
onChange={(e) =>
act(() => api(`/forum/topics/${t.slug}`, { method: "PATCH", body: { visibility: e.target.value } }))
}
>
{Object.entries(VISIBILITY).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</li>
))}
</ul>
<form
className="fh-card fnew"
onSubmit={(e) => {
e.preventDefault();
void act(async () => {
await api("/forum/topics", { body: form });
setForm({ name: "", description: "", visibility: "restricted", listening: false });
});
}}
>
<strong>Új téma</strong>
<div className="field">
<label htmlFor="ftop-name">Név</label>
<input
id="ftop-name"
className="inp"
value={form.name}
maxLength={60}
onChange={(e) => setForm({ ...form, name: e.target.value })}
required
/>
</div>
<div className="field">
<label htmlFor="ftop-desc">Rövid leírás</label>
<input
id="ftop-desc"
className="inp"
value={form.description}
maxLength={160}
onChange={(e) => setForm({ ...form, description: e.target.value })}
required
/>
</div>
<div className="field">
<label htmlFor="ftop-visibility">Láthatóság</label>
<select
id="ftop-visibility"
className="inp"
value={form.visibility}
onChange={(e) => setForm({ ...form, visibility: e.target.value })}
>
{Object.entries(VISIBILITY).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</div>
<label className="fprof-check">
<input
type="checkbox"
checked={form.listening}
onChange={(e) => setForm({ ...form, listening: e.target.checked })}
/>
<span>
<strong>Meghallgatós téma</strong>
<span className="hint">Az új szálak alapból meghallgatást kérnek, nem tanácsot.</span>
</span>
</label>
<button
type="submit"
className="btn btn-primary"
disabled={busy || !form.name.trim() || !form.description.trim()}
>
Téma létrehozása
</button>
</form>
</section>
)}
</>
);
}
@@ -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<string, string> = {
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 (
<div className="fh">
<h1 className="fpage-title">Moderálás</h1>
<nav className="fmod-tabs" aria-label="Moderálás">
<Link href="/forum/moderalas" aria-current={log ? undefined : "page"}>
<Link href="/forum/moderalas" aria-current={log || topics ? undefined : "page"}>
Jelentések
</Link>
<Link href="/forum/moderalas?nezet=temak" aria-current={topics ? "page" : undefined}>
Témák
</Link>
<Link href="/forum/moderalas?nezet=naplo" aria-current={log ? "page" : undefined}>
Napló
</Link>
</nav>
{log ? <LogView /> : <ReportsView />}
{log ? <LogView /> : topics ? <TopicsView /> : <ReportsView />}
</div>
);
}
@@ -50,6 +70,22 @@ async function ReportsView() {
return <ReportsList initial={res.data.reports} />;
}
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 (
<TopicsAdmin
requests={requests.data.requests}
topics={list.ok ? list.data.topics : []}
admin={me?.user.roles.includes("admin") ?? false}
/>
);
}
async function LogView() {
const res = await forumGet<{ entries: ModLogEntry[] }>("/v1/forum/mod/log");
if (!res.ok) notFound();
+79 -35
View File
@@ -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() {
<h2 id="fh-topics">Témák</h2>
</div>
<ul className="fh-card fh-flush fh-topics">
{topics.map((t) => (
<li key={t.slug}>
<Link href={t.readable ? `/forum/${t.slug}` : `/belepes?vissza=/forum/${t.slug}`} className="fh-topic">
<span className="fh-topic-icon">
<TopicIcon slug={t.slug} />
</span>
<span className="fh-topic-text">
<span className="fh-topic-name">
{t.name}
{t.visibility !== "public" && (
<svg viewBox="0 0 24 24" className="fh-lock" role="img" aria-label="Csak tagoknak">
{topics.map((t) =>
t.visibility === "restricted" && !t.readable ? (
<li key={t.slug}>
<div className="fh-topic fh-topic-closed">
<span className="fh-topic-icon">
<TopicIcon slug={t.slug} />
</span>
<span className="fh-topic-text">
<span className="fh-topic-name">
{t.name}
<svg viewBox="0 0 24 24" className="fh-lock" role="img" aria-label="Zárt téma">
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</svg>
)}
</span>
<span className="fh-topic-desc">{t.description}</span>
<span className="fh-topic-last">Zárt kör: jóváhagyás után olvasható</span>
</span>
<span className="fh-topic-desc">{t.description}</span>
{t.readable && t.last && (
<span className="fh-topic-last">
{t.last.author && (
<Avatar avatar={t.last.author.avatar} size={18} online={t.last.author.online} />
{viewer.member && <JoinTopic slug={t.slug} pending={t.membership === "pending"} />}
</div>
</li>
) : (
<li key={t.slug}>
<Link
href={t.readable ? `/forum/${t.slug}` : `/belepes?vissza=/forum/${t.slug}`}
className="fh-topic"
>
<span className="fh-topic-icon">
<TopicIcon slug={t.slug} />
</span>
<span className="fh-topic-text">
<span className="fh-topic-name">
{t.name}
{t.visibility !== "public" && (
<svg viewBox="0 0 24 24" className="fh-lock" role="img" aria-label="Csak tagoknak">
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</svg>
)}
{t.last.author?.nickname ?? "Törölt tag"},{" "}
<time suppressHydrationWarning dateTime={t.last.at}>
{ago(t.last.at)}
</time>
</span>
<span className="fh-topic-desc">{t.description}</span>
{t.readable && t.last && (
<span className="fh-topic-last">
{t.last.author && (
<Avatar avatar={t.last.author.avatar} size={18} online={t.last.author.online} />
)}
{t.last.author?.nickname ?? "Törölt tag"},{" "}
<time suppressHydrationWarning dateTime={t.last.at}>
{ago(t.last.at)}
</time>
</span>
)}
{!t.readable && <span className="fh-topic-last">Belépés után olvasható</span>}
</span>
{t.readable && (
<span className="fh-topic-count">
<strong>{t.thread_count ?? 0}</strong> szál
</span>
)}
{!t.readable && <span className="fh-topic-last">Belépés után olvasható</span>}
</span>
{t.readable && (
<span className="fh-topic-count">
<strong>{t.thread_count ?? 0}</strong> szál
</span>
)}
{t.readable && t.new_count ? (
<span className="ft-new">{t.new_count > 99 ? "99+" : t.new_count} új</span>
) : null}
</Link>
</li>
))}
{t.readable && t.new_count ? (
<span className="ft-new">{t.new_count > 99 ? "99+" : t.new_count} új</span>
) : null}
</Link>
</li>
),
)}
</ul>
</section>
</div>
@@ -212,6 +239,23 @@ export default async function ForumHomePage() {
<SkyCard sky={sky} />
</div>
)}
{home.data.online.length > 0 && (
<section className="fh-card fh-online o-7" aria-labelledby="fh-online-title">
<h2 id="fh-online-title" className="fh-online-title">
Most itt vannak <span className="hint">({home.data.online.length})</span>
</h2>
<ul className="fh-online-list">
{home.data.online.map((m) => (
<li key={m.nickname}>
<Link href={memberHref(m.nickname)} className="fh-online-item">
<Avatar avatar={m.avatar} size={28} online />
<span>{m.nickname}</span>
</Link>
</li>
))}
</ul>
</section>
)}
{viewer.member && (
<section className="fh-card fh-me o-7" aria-label="Saját">
<div className="fh-me-head">
@@ -220,7 +264,7 @@ export default async function ForumHomePage() {
<Link href={memberHref(viewer.member.nickname)} className="fa-name">
{viewer.member.nickname}
</Link>
<span className="fa-rank">{viewer.member.rank_name}</span>
<RankBadge rank={viewer.member.rank} name={viewer.member.rank_name} />
</span>
</div>
<div className="fh-me-actions">
@@ -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<string>("24");
const [reason, setReason] = useState("");
@@ -40,6 +40,19 @@ export function BanPanel({ nickname, banned }: { nickname: string; banned: boole
<details className="fban">
<summary className="btn btn-sm btn-ghost">Moderálás</summary>
<div className="fban-body">
{ownPicture && (
<button
type="button"
className="btn btn-sm"
disabled={busy}
onClick={() =>
window.confirm("Visszaállítod a kezdő avatart? A feltöltött kép törlődik.") &&
act(() => api(`/forum/members/${encodeURIComponent(nickname)}/avatar-reset`, { method: "POST" }))
}
>
Saját kép eltávolítása
</button>
)}
{banned && (
<button
type="button"
@@ -4,6 +4,7 @@ import { notFound } from "next/navigation";
import { Avatar } from "@/components/forum/Avatar";
import { signsText } from "@/components/forum/AuthorLine";
import { Badge, RankBadge } from "@/components/forum/Badges";
import { PostBody } from "@/components/forum/PostBody";
import { type MemberProfile, ago, banText, threadHref } from "@/lib/forum";
import { forumGet } from "@/lib/forumServer";
@@ -45,8 +46,10 @@ export default async function MemberPage({ params }: Props) {
<div className="fmember-names">
<h1>{a.nickname}</h1>
<span className="fmember-badges">
<span className="fa-rank">{a.rank_name}</span>
{a.moderator && <span className="fa-badge fa-badge-mod">Moderátor</span>}
<RankBadge rank={a.rank} name={a.rank_name} />
{a.moderator && <Badge kind="mod" />}
{a.listener && <Badge kind="listener" />}
{a.supporter && <Badge kind="supporter" />}
</span>
{member.last_seen && <span className="hint">{LAST_SEEN[member.last_seen]}</span>}
</div>
@@ -68,7 +71,11 @@ export default async function MemberPage({ params }: Props) {
</Link>
)}
{viewer.moderator && !member.own && !a.moderator && (
<BanPanel nickname={a.nickname} banned={member.banned_until !== null} />
<BanPanel
nickname={a.nickname}
banned={member.banned_until !== null}
ownPicture={a.avatar.startsWith("upload:")}
/>
)}
</section>
@@ -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 }) {
) : (
<span className="fa-name muted">{other}</span>
)}
{c.other && <span className="fa-rank">{c.other.rank_name}</span>}
{c.other && <RankBadge rank={c.other.rank} name={c.other.rank_name} />}
</div>
{c.state === "accepted" && (
<details className="ftv-mod">
+15 -7
View File
@@ -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() {
</p>
<p>
<strong>Forum:</strong> 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() {
<p>
<strong>How we use it:</strong> 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.
</p>
<p>
@@ -326,7 +333,8 @@ export default async function PrivacyPolicyPage() {
</li>
<li>Data needed for invoicing: for the period required by accounting law (8 years).</li>
<li>
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.
@@ -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<string, string> | null | undefined): string | null {
@@ -100,8 +101,10 @@ export function AuthorLine({
{author.nickname}
</Link>
{author.online && <span className="sr-only">(online)</span>}
<span className="fa-rank">{author.rank_name}</span>
{author.moderator && <span className="fa-badge fa-badge-mod">Moderátor</span>}
<RankBadge rank={author.rank} name={author.rank_name} />
{author.moderator && <Badge kind="mod" />}
{author.listener && <Badge kind="listener" />}
{author.supporter && <Badge kind="supporter" />}
{badges}
</span>
{(shown || time) && (
@@ -3,6 +3,8 @@
// a pale tint in the light one (forum.css: .av-<colour>). 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 (
<span className="av av-picture" style={{ width: size, height: size }}>
{/* A member's own picture, served by the forum (already small and square). */}
<img src={picture} alt="" width={size} height={size} loading="lazy" />
{online && <span className="av-online" title="Most online" />}
</span>
);
}
const [glyph, colour] = (avatar ?? "hold-ejkek").split("-");
const known = (AVATAR_COLOURS as readonly string[]).includes(colour) ? colour : "ejkek";
return (
@@ -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<Rank, React.ReactNode> = {
// Vándor: on the way (a path from a starting point).
vandor: (
<>
<circle cx="5.5" cy="18.5" r="1.8" />
<path d="M8 17.5c3-1 2.5-4.5 6-5.5s3.5-3.5 5-6" strokeDasharray="2.2 2.6" />
</>
),
// Kereső: a compass.
kereso: (
<>
<circle cx="12" cy="12" r="8.5" />
<path d="M14.8 9.2l-1.6 4-4 1.6 1.6-4z" />
</>
),
// Fonó: a spool with thread.
fono: (
<>
<path d="M6.5 4.5h11M6.5 19.5h11" />
<path d="M8.5 4.5v15M15.5 4.5v15" />
<path d="M8.5 8.5l7 2.5M8.5 13l7 2.5" />
</>
),
// Csillagfonó: a star with a thread from it.
csillagfono: (
<>
<path d="M10 3.5l1.5 4 4 1.5-4 1.5-1.5 4-1.5-4-4-1.5 4-1.5z" />
<path d="M14 15c2.5 0 3.5 1.5 3.5 3s-1.5 2.5-3 2" />
</>
),
// Sorsfonó: the thread of fate around the circle (the site's mark).
sorsfono: (
<>
<circle cx="12" cy="12" r="7" />
<path d="M4.5 16.5c4.5-.5 6-7 11-8.5" />
<circle cx="18.5" cy="6" r="1.4" />
</>
),
};
export type BadgeKind = "mod" | "listener" | "supporter" | "starter" | "sky";
const BADGES: Record<BadgeKind, { label: string; title: string; icon: React.ReactNode }> = {
// A shield with a tick.
mod: {
label: "Moderátor",
title: "A fórum moderátora",
icon: (
<>
<path d="M12 3.5l7 2.5v5.5c0 4.5-3 7.5-7 9-4-1.5-7-4.5-7-9V6z" />
<path d="M9 12l2.2 2.2L15.5 10" />
</>
),
},
// An ear.
listener: {
label: "Meghallgató",
title: "Önkéntes meghallgató: szívesen meghallgat",
icon: (
<>
<path d="M7 9.5a5 5 0 0 1 10 0c0 3-2.5 4-3 6s-1.5 4-3.8 4A2.7 2.7 0 0 1 7.5 17" />
<path d="M10 10a2 2 0 0 1 4 0c0 1.3-1.2 1.7-1.6 2.6" />
</>
),
},
// A gem.
supporter: {
label: "Támogató",
title: "Vásárlásával támogatja a Sorsfonalakat",
icon: (
<>
<path d="M7.5 5h9l3.5 4.5L12 19.5 4 9.5z" />
<path d="M4 9.5h16M10 5l-1.5 4.5L12 19.5l3.5-10L14 5" />
</>
),
},
// A quill.
starter: {
label: "Szálindító",
title: "Ő indította a szálat",
icon: (
<>
<path d="M19.5 4.5c-6 .5-10.5 4.5-11.5 11l-1.5 4" />
<path d="M8.3 13.5c4.5 0 8.5-3 11.2-9" />
</>
),
},
// A crescent Moon.
sky: {
label: "napi égbolt",
title: "A Sorsfonalak napi szála az égboltról",
icon: <path d="M19 14.5A7.5 7.5 0 0 1 9.5 5a7.5 7.5 0 1 0 9.5 9.5z" />,
},
};
function Icon({ children }: { children: React.ReactNode }) {
return (
<svg className="fa-icon" viewBox="0 0 24 24" aria-hidden="true">
{children}
</svg>
);
}
/** The member's rank, with its icon. */
export function RankBadge({ rank, name }: { rank: Rank; name: string }) {
return (
<span className={`fa-rank fa-rank-${rank}`} title={`Rang: ${name}`}>
<Icon>{RANK_ICONS[rank] ?? RANK_ICONS.vandor}</Icon>
{name}
</span>
);
}
/** 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 (
<span className={`fa-badge fa-badge-${kind === "sky" ? "starter" : kind}`} title={b.title}>
<Icon>{b.icon}</Icon>
{b.label}
</span>
);
}
@@ -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<boolean>;
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<HTMLTextAreaElement>(null);
const timer = useRef<number | undefined>(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({
</label>
<textarea
id={id}
ref={area}
className="fc-text"
rows={rows}
placeholder={placeholder}
value={text}
onChange={(e) => {
withEmoji(e, setText);
lookUp(e.target.value, e.target.selectionStart ?? e.target.value.length);
onTyping?.();
}}
onKeyDown={(e) => {
if (e.key === "Escape") setSuggest(null);
}}
maxLength={10000}
autoFocus={autoFocus}
aria-autocomplete={mentions ? "list" : undefined}
/>
{suggest && (
<div className="fc-suggest" role="listbox" aria-label="Tagok">
{suggest.members.map((m) => (
<button
key={m.nickname}
type="button"
role="option"
aria-selected="false"
className="fc-suggest-item"
onClick={() => pick(m.nickname)}
>
<Avatar avatar={m.avatar} size={24} online={m.online} />
{m.nickname}
</button>
))}
</div>
)}
<div className="fc-actions">
<span className="fc-spacer" />
{onCancel && (
@@ -12,6 +12,8 @@ export interface NavCounts {
unread: number;
messages: number;
reports: number;
/** Listeners: threads waiting for a first reply. */
waiting: number;
}
/** The live notice a page listens to (`window` event `forum:live`). */
@@ -27,7 +29,12 @@ export interface LiveNotice {
const POLL_MS = 30_000;
function counts(data: ForumNavData): NavCounts {
return { unread: data.followed?.new_replies ?? 0, messages: data.messages ?? 0, reports: data.reports ?? 0 };
return {
unread: data.followed?.new_replies ?? 0,
messages: data.messages ?? 0,
reports: data.reports ?? 0,
waiting: data.waiting ?? 0,
};
}
/**
@@ -151,7 +158,7 @@ export function ForumNav({
wsUrl: string;
}) {
const path = usePathname();
const [{ unread, messages, reports }, setCounts] = useState(initial);
const [{ unread, messages, reports, waiting }, setCounts] = useState(initial);
const refresh = useCallback(() => {
api<ForumNavData>("/forum/nav")
.then((data) => setCounts(counts(data)))
@@ -173,6 +180,8 @@ export function ForumNav({
label: "Fórum",
icon: "forum" as const,
current: path === "/forum" || path.startsWith("/forum/szal"),
// Listeners: what waits for a first reply.
badge: waiting,
},
{
href: loggedIn ? "/forum/kovetett" : "/belepes?vissza=/forum/kovetett",
@@ -213,7 +222,7 @@ export function ForumNav({
<>
{reports > 0 && (
<Link href="/forum/moderalas" className="forum-modchip">
Jelentés: {reports}
Moderálás: {reports}
</Link>
)}
<nav className="forum-nav" aria-label="Fórum menü">
@@ -0,0 +1,70 @@
"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { api, errorText } from "@/lib/api";
/** A restricted topic: asking to join it (a moderator decides), or the request waiting. */
export function JoinTopic({ slug, pending }: { slug: string; pending: boolean }) {
const router = useRouter();
const [open, setOpen] = useState(false);
const [note, setNote] = useState("");
const [busy, setBusy] = useState(false);
const [sent, setSent] = useState(pending);
const [error, setError] = useState<string | null>(null);
if (sent) return <span className="hint">Jelentkezésed elküldve, egy moderátor dönt róla.</span>;
async function send(e: React.FormEvent) {
e.preventDefault();
setBusy(true);
setError(null);
try {
await api(`/forum/topics/${slug}/join`, { body: { note } });
setSent(true);
router.refresh();
} catch (err) {
setError(errorText(err));
} finally {
setBusy(false);
}
}
if (!open) {
return (
<button type="button" className="btn btn-sm" onClick={() => setOpen(true)}>
Csatlakozás kérése
</button>
);
}
return (
<form className="fjoin" onSubmit={send}>
<label htmlFor={`join-${slug}`} className="hint">
Pár szó, miért szeretnél csatlakozni (nem kötelező)
</label>
<textarea
id={`join-${slug}`}
className="fc-text"
rows={2}
maxLength={300}
value={note}
onChange={(e) => setNote(e.target.value)}
/>
{error && (
<p className="msg msg-error" role="alert">
{error}
</p>
)}
<div className="fc-actions">
<span className="fc-spacer" />
<button type="button" className="btn btn-ghost btn-sm" onClick={() => setOpen(false)}>
Mégse
</button>
<button type="submit" className="btn btn-primary btn-sm" disabled={busy}>
Jelentkezem
</button>
</div>
</form>
);
}
@@ -1,5 +1,33 @@
/** A post's text: paragraphs and line breaks as typed; links stay plain text. */
export function PostBody({ text }: { text: string }) {
import Link from "next/link";
import { memberHref } from "@/lib/forum";
/** "@Holdfény" as a link to the profile, for the nicknames the post names. */
function withMentions(line: string, mentions: string[]): React.ReactNode[] {
if (mentions.length === 0) return [line];
const escaped = [...mentions]
.sort((a, b) => b.length - a.length)
.map((n) => n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
const pattern = new RegExp(`@(${escaped.join("|")})`, "gi");
const out: React.ReactNode[] = [];
let last = 0;
for (const match of line.matchAll(pattern)) {
const at = match.index ?? 0;
if (at > last) out.push(line.slice(last, at));
const nickname = mentions.find((n) => n.toLowerCase() === match[1].toLowerCase()) ?? match[1];
out.push(
<Link key={at} href={memberHref(nickname)} className="fp-mention">
@{match[1]}
</Link>,
);
last = at + match[0].length;
}
if (last < line.length) out.push(line.slice(last));
return out;
}
/** A post's text: paragraphs and line breaks as typed; links stay plain text; mentions link to profiles. */
export function PostBody({ text, mentions = [] }: { text: string; mentions?: string[] }) {
return (
<div className="fp-body">
{text.split(/\n{2,}/).map((para, i) => (
@@ -7,7 +35,7 @@ export function PostBody({ text }: { text: string }) {
{para.split("\n").map((line, j) => (
<span key={j}>
{j > 0 && <br />}
{line}
{withMentions(line, mentions)}
</span>
))}
</p>
@@ -32,7 +32,7 @@ export function ThreadList({ threads, showTopic = true }: { threads: ThreadCard[
<span className="ft-meta">
{t.author && <Avatar avatar={t.author.avatar} size={20} online={t.author.online} />}
<span>
{t.author?.nickname ?? "Törölt tag"}
{t.system ? "Sorsfonalak" : (t.author?.nickname ?? "Törölt tag")}
{showTopic && ` · ${t.topic.name}`}
<span className="ft-m-narrow">
{" "}
@@ -14,6 +14,7 @@ import type { LiveNotice } from "./ForumNav";
import { ReactionIcon } from "./ReactionIcon";
import { ReportForm } from "./ReportButton";
import { TypingLine, useTypingSender, useTypingWatch } from "./typing";
import { Badge, RankBadge } from "./Badges";
/** How often the open thread looks for new replies (while the page is in front). */
const POLL_MS = 30_000;
@@ -154,6 +155,21 @@ function Popover({
);
}
/** The site's own mark as an avatar (the daily sky thread). */
function SiteMark({ size }: { size: number }) {
return (
<span className="av av-site" style={{ width: size, height: size }}>
<svg viewBox="0 0 64 64" width={size} height={size} aria-hidden="true">
<circle cx="32" cy="32" r="32" className="av-bg" />
<g fill="none" strokeWidth="4.5" strokeLinecap="round" className="av-site-mark">
<circle cx="32" cy="32" r="18" />
<path d="M15 43 C 26 42, 30 25, 42 21" />
</g>
</svg>
</span>
);
}
function PostCard({
post,
page,
@@ -210,7 +226,9 @@ function PostCard({
return (
<article className={classes} id={`h${post.id}`}>
<span className="fp-av">
{author ? (
{post.system ? (
<SiteMark size={size} />
) : author ? (
<Link href={memberHref(author.nickname)} tabIndex={-1} aria-hidden="true">
<Avatar avatar={author.avatar} size={size} online={author.online} />
</Link>
@@ -220,17 +238,32 @@ function PostCard({
</span>
<div className="fp-head">
<span className="fp-names">
{author ? (
{post.system ? (
<span className="fa-name">Sorsfonalak</span>
) : author ? (
<Link href={memberHref(author.nickname)} className="fa-name">
{author.nickname}
</Link>
) : (
<span className="fa-name muted">Törölt tag</span>
)}
{post.reply_to?.nickname && nested && (
<span className="fp-replyto" title={`Válasz neki: ${post.reply_to.nickname}`}>
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M9 14L4 9l5-5" />
<path d="M4 9h10a6 6 0 0 1 6 6v4" />
</svg>
<span className="sr-only">válasz neki:</span>
{post.reply_to.nickname}
</span>
)}
{author?.online && <span className="sr-only">(online)</span>}
{author && <span className="fa-rank">{author.rank_name}</span>}
{author?.moderator && <span className="fa-badge fa-badge-mod">Moderátor</span>}
{starter && !post.is_opening && <span className="fa-badge fa-badge-starter">Szálindító</span>}
{author && <RankBadge rank={author.rank} name={author.rank_name} />}
{post.system && <Badge kind="sky" />}
{author?.moderator && <Badge kind="mod" />}
{author?.listener && <Badge kind="listener" />}
{author?.supporter && <Badge kind="supporter" />}
{starter && !post.is_opening && <Badge kind="starter" />}
{isNew && <span className="fa-badge fa-badge-new">új</span>}
{glyphs && !nested && (
<span className="fp-signs sym" title={glyphs.title}>
@@ -261,6 +294,7 @@ function PostCard({
</button>
) : editing ? (
<Composer
mentions
id={`szerk-${post.id}`}
label="Hozzászólás szerkesztése"
initial={post.body ?? ""}
@@ -275,7 +309,7 @@ function PostCard({
}}
/>
) : (
post.body !== null && <PostBody text={post.body} />
post.body !== null && <PostBody text={post.body} mentions={post.mentions} />
)}
</div>
{!editing && (!post.deleted || menuItems.length > 0) && (
@@ -529,6 +563,22 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
<Link href="/forum">Fórum</Link>
<span aria-hidden="true">›</span>
<Link href={`/forum/${thread.topic.slug}`}>{thread.topic.name}</Link>
{thread.topic.visibility !== "public" && (
<span
className="ftv-private"
title={
thread.topic.visibility === "members"
? "Csak belépett tagok látják, a keresők sem"
: "Zárt kör: csak a jóváhagyott tagok látják"
}
>
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</svg>
{thread.topic.visibility === "members" ? "csak tagoknak" : "zárt kör"}
</span>
)}
</nav>
<div className="ftv-toolbar">
@@ -649,12 +699,6 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
<p className="ftv-gate">Ez a szál le van zárva, új hozzászólás nem írható.</p>
) : (
<>
{thread.intent === "listen" && (
<p className="ftv-hint">
{starter} meghallgatást kér: tanács helyett írd le, ha veled is történt hasonló, vagy csak azt, hogy itt
vagy.
</p>
)}
{replyTo && (
<p className="ftv-replyto">
Válasz neki: <strong>{replyTo.author?.nickname ?? "Törölt tag"}</strong>
@@ -669,6 +713,7 @@ export function ThreadView({ initial }: { initial: ThreadPage }) {
</p>
)}
<Composer
mentions
onTyping={imTyping}
id="valasz-szoveg"
label="Válaszod"
+42
View File
@@ -19,6 +19,10 @@ export interface ForumAuthor {
online: boolean;
/** Planet (or `ascendant`) → sign, as the member chose to share. */
signs: Record<string, string> | null;
/** A volunteer listener ("Meghallgató"). */
listener?: boolean;
/** Bought a package and shows the "Támogató" badge. */
supporter?: boolean;
}
export interface ForumViewer {
@@ -39,6 +43,8 @@ export interface ForumTopic extends TopicRef {
visibility: "public" | "members" | "restricted";
listening: boolean;
readable: boolean;
/** A restricted topic: the viewer's place in it. */
membership?: "none" | "pending" | "approved" | null;
thread_count?: number;
new_count?: number | null;
last?: { author: ForumAuthor | null; at: string } | null;
@@ -58,11 +64,15 @@ export interface ThreadCard {
pinned: boolean;
locked: boolean;
unread: number | null;
/** The site's own thread (the daily sky). */
system?: boolean;
}
export interface ForumHome {
viewer: ForumViewer;
followed: { new_replies: number; threads: number } | null;
/** "Most itt vannak". */
online: ForumAuthor[];
topics: ForumTopic[];
unanswered: ThreadCard[];
hot: ThreadCard[];
@@ -93,6 +103,12 @@ export interface ForumPost {
mine: ReactionKind | "down" | null;
/** Moderators only. */
down?: number;
/** The nicknames the post names ("@Holdfény"). */
mentions?: string[];
/** Written by the site itself (the daily sky). */
system?: boolean;
/** The post this reply answered (it may sit on the same level). */
reply_to?: { id: number; nickname: string | null } | null;
}
export interface ThreadPage {
@@ -108,6 +124,7 @@ export interface ThreadPage {
locked: boolean;
pinned: boolean;
deleted: { reason: string | null } | null;
system?: boolean;
};
posts: ForumPost[];
access?: {
@@ -123,6 +140,9 @@ export interface EmailSettings {
replies: "off" | "daily" | "instant";
followed: "off" | "daily";
messages: "off" | "instant";
mentions: "off" | "instant";
listener: "off" | "instant";
weekly: boolean;
}
export interface ForumMe {
@@ -143,8 +163,14 @@ export interface ForumMe {
banned_until: string | null;
ban_reason: string | null;
email: EmailSettings;
listener: boolean;
supporter_badge: boolean;
can_listen: boolean;
can_upload_avatar: boolean;
} | null;
chart: Record<Exclude<ChartShare, "none">, Record<string, string> | null> | null;
/** Bought a package: may show the "Támogató" badge. */
can_supporter: boolean;
}
export interface MemberProfile {
@@ -204,6 +230,11 @@ export function threadHref(t: { id: number; slug: string }, postId?: number): st
return postId ? `${path}#h${postId}` : path;
}
/** The address of an uploaded avatar (`upload:<file>`), or null for a starter one. */
export function uploadedAvatar(avatar: string | null | undefined): string | null {
return avatar?.startsWith("upload:") ? `/api/v1/forum/avatars/${encodeURIComponent(avatar.slice(7))}` : null;
}
export function memberHref(nickname: string): string {
return `/forum/tag/${encodeURIComponent(nickname)}`;
}
@@ -319,5 +350,16 @@ export interface ForumNavData {
viewer: ForumViewer;
followed: { new_replies: number } | null;
messages: number | null;
/** Moderators: open reports and requests to join restricted topics. */
reports: number | null;
/** Listeners: threads asking to be heard that wait for a reply. */
waiting: number | null;
}
export interface TopicRequest {
topic: TopicRef;
member: ForumAuthor | null;
status: "pending" | "approved";
note: string;
requested_at: string;
}