diff --git a/CoreDataStack/Entity/HomeTimelineIndex.swift b/CoreDataStack/Entity/HomeTimelineIndex.swift index 10b00aaa0..d52d0c3cd 100644 --- a/CoreDataStack/Entity/HomeTimelineIndex.swift +++ b/CoreDataStack/Entity/HomeTimelineIndex.swift @@ -65,7 +65,7 @@ extension HomeTimelineIndex { public let domain: String public let userID: String - public init(domain: String,userID: String) { + public init(domain: String, userID: String) { self.identifier = UUID().uuidString + "@" + domain self.domain = domain self.userID = userID @@ -80,10 +80,20 @@ extension HomeTimelineIndex: Managed { } extension HomeTimelineIndex { - public static func predicate(userID: String) -> NSPredicate { + static func predicate(domain: String) -> NSPredicate { + return NSPredicate(format: "%K == %@", #keyPath(HomeTimelineIndex.domain), domain) + } + + static func predicate(userID: MastodonUser.ID) -> NSPredicate { return NSPredicate(format: "%K == %@", #keyPath(HomeTimelineIndex.userID), userID) } - + + public static func predicate(domain: String, userID: MastodonUser.ID) -> NSPredicate { + return NSCompoundPredicate(andPredicateWithSubpredicates: [ + predicate(domain: domain), + predicate(userID: userID) + ]) + } public static func notDeleted() -> NSPredicate { return NSPredicate(format: "%K == nil", #keyPath(HomeTimelineIndex.deletedAt)) diff --git a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist index 1cafe9c70..a5dbdb347 100644 --- a/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/Mastodon.xcodeproj/xcuserdata/mainasuk.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ AppShared.xcscheme_^#shared#^_ orderHint - 23 + 24 CoreDataStack.xcscheme_^#shared#^_ orderHint - 21 + 22 Mastodon - ASDK.xcscheme_^#shared#^_ @@ -37,12 +37,12 @@ NotificationService.xcscheme_^#shared#^_ orderHint - 20 + 3 ShareActionExtension.xcscheme_^#shared#^_ orderHint - 22 + 21 SuppressBuildableAutocreation diff --git a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift index 611e95368..0bf1e1041 100644 --- a/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift +++ b/Mastodon/Scene/HomeTimeline/HomeTimelineViewModel.swift @@ -120,9 +120,10 @@ final class HomeTimelineViewModel: NSObject { .sink { [weak self] activeMastodonAuthentication in guard let self = self else { return } guard let mastodonAuthentication = activeMastodonAuthentication else { return } - let activeMastodonUserID = mastodonAuthentication.userID + let domain = mastodonAuthentication.domain + let userID = mastodonAuthentication.userID let predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [ - HomeTimelineIndex.predicate(userID: activeMastodonUserID), + HomeTimelineIndex.predicate(domain: domain, userID: userID), HomeTimelineIndex.notDeleted() ]) self.timelinePredicate.value = predicate diff --git a/Mastodon/Service/AuthenticationService.swift b/Mastodon/Service/AuthenticationService.swift index f6ece0440..0b3c3fa11 100644 --- a/Mastodon/Service/AuthenticationService.swift +++ b/Mastodon/Service/AuthenticationService.swift @@ -130,6 +130,19 @@ extension AuthenticationService { appAuthorization: Mastodon.API.OAuth.Authorization(accessToken: mastodonAuthentication.appAccessToken), userAuthorization: Mastodon.API.OAuth.Authorization(accessToken: mastodonAuthentication.userAccessToken) ) + + // remove home timeline indexes + let homeTimelineIndexRequest = HomeTimelineIndex.sortedFetchRequest + homeTimelineIndexRequest.predicate = HomeTimelineIndex.predicate( + domain: mastodonAuthentication.domain, + userID: mastodonAuthentication.userID + ) + let homeTimelineIndexes = managedObjectContext.safeFetch(homeTimelineIndexRequest) + for homeTimelineIndex in homeTimelineIndexes { + managedObjectContext.delete(homeTimelineIndex) + } + + // remove user authentication managedObjectContext.delete(mastodonAuthentication) isSignOut = true }