Skip to content

feat(notifications): announce new audiobooks and ebooks on server channels - #260

Merged
Quick104 merged 1 commit into
mainfrom
claude/laughing-edison-e2a48e
Jul 2, 2026
Merged

Quick104 merged 1 commit into
mainfrom
claude/laughing-edison-e2a48e

Conversation

@Quick104

@Quick104 Quick104 commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Recently Added notifications only supported movies and TV episodes: availability detection ran solely for TV/movie/mixed libraries, AvailabilityKinds had only Episodes/Movies, and server channels exposed only notify_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 in 20260612020209_server_notification_channels.sql explicitly anticipated "audiobooks/music later need only a new kind value".)

What changed

  • New content kinds audiobook and ebook flow through the full pipeline: scan → availability detection → release_events → server-channel sweep → Discord embed / signed generic JSON.
  • Flat-item-kind registry (internal/notifications/item_kind.go): the movie-specific recorder is generalized into RecordItemAvailabilityForLibrary/ForPaths, and the registry drives detection dispatch, WantsContentKind, payload grouping/rendering, test-send fixtures, and SeedAvailability backfill passes. A future kind (music, podcasts) is one registry entry + one toggle column + a constraint-widening migration.
  • Schema (new Goose migration): kind-discriminated item_availability table for kinds after movie (movie_availability untouched), widened release_events kind/shape CHECKs, and notify_new_audiobooks/notify_new_ebooks columns (default true, matching the movie/episode toggles).
  • Author metadata: loadContentMeta gains a LEFT JOIN LATERAL on item_people (kind=author), rendered as an Author field in Discord embeds and an additive author field in the content.added generic payload.
  • internal/librarykind: replaces the is*LibraryType helpers previously duplicated across scanner, libraryingest, and metadata (whose movie predicate silently included mixed; that behavior is preserved but now explicit).
  • Admin surface: additive notify_new_audiobooks/notify_new_ebooks JSON 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

  • Broadcast-only, like movies: audiobooks/ebooks do not fan out per-profile (PartitionEventsByKind already handles this generically).
  • No back-catalog flood: existing audiobook/ebook libraries have no seed markers for the new kinds, so their first post-upgrade full scan seeds silently; only subsequent additions announce.
  • Old-node forward-compat preserved: unknown kinds still return false from WantsContentKind and are skipped (not misrendered) by GroupContentEvents.
  • Mixed libraries excluded from the new kinds: the scanner never routes mixed folders through the audiobook/ebook pipelines.
  • API contract: purely additive within /api/v1; the content.added generic payload keeps version: 1 with omitempty additive fields, matching the precedent set when movies were added.
  • SeedAvailability progress math generalized from a hardcoded 2-pass 50/50 split to N passes.

Testing

  • New/extended unit tests: registry invariants and toggle mapping, kind-scoped cross-library dedupe (including the no-cross-kind-dedupe regression guard), Discord/generic rendering with author, partition behavior, dedupe-key disjointness, librarykind predicates (moved from scanner tests).
  • Migration verified against a real Postgres: fresh-DB migrate-up plus down/up round-trip; resulting constraints and columns inspected.
  • go build/go test on all affected packages, web ESLint (0 errors), Prettier, tsc -b, make verify-local-paths all pass.

Risks / follow-ups

  • Admin UI verified by type-checking and pattern reuse (EVENT_SECTIONS-derived), not by browser walkthrough.
  • Per-profile audiobook/ebook interest (favorites-style fan-out) is deliberately out of scope, same as movies.
  • Worth opening a capability issue for content-kind notification coverage to anchor future kinds (music/podcasts).

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

    • Added notification options for new audiobooks and ebooks in server channel settings and admin APIs.
    • Expanded content notifications to include audiobook and ebook releases, including richer metadata such as author details.
    • Broadened library and scan support for additional media types, improving coverage for non-video collections.
  • Bug Fixes

    • Improved notification grouping and deduplication so different content types are handled correctly.
    • Updated availability tracking and seeding to recognize the new content types consistently.

…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]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR introduces a shared internal/librarykind package for classifying library folder types, and extends notification infrastructure to treat audiobooks and ebooks as flat item kinds alongside movies—covering availability detection, server-channel toggles, payload rendering, database schema/migration, admin API, and web UI.

Changes

Audiobook/Ebook notifications

Layer / File(s) Summary
Centralized library-kind classification
internal/librarykind/librarykind.go, internal/librarykind/librarykind_test.go, internal/libraryingest/executor.go, internal/metadata/worker.go, internal/scanner/scanner*.go
New librarykind package with Kinds struct and Is* predicates; executor, metadata worker, and scanner replace local type-string helpers with this shared package.
Flat item kind registry & release event types
internal/notifications/item_kind*.go, internal/notifications/release_types.go, internal/notifications/discord_embed_meta.go, internal/notifications/fanout_logic.go, internal/notifications/fanout_worker.go
New flatItemKind registry mapping movie/audiobook/ebook to availability tables and toggles; EventKind constants and comments extended for flat kinds.
Availability detection & repository seeding
internal/notifications/availability_detector.go, internal/notifications/release_repo.go, internal/notifications/system.go
AvailabilityKinds gains audiobook/ebook fields; movie-specific repository methods replaced with generic RecordItemAvailabilityForLibrary/ForPaths and ItemDedupeKey; seeding passes now iterate all flat kinds.
Server channel model, toggles & payload rendering
internal/notifications/server_channel_types.go, server_channel_service.go, server_channel_payload.go, server_channel_logic_test.go
ServerChannel/ServerChannelInput gain audiobook/ebook toggles; WantsContentKind, GroupContentEvents, Discord/generic payload builders generalized to flat kinds with new Author field.
Worker author metadata
internal/notifications/server_channel_worker.go
loadContentMeta now joins author credit data and classifies content IDs via flatKindByString.
DB persistence, migration & admin API
internal/notifications/server_channel_repo.go, migrations/sql/20260702033712_audiobook_ebook_notifications.sql, internal/api/handlers/admin_server_channels.go
New migration adds item_availability table, expands release_events constraints, and adds notification columns; repo SQL and admin API request/response updated accordingly.
Web admin UI
web/src/api/types.ts, web/src/pages/admin-settings/ServerNotificationChannels.tsx
TypeScript types and admin settings page expose notify_new_audiobooks/notify_new_ebooks toggles.

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
Loading

Possibly related PRs

Suggested labels: v1

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding audiobook and ebook announcements to server channels.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/laughing-edison-e2a48e

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/notifications/server_channel_service.go (1)

274-311: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Hardcoded EventKindMovie check undercuts the new registry abstraction.

sampleContentGroups decides whether to populate Author by checking k.Kind != EventKindMovie instead of a property on the flatItemKind registry 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 the flatItemKind struct in item_kind.go and 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

📥 Commits

Reviewing files that changed from the base of the PR and between 5bb09a7 and 17044a3.

📒 Files selected for processing (25)
  • internal/api/handlers/admin_server_channels.go
  • internal/libraryingest/executor.go
  • internal/librarykind/librarykind.go
  • internal/librarykind/librarykind_test.go
  • internal/metadata/worker.go
  • internal/notifications/availability_detector.go
  • internal/notifications/discord_embed_meta.go
  • internal/notifications/fanout_logic.go
  • internal/notifications/fanout_worker.go
  • internal/notifications/item_kind.go
  • internal/notifications/item_kind_test.go
  • internal/notifications/release_repo.go
  • internal/notifications/release_types.go
  • internal/notifications/server_channel_logic_test.go
  • internal/notifications/server_channel_payload.go
  • internal/notifications/server_channel_repo.go
  • internal/notifications/server_channel_service.go
  • internal/notifications/server_channel_types.go
  • internal/notifications/server_channel_worker.go
  • internal/notifications/system.go
  • internal/scanner/scanner.go
  • internal/scanner/scanner_test.go
  • migrations/sql/20260702033712_audiobook_ebook_notifications.sql
  • web/src/api/types.ts
  • web/src/pages/admin-settings/ServerNotificationChannels.tsx
💤 Files with no reviewable changes (1)
  • internal/scanner/scanner_test.go

Comment on lines +56 to +63
func IsTV(libraryType string) bool {
switch normalize(libraryType) {
case "series", "tv", "show", "tvshows":
return true
default:
return false
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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' || true

Repository: Silo-Server/silo-server

Length of output: 50380


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,140p' internal/librarykind/librarykind.go

Repository: 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' || true

Repository: 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' || true

Repository: 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.go

Repository: 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' || true

Repository: 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' || true

Repository: 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.go

Repository: 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.

@Quick104
Quick104 merged commit 027b0e2 into main Jul 2, 2026
3 checks passed
@Quick104
Quick104 deleted the claude/laughing-edison-e2a48e branch July 2, 2026 15:42
Quick104 added a commit to RXWatcher/silo-server that referenced this pull request Jul 10, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant