mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-22 01:22:46 +02:00
SP3.1: Update room settings for Spaces element-ios#5231
- Changed the Room Settings screen according to the new design - Implemented the room access flow - Added room upgrade support - Implemented the room suggestion screen
This commit is contained in:
+3
-3
@@ -30,14 +30,14 @@ struct MatrixItemChooserCoordinatorParameters {
|
||||
let detail: String?
|
||||
let selectedItemsIds: [String]
|
||||
let viewProvider: MatrixItemChooserCoordinatorViewProvider?
|
||||
let itemsProcessor: MatrixItemChooserProcessorProtocol?
|
||||
let itemsProcessor: MatrixItemChooserProcessorProtocol
|
||||
|
||||
init(session: MXSession,
|
||||
title: String? = nil,
|
||||
detail: String? = nil,
|
||||
selectedItemsIds: [String] = [],
|
||||
viewProvider: MatrixItemChooserCoordinatorViewProvider? = nil,
|
||||
itemsProcessor: MatrixItemChooserProcessorProtocol?) {
|
||||
itemsProcessor: MatrixItemChooserProcessorProtocol) {
|
||||
self.session = session
|
||||
self.title = title
|
||||
self.detail = detail
|
||||
@@ -55,7 +55,7 @@ final class MatrixItemChooserCoordinator: Coordinator, Presentable {
|
||||
// MARK: Private
|
||||
|
||||
private let parameters: MatrixItemChooserCoordinatorParameters
|
||||
private let matrixItemChooserHostingController: UIViewController
|
||||
private let matrixItemChooserHostingController: VectorHostingController
|
||||
private var matrixItemChooserViewModel: MatrixItemChooserViewModelProtocol
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@@ -21,6 +21,8 @@ import Foundation
|
||||
enum MatrixItemChooserType {
|
||||
case room
|
||||
case people
|
||||
case ancestorsOf(String)
|
||||
case restrictedAllowedSpacesOf(String)
|
||||
}
|
||||
|
||||
// MARK: View model
|
||||
@@ -28,7 +30,7 @@ enum MatrixItemChooserType {
|
||||
enum MatrixItemChooserStateAction {
|
||||
case loadingState(Bool)
|
||||
case updateError(Error?)
|
||||
case updateItems([MatrixListItemData])
|
||||
case updateSections([MatrixListItemSectionData])
|
||||
case updateSelection(Set<String>)
|
||||
}
|
||||
|
||||
@@ -40,8 +42,24 @@ enum MatrixItemChooserViewModelResult {
|
||||
|
||||
// MARK: View
|
||||
|
||||
enum MatrixListItemDataType {
|
||||
case user
|
||||
case room
|
||||
case space
|
||||
}
|
||||
|
||||
struct MatrixListItemSectionData {
|
||||
let id = UUID().uuidString
|
||||
let title: String?
|
||||
let infoText: String?
|
||||
let items: [MatrixListItemData]
|
||||
}
|
||||
|
||||
extension MatrixListItemSectionData: Identifiable, Equatable {}
|
||||
|
||||
struct MatrixListItemData {
|
||||
let id: String
|
||||
let type: MatrixListItemDataType
|
||||
let avatar: AvatarInput
|
||||
let displayName: String?
|
||||
let detailText: String?
|
||||
@@ -53,8 +71,9 @@ struct MatrixItemChooserViewState: BindableState {
|
||||
var title: String?
|
||||
var message: String?
|
||||
var emptyListMessage: String
|
||||
var items: [MatrixListItemData]
|
||||
var sections: [MatrixListItemSectionData]
|
||||
var selectedItemIds: Set<String>
|
||||
var loadingText: String?
|
||||
var loading: Bool
|
||||
var error: String?
|
||||
}
|
||||
|
||||
@@ -51,14 +51,14 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
|
||||
let message = detail
|
||||
let emptyListMessage = VectorL10n.spacesNoResultFoundTitle
|
||||
|
||||
return MatrixItemChooserViewState(title: title, message: message, emptyListMessage: emptyListMessage, items: matrixItemChooserService.itemsSubject.value, selectedItemIds: matrixItemChooserService.selectedItemIdsSubject.value, loading: false)
|
||||
return MatrixItemChooserViewState(title: title, message: message, emptyListMessage: emptyListMessage, sections: matrixItemChooserService.sectionsSubject.value, selectedItemIds: matrixItemChooserService.selectedItemIdsSubject.value, loadingText: matrixItemChooserService.loadingText, loading: false)
|
||||
}
|
||||
|
||||
private func startObservingItems() {
|
||||
let itemsUpdatePublisher = matrixItemChooserService.itemsSubject
|
||||
.map(MatrixItemChooserStateAction.updateItems)
|
||||
let sectionsUpdatePublisher = matrixItemChooserService.sectionsSubject
|
||||
.map(MatrixItemChooserStateAction.updateSections)
|
||||
.eraseToAnyPublisher()
|
||||
dispatch(actionPublisher: itemsUpdatePublisher)
|
||||
dispatch(actionPublisher: sectionsUpdatePublisher)
|
||||
|
||||
let selectionPublisher = matrixItemChooserService.selectedItemIdsSubject
|
||||
.map(MatrixItemChooserStateAction.updateSelection)
|
||||
@@ -99,8 +99,8 @@ class MatrixItemChooserViewModel: MatrixItemChooserViewModelType, MatrixItemChoo
|
||||
|
||||
override class func reducer(state: inout MatrixItemChooserViewState, action: MatrixItemChooserStateAction) {
|
||||
switch action {
|
||||
case .updateItems(let items):
|
||||
state.items = items
|
||||
case .updateSections(let sections):
|
||||
state.sections = sections
|
||||
case .updateSelection(let selectedItemIds):
|
||||
state.selectedItemIds = selectedItemIds
|
||||
case .loadingState(let loading):
|
||||
|
||||
@@ -38,11 +38,11 @@ enum MockMatrixItemChooserScreenState: MockScreenState, CaseIterable {
|
||||
let service: MockMatrixItemChooserService
|
||||
switch self {
|
||||
case .noItems:
|
||||
service = MockMatrixItemChooserService(type: .room, items: [])
|
||||
service = MockMatrixItemChooserService(type: .room, sections: [MatrixListItemSectionData(title: nil, infoText: nil, items: [])])
|
||||
case .items:
|
||||
service = MockMatrixItemChooserService()
|
||||
case .selectedItems:
|
||||
service = MockMatrixItemChooserService(type: .room, items: MockMatrixItemChooserService.mockItems, selectedItemIndexes: [0, 2])
|
||||
service = MockMatrixItemChooserService(type: .room, sections: MockMatrixItemChooserService.mockSections, selectedItemIndexPaths: [IndexPath(row: 0, section: 0), IndexPath(row: 2, section: 0), IndexPath(row: 1, section: 1)])
|
||||
}
|
||||
let viewModel = MatrixItemChooserViewModel.makeMatrixItemChooserViewModel(matrixItemChooserService: service, title: "Some title", detail: "Detail text describing the current screen")
|
||||
|
||||
|
||||
+2
-2
@@ -19,10 +19,10 @@ import Combine
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
protocol MatrixItemChooserServiceProtocol {
|
||||
var type: MatrixItemChooserType { get }
|
||||
var itemsSubject: CurrentValueSubject<[MatrixListItemData], Never> { get }
|
||||
var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never> { get }
|
||||
var selectedItemIdsSubject: CurrentValueSubject<Set<String>, Never> { get }
|
||||
var searchText: String { get set }
|
||||
var loadingText: String? { get }
|
||||
|
||||
func reverseSelectionForItem(withId itemId: String)
|
||||
func processSelection(completion: @escaping (Result<Void, Error>) -> Void)
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
class MatrixItemChooserRoomAncestorsDataSource: MatrixItemChooserDataSource {
|
||||
private let roomId: String
|
||||
|
||||
var preselectedItemIds: Set<String>? { nil }
|
||||
|
||||
init(roomId: String) {
|
||||
self.roomId = roomId
|
||||
}
|
||||
|
||||
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
|
||||
let ancestorsId = session.spaceService.ancestorsPerRoomId[roomId] ?? []
|
||||
completion(Result(catching: {
|
||||
return [
|
||||
MatrixListItemSectionData(title: VectorL10n.roomAccessSpaceChooserKnownSpacesSection(session.room(withRoomId: roomId)?.displayName ?? ""), infoText: nil, items: ancestorsId.compactMap { spaceId in
|
||||
guard let space = session.spaceService.getSpace(withId: spaceId) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let room = space.room else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return MatrixListItemData(mxRoom: room, spaceService: session.spaceService)
|
||||
}
|
||||
.sorted { $0.displayName ?? "" < $1.displayName ?? "" })
|
||||
]
|
||||
}))
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// 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 MatrixItemChooserRoomDirectParentsDataSourcePreselectionMode {
|
||||
case none
|
||||
case suggestedRoom
|
||||
}
|
||||
|
||||
class MatrixItemChooserRoomDirectParentsDataSource: MatrixItemChooserDataSource {
|
||||
|
||||
private let roomId: String
|
||||
private let preselectionMode: MatrixItemChooserRoomDirectParentsDataSourcePreselectionMode
|
||||
|
||||
private(set) var preselectedItemIds: Set<String>?
|
||||
|
||||
init(roomId: String, preselectionMode: MatrixItemChooserRoomDirectParentsDataSourcePreselectionMode = .none) {
|
||||
self.roomId = roomId
|
||||
self.preselectionMode = preselectionMode
|
||||
}
|
||||
|
||||
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
|
||||
let ancestorsId = session.spaceService.directParentIds(ofRoomWithId: roomId)
|
||||
|
||||
switch preselectionMode {
|
||||
case .none:
|
||||
preselectedItemIds = nil
|
||||
case .suggestedRoom:
|
||||
preselectedItemIds = session.spaceService.directParentIds(ofRoomWithId: roomId, isRoomSuggested: true)
|
||||
}
|
||||
|
||||
completion(Result(catching: {
|
||||
return [
|
||||
MatrixListItemSectionData(title: VectorL10n.roomAccessSpaceChooserKnownSpacesSection(session.room(withRoomId: roomId)?.displayName ?? ""), infoText: nil, items: ancestorsId.compactMap { spaceId in
|
||||
guard let space = session.spaceService.getSpace(withId: spaceId) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let room = space.room else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return MatrixListItemData(mxRoom: room, spaceService: session.spaceService)
|
||||
}
|
||||
.sorted { $0.displayName ?? "" < $1.displayName ?? "" })
|
||||
]
|
||||
}))
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
class MatrixItemChooserRoomRestrictedAllowedParentsDataSource: MatrixItemChooserDataSource {
|
||||
private let roomId: String
|
||||
private var allowedParentIds: [String] = []
|
||||
|
||||
var preselectedItemIds: Set<String>? {
|
||||
Set(allowedParentIds)
|
||||
}
|
||||
|
||||
init(roomId: String) {
|
||||
self.roomId = roomId
|
||||
}
|
||||
|
||||
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
|
||||
guard let room = session.room(withRoomId: roomId) else {
|
||||
return
|
||||
}
|
||||
|
||||
room.state { [weak self] state in
|
||||
guard let self = self else { return }
|
||||
|
||||
let joinRuleEvent = state?.stateEvents(with: .roomJoinRules)?.last
|
||||
let allowContent: [[String:String]] = joinRuleEvent?.wireContent["allow"] as? [[String:String]] ?? []
|
||||
self.allowedParentIds = allowContent.compactMap { allowDictionnary in
|
||||
guard let type = allowDictionnary["type"], type == "m.room_membership" else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return allowDictionnary["room_id"]
|
||||
}
|
||||
|
||||
let ancestorsId = session.spaceService.ancestorsPerRoomId[self.roomId] ?? []
|
||||
var sections = [
|
||||
MatrixListItemSectionData(
|
||||
title: VectorL10n.roomAccessSpaceChooserKnownSpacesSection(room.displayName ?? ""),
|
||||
infoText: nil,
|
||||
items: ancestorsId.compactMap { spaceId in
|
||||
guard let space = session.spaceService.getSpace(withId: spaceId) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let room = space.room else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return MatrixListItemData(mxRoom: room, spaceService: session.spaceService)
|
||||
}.sorted { $0.displayName ?? "" < $1.displayName ?? "" }
|
||||
)
|
||||
]
|
||||
|
||||
var unknownParents = self.allowedParentIds
|
||||
for roomId in ancestorsId {
|
||||
if let index = unknownParents.firstIndex(of: roomId) {
|
||||
unknownParents.remove(at: index)
|
||||
}
|
||||
}
|
||||
if !unknownParents.isEmpty {
|
||||
sections.append(MatrixListItemSectionData(
|
||||
title: VectorL10n.roomAccessSpaceChooserOtherSpacesSection,
|
||||
infoText: VectorL10n.roomAccessSpaceChooserOtherSpacesSectionInfo(room.displayName ?? ""),
|
||||
items: unknownParents.compactMap({ roomId in
|
||||
MatrixListItemData(
|
||||
id: roomId,
|
||||
type: .space,
|
||||
avatar: AvatarInput(mxContentUri: roomId, matrixItemId: roomId, displayName: roomId),
|
||||
displayName: roomId,
|
||||
detailText: nil)
|
||||
})
|
||||
))
|
||||
}
|
||||
|
||||
completion(Result(catching: {
|
||||
return sections
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
class MatrixItemChooserRoomsDataSource: MatrixItemChooserDataSource {
|
||||
var preselectedItemIds: Set<String>? { nil }
|
||||
|
||||
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
|
||||
completion(Result(catching: {
|
||||
[
|
||||
MatrixListItemSectionData(title: nil, infoText: nil, items: session.rooms.compactMap { room in
|
||||
if room.summary.roomType == .space || room.isDirect {
|
||||
return nil
|
||||
}
|
||||
|
||||
return MatrixListItemData(mxRoom: room, spaceService: session.spaceService)
|
||||
})
|
||||
]
|
||||
}))
|
||||
}
|
||||
}
|
||||
+54
-86
@@ -17,8 +17,14 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
protocol MatrixItemChooserDataSource {
|
||||
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void)
|
||||
var preselectedItemIds: Set<String>? { get }
|
||||
}
|
||||
|
||||
protocol MatrixItemChooserProcessorProtocol {
|
||||
var dataType: MatrixItemChooserType { get }
|
||||
var loadingText: String? { get }
|
||||
var dataSource: MatrixItemChooserDataSource { get }
|
||||
func computeSelection(withIds itemsIds:[String], completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func isItemIncluded(_ item: (MatrixListItemData)) -> Bool
|
||||
}
|
||||
@@ -30,56 +36,60 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private let processingQueue = DispatchQueue(label: "org.matrix.element.MatrixItemChooserService.processingQueue")
|
||||
private let processingQueue = DispatchQueue(label: "io.matrix.element.MatrixItemChooserService.processingQueue")
|
||||
private let completionQueue = DispatchQueue.main
|
||||
|
||||
private let session: MXSession
|
||||
private let items: [MatrixListItemData]
|
||||
private var filteredItems: [MatrixListItemData] {
|
||||
private var sections: [MatrixListItemSectionData] = []
|
||||
private var filteredSections: [MatrixListItemSectionData] = [] {
|
||||
didSet {
|
||||
itemsSubject.send(filteredItems)
|
||||
sectionsSubject.send(filteredSections)
|
||||
}
|
||||
}
|
||||
private var selectedItemIds: Set<String>
|
||||
private let itemsProcessor: MatrixItemChooserProcessorProtocol?
|
||||
private let itemsProcessor: MatrixItemChooserProcessorProtocol
|
||||
|
||||
// MARK: Public
|
||||
|
||||
private(set) var type: MatrixItemChooserType
|
||||
private(set) var itemsSubject: CurrentValueSubject<[MatrixListItemData], Never>
|
||||
private(set) var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never>
|
||||
private(set) var selectedItemIdsSubject: CurrentValueSubject<Set<String>, Never>
|
||||
var searchText: String = "" {
|
||||
didSet {
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
|
||||
var loadingText: String? {
|
||||
itemsProcessor.loadingText
|
||||
}
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(session: MXSession, selectedItemIds: [String], itemsProcessor: MatrixItemChooserProcessorProtocol?) {
|
||||
init(session: MXSession, selectedItemIds: [String], itemsProcessor: MatrixItemChooserProcessorProtocol) {
|
||||
self.session = session
|
||||
self.type = itemsProcessor?.dataType ?? .room
|
||||
switch type {
|
||||
case .people:
|
||||
self.items = session.users().map { user in
|
||||
MatrixListItemData(mxUser: user)
|
||||
}
|
||||
case .room:
|
||||
self.items = session.rooms.compactMap { room in
|
||||
if room.summary.roomType == .space || room.isDirect {
|
||||
return nil
|
||||
}
|
||||
|
||||
return MatrixListItemData(mxRoom: room, spaceService: session.spaceService)
|
||||
}
|
||||
}
|
||||
self.itemsSubject = CurrentValueSubject(self.items)
|
||||
self.filteredItems = []
|
||||
self.sectionsSubject = CurrentValueSubject(self.sections)
|
||||
|
||||
self.selectedItemIds = Set(selectedItemIds)
|
||||
self.selectedItemIdsSubject = CurrentValueSubject(self.selectedItemIds)
|
||||
self.itemsProcessor = itemsProcessor
|
||||
|
||||
itemsProcessor.dataSource.sections(with: session) { [weak self] result in
|
||||
guard let self = self else { return }
|
||||
|
||||
switch result {
|
||||
case .success(let sections):
|
||||
self.sections = sections
|
||||
self.refresh()
|
||||
if let preselectedItemIds = itemsProcessor.dataSource.preselectedItemIds {
|
||||
for itemId in preselectedItemIds {
|
||||
self.selectedItemIds.insert(itemId)
|
||||
}
|
||||
self.selectedItemIdsSubject.send(self.selectedItemIds)
|
||||
}
|
||||
case .failure(let error):
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
refresh()
|
||||
}
|
||||
|
||||
@@ -95,82 +105,40 @@ class MatrixItemChooserService: MatrixItemChooserServiceProtocol {
|
||||
}
|
||||
|
||||
func processSelection(completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
guard let selectionProcessor = self.itemsProcessor else {
|
||||
completion(Result.success(()))
|
||||
return
|
||||
}
|
||||
|
||||
selectionProcessor.computeSelection(withIds: Array(selectedItemIds), completion: completion)
|
||||
itemsProcessor.computeSelection(withIds: Array(selectedItemIds), completion: completion)
|
||||
}
|
||||
|
||||
func refresh() {
|
||||
self.processingQueue.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
let filteredItems = self.filter(items: self.items)
|
||||
let filteredSections = self.filter(sections: self.sections)
|
||||
|
||||
self.completionQueue.async {
|
||||
self.filteredItems = filteredItems
|
||||
self.filteredSections = filteredSections
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func filter(items: [MatrixListItemData]) -> [MatrixListItemData] {
|
||||
if searchText.isEmpty {
|
||||
if let selectionProcessor = self.itemsProcessor {
|
||||
return items.filter {
|
||||
selectionProcessor.isItemIncluded($0)
|
||||
private func filter(sections: [MatrixListItemSectionData]) -> [MatrixListItemSectionData] {
|
||||
var newSections: [MatrixListItemSectionData] = []
|
||||
|
||||
for section in sections {
|
||||
let items: [MatrixListItemData]
|
||||
if searchText.isEmpty {
|
||||
items = section.items.filter {
|
||||
itemsProcessor.isItemIncluded($0)
|
||||
}
|
||||
} else {
|
||||
return items
|
||||
}
|
||||
} else {
|
||||
let lowercasedSearchText = self.searchText.lowercased()
|
||||
if let selectionProcessor = self.itemsProcessor {
|
||||
return items.filter {
|
||||
selectionProcessor.isItemIncluded($0) && ($0.id.lowercased().contains(lowercasedSearchText) || ($0.displayName ?? "").lowercased().contains(lowercasedSearchText))
|
||||
}
|
||||
} else {
|
||||
return items.filter {
|
||||
$0.id.lowercased().contains(lowercasedSearchText) || ($0.displayName ?? "").lowercased().contains(lowercasedSearchText)
|
||||
let lowercasedSearchText = self.searchText.lowercased()
|
||||
items = section.items.filter {
|
||||
itemsProcessor.isItemIncluded($0) && ($0.id.lowercased().contains(lowercasedSearchText) || ($0.displayName ?? "").lowercased().contains(lowercasedSearchText))
|
||||
}
|
||||
}
|
||||
newSections.append(MatrixListItemSectionData(title: section.title, infoText: section.infoText, items: items))
|
||||
}
|
||||
|
||||
return newSections
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate extension MatrixListItemData {
|
||||
|
||||
init(mxUser: MXUser) {
|
||||
self.init(id: mxUser.userId, avatar: mxUser.avatarData, displayName: mxUser.displayname, detailText: mxUser.userId)
|
||||
}
|
||||
|
||||
init(mxRoom: MXRoom, spaceService: MXSpaceService) {
|
||||
let parentSapceIds = mxRoom.summary.parentSpaceIds ?? Set()
|
||||
let detailText: String?
|
||||
if parentSapceIds.isEmpty {
|
||||
detailText = nil
|
||||
} else {
|
||||
if let spaceName = spaceService.getSpace(withId: parentSapceIds.first ?? "")?.summary?.displayname {
|
||||
let count = parentSapceIds.count - 1
|
||||
switch count {
|
||||
case 0:
|
||||
detailText = VectorL10n.spacesCreationInSpacename(spaceName)
|
||||
case 1:
|
||||
detailText = VectorL10n.spacesCreationInSpacenamePlusOne(spaceName)
|
||||
default:
|
||||
detailText = VectorL10n.spacesCreationInSpacenamePlusMany(spaceName, "\(count)")
|
||||
}
|
||||
} else {
|
||||
if parentSapceIds.count > 1 {
|
||||
detailText = VectorL10n.spacesCreationInManySpaces("\(parentSapceIds.count)")
|
||||
} else {
|
||||
detailText = VectorL10n.spacesCreationInOneSpace
|
||||
}
|
||||
}
|
||||
}
|
||||
self.init(id: mxRoom.roomId, avatar: mxRoom.avatarData, displayName: mxRoom.summary.displayname, detailText: detailText)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
class MatrixItemChooserUsersDataSource: MatrixItemChooserDataSource {
|
||||
var preselectedItemIds: Set<String>? { nil }
|
||||
|
||||
func sections(with session: MXSession, completion: @escaping (Result<[MatrixListItemSectionData], Error>) -> Void) {
|
||||
completion(Result(catching: {
|
||||
[
|
||||
MatrixListItemSectionData(title: nil, infoText: nil, items: session.users().map { user in
|
||||
MatrixListItemData(mxUser: user)
|
||||
})
|
||||
]
|
||||
}))
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
extension MatrixListItemData {
|
||||
|
||||
init(mxUser: MXUser) {
|
||||
self.init(id: mxUser.userId, type: .user, avatar: mxUser.avatarData, displayName: mxUser.displayname, detailText: mxUser.userId)
|
||||
}
|
||||
|
||||
init(mxRoom: MXRoom, spaceService: MXSpaceService) {
|
||||
let parentSapceIds = mxRoom.summary.parentSpaceIds ?? Set()
|
||||
let detailText: String?
|
||||
if parentSapceIds.isEmpty {
|
||||
detailText = nil
|
||||
} else {
|
||||
if let spaceName = spaceService.getSpace(withId: parentSapceIds.first ?? "")?.summary?.displayname {
|
||||
let count = parentSapceIds.count - 1
|
||||
switch count {
|
||||
case 0:
|
||||
detailText = VectorL10n.spacesCreationInSpacename(spaceName)
|
||||
case 1:
|
||||
detailText = VectorL10n.spacesCreationInSpacenamePlusOne(spaceName)
|
||||
default:
|
||||
detailText = VectorL10n.spacesCreationInSpacenamePlusMany(spaceName, "\(count)")
|
||||
}
|
||||
} else {
|
||||
if parentSapceIds.count > 1 {
|
||||
detailText = VectorL10n.spacesCreationInManySpaces("\(parentSapceIds.count)")
|
||||
} else {
|
||||
detailText = VectorL10n.spacesCreationInOneSpace
|
||||
}
|
||||
}
|
||||
}
|
||||
let type: MatrixListItemDataType
|
||||
if let summary = mxRoom.summary, summary.roomType == .space {
|
||||
type = .space
|
||||
} else {
|
||||
type = .room
|
||||
}
|
||||
self.init(id: mxRoom.roomId, type: type, avatar: mxRoom.avatarData, displayName: mxRoom.summary.displayname, detailText: detailText)
|
||||
}
|
||||
|
||||
}
|
||||
+24
-14
@@ -20,37 +20,47 @@ import Combine
|
||||
@available(iOS 14.0, *)
|
||||
class MockMatrixItemChooserService: MatrixItemChooserServiceProtocol {
|
||||
|
||||
static let mockItems = [
|
||||
MatrixListItemData(id: "!aaabaa:matrix.org", avatar: MockAvatarInput.example, displayName: "Matrix Discussion", detailText: "Descripton of this room"),
|
||||
MatrixListItemData(id: "!zzasds:matrix.org", avatar: MockAvatarInput.example, displayName: "Element Mobile", detailText: "Descripton of this room"),
|
||||
MatrixListItemData(id: "!scthve:matrix.org", avatar: MockAvatarInput.example, displayName: "Alice Personal", detailText: "Descripton of this room")
|
||||
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"),
|
||||
MatrixListItemData(id: "!zzasds:matrix.org", type: .room, avatar: MockAvatarInput.example, displayName: "Item #2 section #1", detailText: "Descripton of this room"),
|
||||
MatrixListItemData(id: "!scthve:matrix.org", type: .room, avatar: MockAvatarInput.example, displayName: "Item #3 section #1", detailText: "Descripton of this room")
|
||||
]),
|
||||
MatrixListItemSectionData(title: "Section 2", infoText: nil, items: [
|
||||
MatrixListItemData(id: "!asdasd:matrix.org", type: .room, avatar: MockAvatarInput.example, displayName: "Item #1 section #2", detailText: "Descripton of this room"),
|
||||
MatrixListItemData(id: "!lkjlkjl:matrix.org", type: .room, avatar: MockAvatarInput.example, displayName: "Item #2 section #2", detailText: "Descripton of this room"),
|
||||
MatrixListItemData(id: "!vvlkvjlk:matrix.org", type: .room, avatar: MockAvatarInput.example, displayName: "Item #3 section #2", detailText: "Descripton of this room")
|
||||
])
|
||||
]
|
||||
var itemsSubject: CurrentValueSubject<[MatrixListItemData], Never>
|
||||
var sectionsSubject: CurrentValueSubject<[MatrixListItemSectionData], Never>
|
||||
var selectedItemIdsSubject: CurrentValueSubject<Set<String>, Never>
|
||||
var searchText: String = ""
|
||||
var type: MatrixItemChooserType = .room
|
||||
var selectedItemIds: Set<String> = Set()
|
||||
var loadingText: String? {
|
||||
nil
|
||||
}
|
||||
|
||||
init(type: MatrixItemChooserType = .room, items: [MatrixListItemData] = mockItems, selectedItemIndexes: [Int] = []) {
|
||||
itemsSubject = CurrentValueSubject(items)
|
||||
init(type: MatrixItemChooserType = .room, sections: [MatrixListItemSectionData] = mockSections, selectedItemIndexPaths: [IndexPath] = []) {
|
||||
sectionsSubject = CurrentValueSubject(sections)
|
||||
var selectedItemIds = Set<String>()
|
||||
for index in selectedItemIndexes {
|
||||
if index >= items.count {
|
||||
for indexPath in selectedItemIndexPaths {
|
||||
guard indexPath.section < sections.count, indexPath.row < sections[indexPath.section].items.count else {
|
||||
continue
|
||||
}
|
||||
|
||||
selectedItemIds.insert(items[index].id)
|
||||
selectedItemIds.insert(sections[indexPath.section].items[indexPath.row].id)
|
||||
}
|
||||
selectedItemIdsSubject = CurrentValueSubject(selectedItemIds)
|
||||
self.selectedItemIds = selectedItemIds
|
||||
}
|
||||
|
||||
func simulateSelectionForItem(at index: Int) {
|
||||
guard index < itemsSubject.value.count else {
|
||||
func simulateSelectionForItem(at indexPath: IndexPath) {
|
||||
guard indexPath.section < sectionsSubject.value.count, indexPath.row < sectionsSubject.value[indexPath.section].items.count else {
|
||||
return
|
||||
}
|
||||
|
||||
reverseSelectionForItem(withId: itemsSubject.value[index].id)
|
||||
selectedItemIds.insert(sectionsSubject.value[indexPath.section].items[indexPath.row].id)
|
||||
selectedItemIdsSubject.send(selectedItemIds)
|
||||
}
|
||||
|
||||
func reverseSelectionForItem(withId itemId: String) {
|
||||
|
||||
@@ -36,7 +36,7 @@ struct MatrixItemChooser: View {
|
||||
var body: some View {
|
||||
listContent
|
||||
.background(Color.clear)
|
||||
.modifier(WaitOverlay(isLoading: .constant(viewModel.viewState.loading)))
|
||||
.modifier(WaitOverlay(allowUserInteraction: false, message: .constant(viewModel.viewState.loadingText), isLoading: .constant(viewModel.viewState.loading)))
|
||||
.alert(isPresented: .constant(viewModel.viewState.error != nil), content: {
|
||||
Alert(title: Text(MatrixKitL10n.error), message: Text(viewModel.viewState.error ?? ""), dismissButton: .cancel(Text(MatrixKitL10n.ok)))
|
||||
})
|
||||
@@ -48,30 +48,36 @@ struct MatrixItemChooser: View {
|
||||
private var listContent: some View {
|
||||
ScrollView{
|
||||
headerView
|
||||
if viewModel.viewState.items.isEmpty {
|
||||
Text(viewModel.viewState.emptyListMessage)
|
||||
.font(theme.fonts.body)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.accessibility(identifier: "emptyListMessage")
|
||||
Spacer()
|
||||
} else {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(viewModel.viewState.items) { item in
|
||||
MatrixItemChooserListRow(
|
||||
avatar: item.avatar,
|
||||
displayName: item.displayName,
|
||||
detailText: item.detailText,
|
||||
isSelected: viewModel.viewState.selectedItemIds.contains(item.id)
|
||||
)
|
||||
.onTapGesture {
|
||||
viewModel.send(viewAction: .itemTapped(item.id))
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(viewModel.viewState.sections) { section in
|
||||
if section.title != nil || section.infoText != nil {
|
||||
MatrixItemChooserSectionHeader(title: section.title, infoText: section.infoText)
|
||||
}
|
||||
|
||||
if section.items.isEmpty {
|
||||
Text(viewModel.viewState.emptyListMessage)
|
||||
.font(theme.fonts.body)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.accessibility(identifier: "emptyListMessage")
|
||||
} else {
|
||||
ForEach(section.items) { item in
|
||||
MatrixItemChooserListRow(
|
||||
avatar: item.avatar,
|
||||
type: item.type,
|
||||
displayName: item.displayName,
|
||||
detailText: item.detailText,
|
||||
isSelected: viewModel.viewState.selectedItemIds.contains(item.id)
|
||||
)
|
||||
.onTapGesture {
|
||||
viewModel.send(viewAction: .itemTapped(item.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.accessibility(identifier: "itemsList")
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
.animation(nil)
|
||||
}
|
||||
.accessibility(identifier: "sectionsList")
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
.animation(nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ struct MatrixItemChooserListRow: View {
|
||||
// MARK: Public
|
||||
|
||||
let avatar: AvatarInputProtocol
|
||||
let type: MatrixListItemDataType
|
||||
let displayName: String?
|
||||
let detailText: String?
|
||||
let isSelected: Bool
|
||||
@@ -35,7 +36,11 @@ struct MatrixItemChooserListRow: View {
|
||||
@ViewBuilder
|
||||
var body: some View {
|
||||
HStack{
|
||||
AvatarImage(avatarData: avatar, size: .small)
|
||||
if type == .space {
|
||||
SpaceAvatarImage(avatarData: avatar, size: .small)
|
||||
} else {
|
||||
AvatarImage(avatarData: avatar, size: .small)
|
||||
}
|
||||
VStack(alignment: .leading) {
|
||||
Text(displayName ?? "")
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// 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 SwiftUI
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct MatrixItemChooserSectionHeader: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
// MARK: Public
|
||||
|
||||
let title: String?
|
||||
let infoText: String?
|
||||
|
||||
@ViewBuilder
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 16) {
|
||||
if let titleText = title {
|
||||
Text(titleText)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.font(theme.fonts.footnoteSB)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.accessibility(identifier: "headerTitleText")
|
||||
}
|
||||
if let infoText = infoText {
|
||||
HStack(spacing: 16) {
|
||||
Image(uiImage: Asset.Images.roomAccessInfoHeaderIcon.image)
|
||||
.renderingMode(.template)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
Text(infoText)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.font(theme.fonts.footnote)
|
||||
.accessibility(identifier: "headerInfoText")
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.vertical, 8)
|
||||
.padding(.horizontal)
|
||||
.background(theme.colors.navigation)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct MatrixItemChooserSectionHeader_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
Group {
|
||||
VStack(spacing: 16) {
|
||||
MatrixItemChooserSectionHeader(title: nil, infoText: nil)
|
||||
MatrixItemChooserSectionHeader(title: "Some Title", infoText: nil)
|
||||
MatrixItemChooserSectionHeader(title: "Some Title", infoText: "A very long info text in order to see if it's well handled by the UI")
|
||||
}.theme(.light).preferredColorScheme(.light)
|
||||
VStack(spacing: 16) {
|
||||
MatrixItemChooserSectionHeader(title: nil, infoText: nil)
|
||||
MatrixItemChooserSectionHeader(title: "Some Title", infoText: nil)
|
||||
MatrixItemChooserSectionHeader(title: "Some Title", infoText: "A very long info text in order to see if it's well handled by the UI")
|
||||
}.theme(.dark).preferredColorScheme(.dark)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user