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
+33
View File
@@ -428,3 +428,36 @@ func TestStatusReportsMessageDifficulty(t *testing.T) {
t.Fatalf("message_difficulty = %v", st["message_difficulty"])
}
}
func TestBlockingAConversationOverTheAPI(t *testing.T) {
f := newFixture(t, token)
l := f.publish(t)
tk := newThread(t)
f.send(t, buyerHello(t, l, tk, "Hallo"))
f.do(t, "GET", "/api/v1/inbox?listing="+l.ID, "", true) // collects
path := "/api/v1/inbox/" + l.ID + "/" + tk.PublicHex()
if code, _ := f.do(t, "PUT", path+"/block", "", false); code != 401 {
t.Fatalf("blocking without the token: %d", code)
}
if code, body := f.do(t, "PUT", path+"/block", "", true); code != 204 {
t.Fatalf("block: %d %s", code, body)
}
if code, _ := f.do(t, "GET", path, "", true); code != 404 {
t.Fatalf("a blocked conversation can still be read: %d", code)
}
var bl []blockedView
code, body := f.do(t, "GET", "/api/v1/blocked", "", true)
if code != 200 || json.Unmarshal(body, &bl) != nil || len(bl) != 1 || bl[0].Thread != tk.PublicHex() || bl[0].Listing != l.ID {
t.Fatalf("blocked list: %d %s", code, body)
}
if code, _ := f.do(t, "PUT", "/api/v1/inbox/"+l.ID+"/"+strings.Repeat("0", 64)+"/block", "", true); code != 404 {
t.Fatalf("blocking an unknown thread: %d", code)
}
if code, body := f.do(t, "DELETE", path+"/block", "", true); code != 204 {
t.Fatalf("unblock: %d %s", code, body)
}
if _, body := f.do(t, "GET", "/api/v1/blocked", "", true); string(bytes.TrimSpace(body)) != "[]" {
t.Fatalf("blocked list after unblocking: %s", body)
}
}