mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
Configured and applied SwiftFormat
This commit is contained in:
committed by
Stefan Ceriu
parent
ff2e6ddfa7
commit
43c28d23b7
@@ -14,8 +14,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import MatrixSDK
|
||||
import SwiftUI
|
||||
|
||||
struct RoomUpgradeCoordinatorParameters {
|
||||
let session: MXSession
|
||||
@@ -25,7 +25,6 @@ struct RoomUpgradeCoordinatorParameters {
|
||||
}
|
||||
|
||||
final class RoomUpgradeCoordinator: Coordinator, Presentable {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -53,6 +52,7 @@ final class RoomUpgradeCoordinator: Coordinator, Presentable {
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func start() {
|
||||
MXLog.debug("[RoomUpgradeCoordinator] did start.")
|
||||
roomUpgradeViewModel.completion = { [weak self] result in
|
||||
@@ -68,6 +68,6 @@ final class RoomUpgradeCoordinator: Coordinator, Presentable {
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return self.roomUpgradeHostingController
|
||||
roomUpgradeHostingController
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -36,7 +36,7 @@ enum MockRoomUpgradeScreenState: MockScreenState, CaseIterable {
|
||||
}
|
||||
|
||||
/// Generate the view struct for the screen state.
|
||||
var screenView: ([Any], AnyView) {
|
||||
var screenView: ([Any], AnyView) {
|
||||
let service: MockRoomUpgradeService
|
||||
switch self {
|
||||
case .initial:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
@@ -14,14 +14,13 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias RoomUpgradeViewModelType = StateStoreViewModel<RoomUpgradeViewState,
|
||||
Never,
|
||||
RoomUpgradeViewAction>
|
||||
Never,
|
||||
RoomUpgradeViewAction>
|
||||
class RoomUpgradeViewModel: RoomUpgradeViewModelType, RoomUpgradeViewModelProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -35,7 +34,7 @@ class RoomUpgradeViewModel: RoomUpgradeViewModelType, RoomUpgradeViewModelProtoc
|
||||
// MARK: - Setup
|
||||
|
||||
static func makeRoomUpgradeViewModel(roomUpgradeService: RoomUpgradeServiceProtocol) -> RoomUpgradeViewModelProtocol {
|
||||
return RoomUpgradeViewModel(roomUpgradeService: roomUpgradeService)
|
||||
RoomUpgradeViewModel(roomUpgradeService: roomUpgradeService)
|
||||
}
|
||||
|
||||
private init(roomUpgradeService: RoomUpgradeServiceProtocol) {
|
||||
@@ -45,7 +44,7 @@ class RoomUpgradeViewModel: RoomUpgradeViewModelType, RoomUpgradeViewModelProtoc
|
||||
}
|
||||
|
||||
private static func defaultState(roomUpgradeService: RoomUpgradeServiceProtocol) -> RoomUpgradeViewState {
|
||||
return RoomUpgradeViewState(waitingMessage: nil, isLoading: false, parentSpaceName: roomUpgradeService.parentSpaceName)
|
||||
RoomUpgradeViewState(waitingMessage: nil, isLoading: false, parentSpaceName: roomUpgradeService.parentSpaceName)
|
||||
}
|
||||
|
||||
private func setupObservers() {
|
||||
@@ -53,7 +52,7 @@ class RoomUpgradeViewModel: RoomUpgradeViewModelType, RoomUpgradeViewModelProtoc
|
||||
.upgradingSubject
|
||||
.sink { [weak self] isUpgrading in
|
||||
self?.state.isLoading = isUpgrading
|
||||
self?.state.waitingMessage = isUpgrading ? VectorL10n.roomAccessSettingsScreenUpgradeAlertUpgrading: nil
|
||||
self?.state.waitingMessage = isUpgrading ? VectorL10n.roomAccessSettingsScreenUpgradeAlertUpgrading : nil
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
@@ -65,7 +64,7 @@ class RoomUpgradeViewModel: RoomUpgradeViewModelType, RoomUpgradeViewModelProtoc
|
||||
case .cancel:
|
||||
completion?(.cancel(roomUpgradeService.currentRoomId))
|
||||
case .done(let autoInviteUsers):
|
||||
roomUpgradeService.upgradeRoom(autoInviteUsers: autoInviteUsers) { [weak self] success, roomId in
|
||||
roomUpgradeService.upgradeRoom(autoInviteUsers: autoInviteUsers) { [weak self] success, _ in
|
||||
guard let self = self else { return }
|
||||
if success {
|
||||
self.completion?(.done(self.roomUpgradeService.currentRoomId))
|
||||
|
||||
@@ -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
|
||||
|
||||
protocol RoomUpgradeViewModelProtocol {
|
||||
|
||||
var completion: ((RoomUpgradeViewModelResult) -> Void)? { get set }
|
||||
static func makeRoomUpgradeViewModel(roomUpgradeService: RoomUpgradeServiceProtocol) -> RoomUpgradeViewModelProtocol
|
||||
var context: RoomUpgradeViewModelType.Context { get }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,12 +14,11 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Foundation
|
||||
import MatrixSDK
|
||||
|
||||
class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -37,7 +36,7 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
private(set) var currentRoomId: String
|
||||
|
||||
var parentSpaceName: String? {
|
||||
guard let parentId = self.parentSpaceId else {
|
||||
guard let parentId = parentSpaceId else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -53,11 +52,11 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
|
||||
init(session: MXSession, roomId: String, parentSpaceId: String?, versionOverride: String) {
|
||||
self.session = session
|
||||
self.currentRoomId = roomId
|
||||
currentRoomId = roomId
|
||||
self.parentSpaceId = parentSpaceId
|
||||
self.versionOverride = versionOverride
|
||||
self.upgradingSubject = CurrentValueSubject(false)
|
||||
self.errorSubject = CurrentValueSubject(nil)
|
||||
upgradingSubject = CurrentValueSubject(false)
|
||||
errorSubject = CurrentValueSubject(nil)
|
||||
}
|
||||
|
||||
deinit {
|
||||
@@ -70,18 +69,18 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
func upgradeRoom(autoInviteUsers: Bool, completion: @escaping (Bool, String) -> Void) {
|
||||
upgradingSubject.send(true)
|
||||
|
||||
if autoInviteUsers, let room = session.room(withRoomId: self.currentRoomId) {
|
||||
self.currentOperation = room.members { [weak self] response in
|
||||
if autoInviteUsers, let room = session.room(withRoomId: currentRoomId) {
|
||||
currentOperation = room.members { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
switch response {
|
||||
case .success(let members):
|
||||
let memberIds: [String] = members?.members.compactMap({ member in
|
||||
let memberIds: [String] = members?.members.compactMap { member in
|
||||
guard member.membership == .join, member.userId != self.session.myUserId else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return member.userId
|
||||
}) ?? []
|
||||
} ?? []
|
||||
self.upgradeRoom(to: self.versionOverride, inviteUsers: memberIds, completion: completion)
|
||||
case .failure(let error):
|
||||
self.upgradingSubject.send(false)
|
||||
@@ -89,7 +88,7 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.upgradeRoom(to: versionOverride, inviteUsers: [], completion: completion)
|
||||
upgradeRoom(to: versionOverride, inviteUsers: [], completion: completion)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +97,7 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
private func upgradeRoom(to versionOverride: String, inviteUsers userIds: [String], completion: @escaping (Bool, String) -> Void) {
|
||||
// Need to disable graph update during this process as a lot of syncs will occure
|
||||
session.spaceService.graphUpdateEnabled = false
|
||||
currentOperation = session.matrixRestClient.upgradeRoom(withId: self.currentRoomId, to: versionOverride) { [weak self] response in
|
||||
currentOperation = session.matrixRestClient.upgradeRoom(withId: currentRoomId, to: versionOverride) { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch response {
|
||||
@@ -108,7 +107,7 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
let parentSpaces = self.session.spaceService.directParentIds(ofRoomWithId: oldRoomId)
|
||||
self.moveRoom(from: oldRoomId, to: replacementRoomId, within: Array(parentSpaces), at: 0) {
|
||||
self.session.spaceService.graphUpdateEnabled = true
|
||||
self.didBuildSpaceGraphObserver = NotificationCenter.default.addObserver(forName: MXSpaceService.didBuildSpaceGraph, object: nil, queue: OperationQueue.main) { [weak self] notification in
|
||||
self.didBuildSpaceGraphObserver = NotificationCenter.default.addObserver(forName: MXSpaceService.didBuildSpaceGraph, object: nil, queue: OperationQueue.main) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
|
||||
if let observer = self.didBuildSpaceGraphObserver {
|
||||
@@ -144,7 +143,7 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
}
|
||||
|
||||
space.moveChild(withRoomId: roomId, to: newRoomId) { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
guard let self = self else { return }
|
||||
|
||||
if let error = response.error {
|
||||
MXLog.warning("[RoomUpgradeService] moveRoom \(roomId) to \(newRoomId) within \(space.spaceId): failed due to error: \(error)")
|
||||
@@ -158,13 +157,13 @@ class RoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
/// Recurse to the next index once done.
|
||||
private func inviteUser(from userIds: [String], at index: Int, completion: @escaping (Bool, String) -> Void) {
|
||||
guard index < userIds.count else {
|
||||
self.upgradingSubject.send(false)
|
||||
upgradingSubject.send(false)
|
||||
completion(true, currentRoomId)
|
||||
return
|
||||
}
|
||||
|
||||
currentOperation = session.matrixRestClient.invite(.userId(userIds[index]), toRoom: currentRoomId) { [weak self] response in
|
||||
guard let self = self else { return }
|
||||
guard let self = self else { return }
|
||||
|
||||
self.currentOperation = nil
|
||||
if let error = response.error {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,24 +14,22 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
class MockRoomUpgradeService: RoomUpgradeServiceProtocol {
|
||||
var currentRoomId: String = "!sfdlksjdflkfjds:matrix.org"
|
||||
var currentRoomId = "!sfdlksjdflkfjds:matrix.org"
|
||||
|
||||
var errorSubject: CurrentValueSubject<Error?, Never>
|
||||
var upgradingSubject: CurrentValueSubject<Bool, Never>
|
||||
var parentSpaceName: String? {
|
||||
return "Parent space name"
|
||||
"Parent space name"
|
||||
}
|
||||
|
||||
init() {
|
||||
self.errorSubject = CurrentValueSubject(nil)
|
||||
self.upgradingSubject = CurrentValueSubject(false)
|
||||
errorSubject = CurrentValueSubject(nil)
|
||||
upgradingSubject = CurrentValueSubject(false)
|
||||
}
|
||||
|
||||
func upgradeRoom(autoInviteUsers: Bool, completion: @escaping (Bool, String) -> Void) {
|
||||
|
||||
}
|
||||
func upgradeRoom(autoInviteUsers: Bool, completion: @escaping (Bool, String) -> Void) { }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,8 +14,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
import Foundation
|
||||
|
||||
protocol RoomUpgradeServiceProtocol {
|
||||
var currentRoomId: String { get }
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import RiotSwiftUI
|
||||
import XCTest
|
||||
|
||||
class RoomUpgradeUITests: MockScreenTestCase {
|
||||
// Tests to be implemented.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,8 +14,8 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Combine
|
||||
import XCTest
|
||||
|
||||
@testable import RiotSwiftUI
|
||||
|
||||
@@ -24,7 +24,5 @@ class RoomUpgradeViewModelTests: XCTestCase {
|
||||
var viewModel: RoomUpgradeViewModelProtocol!
|
||||
var context: RoomUpgradeViewModelType.Context!
|
||||
|
||||
override func setUpWithError() throws {
|
||||
}
|
||||
|
||||
override func setUpWithError() throws { }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,10 +17,9 @@
|
||||
import SwiftUI
|
||||
|
||||
struct RoomUpgrade: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
@State var autoInviteUsers: Bool = true
|
||||
@State var autoInviteUsers = true
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@@ -86,13 +85,13 @@ struct RoomUpgrade: View {
|
||||
.padding(.horizontal, 24)
|
||||
.padding(.vertical, 16)
|
||||
}
|
||||
.background(RoundedRectangle.init(cornerRadius: 8).foregroundColor(theme.colors.background))
|
||||
.background(RoundedRectangle(cornerRadius: 8).foregroundColor(theme.colors.background))
|
||||
.padding(.horizontal, 20)
|
||||
.frame(minWidth: 0, maxWidth: 500)
|
||||
}
|
||||
|
||||
private func noteText(_ message: String) -> some View {
|
||||
return Text(message)
|
||||
Text(message)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(theme.fonts.subheadline)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
|
||||
Reference in New Issue
Block a user