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:
@@ -237,3 +237,67 @@ func (s *Store) DeleteAddress(ctx context.Context, ref message.Ref) error {
|
||||
`DELETE FROM addresses WHERE author = ? AND listing_id = ?`, ref.Author, ref.ID)
|
||||
return err
|
||||
}
|
||||
|
||||
// BlockThread erases a conversation and remembers its thread key, so the
|
||||
// envelopes the buyer keeps sending are dropped unread. It reports whether the
|
||||
// conversation existed; blocking an unknown thread does nothing.
|
||||
func (s *Store) BlockThread(ctx context.Context, ref message.Ref, thread string, now int64) (bool, error) {
|
||||
tx, err := s.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
res, err := tx.ExecContext(ctx,
|
||||
`DELETE FROM inbox WHERE author = ? AND listing_id = ? AND thread = ?`, ref.Author, ref.ID, thread)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
if n == 0 {
|
||||
return false, nil
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx, `
|
||||
INSERT OR IGNORE INTO inbox_blocked (author, listing_id, thread, blocked_at) VALUES (?, ?, ?, ?)`,
|
||||
ref.Author, ref.ID, thread, now); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, tx.Commit()
|
||||
}
|
||||
|
||||
// UnblockThread lifts a block. What was sent while blocked is gone.
|
||||
func (s *Store) UnblockThread(ctx context.Context, ref message.Ref, thread string) (bool, error) {
|
||||
res, err := s.db.ExecContext(ctx,
|
||||
`DELETE FROM inbox_blocked WHERE author = ? AND listing_id = ? AND thread = ?`, ref.Author, ref.ID, thread)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
n, _ := res.RowsAffected()
|
||||
return n > 0, nil
|
||||
}
|
||||
|
||||
// Blocked is one blocked conversation.
|
||||
type Blocked struct {
|
||||
Listing message.Ref
|
||||
Thread string
|
||||
BlockedAt int64
|
||||
}
|
||||
|
||||
// BlockedThreads lists the author's blocked conversations, newest first.
|
||||
func (s *Store) BlockedThreads(ctx context.Context, author string) ([]Blocked, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `
|
||||
SELECT listing_id, thread, blocked_at FROM inbox_blocked WHERE author = ?
|
||||
ORDER BY blocked_at DESC, thread`, author)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var out []Blocked
|
||||
for rows.Next() {
|
||||
b := Blocked{Listing: message.Ref{Author: author}}
|
||||
if err := rows.Scan(&b.Listing.ID, &b.Thread, &b.BlockedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, b)
|
||||
}
|
||||
return out, rows.Err()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user