mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Fixes #2486 - Implement blocked users management in the app settings
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Copyright 2022 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 Combine
|
||||
import SwiftUI
|
||||
|
||||
struct BlockedUsersScreenCoordinatorParameters {
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum BlockedUsersScreenCoordinatorAction { }
|
||||
|
||||
final class BlockedUsersScreenCoordinator: CoordinatorProtocol {
|
||||
private let viewModel: BlockedUsersScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private let actionsSubject: PassthroughSubject<BlockedUsersScreenCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<BlockedUsersScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(parameters: BlockedUsersScreenCoordinatorParameters) {
|
||||
viewModel = BlockedUsersScreenViewModel(clientProxy: parameters.clientProxy,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func stop() {
|
||||
viewModel.stop()
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(BlockedUsersScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Copyright 2022 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 BlockedUsersScreenViewModelAction { }
|
||||
|
||||
struct BlockedUsersScreenViewState: BindableState {
|
||||
var blockedUsers: [String]
|
||||
var processingUserID: String?
|
||||
|
||||
var bindings = BlockedUsersScreenViewStateBindings()
|
||||
}
|
||||
|
||||
struct BlockedUsersScreenViewStateBindings {
|
||||
var alertInfo: AlertInfo<BlockedUsersScreenViewStateAlertType>?
|
||||
}
|
||||
|
||||
enum BlockedUsersScreenViewAction {
|
||||
case unblockUser(userID: String)
|
||||
}
|
||||
|
||||
enum BlockedUsersScreenViewStateAlertType: Hashable {
|
||||
case unblock
|
||||
case error
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// Copyright 2022 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 Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias BlockedUsersScreenViewModelType = StateStoreViewModel<BlockedUsersScreenViewState, BlockedUsersScreenViewAction>
|
||||
|
||||
class BlockedUsersScreenViewModel: BlockedUsersScreenViewModelType, BlockedUsersScreenViewModelProtocol {
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<BlockedUsersScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<BlockedUsersScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(clientProxy: ClientProxyProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
super.init(initialViewState: BlockedUsersScreenViewState(blockedUsers: clientProxy.ignoredUsersPublisher.value ?? []))
|
||||
|
||||
showLoadingIndicator()
|
||||
|
||||
clientProxy.ignoredUsersPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] blockedUsers in
|
||||
guard let self else { return }
|
||||
|
||||
if let blockedUsers {
|
||||
hideLoadingIndicator()
|
||||
state.blockedUsers = blockedUsers
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: BlockedUsersScreenViewAction) {
|
||||
switch viewAction {
|
||||
case .unblockUser(let userID):
|
||||
state.bindings.alertInfo = .init(id: .unblock,
|
||||
title: L10n.screenBlockedUsersUnblockAlertTitle,
|
||||
message: L10n.screenBlockedUsersUnblockAlertDescription,
|
||||
primaryButton: .init(title: L10n.screenBlockedUsersUnblockAlertAction, role: .destructive) { [weak self] in
|
||||
self?.unblockUser(userID)
|
||||
},
|
||||
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil))
|
||||
}
|
||||
}
|
||||
|
||||
func stop() {
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func unblockUser(_ userID: String) {
|
||||
showLoadingIndicator()
|
||||
state.processingUserID = userID
|
||||
|
||||
Task {
|
||||
if case .failure = await clientProxy.unignoreUser(userID) {
|
||||
state.bindings.alertInfo = .init(id: .error)
|
||||
}
|
||||
|
||||
state.processingUserID = nil
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Loading indicator
|
||||
|
||||
private static let loadingIndicatorIdentifier = "BlockedUsersLoading"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
|
||||
type: .modal(progress: .indeterminate, interactiveDismissDisabled: false, allowsInteraction: true),
|
||||
title: L10n.commonLoading,
|
||||
persistent: true),
|
||||
delay: .milliseconds(100))
|
||||
}
|
||||
|
||||
private func hideLoadingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright 2022 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 Combine
|
||||
|
||||
@MainActor
|
||||
protocol BlockedUsersScreenViewModelProtocol {
|
||||
var actionsPublisher: AnyPublisher<BlockedUsersScreenViewModelAction, Never> { get }
|
||||
var context: BlockedUsersScreenViewModelType.Context { get }
|
||||
|
||||
func stop()
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// Copyright 2022 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 Compound
|
||||
import SwiftUI
|
||||
|
||||
struct BlockedUsersScreen: View {
|
||||
@ObservedObject var context: BlockedUsersScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
content
|
||||
.compoundList()
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(L10n.commonBlockedUsers)
|
||||
.alert(item: $context.alertInfo)
|
||||
.disabled(context.viewState.processingUserID != nil)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@ViewBuilder
|
||||
private var content: some View {
|
||||
if context.viewState.blockedUsers.isEmpty {
|
||||
Text(L10n.screenBlockedUsersEmpty)
|
||||
.font(.compound.bodyMD)
|
||||
.foregroundColor(.compound.textSecondary)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
} else {
|
||||
Form {
|
||||
ForEach(context.viewState.blockedUsers, id: \.self) { userID in
|
||||
ListRow(label: .avatar(title: userID, icon: avatar(for: userID)),
|
||||
details: .isWaiting(context.viewState.processingUserID == userID),
|
||||
kind: .button(action: { context.send(viewAction: .unblockUser(userID: userID)) }))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func avatar(for userID: String) -> some View {
|
||||
LoadableAvatarImage(url: nil,
|
||||
name: String(userID.dropFirst()),
|
||||
contentID: userID,
|
||||
avatarSize: .user(on: .blockedUsers),
|
||||
imageProvider: nil)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct BlockedUsersScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = BlockedUsersScreenViewModel(clientProxy: MockClientProxy(userID: RoomMemberProxyMock.mockMe.userID),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
BlockedUsersScreen(context: viewModel.context)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ final class CompletionSuggestionService: CompletionSuggestionServiceProtocol {
|
||||
init(roomProxy: RoomProxyProtocol) {
|
||||
self.roomProxy = roomProxy
|
||||
suggestionsPublisher = suggestionTriggerSubject
|
||||
.combineLatest(roomProxy.members)
|
||||
.combineLatest(roomProxy.membersPublisher)
|
||||
.map { [weak self] suggestionPattern, members -> [SuggestionItem] in
|
||||
guard let self,
|
||||
let suggestionPattern else {
|
||||
|
||||
@@ -54,12 +54,12 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
super.init(initialViewState: .init(userID: userSession.userID),
|
||||
imageProvider: userSession.mediaProvider)
|
||||
|
||||
userSession.clientProxy.userAvatarURL
|
||||
userSession.clientProxy.userAvatarURLPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.userAvatarURL, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSession.clientProxy.userDisplayName
|
||||
userSession.clientProxy.userDisplayNamePublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.userDisplayName, on: self)
|
||||
.store(in: &cancellables)
|
||||
@@ -256,7 +256,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
|
||||
MXLog.info("Account not migrated, setting view room list mode to \"\(state.roomListMode)\"")
|
||||
|
||||
migrationCancellable = userSession.clientProxy.callbacks
|
||||
migrationCancellable = userSession.clientProxy.actionsPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] callback in
|
||||
guard let self, case .receivedSyncUpdate = callback else { return }
|
||||
|
||||
@@ -118,7 +118,7 @@ class InviteUsersScreenViewModel: InviteUsersScreenViewModelType, InviteUsersScr
|
||||
hideLoader()
|
||||
}
|
||||
|
||||
roomProxy.members
|
||||
roomProxy.membersPublisher
|
||||
.filter { !$0.isEmpty }
|
||||
.first()
|
||||
.receive(on: DispatchQueue.main)
|
||||
|
||||
@@ -132,7 +132,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
// MARK: - Private
|
||||
|
||||
private func setupRoomSubscription() {
|
||||
roomProxy.actions
|
||||
roomProxy.actionsPublisher
|
||||
.filter { $0 == .roomInfoUpdate }
|
||||
.throttle(for: .milliseconds(200), scheduler: DispatchQueue.main, latest: true)
|
||||
.sink { [weak self] _ in
|
||||
@@ -167,7 +167,7 @@ class RoomDetailsScreenViewModel: RoomDetailsScreenViewModelType, RoomDetailsScr
|
||||
return
|
||||
}
|
||||
|
||||
roomProxy.members
|
||||
roomProxy.membersPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] members in
|
||||
guard let self else { return }
|
||||
|
||||
@@ -80,7 +80,7 @@ class RoomMembersListScreenViewModel: RoomMembersListScreenViewModelType, RoomMe
|
||||
hideLoader()
|
||||
}
|
||||
|
||||
roomProxy.members
|
||||
roomProxy.membersPublisher
|
||||
.filter { !$0.isEmpty }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] members in
|
||||
|
||||
+2
-2
@@ -31,12 +31,12 @@ class RoomRolesAndPermissionsScreenViewModel: RoomRolesAndPermissionsScreenViewM
|
||||
self.roomProxy = roomProxy
|
||||
super.init(initialViewState: RoomRolesAndPermissionsScreenViewState())
|
||||
|
||||
roomProxy.members.sink { [weak self] members in
|
||||
roomProxy.membersPublisher.sink { [weak self] members in
|
||||
self?.updateMembers(members)
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
updateMembers(roomProxy.members.value)
|
||||
updateMembers(roomProxy.membersPublisher.value)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
@@ -292,7 +292,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
||||
.store(in: &cancellables)
|
||||
|
||||
roomProxy
|
||||
.actions
|
||||
.actionsPublisher
|
||||
.filter { $0 == .roomInfoUpdate }
|
||||
.throttle(for: .seconds(1), scheduler: DispatchQueue.main, latest: true)
|
||||
.sink { [weak self] _ in
|
||||
@@ -319,7 +319,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
||||
.weakAssign(to: \.state.showReadReceipts, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
roomProxy.members
|
||||
roomProxy.membersPublisher
|
||||
.map { members in
|
||||
members.reduce(into: [String: RoomMemberState]()) { dictionary, member in
|
||||
dictionary[member.userID] = RoomMemberState(displayName: member.displayName, avatarURL: member.avatarURL)
|
||||
@@ -329,7 +329,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
||||
.weakAssign(to: \.state.members, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
roomProxy.typingMembers
|
||||
roomProxy.typingMembersPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.filter { [weak self] _ in self?.appSettings.sharePresence ?? false }
|
||||
.weakAssign(to: \.state.typingMembers, on: self)
|
||||
|
||||
@@ -32,6 +32,7 @@ enum SettingsScreenCoordinatorAction {
|
||||
case appLock
|
||||
case bugReport
|
||||
case about
|
||||
case blockedUsers
|
||||
case sessionVerification
|
||||
case accountSessions
|
||||
case notifications
|
||||
@@ -74,6 +75,8 @@ final class SettingsScreenCoordinator: CoordinatorProtocol {
|
||||
actionsSubject.send(.bugReport)
|
||||
case .about:
|
||||
actionsSubject.send(.about)
|
||||
case .blockedUsers:
|
||||
actionsSubject.send(.blockedUsers)
|
||||
case .sessionVerification:
|
||||
actionsSubject.send(.sessionVerification)
|
||||
case .secureBackup:
|
||||
|
||||
@@ -25,6 +25,7 @@ enum SettingsScreenViewModelAction {
|
||||
case appLock
|
||||
case reportBug
|
||||
case about
|
||||
case blockedUsers
|
||||
case sessionVerification
|
||||
case secureBackup
|
||||
case accountSessionsList
|
||||
@@ -61,6 +62,7 @@ enum SettingsScreenViewAction {
|
||||
case appLock
|
||||
case reportBug
|
||||
case about
|
||||
case blockedUsers
|
||||
case sessionVerification
|
||||
case secureBackup
|
||||
case accountSessionsList
|
||||
|
||||
@@ -34,12 +34,12 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
showDeveloperOptions: appSettings.isDevelopmentBuild),
|
||||
imageProvider: userSession.mediaProvider)
|
||||
|
||||
userSession.clientProxy.userAvatarURL
|
||||
userSession.clientProxy.userAvatarURLPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.userAvatarURL, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
userSession.clientProxy.userDisplayName
|
||||
userSession.clientProxy.userDisplayNamePublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.userDisplayName, on: self)
|
||||
.store(in: &cancellables)
|
||||
@@ -94,6 +94,8 @@ class SettingsScreenViewModel: SettingsScreenViewModelType, SettingsScreenViewMo
|
||||
actionsSubject.send(.reportBug)
|
||||
case .about:
|
||||
actionsSubject.send(.about)
|
||||
case .blockedUsers:
|
||||
actionsSubject.send(.blockedUsers)
|
||||
case .logout:
|
||||
actionsSubject.send(.logout)
|
||||
case .sessionVerification:
|
||||
|
||||
@@ -143,6 +143,13 @@ struct SettingsScreen: View {
|
||||
context.send(viewAction: .about)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.about)
|
||||
|
||||
ListRow(label: .default(title: L10n.commonBlockedUsers,
|
||||
icon: \.block),
|
||||
kind: .navigationLink {
|
||||
context.send(viewAction: .blockedUsers)
|
||||
})
|
||||
.accessibilityIdentifier(A11yIdentifiers.settingsScreen.blockedUsers)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -38,22 +38,22 @@ class UserDetailsEditScreenViewModel: UserDetailsEditScreenViewModelType, UserDe
|
||||
super.init(initialViewState: UserDetailsEditScreenViewState(userID: clientProxy.userID,
|
||||
bindings: .init()), imageProvider: mediaProvider)
|
||||
|
||||
clientProxy.userAvatarURL
|
||||
clientProxy.userAvatarURLPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.currentAvatarURL, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
clientProxy.userAvatarURL
|
||||
clientProxy.userAvatarURLPublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.selectedAvatarURL, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
clientProxy.userDisplayName
|
||||
clientProxy.userDisplayNamePublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.currentDisplayName, on: self)
|
||||
.store(in: &cancellables)
|
||||
|
||||
clientProxy.userDisplayName
|
||||
clientProxy.userDisplayNamePublisher
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] displayName in
|
||||
guard let self else { return }
|
||||
|
||||
Reference in New Issue
Block a user