Purge everything except local posts on logout

This commit is contained in:
Angelo Stavrow 2020-10-22 12:40:07 -04:00
parent 47aec3d143
commit 932da4ac48
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
2 changed files with 5 additions and 3 deletions

View File

@ -280,7 +280,7 @@ private extension WriteFreelyModel {
DispatchQueue.main.async {
self.account.logout()
LocalStorageManager().purgeUserCollections()
self.posts.purgeAllPosts()
self.posts.purgePublishedPosts()
}
} catch {
print("Something went wrong purging the token from the Keychain.")
@ -295,7 +295,7 @@ private extension WriteFreelyModel {
DispatchQueue.main.async {
self.account.logout()
LocalStorageManager().purgeUserCollections()
self.posts.purgeAllPosts()
self.posts.purgePublishedPosts()
}
} catch {
print("Something went wrong purging the token from the Keychain.")

View File

@ -27,13 +27,15 @@ class PostListModel: ObservableObject {
LocalStorageManager().saveContext()
}
func purgeAllPosts() {
func purgePublishedPosts() {
userPosts = []
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "WFAPost")
fetchRequest.predicate = NSPredicate(format: "status != %i", 0)
let deleteRequest = NSBatchDeleteRequest(fetchRequest: fetchRequest)
do {
try LocalStorageManager.persistentContainer.viewContext.executeAndMergeChanges(using: deleteRequest)
loadCachedPosts()
} catch {
print("Error: Failed to purge cached posts.")
}