Remove legacy question storage #7

Merged
codegirl007 merged 3 commits from remove-legacy-post-storage into app 2026-08-27 16:17:58 +00:00
2 changed files with 27 additions and 5 deletions
Showing only changes of commit 17e73ad2d3 - Show all commits
+10 -4
View File
@@ -93,7 +93,8 @@ func (s *Server) handleCreatePost(w http.ResponseWriter, r *http.Request) {
)
}
// notifyPostReply asynchronously emails the direct parent post's author.
// notifyPostReply emails the root homeowner for admin replies and the direct
// parent author for homeowner replies.
func (s *Server) notifyPostReply(
parent *store.Post,
root *store.Post,
@@ -104,13 +105,19 @@ func (s *Server) notifyPostReply(
root == nil ||
reply == nil ||
replyAuthor == nil ||
s.cfg.Mail == nil ||
parent.AuthorID == replyAuthor.ID {
s.cfg.Mail == nil {
return
}
if _, disabled := s.cfg.Mail.(mail.Nop); disabled {
return
}
recipientID := parent.AuthorID
if replyAuthor.Admin() {
recipientID = root.AuthorID
}
if recipientID == replyAuthor.ID {
return
}
msg := mail.PostReply{
RootID: root.ID,
RootTitle: root.Title,
@@ -118,7 +125,6 @@ func (s *Server) notifyPostReply(
ReplyBody: reply.Body,
ReplyAuthorName: replyAuthor.Name,
}
recipientID := parent.AuthorID
go func() {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
+17 -1
View File
@@ -334,6 +334,22 @@ func TestPostReplyNotifications(t *testing.T) {
t.Fatalf("homeowner reply notification = %+v", msg)
}
rec = postForm(handler, "/posts", url.Values{
"_csrf": {adminCSRF},
"parent_id": {adminReply.ID},
"body": {"One more plumber detail."},
}, adminCookies)
if rec.Code != http.StatusSeeOther {
t.Fatalf("nested admin reply status = %d: %s", rec.Code, rec.Body.String())
}
msgs = waitForMail(t, recording, 3)
if msg := msgs[2]; msg.ToEmail != homeowner.Email ||
msg.RootID != root.ID ||
msg.ReplyBody != "One more plumber detail." ||
msg.ReplyAuthorName != admin.Name {
t.Fatalf("nested admin reply notification = %+v", msg)
}
rec = postForm(handler, "/posts", url.Values{
"_csrf": {homeownerCSRF},
"parent_id": {root.ID},
@@ -376,7 +392,7 @@ func TestPostReplyNotifications(t *testing.T) {
t.Fatalf("no-email reply status = %d: %s", rec.Code, rec.Body.String())
}
time.Sleep(50 * time.Millisecond)
if recording.Len() != 2 {
if recording.Len() != 3 {
t.Fatalf("self, edit, or no-email action sent a notification: %+v", recording.Snapshot())
}
}