Read notification-setting from CoreData (IOS-14)
aka subscription
This commit is contained in:
parent
00fa7e1220
commit
f2180034ee
|
@ -543,7 +543,8 @@ private extension SceneCoordinator {
|
|||
|
||||
let settingsCoordinator = SettingsCoordinator(presentedOn: presentedOn,
|
||||
accountName: accountName,
|
||||
setting: setting)
|
||||
setting: setting,
|
||||
appContext: appContext)
|
||||
settingsCoordinator.delegate = self
|
||||
settingsCoordinator.start()
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
import Foundation
|
||||
import MastodonLocalization
|
||||
import MastodonSDK
|
||||
import CoreDataStack
|
||||
|
||||
struct NotificationSettingsSection: Hashable {
|
||||
let entries: [NotificationSettingEntry]
|
||||
|
@ -34,6 +36,19 @@ enum NotificationPolicy: Hashable, CaseIterable {
|
|||
return L10n.Scene.Settings.Notifications.Policy.noone
|
||||
}
|
||||
}
|
||||
|
||||
var subscriptionPolicy: Mastodon.API.Subscriptions.Policy {
|
||||
switch self {
|
||||
case .anyone:
|
||||
return .all
|
||||
case .followers:
|
||||
return .follower
|
||||
case .follow:
|
||||
return .followed
|
||||
case .noone:
|
||||
return .none
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum NotificationAlert: Hashable, CaseIterable {
|
||||
|
@ -56,3 +71,22 @@ enum NotificationAlert: Hashable, CaseIterable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Subscription {
|
||||
var notificationPolicy: NotificationPolicy? {
|
||||
guard let policy else { return nil }
|
||||
|
||||
switch policy {
|
||||
case .all:
|
||||
return .anyone
|
||||
case .followed:
|
||||
return .follow
|
||||
case .follower:
|
||||
return .followers
|
||||
case .none:
|
||||
return .noone
|
||||
case ._other(_):
|
||||
return .noone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
||||
|
||||
import UIKit
|
||||
import CoreDataStack
|
||||
import MastodonLocalization
|
||||
|
||||
protocol NotificationSettingsViewControllerDelegate: AnyObject {
|
||||
|
@ -17,10 +18,8 @@ class NotificationSettingsViewController: UIViewController {
|
|||
let sections: [NotificationSettingsSection]
|
||||
var viewModel: NotificationSettingsViewModel
|
||||
|
||||
init() {
|
||||
|
||||
//TODO: @zeitschlag Read Settings
|
||||
viewModel = NotificationSettingsViewModel(selectedPolicy: .follow)
|
||||
init(currentSetting: Setting?) {
|
||||
viewModel = NotificationSettingsViewModel(selectedPolicy: currentSetting?.activeSubscription?.notificationPolicy ?? .noone)
|
||||
sections = [
|
||||
NotificationSettingsSection(entries: [.policy]),
|
||||
NotificationSettingsSection(entries: NotificationAlert.allCases.map { NotificationSettingEntry.alert($0) } )
|
||||
|
|
|
@ -21,11 +21,13 @@ class SettingsCoordinator: NSObject, Coordinator {
|
|||
private let settingsViewController: SettingsViewController
|
||||
|
||||
let setting: Setting
|
||||
let appContext: AppContext
|
||||
|
||||
init(presentedOn: UIViewController, accountName: String, setting: Setting) {
|
||||
init(presentedOn: UIViewController, accountName: String, setting: Setting, appContext: AppContext) {
|
||||
self.presentedOn = presentedOn
|
||||
navigationController = UINavigationController()
|
||||
self.setting = setting
|
||||
self.appContext = appContext
|
||||
|
||||
settingsViewController = SettingsViewController(accountName: accountName)
|
||||
}
|
||||
|
@ -52,10 +54,13 @@ extension SettingsCoordinator: SettingsViewControllerDelegate {
|
|||
|
||||
navigationController.pushViewController(generalSettingsViewController, animated: true)
|
||||
case .notifications:
|
||||
let notificationViewController = NotificationSettingsViewController()
|
||||
|
||||
let currentSetting = appContext.settingService.currentSetting.value
|
||||
let notificationViewController = NotificationSettingsViewController(currentSetting: currentSetting)
|
||||
notificationViewController.delegate = self
|
||||
|
||||
navigationController.pushViewController(notificationViewController, animated: true)
|
||||
self.navigationController.pushViewController(notificationViewController, animated: true)
|
||||
|
||||
case .aboutMastodon:
|
||||
let aboutViewController = AboutViewController()
|
||||
aboutViewController.delegate = self
|
||||
|
|
|
@ -13,8 +13,8 @@ public typealias NotificationSubscription = Subscription
|
|||
|
||||
extension Subscription {
|
||||
|
||||
public var policy: Mastodon.API.Subscriptions.Policy {
|
||||
return Mastodon.API.Subscriptions.Policy(rawValue: policyRaw) ?? .all
|
||||
public var policy: Mastodon.API.Subscriptions.Policy? {
|
||||
return Mastodon.API.Subscriptions.Policy(rawValue: policyRaw)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue