mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 16:42:44 +02:00
Configured and applied SwiftFormat
This commit is contained in:
committed by
Stefan Ceriu
parent
ff2e6ddfa7
commit
43c28d23b7
+29
-31
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import Foundation
|
||||
|
||||
final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceType {
|
||||
|
||||
typealias Completion = () -> Void
|
||||
|
||||
// MARK: - Properties
|
||||
@@ -50,11 +49,11 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
// MARK: - Public
|
||||
|
||||
func observeNotificationState(listener: @escaping RoomNotificationStateCallback) {
|
||||
|
||||
let observer = NotificationCenter.default.addObserver(
|
||||
forName: NSNotification.Name(rawValue: kMXNotificationCenterDidUpdateRules),
|
||||
object: nil,
|
||||
queue: OperationQueue.main) { [weak self] _ in
|
||||
queue: OperationQueue.main
|
||||
) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
listener(self.room.notificationState)
|
||||
}
|
||||
@@ -88,7 +87,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
}
|
||||
|
||||
guard let rule = room.overridePushRule else {
|
||||
self.addPushRuleToMute(completion: completion)
|
||||
addPushRuleToMute(completion: completion)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -96,7 +95,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
MXLog.debug("[RoomNotificationSettingsService] Request in progress: ignore push rule update")
|
||||
completion()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// if the user defined one, use it
|
||||
if rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify) {
|
||||
@@ -130,7 +129,7 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
MXLog.debug("[MXRoom+Riot] Request in progress: ignore push rule update")
|
||||
completion()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// if the user defined one, use it
|
||||
if rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify) {
|
||||
@@ -140,11 +139,10 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
self.addPushRuleToMentionOnly(completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func allMessages(completion: @escaping Completion) {
|
||||
if !room.isMentionsOnly && !room.isMuted {
|
||||
if !room.isMentionsOnly, !room.isMuted {
|
||||
completion()
|
||||
return
|
||||
}
|
||||
@@ -172,7 +170,8 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
room.roomId,
|
||||
notify: false,
|
||||
sound: false,
|
||||
highlight: false)
|
||||
highlight: false
|
||||
)
|
||||
}
|
||||
|
||||
private func addPushRuleToMute(completion: @escaping Completion) {
|
||||
@@ -207,18 +206,19 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
private func enablePushRule(rule: MXPushRule, completion: @escaping Completion) {
|
||||
handleUpdateCallback(completion) {
|
||||
// No way to check whether this notification concerns the push rule. Consider the change is applied.
|
||||
return true
|
||||
true
|
||||
}
|
||||
handleFailureCallback(completion)
|
||||
|
||||
room.mxSession.notificationCenter.enableRule(rule, isEnabled: true)
|
||||
}
|
||||
|
||||
private func handleUpdateCallback(_ completion: @escaping Completion, releaseCheck: @escaping () -> Bool) {
|
||||
private func handleUpdateCallback(_ completion: @escaping Completion, releaseCheck: @escaping () -> Bool) {
|
||||
notificationCenterDidUpdateObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSNotification.Name(rawValue: kMXNotificationCenterDidUpdateRules),
|
||||
object: nil,
|
||||
queue: OperationQueue.main) { [weak self] _ in
|
||||
queue: OperationQueue.main
|
||||
) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
if releaseCheck() {
|
||||
self.removeObservers()
|
||||
@@ -231,7 +231,8 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
notificationCenterDidFailObserver = NotificationCenter.default.addObserver(
|
||||
forName: NSNotification.Name(rawValue: kMXNotificationCenterDidFailRulesUpdate),
|
||||
object: nil,
|
||||
queue: OperationQueue.main) { [weak self] _ in
|
||||
queue: OperationQueue.main
|
||||
) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
self.removeObservers()
|
||||
completion()
|
||||
@@ -239,23 +240,23 @@ final class MXRoomNotificationSettingsService: RoomNotificationSettingsServiceTy
|
||||
}
|
||||
|
||||
func removeObservers() {
|
||||
if let observer = self.notificationCenterDidUpdateObserver {
|
||||
if let observer = notificationCenterDidUpdateObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
self.notificationCenterDidUpdateObserver = nil
|
||||
notificationCenterDidUpdateObserver = nil
|
||||
}
|
||||
|
||||
if let observer = self.notificationCenterDidFailObserver {
|
||||
if let observer = notificationCenterDidFailObserver {
|
||||
NotificationCenter.default.removeObserver(observer)
|
||||
self.notificationCenterDidFailObserver = nil
|
||||
notificationCenterDidFailObserver = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension MXRoom {
|
||||
public var isMuted: Bool {
|
||||
public extension MXRoom {
|
||||
var isMuted: Bool {
|
||||
// Check whether an override rule has been defined with the roomm id as rule id.
|
||||
// This kind of rule is created to mute the room
|
||||
guard let rule = self.overridePushRule,
|
||||
guard let rule = overridePushRule,
|
||||
rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify),
|
||||
rule.conditionIsEnabled(kind: .eventMatch, for: roomId) else {
|
||||
return false
|
||||
@@ -263,7 +264,7 @@ extension MXRoom {
|
||||
return rule.enabled
|
||||
}
|
||||
|
||||
public var isMentionsOnly: Bool {
|
||||
var isMentionsOnly: Bool {
|
||||
// Check push rules at room level
|
||||
guard let rule = roomPushRule else { return false }
|
||||
return rule.enabled && rule.actionsContains(actionType: MXPushRuleActionTypeDontNotify)
|
||||
@@ -271,8 +272,7 @@ extension MXRoom {
|
||||
}
|
||||
|
||||
// We could move these to their own file and make available in global namespace or move to sdk but they are only used here at the moment
|
||||
fileprivate extension MXRoom {
|
||||
|
||||
private extension MXRoom {
|
||||
typealias Completion = () -> Void
|
||||
func getRoomRule(from rules: [Any]) -> MXPushRule? {
|
||||
guard let pushRules = rules as? [MXPushRule] else {
|
||||
@@ -285,19 +285,18 @@ fileprivate extension MXRoom {
|
||||
var overridePushRule: MXPushRule? {
|
||||
guard let overrideRules = mxSession.notificationCenter.rules.global.override else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return getRoomRule(from: overrideRules)
|
||||
}
|
||||
|
||||
var roomPushRule: MXPushRule? {
|
||||
guard let roomRules = mxSession.notificationCenter.rules.global.room else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return getRoomRule(from: roomRules)
|
||||
}
|
||||
|
||||
var notificationState: RoomNotificationState {
|
||||
|
||||
if isMuted {
|
||||
return .mute
|
||||
}
|
||||
@@ -306,10 +305,9 @@ fileprivate extension MXRoom {
|
||||
}
|
||||
return .all
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileprivate extension MXPushRule {
|
||||
private extension MXPushRule {
|
||||
func actionsContains(actionType: MXPushRuleActionType) -> Bool {
|
||||
guard let actions = actions as? [MXPushRuleAction] else {
|
||||
return false
|
||||
@@ -323,8 +321,8 @@ fileprivate extension MXPushRule {
|
||||
}
|
||||
let ruleContainsCondition = conditions.contains { condition in
|
||||
guard case kind = MXPushRuleConditionType(identifier: condition.kind),
|
||||
let key = condition.parameters["key"] as? String,
|
||||
let pattern = condition.parameters["pattern"] as? String
|
||||
let key = condition.parameters["key"] as? String,
|
||||
let pattern = condition.parameters["pattern"] as? String
|
||||
else { return false }
|
||||
return key == "room_id" && pattern == roomId
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,7 +17,6 @@
|
||||
import Foundation
|
||||
|
||||
class MockRoomNotificationSettingsService: RoomNotificationSettingsServiceType {
|
||||
|
||||
static let example = MockRoomNotificationSettingsService(initialState: .all)
|
||||
|
||||
var listener: RoomNotificationStateCallback?
|
||||
@@ -32,7 +31,7 @@ class MockRoomNotificationSettingsService: RoomNotificationSettingsServiceType {
|
||||
}
|
||||
|
||||
func update(state: RoomNotificationState, completion: @escaping UpdateRoomNotificationStateCompletion) {
|
||||
self.notificationState = state
|
||||
notificationState = state
|
||||
completion()
|
||||
listener?(state)
|
||||
}
|
||||
|
||||
+1
-2
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -20,7 +20,6 @@ typealias UpdateRoomNotificationStateCompletion = () -> Void
|
||||
typealias RoomNotificationStateCallback = (RoomNotificationState) -> Void
|
||||
|
||||
protocol RoomNotificationSettingsServiceType {
|
||||
|
||||
func observeNotificationState(listener: @escaping RoomNotificationStateCallback)
|
||||
func update(state: RoomNotificationState, completion: @escaping UpdateRoomNotificationStateCompletion)
|
||||
var notificationState: RoomNotificationState { get }
|
||||
|
||||
Reference in New Issue
Block a user