mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Edit the room Notification setting (#1394)
This commit is contained in:
@@ -51,15 +51,26 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
return RoomNotificationSettingsProxy(roomNotificationSettings: roomMotificationSettings)
|
||||
}
|
||||
|
||||
func setNotificationMode(roomId: String, mode: RoomNotificationMode) async throws {
|
||||
func setNotificationMode(roomId: String, mode: RoomNotificationModeProxy) async throws {
|
||||
let backgroundTask = await backgroundTaskService?.startBackgroundTask(withName: "setNotificationMode")
|
||||
defer { backgroundTask?.stop() }
|
||||
|
||||
try await notificationSettings.setRoomNotificationMode(roomId: roomId, mode: mode)
|
||||
let roomNotificationMode: RoomNotificationMode
|
||||
switch mode {
|
||||
case .allMessages:
|
||||
roomNotificationMode = .allMessages
|
||||
case .mentionsAndKeywordsOnly:
|
||||
roomNotificationMode = .mentionsAndKeywordsOnly
|
||||
case .mute:
|
||||
roomNotificationMode = .mute
|
||||
}
|
||||
try await notificationSettings.setRoomNotificationMode(roomId: roomId, mode: roomNotificationMode)
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func getDefaultNotificationRoomMode(isEncrypted: Bool, activeMembersCount: UInt64) async -> RoomNotificationMode {
|
||||
await notificationSettings.getDefaultRoomNotificationMode(isEncrypted: isEncrypted, activeMembersCount: activeMembersCount)
|
||||
func getDefaultNotificationRoomMode(isEncrypted: Bool, activeMembersCount: UInt64) async -> RoomNotificationModeProxy {
|
||||
let roomNotificationMode = await notificationSettings.getDefaultRoomNotificationMode(isEncrypted: isEncrypted, activeMembersCount: activeMembersCount)
|
||||
return RoomNotificationModeProxy.from(roomNotificationMode: roomNotificationMode)
|
||||
}
|
||||
|
||||
func restoreDefaultNotificationMode(roomId: String) async throws {
|
||||
@@ -67,6 +78,7 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
defer { backgroundTask?.stop() }
|
||||
|
||||
try await notificationSettings.restoreDefaultRoomNotificationMode(roomId: roomId)
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func containsKeywordsRules() async -> Bool {
|
||||
@@ -78,6 +90,7 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
defer { backgroundTask?.stop() }
|
||||
|
||||
try await notificationSettings.unmuteRoom(roomId: roomId, isEncrypted: isEncrypted, membersCount: activeMembersCount)
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func isRoomMentionEnabled() async throws -> Bool {
|
||||
@@ -89,6 +102,7 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
defer { backgroundTask?.stop() }
|
||||
|
||||
try await notificationSettings.setRoomMentionEnabled(enabled: enabled)
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func isUserMentionEnabled() async throws -> Bool {
|
||||
@@ -100,6 +114,7 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
defer { backgroundTask?.stop() }
|
||||
|
||||
try await notificationSettings.setUserMentionEnabled(enabled: enabled)
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
func isCallEnabled() async throws -> Bool {
|
||||
@@ -111,10 +126,15 @@ final class NotificationSettingsProxy: NotificationSettingsProxyProtocol {
|
||||
defer { backgroundTask?.stop() }
|
||||
|
||||
try await notificationSettings.setCallEnabled(enabled: enabled)
|
||||
await updatedSettings()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
func updatedSettings() async {
|
||||
_ = await callbacks.values.first(where: { $0 == .settingsDidChange })
|
||||
}
|
||||
|
||||
@MainActor
|
||||
func settingsDidChange() {
|
||||
callbacks.send(.settingsDidChange)
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ protocol NotificationSettingsProxyProtocol {
|
||||
var callbacks: PassthroughSubject<NotificationSettingsProxyCallback, Never> { get }
|
||||
|
||||
func getNotificationSettings(roomId: String, isEncrypted: Bool, activeMembersCount: UInt64) async throws -> RoomNotificationSettingsProxyProtocol
|
||||
func setNotificationMode(roomId: String, mode: RoomNotificationMode) async throws
|
||||
func getDefaultNotificationRoomMode(isEncrypted: Bool, activeMembersCount: UInt64) async -> RoomNotificationMode
|
||||
func setNotificationMode(roomId: String, mode: RoomNotificationModeProxy) async throws
|
||||
func getDefaultNotificationRoomMode(isEncrypted: Bool, activeMembersCount: UInt64) async -> RoomNotificationModeProxy
|
||||
func restoreDefaultNotificationMode(roomId: String) async throws
|
||||
func containsKeywordsRules() async -> Bool
|
||||
func unmuteRoom(roomId: String, isEncrypted: Bool, activeMembersCount: UInt64) async throws
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// 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
|
||||
import MatrixRustSDK
|
||||
|
||||
enum RoomNotificationModeProxy {
|
||||
case allMessages
|
||||
case mentionsAndKeywordsOnly
|
||||
case mute
|
||||
}
|
||||
|
||||
extension RoomNotificationModeProxy {
|
||||
static func from(roomNotificationMode: RoomNotificationMode) -> Self {
|
||||
switch roomNotificationMode {
|
||||
case .allMessages:
|
||||
return .allMessages
|
||||
case .mentionsAndKeywordsOnly:
|
||||
return .mentionsAndKeywordsOnly
|
||||
case .mute:
|
||||
return .mute
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ import MatrixRustSDK
|
||||
struct RoomNotificationSettingsProxy: RoomNotificationSettingsProxyProtocol {
|
||||
private let roomNotificationSettings: RoomNotificationSettings
|
||||
|
||||
var mode: RoomNotificationMode {
|
||||
roomNotificationSettings.mode
|
||||
var mode: RoomNotificationModeProxy {
|
||||
RoomNotificationModeProxy.from(roomNotificationMode: roomNotificationSettings.mode)
|
||||
}
|
||||
|
||||
var isDefault: Bool {
|
||||
|
||||
+1
-1
@@ -19,6 +19,6 @@ import MatrixRustSDK
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol RoomNotificationSettingsProxyProtocol {
|
||||
var mode: RoomNotificationMode { get }
|
||||
var mode: RoomNotificationModeProxy { get }
|
||||
var isDefault: Bool { get }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user