mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Display the list of rooms with user-defined notification settings (#1535)
This commit is contained in:
+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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user