Run SwiftFormat.

This commit is contained in:
Doug
2026-05-27 14:38:50 +01:00
committed by Doug
parent 5138e05e47
commit fa67713726
573 changed files with 2426 additions and 2426 deletions
@@ -38,7 +38,7 @@ final class NotificationSettingsScreenCoordinator: CoordinatorProtocol {
init(parameters: NotificationSettingsScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = NotificationSettingsScreenViewModel(appSettings: parameters.appSettings,
userNotificationCenter: parameters.userNotificationCenter,
notificationToneManager: NotificationToneManager(appSettings: parameters.appSettings),
@@ -26,7 +26,7 @@ struct NotificationSettingsScreenViewState: BindableState {
var showSystemNotificationsAlert: Bool {
bindings.enableNotifications && isUserPermissionGranted == false
}
var settings: NotificationSettingsScreenSettings?
var applyingChange = false
var selectedAlertTone: NotificationTone
@@ -21,11 +21,11 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
@CancellableTask private var fetchSettingsTask: Task<Void, Error>?
private let notificationTonePreviewer: AudioPlayerProtocol
private let notificationToneManager: NotificationToneManagerProtocol
var actions: AnyPublisher<NotificationSettingsScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(appSettings: AppSettings,
userNotificationCenter: UserNotificationCenterProtocol,
notificationToneManager: NotificationToneManagerProtocol,
@@ -44,7 +44,7 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
isModallyPresented: isModallyPresented,
selectedAlertTone: appSettings.selectedNotificationTone ?? NotificationToneManager.defaultElementXMessageTone,
availableCustomTones: notificationToneManager.customTones()))
// Listen for changes to AppSettings.
appSettings.$enableNotifications
.weakAssign(to: \.state.bindings.enableNotifications, on: self)
@@ -75,7 +75,7 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
func fetchInitialContent() {
fetchSettings()
}
// MARK: - Public
override func process(viewAction: NotificationSettingsScreenViewAction) {
@@ -117,11 +117,11 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
}
// MARK: - Private
func readSystemAuthorizationStatus() async {
state.isUserPermissionGranted = await userNotificationCenter.authorizationStatus() == .authorized
}
func toggleNotifications() {
appSettings.enableNotifications.toggle()
}
@@ -161,11 +161,11 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
// Group chats
var groupChatsMode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: false, isOneToOne: false)
let encryptedGroupChatsMode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: true, isOneToOne: false)
// Direct chats
var directChatsMode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: false, isOneToOne: true)
let encryptedDirectChatsMode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: true, isOneToOne: true)
// Old clients were having specific settings for encrypted and unencrypted rooms,
// so it's possible for `group chats` and `direct chats` settings to be inconsistent (e.g. encrypted `direct chats` can have a different mode that unencrypted `direct chats`)
if groupChatsMode != encryptedGroupChatsMode {
@@ -183,16 +183,16 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
let roomMentionsEnabled = try? await notificationSettingsProxy.isRoomMentionEnabled()
let callEnabled = try? await notificationSettingsProxy.isCallEnabled()
let invitationsEnabled = try? await notificationSettingsProxy.isInviteForMeEnabled()
guard !Task.isCancelled else { return }
let notificationSettings = NotificationSettingsScreenSettings(groupChatsMode: groupChatsMode,
directChatsMode: directChatsMode,
roomMentionsEnabled: roomMentionsEnabled,
callsEnabled: callEnabled,
invitationsEnabled: invitationsEnabled,
inconsistentSettings: inconsistentSettings)
state.settings = notificationSettings
state.bindings.roomMentionsEnabled = notificationSettings.roomMentionsEnabled ?? false
state.bindings.callsEnabled = notificationSettings.callsEnabled ?? false
@@ -234,7 +234,7 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
}
state.applyingChange = false
}
func enableCalls(_ enable: Bool) async {
guard let notificationSettings = state.settings else { return }
do {
@@ -260,7 +260,7 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
}
state.applyingChange = false
}
/// Imports the audio file at the given sandboxed URL into the tone library, refreshing the available custom tones on success.
private func addCustomAlertTone(from urlResult: Result<URL, Error>) async {
do {
@@ -290,13 +290,13 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
MXLog.error("Error setting selected alert tone to designated location in filesystem: \(error)")
}
}
/// Deletes the given tones from the library. If the active tone is deleted, the selection resets to the default.
private func deleteAlertTones(_ tones: [NotificationTone]) {
for tone in tones {
do {
try notificationToneManager.deleteCustomTone(tone)
if tone == state.selectedAlertTone {
appSettings.selectedNotificationTone = nil
}
@@ -38,7 +38,7 @@ struct NotificationSettingsScreen: View {
if context.viewState.settings?.invitationsEnabled != nil {
additionalSettingsSection
}
soundSelectionSection
}
}
@@ -126,7 +126,7 @@ struct NotificationSettingsScreen: View {
.compoundListSectionHeader()
}
}
private var mentionsSection: some View {
Section {
ListRow(label: .plain(title: L10n.screenNotificationSettingsRoomMentionLabel),
@@ -171,7 +171,7 @@ struct NotificationSettingsScreen: View {
.compoundListSectionHeader()
}
}
@ViewBuilder
private var soundSelectionSection: some View {
Section {
@@ -185,12 +185,12 @@ struct NotificationSettingsScreen: View {
Text(L10n.screenNotificationSettingsSoundSectionTitle)
.compoundListSectionHeader()
}
Section(isExpanded: $context.shouldShowAlertSounds) {
presetSoundSelectionSection
} header: { }
}
private var presetSoundSelectionSection: some View {
ForEach(NotificationToneManager.allDefaultAlerts, id: \.filename) { alertTone in
ListRow(label: .plain(title: alertTone.label),
@@ -199,7 +199,7 @@ struct NotificationSettingsScreen: View {
})
}
}
@ViewBuilder
private var customSoundSelectionSection: some View {
ForEach(context.viewState.availableCustomTones, id: \.filename) { alertTone in
@@ -212,10 +212,10 @@ struct NotificationSettingsScreen: View {
let tones = indices.map {
context.viewState.availableCustomTones[$0]
}
context.send(viewAction: .deleteCustomAlertTones(tones))
}
ListRow(label: .plain(title: L10n.screenNotificationSettingsSoundCustomSoundButtonTitle),
kind: .button {
context.shouldShowCustomAlertTonePicker = true
@@ -231,7 +231,7 @@ struct NotificationSettingsScreen: View {
context.send(viewAction: .addedCustomAlertTone($0))
}
}
private var configurationMismatchSection: some View {
Section {
ListRow(kind: .custom {
@@ -278,9 +278,9 @@ struct NotificationSettingsScreen_Previews: PreviewProvider, TestablePreview {
}
notificationSettingsProxy.isRoomMentionEnabledReturnValue = true
notificationSettingsProxy.isCallEnabledReturnValue = false
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "John Doe"))))
var viewModel = NotificationSettingsScreenViewModel(appSettings: appSettings,
userNotificationCenter: notificationCenter,
notificationToneManager: NotificationToneManagerMock(.init()),
@@ -310,7 +310,7 @@ struct NotificationSettingsScreen_Previews: PreviewProvider, TestablePreview {
notificationSettingsProxy.isCallEnabledReturnValue = false
let userSession = UserSessionMock(.init(clientProxy: ClientProxyMock(.init(userID: "John Doe"))))
var viewModel = NotificationSettingsScreenViewModel(appSettings: appSettings,
userNotificationCenter: notificationCenter,
notificationToneManager: NotificationToneManagerMock(.init()),
@@ -320,7 +320,7 @@ struct NotificationSettingsScreen_Previews: PreviewProvider, TestablePreview {
viewModel.fetchInitialContent()
return viewModel
}()
static var previews: some View {
NotificationSettingsScreen(context: viewModel.context)
.snapshotPreferences(expect: viewModel.context.observe(\.viewState.settings).map { $0 != nil })