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:
@@ -414,3 +414,66 @@ func TestAddressesAndThreadsCanBeErased(t *testing.T) {
|
||||
t.Fatalf("an erased conversation came back (%d)", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestABlockedConversationStaysSilentAndFreesNothingElse(t *testing.T) {
|
||||
f := newFixture(t, 1) // one new conversation per day
|
||||
l := f.listing()
|
||||
ref := message.Ref{Author: l.Author, ID: l.ID}
|
||||
var announced int
|
||||
f.in.OnArrivals = func(a []Arrival) { announced += len(a) }
|
||||
|
||||
spam := f.newThread()
|
||||
f.buyer(l, spam, 1, "Hallo", msgDifficulty)
|
||||
f.collect()
|
||||
if err := f.in.Block(ctx, ref, spam.PublicHex()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if th, _ := f.st.Threads(ctx, l.Author); len(th) != 0 {
|
||||
t.Fatal("the blocked conversation is still listed")
|
||||
}
|
||||
announced = 0
|
||||
|
||||
// The buyer keeps writing in the same thread: nothing is filed or announced.
|
||||
f.buyer(l, spam, 2, "Hallo?", msgDifficulty)
|
||||
f.buyer(l, spam, 3, "Antwortet bitte", msgDifficulty)
|
||||
if n := f.collect(); n != 0 || announced != 0 {
|
||||
t.Fatalf("a blocked thread got through: filed %d, announced %d", n, announced)
|
||||
}
|
||||
if th, _ := f.st.Threads(ctx, l.Author); len(th) != 0 {
|
||||
t.Fatal("a blocked thread reappeared")
|
||||
}
|
||||
|
||||
// Blocking is per thread: someone else (here under a new daily budget) is heard.
|
||||
f.now = f.now.Add(25 * time.Hour)
|
||||
other := f.newThread()
|
||||
f.buyer(l, other, 1, "Guten Tag", msgDifficulty)
|
||||
if n := f.collect(); n != 1 {
|
||||
t.Fatalf("another buyer was not heard: %d", n)
|
||||
}
|
||||
|
||||
// The block can be lifted; the buyer's later messages arrive again.
|
||||
if err := f.in.Unblock(ctx, ref, spam.PublicHex()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.now = f.now.Add(25 * time.Hour) // it starts a new conversation, which the daily limit applies to
|
||||
f.buyer(l, spam, 4, "Noch da?", msgDifficulty)
|
||||
f.collect()
|
||||
if th, _ := f.st.Threads(ctx, l.Author); len(th) != 2 {
|
||||
t.Fatalf("after unblocking, %d conversations, want 2", len(th))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockingNeedsAnExistingConversationOfYours(t *testing.T) {
|
||||
f := newFixture(t, 0)
|
||||
l := f.listing()
|
||||
tk := f.newThread()
|
||||
if err := f.in.Block(ctx, message.Ref{Author: l.Author, ID: l.ID}, tk.PublicHex()); !errors.Is(err, ErrNoThread) {
|
||||
t.Fatalf("blocking an unknown thread: %v", err)
|
||||
}
|
||||
if err := f.in.Block(ctx, message.Ref{Author: "someone-else", ID: l.ID}, tk.PublicHex()); !errors.Is(err, ErrNotOwner) {
|
||||
t.Fatalf("blocking another author's listing: %v", err)
|
||||
}
|
||||
if err := f.in.Unblock(ctx, message.Ref{Author: l.Author, ID: l.ID}, tk.PublicHex()); !errors.Is(err, ErrNoThread) {
|
||||
t.Fatalf("unblocking a thread that is not blocked: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user