Commit 3a4ccb63 authored by Kourser's avatar Kourser
Browse files

feat(episodes): mark a podcast's episodes played in bulk

Catching up on a back catalogue — 150 to 200 episodes after moving from
another app — meant marking each episode by hand.

On a podcast's page, an episode's context menu offers "Mark this and
older as played", and the Filter menu "Mark all as played". Both act on
the episodes shown, filter and search applied, leave out those already
played, and ask first beyond one episode.

AppModel.markPlayed takes a list, written in one transaction
(LibraryStore.setPlayStates) and sent in one sync; "delete after
playing" only touches episodes that have a download.

New strings in the 23 languages.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 78eaff23
Loading
Loading
Loading
Loading
+5
Changes for CHANGELOG.md: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,6 +12,11 @@ adopte le [versionnage sémantique](https://semver.org/lang/fr/).
  Réglages › Téléchargement, avec le nombre d'épisodes non lus à garder
  téléchargés (3, 5, 10 ou illimité). Chaque podcast suit ce réglage global ou
  a le sien : activé ou désactivé, et son propre nombre d'épisodes.
- **Marquer d'un coup comme lus** les épisodes d'un podcast : « Marquer
  celui-ci et les plus anciens comme lus » dans le menu contextuel d'un
  épisode, et « Tout marquer comme lu » dans le menu Filtrer. Les deux
  agissent sur les épisodes affichés (filtre et recherche compris) et
  demandent confirmation au-delà d'un épisode.

### Modifié
- Le nombre d'épisodes à conserver compte désormais les épisodes **non lus**.
+21
Changes for Packages/Core/Sources/StorageKit/LibraryStore+PlayState.swift: 21 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -20,6 +20,27 @@ extension LibraryStore {
        }
    }

    /// Sets several episodes' play state in one transaction — a whole back
    /// catalogue marked played at once. `positions` maps each episode to its
    /// position.
    public func setPlayStates(
        _ positions: [UUID: TimeInterval],
        isPlayed: Bool,
        updatedAt: Date = Date()
    ) async throws {
        let records = positions.map { id, position in
            PlayStateRecord(
                episodeId: id.uuidString,
                position: position,
                isPlayed: isPlayed,
                updatedAt: updatedAt.timeIntervalSince1970
            )
        }
        try await dbQueue.write { db in
            for record in records { try record.upsert(db) }
        }
    }

    public func playState(forEpisodeID id: UUID) async throws -> PlayState? {
        try await dbQueue.read { db in
            try PlayStateRecord.fetchOne(db, key: id.uuidString).map {
+12
Changes for Packages/Core/Tests/StorageKitTests/PlayStateTests.swift: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -28,6 +28,18 @@ import PodcastModel
        #expect(try await store.playState(forEpisodeID: eps[1].id) == nil)
    }

    @Test func setsSeveralAtOnce() async throws {
        let (store, eps) = try await store()
        try await store.setPlayState(episodeID: eps[0].id, position: 10, isPlayed: false)

        try await store.setPlayStates([eps[0].id: 60, eps[1].id: 90], isPlayed: true)

        let states = try await store.playStates(forEpisodeIDs: eps.map(\.id))
        #expect(states[eps[0].id] == PlayState(position: 60, isPlayed: true))
        #expect(states[eps[1].id] == PlayState(position: 90, isPlayed: true))
        #expect(states[eps[2].id] == nil)
    }

    @Test func upsertsOnRepeatedWrites() async throws {
        let (store, eps) = try await store()
        try await store.setPlayState(episodeID: eps[0].id, position: 10, isPlayed: false)
+20 −3
Changes for Skingomz/AppModel.swift: 20 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -801,10 +801,27 @@ final class AppModel {
    }

    func markPlayed(_ episode: Episode, _ played: Bool) async {
        await markPlayed([episode], played)
    }

    /// Marks several episodes at once — a back catalogue caught up on — in one
    /// write and one sync.
    func markPlayed(_ episodes: [Episode], _ played: Bool) async {
        guard !episodes.isEmpty else { return }
        var states = playStates
        var positions: [UUID: TimeInterval] = [:]
        for episode in episodes {
            let position = played ? (episode.duration ?? 0) : 0
        playStates[episode.id] = PlayState(position: position, isPlayed: played)
        try? await store.setPlayState(episodeID: episode.id, position: position, isPlayed: played)
        if played && downloadSettings.deleteWhenPlayed { downloads.delete(episode) }
            positions[episode.id] = position
            states[episode.id] = PlayState(position: position, isPlayed: played)
        }
        playStates = states
        try? await store.setPlayStates(positions, isPlayed: played)
        if played && downloadSettings.deleteWhenPlayed {
            for episode in episodes where downloads.status(for: episode) != .idle {
                downloads.delete(episode)
            }
        }
        scheduleProgressSync()
    }

+10
Changes for Skingomz/EpisodeListRow.swift: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@ struct EpisodeListRow: View {
    /// Shows the owning podcast's thumbnail (used in cross-podcast lists like
    /// the inbox); off in single-podcast contexts where it would be redundant.
    var showArtwork = false
    /// Offered by the podcast screen: marks this episode and the older ones
    /// shown played. `nil` hides the action.
    var markOlderPlayed: (() -> Void)?
    @State private var showingNotes = false

    var body: some View {
@@ -251,6 +254,13 @@ struct EpisodeListRow: View {
                      systemImage: isPlayed ? "circle" : "checkmark.circle")
            }

            if let markOlderPlayed {
                Button(action: markOlderPlayed) {
                    Label("Marquer celui-ci et les plus anciens comme lus",
                          systemImage: "text.badge.checkmark")
                }
            }

            Button {
                Task { await model.toggleFavorite(episode) }
            } label: {
Loading