Forum: daily sky thread, listeners, mentions, own avatars, restricted topics
- The worker opens a "Mai égbolt" thread every morning from the day's sky (no AI), pinned for the day. - Volunteer listeners (from the Kereső rank) get a badge, a count of the threads asking to be heard that still wait for a reply, and, if they ask, an e-mail after two hours of waiting. - "@Holdfény" names a member (nicknames with spaces too): they follow the thread, hear of it live and, if they asked, by e-mail; a search helps typing it. - From the Kereső rank a member may upload an own avatar: a small square JPEG without metadata in the object storage (now a shared crate with the backend), served by the forum; moderators can put the starter back. - The "Támogató" badge for buyers who switch it on. - The admin creates and edits topics; restricted ones are read by their approved members, who ask to join and moderators decide. - "Most itt vannak" on the front page; the weekly summary e-mail on Sunday evening for those who ask (off by default). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -187,6 +187,9 @@ pub fn render(template: &str, locale: &str, payload: &Value) -> Result<Rendered,
|
||||
("forum_digest", _) => forum_digest(payload, url)?,
|
||||
("forum_message", _) => forum_message(payload, url)?,
|
||||
("forum_moderation", _) => forum_moderation(payload, url)?,
|
||||
("forum_mention", _) => forum_mention(payload, url)?,
|
||||
("forum_listener", _) => forum_listener(payload, url)?,
|
||||
("forum_weekly", _) => forum_weekly(payload, url)?,
|
||||
("forum_report_result", _) => forum_report_result(payload, url)?,
|
||||
_ => return Err(TemplateError::UnknownTemplate(template.to_owned())),
|
||||
};
|
||||
@@ -361,6 +364,90 @@ fn forum_reply(payload: &Value, url: String) -> Result<Content, TemplateError> {
|
||||
forum_footer(payload, content, "a fórumon azonnali értesítést kértél a válaszokról")
|
||||
}
|
||||
|
||||
/// Someone named the member ("@Holdfény") in a post.
|
||||
fn forum_mention(payload: &Value, url: String) -> Result<Content, TemplateError> {
|
||||
let author = name(payload, "author").unwrap_or_else(|| "Valaki".into());
|
||||
let title = name(payload, "thread_title").ok_or(TemplateError::MissingField("thread_title"))?;
|
||||
let content = Content {
|
||||
subject: format!("{author} megemlített: „{title}”"),
|
||||
preheader: excerpt(payload, "excerpt", 90),
|
||||
greeting: hello(payload),
|
||||
intro: format!("{author} megemlített a Sorsfonalak fórumán, a(z) „{title}” szálban:"),
|
||||
quote: excerpt(payload, "excerpt", 300),
|
||||
points: None,
|
||||
code: None,
|
||||
button: "Megnézem",
|
||||
url,
|
||||
note: "Az említésekről szóló leveleket a fórumprofilodnál kapcsolhatod ki.".into(),
|
||||
reason: None,
|
||||
unsubscribe: None,
|
||||
unsubscribe_post_url: None,
|
||||
};
|
||||
forum_footer(payload, content, "a fórumon értesítést kértél, ha megemlítenek")
|
||||
}
|
||||
|
||||
/// For a volunteer listener: a thread asking to be heard waits for a reply.
|
||||
fn forum_listener(payload: &Value, url: String) -> Result<Content, TemplateError> {
|
||||
let title = name(payload, "thread_title").ok_or(TemplateError::MissingField("thread_title"))?;
|
||||
let content = Content {
|
||||
subject: format!("Válaszra vár: „{title}”"),
|
||||
preheader: Some("Valaki meghallgatást kért, és még senki nem válaszolt.".into()),
|
||||
greeting: hello(payload),
|
||||
intro: format!(
|
||||
"A(z) „{title}” szálban valaki meghallgatást kért, és még senki nem válaszolt neki. Ha van rá időd, egy pár soros válasz is sokat jelenthet."
|
||||
),
|
||||
quote: None,
|
||||
points: None,
|
||||
code: None,
|
||||
button: "Elolvasom",
|
||||
url,
|
||||
note: "Tanács helyett elég, ha leírod, hogy itt vagy, vagy hogy veled is történt hasonló.".into(),
|
||||
reason: None,
|
||||
unsubscribe: None,
|
||||
unsubscribe_post_url: None,
|
||||
};
|
||||
forum_footer(payload, content, "önkéntes meghallgatóként értesítést kértél a válasz nélküli szálakról")
|
||||
}
|
||||
|
||||
/// The weekly summary: the busiest threads, and those still waiting.
|
||||
fn forum_weekly(payload: &Value, url: String) -> Result<Content, TemplateError> {
|
||||
let lines = |key: &'static str| -> Vec<String> {
|
||||
payload[key]
|
||||
.as_array()
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|l| l.as_str())
|
||||
.map(|l| l.chars().filter(|c| !c.is_control()).take(160).collect())
|
||||
.collect()
|
||||
};
|
||||
let busy = lines("busy");
|
||||
let waiting = lines("waiting");
|
||||
if busy.is_empty() && waiting.is_empty() {
|
||||
return Err(TemplateError::MissingField("busy"));
|
||||
}
|
||||
let mut items = busy;
|
||||
if !waiting.is_empty() {
|
||||
items.push("Még válaszra vár:".into());
|
||||
items.extend(waiting.into_iter().map(|w| format!(" {w}")));
|
||||
}
|
||||
let content = Content {
|
||||
subject: "A hét a fórumon".into(),
|
||||
preheader: items.first().cloned(),
|
||||
greeting: hello(payload),
|
||||
intro: "Ezekről beszélgettünk a héten a Sorsfonalak fórumán:".into(),
|
||||
quote: None,
|
||||
points: Some(("A hét szálai:", items)),
|
||||
code: None,
|
||||
button: "Benézek a fórumra",
|
||||
url,
|
||||
note: "Hetente egyszer, vasárnap este küldjük, ha kérted.".into(),
|
||||
reason: None,
|
||||
unsubscribe: None,
|
||||
unsubscribe_post_url: None,
|
||||
};
|
||||
forum_footer(payload, content, "a fórumon heti összefoglalót kértél")
|
||||
}
|
||||
|
||||
/// The daily digest: the threads with new posts for the member.
|
||||
fn forum_digest(payload: &Value, url: String) -> Result<Content, TemplateError> {
|
||||
let lines: Vec<String> = payload["lines"]
|
||||
@@ -1367,5 +1454,18 @@ mod tests {
|
||||
let m = render("forum_report_result", "hu", &json!({"url": "u", "outcome": "no_violation"})).unwrap();
|
||||
assert!(m.text.starts_with("Szia!") && m.text.contains("a tartalom marad"));
|
||||
assert!(render("forum_report_result", "hu", &json!({"url": "u"})).is_err());
|
||||
|
||||
let mut p = forum_links();
|
||||
p["author"] = json!("Zöldág");
|
||||
p["thread_title"] = json!("Téli levesek");
|
||||
p["excerpt"] = json!("@Csendesvíz szerinted?");
|
||||
assert_eq!(render("forum_mention", "hu", &p).unwrap().subject, "Zöldág megemlített: „Téli levesek”");
|
||||
let m = render("forum_listener", "hu", &p).unwrap();
|
||||
assert_eq!(m.subject, "Válaszra vár: „Téli levesek”");
|
||||
let mut p = forum_links();
|
||||
p["busy"] = json!(["„Téli levesek” – 12 hozzászólás"]);
|
||||
p["waiting"] = json!(["„Nehéz napok”"]);
|
||||
let m = render("forum_weekly", "hu", &p).unwrap();
|
||||
assert!(m.text.contains("Még válaszra vár") && m.unsubscribe_post_url.is_some());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user