mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Add translations, footer message and room encryption handling
This commit is contained in:
@@ -287,6 +287,7 @@ fileprivate extension MXRoom {
|
||||
}
|
||||
|
||||
var notificationState: RoomNotificationState {
|
||||
|
||||
if isMuted {
|
||||
return .mute
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ final class RoomNotificationSettingsCoordinator: RoomNotificationSettingsCoordin
|
||||
|
||||
init(room: MXRoom) {
|
||||
let repository = RoomNotificationRepositoryImpl(room: room)
|
||||
let roomNotificationSettingsViewModel = RoomNotificationSettingsViewModel(roomNotificationRepository: repository)
|
||||
let roomNotificationSettingsViewModel = RoomNotificationSettingsViewModel(roomNotificationRepository: repository, roomEncrypted: room.summary.isEncrypted)
|
||||
let roomNotificationSettingsViewController = RoomNotificationSettingsViewController.instantiate(with: roomNotificationSettingsViewModel)
|
||||
self.roomNotificationSettingsViewModel = roomNotificationSettingsViewModel
|
||||
self.roomNotificationSettingsViewController = roomNotificationSettingsViewController
|
||||
|
||||
+20
-14
@@ -115,11 +115,11 @@ final class RoomNotificationSettingsViewController: UIViewController {
|
||||
}
|
||||
|
||||
private func setupViews() {
|
||||
let doneBarButtonItem = MXKBarButtonItem(title: "Done", style: .plain) { [weak self] in
|
||||
let doneBarButtonItem = MXKBarButtonItem(title: VectorL10n.roomNotifsSettingsDoneAction, style: .plain) { [weak self] in
|
||||
self?.viewModel.process(viewAction: .save)
|
||||
}
|
||||
|
||||
let cancelBarButtonItem = MXKBarButtonItem(title: "Cancel", style: .plain) { [weak self] in
|
||||
let cancelBarButtonItem = MXKBarButtonItem(title: VectorL10n.roomNotifsSettingsCancelAction, style: .plain) { [weak self] in
|
||||
self?.viewModel.process(viewAction: .cancel)
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ final class RoomNotificationSettingsViewController: UIViewController {
|
||||
}
|
||||
|
||||
private func updateSections() {
|
||||
let rows = RoomNotificationState.allCases.map({ (setting) -> Row in
|
||||
let rows = viewState.notificationOptions.map({ (setting) -> Row in
|
||||
return Row(type: .plain,
|
||||
setting: setting,
|
||||
text: setting.title,
|
||||
@@ -151,20 +151,26 @@ final class RoomNotificationSettingsViewController: UIViewController {
|
||||
})
|
||||
})
|
||||
|
||||
let formatStr = "You can manage keywords in the %@"
|
||||
let linkStr = "Account Settings"
|
||||
let linkStr = VectorL10n.roomNotifsSettingsAccountSettings
|
||||
let formatStr = VectorL10n.roomNotifsSettingsManageNotifications(linkStr)
|
||||
|
||||
let formattedStr = String(format: formatStr, arguments: [linkStr])
|
||||
|
||||
|
||||
let paragraphStyle = NSMutableParagraphStyle()
|
||||
paragraphStyle.lineHeightMultiple = 1.16
|
||||
let footer_0 = NSMutableAttributedString(string: formattedStr, attributes: [
|
||||
let paragraphAttributes: [NSAttributedString.Key: Any] = [
|
||||
NSAttributedString.Key.kern: -0.08,
|
||||
NSAttributedString.Key.paragraphStyle: paragraphStyle,
|
||||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 13.0)
|
||||
])
|
||||
let linkRange = (footer_0.string as NSString).range(of: linkStr)
|
||||
footer_0.addAttribute(NSAttributedString.Key.link, value: Constants.linkToAccountSettings, range: linkRange)
|
||||
let section0 = Section(header: nil, rows: rows, footer: footer_0)
|
||||
]
|
||||
let footer0 = NSMutableAttributedString(string: formattedStr, attributes: paragraphAttributes)
|
||||
let linkRange = (footer0.string as NSString).range(of: linkStr)
|
||||
footer0.addAttribute(NSAttributedString.Key.link, value: Constants.linkToAccountSettings, range: linkRange)
|
||||
|
||||
if viewState.roomEncrypted {
|
||||
footer0.append(NSAttributedString(string: VectorL10n.roomNotifsSettingsEncryedRoomNotice, attributes: paragraphAttributes))
|
||||
}
|
||||
let section0 = Section(header: nil, rows: rows, footer: footer0)
|
||||
|
||||
sections = [
|
||||
section0
|
||||
@@ -264,11 +270,11 @@ extension RoomNotificationState {
|
||||
var title: String {
|
||||
switch self {
|
||||
case .all:
|
||||
return "All Messages"
|
||||
return VectorL10n.roomNotifsSettingsAllMessages
|
||||
case .mentionsOnly:
|
||||
return "Mentions and Keywords only"
|
||||
return VectorL10n.roomNotifsSettingsMentionsAndKeywords
|
||||
case .mute:
|
||||
return "None"
|
||||
return VectorL10n.roomNotifsSettingsNone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,15 @@ final class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModel
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(roomNotificationRepository: RoomNotificationRepository) {
|
||||
init(roomNotificationRepository: RoomNotificationRepository, roomEncrypted: Bool) {
|
||||
self.roomNotificationRepository = roomNotificationRepository
|
||||
self.state = RoomNotificationSettingsViewStateImpl(saving: false, notificationState: roomNotificationRepository.notificationState)
|
||||
self.roomNotificationRepository.observeNotificationState { state in
|
||||
self.state.notificationState = state
|
||||
|
||||
let notificationState = Self.mapNotificationStateOnRead(encrypted: roomEncrypted, state: roomNotificationRepository.notificationState)
|
||||
self.state = RoomNotificationSettingsViewStateImpl(roomEncrypted: roomEncrypted, saving: false, notificationState: notificationState)
|
||||
self.roomNotificationRepository.observeNotificationState { [weak self] state in
|
||||
guard let self = self else { return }
|
||||
|
||||
self.state.notificationState = Self.mapNotificationStateOnRead(encrypted: roomEncrypted, state: state)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +61,8 @@ final class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModel
|
||||
self.state.notificationState = state
|
||||
case .save:
|
||||
self.state.saving = true
|
||||
roomNotificationRepository.update(state: state.notificationState) { [weak self] in
|
||||
let updateState = Self.mapNotificationStateOnUpdate(encrypted: self.state.roomEncrypted, state: state.notificationState)
|
||||
roomNotificationRepository.update(state: updateState) { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.state.saving = false
|
||||
self.coordinatorDelegate?.roomNotificationSettingsViewModelDidComplete(self)
|
||||
@@ -69,7 +74,27 @@ final class RoomNotificationSettingsViewModel: RoomNotificationSettingsViewModel
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private static func mapNotificationStateOnRead(encrypted: Bool, state: RoomNotificationState) -> RoomNotificationState {
|
||||
if encrypted, case .mentionsOnly = state {
|
||||
// Notifications not supported on encrypted rooms, map mentionsOnly to mute on read
|
||||
return .mute
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
private static func mapNotificationStateOnUpdate(encrypted: Bool, state: RoomNotificationState) -> RoomNotificationState {
|
||||
if encrypted, case .mute = state {
|
||||
// Notifications not supported on encrypted rooms, map mute to mentions only on update
|
||||
return .mentionsOnly
|
||||
} else {
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
private func update(viewState: RoomNotificationSettingsViewState) {
|
||||
self.viewDelegate?.roomNotificationSettingsViewModel(self, didUpdateViewState: viewState)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -20,11 +20,21 @@ import Foundation
|
||||
|
||||
/// RoomNotificationSettingsViewController view state
|
||||
struct RoomNotificationSettingsViewStateImpl: RoomNotificationSettingsViewState {
|
||||
let roomEncrypted: Bool
|
||||
var saving: Bool
|
||||
var notificationState: RoomNotificationState
|
||||
var notificationOptions: [RoomNotificationState] {
|
||||
if roomEncrypted {
|
||||
return [.all, .mute]
|
||||
} else {
|
||||
return RoomNotificationState.allCases
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protocol RoomNotificationSettingsViewState {
|
||||
var saving: Bool { get }
|
||||
var roomEncrypted: Bool { get }
|
||||
var notificationOptions: [RoomNotificationState] { get }
|
||||
var notificationState: RoomNotificationState { get }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user