Benachrichtigungen: Handle bei Antworten, neu auch Reposts
Bei Antworten steht statt "Jemand" der Handle. Damit er nach einer Umbenennung stimmt, speichert die Benachrichtigung nur die uid (actor) und den Auszug; den Text setzt der Abruf zusammen. Die Tabelle war noch nirgends ausgerollt, daher direkt in neuer Form statt per ALTER. Neu ist der Repost eines eigenen Beitrags (kind bump), in derselben Transaktion wie der Bump. Wer repostet, wird nicht gespeichert, die Meldung sagt daher "Jemand". Eigene Reposts lösen nichts aus. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,7 +47,7 @@ func TestNotifyReply(t *testing.T) {
|
||||
t.Fatalf("liste: %+v", list)
|
||||
}
|
||||
n := list.Notifications[0]
|
||||
wantMsg := "Jemand hat auf deinen Beitrag geantwortet. (" + strings.TrimSpace(long[:50]) + "…)"
|
||||
wantMsg := "@bob hat auf deinen Beitrag geantwortet. (" + strings.TrimSpace(long[:50]) + "…)"
|
||||
if n.Kind != "reply" || n.Link != fmt.Sprintf("/e/%d", answer) || n.Seen || n.Message != wantMsg {
|
||||
t.Errorf("benachrichtigung: %+v", n)
|
||||
}
|
||||
@@ -60,13 +60,16 @@ func TestNotifyReply(t *testing.T) {
|
||||
t.Error("zweiter Abruf: nicht als gesehen markiert")
|
||||
}
|
||||
|
||||
// Bearbeiten zieht den Auszug nach, Löschen nimmt die Benachrichtigung mit.
|
||||
// Bearbeiten zieht den Auszug nach, ein neuer Handle erscheint sofort,
|
||||
// Löschen nimmt die Benachrichtigung mit.
|
||||
editURL := fmt.Sprintf("%s/api/entry/%d/edit", srv.URL, answer)
|
||||
resp := postForm(t, bob, editURL, url.Values{"content": {"neu"}})
|
||||
resp.Body.Close()
|
||||
resp = postForm(t, bob, srv.URL+"/api/user/handle", url.Values{"handle": {"robert"}})
|
||||
resp.Body.Close()
|
||||
getAs(t, alice, srv.URL+"/api/notifications", &list)
|
||||
if got := list.Notifications[0].Message; got != "Jemand hat auf deinen Beitrag geantwortet. (neu)" {
|
||||
t.Errorf("nach dem Bearbeiten: %q", got)
|
||||
if got := list.Notifications[0].Message; got != "@robert hat auf deinen Beitrag geantwortet. (neu)" {
|
||||
t.Errorf("nach Bearbeiten und Umbenennen: %q", got)
|
||||
}
|
||||
resp = postForm(t, bob, fmt.Sprintf("%s/api/entry/%d/delete", srv.URL, answer), nil)
|
||||
resp.Body.Close()
|
||||
@@ -76,6 +79,37 @@ func TestNotifyReply(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotifyBump(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := newTestServer(t)
|
||||
alice := registerAndLogin(t, srv, "alice")
|
||||
bob := registerAndLogin(t, srv, "bob")
|
||||
mine := createEntry(t, alice, srv, post("mein erster\nbeitrag"))
|
||||
own := createEntry(t, alice, srv, post("selbst repostet"))
|
||||
|
||||
for _, b := range []struct {
|
||||
c *http.Client
|
||||
pid int64
|
||||
}{{bob, mine}, {alice, own}} {
|
||||
resp := postForm(t, b.c, fmt.Sprintf("%s/api/entry/%d/bump", srv.URL, b.pid), nil)
|
||||
resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("bump %d: status %d", b.pid, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
var list notificationList
|
||||
getAs(t, alice, srv.URL+"/api/notifications", &list)
|
||||
if len(list.Notifications) != 1 {
|
||||
t.Fatalf("liste: %+v", list.Notifications)
|
||||
}
|
||||
n := list.Notifications[0]
|
||||
// Wer repostet, wird nicht gespeichert: "Jemand", auch wenn es bob war.
|
||||
if n.Kind != "bump" || n.Link != fmt.Sprintf("/e/%d", mine) ||
|
||||
n.Message != "Jemand hat deinen Beitrag repostet. (mein erster beitrag)" {
|
||||
t.Errorf("benachrichtigung: %+v", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotificationsNeedLogin(t *testing.T) {
|
||||
t.Parallel()
|
||||
srv := newTestServer(t)
|
||||
|
||||
Reference in New Issue
Block a user