Aufräumen: Soft-Delete, Benachrichtigungsarten, Antwort-Structs, WebP

Das Soft-Delete-SQL stand zweimal (Beitrag löschen, Konto löschen) und
beide Stellen mussten dieselben Nebentabellen kennen; jetzt macht
softDeleteEntries das für eine WHERE-Bedingung, die Kontolöschung räumt
nur noch ab, was am Nutzer selbst hängt.

Die Benachrichtigungsarten waren an fünf Stellen als Literal im SQL und
im Go-Code; jetzt Konstanten, die als Parameter mitgehen. Antworten auf
Anlegen/Bearbeiten und sessioninfo sind Structs wie der Rest.

media: der Import von x/image/webp registriert den Decoder global, die
Sonderbehandlung in decodeChecked war daher tot und ihr Kommentar falsch
(SaveUpload nahm WebP längst an). Jetzt ein Import mit Kommentar, ein
Pfad für alle Formate.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 13:12:27 +01:00
co-authored by Claude Fable 5.1
parent a93e10956b
commit b2bb1f176f
8 changed files with 86 additions and 70 deletions
+17 -6
View File
@@ -18,6 +18,13 @@ const (
excerptRunes = 50
)
// Arten von Benachrichtigungen (Spalte notification.kind, Feld kind der API).
const (
kindReply = "reply" // Antwort auf einen eigenen Beitrag
kindMention = "mention" // in einem Beitrag erwähnt
kindBump = "bump" // eigener Beitrag repostet
)
// notificationJSON ist eine Benachrichtigung in der Liste. Seen meldet den
// Stand vor dem Abruf: so sieht die Liste, was neu war, obwohl der Abruf
// selbst alles als gesehen markiert.
@@ -41,6 +48,10 @@ func excerpt(content string) string {
return e
}
// entryLink ist der interne Pfad zu einem Beitrag, wie ihn eine
// Benachrichtigung trägt.
func entryLink(pid int64) string { return fmt.Sprintf("/e/%d", pid) }
// notificationMessage ist die Zeile, die sagt, was passiert ist. actor ist
// der Handle dessen, der geantwortet hat; leer (Reposts, unbekannt) heißt
// "Jemand". Den Auszug liefert die API getrennt.
@@ -50,9 +61,9 @@ func notificationMessage(kind, actor string) string {
who = "@" + actor
}
switch kind {
case "reply":
case kindReply:
return who + " hat auf deinen Beitrag geantwortet."
case "mention":
case kindMention:
return who + " hat dich erwähnt."
}
return who + " hat deinen Beitrag repostet."
@@ -64,9 +75,9 @@ func notificationMessage(kind, actor string) string {
func notifyReply(ctx context.Context, tx *sql.Tx, in newEntry, pid int64) error {
if _, err := tx.ExecContext(ctx,
`INSERT INTO notification (uid, kind, actor, excerpt, link, pid, created_at)
SELECT uid, 'reply', $1, $2, $3, $4, $5 FROM entry
SELECT uid, $7, $1, $2, $3, $4, $5 FROM entry
WHERE pid = $6 AND uid <> 0 AND uid <> $1`,
in.uid, excerpt(in.content), fmt.Sprintf("/e/%d", pid), pid, in.created, in.replyTo); err != nil {
in.uid, excerpt(in.content), entryLink(pid), pid, in.created, in.replyTo, kindReply); err != nil {
return fmt.Errorf("benachrichtigung anlegen: %w", err)
}
return nil
@@ -86,8 +97,8 @@ func notifyBump(ctx context.Context, tx *sql.Tx, pid, bumper, now int64) error {
}
if _, err := tx.ExecContext(ctx,
`INSERT INTO notification (uid, kind, excerpt, link, pid, created_at)
VALUES ($1, 'bump', $2, $3, $4, $5)`,
author, excerpt(content), fmt.Sprintf("/e/%d", pid), pid, now); err != nil {
VALUES ($1, $6, $2, $3, $4, $5)`,
author, excerpt(content), entryLink(pid), pid, now, kindBump); err != nil {
return fmt.Errorf("benachrichtigung anlegen: %w", err)
}
return nil