MESSENGER-3671 Merge FOSS 1.9.8

Conflicts:
 - CommonConfiguration.swift
 - BuildSettings.swift
 - Generated/images.Swift
 - RoomMemberDetailsViewController.m
 - LiveLocationSharingViewModell
-  PinCodeEnterViewController.m
This commit is contained in:
Frank Rotermund
2022-10-05 15:47:27 +02:00
744 changed files with 6999 additions and 3819 deletions
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,6 @@ import SwiftUI
class AddRoomSelectorViewProvider: MatrixItemChooserCoordinatorViewProvider {
func view(with viewModel: MatrixItemChooserViewModelType.Context) -> AnyView {
return AnyView(AddRoomSelector(viewModel: viewModel))
AnyView(AddRoomSelector(viewModel: viewModel))
}
}
@@ -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 AddRoomItemsProcessor: MatrixItemChooserProcessorProtocol {
// MARK: Private
private let parentSpace: MXSpace
@@ -40,14 +39,14 @@ class AddRoomItemsProcessor: MatrixItemChooserProcessorProtocol {
addChild(from: itemsIds, at: 0, completion: completion)
}
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool {
return !parentSpace.isRoomAChild(roomId: item.id)
func isItemIncluded(_ item: MatrixListItemData) -> Bool {
!parentSpace.isRoomAChild(roomId: item.id)
}
// MARK: Private
/// Add room with roomId from list of room IDs at index to the parentSpace.
/// Recurse to the next index once done.
/// Recurse to the next index once done.
func addChild(from roomIds: [String], at index: Int, completion: @escaping (Result<Void, Error>) -> Void) {
guard index < roomIds.count else {
// last item has been processed or list is empty --> the recursion has finished
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct AddRoomSelector: View {
// MARK: Properties
@ObservedObject var viewModel: MatrixItemChooserViewModel.Context
@@ -26,7 +25,7 @@ struct AddRoomSelector: View {
@Environment(\.theme) private var theme: ThemeSwiftUI
private var isDoneEnabled: Bool {
return !viewModel.viewState.selectedItemIds.isEmpty && !viewModel.viewState.loading
!viewModel.viewState.selectedItemIds.isEmpty && !viewModel.viewState.loading
}
// MARK: Setup
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
class LeaveSpaceViewProvider: MatrixItemChooserCoordinatorViewProvider {
private let navTitle: String?
init(navTitle: String?) {
@@ -25,6 +24,6 @@ class LeaveSpaceViewProvider: MatrixItemChooserCoordinatorViewProvider {
}
func view(with viewModel: MatrixItemChooserViewModelType.Context) -> AnyView {
return AnyView(LeaveSpace(viewModel: viewModel, navTitle: navTitle))
AnyView(LeaveSpace(viewModel: viewModel, navTitle: navTitle))
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,6 @@ import Foundation
import MatrixSDK
class LeaveSpaceItemsProcessor: MatrixItemChooserProcessorProtocol {
// MARK: Private
private let spaceId: String
@@ -29,7 +28,7 @@ class LeaveSpaceItemsProcessor: MatrixItemChooserProcessorProtocol {
init(spaceId: String, session: MXSession) {
self.spaceId = spaceId
self.session = session
self.dataSource = MatrixItemChooserDirectChildrenDataSource(parentId: spaceId)
dataSource = MatrixItemChooserDirectChildrenDataSource(parentId: spaceId)
}
// MARK: MatrixItemChooserSelectionProcessorProtocol
@@ -41,11 +40,11 @@ class LeaveSpaceItemsProcessor: MatrixItemChooserProcessorProtocol {
}
func computeSelection(withIds itemsIds: [String], completion: @escaping (Result<Void, Error>) -> Void) {
guard let space = self.session.spaceService.getSpace(withId: self.spaceId) else {
guard let space = session.spaceService.getSpace(withId: spaceId) else {
return
}
self.leaveAllRooms(from: itemsIds, at: 0) { [weak self] result in
leaveAllRooms(from: itemsIds, at: 0) { [weak self] result in
guard let self = self else { return }
switch result {
@@ -57,8 +56,8 @@ class LeaveSpaceItemsProcessor: MatrixItemChooserProcessorProtocol {
}
}
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool {
return true
func isItemIncluded(_ item: MatrixListItemData) -> Bool {
true
}
// MARK: Private
@@ -71,8 +70,8 @@ class LeaveSpaceItemsProcessor: MatrixItemChooserProcessorProtocol {
return
}
guard let room = self.session.room(withRoomId: roomIds[index]), !room.isDirect else {
self.leaveAllRooms(from: roomIds, at: index+1, completion: completion)
guard let room = session.room(withRoomId: roomIds[index]), !room.isDirect else {
leaveAllRooms(from: roomIds, at: index + 1, completion: completion)
return
}
@@ -82,7 +81,7 @@ class LeaveSpaceItemsProcessor: MatrixItemChooserProcessorProtocol {
switch response {
case .success:
self.leaveAllRooms(from: roomIds, at: index+1, completion: completion)
self.leaveAllRooms(from: roomIds, at: index + 1, completion: completion)
case .failure(let error):
MXLog.error("[LeaveSpaceItemsProcessor] failed to leave room", context: error)
completion(.failure(error))
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct LeaveSpace: View {
// MARK: Properties
@ObservedObject var viewModel: MatrixItemChooserViewModel.Context
@@ -53,5 +52,4 @@ struct LeaveSpace: View {
.buttonStyle(PrimaryActionButtonStyle(customColor: theme.colors.alert))
.padding()
}
}
@@ -15,8 +15,8 @@
//
import Foundation
import UIKit
import SwiftUI
import UIKit
internal protocol MatrixItemChooserCoordinatorViewProvider {
func view(with viewModel: MatrixItemChooserViewModelType.Context) -> AnyView
@@ -49,7 +49,6 @@ struct MatrixItemChooserCoordinatorParameters {
}
final class MatrixItemChooserCoordinator: Coordinator, Presentable {
// MARK: - Properties
// MARK: Private
@@ -94,6 +93,6 @@ final class MatrixItemChooserCoordinator: Coordinator, Presentable {
// MARK: - Presentable
func toPresentable() -> UIViewController {
return self.matrixItemChooserHostingController
matrixItemChooserHostingController
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -58,7 +58,7 @@ struct MatrixListItemSectionData {
}
}
extension MatrixListItemSectionData: Identifiable, Equatable {}
extension MatrixListItemSectionData: Identifiable, Equatable { }
struct MatrixListItemData {
let id: String
@@ -68,7 +68,7 @@ struct MatrixListItemData {
let detailText: String?
}
extension MatrixListItemData: Identifiable, Equatable {}
extension MatrixListItemData: Identifiable, Equatable { }
struct MatrixItemChooserSelectionHeader {
var title: String
@@ -14,21 +14,19 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias MatrixItemChooserViewModelType = StateStoreViewModel<MatrixItemChooserViewState, MatrixItemChooserViewAction>
typealias MatrixItemChooserViewModelType = StateStoreViewModel<MatrixItemChooserViewState,
Never,
MatrixItemChooserViewAction>
class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChooserViewModelProtocol {
// MARK: - Properties
// MARK: Private
private var matrixItemChooserService: MatrixItemChooserServiceProtocol
private var isLoading: Bool = false {
private var isLoading = false {
didSet {
state.loading = isLoading
if isLoading {
@@ -44,7 +42,7 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
// MARK: - Setup
static func makeMatrixItemChooserViewModel(matrixItemChooserService: MatrixItemChooserServiceProtocol, title: String?, detail: String?, selectionHeader: MatrixItemChooserSelectionHeader?) -> MatrixItemChooserViewModelProtocol {
return MatrixItemChooserViewModel(matrixItemChooserService: matrixItemChooserService, title: title, detail: detail, selectionHeader: selectionHeader)
MatrixItemChooserViewModel(matrixItemChooserService: matrixItemChooserService, title: title, detail: detail, selectionHeader: selectionHeader)
}
private init(matrixItemChooserService: MatrixItemChooserServiceProtocol, title: String?, detail: String?, selectionHeader: MatrixItemChooserSelectionHeader?) {
@@ -98,13 +96,13 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
}
}
case .searchTextChanged(let searchText):
self.matrixItemChooserService.searchText = searchText
matrixItemChooserService.searchText = searchText
case .itemTapped(let itemId):
self.matrixItemChooserService.reverseSelectionForItem(withId: itemId)
matrixItemChooserService.reverseSelectionForItem(withId: itemId)
case .selectAll:
self.matrixItemChooserService.selectAllItems()
matrixItemChooserService.selectAllItems()
case .selectNone:
self.matrixItemChooserService.deselectAllItems()
matrixItemChooserService.deselectAllItems()
}
}
@@ -119,5 +117,4 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
private func back() {
completion?(.back)
}
}
@@ -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 MatrixItemChooserViewModelProtocol {
var completion: ((MatrixItemChooserViewModelResult) -> Void)? { get set }
static func makeMatrixItemChooserViewModel(matrixItemChooserService: MatrixItemChooserServiceProtocol, title: String?, detail: String?, selectionHeader: MatrixItemChooserSelectionHeader?) -> MatrixItemChooserViewModelProtocol
var context: MatrixItemChooserViewModelType.Context { get }
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -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 MatrixItemChooserServiceProtocol {
var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never> { get }
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import Foundation
class MatrixItemChooserDirectChildrenDataSource: MatrixItemChooserDataSource {
// MARK: - Private
private let parentId: String
@@ -34,13 +33,13 @@ class MatrixItemChooserDirectChildrenDataSource: MatrixItemChooserDataSource {
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
let space = session.spaceService.getSpace(withId: parentId)
let children: [MatrixListItemData] = space?.childRoomIds.compactMap({ roomId in
let children: [MatrixListItemData] = space?.childRoomIds.compactMap { roomId in
guard let room = session.room(withRoomId: roomId), !room.isDirect else {
return nil
}
return MatrixListItemData(mxRoom: room, spaceService: session.spaceService)
}) ?? []
} ?? []
completion(Result(catching: {
[
MatrixListItemSectionData(items: children)
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +28,7 @@ class MatrixItemChooserRoomAncestorsDataSource: MatrixItemChooserDataSource {
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
let ancestorsIds = session.spaceService.ancestorsPerRoomId[roomId] ?? []
completion(Result(catching: {
return [
[
MatrixListItemSectionData(title: VectorL10n.roomAccessSpaceChooserKnownSpacesSection(session.room(withRoomId: roomId)?.displayName ?? ""), items: ancestorsIds.compactMap { spaceId in
guard let space = session.spaceService.getSpace(withId: spaceId) else {
return nil
@@ -22,7 +22,6 @@ enum MatrixItemChooserRoomDirectParentsDataSourcePreselectionMode {
}
class MatrixItemChooserRoomDirectParentsDataSource: MatrixItemChooserDataSource {
private let roomId: String
private let preselectionMode: MatrixItemChooserRoomDirectParentsDataSourcePreselectionMode
@@ -44,7 +43,7 @@ class MatrixItemChooserRoomDirectParentsDataSource: MatrixItemChooserDataSource
}
completion(Result(catching: {
return [
[
MatrixListItemSectionData(title: VectorL10n.roomAccessSpaceChooserKnownSpacesSection(session.room(withRoomId: roomId)?.displayName ?? ""), items: ancestorsIds.compactMap { spaceId in
guard let space = session.spaceService.getSpace(withId: spaceId) else {
return nil
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,7 +34,7 @@ class MatrixItemChooserRoomRestrictedAllowedParentsDataSource: MatrixItemChooser
}
room.state { [weak self] state in
guard let self = self else { return }
guard let self = self else { return }
let joinRuleEvent = state?.stateEvents(with: .roomJoinRules)?.last
let allowContent: [[String: String]] = joinRuleEvent?.wireContent[kMXJoinRulesContentKeyAllow] as? [[String: String]] ?? []
@@ -74,19 +74,20 @@ class MatrixItemChooserRoomRestrictedAllowedParentsDataSource: MatrixItemChooser
sections.append(MatrixListItemSectionData(
title: VectorL10n.roomAccessSpaceChooserOtherSpacesSection,
infoText: VectorL10n.roomAccessSpaceChooserOtherSpacesSectionInfo(room.displayName ?? ""),
items: unknownParents.compactMap({ roomId in
items: unknownParents.compactMap { roomId in
MatrixListItemData(
id: roomId,
type: .space,
avatar: AvatarInput(mxContentUri: roomId, matrixItemId: roomId, displayName: roomId),
displayName: roomId,
detailText: nil)
})
detailText: nil
)
}
))
}
completion(Result(catching: {
return sections
sections
}))
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -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 MatrixItemChooserDataSource {
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void)
@@ -25,12 +25,11 @@ protocol MatrixItemChooserDataSource {
protocol MatrixItemChooserProcessorProtocol {
var loadingText: String? { get }
var dataSource: MatrixItemChooserDataSource { get }
func computeSelection(withIds itemsIds:[String], completion: @escaping (Result<Void, Error>) -> Void)
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool
func computeSelection(withIds itemsIds: [String], completion: @escaping (Result<Void, Error>) -> Void)
func isItemIncluded(_ item: MatrixListItemData) -> Bool
}
class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
// MARK: - Properties
// MARK: Private
@@ -45,6 +44,7 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
sectionsSubject.send(filteredSections)
}
}
private var selectedItemIds: Set<String>
private let itemsProcessor: MatrixItemChooserProcessorProtocol
@@ -52,14 +52,16 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
private(set) var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never>
private(set) var selectedItemIdsSubject: CurrentValueSubject<Set<String>, Never>
var searchText: String = "" {
var searchText = "" {
didSet {
refresh()
}
}
var loadingText: String? {
itemsProcessor.loadingText
}
var itemCount: Int {
var itemCount = 0
for section in sections {
@@ -72,10 +74,10 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
init(session: MXSession, selectedItemIds: [String], itemsProcessor: MatrixItemChooserProcessorProtocol) {
self.session = session
self.sectionsSubject = CurrentValueSubject(self.sections)
sectionsSubject = CurrentValueSubject(sections)
self.selectedItemIds = Set(selectedItemIds)
self.selectedItemIdsSubject = CurrentValueSubject(self.selectedItemIds)
selectedItemIdsSubject = CurrentValueSubject(self.selectedItemIds)
self.itemsProcessor = itemsProcessor
itemsProcessor.dataSource.sections(with: session) { [weak self] result in
@@ -115,7 +117,7 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
}
func refresh() {
self.processingQueue.async { [weak self] in
processingQueue.async { [weak self] in
guard let self = self else { return }
let filteredSections = self.filter(sections: self.sections)
@@ -132,12 +134,12 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
newSelection.insert(item.id)
}
}
self.selectedItemIds = newSelection
selectedItemIds = newSelection
selectedItemIdsSubject.send(selectedItemIds)
}
func deselectAllItems() {
self.selectedItemIds = Set()
selectedItemIds = Set()
selectedItemIdsSubject.send(selectedItemIds)
}
@@ -153,7 +155,7 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
itemsProcessor.isItemIncluded($0)
}
} else {
let lowercasedSearchText = self.searchText.lowercased()
let lowercasedSearchText = searchText.lowercased()
items = section.items.filter {
itemsProcessor.isItemIncluded($0) && ($0.id.lowercased().contains(lowercasedSearchText) || ($0.displayName ?? "").lowercased().contains(lowercasedSearchText))
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -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
extension MatrixListItemData {
init(mxUser: MXUser) {
self.init(id: mxUser.userId, type: .user, avatar: mxUser.avatarData, displayName: mxUser.displayname, detailText: mxUser.userId)
}
@@ -54,5 +53,4 @@ extension MatrixListItemData {
}
self.init(id: mxRoom.roomId, type: type, avatar: mxRoom.avatarData, displayName: mxRoom.summary.displayname, detailText: detailText)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,11 +14,10 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
static let mockSections = [
MatrixListItemSectionData(title: "Section 1", infoText: "This is the first section with a very long description in order to check multi line description", items: [
MatrixListItemData(id: "!aaabaa:matrix.org", type: .room, avatar: MockAvatarInput.example, displayName: "Item #1 section #1", detailText: "Descripton of this room"),
@@ -33,11 +32,12 @@ class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
]
var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never>
var selectedItemIdsSubject: CurrentValueSubject<Set<String>, Never>
var searchText: String = ""
var searchText = ""
var selectedItemIds: Set<String> = Set()
var loadingText: String? {
nil
}
var itemCount: Int {
var itemCount = 0
for section in sectionsSubject.value {
@@ -82,9 +82,7 @@ class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
completion(Result.success(()))
}
func refresh() {
}
func refresh() { }
func selectAllItems() {
var newSelection: Set<String> = Set()
@@ -93,12 +91,12 @@ class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
newSelection.insert(item.id)
}
}
self.selectedItemIds = newSelection
selectedItemIds = newSelection
selectedItemIdsSubject.send(selectedItemIds)
}
func deselectAllItems() {
self.selectedItemIds = Set()
selectedItemIds = Set()
selectedItemIdsSubject.send(selectedItemIds)
}
}
@@ -14,8 +14,8 @@
// limitations under the License.
//
import XCTest
import RiotSwiftUI
import XCTest
class MatrixItemChooserUITests: MockScreenTestCase {
func testEmptyScreen() {
@@ -42,5 +42,4 @@ class MatrixItemChooserUITests: MockScreenTestCase {
XCTAssertEqual(app.staticTexts["messageText"].label, VectorL10n.spacesCreationAddRoomsMessage)
XCTAssertEqual(app.staticTexts["emptyListMessage"].exists, false)
}
}
@@ -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
@@ -19,12 +19,11 @@
import SwiftUI
struct MatrixItemChooser: View {
// MARK: Properties
@ObservedObject var viewModel: MatrixItemChooserViewModel.Context
let listBottomPadding: CGFloat?
@State var searchText: String = ""
@State var searchText = ""
// MARK: Private
@@ -113,7 +112,7 @@ struct MatrixItemChooser: View {
}
Spacer().frame(height: spacerHeight)
SearchBar(placeholder: VectorL10n.searchDefaultPlaceholder, text: $searchText)
.onChange(of: searchText) { value in
.onChange(of: searchText) { _ in
viewModel.send(viewAction: .searchTextChanged(searchText))
}
if let selectionHeader = viewModel.viewState.selectionHeader, searchText.isEmpty {
@@ -124,7 +123,7 @@ struct MatrixItemChooser: View {
}
private func itemSelectionHeader(with selectionHeader: MatrixItemChooserSelectionHeader) -> some View {
VStack(alignment:.leading) {
VStack(alignment: .leading) {
HStack {
Text(selectionHeader.title)
.font(theme.fonts.calloutSB)
@@ -151,7 +150,6 @@ struct MatrixItemChooser: View {
// MARK: - Previews
struct MatrixItemChooser_Previews: PreviewProvider {
static let stateRenderer = MockMatrixItemChooserScreenState.stateRenderer
static var previews: some View {
stateRenderer.screenGroup(addNavigation: false)
@@ -17,7 +17,6 @@
import SwiftUI
struct MatrixItemChooserListRow: View {
// MARK: - Properties
// MARK: Private
@@ -34,7 +33,7 @@ struct MatrixItemChooserListRow: View {
@ViewBuilder
var body: some View {
HStack{
HStack {
if type == .space {
SpaceAvatarImage(avatarData: avatar, size: .small)
} else {
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct MatrixItemChooserSectionHeader: View {
// MARK: - Properties
// MARK: Private
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
class RoomAncestorSelectorViewProvider: MatrixItemChooserCoordinatorViewProvider {
private let navTitle: String?
init(navTitle: String?) {
@@ -25,6 +24,6 @@ class RoomAncestorSelectorViewProvider: MatrixItemChooserCoordinatorViewProvider
}
func view(with viewModel: MatrixItemChooserViewModelType.Context) -> AnyView {
return AnyView(RoomAncestorSelector(viewModel: viewModel, navTitle: navTitle))
AnyView(RoomAncestorSelector(viewModel: viewModel, navTitle: navTitle))
}
}
@@ -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 RoomAncestorSelectorItemsProcessor: MatrixItemChooserProcessorProtocol {
// MARK: Private
private let roomId: String
@@ -26,7 +25,7 @@ class RoomAncestorSelectorItemsProcessor: MatrixItemChooserProcessorProtocol {
init(roomId: String) {
self.roomId = roomId
self.dataSource = MatrixItemChooserRoomAncestorsDataSource(roomId: roomId)
dataSource = MatrixItemChooserRoomAncestorsDataSource(roomId: roomId)
}
// MARK: MatrixItemChooserSelectionProcessorProtocol
@@ -41,7 +40,7 @@ class RoomAncestorSelectorItemsProcessor: MatrixItemChooserProcessorProtocol {
completion(Result.success(()))
}
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool {
return true
func isItemIncluded(_ item: MatrixListItemData) -> Bool {
true
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct RoomAncestorSelector: View {
// MARK: Properties
@ObservedObject var viewModel: MatrixItemChooserViewModel.Context
@@ -46,5 +45,4 @@ struct RoomAncestorSelector: View {
}
}
}
}
@@ -22,7 +22,6 @@ import UIKit
@objcMembers
final class SpaceCreationCoordinator: Coordinator {
// MARK: - Properties
// MARK: Private
@@ -30,7 +29,7 @@ final class SpaceCreationCoordinator: Coordinator {
private let parameters: SpaceCreationCoordinatorParameters
private var navigationRouter: NavigationRouterType {
return self.parameters.navigationRouter
parameters.navigationRouter
}
private let spaceVisibilityMenuParameters: SpaceCreationMenuCoordinatorParameters
@@ -57,7 +56,7 @@ final class SpaceCreationCoordinator: Coordinator {
}
self.parameters = parameters
self.spaceVisibilityMenuParameters = SpaceCreationMenuCoordinatorParameters(
spaceVisibilityMenuParameters = SpaceCreationMenuCoordinatorParameters(
session: parameters.session,
creationParams: parameters.creationParameters,
navTitle: VectorL10n.spacesCreateSpaceTitle,
@@ -70,7 +69,7 @@ final class SpaceCreationCoordinator: Coordinator {
]
)
self.spaceSharingTypeMenuParameters = SpaceCreationMenuCoordinatorParameters(
spaceSharingTypeMenuParameters = SpaceCreationMenuCoordinatorParameters(
session: parameters.session,
creationParams: parameters.creationParameters,
navTitle: nil,
@@ -91,26 +90,26 @@ final class SpaceCreationCoordinator: Coordinator {
Analytics.shared.trackScreen(.createSpace)
let rootCoordinator = self.createMenuCoordinator(with: spaceVisibilityMenuParameters)
let rootCoordinator = createMenuCoordinator(with: spaceVisibilityMenuParameters)
rootCoordinator.start()
self.add(childCoordinator: rootCoordinator)
add(childCoordinator: rootCoordinator)
self.toPresentable().isModalInPresentation = true
toPresentable().isModalInPresentation = true
if self.navigationRouter.modules.isEmpty == false {
self.navigationRouter.push(rootCoordinator, animated: true, popCompletion: { [weak self] in
if navigationRouter.modules.isEmpty == false {
navigationRouter.push(rootCoordinator, animated: true, popCompletion: { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
})
} else {
self.navigationRouter.setRootModule(rootCoordinator) { [weak self] in
navigationRouter.setRootModule(rootCoordinator) { [weak self] in
self?.remove(childCoordinator: rootCoordinator)
}
}
}
func toPresentable() -> UIViewController {
return self.navigationRouter.toPresentable()
navigationRouter.toPresentable()
}
// MARK: - Private
@@ -118,7 +117,7 @@ final class SpaceCreationCoordinator: Coordinator {
func pushScreen(with coordinator: Coordinator & Presentable) {
add(childCoordinator: coordinator)
self.navigationRouter.push(coordinator, animated: true, popCompletion: { [weak self] in
navigationRouter.push(coordinator, animated: true, popCompletion: { [weak self] in
self?.remove(childCoordinator: coordinator)
})
@@ -126,7 +125,7 @@ final class SpaceCreationCoordinator: Coordinator {
}
private func createMenuCoordinator(with parameters: SpaceCreationMenuCoordinatorParameters) -> SpaceCreationMenuCoordinator {
let coordinator: SpaceCreationMenuCoordinator = SpaceCreationMenuCoordinator(parameters: parameters)
let coordinator = SpaceCreationMenuCoordinator(parameters: parameters)
coordinator.callback = { [weak self] result in
MXLog.debug("[SpaceCreationCoordinator] SpaceCreationMenuCoordinator did complete with result \(result).")
@@ -217,7 +216,8 @@ final class SpaceCreationCoordinator: Coordinator {
detail: VectorL10n.spacesCreationInviteByUsernameMessage,
selectedItemsIds: parameters.creationParameters.userIdInvites,
viewProvider: SpaceCreationMatrixItemChooserViewProvider(),
itemsProcessor: SpaceCreationInviteUsersItemsProcessor(creationParams: parameters.creationParameters))
itemsProcessor: SpaceCreationInviteUsersItemsProcessor(creationParams: parameters.creationParameters)
)
let coordinator = MatrixItemChooserCoordinator(parameters: parameters)
coordinator.completion = { [weak self] result in
guard let self = self else { return }
@@ -240,7 +240,8 @@ final class SpaceCreationCoordinator: Coordinator {
detail: VectorL10n.spacesCreationAddRoomsMessage,
selectedItemsIds: parameters.creationParameters.addedRoomIds ?? [],
viewProvider: SpaceCreationMatrixItemChooserViewProvider(),
itemsProcessor: SpaceCreationAddRoomsItemsProcessor(creationParams: parameters.creationParameters))
itemsProcessor: SpaceCreationAddRoomsItemsProcessor(creationParams: parameters.creationParameters)
)
let coordinator = MatrixItemChooserCoordinator(parameters: parameters)
coordinator.completion = { [weak self] result in
guard let self = self else { return }
@@ -275,13 +276,13 @@ final class SpaceCreationCoordinator: Coordinator {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
let alert = UIAlertController(title: VectorL10n.spacesCreationCancelTitle, message: VectorL10n.spacesCreationCancelMessage, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: VectorL10n.stop, style: .destructive, handler: { action in
alert.addAction(UIAlertAction(title: VectorL10n.stop, style: .destructive, handler: { _ in
self.callback?(.cancel)
}))
alert.addAction(UIAlertAction(title: BWIL10n.continue, style: .cancel, handler: nil))
navigationRouter.present(alert, animated: true)
} else {
self.callback?(.cancel)
callback?(.cancel)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@ import Foundation
/// SpaceCreationCoordinator input parameters
struct SpaceCreationCoordinatorParameters {
/// The Matrix session
let session: MXSession
@@ -30,7 +29,7 @@ struct SpaceCreationCoordinatorParameters {
let parentSpaceId: String?
/// Parameters needed to create the new space
let creationParameters: SpaceCreationParameters = SpaceCreationParameters()
let creationParameters = SpaceCreationParameters()
/// The navigation router that manage physical navigation
let navigationRouter: NavigationRouterType
@@ -17,11 +17,10 @@
*/
import Foundation
import UIKit
import SwiftUI
import UIKit
final class SpaceCreationEmailInvitesCoordinator: Coordinator, Presentable {
// MARK: - Properties
// MARK: Private
@@ -75,7 +74,7 @@ final class SpaceCreationEmailInvitesCoordinator: Coordinator, Presentable {
}
func toPresentable() -> UIViewController {
return self.spaceCreationEmailInvitesHostingController
spaceCreationEmailInvitesHostingController
}
// MARK: - Identity service
@@ -90,34 +89,34 @@ final class SpaceCreationEmailInvitesCoordinator: Coordinator, Presentable {
let presenter = ServiceTermsModalCoordinatorBridgePresenter(session: parameters.session, baseUrl: baseUrl, serviceType: MXServiceTypeIdentityService, accessToken: accessToken)
presenter.delegate = self
presenter.present(from: self.toPresentable(), animated: true)
presenter.present(from: toPresentable(), animated: true)
serviceTermsModalCoordinatorBridgePresenter = presenter
}
private func showIdentityServiceFailure(_ error: Error?) {
let alertController = UIAlertController(title: VectorL10n.findYourContactsIdentityServiceError, message: nil, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: VectorL10n.ok, style: .default, handler: nil))
self.toPresentable().present(alertController, animated: true, completion: nil);
toPresentable().present(alertController, animated: true, completion: nil)
}
}
extension SpaceCreationEmailInvitesCoordinator: ServiceTermsModalCoordinatorBridgePresenterDelegate {
func serviceTermsModalCoordinatorBridgePresenterDelegateDidAccept(_ coordinatorBridgePresenter: ServiceTermsModalCoordinatorBridgePresenter) {
coordinatorBridgePresenter.dismiss(animated: true) {
self.serviceTermsModalCoordinatorBridgePresenter = nil;
self.serviceTermsModalCoordinatorBridgePresenter = nil
self.callback?(.done)
}
}
func serviceTermsModalCoordinatorBridgePresenterDelegateDidDecline(_ coordinatorBridgePresenter: ServiceTermsModalCoordinatorBridgePresenter, session: MXSession) {
coordinatorBridgePresenter.dismiss(animated: true) {
self.serviceTermsModalCoordinatorBridgePresenter = nil;
self.serviceTermsModalCoordinatorBridgePresenter = nil
}
}
func serviceTermsModalCoordinatorBridgePresenterDelegateDidClose(_ coordinatorBridgePresenter: ServiceTermsModalCoordinatorBridgePresenter) {
coordinatorBridgePresenter.dismiss(animated: true) {
self.serviceTermsModalCoordinatorBridgePresenter = nil;
self.serviceTermsModalCoordinatorBridgePresenter = nil
}
}
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,24 +0,0 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
// Copyright 2021 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
enum SpaceCreationEmailInvitesStateAction {
case updateEmailValidity(_ validity: [Bool])
case updateLoading(_ loading: Bool)
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,11 +16,10 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
class SpaceCreationEmailInvitesService: SpaceCreationEmailInvitesServiceProtocol {
private let session: MXSession
private(set) var isLoadingSubject: CurrentValueSubject<Bool, Never>
@@ -37,12 +36,12 @@ class SpaceCreationEmailInvitesService: SpaceCreationEmailInvitesServiceProtocol
}
func validate(_ emailAddresses: [String]) -> [Bool] {
return emailAddresses.map { $0.isEmpty || MXTools.isEmailAddress($0) }
emailAddresses.map { $0.isEmpty || MXTools.isEmailAddress($0) }
}
func prepareIdentityService(prepared: ((String?, String?) -> Void)?, failure: ((Error?) -> Void)?) {
isLoadingSubject.send(true)
session.prepareIdentityServiceForTerms(withDefault: RiotSettings.shared.identityServerUrlString) { [weak self] session, baseURL, accessToken in
session.prepareIdentityServiceForTerms(withDefault: RiotSettings.shared.identityServerUrlString) { [weak self] _, baseURL, accessToken in
self?.isLoadingSubject.send(false)
prepared?(baseURL, accessToken)
} failure: { [weak self] error in
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -41,7 +41,7 @@ enum MockSpaceCreationEmailInvitesScreenState: MockScreenState, CaseIterable {
}
/// Generate the view struct for the screen state.
var screenView: ([Any], AnyView) {
var screenView: ([Any], AnyView) {
let creationParams = SpaceCreationParameters()
let service: MockSpaceCreationEmailInvitesService
switch self {
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
class MockSpaceCreationEmailInvitesService: SpaceCreationEmailInvitesServiceProtocol {
var isLoadingSubject: CurrentValueSubject<Bool, Never>
@@ -25,16 +25,16 @@ class MockSpaceCreationEmailInvitesService: SpaceCreationEmailInvitesServiceProt
private let defaultValidation: Bool
var isIdentityServiceReady: Bool {
return true
true
}
init(defaultValidation: Bool, isLoading: Bool) {
self.defaultValidation = defaultValidation
self.isLoadingSubject = CurrentValueSubject(isLoading)
isLoadingSubject = CurrentValueSubject(isLoading)
}
func validate(_ emailAddresses: [String]) -> [Bool] {
return emailAddresses.map { _ in defaultValidation }
emailAddresses.map { _ in defaultValidation }
}
func prepareIdentityService(prepared: ((String?, String?) -> Void)?, failure: ((Error?) -> Void)?) {
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
protocol SpaceCreationEmailInvitesServiceProtocol {
var isIdentityServiceReady: Bool { get }
@@ -16,8 +16,8 @@
// limitations under the License.
//
import XCTest
import RiotSwiftUI
import XCTest
class SpaceCreationEmailInvitesUITests: MockScreenTestCase {
func testDefaultEmailValues() {
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,8 @@
// limitations under the License.
//
import XCTest
import Combine
import XCTest
@testable import RiotSwiftUI
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@
import SwiftUI
struct SpaceCreationEmailInvites: View {
// MARK: - Properties
@ObservedObject var viewModel: SpaceCreationEmailInvitesViewModel.Context
@@ -85,7 +84,7 @@ struct SpaceCreationEmailInvites: View {
private var formView: some View {
VStack {
VStack(spacing: 20) {
ForEach(viewModel.emailInvites.indices) { index in
ForEach(viewModel.emailInvites.indices, id: \.self) { index in
RoundedBorderTextField(title: VectorL10n.spacesCreationEmailInvitesEmailTitle, placeHolder: VectorL10n.spacesCreationEmailInvitesEmailTitle, text: $viewModel.emailInvites[index], footerText: viewModel.viewState.emailAddressesValid[index] ? nil : VectorL10n.authInvalidEmail, isError: !viewModel.viewState.emailAddressesValid[index], configuration: UIKitTextInputConfiguration(keyboardType: .emailAddress, returnKeyType: index < viewModel.emailInvites.endIndex - 1 ? .next : .done, autocapitalizationType: .none, autocorrectionType: .no))
.accessibility(identifier: "emailTextField")
}
@@ -16,14 +16,12 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias SpaceCreationEmailInvitesViewModelType = StateStoreViewModel<SpaceCreationEmailInvitesViewState, SpaceCreationEmailInvitesViewAction>
typealias SpaceCreationEmailInvitesViewModelType = StateStoreViewModel<SpaceCreationEmailInvitesViewState,
SpaceCreationEmailInvitesStateAction,
SpaceCreationEmailInvitesViewAction>
class SpaceCreationEmailInvitesViewModel: SpaceCreationEmailInvitesViewModelType, SpaceCreationEmailInvitesViewModelProtocol {
// MARK: - Properties
// MARK: Private
@@ -42,12 +40,14 @@ class SpaceCreationEmailInvitesViewModel: SpaceCreationEmailInvitesViewModelType
self.service = service
super.init(initialViewState: SpaceCreationEmailInvitesViewModel.defaultState(creationParameters: creationParameters, service: service))
}
private func setupServiceObserving() {
let publisher = service.isLoadingSubject
.map(SpaceCreationEmailInvitesStateAction.updateLoading)
.eraseToAnyPublisher()
dispatch(actionPublisher: publisher)
service
.isLoadingSubject
.sink(receiveValue: { [weak self] isLoading in
self?.state.loading = isLoading
})
.store(in: &cancellables)
}
private static func defaultState(creationParameters: SpaceCreationParameters, service: SpaceCreationEmailInvitesServiceProtocol) -> SpaceCreationEmailInvitesViewState {
@@ -76,24 +76,16 @@ class SpaceCreationEmailInvitesViewModel: SpaceCreationEmailInvitesViewModelType
}
}
override class func reducer(state: inout SpaceCreationEmailInvitesViewState, action: SpaceCreationEmailInvitesStateAction) {
switch action {
case .updateEmailValidity(let emailValidity):
state.emailAddressesValid = emailValidity
case .updateLoading(let isLoading):
state.loading = isLoading
}
}
private func done() {
self.creationParameters.emailInvites = self.context.emailInvites
self.creationParameters.inviteType = .email
let emailAddressesValidity = service.validate(self.context.emailInvites)
creationParameters.emailInvites = context.emailInvites
creationParameters.inviteType = .email
dispatch(action: .updateEmailValidity(emailAddressesValidity))
if self.context.emailInvites.reduce(true, { $0 && $1.isEmpty }) {
let emailAddressesValidity = service.validate(context.emailInvites)
state.emailAddressesValid = emailAddressesValidity
if context.emailInvites.reduce(true, { $0 && $1.isEmpty }) {
completion?(.done)
} else if emailAddressesValidity.reduce(true, { $0 && $1}) {
} else if emailAddressesValidity.reduce(true, { $0 && $1 }) {
if service.isIdentityServiceReady {
completion?(.done)
} else {
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationEmailInvites SpaceCreationEmailInvites
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@
import Foundation
protocol SpaceCreationEmailInvitesViewModelProtocol {
var completion: ((SpaceCreationEmailInvitesViewModelResult) -> Void)? { get set }
var context: SpaceCreationEmailInvitesViewModelType.Context { get }
}
@@ -18,6 +18,6 @@ import SwiftUI
class SpaceCreationMatrixItemChooserViewProvider: MatrixItemChooserCoordinatorViewProvider {
func view(with viewModel: MatrixItemChooserViewModelType.Context) -> AnyView {
return AnyView(SpaceCreationMatrixItemChooser(viewModel: viewModel))
AnyView(SpaceCreationMatrixItemChooser(viewModel: viewModel))
}
}
@@ -17,7 +17,6 @@
import Foundation
class SpaceCreationAddRoomsItemsProcessor: MatrixItemChooserProcessorProtocol {
// MARK: Private
private let creationParams: SpaceCreationParameters
@@ -41,8 +40,7 @@ class SpaceCreationAddRoomsItemsProcessor: MatrixItemChooserProcessorProtocol {
completion(.success(()))
}
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool {
return true
func isItemIncluded(_ item: MatrixListItemData) -> Bool {
true
}
}
@@ -17,7 +17,6 @@
import Foundation
class SpaceCreationInviteUsersItemsProcessor: MatrixItemChooserProcessorProtocol {
// MARK: Private
private let creationParams: SpaceCreationParameters
@@ -42,8 +41,7 @@ class SpaceCreationInviteUsersItemsProcessor: MatrixItemChooserProcessorProtocol
completion(.success(()))
}
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool {
return true
func isItemIncluded(_ item: MatrixListItemData) -> Bool {
true
}
}
@@ -17,7 +17,6 @@
import SwiftUI
struct SpaceCreationMatrixItemChooser: View {
// MARK: Properties
@ObservedObject var viewModel: MatrixItemChooserViewModel.Context
@@ -52,7 +51,6 @@ struct SpaceCreationMatrixItemChooser: View {
}
}
@ViewBuilder
private var footerView: some View {
ThemableButton(icon: nil, title: viewModel.viewState.selectedItemIds.isEmpty ? VectorL10n.skip : VectorL10n.next) {
@@ -17,11 +17,10 @@
*/
import Foundation
import UIKit
import SwiftUI
import UIKit
final class SpaceCreationMenuCoordinator: Coordinator, Presentable {
// MARK: - Properties
// MARK: Private
@@ -63,12 +62,11 @@ final class SpaceCreationMenuCoordinator: Coordinator, Presentable {
self.callback?(.cancel)
case .back:
self.callback?(.back)
break
}
}
}
func toPresentable() -> UIViewController {
return self.spaceCreationMenuHostingController
spaceCreationMenuHostingController
}
}
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,4 +38,4 @@ struct SpaceCreationMenuRoomOption {
let detail: String
}
extension SpaceCreationMenuRoomOption: Identifiable, Equatable {}
extension SpaceCreationMenuRoomOption: Identifiable, Equatable { }
@@ -1,23 +0,0 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
// Copyright 2021 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
/// Actions to be performed on the `ViewModel` State
enum SpaceCreationMenuStateAction {
}
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,26 +28,31 @@ class SpaceCreationParameters {
isModified = true
}
}
var topic: String? {
didSet {
isModified = true
}
}
var address: String? {
didSet {
isModified = true
}
}
var userDefinedAddress: String? {
didSet {
isModified = true
}
}
var isPublic: Bool = false {
var isPublic = false {
didSet {
isModified = true
}
}
var showAddress: Bool {
isPublic
}
@@ -57,7 +62,8 @@ class SpaceCreationParameters {
isModified = true
}
}
var isShared: Bool = false {
var isShared = false {
didSet {
isModified = true
}
@@ -84,22 +90,26 @@ class SpaceCreationParameters {
isModified = true
}
}
var userDefinedEmailInvites: [String] {
return emailInvites.filter { address in
return !address.isEmpty
emailInvites.filter { address in
!address.isEmpty
}
}
var userIdInvites: [String] = [] {
didSet {
isModified = true
}
}
var inviteType: SpaceCreationInviteType = .email {
didSet {
isModified = true
}
}
var isModified: Bool = false
var isModified = false
}
struct SpaceCreationNewRoom: Equatable {
@@ -107,6 +117,6 @@ struct SpaceCreationNewRoom: Equatable {
var defaultName: String
static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.defaultName == rhs.defaultName && lhs.name == rhs.name
lhs.defaultName == rhs.defaultName && lhs.name == rhs.name
}
}
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,14 +16,14 @@
// limitations under the License.
//
import XCTest
import RiotSwiftUI
import XCTest
class SpaceCreationMenuUITests: MockScreenTestCase {
func testSpaceCreationMenuOptions() {
app.goToScreenWithIdentifier(MockSpaceCreationMenuScreenState.options.title)
let optionButtonCount = app.buttons.matching(identifier:"optionButton").count
let optionButtonCount = app.buttons.matching(identifier: "optionButton").count
XCTAssertEqual(optionButtonCount, 2)
let titleText = app.staticTexts["titleText"]
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,14 +16,13 @@
// limitations under the License.
//
import XCTest
import Combine
import XCTest
@testable import RiotSwiftUI
class SpaceCreationMenuViewModelTests: XCTestCase {
private enum Constants {
}
private enum Constants { }
let navTitle = VectorL10n.spacesCreateSpaceTitle
var creationParams = SpaceCreationParameters()
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@
import SwiftUI
struct SpaceCreationMenu: View {
// MARK: - Properties
@ObservedObject var viewModel: SpaceCreationMenuViewModelType.Context
@@ -100,7 +99,6 @@ struct SpaceCreationMenu: View {
// MARK: - Previews
struct SpaceCreationMenu_Previews: PreviewProvider {
static let stateRenderer = MockSpaceCreationMenuScreenState.stateRenderer
static var previews: some View {
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,14 +16,12 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias SpaceCreationMenuViewModelType = StateStoreViewModel<SpaceCreationMenuViewState,
SpaceCreationMenuStateAction,
SpaceCreationMenuViewAction>
typealias SpaceCreationMenuViewModelType = StateStoreViewModel<SpaceCreationMenuViewState, SpaceCreationMenuViewAction>
class SpaceCreationMenuViewModel: SpaceCreationMenuViewModelType, SpaceCreationMenuViewModelProtocol {
// MARK: - Properties
// MARK: Private
@@ -43,7 +41,7 @@ class SpaceCreationMenuViewModel: SpaceCreationMenuViewModelType, SpaceCreationM
}
private static func defaultState(navTitle: String?, creationParams: SpaceCreationParameters, title: String, detail: String, options: [SpaceCreationMenuRoomOption]) -> SpaceCreationMenuViewState {
var navigationTitle: String = ""
var navigationTitle = ""
if let navTitle = navTitle {
navigationTitle = navTitle
} else {
@@ -60,13 +58,13 @@ class SpaceCreationMenuViewModel: SpaceCreationMenuViewModelType, SpaceCreationM
case .didSelectOption(let optionId):
switch optionId {
case .publicSpace:
self.creationParams.isPublic = true
creationParams.isPublic = true
case .privateSpace:
self.creationParams.isPublic = false
creationParams.isPublic = false
case .ownedPrivateSpace:
self.creationParams.isShared = false
creationParams.isShared = false
case .sharedPrivateSpace:
self.creationParams.isShared = true
creationParams.isShared = true
}
didSelectOption(withId: optionId)
@@ -1,6 +1,6 @@
// File created from TemplateAdvancedRoomsExample
// $ createSwiftUITwoScreen.sh Spaces/SpaceCreation SpaceCreation SpaceCreationMenu SpaceCreationSettings
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,11 +17,10 @@
*/
import Foundation
import UIKit
import SwiftUI
import UIKit
final class SpaceCreationPostProcessCoordinator: Coordinator, Presentable {
// MARK: - Properties
// MARK: Private
@@ -50,6 +49,7 @@ final class SpaceCreationPostProcessCoordinator: Coordinator, Presentable {
}
// MARK: - Public
func start() {
MXLog.debug("[SpaceCreationPostProcessCoordinator] did start.")
spaceCreationPostProcessViewModel.completion = { [weak self] result in
@@ -65,6 +65,6 @@ final class SpaceCreationPostProcessCoordinator: Coordinator, Presentable {
}
func toPresentable() -> UIViewController {
return self.spaceCreationPostProcessHostingController
spaceCreationPostProcessHostingController
}
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,11 +38,12 @@ struct SpaceCreationPostProcessTask: Equatable {
let title: String
var state: SpaceCreationPostProcessTaskState
var isFinished: Bool {
return state == .failure || state == .success
state == .failure || state == .success
}
var subTasks: [SpaceCreationPostProcessTask] = []
static func == (lhs: SpaceCreationPostProcessTask, rhs: SpaceCreationPostProcessTask) -> Bool {
return lhs.type == rhs.type && lhs.title == rhs.title && lhs.state == rhs.state && lhs.subTasks == lhs.subTasks
lhs.type == rhs.type && lhs.title == rhs.title && lhs.state == rhs.state && lhs.subTasks == lhs.subTasks
}
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,12 +16,11 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
import MatrixSDK
class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
// MARK: - Properties
// MARK: Private
@@ -39,19 +38,16 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
createdSpaceId = createdSpace?.spaceId
}
}
private var createdRoomsByName: [String: MXRoom] = [:]
private var currentSubTaskIndex = 0
private var processingQueue = DispatchQueue(label: "io.element.MXSpace.processingQueue", attributes: .concurrent)
private lazy var stateEventBuilder: MXRoomInitialStateEventBuilder = {
return MXRoomInitialStateEventBuilder()
}()
private lazy var stateEventBuilder = MXRoomInitialStateEventBuilder()
private lazy var mediaUploader: MXMediaLoader = {
return MXMediaManager.prepareUploader(withMatrixSession: session, initialRange: 0, andRange: 1.0)
}()
private lazy var mediaUploader: MXMediaLoader = MXMediaManager.prepareUploader(withMatrixSession: session, initialRange: 0, andRange: 1.0)
// MARK: Public
@@ -61,8 +57,9 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
let alias = creationParams.userDefinedAddress.isEmptyOrNil ? creationParams.address : creationParams.userDefinedAddress
return AvatarInput(mxContentUri: alias, matrixItemId: "", displayName: creationParams.name)
}
var avatarImage: UIImage? {
return creationParams.userSelectedAvatar
creationParams.userSelectedAvatar
}
// MARK: - Setup
@@ -71,18 +68,17 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
self.session = session
self.parentSpaceId = parentSpaceId
self.creationParams = creationParams
self.tasks = Self.tasks(with: creationParams)
self.tasksSubject = CurrentValueSubject(tasks)
tasks = Self.tasks(with: creationParams)
tasksSubject = CurrentValueSubject(tasks)
}
deinit {
}
deinit { }
// MARK: - Public
func run() {
self.isRetry = self.currentTaskIndex > 0
self.currentTaskIndex = -1
isRetry = currentTaskIndex > 0
currentTaskIndex = -1
runNextTask()
}
@@ -106,13 +102,13 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
tasks.append(SpaceCreationPostProcessTask(type: .addRooms, title: VectorL10n.spacesCreationPostProcessAddingRooms("\(addedRoomIds.count)"), state: .none, subTasks: subTasks))
}
} else {
tasks.append(contentsOf: creationParams.newRooms.compactMap({ room in
tasks.append(contentsOf: creationParams.newRooms.compactMap { room in
guard !room.name.isEmpty else {
return nil
}
return SpaceCreationPostProcessTask(type: .createRoom(room.name), title: VectorL10n.spacesCreationPostProcessCreatingRoom(room.name), state: .none)
}))
})
}
if creationParams.inviteType == .email {
@@ -183,7 +179,7 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
return
}
parentSpace.addChild(roomId: createdSpaceId) { [weak self] response in
parentSpace.addChild(roomId: createdSpaceId) { [weak self] _ in
guard let self = self else { return }
self.updateCurrentTask(with: .success)
@@ -194,45 +190,45 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
}
private func uploadAvatar(andUpdate task: SpaceCreationPostProcessTask) {
self.updateCurrentTask(with: .started)
updateCurrentTask(with: .started)
guard let avatar = creationParams.userSelectedAvatar, let spaceRoom = self.createdSpace?.room else {
self.updateCurrentTask(with: .success)
self.runNextTask()
guard let avatar = creationParams.userSelectedAvatar, let spaceRoom = createdSpace?.room else {
updateCurrentTask(with: .success)
runNextTask()
return
}
let avatarUp = MXKTools.forceImageOrientationUp(avatar)
mediaUploader.uploadData(avatarUp?.jpegData(compressionQuality: 0.5), filename: nil, mimeType: "image/jpeg",
success: { [weak self] (urlString) in
guard let self = self else { return }
guard let urlString = urlString else { return }
guard let url = URL(string: urlString) else { return }
success: { [weak self] urlString in
guard let self = self else { return }
guard let urlString = urlString else { return }
guard let url = URL(string: urlString) else { return }
self.setAvatar(ofRoom: spaceRoom, withURL: url, andUpdate: task)
self.setAvatar(ofRoom: spaceRoom, withURL: url, andUpdate: task)
},
failure: { [weak self] (error) in
guard let self = self else { return }
failure: { [weak self] _ in
guard let self = self else { return }
self.updateCurrentTask(with: .failure)
self.runNextTask()
self.updateCurrentTask(with: .failure)
self.runNextTask()
})
}
private func setAvatar(ofRoom room: MXRoom, withURL url: URL, andUpdate task: SpaceCreationPostProcessTask) {
updateCurrentTask(with: .started)
room.setAvatar(url: url) { [weak self] (response) in
room.setAvatar(url: url) { [weak self] response in
guard let self = self else { return }
self.updateCurrentTask(with: response.isSuccess ? .success: .failure)
self.updateCurrentTask(with: response.isSuccess ? .success : .failure)
self.runNextTask()
}
}
private func createRoom(withName roomName: String, andUpdate task: SpaceCreationPostProcessTask) {
guard let createdSpace = self.createdSpace else {
guard let createdSpace = createdSpace else {
updateCurrentTask(with: .failure)
runNextTask()
return
@@ -257,7 +253,7 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
}
private func addToSpace(room: MXRoom) {
guard let createdSpace = self.createdSpace else {
guard let createdSpace = createdSpace else {
updateCurrentTask(with: .failure)
runNextTask()
return
@@ -282,7 +278,7 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
}
private func inviteNextUserByEmail() {
guard let createdSpace = self.createdSpace, let room = createdSpace.room else {
guard let createdSpace = createdSpace, let room = createdSpace.room else {
updateCurrentTask(with: .failure)
runNextTask()
return
@@ -291,7 +287,7 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
currentSubTaskIndex += 1
guard currentSubTaskIndex < tasks[currentTaskIndex].subTasks.count else {
let isSuccess = tasks[currentTaskIndex].subTasks.reduce(true, { $0 && $1.state == .success })
let isSuccess = tasks[currentTaskIndex].subTasks.reduce(true) { $0 && $1.state == .success }
updateCurrentTask(with: isSuccess ? .success : .failure)
runNextTask()
return
@@ -306,7 +302,7 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
}
private func addNextExistingRoom() {
guard let createdSpace = self.createdSpace else {
guard let createdSpace = createdSpace else {
updateCurrentTask(with: .failure)
runNextTask()
return
@@ -315,7 +311,7 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
currentSubTaskIndex += 1
guard currentSubTaskIndex < tasks[currentTaskIndex].subTasks.count else {
let isSuccess = tasks[currentTaskIndex].subTasks.reduce(true, { $0 && $1.state == .success })
let isSuccess = tasks[currentTaskIndex].subTasks.reduce(true) { $0 && $1.state == .success }
updateCurrentTask(with: isSuccess ? .success : .failure)
runNextTask()
return
@@ -351,6 +347,6 @@ class SpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
}
tasks[currentTaskIndex].state = state
self.tasksSubject.send(tasks)
tasksSubject.send(tasks)
}
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,6 @@ import SwiftUI
enum MockSpaceCreationPostProcessScreenState: MockScreenState {
static var screenStates: [MockScreenState] = [MockSpaceCreationPostProcessScreenState.running, MockSpaceCreationPostProcessScreenState.done, MockSpaceCreationPostProcessScreenState.doneWithError]
// A case for each state you want to represent
// with specific, minimal associated data that will allow you
// mock that screen.
@@ -38,7 +37,7 @@ enum MockSpaceCreationPostProcessScreenState: MockScreenState {
}
/// Generate the view struct for the screen state.
var screenView: ([Any], AnyView) {
var screenView: ([Any], AnyView) {
let service: MockSpaceCreationPostProcessService
switch self {
case .running:
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,12 +16,11 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
import UIKit
class MockSpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol {
static let defaultTasks: [SpaceCreationPostProcessTask] = [
SpaceCreationPostProcessTask(type: .createSpace, title: "Space creation", state: .success),
SpaceCreationPostProcessTask(type: .createRoom("Room#1"), title: "Room#1 creation", state: .failure),
@@ -53,22 +52,22 @@ class MockSpaceCreationPostProcessService: SpaceCreationPostProcessServiceProtoc
var tasksSubject: CurrentValueSubject<[SpaceCreationPostProcessTask], Never>
private(set) var createdSpaceId: String?
var avatar: AvatarInput {
return AvatarInput(mxContentUri: nil, matrixItemId: "", displayName: "Some space")
AvatarInput(mxContentUri: nil, matrixItemId: "", displayName: "Some space")
}
var avatarImage: UIImage? {
return nil
nil
}
init(
tasks: [SpaceCreationPostProcessTask] = defaultTasks
) {
self.tasksSubject = CurrentValueSubject<[SpaceCreationPostProcessTask], Never>(tasks)
tasksSubject = CurrentValueSubject<[SpaceCreationPostProcessTask], Never>(tasks)
}
func simulateUpdate(tasks: [SpaceCreationPostProcessTask]) {
self.tasksSubject.send(tasks)
tasksSubject.send(tasks)
}
func run() {
}
func run() { }
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
import UIKit
protocol SpaceCreationPostProcessServiceProtocol: AnyObject {
@@ -16,8 +16,8 @@
// limitations under the License.
//
import XCTest
import RiotSwiftUI
import XCTest
class SpaceCreationPostProcessUITests: MockScreenTestCase {
// No tests have been implemented
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,13 +16,12 @@
// limitations under the License.
//
import XCTest
import Combine
import XCTest
@testable import RiotSwiftUI
class SpaceCreationPostProcessViewModelTests: XCTestCase {
var service: MockSpaceCreationPostProcessService!
var viewModel: SpaceCreationPostProcessViewModelProtocol!
var context: SpaceCreationPostProcessViewModelType.Context!
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@
import SwiftUI
struct SpaceCreationPostProcess: View {
// MARK: - Properties
// MARK: Private
@@ -44,7 +43,7 @@ struct SpaceCreationPostProcess: View {
.navigationBarHidden(true)
.background(theme.colors.background.ignoresSafeArea())
.frame(maxHeight: .infinity)
.onAppear() {
.onAppear {
viewModel.send(viewAction: .runTasks)
}
}
@@ -62,7 +61,7 @@ struct SpaceCreationPostProcess: View {
@ViewBuilder
private var tasksList: some View {
VStack(alignment: .leading, spacing: 11) {
ForEach(viewModel.viewState.tasks.indices) { index in
ForEach(viewModel.viewState.tasks.indices, id: \.self) { index in
SpaceCreationPostProcessItem(title: viewModel.viewState.tasks[index].title, state: viewModel.viewState.tasks[index].state)
}
}
@@ -85,7 +84,7 @@ struct SpaceCreationPostProcess: View {
private var avatarView: some View {
ZStack {
SpaceAvatarImage(mxContentUri: viewModel.viewState.avatar.mxContentUri, matrixItemId: viewModel.viewState.avatar.matrixItemId, displayName: viewModel.viewState.avatar.displayName, size: .xLarge)
.padding(6)
.padding(6)
if let image = viewModel.viewState.avatarImage {
Image(uiImage: image)
.resizable()
@@ -95,7 +94,6 @@ struct SpaceCreationPostProcess: View {
}
}
}
}
// MARK: - Previews
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,16 +16,12 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias SpaceCreationPostProcessViewModelType = StateStoreViewModel<SpaceCreationPostProcessViewState, SpaceCreationPostProcessViewAction>
typealias SpaceCreationPostProcessViewModelType = StateStoreViewModel<SpaceCreationPostProcessViewState,
SpaceCreationPostProcessStateAction,
SpaceCreationPostProcessViewAction>
class SpaceCreationPostProcessViewModel: SpaceCreationPostProcessViewModelType, SpaceCreationPostProcessViewModelProtocol {
// MARK: - Properties
// MARK: Private
@@ -40,7 +36,7 @@ class SpaceCreationPostProcessViewModel: SpaceCreationPostProcessViewModelType,
// MARK: - Setup
static func makeSpaceCreationPostProcessViewModel(spaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol) -> SpaceCreationPostProcessViewModelProtocol {
return SpaceCreationPostProcessViewModel(spaceCreationPostProcessService: spaceCreationPostProcessService)
SpaceCreationPostProcessViewModel(spaceCreationPostProcessService: spaceCreationPostProcessService)
}
private init(spaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol) {
@@ -55,16 +51,27 @@ class SpaceCreationPostProcessViewModel: SpaceCreationPostProcessViewModelType,
avatar: spaceCreationPostProcessService.avatar,
avatarImage: spaceCreationPostProcessService.avatarImage,
tasks: tasks,
isFinished: tasks.first?.state == .failure || tasks.reduce(true, { result, task in result && task.isFinished }),
errorCount: tasks.reduce(0, { result, task in result + (task.state == .failure ? 1 : 0) })
isFinished: tasks.first?.state == .failure || tasks.reduce(true) { result, task in result && task.isFinished },
errorCount: tasks.reduce(0) { result, task in result + (task.state == .failure ? 1 : 0) }
)
}
private func setupTasksObserving() {
let tasksUpdatePublisher = spaceCreationPostProcessService.tasksSubject
.map(SpaceCreationPostProcessStateAction.updateTasks)
.eraseToAnyPublisher()
dispatch(actionPublisher: tasksUpdatePublisher)
spaceCreationPostProcessService
.tasksSubject
.sink(receiveValue: { [weak self] tasks in
guard let self = self else { return }
self.state.tasks = tasks
self.state.isFinished = tasks.first?.state == .failure || tasks.reduce(true) { result, task in result && task.isFinished }
self.state.errorCount = tasks.reduce(0) { result, task in result + (task.state == .failure ? 1 : 0) }
NotificationCenter.default.post(name: SpaceCreationPostProcessViewModel.didUpdate,
object: nil,
userInfo: [SpaceCreationPostProcessViewModel.newStateKey: self.state])
})
.store(in: &cancellables)
updateNotificationObserver = NotificationCenter.default.addObserver(forName: SpaceCreationPostProcessViewModel.didUpdate, object: nil, queue: OperationQueue.main) { [weak self] notification in
guard let self = self else {
return
@@ -74,7 +81,7 @@ class SpaceCreationPostProcessViewModel: SpaceCreationPostProcessViewModelType,
return
}
if state.isFinished && state.errorCount == 0 {
if state.isFinished, state.errorCount == 0 {
guard let spaceId = self.spaceCreationPostProcessService.createdSpaceId else {
self.cancel()
return
@@ -104,19 +111,6 @@ class SpaceCreationPostProcessViewModel: SpaceCreationPostProcessViewModelType,
}
}
override class func reducer(state: inout SpaceCreationPostProcessViewState, action: SpaceCreationPostProcessStateAction) {
switch action {
case .updateTasks(let tasks):
state.tasks = tasks
state.isFinished = tasks.first?.state == .failure || tasks.reduce(true, { result, task in result && task.isFinished })
state.errorCount = tasks.reduce(0, { result, task in result + (task.state == .failure ? 1 : 0) })
}
NotificationCenter.default.post(name: SpaceCreationPostProcessViewModel.didUpdate, object: nil, userInfo: [SpaceCreationPostProcessViewModel.newStateKey : state])
UILog.debug("[SpaceCreationPostProcessViewModel] reducer with action \(action) produced state: \(state)")
}
private func done(spaceId: String) {
completion?(.done(spaceId))
}
@@ -131,6 +125,7 @@ class SpaceCreationPostProcessViewModel: SpaceCreationPostProcessViewModelType,
}
// MARK: - MXSpaceService notification constants
extension SpaceCreationPostProcessViewModel {
/// Posted once the process is finished
public static let didUpdate = Notification.Name("SpaceCreationPostProcessViewModelDidUpdate")
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationPostProcess SpaceCreationPostProcess
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@
import Foundation
protocol SpaceCreationPostProcessViewModelProtocol {
var completion: ((SpaceCreationPostProcessViewModelResult) -> Void)? { get set }
static func makeSpaceCreationPostProcessViewModel(spaceCreationPostProcessService: SpaceCreationPostProcessServiceProtocol) -> SpaceCreationPostProcessViewModelProtocol
var context: SpaceCreationPostProcessViewModelType.Context { get }
@@ -17,11 +17,10 @@
*/
import Foundation
import UIKit
import SwiftUI
import UIKit
final class SpaceCreationRoomsCoordinator: Coordinator, Presentable {
// MARK: - Properties
// MARK: Private
@@ -68,6 +67,6 @@ final class SpaceCreationRoomsCoordinator: Coordinator, Presentable {
}
func toPresentable() -> UIViewController {
return self.spaceCreationRoomsHostingController
spaceCreationRoomsHostingController
}
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,22 +0,0 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
// Copyright 2021 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
enum SpaceCreationRoomsStateAction {
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,7 +39,7 @@ enum MockSpaceCreationRoomsScreenState: MockScreenState, CaseIterable {
}
/// Generate the view struct for the screen state.
var screenView: ([Any], AnyView) {
var screenView: ([Any], AnyView) {
let creationParams = SpaceCreationParameters()
switch self {
case .defaultValues: break
@@ -16,8 +16,8 @@
// limitations under the License.
//
import XCTest
import RiotSwiftUI
import XCTest
class SpaceCreationRoomsUITests: MockScreenTestCase {
func testDefaultValues() {
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,8 +16,8 @@
// limitations under the License.
//
import XCTest
import Combine
import XCTest
@testable import RiotSwiftUI
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@
import SwiftUI
struct SpaceCreationRooms: View {
// MARK: - Properties
// MARK: Private
@@ -50,7 +49,7 @@ struct SpaceCreationRooms: View {
VStack {
GeometryReader { reader in
ScrollView {
ScrollViewReader { scrollViewReader in
ScrollViewReader { _ in
VStack(spacing: 20) {
Text(VectorL10n.spacesCreationNewRoomsTitle)
.multilineTextAlignment(.center)
@@ -61,8 +60,8 @@ struct SpaceCreationRooms: View {
.font(theme.fonts.body)
.foregroundColor(theme.colors.secondaryContent)
Spacer()
ForEach(viewModel.rooms.indices) { index in
RoundedBorderTextField(title: VectorL10n.spacesCreationNewRoomsRoomNameTitle, placeHolder: viewModel.rooms[index].defaultName, text: $viewModel.rooms[index].name, configuration: UIKitTextInputConfiguration( returnKeyType: index < viewModel.rooms.endIndex - 1 ? .next : .done))
ForEach(viewModel.rooms.indices, id: \.self) { index in
RoundedBorderTextField(title: VectorL10n.spacesCreationNewRoomsRoomNameTitle, placeHolder: viewModel.rooms[index].defaultName, text: $viewModel.rooms[index].name, configuration: UIKitTextInputConfiguration(returnKeyType: index < viewModel.rooms.endIndex - 1 ? .next : .done))
.accessibility(identifier: "roomTextField")
}
}
@@ -16,16 +16,12 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias SpaceCreationRoomsViewModelType = StateStoreViewModel<SpaceCreationRoomsViewState, SpaceCreationRoomsViewAction>
typealias SpaceCreationRoomsViewModelType = StateStoreViewModel<SpaceCreationRoomsViewState,
SpaceCreationRoomsStateAction,
SpaceCreationRoomsViewAction>
class SpaceCreationRoomsViewModel: SpaceCreationRoomsViewModelType, SpaceCreationRoomsViewModelProtocol {
// MARK: - Setup
// MARK: Private
@@ -51,7 +47,6 @@ class SpaceCreationRoomsViewModel: SpaceCreationRoomsViewModelType, SpaceCreatio
)
}
// MARK: - Public
override func process(viewAction: SpaceCreationRoomsViewAction) {
@@ -64,14 +59,11 @@ class SpaceCreationRoomsViewModel: SpaceCreationRoomsViewModelType, SpaceCreatio
done()
}
}
override class func reducer(state: inout SpaceCreationRoomsViewState, action: SpaceCreationRoomsStateAction) {
}
// MARK: - Private
private func done() {
self.creationParameters.newRooms = self.context.rooms
creationParameters.newRooms = context.rooms
callback?(.done)
}
@@ -1,6 +1,6 @@
// File created from SimpleUserProfileExample
// $ createScreen.sh Spaces/SpaceCreation/SpaceCreationRooms SpaceCreationRooms
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@
import Foundation
protocol SpaceCreationRoomsViewModelProtocol {
var callback: ((SpaceCreationRoomsViewModelResult) -> Void)? { get set }
var context: SpaceCreationRoomsViewModelType.Context { get }
}

Some files were not shown because too many files have changed in this diff Show More