mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Security and privacy part 2 (#3637)
* handling the history visibility flag * better logic to handle visibility * better handling of the visibility options state * added some copies, and the public room directory visibility state * completed the UI added also the preview tests * improved the handling of the directory visibility * added the space users case and improved handling of the access -> vsibility reaction. Also added a simple error handling for the public directory toggle * added the edit room address view but is missing its full implementation * implement the UI for the edit room address screen * implemented error checking when editing the address * updated preview tests and improved code * typo fix * Fix various issues after rebasing. * Fix build errors and broken snapshot tests * Adopt latest room privacy and canonical alias setting APIs * Add support for creating and editing the room's alias. * Add support for saving room privacy setting changes. * Fix room alias screen snapshot tests following recent changes. --------- Co-authored-by: Stefan Ceriu <stefanc@matrix.org>
This commit is contained in:
@@ -1468,14 +1468,16 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
}
|
||||
|
||||
private func presentSecurityAndPrivacyScreen() {
|
||||
let coordinator = SecurityAndPrivacyScreenCoordinator(parameters: .init(roomProxy: roomProxy))
|
||||
let coordinator = SecurityAndPrivacyScreenCoordinator(parameters: .init(roomProxy: roomProxy,
|
||||
clientProxy: userSession.clientProxy,
|
||||
userIndicatorController: userIndicatorController))
|
||||
|
||||
coordinator.actionsPublisher.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .done:
|
||||
break
|
||||
case .displayEditAddressScreen:
|
||||
presentEditAddressScreen()
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@@ -1485,6 +1487,24 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
private func presentEditAddressScreen() {
|
||||
let stackCoordinator = NavigationStackCoordinator()
|
||||
let coordinator = EditRoomAddressScreenCoordinator(parameters: .init(roomProxy: roomProxy,
|
||||
clientProxy: userSession.clientProxy,
|
||||
userIndicatorController: userIndicatorController))
|
||||
|
||||
coordinator.actionsPublisher.sink { [weak self] action in
|
||||
switch action {
|
||||
case .dismiss:
|
||||
self?.navigationStackCoordinator.setSheetCoordinator(nil)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
stackCoordinator.setRootCoordinator(coordinator)
|
||||
navigationStackCoordinator.setSheetCoordinator(stackCoordinator)
|
||||
}
|
||||
|
||||
// MARK: - Other flows
|
||||
|
||||
private func startChildFlow(for roomID: String, via: [String], entryPoint: RoomFlowCoordinatorEntryPoint) async {
|
||||
|
||||
@@ -6223,6 +6223,70 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol {
|
||||
return messageFilteredTimelineAllowedMessageTypesReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - enableEncryption
|
||||
|
||||
var enableEncryptionUnderlyingCallsCount = 0
|
||||
var enableEncryptionCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return enableEncryptionUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = enableEncryptionUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
enableEncryptionUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
enableEncryptionUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var enableEncryptionCalled: Bool {
|
||||
return enableEncryptionCallsCount > 0
|
||||
}
|
||||
|
||||
var enableEncryptionUnderlyingReturnValue: Result<Void, RoomProxyError>!
|
||||
var enableEncryptionReturnValue: Result<Void, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return enableEncryptionUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = enableEncryptionUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
enableEncryptionUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
enableEncryptionUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var enableEncryptionClosure: (() async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func enableEncryption() async -> Result<Void, RoomProxyError> {
|
||||
enableEncryptionCallsCount += 1
|
||||
if let enableEncryptionClosure = enableEncryptionClosure {
|
||||
return await enableEncryptionClosure()
|
||||
} else {
|
||||
return enableEncryptionReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - redact
|
||||
|
||||
var redactUnderlyingCallsCount = 0
|
||||
@@ -7227,6 +7291,490 @@ class JoinedRoomProxyMock: JoinedRoomProxyProtocol {
|
||||
return withdrawVerificationAndResendUserIDsSendHandleReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - updateJoinRule
|
||||
|
||||
var updateJoinRuleUnderlyingCallsCount = 0
|
||||
var updateJoinRuleCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateJoinRuleUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateJoinRuleUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateJoinRuleUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateJoinRuleUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateJoinRuleCalled: Bool {
|
||||
return updateJoinRuleCallsCount > 0
|
||||
}
|
||||
var updateJoinRuleReceivedRule: JoinRule?
|
||||
var updateJoinRuleReceivedInvocations: [JoinRule] = []
|
||||
|
||||
var updateJoinRuleUnderlyingReturnValue: Result<Void, RoomProxyError>!
|
||||
var updateJoinRuleReturnValue: Result<Void, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateJoinRuleUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateJoinRuleUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateJoinRuleUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateJoinRuleUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateJoinRuleClosure: ((JoinRule) async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func updateJoinRule(_ rule: JoinRule) async -> Result<Void, RoomProxyError> {
|
||||
updateJoinRuleCallsCount += 1
|
||||
updateJoinRuleReceivedRule = rule
|
||||
DispatchQueue.main.async {
|
||||
self.updateJoinRuleReceivedInvocations.append(rule)
|
||||
}
|
||||
if let updateJoinRuleClosure = updateJoinRuleClosure {
|
||||
return await updateJoinRuleClosure(rule)
|
||||
} else {
|
||||
return updateJoinRuleReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - updateHistoryVisibility
|
||||
|
||||
var updateHistoryVisibilityUnderlyingCallsCount = 0
|
||||
var updateHistoryVisibilityCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateHistoryVisibilityUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateHistoryVisibilityUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateHistoryVisibilityUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateHistoryVisibilityUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateHistoryVisibilityCalled: Bool {
|
||||
return updateHistoryVisibilityCallsCount > 0
|
||||
}
|
||||
var updateHistoryVisibilityReceivedVisibility: RoomHistoryVisibility?
|
||||
var updateHistoryVisibilityReceivedInvocations: [RoomHistoryVisibility] = []
|
||||
|
||||
var updateHistoryVisibilityUnderlyingReturnValue: Result<Void, RoomProxyError>!
|
||||
var updateHistoryVisibilityReturnValue: Result<Void, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateHistoryVisibilityUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateHistoryVisibilityUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateHistoryVisibilityUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateHistoryVisibilityUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateHistoryVisibilityClosure: ((RoomHistoryVisibility) async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func updateHistoryVisibility(_ visibility: RoomHistoryVisibility) async -> Result<Void, RoomProxyError> {
|
||||
updateHistoryVisibilityCallsCount += 1
|
||||
updateHistoryVisibilityReceivedVisibility = visibility
|
||||
DispatchQueue.main.async {
|
||||
self.updateHistoryVisibilityReceivedInvocations.append(visibility)
|
||||
}
|
||||
if let updateHistoryVisibilityClosure = updateHistoryVisibilityClosure {
|
||||
return await updateHistoryVisibilityClosure(visibility)
|
||||
} else {
|
||||
return updateHistoryVisibilityReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - isVisibleInRoomDirectory
|
||||
|
||||
var isVisibleInRoomDirectoryUnderlyingCallsCount = 0
|
||||
var isVisibleInRoomDirectoryCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return isVisibleInRoomDirectoryUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = isVisibleInRoomDirectoryUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
isVisibleInRoomDirectoryUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
isVisibleInRoomDirectoryUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var isVisibleInRoomDirectoryCalled: Bool {
|
||||
return isVisibleInRoomDirectoryCallsCount > 0
|
||||
}
|
||||
|
||||
var isVisibleInRoomDirectoryUnderlyingReturnValue: Result<Bool, RoomProxyError>!
|
||||
var isVisibleInRoomDirectoryReturnValue: Result<Bool, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return isVisibleInRoomDirectoryUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Bool, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = isVisibleInRoomDirectoryUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
isVisibleInRoomDirectoryUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
isVisibleInRoomDirectoryUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var isVisibleInRoomDirectoryClosure: (() async -> Result<Bool, RoomProxyError>)?
|
||||
|
||||
func isVisibleInRoomDirectory() async -> Result<Bool, RoomProxyError> {
|
||||
isVisibleInRoomDirectoryCallsCount += 1
|
||||
if let isVisibleInRoomDirectoryClosure = isVisibleInRoomDirectoryClosure {
|
||||
return await isVisibleInRoomDirectoryClosure()
|
||||
} else {
|
||||
return isVisibleInRoomDirectoryReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - updateRoomDirectoryVisibility
|
||||
|
||||
var updateRoomDirectoryVisibilityUnderlyingCallsCount = 0
|
||||
var updateRoomDirectoryVisibilityCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateRoomDirectoryVisibilityUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateRoomDirectoryVisibilityUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateRoomDirectoryVisibilityUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateRoomDirectoryVisibilityUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateRoomDirectoryVisibilityCalled: Bool {
|
||||
return updateRoomDirectoryVisibilityCallsCount > 0
|
||||
}
|
||||
var updateRoomDirectoryVisibilityReceivedVisibility: RoomVisibility?
|
||||
var updateRoomDirectoryVisibilityReceivedInvocations: [RoomVisibility] = []
|
||||
|
||||
var updateRoomDirectoryVisibilityUnderlyingReturnValue: Result<Void, RoomProxyError>!
|
||||
var updateRoomDirectoryVisibilityReturnValue: Result<Void, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateRoomDirectoryVisibilityUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateRoomDirectoryVisibilityUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateRoomDirectoryVisibilityUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateRoomDirectoryVisibilityUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateRoomDirectoryVisibilityClosure: ((RoomVisibility) async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func updateRoomDirectoryVisibility(_ visibility: RoomVisibility) async -> Result<Void, RoomProxyError> {
|
||||
updateRoomDirectoryVisibilityCallsCount += 1
|
||||
updateRoomDirectoryVisibilityReceivedVisibility = visibility
|
||||
DispatchQueue.main.async {
|
||||
self.updateRoomDirectoryVisibilityReceivedInvocations.append(visibility)
|
||||
}
|
||||
if let updateRoomDirectoryVisibilityClosure = updateRoomDirectoryVisibilityClosure {
|
||||
return await updateRoomDirectoryVisibilityClosure(visibility)
|
||||
} else {
|
||||
return updateRoomDirectoryVisibilityReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - updateCanonicalAlias
|
||||
|
||||
var updateCanonicalAliasAltAliasesUnderlyingCallsCount = 0
|
||||
var updateCanonicalAliasAltAliasesCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateCanonicalAliasAltAliasesUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateCanonicalAliasAltAliasesUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateCanonicalAliasAltAliasesUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateCanonicalAliasAltAliasesUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateCanonicalAliasAltAliasesCalled: Bool {
|
||||
return updateCanonicalAliasAltAliasesCallsCount > 0
|
||||
}
|
||||
var updateCanonicalAliasAltAliasesReceivedArguments: (alias: String?, altAliases: [String])?
|
||||
var updateCanonicalAliasAltAliasesReceivedInvocations: [(alias: String?, altAliases: [String])] = []
|
||||
|
||||
var updateCanonicalAliasAltAliasesUnderlyingReturnValue: Result<Void, RoomProxyError>!
|
||||
var updateCanonicalAliasAltAliasesReturnValue: Result<Void, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateCanonicalAliasAltAliasesUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateCanonicalAliasAltAliasesUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateCanonicalAliasAltAliasesUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateCanonicalAliasAltAliasesUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var updateCanonicalAliasAltAliasesClosure: ((String?, [String]) async -> Result<Void, RoomProxyError>)?
|
||||
|
||||
func updateCanonicalAlias(_ alias: String?, altAliases: [String]) async -> Result<Void, RoomProxyError> {
|
||||
updateCanonicalAliasAltAliasesCallsCount += 1
|
||||
updateCanonicalAliasAltAliasesReceivedArguments = (alias: alias, altAliases: altAliases)
|
||||
DispatchQueue.main.async {
|
||||
self.updateCanonicalAliasAltAliasesReceivedInvocations.append((alias: alias, altAliases: altAliases))
|
||||
}
|
||||
if let updateCanonicalAliasAltAliasesClosure = updateCanonicalAliasAltAliasesClosure {
|
||||
return await updateCanonicalAliasAltAliasesClosure(alias, altAliases)
|
||||
} else {
|
||||
return updateCanonicalAliasAltAliasesReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - publishRoomAliasInRoomDirectory
|
||||
|
||||
var publishRoomAliasInRoomDirectoryUnderlyingCallsCount = 0
|
||||
var publishRoomAliasInRoomDirectoryCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return publishRoomAliasInRoomDirectoryUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = publishRoomAliasInRoomDirectoryUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
publishRoomAliasInRoomDirectoryUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
publishRoomAliasInRoomDirectoryUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var publishRoomAliasInRoomDirectoryCalled: Bool {
|
||||
return publishRoomAliasInRoomDirectoryCallsCount > 0
|
||||
}
|
||||
var publishRoomAliasInRoomDirectoryReceivedAlias: String?
|
||||
var publishRoomAliasInRoomDirectoryReceivedInvocations: [String] = []
|
||||
|
||||
var publishRoomAliasInRoomDirectoryUnderlyingReturnValue: Result<Bool, RoomProxyError>!
|
||||
var publishRoomAliasInRoomDirectoryReturnValue: Result<Bool, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return publishRoomAliasInRoomDirectoryUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Bool, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = publishRoomAliasInRoomDirectoryUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
publishRoomAliasInRoomDirectoryUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
publishRoomAliasInRoomDirectoryUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var publishRoomAliasInRoomDirectoryClosure: ((String) async -> Result<Bool, RoomProxyError>)?
|
||||
|
||||
func publishRoomAliasInRoomDirectory(_ alias: String) async -> Result<Bool, RoomProxyError> {
|
||||
publishRoomAliasInRoomDirectoryCallsCount += 1
|
||||
publishRoomAliasInRoomDirectoryReceivedAlias = alias
|
||||
DispatchQueue.main.async {
|
||||
self.publishRoomAliasInRoomDirectoryReceivedInvocations.append(alias)
|
||||
}
|
||||
if let publishRoomAliasInRoomDirectoryClosure = publishRoomAliasInRoomDirectoryClosure {
|
||||
return await publishRoomAliasInRoomDirectoryClosure(alias)
|
||||
} else {
|
||||
return publishRoomAliasInRoomDirectoryReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - removeRoomAliasFromRoomDirectory
|
||||
|
||||
var removeRoomAliasFromRoomDirectoryUnderlyingCallsCount = 0
|
||||
var removeRoomAliasFromRoomDirectoryCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return removeRoomAliasFromRoomDirectoryUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = removeRoomAliasFromRoomDirectoryUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
removeRoomAliasFromRoomDirectoryUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
removeRoomAliasFromRoomDirectoryUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var removeRoomAliasFromRoomDirectoryCalled: Bool {
|
||||
return removeRoomAliasFromRoomDirectoryCallsCount > 0
|
||||
}
|
||||
var removeRoomAliasFromRoomDirectoryReceivedAlias: String?
|
||||
var removeRoomAliasFromRoomDirectoryReceivedInvocations: [String] = []
|
||||
|
||||
var removeRoomAliasFromRoomDirectoryUnderlyingReturnValue: Result<Bool, RoomProxyError>!
|
||||
var removeRoomAliasFromRoomDirectoryReturnValue: Result<Bool, RoomProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return removeRoomAliasFromRoomDirectoryUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Bool, RoomProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = removeRoomAliasFromRoomDirectoryUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
removeRoomAliasFromRoomDirectoryUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
removeRoomAliasFromRoomDirectoryUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var removeRoomAliasFromRoomDirectoryClosure: ((String) async -> Result<Bool, RoomProxyError>)?
|
||||
|
||||
func removeRoomAliasFromRoomDirectory(_ alias: String) async -> Result<Bool, RoomProxyError> {
|
||||
removeRoomAliasFromRoomDirectoryCallsCount += 1
|
||||
removeRoomAliasFromRoomDirectoryReceivedAlias = alias
|
||||
DispatchQueue.main.async {
|
||||
self.removeRoomAliasFromRoomDirectoryReceivedInvocations.append(alias)
|
||||
}
|
||||
if let removeRoomAliasFromRoomDirectoryClosure = removeRoomAliasFromRoomDirectoryClosure {
|
||||
return await removeRoomAliasFromRoomDirectoryClosure(alias)
|
||||
} else {
|
||||
return removeRoomAliasFromRoomDirectoryReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - flagAsUnread
|
||||
|
||||
var flagAsUnreadUnderlyingCallsCount = 0
|
||||
|
||||
@@ -625,52 +625,6 @@ open class ClientSDKMock: MatrixRustSDK.Client {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - createRoomAlias
|
||||
|
||||
open var createRoomAliasRoomAliasRoomIdThrowableError: Error?
|
||||
var createRoomAliasRoomAliasRoomIdUnderlyingCallsCount = 0
|
||||
open var createRoomAliasRoomAliasRoomIdCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return createRoomAliasRoomAliasRoomIdUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = createRoomAliasRoomAliasRoomIdUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
createRoomAliasRoomAliasRoomIdUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
createRoomAliasRoomAliasRoomIdUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var createRoomAliasRoomAliasRoomIdCalled: Bool {
|
||||
return createRoomAliasRoomAliasRoomIdCallsCount > 0
|
||||
}
|
||||
open var createRoomAliasRoomAliasRoomIdReceivedArguments: (roomAlias: String, roomId: String)?
|
||||
open var createRoomAliasRoomAliasRoomIdReceivedInvocations: [(roomAlias: String, roomId: String)] = []
|
||||
open var createRoomAliasRoomAliasRoomIdClosure: ((String, String) async throws -> Void)?
|
||||
|
||||
open override func createRoomAlias(roomAlias: String, roomId: String) async throws {
|
||||
if let error = createRoomAliasRoomAliasRoomIdThrowableError {
|
||||
throw error
|
||||
}
|
||||
createRoomAliasRoomAliasRoomIdCallsCount += 1
|
||||
createRoomAliasRoomAliasRoomIdReceivedArguments = (roomAlias: roomAlias, roomId: roomId)
|
||||
DispatchQueue.main.async {
|
||||
self.createRoomAliasRoomAliasRoomIdReceivedInvocations.append((roomAlias: roomAlias, roomId: roomId))
|
||||
}
|
||||
try await createRoomAliasRoomAliasRoomIdClosure?(roomAlias, roomId)
|
||||
}
|
||||
|
||||
//MARK: - customLoginWithJwt
|
||||
|
||||
open var customLoginWithJwtJwtInitialDeviceNameDeviceIdThrowableError: Error?
|
||||
@@ -11326,6 +11280,46 @@ open class RoomSDKMock: MatrixRustSDK.Room {
|
||||
try await editEventIdNewContentClosure?(eventId, newContent)
|
||||
}
|
||||
|
||||
//MARK: - enableEncryption
|
||||
|
||||
open var enableEncryptionThrowableError: Error?
|
||||
var enableEncryptionUnderlyingCallsCount = 0
|
||||
open var enableEncryptionCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return enableEncryptionUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = enableEncryptionUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
enableEncryptionUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
enableEncryptionUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var enableEncryptionCalled: Bool {
|
||||
return enableEncryptionCallsCount > 0
|
||||
}
|
||||
open var enableEncryptionClosure: (() async throws -> Void)?
|
||||
|
||||
open override func enableEncryption() async throws {
|
||||
if let error = enableEncryptionThrowableError {
|
||||
throw error
|
||||
}
|
||||
enableEncryptionCallsCount += 1
|
||||
try await enableEncryptionClosure?()
|
||||
}
|
||||
|
||||
//MARK: - enableSendQueue
|
||||
|
||||
var enableSendQueueEnableUnderlyingCallsCount = 0
|
||||
@@ -11437,6 +11431,75 @@ open class RoomSDKMock: MatrixRustSDK.Room {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - getRoomVisibility
|
||||
|
||||
open var getRoomVisibilityThrowableError: Error?
|
||||
var getRoomVisibilityUnderlyingCallsCount = 0
|
||||
open var getRoomVisibilityCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return getRoomVisibilityUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = getRoomVisibilityUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
getRoomVisibilityUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
getRoomVisibilityUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var getRoomVisibilityCalled: Bool {
|
||||
return getRoomVisibilityCallsCount > 0
|
||||
}
|
||||
|
||||
var getRoomVisibilityUnderlyingReturnValue: RoomVisibility!
|
||||
open var getRoomVisibilityReturnValue: RoomVisibility! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return getRoomVisibilityUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: RoomVisibility? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = getRoomVisibilityUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
getRoomVisibilityUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
getRoomVisibilityUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var getRoomVisibilityClosure: (() async throws -> RoomVisibility)?
|
||||
|
||||
open override func getRoomVisibility() async throws -> RoomVisibility {
|
||||
if let error = getRoomVisibilityThrowableError {
|
||||
throw error
|
||||
}
|
||||
getRoomVisibilityCallsCount += 1
|
||||
if let getRoomVisibilityClosure = getRoomVisibilityClosure {
|
||||
return try await getRoomVisibilityClosure()
|
||||
} else {
|
||||
return getRoomVisibilityReturnValue
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - hasActiveRoomCall
|
||||
|
||||
var hasActiveRoomCallUnderlyingCallsCount = 0
|
||||
@@ -13387,6 +13450,81 @@ open class RoomSDKMock: MatrixRustSDK.Room {
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - publishRoomAliasInRoomDirectory
|
||||
|
||||
open var publishRoomAliasInRoomDirectoryAliasThrowableError: Error?
|
||||
var publishRoomAliasInRoomDirectoryAliasUnderlyingCallsCount = 0
|
||||
open var publishRoomAliasInRoomDirectoryAliasCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return publishRoomAliasInRoomDirectoryAliasUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = publishRoomAliasInRoomDirectoryAliasUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
publishRoomAliasInRoomDirectoryAliasUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
publishRoomAliasInRoomDirectoryAliasUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var publishRoomAliasInRoomDirectoryAliasCalled: Bool {
|
||||
return publishRoomAliasInRoomDirectoryAliasCallsCount > 0
|
||||
}
|
||||
open var publishRoomAliasInRoomDirectoryAliasReceivedAlias: String?
|
||||
open var publishRoomAliasInRoomDirectoryAliasReceivedInvocations: [String] = []
|
||||
|
||||
var publishRoomAliasInRoomDirectoryAliasUnderlyingReturnValue: Bool!
|
||||
open var publishRoomAliasInRoomDirectoryAliasReturnValue: Bool! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return publishRoomAliasInRoomDirectoryAliasUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Bool? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = publishRoomAliasInRoomDirectoryAliasUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
publishRoomAliasInRoomDirectoryAliasUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
publishRoomAliasInRoomDirectoryAliasUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var publishRoomAliasInRoomDirectoryAliasClosure: ((String) async throws -> Bool)?
|
||||
|
||||
open override func publishRoomAliasInRoomDirectory(alias: String) async throws -> Bool {
|
||||
if let error = publishRoomAliasInRoomDirectoryAliasThrowableError {
|
||||
throw error
|
||||
}
|
||||
publishRoomAliasInRoomDirectoryAliasCallsCount += 1
|
||||
publishRoomAliasInRoomDirectoryAliasReceivedAlias = alias
|
||||
DispatchQueue.main.async {
|
||||
self.publishRoomAliasInRoomDirectoryAliasReceivedInvocations.append(alias)
|
||||
}
|
||||
if let publishRoomAliasInRoomDirectoryAliasClosure = publishRoomAliasInRoomDirectoryAliasClosure {
|
||||
return try await publishRoomAliasInRoomDirectoryAliasClosure(alias)
|
||||
} else {
|
||||
return publishRoomAliasInRoomDirectoryAliasReturnValue
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - rawName
|
||||
|
||||
var rawNameUnderlyingCallsCount = 0
|
||||
@@ -13538,6 +13676,81 @@ open class RoomSDKMock: MatrixRustSDK.Room {
|
||||
try await removeAvatarClosure?()
|
||||
}
|
||||
|
||||
//MARK: - removeRoomAliasFromRoomDirectory
|
||||
|
||||
open var removeRoomAliasFromRoomDirectoryAliasThrowableError: Error?
|
||||
var removeRoomAliasFromRoomDirectoryAliasUnderlyingCallsCount = 0
|
||||
open var removeRoomAliasFromRoomDirectoryAliasCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return removeRoomAliasFromRoomDirectoryAliasUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = removeRoomAliasFromRoomDirectoryAliasUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
removeRoomAliasFromRoomDirectoryAliasUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
removeRoomAliasFromRoomDirectoryAliasUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var removeRoomAliasFromRoomDirectoryAliasCalled: Bool {
|
||||
return removeRoomAliasFromRoomDirectoryAliasCallsCount > 0
|
||||
}
|
||||
open var removeRoomAliasFromRoomDirectoryAliasReceivedAlias: String?
|
||||
open var removeRoomAliasFromRoomDirectoryAliasReceivedInvocations: [String] = []
|
||||
|
||||
var removeRoomAliasFromRoomDirectoryAliasUnderlyingReturnValue: Bool!
|
||||
open var removeRoomAliasFromRoomDirectoryAliasReturnValue: Bool! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return removeRoomAliasFromRoomDirectoryAliasUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Bool? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = removeRoomAliasFromRoomDirectoryAliasUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
removeRoomAliasFromRoomDirectoryAliasUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
removeRoomAliasFromRoomDirectoryAliasUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var removeRoomAliasFromRoomDirectoryAliasClosure: ((String) async throws -> Bool)?
|
||||
|
||||
open override func removeRoomAliasFromRoomDirectory(alias: String) async throws -> Bool {
|
||||
if let error = removeRoomAliasFromRoomDirectoryAliasThrowableError {
|
||||
throw error
|
||||
}
|
||||
removeRoomAliasFromRoomDirectoryAliasCallsCount += 1
|
||||
removeRoomAliasFromRoomDirectoryAliasReceivedAlias = alias
|
||||
DispatchQueue.main.async {
|
||||
self.removeRoomAliasFromRoomDirectoryAliasReceivedInvocations.append(alias)
|
||||
}
|
||||
if let removeRoomAliasFromRoomDirectoryAliasClosure = removeRoomAliasFromRoomDirectoryAliasClosure {
|
||||
return try await removeRoomAliasFromRoomDirectoryAliasClosure(alias)
|
||||
} else {
|
||||
return removeRoomAliasFromRoomDirectoryAliasReturnValue
|
||||
}
|
||||
}
|
||||
|
||||
//MARK: - reportContent
|
||||
|
||||
open var reportContentEventIdScoreReasonThrowableError: Error?
|
||||
@@ -14863,6 +15076,144 @@ open class RoomSDKMock: MatrixRustSDK.Room {
|
||||
try await unbanUserUserIdReasonClosure?(userId, reason)
|
||||
}
|
||||
|
||||
//MARK: - updateCanonicalAlias
|
||||
|
||||
open var updateCanonicalAliasAliasAltAliasesThrowableError: Error?
|
||||
var updateCanonicalAliasAliasAltAliasesUnderlyingCallsCount = 0
|
||||
open var updateCanonicalAliasAliasAltAliasesCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateCanonicalAliasAliasAltAliasesUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateCanonicalAliasAliasAltAliasesUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateCanonicalAliasAliasAltAliasesUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateCanonicalAliasAliasAltAliasesUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var updateCanonicalAliasAliasAltAliasesCalled: Bool {
|
||||
return updateCanonicalAliasAliasAltAliasesCallsCount > 0
|
||||
}
|
||||
open var updateCanonicalAliasAliasAltAliasesReceivedArguments: (alias: String?, altAliases: [String])?
|
||||
open var updateCanonicalAliasAliasAltAliasesReceivedInvocations: [(alias: String?, altAliases: [String])] = []
|
||||
open var updateCanonicalAliasAliasAltAliasesClosure: ((String?, [String]) async throws -> Void)?
|
||||
|
||||
open override func updateCanonicalAlias(alias: String?, altAliases: [String]) async throws {
|
||||
if let error = updateCanonicalAliasAliasAltAliasesThrowableError {
|
||||
throw error
|
||||
}
|
||||
updateCanonicalAliasAliasAltAliasesCallsCount += 1
|
||||
updateCanonicalAliasAliasAltAliasesReceivedArguments = (alias: alias, altAliases: altAliases)
|
||||
DispatchQueue.main.async {
|
||||
self.updateCanonicalAliasAliasAltAliasesReceivedInvocations.append((alias: alias, altAliases: altAliases))
|
||||
}
|
||||
try await updateCanonicalAliasAliasAltAliasesClosure?(alias, altAliases)
|
||||
}
|
||||
|
||||
//MARK: - updateHistoryVisibility
|
||||
|
||||
open var updateHistoryVisibilityVisibilityThrowableError: Error?
|
||||
var updateHistoryVisibilityVisibilityUnderlyingCallsCount = 0
|
||||
open var updateHistoryVisibilityVisibilityCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateHistoryVisibilityVisibilityUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateHistoryVisibilityVisibilityUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateHistoryVisibilityVisibilityUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateHistoryVisibilityVisibilityUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var updateHistoryVisibilityVisibilityCalled: Bool {
|
||||
return updateHistoryVisibilityVisibilityCallsCount > 0
|
||||
}
|
||||
open var updateHistoryVisibilityVisibilityReceivedVisibility: RoomHistoryVisibility?
|
||||
open var updateHistoryVisibilityVisibilityReceivedInvocations: [RoomHistoryVisibility] = []
|
||||
open var updateHistoryVisibilityVisibilityClosure: ((RoomHistoryVisibility) async throws -> Void)?
|
||||
|
||||
open override func updateHistoryVisibility(visibility: RoomHistoryVisibility) async throws {
|
||||
if let error = updateHistoryVisibilityVisibilityThrowableError {
|
||||
throw error
|
||||
}
|
||||
updateHistoryVisibilityVisibilityCallsCount += 1
|
||||
updateHistoryVisibilityVisibilityReceivedVisibility = visibility
|
||||
DispatchQueue.main.async {
|
||||
self.updateHistoryVisibilityVisibilityReceivedInvocations.append(visibility)
|
||||
}
|
||||
try await updateHistoryVisibilityVisibilityClosure?(visibility)
|
||||
}
|
||||
|
||||
//MARK: - updateJoinRules
|
||||
|
||||
open var updateJoinRulesNewRuleThrowableError: Error?
|
||||
var updateJoinRulesNewRuleUnderlyingCallsCount = 0
|
||||
open var updateJoinRulesNewRuleCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateJoinRulesNewRuleUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateJoinRulesNewRuleUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateJoinRulesNewRuleUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateJoinRulesNewRuleUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var updateJoinRulesNewRuleCalled: Bool {
|
||||
return updateJoinRulesNewRuleCallsCount > 0
|
||||
}
|
||||
open var updateJoinRulesNewRuleReceivedNewRule: JoinRule?
|
||||
open var updateJoinRulesNewRuleReceivedInvocations: [JoinRule] = []
|
||||
open var updateJoinRulesNewRuleClosure: ((JoinRule) async throws -> Void)?
|
||||
|
||||
open override func updateJoinRules(newRule: JoinRule) async throws {
|
||||
if let error = updateJoinRulesNewRuleThrowableError {
|
||||
throw error
|
||||
}
|
||||
updateJoinRulesNewRuleCallsCount += 1
|
||||
updateJoinRulesNewRuleReceivedNewRule = newRule
|
||||
DispatchQueue.main.async {
|
||||
self.updateJoinRulesNewRuleReceivedInvocations.append(newRule)
|
||||
}
|
||||
try await updateJoinRulesNewRuleClosure?(newRule)
|
||||
}
|
||||
|
||||
//MARK: - updatePowerLevelsForUsers
|
||||
|
||||
open var updatePowerLevelsForUsersUpdatesThrowableError: Error?
|
||||
@@ -14909,6 +15260,52 @@ open class RoomSDKMock: MatrixRustSDK.Room {
|
||||
try await updatePowerLevelsForUsersUpdatesClosure?(updates)
|
||||
}
|
||||
|
||||
//MARK: - updateRoomVisibility
|
||||
|
||||
open var updateRoomVisibilityVisibilityThrowableError: Error?
|
||||
var updateRoomVisibilityVisibilityUnderlyingCallsCount = 0
|
||||
open var updateRoomVisibilityVisibilityCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return updateRoomVisibilityVisibilityUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = updateRoomVisibilityVisibilityUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
updateRoomVisibilityVisibilityUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
updateRoomVisibilityVisibilityUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var updateRoomVisibilityVisibilityCalled: Bool {
|
||||
return updateRoomVisibilityVisibilityCallsCount > 0
|
||||
}
|
||||
open var updateRoomVisibilityVisibilityReceivedVisibility: RoomVisibility?
|
||||
open var updateRoomVisibilityVisibilityReceivedInvocations: [RoomVisibility] = []
|
||||
open var updateRoomVisibilityVisibilityClosure: ((RoomVisibility) async throws -> Void)?
|
||||
|
||||
open override func updateRoomVisibility(visibility: RoomVisibility) async throws {
|
||||
if let error = updateRoomVisibilityVisibilityThrowableError {
|
||||
throw error
|
||||
}
|
||||
updateRoomVisibilityVisibilityCallsCount += 1
|
||||
updateRoomVisibilityVisibilityReceivedVisibility = visibility
|
||||
DispatchQueue.main.async {
|
||||
self.updateRoomVisibilityVisibilityReceivedInvocations.append(visibility)
|
||||
}
|
||||
try await updateRoomVisibilityVisibilityClosure?(visibility)
|
||||
}
|
||||
|
||||
//MARK: - uploadAvatar
|
||||
|
||||
open var uploadAvatarMimeTypeDataMediaInfoThrowableError: Error?
|
||||
@@ -22276,6 +22673,46 @@ open class UserIdentitySDKMock: MatrixRustSDK.UserIdentity {
|
||||
pinCallsCount += 1
|
||||
try await pinClosure?()
|
||||
}
|
||||
|
||||
//MARK: - withdrawVerification
|
||||
|
||||
open var withdrawVerificationThrowableError: Error?
|
||||
var withdrawVerificationUnderlyingCallsCount = 0
|
||||
open var withdrawVerificationCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return withdrawVerificationUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = withdrawVerificationUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
withdrawVerificationUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
withdrawVerificationUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
open var withdrawVerificationCalled: Bool {
|
||||
return withdrawVerificationCallsCount > 0
|
||||
}
|
||||
open var withdrawVerificationClosure: (() async throws -> Void)?
|
||||
|
||||
open override func withdrawVerification() async throws {
|
||||
if let error = withdrawVerificationThrowableError {
|
||||
throw error
|
||||
}
|
||||
withdrawVerificationCallsCount += 1
|
||||
try await withdrawVerificationClosure?()
|
||||
}
|
||||
}
|
||||
open class WidgetDriverSDKMock: MatrixRustSDK.WidgetDriver {
|
||||
init() {
|
||||
|
||||
@@ -60,7 +60,8 @@ extension RoomInfo {
|
||||
numUnreadNotifications: 0,
|
||||
numUnreadMentions: 0,
|
||||
pinnedEventIds: [],
|
||||
joinRule: .invite)
|
||||
joinRule: .invite,
|
||||
historyVisibility: .shared)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ struct JoinedRoomProxyMockConfiguration {
|
||||
|
||||
var shouldUseAutoUpdatingTimeline = false
|
||||
var joinRule: JoinRule?
|
||||
var isVisibleInPublicDirectory = false
|
||||
}
|
||||
|
||||
extension JoinedRoomProxyMock {
|
||||
@@ -127,6 +128,7 @@ extension JoinedRoomProxyMock {
|
||||
loadDraftReturnValue = .success(nil)
|
||||
clearDraftReturnValue = .success(())
|
||||
sendTypingNotificationIsTypingReturnValue = .success(())
|
||||
isVisibleInRoomDirectoryReturnValue = .success(configuration.isVisibleInPublicDirectory)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +172,7 @@ extension RoomInfo {
|
||||
numUnreadNotifications: 0,
|
||||
numUnreadMentions: 0,
|
||||
pinnedEventIds: Array(configuration.pinnedEventIDs),
|
||||
joinRule: configuration.joinRule)
|
||||
joinRule: configuration.joinRule,
|
||||
historyVisibility: .shared)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ extension RoomInfo {
|
||||
numUnreadNotifications: 0,
|
||||
numUnreadMentions: 0,
|
||||
pinnedEventIds: [],
|
||||
joinRule: .knock)
|
||||
joinRule: .knock,
|
||||
historyVisibility: .shared)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,3 +97,13 @@ extension String {
|
||||
trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
static func makeCanonicalAlias(aliasLocalPart: Self?, serverName: Self?) -> Self? {
|
||||
guard let aliasLocalPart, !aliasLocalPart.isEmpty,
|
||||
let serverName, !serverName.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
return "#\(aliasLocalPart):\(serverName)"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// Copyright 2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct EditRoomAddressListRow: View {
|
||||
@Binding var aliasLocalPart: String
|
||||
var serverName: String
|
||||
var shouldDisplayError: Bool
|
||||
|
||||
var body: some View {
|
||||
ListRow(kind: .custom {
|
||||
HStack(spacing: 0) {
|
||||
Text("#")
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
TextField("", text: $aliasLocalPart)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
.textContentType(.URL)
|
||||
.tint(.compound.iconAccentTertiary)
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textPrimary)
|
||||
.padding(.horizontal, 8)
|
||||
Text(":\(serverName)")
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
}
|
||||
.padding(ListRowPadding.textFieldInsets)
|
||||
.environment(\.layoutDirection, .leftToRight)
|
||||
.errorBackground(shouldDisplayError)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private extension View {
|
||||
func errorBackground(_ shouldDisplay: Bool) -> some View {
|
||||
listRowBackground(shouldDisplay ? AnyView(RoundedRectangle(cornerRadius: 10)
|
||||
.inset(by: 1)
|
||||
.fill(.compound.bgCriticalSubtleHovered)
|
||||
.stroke(Color.compound.borderCriticalPrimary)) : AnyView(Color.compound.bgCanvasDefaultLevel1))
|
||||
}
|
||||
}
|
||||
|
||||
enum EditRoomAddressErrorState {
|
||||
case alreadyExists
|
||||
case invalidSymbols
|
||||
}
|
||||
|
||||
extension Set<EditRoomAddressErrorState> {
|
||||
var errorDescription: String? {
|
||||
if contains(.alreadyExists) {
|
||||
return L10n.errorRoomAddressAlreadyExists
|
||||
} else if contains(.invalidSymbols) {
|
||||
return L10n.errorRoomAddressInvalidSymbols
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -72,3 +72,14 @@ enum CreateRoomAliasErrorState {
|
||||
case alreadyExists
|
||||
case invalidSymbols
|
||||
}
|
||||
|
||||
extension Set<CreateRoomAliasErrorState> {
|
||||
var errorDescription: String? {
|
||||
if contains(.alreadyExists) {
|
||||
return L10n.errorRoomAddressAlreadyExists
|
||||
} else if contains(.invalidSymbols) {
|
||||
return L10n.errorRoomAddressInvalidSymbols
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +154,8 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
||||
|
||||
guard state.isKnockingFeatureEnabled,
|
||||
!state.bindings.isRoomPrivate,
|
||||
let canonicalAlias = canonicalAlias(aliasLocalPart: aliasLocalPart) else {
|
||||
let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: aliasLocalPart,
|
||||
serverName: state.serverName) else {
|
||||
// While is empty or private room we don't change or display the error
|
||||
return
|
||||
}
|
||||
@@ -209,8 +210,9 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
||||
|
||||
// Better to double check the errors also when trying to create the room
|
||||
if state.isKnockingFeatureEnabled, !createRoomParameters.isRoomPrivate {
|
||||
guard let canonicalAlias = canonicalAlias(aliasLocalPart: createRoomParameters.aliasLocalPart),
|
||||
isRoomAliasFormatValid(alias: canonicalAlias) else {
|
||||
guard let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: createRoomParameters.aliasLocalPart,
|
||||
serverName: state.serverName),
|
||||
isRoomAliasFormatValid(alias: canonicalAlias) else {
|
||||
state.aliasErrors = [.invalidSymbols]
|
||||
return
|
||||
}
|
||||
@@ -271,14 +273,6 @@ class CreateRoomViewModel: CreateRoomViewModelType, CreateRoomViewModelProtocol
|
||||
}
|
||||
}
|
||||
|
||||
func canonicalAlias(aliasLocalPart: String?) -> String? {
|
||||
guard let aliasLocalPart,
|
||||
!aliasLocalPart.isEmpty else {
|
||||
return nil
|
||||
}
|
||||
return "#\(aliasLocalPart):\(state.serverName)"
|
||||
}
|
||||
|
||||
// MARK: Loading indicator
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(CreateRoomViewModel.self)-Loading"
|
||||
|
||||
@@ -190,35 +190,17 @@ struct CreateRoomScreen: View {
|
||||
|
||||
private var roomAliasSection: some View {
|
||||
Section {
|
||||
ListRow(kind: .custom {
|
||||
HStack(spacing: 0) {
|
||||
Text("#")
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
TextField("", text: aliasBinding)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
.textContentType(.URL)
|
||||
.focused($focus, equals: .alias)
|
||||
.tint(.compound.iconAccentTertiary)
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textPrimary)
|
||||
.padding(.horizontal, 8)
|
||||
Text(":\(context.viewState.serverName)")
|
||||
.font(.compound.bodyLG)
|
||||
.foregroundStyle(.compound.textSecondary)
|
||||
}
|
||||
.padding(ListRowPadding.textFieldInsets)
|
||||
.environment(\.layoutDirection, .leftToRight)
|
||||
.errorBackground(!context.viewState.aliasErrors.isEmpty)
|
||||
})
|
||||
.id(Focus.alias)
|
||||
EditRoomAddressListRow(aliasLocalPart: aliasBinding,
|
||||
serverName: context.viewState.serverName,
|
||||
shouldDisplayError: context.viewState.aliasErrors.errorDescription != nil)
|
||||
.focused($focus, equals: .alias)
|
||||
.id(Focus.alias)
|
||||
} header: {
|
||||
Text(L10n.screenCreateRoomRoomAddressSectionTitle)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if let errorDescription = context.viewState.aliasErrorDescription {
|
||||
if let errorDescription = context.viewState.aliasErrors.errorDescription {
|
||||
Label(errorDescription, icon: \.error, iconSize: .xSmall, relativeTo: .compound.bodySM)
|
||||
.foregroundStyle(.compound.textCriticalPrimary)
|
||||
.font(.compound.bodySM)
|
||||
@@ -241,15 +223,6 @@ struct CreateRoomScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private extension View {
|
||||
func errorBackground(_ shouldDisplay: Bool) -> some View {
|
||||
listRowBackground(shouldDisplay ? AnyView(RoundedRectangle(cornerRadius: 10)
|
||||
.inset(by: 1)
|
||||
.fill(.compound.bgCriticalSubtleHovered)
|
||||
.stroke(Color.compound.borderCriticalPrimary)) : AnyView(Color.compound.bgCanvasDefaultLevel1))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct CreateRoom_Previews: PreviewProvider, TestablePreview {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
// periphery:ignore:all - this is just a editRoomAddress remove this comment once generating the final file
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
struct EditRoomAddressScreenCoordinatorParameters {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum EditRoomAddressScreenCoordinatorAction {
|
||||
case dismiss
|
||||
}
|
||||
|
||||
final class EditRoomAddressScreenCoordinator: CoordinatorProtocol {
|
||||
private let viewModel: EditRoomAddressScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private let actionsSubject: PassthroughSubject<EditRoomAddressScreenCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<EditRoomAddressScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(parameters: EditRoomAddressScreenCoordinatorParameters) {
|
||||
viewModel = EditRoomAddressScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
clientProxy: parameters.clientProxy,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
viewModel.actionsPublisher.sink { [weak self] action in
|
||||
MXLog.info("Coordinator: received view model action: \(action)")
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .dismiss:
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(EditRoomAddressScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum EditRoomAddressScreenViewModelAction {
|
||||
case dismiss
|
||||
}
|
||||
|
||||
struct EditRoomAddressScreenViewState: BindableState {
|
||||
let serverName: String
|
||||
var currentAliasLocalPart: String?
|
||||
var aliasErrors: Set<EditRoomAddressErrorState> = []
|
||||
|
||||
var canSave: Bool {
|
||||
currentAliasLocalPart != bindings.desiredAliasLocalPart &&
|
||||
aliasErrors.isEmpty &&
|
||||
!bindings.desiredAliasLocalPart.isEmpty
|
||||
}
|
||||
|
||||
var bindings: EditRoomAddressScreenViewStateBindings
|
||||
}
|
||||
|
||||
struct EditRoomAddressScreenViewStateBindings {
|
||||
var desiredAliasLocalPart: String
|
||||
}
|
||||
|
||||
enum EditRoomAddressScreenViewAction {
|
||||
case save
|
||||
case cancel
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
typealias EditRoomAddressScreenViewModelType = StateStoreViewModel<EditRoomAddressScreenViewState, EditRoomAddressScreenViewAction>
|
||||
|
||||
class EditRoomAddressScreenViewModel: EditRoomAddressScreenViewModelType, EditRoomAddressScreenViewModelProtocol {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<EditRoomAddressScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<EditRoomAddressScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
@CancellableTask private var checkAliasAvailabilityTask: Task<Void, Never>?
|
||||
|
||||
init(initialViewState: EditRoomAddressScreenViewState? = nil,
|
||||
roomProxy: JoinedRoomProxyProtocol,
|
||||
clientProxy: ClientProxyProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.roomProxy = roomProxy
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
|
||||
var aliasLocalPart = ""
|
||||
if let canonicalAlias = roomProxy.infoPublisher.value.canonicalAlias {
|
||||
aliasLocalPart = canonicalAlias.dropFirst().split(separator: ":").first.flatMap(String.init) ?? ""
|
||||
} else if let displayName = roomProxy.infoPublisher.value.displayName {
|
||||
aliasLocalPart = roomAliasNameFromRoomDisplayName(roomName: displayName)
|
||||
}
|
||||
|
||||
if let initialViewState {
|
||||
super.init(initialViewState: initialViewState)
|
||||
} else {
|
||||
super.init(initialViewState: EditRoomAddressScreenViewState(serverName: clientProxy.userIDServerName ?? "",
|
||||
currentAliasLocalPart: aliasLocalPart,
|
||||
bindings: .init(desiredAliasLocalPart: aliasLocalPart)))
|
||||
}
|
||||
setupSubscriptions()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: EditRoomAddressScreenViewAction) {
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .save:
|
||||
Task { await save() }
|
||||
case .cancel:
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
}
|
||||
|
||||
private func setupSubscriptions() {
|
||||
context.$viewState
|
||||
.map(\.bindings.desiredAliasLocalPart)
|
||||
.removeDuplicates()
|
||||
.debounce(for: 0.5, scheduler: DispatchQueue.main)
|
||||
.sink { [weak self] aliasLocalPart in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
guard let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: aliasLocalPart,
|
||||
serverName: state.serverName) else {
|
||||
// While is empty don't display the errors, since the save button is already disabled
|
||||
state.aliasErrors.removeAll()
|
||||
return
|
||||
}
|
||||
|
||||
if !isRoomAliasFormatValid(alias: canonicalAlias) {
|
||||
state.aliasErrors.insert(.invalidSymbols)
|
||||
// If the alias is invalid we don't need to check for availability
|
||||
state.aliasErrors.remove(.alreadyExists)
|
||||
checkAliasAvailabilityTask = nil
|
||||
return
|
||||
}
|
||||
|
||||
state.aliasErrors.remove(.invalidSymbols)
|
||||
|
||||
guard aliasLocalPart != state.currentAliasLocalPart else {
|
||||
// Doesn't make sense to check the availability and display an error if the alias didn't change, the save button should also be disabled
|
||||
state.aliasErrors.remove(.alreadyExists)
|
||||
checkAliasAvailabilityTask = nil
|
||||
return
|
||||
}
|
||||
|
||||
checkAliasAvailabilityTask = Task { [weak self] in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
|
||||
if case .success(false) = await self.clientProxy.isAliasAvailable(canonicalAlias) {
|
||||
guard !Task.isCancelled else { return }
|
||||
state.aliasErrors.insert(.alreadyExists)
|
||||
} else {
|
||||
guard !Task.isCancelled else { return }
|
||||
state.aliasErrors.remove(.alreadyExists)
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func save() async {
|
||||
showLoadingIndicator()
|
||||
|
||||
defer {
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
|
||||
guard let canonicalAlias = String.makeCanonicalAlias(aliasLocalPart: state.bindings.desiredAliasLocalPart, serverName: state.serverName),
|
||||
isRoomAliasFormatValid(alias: canonicalAlias) else {
|
||||
state.aliasErrors = [.invalidSymbols]
|
||||
return
|
||||
}
|
||||
|
||||
switch await clientProxy.isAliasAvailable(canonicalAlias) {
|
||||
case .success(true):
|
||||
break
|
||||
case .success(false):
|
||||
state.aliasErrors = [.alreadyExists]
|
||||
return
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
let oldAlias = roomProxy.infoPublisher.value.canonicalAlias
|
||||
|
||||
// First publish the new alias
|
||||
if case .failure = await roomProxy.publishRoomAliasInRoomDirectory(canonicalAlias) {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
// Then set it as the main alias
|
||||
if case .failure = await roomProxy.updateCanonicalAlias(canonicalAlias, altAliases: []) {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
// And finally delete the old one
|
||||
if let oldAlias, case .failure = await roomProxy.removeRoomAliasFromRoomDirectory(oldAlias) {
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
return
|
||||
}
|
||||
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(EditRoomAddressScreenViewModel.self)-Loading"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
|
||||
type: .modal,
|
||||
title: L10n.commonLoading,
|
||||
persistent: true))
|
||||
}
|
||||
|
||||
private func hideLoadingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Combine
|
||||
|
||||
@MainActor
|
||||
protocol EditRoomAddressScreenViewModelProtocol {
|
||||
var actionsPublisher: AnyPublisher<EditRoomAddressScreenViewModelAction, Never> { get }
|
||||
var context: EditRoomAddressScreenViewModelType.Context { get }
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
//
|
||||
// Copyright 2022-2024 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct EditRoomAddressScreen: View {
|
||||
@ObservedObject var context: EditRoomAddressScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
Section {
|
||||
EditRoomAddressListRow(aliasLocalPart: $context.desiredAliasLocalPart,
|
||||
serverName: context.viewState.serverName, shouldDisplayError: context.viewState.aliasErrors.errorDescription != nil)
|
||||
.onChange(of: context.desiredAliasLocalPart) { _, newAliasLocalPart in
|
||||
context.desiredAliasLocalPart = newAliasLocalPart.lowercased()
|
||||
}
|
||||
.onSubmit {
|
||||
if context.viewState.canSave {
|
||||
context.send(viewAction: .save)
|
||||
}
|
||||
}
|
||||
} footer: {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
if let errorDescription = context.viewState.aliasErrors.errorDescription {
|
||||
Label(errorDescription, icon: \.error, iconSize: .xSmall, relativeTo: .compound.bodySM)
|
||||
.foregroundStyle(.compound.textCriticalPrimary)
|
||||
.font(.compound.bodySM)
|
||||
}
|
||||
Text(L10n.screenCreateRoomRoomAddressSectionFooter)
|
||||
.compoundListSectionFooter()
|
||||
.font(.compound.bodySM)
|
||||
}
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(L10n.screenEditRoomAddressTitle)
|
||||
.toolbar { toolbar }
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(L10n.actionSave) {
|
||||
context.send(viewAction: .save)
|
||||
}
|
||||
.disabled(!context.viewState.canSave)
|
||||
}
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(L10n.actionCancel) {
|
||||
context.send(viewAction: .cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct EditRoomAddressScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let noAliasviewModel = EditRoomAddressScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Room Name")),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let aliasviewModel = EditRoomAddressScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Room Name", canonicalAlias: "#room-alias:matrix.org")),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let invalidSymbolsViewModel = EditRoomAddressScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(name: "Room Name", canonicalAlias: "#room#-alias:matrix.org")),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let alreadyExistingViewModel = {
|
||||
let clientProxy = ClientProxyMock(.init(userIDServerName: "matrix.org"))
|
||||
clientProxy.isAliasAvailableReturnValue = .success(false)
|
||||
return EditRoomAddressScreenViewModel(initialViewState: .init(serverName: "matrix.org",
|
||||
bindings: .init(desiredAliasLocalPart: "whatever")),
|
||||
roomProxy: JoinedRoomProxyMock(.init(name: "Room Name")),
|
||||
clientProxy: clientProxy,
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
}()
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: noAliasviewModel.context)
|
||||
}
|
||||
.previewDisplayName("No alias")
|
||||
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: aliasviewModel.context)
|
||||
}
|
||||
.previewDisplayName("With alias")
|
||||
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: invalidSymbolsViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: invalidSymbolsViewModel.context.$viewState.map { state in
|
||||
!state.aliasErrors.isEmpty
|
||||
})
|
||||
.previewDisplayName("Invalid symbols")
|
||||
|
||||
NavigationStack {
|
||||
EditRoomAddressScreen(context: alreadyExistingViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: alreadyExistingViewModel.context.$viewState.map { state in
|
||||
!state.aliasErrors.isEmpty
|
||||
})
|
||||
.previewDisplayName("Already existing")
|
||||
}
|
||||
}
|
||||
+8
-9
@@ -10,16 +10,15 @@ import SwiftUI
|
||||
|
||||
struct SecurityAndPrivacyScreenCoordinatorParameters {
|
||||
let roomProxy: JoinedRoomProxyProtocol
|
||||
let clientProxy: ClientProxyProtocol
|
||||
let userIndicatorController: UserIndicatorControllerProtocol
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyScreenCoordinatorAction {
|
||||
case done
|
||||
|
||||
// Consider adding CustomStringConvertible conformance if the actions contain PII
|
||||
case displayEditAddressScreen
|
||||
}
|
||||
|
||||
final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
private let parameters: SecurityAndPrivacyScreenCoordinatorParameters
|
||||
private let viewModel: SecurityAndPrivacyScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
@@ -30,9 +29,9 @@ final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
}
|
||||
|
||||
init(parameters: SecurityAndPrivacyScreenCoordinatorParameters) {
|
||||
self.parameters = parameters
|
||||
|
||||
viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: parameters.roomProxy)
|
||||
viewModel = SecurityAndPrivacyScreenViewModel(roomProxy: parameters.roomProxy,
|
||||
clientProxy: parameters.clientProxy,
|
||||
userIndicatorController: parameters.userIndicatorController)
|
||||
}
|
||||
|
||||
func start() {
|
||||
@@ -41,8 +40,8 @@ final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .done:
|
||||
actionsSubject.send(.done)
|
||||
case .displayEditAddressScreen:
|
||||
actionsSubject.send(.displayEditAddressScreen)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
+49
-7
@@ -8,21 +8,44 @@
|
||||
import Foundation
|
||||
|
||||
enum SecurityAndPrivacyScreenViewModelAction {
|
||||
case done
|
||||
case displayEditAddressScreen
|
||||
}
|
||||
|
||||
struct SecurityAndPrivacyScreenViewState: BindableState {
|
||||
var bindings: SecurityAndPrivacyScreenViewStateBindings
|
||||
|
||||
let serverName: String
|
||||
var currentSettings: SecurityAndPrivacySettings
|
||||
var bindings: SecurityAndPrivacyScreenViewStateBindings
|
||||
var canonicalAlias: String?
|
||||
|
||||
var hasChanges: Bool {
|
||||
private var hasChanges: Bool {
|
||||
currentSettings != bindings.desiredSettings
|
||||
}
|
||||
|
||||
init(accessType: SecurityAndPrivacyRoomAccessType,
|
||||
isEncryptionEnabled: Bool) {
|
||||
let settings = SecurityAndPrivacySettings(accessType: accessType, isEncryptionEnabled: isEncryptionEnabled)
|
||||
var isSaveDisabled: Bool {
|
||||
!hasChanges ||
|
||||
(currentSettings.isVisibileInRoomDirectory == nil &&
|
||||
bindings.desiredSettings.accessType != .inviteOnly &&
|
||||
canonicalAlias != nil)
|
||||
}
|
||||
|
||||
var availableVisibilityOptions: [SecurityAndPrivacyHistoryVisibility] {
|
||||
var options = [SecurityAndPrivacyHistoryVisibility.sinceSelection]
|
||||
if !bindings.desiredSettings.isEncryptionEnabled, bindings.desiredSettings.accessType == .anyone {
|
||||
options.append(.anyone)
|
||||
} else {
|
||||
options.append(.sinceInvite)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
init(serverName: String,
|
||||
accessType: SecurityAndPrivacyRoomAccessType,
|
||||
isEncryptionEnabled: Bool,
|
||||
historyVisibility: SecurityAndPrivacyHistoryVisibility) {
|
||||
self.serverName = serverName
|
||||
let settings = SecurityAndPrivacySettings(accessType: accessType,
|
||||
isEncryptionEnabled: isEncryptionEnabled,
|
||||
historyVisibility: historyVisibility)
|
||||
currentSettings = settings
|
||||
bindings = SecurityAndPrivacyScreenViewStateBindings(desiredSettings: settings)
|
||||
}
|
||||
@@ -36,12 +59,15 @@ struct SecurityAndPrivacyScreenViewStateBindings {
|
||||
struct SecurityAndPrivacySettings: Equatable {
|
||||
var accessType: SecurityAndPrivacyRoomAccessType
|
||||
var isEncryptionEnabled: Bool
|
||||
var historyVisibility: SecurityAndPrivacyHistoryVisibility
|
||||
var isVisibileInRoomDirectory: Bool?
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyRoomAccessType {
|
||||
case inviteOnly
|
||||
case askToJoin
|
||||
case anyone
|
||||
case spaceUsers
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyAlertType {
|
||||
@@ -51,4 +77,20 @@ enum SecurityAndPrivacyAlertType {
|
||||
enum SecurityAndPrivacyScreenViewAction {
|
||||
case save
|
||||
case tryUpdatingEncryption(Bool)
|
||||
case editAddress
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyHistoryVisibility {
|
||||
case sinceSelection
|
||||
case sinceInvite
|
||||
case anyone
|
||||
|
||||
var fallbackOption: Self {
|
||||
switch self {
|
||||
case .sinceInvite, .sinceSelection:
|
||||
return .sinceSelection
|
||||
case .anyone:
|
||||
return .sinceInvite
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+176
-12
@@ -6,22 +6,34 @@
|
||||
//
|
||||
|
||||
import Combine
|
||||
import MatrixRustSDK
|
||||
import SwiftUI
|
||||
|
||||
typealias SecurityAndPrivacyScreenViewModelType = StateStoreViewModel<SecurityAndPrivacyScreenViewState, SecurityAndPrivacyScreenViewAction>
|
||||
|
||||
class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType, SecurityAndPrivacyScreenViewModelProtocol {
|
||||
private let roomProxy: JoinedRoomProxyProtocol
|
||||
private let clientProxy: ClientProxyProtocol
|
||||
private let userIndicatorController: UserIndicatorControllerProtocol
|
||||
|
||||
private let actionsSubject: PassthroughSubject<SecurityAndPrivacyScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<SecurityAndPrivacyScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(roomProxy: JoinedRoomProxyProtocol) {
|
||||
|
||||
init(roomProxy: JoinedRoomProxyProtocol,
|
||||
clientProxy: ClientProxyProtocol,
|
||||
userIndicatorController: UserIndicatorControllerProtocol) {
|
||||
self.roomProxy = roomProxy
|
||||
super.init(initialViewState: SecurityAndPrivacyScreenViewState(accessType: roomProxy.infoPublisher.value.roomAccessType,
|
||||
isEncryptionEnabled: roomProxy.isEncrypted))
|
||||
self.clientProxy = clientProxy
|
||||
self.userIndicatorController = userIndicatorController
|
||||
super.init(initialViewState: SecurityAndPrivacyScreenViewState(serverName: clientProxy.userIDServerName ?? "",
|
||||
accessType: roomProxy.infoPublisher.value.joinRule.toSecurityAndPrivacyRoomAccessType,
|
||||
isEncryptionEnabled: roomProxy.isEncrypted,
|
||||
historyVisibility: roomProxy.infoPublisher.value.historyVisibility.toSecurityAndPrivacyHistoryVisibility))
|
||||
|
||||
setupRoomDirectoryVisibility()
|
||||
setupSubscriptions()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
@@ -31,32 +43,184 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
|
||||
switch viewAction {
|
||||
case .save:
|
||||
actionsSubject.send(.done)
|
||||
Task {
|
||||
await saveDesiredSettings()
|
||||
}
|
||||
case .tryUpdatingEncryption(let updatedValue):
|
||||
if updatedValue {
|
||||
state.bindings.alertInfo = .init(id: .enableEncryption,
|
||||
title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertTitle,
|
||||
message: L10n.screenSecurityAndPrivacyEnableEncryptionAlertDescription,
|
||||
primaryButton: .init(title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertConfirmButtonTitle) { [weak self] in
|
||||
self?.state.bindings.desiredSettings.isEncryptionEnabled = true
|
||||
},
|
||||
primaryButton: .init(title: L10n.screenSecurityAndPrivacyEnableEncryptionAlertConfirmButtonTitle) { [weak self] in self?.state.bindings.desiredSettings.isEncryptionEnabled = true },
|
||||
secondaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil))
|
||||
} else {
|
||||
state.bindings.desiredSettings.isEncryptionEnabled = false
|
||||
}
|
||||
case .editAddress:
|
||||
actionsSubject.send(.displayEditAddressScreen)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func setupSubscriptions() {
|
||||
context.$viewState
|
||||
.map(\.availableVisibilityOptions)
|
||||
.removeDuplicates()
|
||||
// To allow the view to update properly
|
||||
.receive(on: DispatchQueue.main)
|
||||
// When the available options changes always default to `sinceSelection` if the currently selected option is not available
|
||||
.sink { [weak self] availableVisibilityOptions in
|
||||
guard let self else { return }
|
||||
let desiredHistoryVisibility = state.bindings.desiredSettings.historyVisibility
|
||||
if !availableVisibilityOptions.contains(desiredHistoryVisibility) {
|
||||
state.bindings.desiredSettings.historyVisibility = desiredHistoryVisibility.fallbackOption
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
roomProxy.infoPublisher
|
||||
.map(\.canonicalAlias)
|
||||
.removeDuplicates()
|
||||
.receive(on: DispatchQueue.main)
|
||||
.weakAssign(to: \.state.canonicalAlias, on: self)
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
private func setupRoomDirectoryVisibility() {
|
||||
Task {
|
||||
switch await roomProxy.isVisibleInRoomDirectory() {
|
||||
case .success(let value):
|
||||
state.bindings.desiredSettings.isVisibileInRoomDirectory = value
|
||||
state.currentSettings.isVisibileInRoomDirectory = value
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
state.bindings.desiredSettings.isVisibileInRoomDirectory = false
|
||||
state.currentSettings.isVisibileInRoomDirectory = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func saveDesiredSettings() async {
|
||||
showLoadingIndicator()
|
||||
|
||||
defer {
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
|
||||
if state.currentSettings.isEncryptionEnabled != state.bindings.desiredSettings.isEncryptionEnabled {
|
||||
switch await roomProxy.enableEncryption() {
|
||||
case .success:
|
||||
state.currentSettings.isEncryptionEnabled = state.bindings.desiredSettings.isEncryptionEnabled
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
if state.currentSettings.historyVisibility != state.bindings.desiredSettings.historyVisibility {
|
||||
switch await roomProxy.updateHistoryVisibility(state.bindings.desiredSettings.historyVisibility.toRoomHistoryVisibility) {
|
||||
case .success:
|
||||
state.currentSettings.historyVisibility = state.bindings.desiredSettings.historyVisibility
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
if state.currentSettings.accessType != state.bindings.desiredSettings.accessType {
|
||||
// When a user changes join rules to something other than knock or public,
|
||||
// the room should be automatically made invisible (private) in the room directory.
|
||||
if state.currentSettings.accessType != .askToJoin, state.currentSettings.accessType != .anyone {
|
||||
state.bindings.desiredSettings.isVisibileInRoomDirectory = false
|
||||
}
|
||||
|
||||
switch await roomProxy.updateJoinRule(state.bindings.desiredSettings.accessType.toJoinRule) {
|
||||
case .success:
|
||||
state.currentSettings.accessType = state.bindings.desiredSettings.accessType
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
|
||||
if state.currentSettings.isVisibileInRoomDirectory != state.bindings.desiredSettings.isVisibileInRoomDirectory {
|
||||
let visibility: RoomVisibility = state.bindings.desiredSettings.isVisibileInRoomDirectory == true ? .public : .private
|
||||
|
||||
switch await roomProxy.updateRoomDirectoryVisibility(visibility) {
|
||||
case .success:
|
||||
state.currentSettings.isVisibileInRoomDirectory = state.bindings.desiredSettings.isVisibileInRoomDirectory
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static let loadingIndicatorIdentifier = "\(EditRoomAddressScreenViewModel.self)-Loading"
|
||||
|
||||
private func showLoadingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier,
|
||||
type: .modal,
|
||||
title: L10n.commonLoading,
|
||||
persistent: true))
|
||||
}
|
||||
|
||||
private func hideLoadingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
private extension SecurityAndPrivacyRoomAccessType {
|
||||
var toJoinRule: JoinRule {
|
||||
switch self {
|
||||
case .inviteOnly:
|
||||
.invite
|
||||
case .askToJoin:
|
||||
.knock
|
||||
case .anyone:
|
||||
.public
|
||||
case .spaceUsers:
|
||||
fatalError("The user shouldn't be able to select this rule")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomInfoProxy {
|
||||
var roomAccessType: SecurityAndPrivacyRoomAccessType {
|
||||
switch joinRule {
|
||||
case .invite, .restricted:
|
||||
private extension Optional where Wrapped == JoinRule {
|
||||
var toSecurityAndPrivacyRoomAccessType: SecurityAndPrivacyRoomAccessType {
|
||||
switch self {
|
||||
case .none, .public:
|
||||
return .anyone
|
||||
case .invite:
|
||||
return .inviteOnly
|
||||
case .knock, .knockRestricted:
|
||||
return .askToJoin
|
||||
case .restricted:
|
||||
return .spaceUsers
|
||||
default:
|
||||
return .inviteOnly
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension RoomHistoryVisibility {
|
||||
var toSecurityAndPrivacyHistoryVisibility: SecurityAndPrivacyHistoryVisibility {
|
||||
switch self {
|
||||
case .joined, .invited:
|
||||
return .sinceInvite
|
||||
case .shared, .custom:
|
||||
return .sinceSelection
|
||||
case .worldReadable:
|
||||
return .anyone
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension SecurityAndPrivacyHistoryVisibility {
|
||||
var toRoomHistoryVisibility: RoomHistoryVisibility {
|
||||
switch self {
|
||||
case .sinceSelection:
|
||||
return .shared
|
||||
case .sinceInvite:
|
||||
return .invited
|
||||
case .anyone:
|
||||
return .worldReadable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+153
-7
@@ -14,7 +14,18 @@ struct SecurityAndPrivacyScreen: View {
|
||||
var body: some View {
|
||||
Form {
|
||||
roomAccessSection
|
||||
if context.desiredSettings.accessType != .inviteOnly {
|
||||
if let canonicalAlias = context.viewState.canonicalAlias {
|
||||
visibilitySection
|
||||
addressSection(canonicalAlias: canonicalAlias)
|
||||
roomDirectoryVisibilitySection
|
||||
} else {
|
||||
publishingSection
|
||||
addAddressSection
|
||||
}
|
||||
}
|
||||
encryptionSection
|
||||
historySection
|
||||
}
|
||||
.compoundList()
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
@@ -34,6 +45,14 @@ struct SecurityAndPrivacyScreen: View {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomAccessAnyoneOptionTitle,
|
||||
description: L10n.screenSecurityAndPrivacyRoomAccessAnyoneOptionDescription),
|
||||
kind: .selection(isSelected: context.desiredSettings.accessType == .anyone) { context.desiredSettings.accessType = .anyone })
|
||||
|
||||
if context.viewState.currentSettings.accessType == .spaceUsers {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomAccessSpaceMembersOptionTitle,
|
||||
description: L10n.screenSecurityAndPrivacyRoomAccessSpaceMembersOptionDescription),
|
||||
kind: .selection(isSelected: context.desiredSettings.accessType == .spaceUsers) { })
|
||||
// This is not supported so it will always be disabled and has no handler
|
||||
.disabled(true)
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomAccessSectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
@@ -42,7 +61,7 @@ struct SecurityAndPrivacyScreen: View {
|
||||
|
||||
@ViewBuilder
|
||||
private var encryptionSection: some View {
|
||||
let encryptionBinding = Binding<Bool>(get: {
|
||||
let binding = Binding<Bool>(get: {
|
||||
context.desiredSettings.isEncryptionEnabled
|
||||
}, set: { newValue in
|
||||
context.send(viewAction: .tryUpdatingEncryption(newValue))
|
||||
@@ -50,7 +69,7 @@ struct SecurityAndPrivacyScreen: View {
|
||||
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyEncryptionToggleTitle),
|
||||
kind: .toggle(encryptionBinding))
|
||||
kind: .toggle(binding))
|
||||
// We don't allow editing the encryption state if the current setting on the server is `enabled`
|
||||
.disabled(context.viewState.currentSettings.isEncryptionEnabled)
|
||||
} header: {
|
||||
@@ -62,26 +81,153 @@ struct SecurityAndPrivacyScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var historySection: some View {
|
||||
Section {
|
||||
ForEach(context.viewState.availableVisibilityOptions, id: \.self) { option in
|
||||
switch option {
|
||||
case .sinceSelection:
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomHistorySinceSelectingOptionTitle),
|
||||
kind: .selection(isSelected: context.desiredSettings.historyVisibility == .sinceSelection) { context.desiredSettings.historyVisibility = .sinceSelection })
|
||||
case .anyone:
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomHistoryAnyoneOptionTitle),
|
||||
kind: .selection(isSelected: context.desiredSettings.historyVisibility == .anyone) { context.desiredSettings.historyVisibility = .anyone })
|
||||
case .sinceInvite:
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomHistorySinceInviteOptionTitle),
|
||||
kind: .selection(isSelected: context.desiredSettings.historyVisibility == .sinceInvite) { context.desiredSettings.historyVisibility = .sinceInvite })
|
||||
}
|
||||
}
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomHistorySectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
}
|
||||
|
||||
private var visibilitySection: some View {
|
||||
Section {
|
||||
EmptyView()
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomVisibilitySectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomVisibilitySectionFooter(context.viewState.serverName))
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
private func addressSection(canonicalAlias: String) -> some View {
|
||||
Section {
|
||||
ListRow(label: .plain(title: canonicalAlias), kind: .navigationLink { context.send(viewAction: .editAddress) })
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomAddressSectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomAddressSectionFooter)
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
private var publishingSection: some View {
|
||||
Section {
|
||||
EmptyView()
|
||||
} header: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomPublishingSectionHeader)
|
||||
.compoundListSectionHeader()
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomPublishingSectionFooter)
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
private var addAddressSection: some View {
|
||||
Section {
|
||||
ListRow(kind: .custom {
|
||||
Button(L10n.screenSecurityAndPrivacyAddRoomAddressAction) { context.send(viewAction: .editAddress) }
|
||||
.foregroundColor(.compound.textActionAccent)
|
||||
.padding(ListRowPadding.insets)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var roomDirectoryVisibilitySection: some View {
|
||||
let binding = Binding<Bool>(get: {
|
||||
context.desiredSettings.isVisibileInRoomDirectory ?? false
|
||||
}, set: { newValue in
|
||||
context.desiredSettings.isVisibileInRoomDirectory = newValue
|
||||
})
|
||||
|
||||
Section {
|
||||
ListRow(label: .plain(title: L10n.screenSecurityAndPrivacyRoomDirectoryVisibilityToggleTitle),
|
||||
details: .isWaiting(context.desiredSettings.isVisibileInRoomDirectory == nil),
|
||||
kind: context.desiredSettings.isVisibileInRoomDirectory == nil ? .label : .toggle(binding))
|
||||
} footer: {
|
||||
Text(L10n.screenSecurityAndPrivacyRoomDirectoryVisibilitySectionFooter(context.viewState.serverName))
|
||||
.compoundListSectionFooter()
|
||||
}
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
var toolbar: some ToolbarContent {
|
||||
private var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(L10n.actionSave) {
|
||||
context.send(viewAction: .save)
|
||||
}
|
||||
.disabled(!context.viewState.hasChanges)
|
||||
.disabled(context.viewState.isSaveDisabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
// TODO: Add back TestablePreview, this is WIP so running preview tests for it is not necessary
|
||||
struct SecurityAndPrivacyScreen_Previews: PreviewProvider {
|
||||
static let inviteOnlyViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(joinRule: .invite)))
|
||||
struct SecurityAndPrivacyScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let inviteOnlyViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(joinRule: .invite)),
|
||||
clientProxy: ClientProxyMock(.init()),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let publicViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false,
|
||||
canonicalAlias: "#room:matrix.org",
|
||||
joinRule: .public,
|
||||
isVisibleInPublicDirectory: true)),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let publicNoAddressViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false,
|
||||
joinRule: .public)),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static let restrictedViewModel = SecurityAndPrivacyScreenViewModel(roomProxy: JoinedRoomProxyMock(.init(isEncrypted: false,
|
||||
canonicalAlias: "#room:matrix.org",
|
||||
joinRule: .restricted(rules: []),
|
||||
isVisibleInPublicDirectory: true)),
|
||||
clientProxy: ClientProxyMock(.init(userIDServerName: "matrix.org")),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: inviteOnlyViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Private invite only room")
|
||||
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: publicViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: publicViewModel.context.$viewState.map { state in
|
||||
state.currentSettings.isVisibileInRoomDirectory == true
|
||||
})
|
||||
.previewDisplayName("Public room")
|
||||
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: publicNoAddressViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Public room without address")
|
||||
|
||||
NavigationStack {
|
||||
SecurityAndPrivacyScreen(context: restrictedViewModel.context)
|
||||
}
|
||||
.snapshotPreferences(expect: restrictedViewModel.context.$viewState.map { state in
|
||||
state.currentSettings.isVisibileInRoomDirectory == true
|
||||
})
|
||||
.previewDisplayName("Restricted room")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,8 @@ struct MediaUploadingPreprocessor {
|
||||
size: fileSize,
|
||||
thumbnailInfo: thumbnailInfo,
|
||||
thumbnailSource: nil,
|
||||
blurhash: thumbnailResult.blurhash)
|
||||
blurhash: thumbnailResult.blurhash,
|
||||
isAnimated: nil)
|
||||
|
||||
let mediaInfo = MediaInfo.image(imageURL: url, thumbnailURL: thumbnailResult.url, imageInfo: imageInfo)
|
||||
|
||||
|
||||
@@ -190,6 +190,16 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func enableEncryption() async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.enableEncryption()
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed enabling encryption with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func redact(_ eventID: String) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.redact(eventId: eventID, reason: nil)
|
||||
@@ -359,6 +369,79 @@ class JoinedRoomProxy: JoinedRoomProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Privacy settings
|
||||
|
||||
func updateJoinRule(_ rule: JoinRule) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.updateJoinRules(newRule: rule)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed updating join rule with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func updateHistoryVisibility(_ visibility: RoomHistoryVisibility) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.updateHistoryVisibility(visibility: visibility)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed updating history visibility with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func isVisibleInRoomDirectory() async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(room.getRoomVisibility() == .public)
|
||||
} catch {
|
||||
MXLog.error("Failed checking if room is visible in room directory with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func updateRoomDirectoryVisibility(_ visibility: RoomVisibility) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.updateRoomVisibility(visibility: visibility)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed updating room directory visibility with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Canonical Alias
|
||||
|
||||
func updateCanonicalAlias(_ alias: String?, altAliases: [String]) async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await room.updateCanonicalAlias(alias: alias, altAliases: altAliases)
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed updating canonical alias with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func publishRoomAliasInRoomDirectory(_ alias: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
let result = try await room.publishRoomAliasInRoomDirectory(alias: alias)
|
||||
return .success(result)
|
||||
} catch {
|
||||
MXLog.error("Failed publishing the room's alias in the room directory with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
func removeRoomAliasFromRoomDirectory(_ alias: String) async -> Result<Bool, RoomProxyError> {
|
||||
do {
|
||||
let result = try await room.removeRoomAliasFromRoomDirectory(alias: alias)
|
||||
return .success(result)
|
||||
} catch {
|
||||
MXLog.error("Failed removing the room's alias in the room directory with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Room flags
|
||||
|
||||
func flagAsUnread(_ isUnread: Bool) async -> Result<Void, RoomProxyError> {
|
||||
|
||||
@@ -66,6 +66,7 @@ struct RoomInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
var unreadMentionsCount: UInt { UInt(roomInfo.numUnreadMentions) }
|
||||
var pinnedEventIDs: Set<String> { Set(roomInfo.pinnedEventIds) }
|
||||
var joinRule: JoinRule? { roomInfo.joinRule }
|
||||
var historyVisibility: RoomHistoryVisibility { roomInfo.historyVisibility }
|
||||
}
|
||||
|
||||
struct RoomPreviewInfoProxy: BaseRoomInfoProxyProtocol {
|
||||
|
||||
@@ -79,6 +79,8 @@ protocol JoinedRoomProxyProtocol: RoomProxyProtocol {
|
||||
|
||||
func messageFilteredTimeline(allowedMessageTypes: [RoomMessageEventMessageType]) async -> Result<TimelineProxyProtocol, RoomProxyError>
|
||||
|
||||
func enableEncryption() async -> Result<Void, RoomProxyError>
|
||||
|
||||
func redact(_ eventID: String) async -> Result<Void, RoomProxyError>
|
||||
|
||||
func reportContent(_ eventID: String, reason: String?) async -> Result<Void, RoomProxyError>
|
||||
@@ -110,6 +112,21 @@ protocol JoinedRoomProxyProtocol: RoomProxyProtocol {
|
||||
|
||||
func withdrawVerificationAndResend(userIDs: [String], sendHandle: SendHandleProxy) async -> Result<Void, RoomProxyError>
|
||||
|
||||
// MARK: - Privacy settings
|
||||
|
||||
func updateJoinRule(_ rule: JoinRule) async -> Result<Void, RoomProxyError>
|
||||
func updateHistoryVisibility(_ visibility: RoomHistoryVisibility) async -> Result<Void, RoomProxyError>
|
||||
|
||||
func isVisibleInRoomDirectory() async -> Result<Bool, RoomProxyError>
|
||||
func updateRoomDirectoryVisibility(_ visibility: RoomVisibility) async -> Result<Void, RoomProxyError>
|
||||
|
||||
// MARK: - Canonical Alias
|
||||
|
||||
func updateCanonicalAlias(_ alias: String?, altAliases: [String]) async -> Result<Void, RoomProxyError>
|
||||
|
||||
func publishRoomAliasInRoomDirectory(_ alias: String) async -> Result<Bool, RoomProxyError>
|
||||
func removeRoomAliasFromRoomDirectory(_ alias: String) async -> Result<Bool, RoomProxyError>
|
||||
|
||||
// MARK: - Room Flags
|
||||
|
||||
func flagAsUnread(_ isUnread: Bool) async -> Result<Void, RoomProxyError>
|
||||
|
||||
Reference in New Issue
Block a user