messaging: owners can block a conversation

A blocked thread key is dropped unread (not announced, not counted against
the daily new-conversation limit). API, UI button with confirmation, and a
list with unblock.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 20:50:38 +01:00
co-authored by Claude Sonnet 5.5
parent a54094ea35
commit 13c82f8d59
14 changed files with 433 additions and 3 deletions
+45
View File
@@ -2,6 +2,7 @@ package api
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
@@ -399,6 +400,50 @@ func (s *server) deleteThread(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}
func (s *server) blockThread(w http.ResponseWriter, r *http.Request) {
s.blockOrUnblock(w, r, s.Inbox.Block)
}
func (s *server) unblockThread(w http.ResponseWriter, r *http.Request) {
s.blockOrUnblock(w, r, s.Inbox.Unblock)
}
func (s *server) blockOrUnblock(w http.ResponseWriter, r *http.Request, do func(context.Context, message.Ref, string) error) {
ref, thread, ok := s.threadRef(w, r)
if !ok {
return
}
switch err := do(r.Context(), ref, thread); {
case err == nil:
w.WriteHeader(http.StatusNoContent)
case errors.Is(err, inbox.ErrNoThread), errors.Is(err, inbox.ErrNotOwner):
fail(w, http.StatusNotFound, "no such conversation")
default:
fail(w, http.StatusInternalServerError, "internal error")
}
}
type blockedView struct {
Listing string `json:"listing"`
Thread string `json:"thread"`
BlockedAt int64 `json:"blocked_at"`
}
// listBlocked lists the conversations the owner blocked, so a block can be lifted.
func (s *server) listBlocked(w http.ResponseWriter, r *http.Request) {
bs, err := s.Store.BlockedThreads(r.Context(), s.Device.Cert.Author)
if err != nil {
fail(w, http.StatusInternalServerError, "internal error")
return
}
out := make([]blockedView, 0, len(bs))
for _, b := range bs {
out = append(out, blockedView{Listing: b.Listing.ID, Thread: b.Thread, BlockedAt: b.BlockedAt})
}
noStore(w)
writeJSON(w, http.StatusOK, out)
}
// threadRef reads {id} and {thread} from the path. The listing is always the
// node's own: the inbox holds nobody else's conversations.
func (s *server) threadRef(w http.ResponseWriter, r *http.Request) (message.Ref, string, bool) {