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,
|
let settingsCoordinator = SettingsCoordinator(presentedOn: presentedOn,
|
||||||
accountName: accountName,
|
accountName: accountName,
|
||||||
setting: setting)
|
setting: setting,
|
||||||
|
appContext: appContext)
|
||||||
settingsCoordinator.delegate = self
|
settingsCoordinator.delegate = self
|
||||||
settingsCoordinator.start()
|
settingsCoordinator.start()
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import MastodonLocalization
|
import MastodonLocalization
|
||||||
|
import MastodonSDK
|
||||||
|
import CoreDataStack
|
||||||
|
|
||||||
struct NotificationSettingsSection: Hashable {
|
struct NotificationSettingsSection: Hashable {
|
||||||
let entries: [NotificationSettingEntry]
|
let entries: [NotificationSettingEntry]
|
||||||
|
@ -34,6 +36,19 @@ enum NotificationPolicy: Hashable, CaseIterable {
|
||||||
return L10n.Scene.Settings.Notifications.Policy.noone
|
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 {
|
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.
|
// Copyright © 2023 Mastodon gGmbH. All rights reserved.
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import CoreDataStack
|
||||||
import MastodonLocalization
|
import MastodonLocalization
|
||||||
|
|
||||||
protocol NotificationSettingsViewControllerDelegate: AnyObject {
|
protocol NotificationSettingsViewControllerDelegate: AnyObject {
|
||||||
|
@ -17,10 +18,8 @@ class NotificationSettingsViewController: UIViewController {
|
||||||
let sections: [NotificationSettingsSection]
|
let sections: [NotificationSettingsSection]
|
||||||
var viewModel: NotificationSettingsViewModel
|
var viewModel: NotificationSettingsViewModel
|
||||||
|
|
||||||
init() {
|
init(currentSetting: Setting?) {
|
||||||
|
viewModel = NotificationSettingsViewModel(selectedPolicy: currentSetting?.activeSubscription?.notificationPolicy ?? .noone)
|
||||||
//TODO: @zeitschlag Read Settings
|
|
||||||
viewModel = NotificationSettingsViewModel(selectedPolicy: .follow)
|
|
||||||
sections = [
|
sections = [
|
||||||
NotificationSettingsSection(entries: [.policy]),
|
NotificationSettingsSection(entries: [.policy]),
|
||||||
NotificationSettingsSection(entries: NotificationAlert.allCases.map { NotificationSettingEntry.alert($0) } )
|
NotificationSettingsSection(entries: NotificationAlert.allCases.map { NotificationSettingEntry.alert($0) } )
|
||||||
|
|
|
@ -21,11 +21,13 @@ class SettingsCoordinator: NSObject, Coordinator {
|
||||||
private let settingsViewController: SettingsViewController
|
private let settingsViewController: SettingsViewController
|
||||||
|
|
||||||
let setting: Setting
|
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
|
self.presentedOn = presentedOn
|
||||||
navigationController = UINavigationController()
|
navigationController = UINavigationController()
|
||||||
self.setting = setting
|
self.setting = setting
|
||||||
|
self.appContext = appContext
|
||||||
|
|
||||||
settingsViewController = SettingsViewController(accountName: accountName)
|
settingsViewController = SettingsViewController(accountName: accountName)
|
||||||
}
|
}
|
||||||
|
@ -52,10 +54,13 @@ extension SettingsCoordinator: SettingsViewControllerDelegate {
|
||||||
|
|
||||||
navigationController.pushViewController(generalSettingsViewController, animated: true)
|
navigationController.pushViewController(generalSettingsViewController, animated: true)
|
||||||
case .notifications:
|
case .notifications:
|
||||||
let notificationViewController = NotificationSettingsViewController()
|
|
||||||
|
let currentSetting = appContext.settingService.currentSetting.value
|
||||||
|
let notificationViewController = NotificationSettingsViewController(currentSetting: currentSetting)
|
||||||
notificationViewController.delegate = self
|
notificationViewController.delegate = self
|
||||||
|
|
||||||
navigationController.pushViewController(notificationViewController, animated: true)
|
self.navigationController.pushViewController(notificationViewController, animated: true)
|
||||||
|
|
||||||
case .aboutMastodon:
|
case .aboutMastodon:
|
||||||
let aboutViewController = AboutViewController()
|
let aboutViewController = AboutViewController()
|
||||||
aboutViewController.delegate = self
|
aboutViewController.delegate = self
|
||||||
|
|
|
@ -13,8 +13,8 @@ public typealias NotificationSubscription = Subscription
|
||||||
|
|
||||||
extension Subscription {
|
extension Subscription {
|
||||||
|
|
||||||
public var policy: Mastodon.API.Subscriptions.Policy {
|
public var policy: Mastodon.API.Subscriptions.Policy? {
|
||||||
return Mastodon.API.Subscriptions.Policy(rawValue: policyRaw) ?? .all
|
return Mastodon.API.Subscriptions.Policy(rawValue: policyRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue