Configured and applied SwiftFormat

This commit is contained in:
Stefan Ceriu
2022-09-27 10:17:22 +03:00
committed by Stefan Ceriu
parent ff2e6ddfa7
commit 43c28d23b7
663 changed files with 2329 additions and 2840 deletions
@@ -16,12 +16,11 @@
limitations under the License.
*/
import Foundation
import Combine
import Foundation
import SwiftUI
final class NotificationSettingsViewModel: NotificationSettingsViewModelType, ObservableObject {
// MARK: - Properties
// MARK: Private
@@ -46,7 +45,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
init(notificationSettingsService: NotificationSettingsServiceType, ruleIds: [NotificationPushRuleId], initialState: NotificationSettingsViewState) {
self.notificationSettingsService = notificationSettingsService
self.ruleIds = ruleIds
self.viewState = initialState
viewState = initialState
// Observe when the rules are updated, to subsequently update the state of the settings.
notificationSettingsService.rulesPublisher
@@ -57,11 +56,11 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
if ruleIds.contains(.keywords) {
// Publisher of all the keyword push rules (keyword rules do not start with '.')
let keywordsRules = notificationSettingsService.contentRulesPublisher
.map { $0.filter { !$0.ruleId.starts(with: ".")} }
.map { $0.filter { !$0.ruleId.starts(with: ".") } }
// Map to just the keyword strings
let keywords = keywordsRules
.map { Set($0.compactMap { $0.ruleId }) }
.map { Set($0.compactMap(\.ruleId)) }
// Update the keyword set
keywords
@@ -100,7 +99,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
}
convenience init(notificationSettingsService: NotificationSettingsServiceType, ruleIds: [NotificationPushRuleId]) {
let ruleState = Dictionary(uniqueKeysWithValues: ruleIds.map({ ($0, selected: true) }))
let ruleState = Dictionary(uniqueKeysWithValues: ruleIds.map { ($0, selected: true) })
self.init(notificationSettingsService: notificationSettingsService, ruleIds: ruleIds, initialState: NotificationSettingsViewState(saving: false, ruleIds: ruleIds, selectionState: ruleState))
}
@@ -125,7 +124,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
private func updateKeywords(isChecked: Bool) {
guard !keywordsOrdered.isEmpty else {
self.viewState.selectionState[.keywords]?.toggle()
viewState.selectionState[.keywords]?.toggle()
return
}
// Get the static definition and update the actions and enabled state for every keyword.
@@ -149,22 +148,23 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
}
func remove(keyword: String) {
keywordsOrdered = keywordsOrdered.filter({ $0 != keyword })
keywordsOrdered = keywordsOrdered.filter { $0 != keyword }
notificationSettingsService.remove(keyword: keyword)
}
// MARK: - Private
private func rulesUpdated(newRules: [NotificationPushRuleType]) {
for rule in newRules {
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId),
ruleIds.contains(ruleId) else { continue }
self.viewState.selectionState[ruleId] = self.isChecked(rule: rule)
viewState.selectionState[ruleId] = isChecked(rule: rule)
}
}
private func keywordRuleUpdated(anyEnabled: Bool) {
if !keywordsOrdered.isEmpty {
self.viewState.selectionState[.keywords] = anyEnabled
viewState.selectionState[.keywords] = anyEnabled
}
}
@@ -178,7 +178,7 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
guard let ruleId = NotificationPushRuleId(rawValue: rule.ruleId) else { return false }
let firstIndex = NotificationIndex.allCases.first { nextIndex in
return rule.matches(standardActions: ruleId.standardActions(for: nextIndex))
rule.matches(standardActions: ruleId.standardActions(for: nextIndex))
}
guard let index = firstIndex else {
@@ -187,5 +187,4 @@ final class NotificationSettingsViewModel: NotificationSettingsViewModelType, Ob
return index.enabled
}
}