diff --git a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion index 2145ac780..1d5ea989f 100644 --- a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion +++ b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - CoreData 5.xcdatamodel + CoreData 4.xcdatamodel diff --git a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 5.xcdatamodel/contents b/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 5.xcdatamodel/contents deleted file mode 100644 index 1388fa741..000000000 --- a/MastodonSDK/Sources/CoreDataStack/CoreData.xcdatamodeld/CoreData 5.xcdatamodel/contents +++ /dev/null @@ -1,254 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift index 62d4b435c..60f15367e 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Block.swift @@ -51,10 +51,10 @@ extension APIService { fetchRequest.includesPropertyValues = false try await managedObjectContext.performChanges { - let accounts = try managedObjectContext.fetch(fetchRequest) as! [MastodonUser] + let users = try managedObjectContext.fetch(fetchRequest) as! [MastodonUser] - for account in accounts { - managedObjectContext.delete(account) + for user in users { + user.statuses.deleteAllFeedsForBlockOrMute(in: managedObjectContext) } } @@ -149,3 +149,11 @@ extension APIService { } } + +extension Set { + func deleteAllFeedsForBlockOrMute(in managedObjectContext: NSManagedObjectContext) { + map { $0.feeds.union($0.reblogFrom.map { $0.feeds }.flatMap { $0 }) } + .flatMap { $0 } + .forEach(managedObjectContext.delete) + } +} diff --git a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift index 1d6738e32..e0e95fd35 100644 --- a/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift +++ b/MastodonSDK/Sources/MastodonCore/Service/API/APIService+Mute.swift @@ -50,10 +50,10 @@ extension APIService { fetchRequest.includesPropertyValues = false try await managedObjectContext.performChanges { - let accounts = try managedObjectContext.fetch(fetchRequest) as! [MastodonUser] + let users = try managedObjectContext.fetch(fetchRequest) as! [MastodonUser] - for account in accounts { - managedObjectContext.delete(account) + for user in users { + user.statuses.deleteAllFeedsForBlockOrMute(in: managedObjectContext) } }