Skip to main content

storage_set_watched

Function storage_set_watched 

Source
pub async fn storage_set_watched(
    db: State<'_, DatabaseWrapper>,
    user_id: String,
    item_id: String,
    watched: bool,
) -> Result<(), String>
Expand description

Set the watched flag locally for an item and everything inside it.

This backs the watched toggle, and is deliberately separate from storage_mark_played — which reports a single track/episode finishing and increments play_count — because the toggle has two directions and applies to containers.

The recursion is what makes the toggle honest offline. Jellyfin applies POST/DELETE /PlayedItems/{id} recursively over a season or series, so online the server fixes up the children on the next read; with no server to ask, marking a season watched would otherwise tick the season and leave every episode inside it unwatched. Targets are drawn from items by the same link columns the rest of the offline layer uses, so an id that is not cached selects nothing and the statement is a no-op rather than a foreign-key error.

Un-marking clears the resume position too, matching the server, so an item un-marked offline does not come back offering to resume from a position it is no longer meant to have.

pending_sync = 1 hands the rows to the sync drain.

TRACES: UR-073 | DR-158