mirror of
https://github.com/yattee/yattee.git
synced 2026-02-20 01:39:46 +00:00
Fix deleted playlists resurrecting from iCloud after app restart
Pending deletes were lost across app restarts because recoverPersistedPendingChanges() never reconstructed CKRecord.ID objects from persisted record names. Additionally, incoming iCloud records for deleted playlists were blindly applied, and orphaned playlist items in CloudKit would recreate placeholder playlists. - Rebuild pendingDeletes array from UserDefaults on recovery - Guard applyRemoteRecord against records pending local deletion - Skip deferred items whose parent playlist is pending deletion - Queue all playlist item deletions when deleting a playlist - Clean up placeholder playlists for pending-delete playlists
This commit is contained in:
@@ -40,12 +40,17 @@ extension DataManager {
|
||||
/// Deletes a local playlist.
|
||||
func deletePlaylist(_ playlist: LocalPlaylist) {
|
||||
let playlistID = playlist.id
|
||||
let itemIDs = playlist.sortedItems.map { $0.id }
|
||||
|
||||
modelContext.delete(playlist)
|
||||
save()
|
||||
|
||||
// Queue for CloudKit deletion
|
||||
|
||||
// Queue playlist and all its items for CloudKit deletion
|
||||
cloudKitSync?.queuePlaylistDelete(playlistID: playlistID)
|
||||
|
||||
for itemID in itemIDs {
|
||||
cloudKitSync?.queuePlaylistItemDelete(itemID: itemID)
|
||||
}
|
||||
|
||||
NotificationCenter.default.post(name: .playlistsDidChange, object: nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user