mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Add toggle not invite notifications. (#2207)
This commit is contained in:
@@ -1710,6 +1710,47 @@ class NotificationSettingsProxyMock: NotificationSettingsProxyProtocol {
|
||||
setCallEnabledEnabledReceivedInvocations.append(enabled)
|
||||
try await setCallEnabledEnabledClosure?(enabled)
|
||||
}
|
||||
//MARK: - isInviteForMeEnabled
|
||||
|
||||
var isInviteForMeEnabledThrowableError: Error?
|
||||
var isInviteForMeEnabledCallsCount = 0
|
||||
var isInviteForMeEnabledCalled: Bool {
|
||||
return isInviteForMeEnabledCallsCount > 0
|
||||
}
|
||||
var isInviteForMeEnabledReturnValue: Bool!
|
||||
var isInviteForMeEnabledClosure: (() async throws -> Bool)?
|
||||
|
||||
func isInviteForMeEnabled() async throws -> Bool {
|
||||
if let error = isInviteForMeEnabledThrowableError {
|
||||
throw error
|
||||
}
|
||||
isInviteForMeEnabledCallsCount += 1
|
||||
if let isInviteForMeEnabledClosure = isInviteForMeEnabledClosure {
|
||||
return try await isInviteForMeEnabledClosure()
|
||||
} else {
|
||||
return isInviteForMeEnabledReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - setInviteForMeEnabled
|
||||
|
||||
var setInviteForMeEnabledEnabledThrowableError: Error?
|
||||
var setInviteForMeEnabledEnabledCallsCount = 0
|
||||
var setInviteForMeEnabledEnabledCalled: Bool {
|
||||
return setInviteForMeEnabledEnabledCallsCount > 0
|
||||
}
|
||||
var setInviteForMeEnabledEnabledReceivedEnabled: Bool?
|
||||
var setInviteForMeEnabledEnabledReceivedInvocations: [Bool] = []
|
||||
var setInviteForMeEnabledEnabledClosure: ((Bool) async throws -> Void)?
|
||||
|
||||
func setInviteForMeEnabled(enabled: Bool) async throws {
|
||||
if let error = setInviteForMeEnabledEnabledThrowableError {
|
||||
throw error
|
||||
}
|
||||
setInviteForMeEnabledEnabledCallsCount += 1
|
||||
setInviteForMeEnabledEnabledReceivedEnabled = enabled
|
||||
setInviteForMeEnabledEnabledReceivedInvocations.append(enabled)
|
||||
try await setInviteForMeEnabledEnabledClosure?(enabled)
|
||||
}
|
||||
//MARK: - getRoomsWithUserDefinedRules
|
||||
|
||||
var getRoomsWithUserDefinedRulesThrowableError: Error?
|
||||
|
||||
@@ -42,6 +42,7 @@ extension NotificationSettingsProxyMock {
|
||||
getRoomsWithUserDefinedRulesReturnValue = []
|
||||
isRoomMentionEnabledReturnValue = true
|
||||
isCallEnabledReturnValue = true
|
||||
isInviteForMeEnabledReturnValue = true
|
||||
|
||||
setNotificationModeRoomIdModeClosure = { [weak self] _, mode in
|
||||
guard let self else { return }
|
||||
@@ -83,6 +84,14 @@ extension NotificationSettingsProxyMock {
|
||||
}
|
||||
}
|
||||
|
||||
setInviteForMeEnabledEnabledClosure = { [weak self] enabled in
|
||||
guard let self else { return }
|
||||
self.isInviteForMeEnabledReturnValue = enabled
|
||||
Task {
|
||||
self.callbacks.send(.settingsDidChange)
|
||||
}
|
||||
}
|
||||
|
||||
canHomeserverPushEncryptedEventsToDeviceClosure = {
|
||||
configuration.canHomeserverPushEncryptedEvents
|
||||
}
|
||||
|
||||
+3
@@ -44,6 +44,7 @@ struct NotificationSettingsScreenViewStateBindings {
|
||||
var enableNotifications = false
|
||||
var roomMentionsEnabled = false
|
||||
var callsEnabled = false
|
||||
var invitationsEnabled = false
|
||||
var alertInfo: AlertInfo<NotificationSettingsScreenErrorType>?
|
||||
}
|
||||
|
||||
@@ -52,6 +53,7 @@ struct NotificationSettingsScreenSettings {
|
||||
let directChatsMode: RoomNotificationModeProxy
|
||||
let roomMentionsEnabled: Bool?
|
||||
let callsEnabled: Bool?
|
||||
let invitationsEnabled: Bool?
|
||||
// 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`)
|
||||
let inconsistentSettings: [NotificationSettingsScreenInvalidSetting]
|
||||
@@ -93,6 +95,7 @@ enum NotificationSettingsScreenViewAction {
|
||||
case directChatsTapped
|
||||
case roomMentionChanged
|
||||
case callsChanged
|
||||
case invitationsChanged
|
||||
case close
|
||||
case fixConfigurationMismatchTapped
|
||||
}
|
||||
|
||||
+23
-2
@@ -73,6 +73,11 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
return
|
||||
}
|
||||
Task { await enableCalls(state.bindings.callsEnabled) }
|
||||
case .invitationsChanged:
|
||||
guard let settings = state.settings, settings.invitationsEnabled != state.bindings.invitationsEnabled else {
|
||||
return
|
||||
}
|
||||
Task { await enableInvitations(state.bindings.invitationsEnabled) }
|
||||
case .close:
|
||||
actionsSubject.send(.close)
|
||||
case .fixConfigurationMismatchTapped:
|
||||
@@ -146,6 +151,7 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
// The following calls may fail if the associated push rule doesn't exist
|
||||
let roomMentionsEnabled = try? await notificationSettingsProxy.isRoomMentionEnabled()
|
||||
let callEnabled = try? await notificationSettingsProxy.isCallEnabled()
|
||||
let invitationsEnabled = try? await notificationSettingsProxy.isInviteForMeEnabled()
|
||||
|
||||
guard !Task.isCancelled else { return }
|
||||
|
||||
@@ -153,11 +159,13 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
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
|
||||
state.bindings.invitationsEnabled = notificationSettings.invitationsEnabled ?? false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +195,7 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
guard let notificationSettings = state.settings else { return }
|
||||
do {
|
||||
state.applyingChange = true
|
||||
MXLog.info("[NotificationSettingsScreenViewMode] setRoomMentionEnabled(\(enable))")
|
||||
MXLog.info("setRoomMentionEnabled(\(enable))")
|
||||
try await notificationSettingsProxy.setRoomMentionEnabled(enabled: enable)
|
||||
} catch {
|
||||
state.bindings.alertInfo = AlertInfo(id: .alert)
|
||||
@@ -200,7 +208,7 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
guard let notificationSettings = state.settings else { return }
|
||||
do {
|
||||
state.applyingChange = true
|
||||
MXLog.info("[NotificationSettingsScreenViewMode] setCallEnabled(\(enable))")
|
||||
MXLog.info("setCallEnabled(\(enable))")
|
||||
try await notificationSettingsProxy.setCallEnabled(enabled: enable)
|
||||
} catch {
|
||||
state.bindings.alertInfo = AlertInfo(id: .alert)
|
||||
@@ -208,6 +216,19 @@ class NotificationSettingsScreenViewModel: NotificationSettingsScreenViewModelTy
|
||||
}
|
||||
state.applyingChange = false
|
||||
}
|
||||
|
||||
func enableInvitations(_ enable: Bool) async {
|
||||
guard let notificationSettings = state.settings else { return }
|
||||
do {
|
||||
state.applyingChange = true
|
||||
MXLog.info("setInviteForMeEnabled(\(enable))")
|
||||
try await notificationSettingsProxy.setInviteForMeEnabled(enabled: enable)
|
||||
} catch {
|
||||
state.bindings.alertInfo = AlertInfo(id: .alert)
|
||||
state.bindings.callsEnabled = notificationSettings.invitationsEnabled ?? false
|
||||
}
|
||||
state.applyingChange = false
|
||||
}
|
||||
}
|
||||
|
||||
extension UNUserNotificationCenter {
|
||||
|
||||
+20
@@ -37,6 +37,9 @@ struct NotificationSettingsScreen: View {
|
||||
if context.viewState.showCallsSettings, context.viewState.settings?.callsEnabled != nil {
|
||||
callsSection
|
||||
}
|
||||
if context.viewState.settings?.invitationsEnabled != nil {
|
||||
additionalSettingsSection
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,6 +156,21 @@ struct NotificationSettingsScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var additionalSettingsSection: some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenNotificationSettingsInviteForMeLabel),
|
||||
kind: .toggle($context.invitationsEnabled))
|
||||
.disabled(context.viewState.settings?.invitationsEnabled == nil)
|
||||
.allowsHitTesting(!context.viewState.applyingChange)
|
||||
.onChange(of: context.invitationsEnabled) { _ in
|
||||
context.send(viewAction: .invitationsChanged)
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.screenNotificationSettingsAdditionalSettingsSectionTitle)
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
}
|
||||
|
||||
private var configurationMismatchSection: some View {
|
||||
Section {
|
||||
ListRow(kind: .custom {
|
||||
@@ -242,7 +260,9 @@ struct NotificationSettingsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
|
||||
static var previews: some View {
|
||||
NotificationSettingsScreen(context: viewModel.context)
|
||||
.snapshot(delay: 0.1)
|
||||
NotificationSettingsScreen(context: viewModelConfigurationMismatch.context)
|
||||
.snapshot(delay: 0.1)
|
||||
.previewDisplayName("Configuration mismatch")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +141,18 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func isInviteForMeEnabled() async throws -> Bool {
|
||||
try await notificationSettings.isInviteForMeEnabled()
|
||||
}
|
||||
|
||||
func setInviteForMeEnabled(enabled: Bool) async throws {
|
||||
let backgroundTask = await backgroundTaskService?.startBackgroundTask(withName: "setInviteForMeEnabled")
|
||||
defer { backgroundTask?.stop() }
|
||||
|
||||
try await notificationSettings.setInviteForMeEnabled(enabled: enabled)
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func getRoomsWithUserDefinedRules() async throws -> [String] {
|
||||
await notificationSettings.getRoomsWithUserDefinedRules(enabled: true)
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ protocol NotificationSettingsProxyProtocol {
|
||||
func setUserMentionEnabled(enabled: Bool) async throws
|
||||
func isCallEnabled() async throws -> Bool
|
||||
func setCallEnabled(enabled: Bool) async throws
|
||||
func isInviteForMeEnabled() async throws -> Bool
|
||||
func setInviteForMeEnabled(enabled: Bool) async throws
|
||||
func getRoomsWithUserDefinedRules() async throws -> [String]
|
||||
func canHomeserverPushEncryptedEventsToDevice() async -> Bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user