From 7745ccefabddd83b222b863e63a463212ec59733 Mon Sep 17 00:00:00 2001 From: ronaldheft Date: Sun, 21 Aug 2022 11:25:50 -0400 Subject: [PATCH] Fixes missing LocalMediaProgress for downloads without existing progress --- ios/App/App/plugins/AbsDownloader.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ios/App/App/plugins/AbsDownloader.swift b/ios/App/App/plugins/AbsDownloader.swift index a5dbffa2..04dae1a6 100644 --- a/ios/App/App/plugins/AbsDownloader.swift +++ b/ios/App/App/plugins/AbsDownloader.swift @@ -186,12 +186,15 @@ public class AbsDownloader: CAPPlugin, URLSessionDownloadDelegate { statusNotification["localLibraryItem"] = try? localLibraryItem.asDictionary() + var localMediaProgress: LocalMediaProgress if let progress = libraryItem.userMediaProgress { let episode = downloadItem.media?.episodes.first(where: { $0.id == downloadItem.episodeId }) - let localMediaProgress = LocalMediaProgress(localLibraryItem: localLibraryItem!, episode: episode, progress: progress) - Database.shared.saveLocalMediaProgress(localMediaProgress) - statusNotification["localMediaProgress"] = try? localMediaProgress.asDictionary() + localMediaProgress = LocalMediaProgress(localLibraryItem: localLibraryItem!, episode: episode, progress: progress) + } else { + localMediaProgress = LocalMediaProgress.fetchOrCreateLocalMediaProgress(localMediaProgressId: nil, localLibraryItemId: localLibraryItem?.id, localEpisodeId: downloadItem.episodeId)! } + Database.shared.saveLocalMediaProgress(localMediaProgress) + statusNotification["localMediaProgress"] = try? localMediaProgress.asDictionary() self.notifyListeners("onItemDownloadComplete", data: statusNotification) }