Files
letro-ios/ElementX/Sources/Mocks/NotificationSettingsProxyMock.swift
2023-07-26 09:27:14 +00:00

56 lines
2.4 KiB
Swift

//
// 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 Combine
import Foundation
import MatrixRustSDK
struct NotificationSettingsProxyMockConfiguration {
var callback = PassthroughSubject<NotificationSettingsProxyCallback, Never>()
var defaultRoomMode: RoomNotificationModeProxy
var roomMode: RoomNotificationSettingsProxyMock
init(defaultRoomMode: RoomNotificationModeProxy = .allMessages, roomMode: RoomNotificationModeProxy = .allMessages) {
self.defaultRoomMode = defaultRoomMode
self.roomMode = RoomNotificationSettingsProxyMock(with: RoomNotificationSettingsProxyMockConfiguration(mode: roomMode, isDefault: defaultRoomMode == roomMode))
}
}
extension NotificationSettingsProxyMock {
convenience init(with configuration: NotificationSettingsProxyMockConfiguration) {
self.init()
callbacks = configuration.callback
getNotificationSettingsRoomIdIsEncryptedActiveMembersCountReturnValue = configuration.roomMode
getDefaultNotificationRoomModeIsEncryptedActiveMembersCountReturnValue = configuration.defaultRoomMode
setNotificationModeRoomIdModeClosure = { [weak self] _, mode in
guard let self else { return }
self.getNotificationSettingsRoomIdIsEncryptedActiveMembersCountReturnValue = RoomNotificationSettingsProxyMock(with: .init(mode: mode, isDefault: false))
Task {
self.callbacks.send(.settingsDidChange)
}
}
restoreDefaultNotificationModeRoomIdClosure = { [weak self] _ in
guard let self else { return }
self.getNotificationSettingsRoomIdIsEncryptedActiveMembersCountReturnValue = RoomNotificationSettingsProxyMock(with: .init(mode: configuration.defaultRoomMode, isDefault: true))
Task {
self.callbacks.send(.settingsDidChange)
}
}
}
}