mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Added a disclaimer in Notification Settings for "Mentions Only" (#2081)
This commit is contained in:
@@ -1716,6 +1716,23 @@ class NotificationSettingsProxyMock: NotificationSettingsProxyProtocol {
|
||||
return getRoomsWithUserDefinedRulesReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - canHomeserverPushEncryptedEventsToDevice
|
||||
|
||||
var canHomeserverPushEncryptedEventsToDeviceCallsCount = 0
|
||||
var canHomeserverPushEncryptedEventsToDeviceCalled: Bool {
|
||||
return canHomeserverPushEncryptedEventsToDeviceCallsCount > 0
|
||||
}
|
||||
var canHomeserverPushEncryptedEventsToDeviceReturnValue: Bool!
|
||||
var canHomeserverPushEncryptedEventsToDeviceClosure: (() async -> Bool)?
|
||||
|
||||
func canHomeserverPushEncryptedEventsToDevice() async -> Bool {
|
||||
canHomeserverPushEncryptedEventsToDeviceCallsCount += 1
|
||||
if let canHomeserverPushEncryptedEventsToDeviceClosure = canHomeserverPushEncryptedEventsToDeviceClosure {
|
||||
return await canHomeserverPushEncryptedEventsToDeviceClosure()
|
||||
} else {
|
||||
return canHomeserverPushEncryptedEventsToDeviceReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
class RoomMemberProxyMock: RoomMemberProxyProtocol {
|
||||
var userID: String {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Generated using Sourcery 2.1.1 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// Generated using Sourcery 2.1.2 — https://github.com/krzysztofzablocki/Sourcery
|
||||
// DO NOT EDIT
|
||||
|
||||
// swiftlint:disable all
|
||||
|
||||
@@ -22,10 +22,12 @@ struct NotificationSettingsProxyMockConfiguration {
|
||||
var callback = PassthroughSubject<NotificationSettingsProxyCallback, Never>()
|
||||
var defaultRoomMode: RoomNotificationModeProxy
|
||||
var roomMode: RoomNotificationSettingsProxyMock
|
||||
var canHomeserverPushEncryptedEvents = false
|
||||
|
||||
init(defaultRoomMode: RoomNotificationModeProxy = .allMessages, roomMode: RoomNotificationModeProxy = .allMessages) {
|
||||
init(defaultRoomMode: RoomNotificationModeProxy = .allMessages, roomMode: RoomNotificationModeProxy = .allMessages, canHomeserverPushEncryptedEvents: Bool = false) {
|
||||
self.defaultRoomMode = defaultRoomMode
|
||||
self.roomMode = RoomNotificationSettingsProxyMock(with: RoomNotificationSettingsProxyMockConfiguration(mode: roomMode, isDefault: defaultRoomMode == roomMode))
|
||||
self.canHomeserverPushEncryptedEvents = canHomeserverPushEncryptedEvents
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,5 +82,9 @@ extension NotificationSettingsProxyMock {
|
||||
self.callbacks.send(.settingsDidChange)
|
||||
}
|
||||
}
|
||||
|
||||
canHomeserverPushEncryptedEventsToDeviceClosure = {
|
||||
configuration.canHomeserverPushEncryptedEvents
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -61,6 +61,15 @@ struct RoomNotificationSettingsScreenViewState: BindableState {
|
||||
var navigationTitle: String
|
||||
var customSettingsSectionHeader: String
|
||||
var deletingCustomSetting = false
|
||||
var shouldDisplayMentionsOnlyDisclaimer = true
|
||||
|
||||
func description(mode: RoomNotificationModeProxy) -> String? {
|
||||
guard mode == .mentionsAndKeywordsOnly,
|
||||
shouldDisplayMentionsOnlyDisclaimer else {
|
||||
return nil
|
||||
}
|
||||
return L10n.screenRoomNotificationSettingsMentionsOnlyDisclaimer
|
||||
}
|
||||
|
||||
func isSelected(mode: RoomNotificationModeProxy) -> Bool {
|
||||
if case .loaded(let settings) = notificationSettingsState, settings.mode == mode, pendingCustomMode == nil {
|
||||
|
||||
+1
@@ -83,6 +83,7 @@ class RoomNotificationSettingsScreenViewModel: RoomNotificationSettingsScreenVie
|
||||
}
|
||||
|
||||
private func fetchRoomNotificationSettings() async {
|
||||
state.shouldDisplayMentionsOnlyDisclaimer = roomProxy.isEncrypted ? await !notificationSettingsProxy.canHomeserverPushEncryptedEventsToDevice() : false
|
||||
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,
|
||||
|
||||
+20
-2
@@ -23,7 +23,8 @@ struct RoomNotificationSettingsCustomSectionView: View {
|
||||
var body: some View {
|
||||
Section {
|
||||
ForEach(context.viewState.availableCustomRoomNotificationModes, id: \.self) { mode in
|
||||
ListRow(label: .plain(title: context.viewState.strings.string(for: mode)),
|
||||
ListRow(label: .plain(title: context.viewState.strings.string(for: mode),
|
||||
description: context.viewState.description(mode: mode)),
|
||||
details: (context.viewState.pendingCustomMode == mode) ? .isWaiting(true) : nil,
|
||||
kind: .selection(isSelected: context.viewState.isSelected(mode: mode)) {
|
||||
context.send(viewAction: .setCustomMode(mode))
|
||||
@@ -40,7 +41,7 @@ struct RoomNotificationSettingsCustomSectionView: View {
|
||||
struct RoomNotificationSettingsCustomSectionView_Previews: PreviewProvider, TestablePreview {
|
||||
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,
|
||||
@@ -48,10 +49,27 @@ struct RoomNotificationSettingsCustomSectionView_Previews: PreviewProvider, Test
|
||||
displayAsUserDefinedRoomSettings: false)
|
||||
}()
|
||||
|
||||
static let viewModelUnencrypted = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(defaultRoomMode: .allMessages, roomMode: .mentionsAndKeywordsOnly))
|
||||
|
||||
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: false, joinedMembersCount: 4))
|
||||
|
||||
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: false)
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
Form {
|
||||
RoomNotificationSettingsCustomSectionView(context: viewModel.context)
|
||||
}
|
||||
.compoundForm()
|
||||
.previewDisplayName("Encrypted")
|
||||
|
||||
Form {
|
||||
RoomNotificationSettingsCustomSectionView(context: viewModelUnencrypted.context)
|
||||
}
|
||||
.compoundForm()
|
||||
.previewDisplayName("Unencrypted")
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -58,8 +58,21 @@ struct RoomNotificationSettingsUserDefinedScreen_Previews: PreviewProvider, Test
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: true)
|
||||
}()
|
||||
|
||||
static let viewModelUnencrypted = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(defaultRoomMode: .mentionsAndKeywordsOnly, roomMode: .mentionsAndKeywordsOnly))
|
||||
|
||||
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: false, joinedMembersCount: 4))
|
||||
|
||||
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
|
||||
roomProxy: roomProxy,
|
||||
displayAsUserDefinedRoomSettings: true)
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
RoomNotificationSettingsUserDefinedScreen(context: viewModel.context)
|
||||
.previewDisplayName("Encrypted")
|
||||
RoomNotificationSettingsUserDefinedScreen(context: viewModelUnencrypted.context)
|
||||
.previewDisplayName("Unencrypted")
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -33,11 +33,20 @@ struct NotificationSettingsEditScreenViewState: BindableState {
|
||||
var defaultMode: NotificationSettingsEditScreenDefaultMode?
|
||||
var pendingMode: NotificationSettingsEditScreenDefaultMode?
|
||||
var roomsWithUserDefinedMode: [NotificationSettingsEditScreenRoom] = []
|
||||
var canHomeServerPushEncryptedEvents = false
|
||||
|
||||
func isSelected(mode: NotificationSettingsEditScreenDefaultMode) -> Bool {
|
||||
pendingMode == nil && defaultMode == mode
|
||||
}
|
||||
|
||||
func description(for mode: NotificationSettingsEditScreenDefaultMode) -> String? {
|
||||
guard mode == .mentionsAndKeywordsOnly,
|
||||
!canHomeServerPushEncryptedEvents else {
|
||||
return nil
|
||||
}
|
||||
return L10n.screenNotificationSettingsMentionsOnlyDisclaimer
|
||||
}
|
||||
|
||||
var displayRoomsWithCustomSettings: Bool {
|
||||
!roomsWithUserDefinedMode.isEmpty
|
||||
}
|
||||
|
||||
+2
@@ -91,6 +91,7 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
if encrypted_mode == unencrypted_mode {
|
||||
mode = encrypted_mode
|
||||
}
|
||||
let canHomserverPushEncryptedEvents = await notificationSettingsProxy.canHomeserverPushEncryptedEventsToDevice()
|
||||
guard !Task.isCancelled else { return }
|
||||
|
||||
switch mode {
|
||||
@@ -101,6 +102,7 @@ class NotificationSettingsEditScreenViewModel: NotificationSettingsEditScreenVie
|
||||
default:
|
||||
state.defaultMode = nil
|
||||
}
|
||||
state.canHomeServerPushEncryptedEvents = canHomserverPushEncryptedEvents
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-1
@@ -40,7 +40,8 @@ struct NotificationSettingsEditScreen: View {
|
||||
private var notificationModeSection: some View {
|
||||
Section {
|
||||
ForEach(context.viewState.availableDefaultModes, id: \.self) { mode in
|
||||
ListRow(label: .plain(title: context.viewState.strings.string(for: mode)),
|
||||
ListRow(label: .plain(title: context.viewState.strings.string(for: mode),
|
||||
description: context.viewState.description(for: mode)),
|
||||
details: (context.viewState.pendingMode == mode) ? .isWaiting(true) : nil,
|
||||
kind: .selection(isSelected: context.viewState.isSelected(mode: mode)) {
|
||||
context.send(viewAction: .setMode(mode))
|
||||
@@ -114,6 +115,22 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
|
||||
return viewModel
|
||||
}()
|
||||
|
||||
static let viewModelGroupChatsWithouDisclaimer: NotificationSettingsEditScreenViewModel = {
|
||||
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(canHomeserverPushEncryptedEvents: true))
|
||||
notificationSettingsProxy.getDefaultRoomNotificationModeIsEncryptedIsOneToOneReturnValue = .allMessages
|
||||
|
||||
notificationSettingsProxy.getRoomsWithUserDefinedRulesReturnValue = [RoomSummary].mockRooms.compactMap(\.id)
|
||||
let userSession = MockUserSession(clientProxy: MockClientProxy(userID: "@alice:example.com",
|
||||
roomSummaryProvider: MockRoomSummaryProvider(state: .loaded(.mockRooms))),
|
||||
mediaProvider: MockMediaProvider(),
|
||||
voiceMessageMediaManager: VoiceMessageMediaManagerMock())
|
||||
var viewModel = NotificationSettingsEditScreenViewModel(chatType: .groupChat,
|
||||
userSession: userSession,
|
||||
notificationSettingsProxy: notificationSettingsProxy)
|
||||
viewModel.fetchInitialContent()
|
||||
return viewModel
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
NotificationSettingsEditScreen(context: viewModelGroupChats.context)
|
||||
.previewDisplayName("Group Chats")
|
||||
@@ -121,5 +138,7 @@ struct NotificationSettingsEditScreen_Previews: PreviewProvider, TestablePreview
|
||||
.previewDisplayName("Direct Chats")
|
||||
NotificationSettingsEditScreen(context: viewModelDirectApplyingChange.context)
|
||||
.previewDisplayName("Applying change")
|
||||
NotificationSettingsEditScreen(context: viewModelGroupChatsWithouDisclaimer.context)
|
||||
.previewDisplayName("Group Chats Without Disclaimer")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,10 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
await notificationSettings.getRoomsWithUserDefinedRules(enabled: true)
|
||||
}
|
||||
|
||||
func canHomeserverPushEncryptedEventsToDevice() async -> Bool {
|
||||
await notificationSettings.canHomeserverPushEncryptedEventToDevice()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
func updatedSettings() async {
|
||||
|
||||
@@ -41,4 +41,5 @@ protocol NotificationSettingsProxyProtocol {
|
||||
func isCallEnabled() async throws -> Bool
|
||||
func setCallEnabled(enabled: Bool) async throws
|
||||
func getRoomsWithUserDefinedRules() async throws -> [String]
|
||||
func canHomeserverPushEncryptedEventsToDevice() async -> Bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user