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:
+50
-1
@@ -133,6 +133,15 @@ func (i *Inbox) Collect(ctx context.Context) (int, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
blockedList, err := i.Store.BlockedThreads(ctx, i.Device.Cert.Author)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
blocked := map[threadKey]bool{}
|
||||
for _, b := range blockedList {
|
||||
blocked[threadKey{b.Listing, b.Thread}] = true
|
||||
}
|
||||
|
||||
var known []candidate
|
||||
fresh := map[threadKey][]candidate{}
|
||||
for k, e := range envs {
|
||||
@@ -148,9 +157,16 @@ func (i *Inbox) Collect(ctx context.Context) (int, error) {
|
||||
}
|
||||
continue
|
||||
}
|
||||
key := threadKey{e.Listing, p.Thread}
|
||||
if blocked[key] {
|
||||
// The owner blocked this conversation: drop it unread, count nothing.
|
||||
if err := i.Store.MarkSeen(ctx, h, e.ExpiresAt); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
continue
|
||||
}
|
||||
work, _ := e.Work()
|
||||
c := candidate{hash: h, env: e, plain: p, work: work}
|
||||
key := threadKey{e.Listing, p.Thread}
|
||||
exists, err := i.Store.HasThread(ctx, e.Listing, p.Thread)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -244,6 +260,39 @@ func (i *Inbox) file(ctx context.Context, c candidate) (hidden bool, err error)
|
||||
return hidden, err
|
||||
}
|
||||
|
||||
// Block erases a conversation and drops everything its thread key sends from
|
||||
// now on, without notice to the buyer. A buyer can start over with a new
|
||||
// thread key, which costs a first message (proof-of-work, link ban, the daily
|
||||
// new-conversation limit) again.
|
||||
func (i *Inbox) Block(ctx context.Context, ref message.Ref, thread string) error {
|
||||
if ref.Author != i.Device.Cert.Author {
|
||||
return ErrNotOwner
|
||||
}
|
||||
ok, err := i.Store.BlockThread(ctx, ref, thread, i.now().Unix())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return ErrNoThread
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unblock lifts a block. Envelopes that arrived while blocked are gone.
|
||||
func (i *Inbox) Unblock(ctx context.Context, ref message.Ref, thread string) error {
|
||||
if ref.Author != i.Device.Cert.Author {
|
||||
return ErrNotOwner
|
||||
}
|
||||
ok, err := i.Store.UnblockThread(ctx, ref, thread)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
return ErrNoThread
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reply is what the owner sends back.
|
||||
type Reply struct {
|
||||
Type string // message.TypeText or message.TypeGrant
|
||||
|
||||
Reference in New Issue
Block a user