feat: purge home timeline when user sign out
This commit is contained in:
parent
c86c29afe7
commit
4db73d4f74
|
@ -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))
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
<key>AppShared.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>23</integer>
|
||||
<integer>24</integer>
|
||||
</dict>
|
||||
<key>CoreDataStack.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>21</integer>
|
||||
<integer>22</integer>
|
||||
</dict>
|
||||
<key>Mastodon - ASDK.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
|
@ -37,12 +37,12 @@
|
|||
<key>NotificationService.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>20</integer>
|
||||
<integer>3</integer>
|
||||
</dict>
|
||||
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>22</integer>
|
||||
<integer>21</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>SuppressBuildableAutocreation</key>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue