mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 00:52:43 +02:00
Configured and applied SwiftFormat
This commit is contained in:
committed by
Stefan Ceriu
parent
ff2e6ddfa7
commit
43c28d23b7
+7
-9
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -25,7 +25,6 @@ import Foundation
|
||||
/// Each bridge should be removed once the underlying Coordinator has been integrated by another Coordinator.
|
||||
@objcMembers
|
||||
final class RoomNotificationSettingsCoordinatorBridgePresenter: NSObject {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -61,11 +60,11 @@ final class RoomNotificationSettingsCoordinatorBridgePresenter: NSObject {
|
||||
viewController.present(navigationController, animated: animated, completion: nil)
|
||||
roomNotificationSettingsCoordinator.start()
|
||||
|
||||
self.coordinator = roomNotificationSettingsCoordinator
|
||||
coordinator = roomNotificationSettingsCoordinator
|
||||
}
|
||||
|
||||
func dismiss(animated: Bool, completion: (() -> Void)?) {
|
||||
guard let coordinator = self.coordinator else {
|
||||
guard let coordinator = coordinator else {
|
||||
return
|
||||
}
|
||||
coordinator.toPresentable().dismiss(animated: animated) {
|
||||
@@ -79,22 +78,21 @@ final class RoomNotificationSettingsCoordinatorBridgePresenter: NSObject {
|
||||
}
|
||||
|
||||
// MARK: - RoomNotificationSettingsCoordinatorDelegate
|
||||
|
||||
extension RoomNotificationSettingsCoordinatorBridgePresenter: RoomNotificationSettingsCoordinatorDelegate {
|
||||
func roomNotificationSettingsCoordinatorDidCancel(_ coordinator: RoomNotificationSettingsCoordinatorType) {
|
||||
self.delegate?.roomNotificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
|
||||
delegate?.roomNotificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
|
||||
}
|
||||
|
||||
func roomNotificationSettingsCoordinatorDidComplete(_ coordinator: RoomNotificationSettingsCoordinatorType) {
|
||||
self.delegate?.roomNotificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
|
||||
delegate?.roomNotificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIAdaptivePresentationControllerDelegate
|
||||
|
||||
extension RoomNotificationSettingsCoordinatorBridgePresenter: UIAdaptivePresentationControllerDelegate {
|
||||
|
||||
func roomNotificationSettingsCoordinatorDidComplete(_ presentationController: UIPresentationController) {
|
||||
self.delegate?.roomNotificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
|
||||
delegate?.roomNotificationSettingsCoordinatorBridgePresenterDelegateDidComplete(self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-11
@@ -15,14 +15,14 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
final class RoomNotificationSettingsCoordinator: RoomNotificationSettingsCoordinatorType {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private var roomNotificationSettingsViewModel: RoomNotificationSettingsViewModelType
|
||||
private let roomNotificationSettingsViewController: UIViewController
|
||||
|
||||
@@ -47,34 +47,35 @@ final class RoomNotificationSettingsCoordinator: RoomNotificationSettingsCoordin
|
||||
roomNotificationService: roomNotificationService,
|
||||
avatarData: avatarData,
|
||||
displayName: room.summary.displayname,
|
||||
roomEncrypted: room.summary.isEncrypted)
|
||||
roomEncrypted: room.summary.isEncrypted
|
||||
)
|
||||
let avatarService: AvatarServiceProtocol = AvatarService(mediaManager: room.mxSession.mediaManager)
|
||||
let view = RoomNotificationSettings(viewModel: viewModel, presentedModally: presentedModally)
|
||||
.addDependency(avatarService)
|
||||
let viewController = VectorHostingController(rootView: view)
|
||||
self.roomNotificationSettingsViewModel = viewModel
|
||||
self.roomNotificationSettingsViewController = viewController
|
||||
roomNotificationSettingsViewModel = viewModel
|
||||
roomNotificationSettingsViewController = viewController
|
||||
}
|
||||
|
||||
// MARK: - Public methods
|
||||
|
||||
func start() {
|
||||
self.roomNotificationSettingsViewModel.coordinatorDelegate = self
|
||||
func start() {
|
||||
roomNotificationSettingsViewModel.coordinatorDelegate = self
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return self.roomNotificationSettingsViewController
|
||||
roomNotificationSettingsViewController
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - RoomNotificationSettingsViewModelCoordinatorDelegate
|
||||
|
||||
extension RoomNotificationSettingsCoordinator: RoomNotificationSettingsViewModelCoordinatorDelegate {
|
||||
|
||||
func roomNotificationSettingsViewModelDidComplete(_ viewModel: RoomNotificationSettingsViewModelType) {
|
||||
self.delegate?.roomNotificationSettingsCoordinatorDidComplete(self)
|
||||
delegate?.roomNotificationSettingsCoordinatorDidComplete(self)
|
||||
}
|
||||
|
||||
func roomNotificationSettingsViewModelDidCancel(_ viewModel: RoomNotificationSettingsViewModelType) {
|
||||
self.delegate?.roomNotificationSettingsCoordinatorDidCancel(self)
|
||||
delegate?.roomNotificationSettingsCoordinatorDidCancel(self)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -40,4 +40,3 @@ extension RoomNotificationSettingsViewState {
|
||||
roomEncrypted ? VectorL10n.roomNotifsSettingsEncryptedRoomNotice : ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -26,4 +26,3 @@ protocol RoomNotificationSettingsViewStateType {
|
||||
var avatarData: AvatarProtocol? { get }
|
||||
var displayName: String? { get }
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -25,7 +25,7 @@ enum RoomNotificationState: Int {
|
||||
extension RoomNotificationState: CaseIterable { }
|
||||
|
||||
extension RoomNotificationState: Identifiable {
|
||||
var id: Int { self.rawValue }
|
||||
var id: Int { rawValue }
|
||||
}
|
||||
|
||||
extension RoomNotificationState {
|
||||
|
||||
+29
-31
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import Foundation
|
||||
|
||||
final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceType {
|
||||
|
||||
typealias Completion = () -> Void
|
||||
|
||||
// MARK: - Properties
|
||||
@@ -50,11 +49,11 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
// MARK: - Public
|
||||
|
||||
func observeNotificationState(listener: @escaping RoomNotificationStateCallback) {
|
||||
|
||||
let observer = NotificationCenter.default.addObserver(
|
||||
forName: NSNotification.Name(rawValue: kMXNotificationCenterDidUpdateRules),
|
||||
object: nil,
|
||||
queue: OperationQueue.main) { [weak self] _ in
|
||||
queue: OperationQueue.main
|
||||
) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
listener(self.room.notificationState)
|
||||
}
|
||||
@@ -88,7 +87,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
}
|
||||
|
||||
guard let rule = room.overridePushRule else {
|
||||
self.addPushRuleToMute(completion: completion)
|
||||
addPushRuleToMute(completion: completion)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -96,7 +95,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
MXLog.debug("[RoomNotificationSettingsService] Request in progress: ignore push rule update")
|
||||
completion()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// if the user defined one, use it
|
||||
if rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify) {
|
||||
@@ -130,7 +129,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
MXLog.debug("[MXRoom+Riot] Request in progress: ignore push rule update")
|
||||
completion()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// if the user defined one, use it
|
||||
if rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify) {
|
||||
@@ -140,11 +139,10 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
self.addPushRuleToMentionOnly(completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func allMessages(completion: @escaping Completion) {
|
||||
if !room.isMentionsOnly && !room.isMuted {
|
||||
if !room.isMentionsOnly, !room.isMuted {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
@@ -172,7 +170,8 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
room.roomId,
|
||||
notify: false,
|
||||
sound: false,
|
||||
highlight: false)
|
||||
highlight: false
|
||||
)
|
||||
}
|
||||
|
||||
private func addPushRuleToMute(completion: @escaping Completion) {
|
||||
@@ -207,18 +206,19 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
private func enablePushRule(rule: MXPushRule, completion: @escaping Completion) {
|
||||
handleUpdateCallback(completion) {
|
||||
// No way to check whether this notification concerns the push rule. Consider the change is applied.
|
||||
return true
|
||||
true
|
||||
}
|
||||
handleFailureCallback(completion)
|
||||
|
||||
room.mxSession.notificationCenter.enableRule(rule, isEnabled: true)
|
||||
}
|
||||
|
||||
private func handleUpdateCallback(_ completion: @escaping Completion, releaseCheck: @escaping () -> Bool) {
|
||||
private func handleUpdateCallback(_ completion: @escaping Completion, releaseCheck: @escaping () -> Bool) {
|
||||
notificationCenterDidUpdateObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSNotification.Name(rawValue: kMXNotificationCenterDidUpdateRules),
|
||||
object: nil,
|
||||
queue: OperationQueue.main) { [weak self] _ in
|
||||
queue: OperationQueue.main
|
||||
) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
if releaseCheck() {
|
||||
self.removeObservers()
|
||||
@@ -231,7 +231,8 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
notificationCenterDidFailObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSNotification.Name(rawValue: kMXNotificationCenterDidFailRulesUpdate),
|
||||
object: nil,
|
||||
queue: OperationQueue.main) { [weak self] _ in
|
||||
queue: OperationQueue.main
|
||||
) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
self.removeObservers()
|
||||
completion()
|
||||
@@ -239,23 +240,23 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
}
|
||||
|
||||
func removeObservers() {
|
||||
if let observer = self.notificationCenterDidUpdateObserver {
|
||||
if let observer = notificationCenterDidUpdateObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
self.notificationCenterDidUpdateObserver = nil
|
||||
notificationCenterDidUpdateObserver = nil
|
||||
}
|
||||
|
||||
if let observer = self.notificationCenterDidFailObserver {
|
||||
if let observer = notificationCenterDidFailObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
self.notificationCenterDidFailObserver = nil
|
||||
notificationCenterDidFailObserver = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension MXRoom {
|
||||
public var isMuted: Bool {
|
||||
public extension MXRoom {
|
||||
var isMuted: Bool {
|
||||
// Check whether an override rule has been defined with the roomm id as rule id.
|
||||
// This kind of rule is created to mute the room
|
||||
guard let rule = self.overridePushRule,
|
||||
guard let rule = overridePushRule,
|
||||
rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify),
|
||||
rule.conditionIsEnabled(kind: .eventMatch, for: roomId) else {
|
||||
return false
|
||||
@@ -263,7 +264,7 @@ extension MXRoom {
|
||||
return rule.enabled
|
||||
}
|
||||
|
||||
public var isMentionsOnly: Bool {
|
||||
var isMentionsOnly: Bool {
|
||||
// Check push rules at room level
|
||||
guard let rule = roomPushRule else { return false }
|
||||
return rule.enabled && rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify)
|
||||
@@ -271,8 +272,7 @@ extension MXRoom {
|
||||
}
|
||||
|
||||
// We could move these to their own file and make available in global namespace or move to sdk but they are only used here at the moment
|
||||
fileprivate extension MXRoom {
|
||||
|
||||
private extension MXRoom {
|
||||
typealias Completion = () -> Void
|
||||
func getRoomRule(from rules: [Any]) -> MXPushRule? {
|
||||
guard let pushRules = rules as? [MXPushRule] else {
|
||||
@@ -285,19 +285,18 @@ fileprivate extension MXRoom {
|
||||
var overridePushRule: MXPushRule? {
|
||||
guard let overrideRules = mxSession.notificationCenter.rules.global.override else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return getRoomRule(from: overrideRules)
|
||||
}
|
||||
|
||||
var roomPushRule: MXPushRule? {
|
||||
guard let roomRules = mxSession.notificationCenter.rules.global.room else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return getRoomRule(from: roomRules)
|
||||
}
|
||||
|
||||
var notificationState: RoomNotificationState {
|
||||
|
||||
if isMuted {
|
||||
return .mute
|
||||
}
|
||||
@@ -306,10 +305,9 @@ fileprivate extension MXRoom {
|
||||
}
|
||||
return .all
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileprivate extension MXPushRule {
|
||||
private extension MXPushRule {
|
||||
func actionsContains(actionType: MXPushRuleActionType) -> Bool {
|
||||
guard let actions = actions as? [MXPushRuleAction] else {
|
||||
return false
|
||||
@@ -323,8 +321,8 @@ fileprivate extension MXPushRule {
|
||||
}
|
||||
let ruleContainsCondition = conditions.contains { condition in
|
||||
guard case kind = MXPushRuleConditionType(identifier: condition.kind),
|
||||
let key = condition.parameters["key"] as? String,
|
||||
let pattern = condition.parameters["pattern"] as? String
|
||||
let key = condition.parameters["key"] as? String,
|
||||
let pattern = condition.parameters["pattern"] as? String
|
||||
else { return false }
|
||||
return key == "room_id" && pattern == roomId
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import Foundation
|
||||
|
||||
class MockRoomNotificationSettingsService: RoomNotificationSettingsServiceType {
|
||||
|
||||
static let example = MockRoomNotificationSettingsService(initialState: .all)
|
||||
|
||||
var listener: RoomNotificationStateCallback?
|
||||
@@ -32,7 +31,7 @@ class MockRoomNotificationSettingsService: RoomNotificationSettingsServiceType {
|
||||
}
|
||||
|
||||
func update(state: RoomNotificationState, completion: @escaping UpdateRoomNotificationStateCompletion) {
|
||||
self.notificationState = state
|
||||
notificationState = state
|
||||
completion()
|
||||
listener?(state)
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -20,7 +20,6 @@ typealias UpdateRoomNotificationStateCompletion = () -> Void
|
||||
typealias RoomNotificationStateCallback = (RoomNotificationState) -> Void
|
||||
|
||||
protocol RoomNotificationSettingsServiceType {
|
||||
|
||||
func observeNotificationState(listener: @escaping RoomNotificationStateCallback)
|
||||
func update(state: RoomNotificationState, completion: @escaping UpdateRoomNotificationStateCompletion)
|
||||
var notificationState: RoomNotificationState { get }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct FormPickerItem: View {
|
||||
|
||||
typealias TapCallback = () -> Void
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
@@ -53,7 +52,6 @@ struct FormPickerItem: View {
|
||||
}
|
||||
|
||||
struct FormPickerItem_Previews: PreviewProvider {
|
||||
|
||||
static let items = ["Item 1", "Item 2", "Item 3"]
|
||||
static var selected: String = items[0]
|
||||
static var previews: some View {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct FormSectionFooter: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var text: String
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct FormSectionHeader: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var text: String
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct RoomNotificationSettings: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
|
||||
@ObservedObject var viewModel: RoomNotificationSettingsSwiftUIViewModel
|
||||
@@ -42,7 +41,7 @@ struct RoomNotificationSettings: View {
|
||||
|
||||
var body: some View {
|
||||
VectorForm {
|
||||
if let avatarData = viewModel.viewState.avatarData as? AvatarInputProtocol {
|
||||
if let avatarData = viewModel.viewState.avatarData as? AvatarInputProtocol {
|
||||
RoomNotificationSettingsHeader(
|
||||
avatarData: avatarData,
|
||||
displayName: viewModel.viewState.displayName
|
||||
@@ -74,7 +73,6 @@ struct RoomNotificationSettings: View {
|
||||
}
|
||||
|
||||
struct RoomNotificationSettings_Previews: PreviewProvider {
|
||||
|
||||
static let mockViewModel = RoomNotificationSettingsSwiftUIViewModel(
|
||||
roomNotificationService: MockRoomNotificationSettingsService.example,
|
||||
avatarData: MockAvatarInput.example,
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct RoomNotificationSettingsHeader: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var avatarData: AvatarInputProtocol
|
||||
var displayName: String?
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import SwiftUI
|
||||
|
||||
struct VectorForm<Content: View>: View {
|
||||
|
||||
@Environment(\.theme) var theme: ThemeSwiftUI
|
||||
var content: () -> Content
|
||||
|
||||
@@ -38,12 +37,10 @@ struct VectorForm<Content: View>: View {
|
||||
)
|
||||
.background(theme.colors.system)
|
||||
.edgesIgnoringSafeArea(.bottom)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct VectorForm_Previews: PreviewProvider {
|
||||
|
||||
static var previews: some View {
|
||||
Group {
|
||||
VectorForm {
|
||||
|
||||
+3
-4
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,17 +14,16 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
class RoomNotificationSettingsSwiftUIViewModel: RoomNotificationSettingsViewModel, ObservableObject {
|
||||
|
||||
@Published var viewState: RoomNotificationSettingsViewState
|
||||
|
||||
lazy var cancellables = Set<AnyCancellable>()
|
||||
|
||||
override init(roomNotificationService: RoomNotificationSettingsServiceType, initialState: RoomNotificationSettingsViewState) {
|
||||
self.viewState = initialState
|
||||
viewState = initialState
|
||||
super.init(roomNotificationService: roomNotificationService, initialState: initialState)
|
||||
}
|
||||
|
||||
|
||||
+12
-17
@@ -16,11 +16,10 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModelType {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -40,12 +39,10 @@ class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModelType {
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(
|
||||
roomNotificationService: RoomNotificationSettingsServiceType,
|
||||
initialState: RoomNotificationSettingsViewState
|
||||
) {
|
||||
init(roomNotificationService: RoomNotificationSettingsServiceType,
|
||||
initialState: RoomNotificationSettingsViewState) {
|
||||
self.roomNotificationService = roomNotificationService
|
||||
self.state = initialState
|
||||
state = initialState
|
||||
|
||||
self.roomNotificationService.observeNotificationState { [weak self] state in
|
||||
guard let self = self else { return }
|
||||
@@ -53,12 +50,10 @@ class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModelType {
|
||||
}
|
||||
}
|
||||
|
||||
convenience init(
|
||||
roomNotificationService: RoomNotificationSettingsServiceType,
|
||||
avatarData: AvatarProtocol?,
|
||||
displayName: String?,
|
||||
roomEncrypted: Bool
|
||||
) {
|
||||
convenience init(roomNotificationService: RoomNotificationSettingsServiceType,
|
||||
avatarData: AvatarProtocol?,
|
||||
displayName: String?,
|
||||
roomEncrypted: Bool) {
|
||||
let notificationState = Self.mapNotificationStateOnRead(encrypted: roomEncrypted, state: roomNotificationService.notificationState)
|
||||
|
||||
let initialState = RoomNotificationSettingsViewState(
|
||||
@@ -71,16 +66,16 @@ class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModelType {
|
||||
self.init(roomNotificationService: roomNotificationService, initialState: initialState)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
// MARK: - Public
|
||||
|
||||
func process(viewAction: RoomNotificationSettingsViewAction) {
|
||||
switch viewAction {
|
||||
case .load:
|
||||
update(viewState: self.state)
|
||||
update(viewState: state)
|
||||
case .selectNotificationState(let state):
|
||||
self.state.notificationState = state
|
||||
case .save:
|
||||
self.state.saving = true
|
||||
state.saving = true
|
||||
roomNotificationService.update(state: state.notificationState) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.state.saving = false
|
||||
@@ -103,6 +98,6 @@ class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModelType {
|
||||
}
|
||||
|
||||
func update(viewState: RoomNotificationSettingsViewState) {
|
||||
self.viewDelegate?.roomNotificationSettingsViewModel(self, didUpdateViewState: viewState)
|
||||
viewDelegate?.roomNotificationSettingsViewModel(self, didUpdateViewState: viewState)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -28,8 +28,7 @@ protocol RoomNotificationSettingsViewModelCoordinatorDelegate: AnyObject {
|
||||
}
|
||||
|
||||
/// Protocol describing the view model used by `RoomNotificationSettingsViewController`
|
||||
protocol RoomNotificationSettingsViewModelType {
|
||||
|
||||
protocol RoomNotificationSettingsViewModelType {
|
||||
var viewDelegate: RoomNotificationSettingsViewModelViewDelegate? { get set }
|
||||
var coordinatorDelegate: RoomNotificationSettingsViewModelCoordinatorDelegate? { get set }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user