mirror of
https://github.com/writeas/writefreely-swiftui-multiplatform.git
synced 2024-11-15 01:11:02 +00:00
Purge everything except local posts on logout
This commit is contained in:
parent
47aec3d143
commit
932da4ac48
@ -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.")
|
||||
|
@ -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.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user