mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 00:52:43 +02:00
Configured and applied SwiftFormat
This commit is contained in:
committed by
Stefan Ceriu
parent
ff2e6ddfa7
commit
43c28d23b7
+7
-10
@@ -14,10 +14,10 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
protocol UserSuggestionCoordinatorDelegate: AnyObject {
|
||||
func userSuggestionCoordinator(_ coordinator: UserSuggestionCoordinator, didRequestMentionForMember member: MXRoomMember, textTrigger: String?)
|
||||
@@ -30,7 +30,6 @@ struct UserSuggestionCoordinatorParameters {
|
||||
}
|
||||
|
||||
final class UserSuggestionCoordinator: Coordinator, Presentable {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -94,12 +93,11 @@ final class UserSuggestionCoordinator: Coordinator, Presentable {
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
func start() {
|
||||
|
||||
}
|
||||
|
||||
func start() { }
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
return self.userSuggestionHostingController
|
||||
userSuggestionHostingController
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
@@ -131,13 +129,12 @@ final class UserSuggestionCoordinator: Coordinator, Presentable {
|
||||
}
|
||||
|
||||
private class UserSuggestionCoordinatorRoomMemberProvider: RoomMembersProviderProtocol {
|
||||
|
||||
private let room: MXRoom
|
||||
|
||||
var roomMembers: [MXRoomMember] = []
|
||||
|
||||
init(room: MXRoom) {
|
||||
self.room = room;
|
||||
self.room = room
|
||||
}
|
||||
|
||||
func fetchMembers(_ members: @escaping ([RoomMembersProviderMember]) -> Void) {
|
||||
|
||||
+6
-7
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -24,10 +24,9 @@ protocol UserSuggestionCoordinatorBridgeDelegate: AnyObject {
|
||||
|
||||
@objcMembers
|
||||
final class UserSuggestionCoordinatorBridge: NSObject {
|
||||
|
||||
private var _userSuggestionCoordinator: Any? = nil
|
||||
private var _userSuggestionCoordinator: Any?
|
||||
fileprivate var userSuggestionCoordinator: UserSuggestionCoordinator {
|
||||
return _userSuggestionCoordinator as! UserSuggestionCoordinator
|
||||
_userSuggestionCoordinator as! UserSuggestionCoordinator
|
||||
}
|
||||
|
||||
weak var delegate: UserSuggestionCoordinatorBridgeDelegate?
|
||||
@@ -35,7 +34,7 @@ final class UserSuggestionCoordinatorBridge: NSObject {
|
||||
init(mediaManager: MXMediaManager, room: MXRoom) {
|
||||
let parameters = UserSuggestionCoordinatorParameters(mediaManager: mediaManager, room: room)
|
||||
let userSuggestionCoordinator = UserSuggestionCoordinator(parameters: parameters)
|
||||
self._userSuggestionCoordinator = userSuggestionCoordinator
|
||||
_userSuggestionCoordinator = userSuggestionCoordinator
|
||||
|
||||
super.init()
|
||||
|
||||
@@ -43,11 +42,11 @@ final class UserSuggestionCoordinatorBridge: NSObject {
|
||||
}
|
||||
|
||||
func processTextMessage(_ textMessage: String) {
|
||||
return self.userSuggestionCoordinator.processTextMessage(textMessage)
|
||||
userSuggestionCoordinator.processTextMessage(textMessage)
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController? {
|
||||
return self.userSuggestionCoordinator.toPresentable()
|
||||
userSuggestionCoordinator.toPresentable()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
struct RoomMembersProviderMember {
|
||||
var userId: String
|
||||
@@ -34,7 +34,6 @@ struct UserSuggestionServiceItem: UserSuggestionItemProtocol {
|
||||
}
|
||||
|
||||
class UserSuggestionService: UserSuggestionServiceProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -58,7 +57,7 @@ class UserSuggestionService: UserSuggestionServiceProtocol {
|
||||
init(roomMemberProvider: RoomMembersProviderProtocol, shouldDebounce: Bool = true) {
|
||||
self.roomMemberProvider = roomMemberProvider
|
||||
|
||||
if (shouldDebounce) {
|
||||
if shouldDebounce {
|
||||
currentTextTriggerSubject
|
||||
.debounce(for: 0.5, scheduler: RunLoop.main)
|
||||
.removeDuplicates()
|
||||
@@ -79,12 +78,12 @@ class UserSuggestionService: UserSuggestionServiceProtocol {
|
||||
let lastComponent = textMessage.components(separatedBy: .whitespaces).last,
|
||||
lastComponent.prefix(while: { $0 == "@" }).count == 1 // Partial username should start with one and only one "@" character
|
||||
else {
|
||||
self.items.send([])
|
||||
self.currentTextTriggerSubject.send(nil)
|
||||
items.send([])
|
||||
currentTextTriggerSubject.send(nil)
|
||||
return
|
||||
}
|
||||
|
||||
self.currentTextTriggerSubject.send(lastComponent)
|
||||
currentTextTriggerSubject.send(lastComponent)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
@@ -105,12 +104,12 @@ class UserSuggestionService: UserSuggestionServiceProtocol {
|
||||
UserSuggestionServiceItem(userId: member.userId, displayName: member.displayName, avatarUrl: member.avatarUrl)
|
||||
}
|
||||
|
||||
self.items.send(self.suggestionItems.filter({ userSuggestion in
|
||||
self.items.send(self.suggestionItems.filter { userSuggestion in
|
||||
let containedInUsername = userSuggestion.userId.lowercased().contains(partialName.lowercased())
|
||||
let containedInDisplayName = (userSuggestion.displayName ?? "").lowercased().contains(partialName.lowercased())
|
||||
|
||||
return (containedInUsername || containedInDisplayName)
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 UserSuggestionItemProtocol: Avatarable {
|
||||
var userId: String { get }
|
||||
@@ -24,7 +24,6 @@ protocol UserSuggestionItemProtocol: Avatarable {
|
||||
}
|
||||
|
||||
protocol UserSuggestionServiceProtocol {
|
||||
|
||||
var items: CurrentValueSubject<[UserSuggestionItemProtocol], Never> { get }
|
||||
|
||||
var currentTextTrigger: String? { get }
|
||||
@@ -38,6 +37,7 @@ extension UserSuggestionItemProtocol {
|
||||
var mxContentUri: String? {
|
||||
avatarUrl
|
||||
}
|
||||
|
||||
var matrixItemId: String {
|
||||
userId
|
||||
}
|
||||
|
||||
@@ -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 RiotSwiftUI
|
||||
import XCTest
|
||||
|
||||
class UserSuggestionUITests: MockScreenTestCase {
|
||||
func testUserSuggestionScreen() throws {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,13 +14,12 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
import Combine
|
||||
import XCTest
|
||||
|
||||
@testable import RiotSwiftUI
|
||||
|
||||
class UserSuggestionServiceTests: XCTestCase {
|
||||
|
||||
var service: UserSuggestionService?
|
||||
|
||||
override func setUp() {
|
||||
@@ -107,12 +106,11 @@ class UserSuggestionServiceTests: XCTestCase {
|
||||
|
||||
extension UserSuggestionServiceTests: RoomMembersProviderProtocol {
|
||||
func fetchMembers(_ members: @escaping ([RoomMembersProviderMember]) -> Void) {
|
||||
|
||||
let users = [("Alice", "@alice:matrix.org"),
|
||||
("Bob", "@bob:matrix.org")]
|
||||
|
||||
members(users.map({ user in
|
||||
members(users.map { user in
|
||||
RoomMembersProviderMember(userId: user.1, displayName: user.0, avatarUrl: "")
|
||||
}))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
@@ -20,13 +20,13 @@ import SwiftUI
|
||||
enum MockUserSuggestionScreenState: MockScreenState, CaseIterable {
|
||||
case multipleResults
|
||||
|
||||
static private var members: [RoomMembersProviderMember]!
|
||||
private static var members: [RoomMembersProviderMember]!
|
||||
|
||||
var screenType: Any.Type {
|
||||
UserSuggestionList.self
|
||||
}
|
||||
|
||||
var screenView: ([Any], AnyView) {
|
||||
var screenView: ([Any], AnyView) {
|
||||
let service = UserSuggestionService(roomMemberProvider: self)
|
||||
let listViewModel = UserSuggestionViewModel(userSuggestionService: service)
|
||||
|
||||
@@ -37,7 +37,7 @@ enum MockUserSuggestionScreenState: MockScreenState, CaseIterable {
|
||||
return (
|
||||
[service, listViewModel],
|
||||
AnyView(UserSuggestionListWithInput(viewModel: viewModel)
|
||||
.addDependency(MockAvatarService.example))
|
||||
.addDependency(MockAvatarService.example))
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ extension MockUserSuggestionScreenState: RoomMembersProviderProtocol {
|
||||
}
|
||||
|
||||
private func generateUsersWithCount(_ count: UInt) -> [RoomMembersProviderMember] {
|
||||
return (0..<count).map { _ in
|
||||
(0..<count).map { _ in
|
||||
let identifier = "@" + UUID().uuidString
|
||||
return RoomMembersProviderMember(userId: identifier, displayName: identifier, avatarUrl: "mxc://matrix.org/VyNYAgahaiAzUoOeZETtQ")
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,15 +14,14 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias UserSuggestionViewModelType = StateStoreViewModel <UserSuggestionViewState,
|
||||
Never,
|
||||
UserSuggestionViewAction>
|
||||
typealias UserSuggestionViewModelType = StateStoreViewModel<UserSuggestionViewState,
|
||||
Never,
|
||||
UserSuggestionViewAction>
|
||||
|
||||
class UserSuggestionViewModel: UserSuggestionViewModelType, UserSuggestionViewModelProtocol {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -39,15 +38,15 @@ class UserSuggestionViewModel: UserSuggestionViewModelType, UserSuggestionViewMo
|
||||
self.userSuggestionService = userSuggestionService
|
||||
|
||||
let items = userSuggestionService.items.value.map { suggestionItem in
|
||||
return UserSuggestionViewStateItem(id: suggestionItem.userId, avatar: suggestionItem, displayName: suggestionItem.displayName)
|
||||
UserSuggestionViewStateItem(id: suggestionItem.userId, avatar: suggestionItem, displayName: suggestionItem.displayName)
|
||||
}
|
||||
|
||||
super.init(initialViewState: UserSuggestionViewState(items: items))
|
||||
|
||||
userSuggestionService.items.sink { [weak self] items in
|
||||
self?.state.items = items.map({ item in
|
||||
self?.state.items = items.map { item in
|
||||
UserSuggestionViewStateItem(id: item.userId, avatar: item, displayName: item.displayName)
|
||||
})
|
||||
}
|
||||
}.store(in: &cancellables)
|
||||
}
|
||||
|
||||
|
||||
@@ -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,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct UserSuggestionList: View {
|
||||
private struct Constants {
|
||||
private enum Constants {
|
||||
static let topPadding: CGFloat = 8.0
|
||||
static let listItemPadding: CGFloat = 4.0
|
||||
static let lineSpacing: CGFloat = 10.0
|
||||
@@ -57,7 +57,7 @@ struct UserSuggestionList: View {
|
||||
userId: item.id
|
||||
)
|
||||
.padding(.bottom, Constants.listItemPadding)
|
||||
.padding(.top, (viewModel.viewState.items.first?.id == item.id ? Constants.listItemPadding + Constants.topPadding : Constants.listItemPadding))
|
||||
.padding(.top, viewModel.viewState.items.first?.id == item.id ? Constants.listItemPadding + Constants.topPadding : Constants.listItemPadding)
|
||||
}
|
||||
}
|
||||
.listStyle(PlainListStyle())
|
||||
@@ -76,7 +76,6 @@ struct UserSuggestionList: View {
|
||||
}
|
||||
|
||||
private struct BackgroundView<Content: View>: View {
|
||||
|
||||
var content: () -> Content
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -17,13 +17,14 @@
|
||||
import SwiftUI
|
||||
|
||||
struct UserSuggestionListItem: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
// MARK: Public
|
||||
|
||||
let avatar: AvatarInputProtocol?
|
||||
let displayName: String?
|
||||
let userId: String
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2021 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -18,11 +18,10 @@ import SwiftUI
|
||||
|
||||
struct UserSuggestionListWithInputViewModel {
|
||||
let listViewModel: UserSuggestionViewModel
|
||||
let callback: (String)->()
|
||||
let callback: (String) -> Void
|
||||
}
|
||||
|
||||
struct UserSuggestionListWithInput: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
@@ -30,14 +29,14 @@ struct UserSuggestionListWithInput: View {
|
||||
// MARK: Public
|
||||
|
||||
var viewModel: UserSuggestionListWithInputViewModel
|
||||
@State private var inputText: String = ""
|
||||
@State private var inputText = ""
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0.0) {
|
||||
UserSuggestionList(viewModel: viewModel.listViewModel.context)
|
||||
TextField("Search for user", text: $inputText)
|
||||
.background(Color.white)
|
||||
.onChange(of: inputText, perform:viewModel.callback)
|
||||
.onChange(of: inputText, perform: viewModel.callback)
|
||||
.textFieldStyle(RoundedBorderTextFieldStyle())
|
||||
.padding([.leading, .trailing])
|
||||
.onAppear {
|
||||
|
||||
Reference in New Issue
Block a user