Merge the forum (community module) into main

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 16:43:19 +00:00
co-authored by Claude Opus 5.5
131 changed files with 17773 additions and 357 deletions
+1
View File
@@ -58,6 +58,7 @@ export const ROLE_LABELS: Record<string, string> = {
premium: "Prémium",
vip: "VIP",
creator: "Szerző",
moderator: "Moderátor",
admin: "Admin",
};
+68
View File
@@ -0,0 +1,68 @@
// The old forums' character smileys, turned into emoji while typing (the
// forum service converts the same list on save: services/forum/src/text.rs).
// A smiley converts only standing alone, once a space or line break follows
// it, so links and the like stay as typed.
export const EMOTICONS: [string, string][] = [
[":)", "🙂"],
[":-)", "🙂"],
["(:", "🙂"],
[":D", "😄"],
[":-D", "😄"],
["xD", "😆"],
["XD", "😆"],
[";)", "😉"],
[";-)", "😉"],
[":(", "🙁"],
[":-(", "🙁"],
[":'(", "😢"],
[":P", "😛"],
[":-P", "😛"],
[":p", "😛"],
[":O", "😮"],
[":o", "😮"],
[":-O", "😮"],
[":*", "😘"],
[":-*", "😘"],
[":/", "😕"],
[":|", "😐"],
["B)", "😎"],
["^^", "😊"],
["^_^", "😊"],
["<3", "❤️"],
["</3", "💔"],
];
const LOOKUP = new Map(EMOTICONS);
const ALTERNATIVES = [...LOOKUP.keys()]
.sort((a, b) => b.length - a.length)
.map((code) => code.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
.join("|");
/**
* The text with its finished smileys as emoji, and where the caret goes.
* `atEnd`: also a smiley at the very end (when sending).
*/
export function convertEmoticons(text: string, caret: number, atEnd = false): { text: string; caret: number } {
const pattern = new RegExp(`(^|\\s)(${ALTERNATIVES})(?=\\s${atEnd ? "|$" : ""})`, "g");
let shift = 0;
const converted = text.replace(pattern, (match, space: string, code: string, offset: number) => {
const emoji = LOOKUP.get(code) ?? code;
if (offset + space.length < caret) shift += emoji.length - code.length;
return space + emoji;
});
return { text: converted, caret: caret + shift };
}
/**
* For a text field's change: converts and puts the caret back where it was
* (a controlled field would jump it to the end).
*/
export function withEmoji(e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>, set: (text: string) => void) {
const el = e.target;
const { text, caret } = convertEmoticons(el.value, el.selectionStart ?? el.value.length);
set(text);
if (text !== el.value) {
requestAnimationFrame(() => el.setSelectionRange(caret, caret));
}
}
+418
View File
@@ -0,0 +1,418 @@
// The forum's data as the forum service sends it, and small helpers shared
// by its server and client components.
/** The forum's colours: light by default, dark on request (a cookie). */
export const FORUM_THEME_COOKIE = "sf_forum_theme";
export type ForumTheme = "light" | "dark";
export type Rank = "vandor" | "kereso" | "fono" | "csillagfono" | "sorsfono";
export type ReactionKind = "with_you" | "thanks" | "me_too" | "insight";
export type ChartShare = "none" | "sun" | "big3" | "planets";
/** How a member appears next to what they wrote. */
export interface ForumAuthor {
nickname: string;
avatar: string;
rank: Rank;
rank_name: string;
moderator: boolean;
online: boolean;
/** Planet (or `ascendant`) → sign, as the member chose to share. */
signs: Record<string, string> | null;
/** A volunteer companion ("Kísérő") for the threads asking to be heard. */
listener?: boolean;
/** Bought a package and shows the "Támogató" badge. */
supporter?: boolean;
/** One of the first hundred members ("Alapító tag"). */
founder?: boolean;
}
export interface ForumViewer {
logged_in: boolean;
needs_nickname: boolean;
moderator: boolean;
member: { nickname: string; avatar: string; rank: Rank; rank_name: string; banned: boolean } | null;
}
export interface TopicRef {
slug: string;
name: string;
}
export interface ForumTopic extends TopicRef {
id: number;
description: string;
visibility: "public" | "members" | "restricted";
listening: boolean;
/** Archived: readable, but takes nothing new. */
archived?: 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;
}
export interface ThreadCard {
id: number;
slug: string;
title: string;
intent: "listen" | "advice" | null;
topic: TopicRef;
author: ForumAuthor | null;
created_at: string;
last_post_at: string;
reply_count: number;
participants: number;
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;
/** Unread answers to the member. */
replies: number | null;
/** Listeners: threads asking to be heard that wait for a reply. */
waiting: number | null;
/** "Most itt vannak". */
online: ForumAuthor[];
topics: ForumTopic[];
unanswered: ThreadCard[];
hot: ThreadCard[];
}
export interface TopicPage {
viewer: ForumViewer;
topic: TopicRef & { description: string; visibility: string; listening: boolean; archived?: boolean };
threads: ThreadCard[];
page: number;
has_more: boolean;
}
export interface ForumPost {
id: number;
parent_id: number | null;
is_opening: boolean;
author: ForumAuthor | null;
own: boolean;
body: string | null;
deleted: { by_moderator: boolean; reason: string | null } | null;
created_at: string;
edited_at: string | null;
helped: boolean;
reactions: Record<ReactionKind, number>;
score: number;
collapsed: boolean;
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;
/** The viewer muted the author: shown folded up. */
muted?: boolean;
/** A chart, forecast or synastry shared with the question. */
share?: ShareCardData | null;
/** Previews of the links a provider knows (YouTube for now). */
links?: LinkPreview[] | null;
}
/** A link the forum's link module knows, under a post. */
export interface LinkPreview {
provider: "youtube";
id: string;
/** As written in the post. */
url: string;
/** Where to start playing, in seconds. */
start: number | null;
title: string;
author: string | null;
/** Our own copy of the thumbnail. */
thumbnail: string | null;
}
/** A shared chart in a post: in full for members, `locked` for visitors, `revoked` when taken down. */
export interface ShareCardData {
slug?: string;
kind: "chart" | "synastry" | "forecast";
locked?: boolean;
revoked?: boolean;
title?: string;
summary?: string | null;
points?: { id: string; sign: string; degree: number | null; house: number | null }[];
time_known?: boolean;
}
export interface ThreadPage {
viewer: ForumViewer;
thread: {
id: number;
slug: string;
title: string;
intent: "listen" | "advice" | null;
topic: TopicRef & { visibility: string; listening: boolean; archived?: boolean };
author: ForumAuthor | null;
created_at: string;
locked: boolean;
pinned: boolean;
deleted: { reason: string | null } | null;
system?: boolean;
};
posts: ForumPost[];
access?: {
can_reply: boolean;
can_downvote: boolean;
is_thread_author: boolean;
following: boolean;
last_read_post_id: number | null;
};
}
export interface EmailSettings {
replies: "off" | "daily" | "instant";
followed: "off" | "daily";
messages: "off" | "instant";
mentions: "off" | "instant";
listener: "off" | "instant";
weekly: boolean;
}
export interface ForumMe {
viewer: ForumViewer;
member: {
nickname: string;
avatar: string;
bio: string;
chart_share: ChartShare;
invisible: boolean;
points: number;
post_count: number;
created_at: string;
rank: Rank;
rank_name: string;
next_rank: { rank: Rank; name: string; points: number; days: number } | null;
nickname_change_after: string | null;
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 {
viewer: ForumViewer;
relation: MemberRelation | null;
member: {
author: ForumAuthor;
bio: string;
created_at: string;
post_count: number;
thread_count: number;
last_seen: "online" | "day" | "week" | "earlier" | null;
own: boolean;
/** The viewer muted them. */
muted: boolean;
banned_until: string | null;
ban_reason: string | null;
};
recent: {
id: number;
thread_id: number;
thread_slug: string;
thread_title: string;
topic: TopicRef;
created_at: string;
excerpt: string;
is_opening: boolean;
}[];
}
export interface ModLogEntry {
id: number;
actor: string | null;
actor_kind: "human" | "ai";
action: string;
target: string | null;
thread: { id: number; title: string | null } | null;
post_id: number | null;
reason: string | null;
until: string | null;
created_at: string;
}
export const REACTIONS: { kind: ReactionKind; emoji: string; label: string }[] = [
{ kind: "with_you", emoji: "🤍", label: "Veled vagyok" },
{ kind: "thanks", emoji: "🙏", label: "Köszönöm" },
{ kind: "me_too", emoji: "✨", label: "Rám is igaz" },
{ kind: "insight", emoji: "💡", label: "Érdekes gondolat" },
];
export const INTENTS = {
listen: { label: "Csak meghallgatást kér", short: "Meghallgatást kér" },
advice: { label: "Tanácsot, véleményt kér", short: "Tanácsot kér" },
} as const;
/** `/forum/szal/123-nem-tudom-elengedni`: the number decides, the words are for reading. */
export function threadHref(t: { id: number; slug: string }, postId?: number): string {
const path = t.slug ? `/forum/szal/${t.id}-${t.slug}` : `/forum/szal/${t.id}`;
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)}`;
}
/** "most", "12 perce", "3 órája", "tegnap", "4 napja", then the date. */
export function ago(iso: string, now: Date = new Date()): string {
const then = new Date(iso);
const minutes = Math.floor((now.getTime() - then.getTime()) / 60000);
if (minutes < 1) return "most";
if (minutes < 60) return `${minutes} perce`;
const hours = Math.floor(minutes / 60);
if (hours < 24) return `${hours} órája`;
const days = Math.floor(hours / 24);
if (days === 1) return "tegnap";
if (days < 7) return `${days} napja`;
return then.toLocaleDateString("hu-HU", {
timeZone: "Europe/Budapest",
year: then.getFullYear() === now.getFullYear() ? undefined : "numeric",
month: "long",
day: "numeric",
});
}
/** A ban's end as the member reads it. */
export function banText(until: string | null): string {
if (!until) return "";
if (until === "infinity") return "véglegesen";
return `eddig: ${new Date(until).toLocaleString("hu-HU", { timeZone: "Europe/Budapest", month: "long", day: "numeric", hour: "2-digit", minute: "2-digit" })}`;
}
/** The viewer's relation to a member (profile page). */
export interface MemberRelation {
conversation_id: number | null;
state: ConversationState | null;
can_request: boolean;
eligible: boolean;
}
export type ConversationState = "accepted" | "incoming" | "outgoing" | "expired" | "blocked_by_me" | "closed";
export interface ConversationItem {
id: number;
other: ForumAuthor | null;
state: ConversationState;
intro: string;
created_at: string;
last_message_at: string | null;
last_message: { excerpt: string; mine: boolean } | null;
unread: number;
}
export interface ChatMessage {
id: number;
mine: boolean;
body: string;
created_at: string;
}
export interface ConversationPage {
viewer: ForumViewer;
conversation: {
id: number;
other: ForumAuthor | null;
state: ConversationState;
intro: string;
requested_by_me: boolean;
created_at: string;
};
messages: ChatMessage[];
}
export type ReportKind = "spam" | "ad" | "rude" | "crisis" | "illegal" | "other";
export const REPORT_KINDS: { kind: ReportKind; label: string }[] = [
{ kind: "rude", label: "Bántó, kioktató vagy sértő" },
{ kind: "ad", label: "Szolgáltatást hirdet (jóslás, gyógyítás, tanfolyam)" },
{ kind: "spam", label: "Kéretlen reklám, spam" },
{ kind: "crisis", label: "Aggódom érte: lelki krízisben lehet" },
{ kind: "illegal", label: "Jogsértő tartalom" },
{ kind: "other", label: "Más (írd le)" },
];
export interface ReportEntry {
id: number;
kind: ReportKind;
note: string;
reporter: string;
status: "open" | "resolved" | "dismissed";
handled_by: string | null;
handled_at: string | null;
created_at: string;
open_reports_of_target: number;
target:
| {
type: "post";
id: number;
thread: { id: number; title: string; slug: string };
author: ForumAuthor | null;
body: string;
deleted: boolean;
}
| {
type: "message";
id: number;
conversation_id: number | null;
messages: { id: number; sender: ForumAuthor | null; body: string; created_at: string; reported: boolean }[];
}
| null;
}
/** The forum menu's counts. */
export interface ForumNavData {
viewer: ForumViewer;
/** Unread answers to the member (a reply to them, in their thread, or naming them). */
replies: number | null;
messages: number | null;
/** Moderators: open reports and requests to join restricted topics. */
reports: number | null;
}
/** An answer to the member, on the "Válaszok" page. */
export interface ReplyEntry {
id: number;
thread: { id: number; title: string; slug: string };
author: ForumAuthor | null;
excerpt: string;
created_at: string;
/** `reply`: to one of their posts; `thread`: in their thread; `mention`: names them. */
kind: "reply" | "thread" | "mention";
unread: boolean;
}
export interface TopicRequest {
topic: TopicRef;
member: ForumAuthor | null;
status: "pending" | "approved";
note: string;
requested_at: string;
}
+44
View File
@@ -0,0 +1,44 @@
// Forum service calls from server components, with the visitor's session.
// Without FORUM_URL the forum is switched off (no menu item, its pages 404).
import "server-only";
import { cookies } from "next/headers";
import { BackendError, SESSION_COOKIE } from "./server";
export const FORUM_URL = (process.env.FORUM_URL ?? "").replace(/\/$/, "");
export function forumEnabled(): boolean {
return FORUM_URL !== "";
}
/** The answer of a forum GET: the data, or why there is none. */
export type ForumResult<T> = { ok: true; data: T } | { ok: false; status: 401 | 404 };
/** GET from the forum service as the visitor (logged in or not). */
export async function forumGet<T>(path: string): Promise<ForumResult<T>> {
if (!forumEnabled()) return { ok: false, status: 404 };
const token = (await cookies()).get(SESSION_COOKIE)?.value;
const headers: HeadersInit = token ? { authorization: `Bearer ${token}` } : {};
const res = await fetch(`${FORUM_URL}${path}`, { headers, cache: "no-store" });
if (res.status === 401 || res.status === 404) return { ok: false, status: res.status };
// Not allowed (e.g. the moderation log for a member): the page does not exist for them.
if (res.status === 403) return { ok: false, status: 404 };
if (!res.ok) throw new BackendError(res.status, `${path}: HTTP ${res.status}`);
return { ok: true, data: (await res.json()) as T };
}
/** The public forum pages for the sitemap (nothing when the forum is off or does not answer). */
export async function forumSitemap(): Promise<{
topics: { slug: string; updated: string | null }[];
threads: { id: number; slug: string; updated: string }[];
}> {
const empty = { topics: [], threads: [] };
if (!forumEnabled()) return empty;
try {
const res = await fetch(`${FORUM_URL}/v1/forum/sitemap`, { next: { revalidate: 3600 } });
return res.ok ? await res.json() : empty;
} catch {
return empty;
}
}
+3 -3
View File
@@ -18,8 +18,8 @@ export const ARBITRATION_BOARD = {
web: "https://panaszrendezes.hu",
};
export const PRIVACY_UPDATED = "2026. november 24.";
export const PRIVACY_UPDATED_EN = "24 November 2026";
export const PRIVACY_UPDATED = "2026. november 26.";
export const PRIVACY_UPDATED_EN = "26 November 2026";
/** The terms (ÁSZF) in force; the backend records this version with every purchase (TERMS_VERSION). */
export const TERMS_UPDATED = "2026. november 23.";
export const TERMS_UPDATED = "2026. november 26.";
+9 -4
View File
@@ -6,7 +6,7 @@ import { headers } from "next/headers";
import { cache } from "react";
import { BACKEND_URL } from "./server";
import type { ChartResult } from "./types";
import type { AnalysisContent, ChartResult, Forecast, SolarReturn, SynastryResult } from "./types";
export interface PublicSummary {
id: string;
@@ -16,13 +16,18 @@ export interface PublicSummary {
completed_at: string | null;
}
/** `GET /v1/public/shares/{slug}` of a shared chart. */
type SharedChart = { label: string | null; chart: ChartResult & { time_known: boolean } };
/** `GET /v1/public/shares/{slug}`: a chart, a comparison or a yearly forecast. */
export interface PublicShare {
kind: "chart" | "synastry" | "analysis";
kind: "chart" | "synastry" | "analysis" | "forecast";
title: string | null;
created_at: string;
chart?: { label: string; chart: ChartResult & { time_known: boolean } };
chart?: SharedChart;
summary?: PublicSummary | null;
synastry?: { chart1: SharedChart; chart2: SharedChart; synastry: SynastryResult };
forecast?: { year: number; forecast: Forecast; solar_return: SolarReturn | null };
analysis?: { kind: string; language: string; content: AnalysisContent | null; completed_at: string | null } | null;
}
const SLUG = /^[A-Za-z0-9_-]{8,64}$/;
+1 -1
View File
@@ -1,6 +1,6 @@
// Shapes of the backend responses the frontend uses.
export type Role = "admin" | "creator" | "premium" | "vip" | "user";
export type Role = "admin" | "creator" | "moderator" | "premium" | "vip" | "user";
export interface User {
id: string;