favorites

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package favorites owns per-viewer favorite identities.

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("favorites: viewer or subject unavailable")

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Subject Subject
	AddedAt time.Time
}

type Kind

type Kind string
const (
	KindTitle      Kind = "title"
	KindPerson     Kind = "person"
	KindCollection Kind = "collection"
	KindChannel    Kind = "channel"
)

type Options

type Options struct {
	DB            *sql.DB
	Active        func(context.Context, int64) (*core.User, error)
	Allowed       func(context.Context, *core.User, Subject) bool
	AllowedTitles func(context.Context, *core.User, []core.RatingKey) (bool, error)
	Changed       func(context.Context, int64, Subject)
	Now           func() time.Time
	Marked        core.TransactionalMarkedPlaylists
}

Options requires Marked to use the same DB as DB, so playlist creation and favorite mutations share one transaction. Callbacks must recheck current access.

type Playlists

type Playlists struct {
	Base      core.Playlists
	Favorites *Service
	Marked    core.MarkedPlaylists
}

Playlists projects the marked Favorites playlist from the authoritative set. The underlying playlist contains no duplicated favorite item list.

func NewPlaylists

func NewPlaylists(base core.Playlists, favorites *Service) (*Playlists, error)

func (*Playlists) Add

func (p *Playlists) Add(ctx context.Context, uid int64, key core.RatingKey, items []core.RatingKey) error

func (*Playlists) Create

func (p *Playlists) Create(ctx context.Context, uid int64, title string, items []core.RatingKey) (*core.Playlist, error)

func (*Playlists) Delete

func (p *Playlists) Delete(ctx context.Context, uid int64, key core.RatingKey) error

func (*Playlists) Get

func (p *Playlists) Get(ctx context.Context, uid int64, key core.RatingKey) (*core.Playlist, error)

func (*Playlists) List

func (p *Playlists) List(ctx context.Context, uid int64) ([]core.Playlist, error)

func (*Playlists) Move

func (p *Playlists) Move(ctx context.Context, uid int64, key core.RatingKey, from, to int) error

func (*Playlists) Remove

func (p *Playlists) Remove(ctx context.Context, uid int64, key core.RatingKey, index int) error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(o Options) (*Service, error)

func (*Service) Generation

func (s *Service) Generation() uint64

Generation changes when a favorite is added or removed.

func (*Service) Has

func (s *Service) Has(ctx context.Context, viewer *core.User, subject Subject) (bool, error)

func (*Service) HasTitles

func (s *Service) HasTitles(ctx context.Context, viewer *core.User, keys []core.RatingKey) (map[core.RatingKey]bool, error)

HasTitles checks title membership in bounded batches, revalidating every subject.

func (*Service) List

func (s *Service) List(ctx context.Context, viewer *core.User, kind Kind, limit int) ([]Entry, error)

List returns permitted favorites newest first, without exposing hidden entries.

func (*Service) Membership

func (s *Service) Membership(ctx context.Context, viewer *core.User, subject Subject) (bool, *time.Time, error)

Membership reads one currently authorized favorite without scanning a list. AddedAt is the stored insertion time. It is nil for a stored record without a known positive timestamp, and it is not the title's date added.

func (*Service) MirrorEnabled

func (s *Service) MirrorEnabled(ctx context.Context, viewer *core.User) (bool, error)

SetMirror enables or disables the Plex projection without changing favorites. MirrorEnabled reports whether the viewer's Plex favorites mirror is enabled. Viewers without an explicit setting default to enabled.

func (*Service) MoveTitle

func (s *Service) MoveTitle(ctx context.Context, viewer *core.User, expected core.RatingKey, from, to int) error

MoveTitle preserves hidden entries while changing the ordering of visible titles.

func (*Service) Set

func (s *Service) Set(ctx context.Context, viewer *core.User, subject Subject, on bool) (bool, error)

Set changes one favorite; repeated identical writes emit no event.

func (*Service) SetMany

func (s *Service) SetMany(ctx context.Context, viewer *core.User, subjects []Subject, on bool) ([]Subject, error)

SetMany validates the entire request before changing any favorite and commits all changes together. Repeated subjects and no-op writes emit no event.

func (*Service) SetMirror

func (s *Service) SetMirror(ctx context.Context, viewer *core.User, enabled bool) error

func (*Service) UpdatedAt

func (s *Service) UpdatedAt(ctx context.Context, viewerID int64) (time.Time, error)

UpdatedAt reports the latest title favorite or order change.

type Subject

type Subject struct {
	Kind Kind
	ID   string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL