mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Display the list of rooms with user-defined notification settings (#1535)
This commit is contained in:
@@ -644,6 +644,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
private func presentNotificationSettingsScreen(animated: Bool) async {
|
||||
let navigationCoordinator = NavigationStackCoordinator()
|
||||
let parameters = await NotificationSettingsScreenCoordinatorParameters(navigationStackCoordinator: navigationCoordinator,
|
||||
userSession: userSession,
|
||||
userNotificationCenter: UNUserNotificationCenter.current(),
|
||||
notificationSettings: userSession.clientProxy.notificationSettings(),
|
||||
isModallyPresented: true)
|
||||
|
||||
@@ -10,10 +10,6 @@ import Foundation
|
||||
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
|
||||
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
|
||||
public enum L10n {
|
||||
/// Plural format key: "%#@COUNT@"
|
||||
public static func countSRoomsWeb(_ p1: Int) -> String {
|
||||
return L10n.tr("Localizable", "%(count)s rooms_web", p1)
|
||||
}
|
||||
/// Hide password
|
||||
public static var a11yHidePassword: String { return L10n.tr("Localizable", "a11y_hide_password") }
|
||||
/// Send files
|
||||
@@ -692,8 +688,14 @@ public enum L10n {
|
||||
public static var screenNotificationSettingsCallsLabel: String { return L10n.tr("Localizable", "screen_notification_settings_calls_label") }
|
||||
/// Direct chats
|
||||
public static var screenNotificationSettingsDirectChats: String { return L10n.tr("Localizable", "screen_notification_settings_direct_chats") }
|
||||
/// Custom setting per chat
|
||||
public static var screenNotificationSettingsEditCustomSettingsSectionTitle: String { return L10n.tr("Localizable", "screen_notification_settings_edit_custom_settings_section_title") }
|
||||
/// An error occurred while updating the notification setting.
|
||||
public static var screenNotificationSettingsEditFailedUpdatingDefaultMode: String { return L10n.tr("Localizable", "screen_notification_settings_edit_failed_updating_default_mode") }
|
||||
/// All messages
|
||||
public static var screenNotificationSettingsEditModeAllMessages: String { return L10n.tr("Localizable", "screen_notification_settings_edit_mode_all_messages") }
|
||||
/// Mentions and Keywords only
|
||||
public static var screenNotificationSettingsEditModeMentionsAndKeywords: String { return L10n.tr("Localizable", "screen_notification_settings_edit_mode_mentions_and_keywords") }
|
||||
/// On direct chats, notify me for
|
||||
public static var screenNotificationSettingsEditScreenDirectSectionHeader: String { return L10n.tr("Localizable", "screen_notification_settings_edit_screen_direct_section_header") }
|
||||
/// On group chats, notify me for
|
||||
@@ -848,6 +850,8 @@ public enum L10n {
|
||||
public static var screenRoomNotificationSettingsDefaultSettingFootnoteContentLink: String { return L10n.tr("Localizable", "screen_room_notification_settings_default_setting_footnote_content_link") }
|
||||
/// Default setting
|
||||
public static var screenRoomNotificationSettingsDefaultSettingTitle: String { return L10n.tr("Localizable", "screen_room_notification_settings_default_setting_title") }
|
||||
/// Remove custom setting
|
||||
public static var screenRoomNotificationSettingsEditRemoveSetting: String { return L10n.tr("Localizable", "screen_room_notification_settings_edit_remove_setting") }
|
||||
/// An error occurred while loading notification settings.
|
||||
public static var screenRoomNotificationSettingsErrorLoadingSettings: String { return L10n.tr("Localizable", "screen_room_notification_settings_error_loading_settings") }
|
||||
/// Failed restoring the default mode, please try again.
|
||||
@@ -858,6 +862,8 @@ public enum L10n {
|
||||
public static var screenRoomNotificationSettingsModeAllMessages: String { return L10n.tr("Localizable", "screen_room_notification_settings_mode_all_messages") }
|
||||
/// Mentions and Keywords only
|
||||
public static var screenRoomNotificationSettingsModeMentionsAndKeywords: String { return L10n.tr("Localizable", "screen_room_notification_settings_mode_mentions_and_keywords") }
|
||||
/// In this room, notify me for
|
||||
public static var screenRoomNotificationSettingsRoomCustomSettingsTitle: String { return L10n.tr("Localizable", "screen_room_notification_settings_room_custom_settings_title") }
|
||||
/// Show less
|
||||
public static var screenRoomReactionsShowLess: String { return L10n.tr("Localizable", "screen_room_reactions_show_less") }
|
||||
/// Show more
|
||||
@@ -1194,13 +1200,6 @@ public enum L10n {
|
||||
public static var testLanguageIdentifier: String { return L10n.tr("Localizable", "test_language_identifier") }
|
||||
/// en
|
||||
public static var testUntranslatedDefaultLanguageIdentifier: String { return L10n.tr("Localizable", "test_untranslated_default_language_identifier") }
|
||||
|
||||
public enum UseAnIdentityServerToInviteByEmail {
|
||||
public enum DefaultUseTheDefaultDefaultIdentityServerNameSDefaultOrManageInSettingsSettingsSettings {
|
||||
/// Use an identity server to invite by email. <default>Use the default (%(defaultIdentityServerName)s)</default> or manage in <settings>Settings</settings>.
|
||||
public static var web: String { return L10n.tr("Localizable", "Use an identity server to invite by email. <default>Use the default (%(defaultIdentityServerName)s)</default> or manage in <settings>Settings</settings>._web") }
|
||||
}
|
||||
}
|
||||
}
|
||||
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
|
||||
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
|
||||
|
||||
@@ -365,6 +365,31 @@ class NotificationSettingsProxyMock: NotificationSettingsProxyProtocol {
|
||||
setNotificationModeRoomIdModeReceivedInvocations.append((roomId: roomId, mode: mode))
|
||||
try await setNotificationModeRoomIdModeClosure?(roomId, mode)
|
||||
}
|
||||
//MARK: - getUserDefinedRoomNotificationMode
|
||||
|
||||
var getUserDefinedRoomNotificationModeRoomIdThrowableError: Error?
|
||||
var getUserDefinedRoomNotificationModeRoomIdCallsCount = 0
|
||||
var getUserDefinedRoomNotificationModeRoomIdCalled: Bool {
|
||||
return getUserDefinedRoomNotificationModeRoomIdCallsCount > 0
|
||||
}
|
||||
var getUserDefinedRoomNotificationModeRoomIdReceivedRoomId: String?
|
||||
var getUserDefinedRoomNotificationModeRoomIdReceivedInvocations: [String] = []
|
||||
var getUserDefinedRoomNotificationModeRoomIdReturnValue: RoomNotificationModeProxy?
|
||||
var getUserDefinedRoomNotificationModeRoomIdClosure: ((String) async throws -> RoomNotificationModeProxy?)?
|
||||
|
||||
func getUserDefinedRoomNotificationMode(roomId: String) async throws -> RoomNotificationModeProxy? {
|
||||
if let error = getUserDefinedRoomNotificationModeRoomIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
getUserDefinedRoomNotificationModeRoomIdCallsCount += 1
|
||||
getUserDefinedRoomNotificationModeRoomIdReceivedRoomId = roomId
|
||||
getUserDefinedRoomNotificationModeRoomIdReceivedInvocations.append(roomId)
|
||||
if let getUserDefinedRoomNotificationModeRoomIdClosure = getUserDefinedRoomNotificationModeRoomIdClosure {
|
||||
return try await getUserDefinedRoomNotificationModeRoomIdClosure(roomId)
|
||||
} else {
|
||||
return getUserDefinedRoomNotificationModeRoomIdReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - getDefaultRoomNotificationMode
|
||||
|
||||
var getDefaultRoomNotificationModeIsEncryptedIsOneToOneCallsCount = 0
|
||||
@@ -586,6 +611,27 @@ class NotificationSettingsProxyMock: NotificationSettingsProxyProtocol {
|
||||
setCallEnabledEnabledReceivedInvocations.append(enabled)
|
||||
try await setCallEnabledEnabledClosure?(enabled)
|
||||
}
|
||||
//MARK: - getRoomsWithUserDefinedRules
|
||||
|
||||
var getRoomsWithUserDefinedRulesThrowableError: Error?
|
||||
var getRoomsWithUserDefinedRulesCallsCount = 0
|
||||
var getRoomsWithUserDefinedRulesCalled: Bool {
|
||||
return getRoomsWithUserDefinedRulesCallsCount > 0
|
||||
}
|
||||
var getRoomsWithUserDefinedRulesReturnValue: [String]!
|
||||
var getRoomsWithUserDefinedRulesClosure: (() async throws -> [String])?
|
||||
|
||||
func getRoomsWithUserDefinedRules() async throws -> [String] {
|
||||
if let error = getRoomsWithUserDefinedRulesThrowableError {
|
||||
throw error
|
||||
}
|
||||
getRoomsWithUserDefinedRulesCallsCount += 1
|
||||
if let getRoomsWithUserDefinedRulesClosure = getRoomsWithUserDefinedRulesClosure {
|
||||
return try await getRoomsWithUserDefinedRulesClosure()
|
||||
} else {
|
||||
return getRoomsWithUserDefinedRulesReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
class RoomMemberProxyMock: RoomMemberProxyProtocol {
|
||||
var userID: String {
|
||||
|
||||
@@ -36,6 +36,8 @@ extension NotificationSettingsProxyMock {
|
||||
callbacks = configuration.callback
|
||||
getNotificationSettingsRoomIdIsEncryptedIsOneToOneReturnValue = configuration.roomMode
|
||||
getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = configuration.defaultRoomMode
|
||||
getUserDefinedRoomNotificationModeRoomIdReturnValue = configuration.roomMode.isDefault ? nil : configuration.roomMode.mode
|
||||
getRoomsWithUserDefinedRulesReturnValue = []
|
||||
|
||||
setNotificationModeRoomIdModeClosure = { [weak self] _, mode in
|
||||
guard let self else { return }
|
||||
|
||||
@@ -36,6 +36,7 @@ struct A11yIdentifiers {
|
||||
static let invitesScreen = InvitesScreen()
|
||||
static let welcomeScreen = WelcomeScreen()
|
||||
static let migrationScreen = MigrationScreen()
|
||||
static let notificationSettingsEditScreen = NotificationSettingsEditScreen()
|
||||
|
||||
struct AnalyticsPromptScreen {
|
||||
let title = "analytics_prompt-title"
|
||||
@@ -161,4 +162,11 @@ struct A11yIdentifiers {
|
||||
struct MigrationScreen {
|
||||
let message = "migration_screen-message"
|
||||
}
|
||||
|
||||
struct NotificationSettingsEditScreen {
|
||||
let roomNamePrefix = "notification_settings_edit_screen-room_name"
|
||||
func roomName(_ name: String) -> String {
|
||||
"\(roomNamePrefix):\(name)"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,9 +78,12 @@ enum RoomAvatarSizeOnScreen {
|
||||
case home
|
||||
case messageForwarding
|
||||
case details
|
||||
case notificationSettings
|
||||
|
||||
var value: CGFloat {
|
||||
switch self {
|
||||
case .notificationSettings:
|
||||
return 30
|
||||
case .timeline:
|
||||
return 32
|
||||
case .messageForwarding:
|
||||
|
||||
@@ -200,7 +200,8 @@ final class RoomDetailsScreenCoordinator: CoordinatorProtocol {
|
||||
private func presentNotificationSettings() {
|
||||
let roomNotificationSettingsParameters = RoomNotificationSettingsScreenCoordinatorParameters(navigationStackCoordinator: parameters.navigationStackCoordinator,
|
||||
notificationSettingsProxy: parameters.notificationSettings,
|
||||
roomProxy: parameters.roomProxy)
|
||||
roomProxy: parameters.roomProxy,
|
||||
displayAsUserDefinedRoomSettings: false)
|
||||
let roomNotificationSettingsCoordinator = RoomNotificationSettingsScreenCoordinator(parameters: roomNotificationSettingsParameters)
|
||||
roomNotificationSettingsCoordinator.actions.sink { [weak self] actions in
|
||||
switch actions {
|
||||
|
||||
+11
-3
@@ -21,6 +21,7 @@ struct RoomNotificationSettingsScreenCoordinatorParameters {
|
||||
weak var navigationStackCoordinator: NavigationStackCoordinator?
|
||||
let notificationSettingsProxy: NotificationSettingsProxyProtocol
|
||||
let roomProxy: RoomProxyProtocol
|
||||
let displayAsUserDefinedRoomSettings: Bool
|
||||
}
|
||||
|
||||
enum RoomNotificationSettingsScreenCoordinatorAction {
|
||||
@@ -45,7 +46,8 @@ final class RoomNotificationSettingsScreenCoordinator: CoordinatorProtocol {
|
||||
init(parameters: RoomNotificationSettingsScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
viewModel = RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: parameters.notificationSettingsProxy,
|
||||
roomProxy: parameters.roomProxy)
|
||||
roomProxy: parameters.roomProxy,
|
||||
displayAsUserDefinedRoomSettings: parameters.displayAsUserDefinedRoomSettings)
|
||||
}
|
||||
|
||||
func start() {
|
||||
@@ -53,11 +55,17 @@ final class RoomNotificationSettingsScreenCoordinator: CoordinatorProtocol {
|
||||
switch action {
|
||||
case .openGlobalSettings:
|
||||
self?.actionsSubject.send(.presentNotificationSettingsScreen)
|
||||
case .dismiss:
|
||||
self?.parameters.navigationStackCoordinator?.pop(animated: true)
|
||||
}
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(RoomNotificationSettingsScreen(context: viewModel.context))
|
||||
if parameters.displayAsUserDefinedRoomSettings {
|
||||
return AnyView(RoomNotificationSettingsUserDefinedScreen(context: viewModel.context))
|
||||
} else {
|
||||
return AnyView(RoomNotificationSettingsScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+14
-1
@@ -18,6 +18,7 @@ import Foundation
|
||||
|
||||
enum RoomNotificationSettingsScreenViewModelAction {
|
||||
case openGlobalSettings
|
||||
case dismiss
|
||||
}
|
||||
|
||||
enum RoomNotificationSettingsState {
|
||||
@@ -56,6 +57,17 @@ struct RoomNotificationSettingsScreenViewState: BindableState {
|
||||
var availableCustomRoomNotificationModes: [RoomNotificationModeProxy] = [.allMessages, .mentionsAndKeywordsOnly, .mute]
|
||||
var isRestoringDefaultSetting = false
|
||||
var pendingCustomMode: RoomNotificationModeProxy?
|
||||
var displayAsUserDefinedRoomSettings = false
|
||||
var navigationTitle: String
|
||||
var customSettingsSectionHeader: String
|
||||
var deletingCustomSetting = false
|
||||
|
||||
func isSelected(mode: RoomNotificationModeProxy) -> Bool {
|
||||
if case .loaded(let settings) = notificationSettingsState, settings.mode == mode, pendingCustomMode == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
struct RoomNotificationSettingsScreenViewStateBindings {
|
||||
@@ -69,6 +81,7 @@ enum RoomNotificationSettingsScreenViewAction {
|
||||
case changedAllowCustomSettings
|
||||
case setCustomMode(RoomNotificationModeProxy)
|
||||
case customSettingFootnoteLinkTapped
|
||||
case deleteCustomSettingTapped
|
||||
}
|
||||
|
||||
struct RoomNotificationSettingsScreenStrings {
|
||||
@@ -87,7 +100,7 @@ struct RoomNotificationSettingsScreenStrings {
|
||||
|
||||
self.customSettingFootnote = customSettingFootnote
|
||||
}
|
||||
|
||||
|
||||
func string(for mode: RoomNotificationModeProxy) -> String {
|
||||
switch mode {
|
||||
case .allMessages:
|
||||
|
||||
+21
-2
@@ -30,11 +30,16 @@ class RoomNotificationSettingsScreenViewModel: RoomNotificationSettingsScreenVie
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(notificationSettingsProxy: NotificationSettingsProxyProtocol, roomProxy: RoomProxyProtocol) {
|
||||
init(notificationSettingsProxy: NotificationSettingsProxyProtocol, roomProxy: RoomProxyProtocol, displayAsUserDefinedRoomSettings: Bool) {
|
||||
let bindings = RoomNotificationSettingsScreenViewStateBindings()
|
||||
self.notificationSettingsProxy = notificationSettingsProxy
|
||||
self.roomProxy = roomProxy
|
||||
super.init(initialViewState: RoomNotificationSettingsScreenViewState(bindings: bindings))
|
||||
let navigationTitle = displayAsUserDefinedRoomSettings ? roomProxy.roomTitle : L10n.screenRoomDetailsNotificationTitle
|
||||
let customSettingsSectionHeader = displayAsUserDefinedRoomSettings ? L10n.screenRoomNotificationSettingsRoomCustomSettingsTitle : L10n.screenRoomNotificationSettingsCustomSettingsTitle
|
||||
super.init(initialViewState: RoomNotificationSettingsScreenViewState(bindings: bindings,
|
||||
displayAsUserDefinedRoomSettings: displayAsUserDefinedRoomSettings,
|
||||
navigationTitle: navigationTitle,
|
||||
customSettingsSectionHeader: customSettingsSectionHeader))
|
||||
|
||||
setupNotificationSettingsSubscription()
|
||||
fetchNotificationSettings()
|
||||
@@ -50,6 +55,8 @@ class RoomNotificationSettingsScreenViewModel: RoomNotificationSettingsScreenVie
|
||||
setCustomMode(mode)
|
||||
case .customSettingFootnoteLinkTapped:
|
||||
actionsSubject.send(.openGlobalSettings)
|
||||
case .deleteCustomSettingTapped:
|
||||
Task { await deleteCustomSetting() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +84,7 @@ class RoomNotificationSettingsScreenViewModel: RoomNotificationSettingsScreenVie
|
||||
|
||||
private func fetchRoomNotificationSettings() async {
|
||||
do {
|
||||
// `isOneToOne` here is not the same as `isDirect` on the room. From the point of view of the push rule, a one-to-one room is a room with exactly two active members.
|
||||
let settings = try await notificationSettingsProxy.getNotificationSettings(roomId: roomProxy.id,
|
||||
isEncrypted: roomProxy.isEncrypted,
|
||||
isOneToOne: roomProxy.activeMembersCount == 2)
|
||||
@@ -153,4 +161,15 @@ class RoomNotificationSettingsScreenViewModel: RoomNotificationSettingsScreenVie
|
||||
message: L10n.screenRoomNotificationSettingsErrorRestoringDefault)
|
||||
}
|
||||
}
|
||||
|
||||
private func deleteCustomSetting() async {
|
||||
state.deletingCustomSetting = true
|
||||
do {
|
||||
try await notificationSettingsProxy.restoreDefaultNotificationMode(roomId: roomProxy.id)
|
||||
actionsSubject.send(.dismiss)
|
||||
} catch {
|
||||
displayError(.restoreDefaultFailed)
|
||||
}
|
||||
state.deletingCustomSetting = false
|
||||
}
|
||||
}
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct RoomNotificationSettingsCustomSectionView: View {
|
||||
@ObservedObject var context: RoomNotificationSettingsScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
Section {
|
||||
ForEach(context.viewState.availableCustomRoomNotificationModes, id: \.self) { mode in
|
||||
ListRow(label: .plain(title: context.viewState.strings.string(for: mode)),
|
||||
details: (context.viewState.pendingCustomMode == mode) ? .isWaiting(true) : nil,
|
||||
kind: .selection(isSelected: context.viewState.isSelected(mode: mode)) {
|
||||
context.send(viewAction: .setCustomMode(mode))
|
||||
})
|
||||
.disabled(context.viewState.pendingCustomMode != nil)
|
||||
}
|
||||
} header: {
|
||||
Text(context.viewState.customSettingsSectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct RoomNotificationSettingsCustomSectionView_Previews: PreviewProvider {
|
||||
static let viewModel = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(defaultRoomMode: .allMessages, roomMode: .mentionsAndKeywordsOnly))
|
||||
|
||||
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
|
||||
|
||||
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: false)
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
Form {
|
||||
RoomNotificationSettingsCustomSectionView(context: viewModel.context)
|
||||
}
|
||||
.compoundForm()
|
||||
}
|
||||
}
|
||||
+9
-26
@@ -31,14 +31,13 @@ struct RoomNotificationSettingsScreen: View {
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(L10n.screenRoomDetailsNotificationTitle)
|
||||
.navigationTitle(context.viewState.navigationTitle)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .roomNotifications)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@ViewBuilder
|
||||
private var allowCustomSettingSection: some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenRoomNotificationSettingsAllowCustom),
|
||||
@@ -54,7 +53,6 @@ struct RoomNotificationSettingsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var defaultSettingSection: some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: context.viewState.isRestoringDefaultSetting ? L10n.commonLoading : context.viewState.strings.string(for: context.viewState.notificationSettingsState)),
|
||||
@@ -74,21 +72,8 @@ struct RoomNotificationSettingsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var customSettingsSection: some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenRoomNotificationSettingsCustomSettingsTitle),
|
||||
kind: .inlinePicker(selection: $context.customMode,
|
||||
items: context.viewState.availableCustomRoomNotificationModes.map {
|
||||
(title: context.viewState.strings.string(for: $0), tag: $0)
|
||||
}))
|
||||
.onChange(of: context.customMode) { mode in
|
||||
context.send(viewAction: .setCustomMode(mode))
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.screenRoomNotificationSettingsCustomSettingsTitle)
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
RoomNotificationSettingsCustomSectionView(context: context)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +85,9 @@ struct RoomNotificationSettingsScreen_Previews: PreviewProvider {
|
||||
|
||||
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
|
||||
|
||||
let model = RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy)
|
||||
|
||||
return model
|
||||
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: false)
|
||||
}()
|
||||
|
||||
static let viewModelCustom = {
|
||||
@@ -111,12 +95,11 @@ struct RoomNotificationSettingsScreen_Previews: PreviewProvider {
|
||||
|
||||
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
|
||||
|
||||
let model = RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy)
|
||||
|
||||
return model
|
||||
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: false)
|
||||
}()
|
||||
|
||||
|
||||
static var previews: some View {
|
||||
RoomNotificationSettingsScreen(context: viewModel.context)
|
||||
.previewDisplayName("Default")
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct RoomNotificationSettingsUserDefinedScreen: View {
|
||||
@ObservedObject var context: RoomNotificationSettingsScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
RoomNotificationSettingsCustomSectionView(context: context)
|
||||
|
||||
deleteButton
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(context.viewState.navigationTitle)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .roomNotifications)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private var deleteButton: some View {
|
||||
ListRow(label: .action(title: L10n.screenRoomNotificationSettingsEditRemoveSetting,
|
||||
systemIcon: .trash,
|
||||
role: .destructive),
|
||||
details: context.viewState.deletingCustomSetting ? .isWaiting(true) : nil,
|
||||
kind: .button {
|
||||
context.send(viewAction: .deleteCustomSettingTapped)
|
||||
})
|
||||
.disabled(context.viewState.deletingCustomSetting)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct RoomNotificationSettingsUserDefinedScreen_Previews: PreviewProvider {
|
||||
static let viewModel = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(defaultRoomMode: .mentionsAndKeywordsOnly, roomMode: .mentionsAndKeywordsOnly))
|
||||
|
||||
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
|
||||
|
||||
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: true)
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
RoomNotificationSettingsUserDefinedScreen(context: viewModel.context)
|
||||
}
|
||||
}
|
||||
+27
-2
@@ -18,7 +18,9 @@ import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct NotificationSettingsEditScreenCoordinatorParameters {
|
||||
let isDirect: Bool
|
||||
weak var navigationStackCoordinator: NavigationStackCoordinator?
|
||||
let chatType: NotificationSettingsChatType
|
||||
let userSession: UserSessionProtocol
|
||||
let notificationSettings: NotificationSettingsProxyProtocol
|
||||
}
|
||||
|
||||
@@ -37,15 +39,38 @@ final class NotificationSettingsEditScreenCoordinator: CoordinatorProtocol {
|
||||
init(parameters: NotificationSettingsEditScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = NotificationSettingsEditScreenViewModel(isDirect: parameters.isDirect,
|
||||
viewModel = NotificationSettingsEditScreenViewModel(chatType: parameters.chatType,
|
||||
userSession: parameters.userSession,
|
||||
notificationSettingsProxy: parameters.notificationSettings)
|
||||
}
|
||||
|
||||
func start() {
|
||||
viewModel.fetchInitialContent()
|
||||
|
||||
viewModel.actions.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .requestRoomNotificationSettingsPresentation(let roomID):
|
||||
Task { await self.presentRoomNotificationSettings(roomID: roomID) }
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(NotificationSettingsEditScreen(context: viewModel.context))
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func presentRoomNotificationSettings(roomID: String) async {
|
||||
guard let roomProxy = await parameters.userSession.clientProxy.roomForIdentifier(roomID) else { return }
|
||||
|
||||
let roomNotificationSettingsParameters = RoomNotificationSettingsScreenCoordinatorParameters(navigationStackCoordinator: parameters.navigationStackCoordinator,
|
||||
notificationSettingsProxy: parameters.notificationSettings,
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: true)
|
||||
let roomNotificationSettingsCoordinator = RoomNotificationSettingsScreenCoordinator(parameters: roomNotificationSettingsParameters)
|
||||
parameters.navigationStackCoordinator?.push(roomNotificationSettingsCoordinator)
|
||||
}
|
||||
}
|
||||
|
||||
+52
-5
@@ -16,7 +16,9 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
enum NotificationSettingsEditScreenViewModelAction { }
|
||||
enum NotificationSettingsEditScreenViewModelAction {
|
||||
case requestRoomNotificationSettingsPresentation(roomID: String)
|
||||
}
|
||||
|
||||
enum NotificationSettingsEditScreenDefaultMode {
|
||||
case allMessages
|
||||
@@ -26,22 +28,29 @@ enum NotificationSettingsEditScreenDefaultMode {
|
||||
struct NotificationSettingsEditScreenViewState: BindableState {
|
||||
var bindings: NotificationSettingsEditScreenViewStateBindings
|
||||
var strings: NotificationSettingsEditScreenStrings
|
||||
var isDirect: Bool
|
||||
var chatType: NotificationSettingsChatType
|
||||
var availableDefaultModes: [NotificationSettingsEditScreenDefaultMode] = [.allMessages, .mentionsAndKeywordsOnly]
|
||||
var defaultMode: NotificationSettingsEditScreenDefaultMode?
|
||||
var pendingMode: NotificationSettingsEditScreenDefaultMode?
|
||||
var roomsWithUserDefinedMode: [NotificationSettingsEditScreenRoom] = []
|
||||
|
||||
func isSelected(mode: NotificationSettingsEditScreenDefaultMode) -> Bool {
|
||||
pendingMode == nil && defaultMode == mode
|
||||
}
|
||||
|
||||
var displayRoomsWithCustomSettings: Bool {
|
||||
!roomsWithUserDefinedMode.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
struct NotificationSettingsEditScreenViewStateBindings {
|
||||
var searchQuery = ""
|
||||
var alertInfo: AlertInfo<NotificationSettingsEditScreenErrorType>?
|
||||
}
|
||||
|
||||
enum NotificationSettingsEditScreenViewAction {
|
||||
case setMode(NotificationSettingsEditScreenDefaultMode)
|
||||
case selectRoom(roomIdentifier: String)
|
||||
}
|
||||
|
||||
enum NotificationSettingsEditScreenErrorType: Hashable {
|
||||
@@ -52,22 +61,60 @@ struct NotificationSettingsEditScreenStrings {
|
||||
let navigationTitle: String
|
||||
let modeSectionTitle: String
|
||||
|
||||
init(isDirect: Bool) {
|
||||
if isDirect {
|
||||
init(chatType: NotificationSettingsChatType) {
|
||||
switch chatType {
|
||||
case .oneToOneChat:
|
||||
navigationTitle = L10n.screenNotificationSettingsDirectChats
|
||||
modeSectionTitle = L10n.screenNotificationSettingsEditScreenDirectSectionHeader
|
||||
} else {
|
||||
case .groupChat:
|
||||
navigationTitle = L10n.screenNotificationSettingsGroupChats
|
||||
modeSectionTitle = L10n.screenNotificationSettingsEditScreenGroupSectionHeader
|
||||
}
|
||||
}
|
||||
|
||||
func string(for mode: NotificationSettingsEditScreenDefaultMode) -> String {
|
||||
switch mode {
|
||||
case .allMessages:
|
||||
return L10n.screenNotificationSettingsEditModeAllMessages
|
||||
case .mentionsAndKeywordsOnly:
|
||||
return L10n.screenNotificationSettingsEditModeMentionsAndKeywords
|
||||
}
|
||||
}
|
||||
|
||||
func string(for mode: RoomNotificationModeProxy) -> String {
|
||||
switch mode {
|
||||
case .allMessages:
|
||||
return L10n.screenNotificationSettingsModeAll
|
||||
case .mentionsAndKeywordsOnly:
|
||||
return L10n.screenNotificationSettingsModeMentions
|
||||
case .mute:
|
||||
return L10n.commonMute
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NotificationSettingsEditScreenRoom: Identifiable, Equatable {
|
||||
static let placeholderLastMessage = AttributedString("Hidden last message")
|
||||
|
||||
/// The list item identifier can be a real room identifier, a custom one for invalidated entries
|
||||
/// or a completely unique one for empty items and skeletons
|
||||
let id: String
|
||||
|
||||
/// The real room identifier this item points to
|
||||
let roomId: String?
|
||||
|
||||
var name = ""
|
||||
|
||||
var avatarURL: URL?
|
||||
|
||||
var notificationMode: RoomNotificationModeProxy?
|
||||
|
||||
var isPlaceholder = false
|
||||
|
||||
static func placeholder() -> NotificationSettingsEditScreenRoom {
|
||||
NotificationSettingsEditScreenRoom(id: UUID().uuidString,
|
||||
roomId: nil,
|
||||
name: "Placeholder room name",
|
||||
isPlaceholder: true)
|
||||
}
|
||||
}
|
||||
|
||||
+97
-15
@@ -21,27 +21,37 @@ typealias NotificationSettingsEditScreenViewModelType = StateStoreViewModel<Noti
|
||||
|
||||
class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenViewModelType, NotificationSettingsEditScreenViewModelProtocol {
|
||||
private var actionsSubject: PassthroughSubject<NotificationSettingsEditScreenViewModelAction, Never> = .init()
|
||||
private let isDirect: Bool
|
||||
private let chatType: NotificationSettingsChatType
|
||||
private let notificationSettingsProxy: NotificationSettingsProxyProtocol
|
||||
@CancellableTask private var fetchSettingsTask: Task<Void, Error>?
|
||||
private let userSession: UserSessionProtocol
|
||||
private let roomSummaryProvider: RoomSummaryProviderProtocol?
|
||||
|
||||
@CancellableTask private var fetchDefaultRoomNotificationModesTask: Task<Void, Error>?
|
||||
@CancellableTask private var updateRoomsWithUserDefinedModeTask: Task<Void, Error>?
|
||||
|
||||
var actions: AnyPublisher<NotificationSettingsEditScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(isDirect: Bool, notificationSettingsProxy: NotificationSettingsProxyProtocol) {
|
||||
|
||||
init(chatType: NotificationSettingsChatType, userSession: UserSessionProtocol, notificationSettingsProxy: NotificationSettingsProxyProtocol) {
|
||||
let bindings = NotificationSettingsEditScreenViewStateBindings()
|
||||
self.isDirect = isDirect
|
||||
self.chatType = chatType
|
||||
self.userSession = userSession
|
||||
self.notificationSettingsProxy = notificationSettingsProxy
|
||||
roomSummaryProvider = userSession.clientProxy.roomSummaryProvider
|
||||
|
||||
super.init(initialViewState: NotificationSettingsEditScreenViewState(bindings: bindings,
|
||||
strings: NotificationSettingsEditScreenStrings(isDirect: isDirect),
|
||||
isDirect: isDirect))
|
||||
strings: NotificationSettingsEditScreenStrings(chatType: chatType),
|
||||
chatType: chatType),
|
||||
imageProvider: userSession.mediaProvider)
|
||||
|
||||
setupNotificationSettingsSubscription()
|
||||
setupRoomSummaryProviderSubscription()
|
||||
}
|
||||
|
||||
func fetchInitialContent() {
|
||||
fetchSettings()
|
||||
fetchDefaultRoomNotificationModes()
|
||||
updateRoomsWithUserDefinedMode()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -50,6 +60,8 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
switch viewAction {
|
||||
case .setMode(let mode):
|
||||
setMode(mode)
|
||||
case .selectRoom(let roomIdentifier):
|
||||
actionsSubject.send(.requestRoomNotificationSettingsPresentation(roomID: roomIdentifier))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,17 +75,19 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
|
||||
switch callback {
|
||||
case .settingsDidChange:
|
||||
self.fetchSettings()
|
||||
self.fetchDefaultRoomNotificationModes()
|
||||
self.updateRoomsWithUserDefinedMode()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func fetchSettings() {
|
||||
fetchSettingsTask = Task {
|
||||
private func fetchDefaultRoomNotificationModes() {
|
||||
fetchDefaultRoomNotificationModesTask = Task {
|
||||
var mode: RoomNotificationModeProxy?
|
||||
let encrypted_mode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: true, isOneToOne: isDirect)
|
||||
let unencrypted_mode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: false, isOneToOne: isDirect)
|
||||
let isOneToOne = chatType == .oneToOneChat
|
||||
let encrypted_mode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: true, isOneToOne: isOneToOne)
|
||||
let unencrypted_mode = await notificationSettingsProxy.getDefaultRoomNotificationMode(isEncrypted: false, isOneToOne: isOneToOne)
|
||||
if encrypted_mode == unencrypted_mode {
|
||||
mode = encrypted_mode
|
||||
}
|
||||
@@ -90,6 +104,71 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
}
|
||||
}
|
||||
|
||||
private func setupRoomSummaryProviderSubscription() {
|
||||
guard let roomSummaryProvider else {
|
||||
MXLog.error("Room summary provider unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
roomSummaryProvider.roomListPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] _ in
|
||||
self?.updateRoomsWithUserDefinedMode()
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func updateRoomsWithUserDefinedMode() {
|
||||
guard let roomSummaryProvider else {
|
||||
MXLog.error("Room summary provider unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
updateRoomsWithUserDefinedModeTask = Task {
|
||||
let roomsWithUserDefinedRules = try await notificationSettingsProxy.getRoomsWithUserDefinedRules()
|
||||
guard !Task.isCancelled else { return }
|
||||
|
||||
let filteredRoomsSummary = roomSummaryProvider.roomListPublisher.value.filter { summary in
|
||||
roomsWithUserDefinedRules.contains(where: { summary.id == $0 })
|
||||
}
|
||||
|
||||
var roomsWithUserDefinedMode: [NotificationSettingsEditScreenRoom] = []
|
||||
|
||||
for roomSummary in filteredRoomsSummary {
|
||||
switch roomSummary {
|
||||
case .empty, .invalidated:
|
||||
break
|
||||
case .filled(let details):
|
||||
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(details.id) else { continue }
|
||||
// `isOneToOneRoom` here is not the same as `isDirect` on the room. From the point of view of the push rule, a one-to-one room is a room with exactly two active members.
|
||||
let isOneToOneRoom = roomProxy.activeMembersCount == 2
|
||||
// display only the rooms we're interested in
|
||||
switch chatType {
|
||||
case .oneToOneChat where isOneToOneRoom,
|
||||
.groupChat where !isOneToOneRoom:
|
||||
await roomsWithUserDefinedMode.append(buildRoom(with: details))
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the room list
|
||||
roomsWithUserDefinedMode.sort(by: { $0.name.localizedCompare($1.name) == .orderedAscending })
|
||||
|
||||
state.roomsWithUserDefinedMode = roomsWithUserDefinedMode
|
||||
}
|
||||
}
|
||||
|
||||
private func buildRoom(with details: RoomSummaryDetails) async -> NotificationSettingsEditScreenRoom {
|
||||
let notificationMode = try? await notificationSettingsProxy.getUserDefinedRoomNotificationMode(roomId: details.id)
|
||||
return NotificationSettingsEditScreenRoom(id: details.id,
|
||||
roomId: details.id,
|
||||
name: details.name,
|
||||
avatarURL: details.avatarURL,
|
||||
notificationMode: notificationMode)
|
||||
}
|
||||
|
||||
private func setMode(_ mode: NotificationSettingsEditScreenDefaultMode) {
|
||||
guard state.pendingMode == nil, !state.isSelected(mode: mode) else { return }
|
||||
let roomNotificationModeProxy: RoomNotificationModeProxy
|
||||
@@ -102,9 +181,12 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
state.pendingMode = mode
|
||||
Task {
|
||||
do {
|
||||
try await notificationSettingsProxy.setDefaultRoomNotificationMode(isEncrypted: true, isOneToOne: isDirect, mode: roomNotificationModeProxy)
|
||||
try await notificationSettingsProxy.setDefaultRoomNotificationMode(isEncrypted: false, isOneToOne: isDirect, mode: roomNotificationModeProxy)
|
||||
// On modern clients, we don't have different settings for encrypted and non-encrypted rooms.
|
||||
let isOneToOne = chatType == .oneToOneChat
|
||||
try await notificationSettingsProxy.setDefaultRoomNotificationMode(isEncrypted: true, isOneToOne: isOneToOne, mode: roomNotificationModeProxy)
|
||||
try await notificationSettingsProxy.setDefaultRoomNotificationMode(isEncrypted: false, isOneToOne: isOneToOne, mode: roomNotificationModeProxy)
|
||||
} catch {
|
||||
// In case of failure, we let the user retry
|
||||
let retryAction: () -> Void = { [weak self] in
|
||||
self?.setMode(mode)
|
||||
}
|
||||
|
||||
+43
-20
@@ -14,16 +14,22 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct NotificationSettingsEditScreen: View {
|
||||
@ObservedObject var context: NotificationSettingsEditScreenViewModel.Context
|
||||
@State var isSearching = false
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
notificationModeSection
|
||||
|
||||
if context.viewState.displayRoomsWithCustomSettings {
|
||||
roomsWithCustomSettingsSection
|
||||
}
|
||||
}
|
||||
.compoundForm()
|
||||
.compoundList()
|
||||
.navigationTitle(context.viewState.strings.navigationTitle)
|
||||
.alert(item: $context.alertInfo)
|
||||
.track(screen: .settingsDefaultNotifications)
|
||||
@@ -34,25 +40,27 @@ struct NotificationSettingsEditScreen: View {
|
||||
private var notificationModeSection: some View {
|
||||
Section {
|
||||
ForEach(context.viewState.availableDefaultModes, id: \.self) { mode in
|
||||
Button {
|
||||
context.send(viewAction: .setMode(mode))
|
||||
} label: {
|
||||
LabeledContent {
|
||||
if context.viewState.pendingMode == mode {
|
||||
ProgressView()
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
} label: {
|
||||
Text(context.viewState.strings.string(for: mode))
|
||||
}
|
||||
}
|
||||
.buttonStyle(.compoundForm(accessory: .selected(context.viewState.isSelected(mode: mode))))
|
||||
.disabled(context.viewState.pendingMode != nil)
|
||||
ListRow(label: .plain(title: context.viewState.strings.string(for: mode)),
|
||||
details: (context.viewState.pendingMode == mode) ? .isWaiting(true) : nil,
|
||||
kind: .selection(isSelected: context.viewState.isSelected(mode: mode)) {
|
||||
context.send(viewAction: .setMode(mode))
|
||||
})
|
||||
.disabled(context.viewState.pendingMode != nil)
|
||||
}
|
||||
} header: {
|
||||
Text(context.viewState.strings.modeSectionTitle)
|
||||
.compoundFormSectionHeader()
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
}
|
||||
|
||||
private var roomsWithCustomSettingsSection: some View {
|
||||
Section {
|
||||
ForEach(context.viewState.roomsWithUserDefinedMode, id: \.id) { room in
|
||||
NotificationSettingsEditScreenRoomCell(room: room, context: context)
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.screenNotificationSettingsEditCustomSettingsSectionTitle)
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
.compoundFormSection()
|
||||
}
|
||||
@@ -64,7 +72,13 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider {
|
||||
static let viewModelGroupChats: NotificationSettingsEditScreenViewModel = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
|
||||
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .allMessages
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(isDirect: false,
|
||||
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id)
|
||||
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@alice:example.com",
|
||||
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms))),
|
||||
mediaProvider: MockMediaProvider())
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat,
|
||||
userSession: userSession,
|
||||
notificationSettingsProxy: notificationSettingsProxy)
|
||||
viewModel.fetchInitialContent()
|
||||
return viewModel
|
||||
@@ -73,7 +87,12 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider {
|
||||
static let viewModelDirectChats: NotificationSettingsEditScreenViewModel = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
|
||||
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .mentionsAndKeywordsOnly
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(isDirect: true,
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = []
|
||||
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@alice:example.com",
|
||||
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms))),
|
||||
mediaProvider: MockMediaProvider())
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .oneToOneChat,
|
||||
userSession: userSession,
|
||||
notificationSettingsProxy: notificationSettingsProxy)
|
||||
viewModel.fetchInitialContent()
|
||||
return viewModel
|
||||
@@ -82,7 +101,11 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider {
|
||||
static let viewModelDirectApplyingChange: NotificationSettingsEditScreenViewModel = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
|
||||
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .mentionsAndKeywordsOnly
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(isDirect: true,
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = []
|
||||
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe"), mediaProvider: MockMediaProvider())
|
||||
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .oneToOneChat,
|
||||
userSession: userSession,
|
||||
notificationSettingsProxy: notificationSettingsProxy)
|
||||
viewModel.state.pendingMode = .mentionsAndKeywordsOnly
|
||||
viewModel.fetchInitialContent()
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct NotificationSettingsEditScreenRoomCell: View {
|
||||
@Environment(\.dynamicTypeSize) var dynamicTypeSize
|
||||
|
||||
let room: NotificationSettingsEditScreenRoom
|
||||
let context: NotificationSettingsEditScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
ListRow(label: .action(title: room.name,
|
||||
icon: avatar),
|
||||
details: roomDetailsLabel,
|
||||
kind: .navigationLink {
|
||||
if let roomId = room.roomId {
|
||||
context.send(viewAction: .selectRoom(roomIdentifier: roomId))
|
||||
}
|
||||
})
|
||||
.lineLimit(1)
|
||||
.accessibilityIdentifier(A11yIdentifiers.notificationSettingsEditScreen.roomName(room.name))
|
||||
}
|
||||
|
||||
@ViewBuilder @MainActor
|
||||
var avatar: some View {
|
||||
if dynamicTypeSize < .accessibility3 {
|
||||
LoadableAvatarImage(url: room.avatarURL,
|
||||
name: room.name,
|
||||
contentID: room.roomId,
|
||||
avatarSize: .room(on: .notificationSettings),
|
||||
imageProvider: context.imageProvider)
|
||||
.dynamicTypeSize(dynamicTypeSize < .accessibility1 ? dynamicTypeSize : .accessibility1)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
var roomDetailsLabel: ListDetailsLabel<EmptyView>? {
|
||||
guard let mode = room.notificationMode else { return nil }
|
||||
return .label(title: context.viewState.strings.string(for: mode),
|
||||
icon: EmptyView())
|
||||
}
|
||||
}
|
||||
|
||||
struct NotificationSettingsEditScreenRoomCell_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let summaryProvider = MockRoomSummaryProvider(state: .loaded(.mockRooms))
|
||||
|
||||
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe", roomSummaryProvider: summaryProvider),
|
||||
mediaProvider: MockMediaProvider())
|
||||
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init())
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = []
|
||||
let viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat,
|
||||
userSession: userSession,
|
||||
notificationSettingsProxy: notificationSettingsProxy)
|
||||
|
||||
let rooms: [NotificationSettingsEditScreenRoom] = summaryProvider.roomListPublisher.value.compactMap { summary -> NotificationSettingsEditScreenRoom? in
|
||||
switch summary {
|
||||
case .empty, .invalidated:
|
||||
return nil
|
||||
case .filled(let details):
|
||||
return NotificationSettingsEditScreenRoom(id: UUID().uuidString,
|
||||
roomId: details.id,
|
||||
name: details.name)
|
||||
}
|
||||
}
|
||||
|
||||
return VStack(spacing: 0) {
|
||||
ForEach(rooms) { room in
|
||||
NotificationSettingsEditScreenRoomCell(room: room, context: viewModel.context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -19,6 +19,7 @@ import SwiftUI
|
||||
|
||||
struct NotificationSettingsScreenCoordinatorParameters {
|
||||
weak var navigationStackCoordinator: NavigationStackCoordinator?
|
||||
let userSession: UserSessionProtocol
|
||||
let userNotificationCenter: UserNotificationCenterProtocol
|
||||
let notificationSettings: NotificationSettingsProxyProtocol
|
||||
let isModallyPresented: Bool
|
||||
@@ -45,7 +46,8 @@ final class NotificationSettingsScreenCoordinator: CoordinatorProtocol {
|
||||
init(parameters: NotificationSettingsScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = NotificationSettingsScreenViewModel(appSettings: ServiceLocator.shared.settings,
|
||||
viewModel = NotificationSettingsScreenViewModel(userSession: parameters.userSession,
|
||||
appSettings: ServiceLocator.shared.settings,
|
||||
userNotificationCenter: parameters.userNotificationCenter,
|
||||
notificationSettingsProxy: parameters.notificationSettings,
|
||||
isModallyPresented: parameters.isModallyPresented)
|
||||
@@ -59,8 +61,8 @@ final class NotificationSettingsScreenCoordinator: CoordinatorProtocol {
|
||||
switch action {
|
||||
case .close:
|
||||
self.actionsSubject.send(.close)
|
||||
case .editDefaultMode(let isDirect):
|
||||
self.presentEditScreen(isDirect: isDirect)
|
||||
case .editDefaultMode(let chatType):
|
||||
self.presentEditScreen(chatType: chatType)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@@ -72,8 +74,10 @@ final class NotificationSettingsScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func presentEditScreen(isDirect: Bool) {
|
||||
let editSettingsParameters = NotificationSettingsEditScreenCoordinatorParameters(isDirect: isDirect,
|
||||
private func presentEditScreen(chatType: NotificationSettingsChatType) {
|
||||
let editSettingsParameters = NotificationSettingsEditScreenCoordinatorParameters(navigationStackCoordinator: parameters.navigationStackCoordinator,
|
||||
chatType: chatType,
|
||||
userSession: parameters.userSession,
|
||||
notificationSettings: parameters.notificationSettings)
|
||||
let editSettingsCoordinator = NotificationSettingsEditScreenCoordinator(parameters: editSettingsParameters)
|
||||
navigationStackCoordinator?.push(editSettingsCoordinator)
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ import UIKit
|
||||
|
||||
enum NotificationSettingsScreenViewModelAction {
|
||||
case close
|
||||
case editDefaultMode(isDirect: Bool)
|
||||
case editDefaultMode(chatType: NotificationSettingsChatType)
|
||||
}
|
||||
|
||||
struct NotificationSettingsScreenViewState: BindableState {
|
||||
|
||||
+5
-3
@@ -24,13 +24,15 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
private let appSettings: AppSettings
|
||||
private let userNotificationCenter: UserNotificationCenterProtocol
|
||||
private let notificationSettingsProxy: NotificationSettingsProxyProtocol
|
||||
private let userSession: UserSessionProtocol
|
||||
@CancellableTask private var fetchSettingsTask: Task<Void, Error>?
|
||||
|
||||
var actions: AnyPublisher<NotificationSettingsScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(appSettings: AppSettings, userNotificationCenter: UserNotificationCenterProtocol, notificationSettingsProxy: NotificationSettingsProxyProtocol, isModallyPresented: Bool) {
|
||||
init(userSession: UserSessionProtocol, appSettings: AppSettings, userNotificationCenter: UserNotificationCenterProtocol, notificationSettingsProxy: NotificationSettingsProxyProtocol, isModallyPresented: Bool) {
|
||||
self.userSession = userSession
|
||||
self.appSettings = appSettings
|
||||
self.userNotificationCenter = userNotificationCenter
|
||||
self.notificationSettingsProxy = notificationSettingsProxy
|
||||
@@ -60,9 +62,9 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
case .changedEnableNotifications:
|
||||
toggleNotifications()
|
||||
case .groupChatsTapped:
|
||||
actionsSubject.send(.editDefaultMode(isDirect: false))
|
||||
actionsSubject.send(.editDefaultMode(chatType: .groupChat))
|
||||
case .directChatsTapped:
|
||||
actionsSubject.send(.editDefaultMode(isDirect: true))
|
||||
actionsSubject.send(.editDefaultMode(chatType: .oneToOneChat))
|
||||
case .roomMentionChanged:
|
||||
guard let settings = state.settings, settings.roomMentionsEnabled != state.bindings.roomMentionsEnabled else {
|
||||
return
|
||||
|
||||
+4
-1
@@ -173,7 +173,10 @@ struct NotificationSettingsScreen_Previews: PreviewProvider {
|
||||
notificationSettingsProxy.isRoomMentionEnabledReturnValue = true
|
||||
notificationSettingsProxy.isCallEnabledReturnValue = false
|
||||
|
||||
var viewModel = NotificationSettingsScreenViewModel(appSettings: appSettings,
|
||||
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "John Doe"), mediaProvider: MockMediaProvider())
|
||||
|
||||
var viewModel = NotificationSettingsScreenViewModel(userSession: userSession,
|
||||
appSettings: appSettings,
|
||||
userNotificationCenter: notificationCenter,
|
||||
notificationSettingsProxy: notificationSettingsProxy,
|
||||
isModallyPresented: true)
|
||||
|
||||
@@ -142,6 +142,7 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
private func presentNotificationSettings() {
|
||||
let notificationParameters = NotificationSettingsScreenCoordinatorParameters(navigationStackCoordinator: parameters.navigationStackCoordinator,
|
||||
userSession: parameters.userSession,
|
||||
userNotificationCenter: UNUserNotificationCenter.current(),
|
||||
notificationSettings: parameters.notificationSettings,
|
||||
isModallyPresented: false)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum NotificationSettingsChatType {
|
||||
/// A one-to-one chat is a chat with exactly two active members
|
||||
case oneToOneChat
|
||||
case groupChat
|
||||
}
|
||||
@@ -59,6 +59,11 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func getUserDefinedRoomNotificationMode(roomId: String) async throws -> RoomNotificationModeProxy? {
|
||||
let roomNotificationMode = try await notificationSettings.getUserDefinedRoomNotificationMode(roomId: roomId)
|
||||
return roomNotificationMode.flatMap { RoomNotificationModeProxy.from(roomNotificationMode: $0) }
|
||||
}
|
||||
|
||||
func getDefaultRoomNotificationMode(isEncrypted: Bool, isOneToOne: Bool) async -> RoomNotificationModeProxy {
|
||||
let roomNotificationMode = await notificationSettings.getDefaultRoomNotificationMode(isEncrypted: isEncrypted, isOneToOne: isOneToOne)
|
||||
return RoomNotificationModeProxy.from(roomNotificationMode: roomNotificationMode)
|
||||
@@ -128,6 +133,10 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func getRoomsWithUserDefinedRules() async throws -> [String] {
|
||||
await notificationSettings.getRoomsWithUserDefinedRules(enabled: true)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
func updatedSettings() async {
|
||||
|
||||
@@ -28,6 +28,7 @@ protocol NotificationSettingsProxyProtocol {
|
||||
|
||||
func getNotificationSettings(roomId: String, isEncrypted: Bool, isOneToOne: Bool) async throws -> RoomNotificationSettingsProxyProtocol
|
||||
func setNotificationMode(roomId: String, mode: RoomNotificationModeProxy) async throws
|
||||
func getUserDefinedRoomNotificationMode(roomId: String) async throws -> RoomNotificationModeProxy?
|
||||
func getDefaultRoomNotificationMode(isEncrypted: Bool, isOneToOne: Bool) async -> RoomNotificationModeProxy
|
||||
func setDefaultRoomNotificationMode(isEncrypted: Bool, isOneToOne: Bool, mode: RoomNotificationModeProxy) async throws
|
||||
func restoreDefaultNotificationMode(roomId: String) async throws
|
||||
@@ -39,4 +40,5 @@ protocol NotificationSettingsProxyProtocol {
|
||||
func setUserMentionEnabled(enabled: Bool) async throws
|
||||
func isCallEnabled() async throws -> Bool
|
||||
func setCallEnabled(enabled: Bool) async throws
|
||||
func getRoomsWithUserDefinedRules() async throws -> [String]
|
||||
}
|
||||
|
||||
@@ -197,7 +197,10 @@ class MockScreen: Identifiable {
|
||||
case .notificationSettingsScreen:
|
||||
let userNotificationCenter = UserNotificationCenterMock()
|
||||
userNotificationCenter.authorizationStatusReturnValue = .denied
|
||||
let parameters = NotificationSettingsScreenCoordinatorParameters(userNotificationCenter: userNotificationCenter,
|
||||
let session = MockUserSession(clientProxy: MockClientProxy(userID: "@mock:matrix.org"),
|
||||
mediaProvider: MockMediaProvider())
|
||||
let parameters = NotificationSettingsScreenCoordinatorParameters(userSession: session,
|
||||
userNotificationCenter: userNotificationCenter,
|
||||
notificationSettings: NotificationSettingsProxyMock(with: .init()),
|
||||
isModallyPresented: false)
|
||||
return NotificationSettingsScreenCoordinator(parameters: parameters)
|
||||
@@ -501,7 +504,8 @@ class MockScreen: Identifiable {
|
||||
let members: [RoomMemberProxyMock] = [.mockInvitedAlice, .mockBob, .mockCharlie]
|
||||
let coordinator = RoomNotificationSettingsScreenCoordinator(parameters: .init(navigationStackCoordinator: navigationStackCoordinator,
|
||||
notificationSettingsProxy: NotificationSettingsProxyMock(with: .init(defaultRoomMode: .allMessages, roomMode: .allMessages)),
|
||||
roomProxy: RoomProxyMock(with: .init(displayName: "test", members: members))))
|
||||
roomProxy: RoomProxyMock(with: .init(displayName: "test", members: members)),
|
||||
displayAsUserDefinedRoomSettings: false))
|
||||
navigationStackCoordinator.setRootCoordinator(coordinator)
|
||||
return navigationStackCoordinator
|
||||
case .roomNotificationSettingsCustomSetting:
|
||||
@@ -509,7 +513,8 @@ class MockScreen: Identifiable {
|
||||
let members: [RoomMemberProxyMock] = [.mockInvitedAlice, .mockBob, .mockCharlie]
|
||||
let coordinator = RoomNotificationSettingsScreenCoordinator(parameters: .init(navigationStackCoordinator: navigationStackCoordinator,
|
||||
notificationSettingsProxy: NotificationSettingsProxyMock(with: .init(defaultRoomMode: .allMessages, roomMode: .mentionsAndKeywordsOnly)),
|
||||
roomProxy: RoomProxyMock(with: .init(displayName: "test", members: members))))
|
||||
roomProxy: RoomProxyMock(with: .init(displayName: "test", members: members)),
|
||||
displayAsUserDefinedRoomSettings: false))
|
||||
navigationStackCoordinator.setRootCoordinator(coordinator)
|
||||
return navigationStackCoordinator
|
||||
case .reportContent:
|
||||
|
||||
Reference in New Issue
Block a user