Repository navigation
feat(notifications): announce new audiobooks and ebooks on server channels - #260
Conversation
…nnels Audiobook and ebook libraries previously never entered the Recently Added pipeline: availability detection only ran for TV/movie/mixed libraries and release_events only knew episode/movie kinds, so server channels (Discord/generic webhooks) could not announce new audiobooks or ebooks. Generalize the movie path into a flat-item-kind registry (internal/notifications/item_kind.go) driving availability detection, recording, channel toggles, payload rendering, test fixtures, and the admin backfill seeder. New kinds share a kind-discriminated item_availability table; movie_availability stays as-is. Channels gain notify_new_audiobooks/notify_new_ebooks toggles (default on, additive API fields) and embeds carry the author from item_people. Flood-safe by construction: existing libraries seed silently on their first post-upgrade full scan. Extract internal/librarykind to replace the is*LibraryType helper copies that had drifted across scanner, libraryingest, and metadata (metadata's movie check silently included mixed; now spelled explicitly). Co-Authored-By: Claude Fable 5 <[email protected]>
📝 WalkthroughWalkthroughThis PR introduces a shared ChangesAudiobook/Ebook notifications
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Ingest
participant AvailabilityDetector
participant ReleaseRepository
participant ServerChannelWorker
participant ServerChannelPayload
Ingest->>AvailabilityDetector: HandleIngestCompleted(kinds)
AvailabilityDetector->>AvailabilityDetector: iterate flatItemKinds, filter Selected
AvailabilityDetector->>ReleaseRepository: RecordItemAvailabilityForLibrary/ForPaths(kind)
ReleaseRepository-->>AvailabilityDetector: availability rows + release_events
ServerChannelWorker->>ServerChannelWorker: classify event via flatKindByString
ServerChannelWorker->>ServerChannelWorker: loadContentMeta (join author)
ServerChannelWorker->>ServerChannelPayload: GroupContentEvents(events, meta)
ServerChannelPayload-->>ServerChannelWorker: ContentGroup with Author
ServerChannelWorker->>ServerChannelWorker: dispatch Discord/generic payload
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
internal/notifications/server_channel_service.go (1)
274-311: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueHardcoded
EventKindMoviecheck undercuts the new registry abstraction.
sampleContentGroupsdecides whether to populateAuthorby checkingk.Kind != EventKindMovieinstead of a property on theflatItemKindregistry entry. This is the exact movie-special-casing pattern the PR's registry is meant to eliminate — a future flat kind without author metadata (or a future flat kind that does have it) will silently get the wrong sample fixture.Consider adding an explicit capability flag (e.g.,
HasAuthor bool) to theflatItemKindstruct initem_kind.goand branching on that instead of the kind constant.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/notifications/server_channel_service.go` around lines 274 - 311, The sample fixture logic in sampleContentGroups still special-cases EventKindMovie, which bypasses the new registry-based design. Add an explicit metadata capability on the flatItemKind entry in item_kind.go (for example, a HasAuthor flag) and use that property when deciding whether to set ContentMeta.Author in sampleContentGroups, so the fixture behavior follows the registry instead of hardcoded kind checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/librarykind/librarykind.go`:
- Around line 56-63: The IsTV helper in librarykind.go is missing the "shows"
alias, so update the switch in IsTV to treat "shows" the same as the other TV
equivalents. Make sure the normalize(libraryType) check includes "shows"
alongside "series", "tv", "show", and "tvshows" so the TV episode notification
flow recognizes it correctly.
---
Nitpick comments:
In `@internal/notifications/server_channel_service.go`:
- Around line 274-311: The sample fixture logic in sampleContentGroups still
special-cases EventKindMovie, which bypasses the new registry-based design. Add
an explicit metadata capability on the flatItemKind entry in item_kind.go (for
example, a HasAuthor flag) and use that property when deciding whether to set
ContentMeta.Author in sampleContentGroups, so the fixture behavior follows the
registry instead of hardcoded kind checks.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 5d36b7bd-d3e8-4db3-b6fe-8c7750a82446
📒 Files selected for processing (25)
internal/api/handlers/admin_server_channels.gointernal/libraryingest/executor.gointernal/librarykind/librarykind.gointernal/librarykind/librarykind_test.gointernal/metadata/worker.gointernal/notifications/availability_detector.gointernal/notifications/discord_embed_meta.gointernal/notifications/fanout_logic.gointernal/notifications/fanout_worker.gointernal/notifications/item_kind.gointernal/notifications/item_kind_test.gointernal/notifications/release_repo.gointernal/notifications/release_types.gointernal/notifications/server_channel_logic_test.gointernal/notifications/server_channel_payload.gointernal/notifications/server_channel_repo.gointernal/notifications/server_channel_service.gointernal/notifications/server_channel_types.gointernal/notifications/server_channel_worker.gointernal/notifications/system.gointernal/scanner/scanner.gointernal/scanner/scanner_test.gomigrations/sql/20260702033712_audiobook_ebook_notifications.sqlweb/src/api/types.tsweb/src/pages/admin-settings/ServerNotificationChannels.tsx
💤 Files with no reviewable changes (1)
- internal/scanner/scanner_test.go
| func IsTV(libraryType string) bool { | ||
| switch normalize(libraryType) { | ||
| case "series", "tv", "show", "tvshows": | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check whether "shows" (plural) is ever used/expected as a media_folders.type value
rg -niP '"shows"' --type=go --type=sql --type=ts
rg -niP "'shows'" -g '*.sql'Repository: Silo-Server/silo-server
Length of output: 161
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## librarykind.go outline\n'
ast-grep outline internal/librarykind/librarykind.go --view expanded || true
printf '\n## relevant call sites\n'
rg -n "IsTV\(|TV \|\| Mixed|folder\.Type|normalize\(" internal -g '*.go'
printf '\n## type/string variants across repo\n'
rg -n '\b(show|shows|series|tvshows|tv)\b' internal -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || trueRepository: Silo-Server/silo-server
Length of output: 50380
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,140p' internal/librarykind/librarykind.goRepository: Silo-Server/silo-server
Length of output: 2987
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## internal/librarykind/librarykind.go\n'
sed -n '1,140p' internal/librarykind/librarykind.go
printf '\n## call sites and related values\n'
rg -n "IsTV\(|TV \|\| Mixed|folder\.Type|normalize\(" internal -g '*.go' || true
printf '\n## tv/show variants across the repo\n'
rg -n '\b(show|shows|series|tvshows|tv)\b' internal -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || trueRepository: Silo-Server/silo-server
Length of output: 50380
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## folder.type / media_folders.type assignments and checks\n'
rg -n "folders\.type|media_folders\.type|folder\.Type|Type: *\"(series|tv|show|tvshows|movie|movies|audiobook|audiobooks|ebook|ebooks|podcast|podcasts|mixed|manga)\"" internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
printf '\n## direct mention of \"tvshows\" as a type\n'
rg -n '"tvshows"|'\''tvshows'\''|tvshows' internal db migrations -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
printf '\n## direct mention of \"shows\" as a type token (exact quoted)\n'
rg -n '"shows"|'\''shows'\''|[\s(]shows[\s,)]' internal db migrations -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || trueRepository: Silo-Server/silo-server
Length of output: 50380
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## internal/librarykind/librarykind_test.go\n'
sed -n '1,120p' internal/librarykind/librarykind_test.go
printf '\n## internal/scanner/file_repo.go TV type checks\n'
sed -n '1868,1886p' internal/scanner/file_repo.go
sed -n '1948,1964p' internal/scanner/file_repo.go
sed -n '1998,2010p' internal/scanner/file_repo.goRepository: Silo-Server/silo-server
Length of output: 4421
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## exact quoted \"shows\" tokens\n'
rg -n --fixed-strings '"shows"' internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
rg -n --fixed-strings "'shows'" internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
printf '\n## any exact library type docs listing accepted tv values\n'
rg -n --fixed-strings 'tvshows' internal/librarykind internal/scanner internal/catalog internal/metadata -g '*.go' -g '*.sql' || trueRepository: Silo-Server/silo-server
Length of output: 10735
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## folder.type / media_folders.type assignments and checks\n'
rg -n "folders\.type|media_folders\.type|folder\.Type|Type: *\"(series|tv|show|tvshows|movie|movies|audiobook|audiobooks|ebook|ebooks|podcast|podcasts|mixed|manga)\"" internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
printf '\n## direct mention of \"tvshows\" as a type\n'
rg -n --fixed-strings '"tvshows"' internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
rg -n --fixed-strings "'tvshows'" internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
printf '\n## direct mention of \"shows\" as a type token (exact quoted)\n'
rg -n --fixed-strings '"shows"' internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || true
rg -n --fixed-strings "'shows'" internal db migrations . -g '*.go' -g '*.sql' -g '*.ts' -g '*.json' -g '*.yaml' -g '*.yml' || trueRepository: Silo-Server/silo-server
Length of output: 50380
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n## internal/api/handlers/library_collections.go around type parsing\n'
sed -n '700,740p' internal/api/handlers/library_collections.go
printf '\n## internal/adminjob/item_refresh.go around folder type normalization\n'
sed -n '328,356p' internal/adminjob/item_refresh.go
printf '\n## internal/libraryingest/executor.go around TV gate\n'
sed -n '444,468p' internal/libraryingest/executor.goRepository: Silo-Server/silo-server
Length of output: 3347
Add the missing shows alias to IsTV internal/librarykind/librarykind.go should accept "shows" too; other TV/type checks already treat it as equivalent to "series", "tv", "show", and "tvshows", and this path feeds the TV episode notification flow.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/librarykind/librarykind.go` around lines 56 - 63, The IsTV helper in
librarykind.go is missing the "shows" alias, so update the switch in IsTV to
treat "shows" the same as the other TV equivalents. Make sure the
normalize(libraryType) check includes "shows" alongside "series", "tv", "show",
and "tvshows" so the TV episode notification flow recognizes it correctly.
…nnels (Silo-Server#260) Audiobook and ebook libraries previously never entered the Recently Added pipeline: availability detection only ran for TV/movie/mixed libraries and release_events only knew episode/movie kinds, so server channels (Discord/generic webhooks) could not announce new audiobooks or ebooks. Generalize the movie path into a flat-item-kind registry (internal/notifications/item_kind.go) driving availability detection, recording, channel toggles, payload rendering, test fixtures, and the admin backfill seeder. New kinds share a kind-discriminated item_availability table; movie_availability stays as-is. Channels gain notify_new_audiobooks/notify_new_ebooks toggles (default on, additive API fields) and embeds carry the author from item_people. Flood-safe by construction: existing libraries seed silently on their first post-upgrade full scan. Extract internal/librarykind to replace the is*LibraryType helper copies that had drifted across scanner, libraryingest, and metadata (metadata's movie check silently included mixed; now spelled explicitly). Co-authored-by: Claude Fable 5 <[email protected]>
Problem
Recently Added notifications only supported movies and TV episodes: availability detection ran solely for TV/movie/mixed libraries,
AvailabilityKindshad onlyEpisodes/Movies, and server channels exposed onlynotify_new_movies/notify_new_episodes. Audiobook (and ebook) libraries never created release events, so Discord/server-channel webhooks could not announce newly added audiobooks. (Reported via user intake; no scope issue exists yet — the schema comment in20260612020209_server_notification_channels.sqlexplicitly anticipated "audiobooks/music later need only a new kind value".)What changed
audiobookandebookflow through the full pipeline: scan → availability detection →release_events→ server-channel sweep → Discord embed / signed generic JSON.internal/notifications/item_kind.go): the movie-specific recorder is generalized intoRecordItemAvailabilityForLibrary/ForPaths, and the registry drives detection dispatch,WantsContentKind, payload grouping/rendering, test-send fixtures, andSeedAvailabilitybackfill passes. A future kind (music, podcasts) is one registry entry + one toggle column + a constraint-widening migration.item_availabilitytable for kinds after movie (movie_availabilityuntouched), widenedrelease_eventskind/shape CHECKs, andnotify_new_audiobooks/notify_new_ebookscolumns (defaulttrue, matching the movie/episode toggles).loadContentMetagains aLEFT JOIN LATERALonitem_people(kind=author), rendered as an Author field in Discord embeds and an additiveauthorfield in thecontent.addedgeneric payload.internal/librarykind: replaces theis*LibraryTypehelpers previously duplicated acrossscanner,libraryingest, andmetadata(whose movie predicate silently includedmixed; that behavior is preserved but now explicit).notify_new_audiobooks/notify_new_ebooksJSON fields on/api/v1/admin/notifications/server-channels, plus "New audiobooks"/"New ebooks" toggles in the web admin form.Why this approach
Cloning the movie code per kind (two more recorder pairs, two more switch arms everywhere) is exactly the cross-file duplication CLAUDE.md flags; this is the third and fourth kind of the same shape, so the abstraction now pays for itself. Movies keep their existing table to avoid migrating a populated hot-path table for zero behavior gain.
Behavior and safety notes
PartitionEventsByKindalready handles this generically).falsefromWantsContentKindand are skipped (not misrendered) byGroupContentEvents./api/v1; thecontent.addedgeneric payload keepsversion: 1withomitemptyadditive fields, matching the precedent set when movies were added.SeedAvailabilityprogress math generalized from a hardcoded 2-pass 50/50 split to N passes.Testing
librarykindpredicates (moved from scanner tests).go build/go teston all affected packages, web ESLint (0 errors), Prettier,tsc -b,make verify-local-pathsall pass.Risks / follow-ups
EVENT_SECTIONS-derived), not by browser walkthrough.AI-use disclosure
Implemented with Claude Code (Claude Fable 5): exploration, architecture comparison, implementation, and three-lens automated review, with human direction on scope, defaults, and approach selection.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes