Forum: e-mail notifications with a daily digest
Members choose per kind: replies to them (daily digest, instant or off), new posts in followed threads (daily or off), private messages and requests (instant or off). The forum service queues the instant e-mails (none while online, at most one per thread an hour); the worker's new forum task makes the evening digest of what is unread. Every forum e-mail greets by the nickname and has a one-click unsubscribe (RFC 8058). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -6,7 +6,7 @@ import { useEffect, useState } from "react";
|
||||
import { AVATAR_COLOURS, AVATAR_GLYPHS, Avatar, GLYPH_NAMES } from "@/components/forum/Avatar";
|
||||
import { signsText } from "@/components/forum/AuthorLine";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { type ChartShare, type ForumMe, banText, memberHref } from "@/lib/forum";
|
||||
import { type ChartShare, type EmailSettings, type ForumMe, banText, memberHref } from "@/lib/forum";
|
||||
|
||||
const SHARE_LEVELS: { value: ChartShare; label: string }[] = [
|
||||
{ value: "none", label: "Semmit" },
|
||||
@@ -24,6 +24,9 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
|
||||
const [bio, setBio] = useState(member?.bio ?? "");
|
||||
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" },
|
||||
);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [saved, setSaved] = useState(false);
|
||||
@@ -51,7 +54,7 @@ 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 },
|
||||
body: { nickname, avatar: avatar || null, bio, chart_share: share, invisible, email },
|
||||
});
|
||||
if (back) {
|
||||
router.push(back);
|
||||
@@ -179,6 +182,47 @@ export function ProfileForm({ me, back }: { me: ForumMe; back: string | null })
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<fieldset className="fnew-set">
|
||||
<legend>Értesítések e-mailben</legend>
|
||||
<div className="fprof-mail">
|
||||
<label htmlFor="fprof-mail-replies">Ha valaki válaszol nekem (a szálamban vagy a hozzászólásomra)</label>
|
||||
<select
|
||||
id="fprof-mail-replies"
|
||||
className="inp"
|
||||
value={email.replies}
|
||||
onChange={(e) => setEmail({ ...email, replies: e.target.value as EmailSettings["replies"] })}
|
||||
>
|
||||
<option value="daily">Napi összesítőben, este</option>
|
||||
<option value="instant">Azonnal (szálanként óránként legfeljebb egy levél)</option>
|
||||
<option value="off">Ne küldjetek</option>
|
||||
</select>
|
||||
<label htmlFor="fprof-mail-followed">Új hozzászólás a követett szálaimban</label>
|
||||
<select
|
||||
id="fprof-mail-followed"
|
||||
className="inp"
|
||||
value={email.followed}
|
||||
onChange={(e) => setEmail({ ...email, followed: e.target.value as EmailSettings["followed"] })}
|
||||
>
|
||||
<option value="off">Ne küldjetek</option>
|
||||
<option value="daily">Napi összesítőben, este</option>
|
||||
</select>
|
||||
<label htmlFor="fprof-mail-messages">Privát üzenet vagy beszélgetési kérés</label>
|
||||
<select
|
||||
id="fprof-mail-messages"
|
||||
className="inp"
|
||||
value={email.messages}
|
||||
onChange={(e) => setEmail({ ...email, messages: e.target.value as EmailSettings["messages"] })}
|
||||
>
|
||||
<option value="instant">Azonnal</option>
|
||||
<option value="off">Ne küldjetek</option>
|
||||
</select>
|
||||
</div>
|
||||
<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.
|
||||
</span>
|
||||
</fieldset>
|
||||
|
||||
{member && (
|
||||
<div className="fprof-rank">
|
||||
<span className="eyebrow">Rangod</span>
|
||||
|
||||
@@ -498,3 +498,8 @@ body:has(.forum[data-theme="light"]) .site-footer { background: #0d1220; }
|
||||
.fchat-msg .frep { width: min(420px, 86vw); }
|
||||
.fchat-compose { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
|
||||
@media (min-width: 760px) { .forum-nav .fn-item { padding: 0 12px; } }
|
||||
|
||||
/* --- e-mail settings --- */
|
||||
.fprof-mail { display: grid; gap: 6px; }
|
||||
.fprof-mail label { font-size: 14px; font-weight: 500; margin-top: 8px; }
|
||||
.fprof-mail label:first-child { margin-top: 0; }
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
|
||||
import { api, errorText } from "@/lib/api";
|
||||
|
||||
export function ForumUnsubscribe({ token }: { token: string | null }) {
|
||||
const [state, setState] = useState<"idle" | "busy" | "done">("idle");
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
if (!token)
|
||||
return <p className="msg msg-error">Hiányzik a leiratkozó link vége. Nyisd meg újra a levélben lévő linket.</p>;
|
||||
|
||||
async function unsubscribe() {
|
||||
setState("busy");
|
||||
setError(null);
|
||||
try {
|
||||
await api(`/forum/unsubscribe?token=${encodeURIComponent(token ?? "")}`, { method: "POST" });
|
||||
setState("done");
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
setState("idle");
|
||||
}
|
||||
}
|
||||
|
||||
if (state === "done") {
|
||||
return (
|
||||
<p className="fh-banner">
|
||||
<span>
|
||||
Kész, a fórum nem küld több levelet. Ha meggondolod magad, a{" "}
|
||||
<Link href="/forum/beallitasok">fórumprofilodnál</Link> újra bekapcsolhatod.
|
||||
</span>
|
||||
</p>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
<button type="button" className="btn btn-primary" disabled={state === "busy"} onClick={unsubscribe}>
|
||||
{state === "busy" ? "Leiratkozás…" : "Leiratkozom a fórum leveleiről"}
|
||||
</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { ForumUnsubscribe } from "./ForumUnsubscribe";
|
||||
|
||||
export const metadata = { title: "Leiratkozás a fórum leveleiről", robots: { index: false } };
|
||||
|
||||
type Props = { searchParams: Promise<{ token?: string | string[] }> };
|
||||
|
||||
/** From the footer of a forum e-mail: every forum e-mail off, no login needed. */
|
||||
export default async function ForumUnsubscribePage({ searchParams }: Props) {
|
||||
const raw = (await searchParams).token;
|
||||
const token = Array.isArray(raw) ? raw[0] : raw;
|
||||
return (
|
||||
<div className="fh fprof">
|
||||
<h1 className="fpage-title">Leiratkozás</h1>
|
||||
<p className="muted">
|
||||
Nem kérsz több levelet a fórumról: se válaszértesítést, se napi összesítőt, se üzenetértesítést.
|
||||
</p>
|
||||
<ForumUnsubscribe token={token ?? null} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -119,6 +119,12 @@ export interface ThreadPage {
|
||||
};
|
||||
}
|
||||
|
||||
export interface EmailSettings {
|
||||
replies: "off" | "daily" | "instant";
|
||||
followed: "off" | "daily";
|
||||
messages: "off" | "instant";
|
||||
}
|
||||
|
||||
export interface ForumMe {
|
||||
viewer: ForumViewer;
|
||||
member: {
|
||||
@@ -136,6 +142,7 @@ export interface ForumMe {
|
||||
nickname_change_after: string | null;
|
||||
banned_until: string | null;
|
||||
ban_reason: string | null;
|
||||
email: EmailSettings;
|
||||
} | null;
|
||||
chart: Record<Exclude<ChartShare, "none">, Record<string, string> | null> | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user