Weekly horoscope landing page, link previews for the forum, and fixes from the review
CI / test (push) Successful in 3m19s
CI / build (push) Skipped
CI / deploy (push) Skipped

- /heti-horoszkop for visitors: what it is, a real example written for the
  example chart, login and sign-up buttons; its own link preview image.
- Forum: link previews (image, title; a public thread's opening words) for
  every forum page; none of a members-only thread's content.
- Review fixes: a removed thread's photos are no longer served; public photos
  are cached for an hour, not a year (removals take effect); photos of threads
  removed a year ago are cleaned up; deleting one forum question no longer
  revokes the chart link another question still shows; the daily digest
  leaves out closed topics the member is no longer in; typing notices at most
  one a second per connection; the weekly page asks for the text once and
  then only reads it (no repeated paid runs after a failure); turning the
  Monday e-mail back on from the e-mail page waits for next Monday, like the
  site's switch; the week's last day is right in the week the clocks go back.

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-27 10:12:27 +00:00
co-authored by Claude Opus 5.5
parent 0358e137f1
commit b37094e481
24 changed files with 461 additions and 90 deletions
+2 -5
View File
@@ -105,11 +105,8 @@ pub async fn put_settings(
}
}
let mut tx = state.db.begin().await?;
sqlx::query("UPDATE users SET weekly_email = $2, updated_at = now() WHERE id = $1")
.bind(user)
.bind(req.weekly_horoscope)
.execute(&mut *tx)
.await?;
// As the switch on the site: turned on again, the first one comes next Monday.
sqlx::query(&super::weekly::switch_sql()).bind(user).bind(req.weekly_horoscope).execute(&mut *tx).await?;
if let Some(f) = &req.forum {
sqlx::query(
"UPDATE forum.members SET email_replies = $2, email_followed = $3, email_messages = $4, \
+15 -12
View File
@@ -24,7 +24,7 @@ use crate::auth::AuthUser;
use crate::error::{ApiError, ApiResult};
/// The Monday of the current week in Hungary.
const THIS_MONDAY: &str = "SELECT date_trunc('week', now() AT TIME ZONE 'Europe/Budapest')::date";
pub(super) const THIS_MONDAY: &str = "SELECT date_trunc('week', now() AT TIME ZONE 'Europe/Budapest')::date";
/// What a weekly text is about, for its cache key: the chart and the week.
pub fn target_hash(chart_hash: &str, week_start: &str) -> String {
@@ -184,22 +184,25 @@ pub struct EmailSwitch {
/// Turns Monday's e-mail on or off. Turned on, the first one comes next
/// Monday (this week's horoscope is already in front of the member).
pub(super) fn switch_sql() -> String {
// Only a change from off to on moves the date: saving "on" again must not
// hold back this Monday's e-mail.
format!(
"UPDATE users SET \
weekly_email_sent_on = CASE WHEN $2 AND NOT weekly_email \
THEN greatest(weekly_email_sent_on, ({THIS_MONDAY})) \
ELSE weekly_email_sent_on END, \
weekly_email = $2, updated_at = now() \
WHERE id = $1"
)
}
pub async fn set_email(
State(state): St,
auth: AuthUser,
WithRejection(Json(req), _): Body<EmailSwitch>,
) -> ApiResult<Json<Value>> {
sqlx::query(&format!(
"UPDATE users SET weekly_email = $2, \
weekly_email_sent_on = CASE WHEN $2 THEN greatest(weekly_email_sent_on, ({THIS_MONDAY})) \
ELSE weekly_email_sent_on END, \
updated_at = now() \
WHERE id = $1"
))
.bind(auth.id())
.bind(req.on)
.execute(&state.db)
.await?;
sqlx::query(&switch_sql()).bind(auth.id()).bind(req.on).execute(&state.db).await?;
Ok(Json(json!({ "email": req.on })))
}
+24 -1
View File
@@ -2093,8 +2093,31 @@ async fn weekly_horoscope_of_the_own_chart(pool: PgPool) {
let off = json!({"replies": "off", "followed": "off", "messages": "off", "mentions": "off", "listener": null, "weekly": false});
let r = app.call("PUT", &page, None, Some(json!({"weekly_horoscope": false, "forum": off}))).await;
assert_eq!((r.status, &r.body["weekly_horoscope"], &r.body["forum"]), (StatusCode::OK, &json!(false), &off));
// The mail client's one-click unsubscribe turns off the weekly e-mail only.
// Turned on again from this page: as on the site, the first one comes next Monday.
sqlx::query("UPDATE users SET weekly_email_sent_on = NULL WHERE email = 'anna@example.com'")
.execute(&pool)
.await
.unwrap();
app.call("PUT", &page, None, Some(json!({"weekly_horoscope": true}))).await;
let sent_on: Option<time::Date> =
sqlx::query_scalar("SELECT weekly_email_sent_on FROM users WHERE email = 'anna@example.com'")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(sent_on, Some(start));
// Saved again while on: this Monday's e-mail is not held back.
sqlx::query("UPDATE users SET weekly_email_sent_on = NULL WHERE email = 'anna@example.com'")
.execute(&pool)
.await
.unwrap();
app.call("PUT", &page, None, Some(json!({"weekly_horoscope": true}))).await;
let sent_on: Option<time::Date> =
sqlx::query_scalar("SELECT weekly_email_sent_on FROM users WHERE email = 'anna@example.com'")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(sent_on, None);
// The mail client's one-click unsubscribe turns off the weekly e-mail only.
let r = app.call("POST", &format!("/v1/public/weekly/unsubscribe?token={token}"), None, None).await;
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
assert_eq!(app.get(&page, None).await.body["weekly_horoscope"], false);