fix: notification settings persist logic issue
This commit is contained in:
parent
9104602893
commit
0d7d659e01
|
@ -289,6 +289,9 @@ class SettingsViewController: UIViewController, NeedsDependency {
|
|||
return
|
||||
}
|
||||
|
||||
// clear badge before sign-out
|
||||
context.notificationService.clearNotificationCountForActiveUser()
|
||||
|
||||
context.authenticationService.signOutMastodonUser(
|
||||
domain: activeMastodonAuthenticationBox.domain,
|
||||
userID: activeMastodonAuthenticationBox.userID
|
||||
|
|
|
@ -18,13 +18,9 @@ extension APIService.CoreData {
|
|||
setting: Setting,
|
||||
policy: Mastodon.API.Subscriptions.Policy
|
||||
) -> (subscription: Subscription, isCreated: Bool) {
|
||||
let oldSubscription: Subscription? = {
|
||||
let request = Subscription.sortedFetchRequest
|
||||
request.predicate = Subscription.predicate(policyRaw: policy.rawValue)
|
||||
request.fetchLimit = 1
|
||||
request.returnsObjectsAsFaults = false
|
||||
return managedObjectContext.safeFetch(request).first
|
||||
}()
|
||||
let oldSubscription = setting.subscriptions?.first(where: { subscription in
|
||||
subscription.policyRaw == policy.rawValue
|
||||
})
|
||||
|
||||
if let oldSubscription = oldSubscription {
|
||||
oldSubscription.setting = setting
|
||||
|
|
|
@ -27,7 +27,7 @@ final class NotificationService {
|
|||
let applicationIconBadgeNeedsUpdate = CurrentValueSubject<Void, Never>(Void())
|
||||
|
||||
// output
|
||||
/// [Token: UserID]
|
||||
/// [Token: NotificationViewModel]
|
||||
let notificationSubscriptionDict: [String: NotificationViewModel] = [:]
|
||||
let unreadNotificationCountDidUpdate = CurrentValueSubject<Void, Never>(Void())
|
||||
let requestRevealNotificationPublisher = PassthroughSubject<Mastodon.Entity.Notification.ID, Never>()
|
||||
|
|
|
@ -44,19 +44,21 @@ final class SettingService {
|
|||
.compactMap { [weak self] mastodonAuthenticationBoxes -> AnyPublisher<[MastodonAuthenticationBox], Never>? in
|
||||
guard let self = self else { return nil }
|
||||
guard let authenticationService = self.authenticationService else { return nil }
|
||||
guard let activeMastodonAuthenticationBox = mastodonAuthenticationBoxes.first else { return nil }
|
||||
|
||||
let domain = activeMastodonAuthenticationBox.domain
|
||||
let userID = activeMastodonAuthenticationBox.userID
|
||||
return authenticationService.backgroundManagedObjectContext.performChanges {
|
||||
_ = APIService.CoreData.createOrMergeSetting(
|
||||
into: authenticationService.backgroundManagedObjectContext,
|
||||
property: Setting.Property(
|
||||
domain: domain,
|
||||
userID: userID,
|
||||
appearanceRaw: SettingsItem.AppearanceMode.automatic.rawValue
|
||||
let managedObjectContext = authenticationService.backgroundManagedObjectContext
|
||||
return managedObjectContext.performChanges {
|
||||
for authenticationBox in mastodonAuthenticationBoxes {
|
||||
let domain = authenticationBox.domain
|
||||
let userID = authenticationBox.userID
|
||||
_ = APIService.CoreData.createOrMergeSetting(
|
||||
into: managedObjectContext,
|
||||
property: Setting.Property(
|
||||
domain: domain,
|
||||
userID: userID,
|
||||
appearanceRaw: SettingsItem.AppearanceMode.automatic.rawValue
|
||||
)
|
||||
)
|
||||
)
|
||||
} // end for
|
||||
}
|
||||
.map { _ in mastodonAuthenticationBoxes }
|
||||
.eraseToAnyPublisher()
|
||||
|
|
Loading…
Reference in New Issue