Documentation
¶
Index ¶
- func NewChatBlocklistReader(store Store) chat.BlocklistReader
- type BlockedUser
- type Cursor
- type Server
- func (s *Server) BlockUser(ctx context.Context, req *blocklistpb.BlockUserRequest) (*blocklistpb.BlockUserResponse, error)
- func (s *Server) GetBlocklist(ctx context.Context, req *blocklistpb.GetBlocklistRequest) (*blocklistpb.GetBlocklistResponse, error)
- func (s *Server) IsBlocked(ctx context.Context, req *blocklistpb.IsBlockedRequest) (*blocklistpb.IsBlockedResponse, error)
- func (s *Server) UnblockUser(ctx context.Context, req *blocklistpb.UnblockUserRequest) (*blocklistpb.UnblockUserResponse, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewChatBlocklistReader ¶
func NewChatBlocklistReader(store Store) chat.BlocklistReader
NewChatBlocklistReader returns a chat.BlocklistReader backed by the given blocklist store, for wiring the Chat service.
Types ¶
type BlockedUser ¶
BlockedUser is one entry in a user's blocklist: a blocked user and the time they were blocked.
It holds only the state owned by the blocklist domain. The richer profile of the blocked user (display name, picture, ...) lives in other domains and is not carried here; the proto surface intentionally exposes only the identity and the blocked-at timestamp.
func (*BlockedUser) Clone ¶
func (b *BlockedUser) Clone() *BlockedUser
Clone returns a deep copy of the entry.
func (*BlockedUser) ToProto ¶
func (b *BlockedUser) ToProto() *blocklistpb.BlockedUser
ToProto projects the entry onto a blocklistpb.BlockedUser.
type Cursor ¶
Cursor marks a position within a blocklist read. The next page resumes at the entry immediately after (BlockedAt, UserID) in the list's descending (blocked_at, user_id) order.
type Server ¶
type Server struct {
blocklistpb.UnimplementedBlocklistServer
// contains filtered or unexported fields
}
func (*Server) BlockUser ¶
func (s *Server) BlockUser(ctx context.Context, req *blocklistpb.BlockUserRequest) (*blocklistpb.BlockUserResponse, error)
func (*Server) GetBlocklist ¶
func (s *Server) GetBlocklist(ctx context.Context, req *blocklistpb.GetBlocklistRequest) (*blocklistpb.GetBlocklistResponse, error)
func (*Server) IsBlocked ¶
func (s *Server) IsBlocked(ctx context.Context, req *blocklistpb.IsBlockedRequest) (*blocklistpb.IsBlockedResponse, error)
func (*Server) UnblockUser ¶
func (s *Server) UnblockUser(ctx context.Context, req *blocklistpb.UnblockUserRequest) (*blocklistpb.UnblockUserResponse, error)
type Store ¶
type Store interface {
// Block adds blockedID to ownerID's blocklist, recording blockedAt as the
// time it was blocked. Blocking a user already on the list is a no-op that
// preserves the existing entry (and its original blocked_at). It reports
// whether a new entry was added.
Block(ctx context.Context, ownerID, blockedID *commonpb.UserId, blockedAt time.Time) (added bool, err error)
// Unblock removes blockedID from ownerID's blocklist. Removing a user that
// is not on the list is a no-op. It reports whether an entry was removed.
Unblock(ctx context.Context, ownerID, blockedID *commonpb.UserId) (removed bool, err error)
// IsBlocked reports whether blockedID is on ownerID's blocklist.
IsBlocked(ctx context.Context, ownerID, blockedID *commonpb.UserId) (bool, error)
// GetBlockedCount returns the number of users on ownerID's blocklist. It is a
// maintained aggregate, not a scan, so it is a cheap O(1) read intended as a
// signal for sizing a read strategy (e.g. a range scan while small, a cached
// set once large). An owner who has blocked no one reports 0.
GetBlockedCount(ctx context.Context, ownerID *commonpb.UserId) (int, error)
// GetBlocked returns which of candidateIDs are on ownerID's blocklist, as a
// set keyed by string(userID.Value): a candidate is present (value true) iff
// ownerID has blocked it. Candidates that are not blocked — along with
// duplicate or empty input — are simply absent from the map.
//
// It is the batch form of IsBlocked, for checking one owner against many
// candidates in a single round trip (e.g. resolving hidden state for a page of
// DM peers) rather than a lookup per candidate.
GetBlocked(ctx context.Context, ownerID *commonpb.UserId, candidateIDs []*commonpb.UserId) (map[string]bool, error)
// GetBlocklistPage returns one page of ownerID's blocklist ordered by
// (blocked_at, user_id) descending (most recently blocked first), at most
// limit entries (limit <= 0 means unbounded). When cursor is nil the page
// starts at the most recently blocked entry; otherwise it resumes strictly
// after cursor. An empty result (no error) is returned when no entries
// remain.
//
// Unlike a chat feed, a blocklist entry's sort key (blocked_at) never
// changes once written, so a multi-page read needs no snapshot watermark: an
// entry can neither move within the ordering nor be duplicated across pages.
// Newly-blocked users sort above any cursor and simply do not appear until
// the list is read afresh.
GetBlocklistPage(ctx context.Context, ownerID *commonpb.UserId, cursor *Cursor, limit int) ([]*BlockedUser, error)
}
Store persists each user's blocklist: the set of users they have blocked.
A blocklist is scoped to its owner (the blocker); ownerID keys every method. The only ordering exposed is most-recently-blocked first, so blocked_at is recorded per entry and is fixed at the time of blocking — re-blocking an already-blocked user preserves the original blocked_at (see Block).