Added the banned room proxy (#3744)

* added the banned room proxy

and a way to have a consistent loading + a retry alert

* trailing closure

* indent a comment

* push package.resolved

* updated test case
This commit is contained in:
Mauro
2025-02-06 10:15:36 +01:00
committed by GitHub
parent 3839025caa
commit f86a5a2bb9
13 changed files with 228 additions and 89 deletions
@@ -0,0 +1,64 @@
//
// Copyright 2025 New Vector Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
// Please see LICENSE files in the repository root for full details.
//
import Combine
import Foundation
import MatrixRustSDK
@MainActor
struct BannedRoomProxyMockConfiguration {
var id = UUID().uuidString
var name: String?
var avatarURL: URL?
var members: [RoomMemberProxyMock] = .allMembers
}
extension BannedRoomProxyMock {
@MainActor
convenience init(_ configuration: KnockedRoomProxyMockConfiguration) {
self.init()
id = configuration.id
info = RoomInfoProxy(roomInfo: .init(configuration))
}
}
extension RoomInfo {
@MainActor init(_ configuration: BannedRoomProxyMockConfiguration) {
self.init(id: configuration.id,
creator: nil,
displayName: configuration.name,
rawName: nil,
topic: nil,
avatarUrl: configuration.avatarURL?.absoluteString,
isDirect: false,
isPublic: false,
isSpace: false,
isTombstoned: false,
isFavourite: false,
canonicalAlias: nil,
alternativeAliases: [],
membership: .knocked,
inviter: nil,
heroes: [],
activeMembersCount: UInt64(configuration.members.filter { $0.membership == .join || $0.membership == .invite }.count),
invitedMembersCount: UInt64(configuration.members.filter { $0.membership == .invite }.count),
joinedMembersCount: UInt64(configuration.members.filter { $0.membership == .join }.count),
userPowerLevels: [:],
highlightCount: 0,
notificationCount: 0,
cachedUserDefinedNotificationMode: nil,
hasRoomCall: false,
activeRoomCallParticipants: [],
isMarkedUnread: false,
numUnreadMessages: 0,
numUnreadNotifications: 0,
numUnreadMentions: 0,
pinnedEventIds: [],
joinRule: .knock,
historyVisibility: .shared)
}
}
@@ -2047,6 +2047,88 @@ class AuthenticationClientBuilderMock: AuthenticationClientBuilderProtocol, @unc
}
}
}
class BannedRoomProxyMock: BannedRoomProxyProtocol, @unchecked Sendable {
var info: BaseRoomInfoProxyProtocol {
get { return underlyingInfo }
set(value) { underlyingInfo = value }
}
var underlyingInfo: BaseRoomInfoProxyProtocol!
var id: String {
get { return underlyingId }
set(value) { underlyingId = value }
}
var underlyingId: String!
var ownUserID: String {
get { return underlyingOwnUserID }
set(value) { underlyingOwnUserID = value }
}
var underlyingOwnUserID: String!
//MARK: - forgetRoom
var forgetRoomUnderlyingCallsCount = 0
var forgetRoomCallsCount: Int {
get {
if Thread.isMainThread {
return forgetRoomUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = forgetRoomUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
forgetRoomUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
forgetRoomUnderlyingCallsCount = newValue
}
}
}
}
var forgetRoomCalled: Bool {
return forgetRoomCallsCount > 0
}
var forgetRoomUnderlyingReturnValue: Result<Void, RoomProxyError>!
var forgetRoomReturnValue: Result<Void, RoomProxyError>! {
get {
if Thread.isMainThread {
return forgetRoomUnderlyingReturnValue
} else {
var returnValue: Result<Void, RoomProxyError>? = nil
DispatchQueue.main.sync {
returnValue = forgetRoomUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
forgetRoomUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
forgetRoomUnderlyingReturnValue = newValue
}
}
}
}
var forgetRoomClosure: (() async -> Result<Void, RoomProxyError>)?
func forgetRoom() async -> Result<Void, RoomProxyError> {
forgetRoomCallsCount += 1
if let forgetRoomClosure = forgetRoomClosure {
return await forgetRoomClosure()
} else {
return forgetRoomReturnValue
}
}
}
class BugReportServiceMock: BugReportServiceProtocol, @unchecked Sendable {
var crashedLastRun: Bool {
get { return underlyingCrashedLastRun }
@@ -13393,70 +13475,6 @@ class RoomPreviewProxyMock: RoomPreviewProxyProtocol, @unchecked Sendable {
var underlyingOwnMembershipDetails: RoomMembershipDetailsProxyProtocol?
var ownMembershipDetailsClosure: (() async -> RoomMembershipDetailsProxyProtocol?)?
//MARK: - forgetRoom
var forgetRoomUnderlyingCallsCount = 0
var forgetRoomCallsCount: Int {
get {
if Thread.isMainThread {
return forgetRoomUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = forgetRoomUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
forgetRoomUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
forgetRoomUnderlyingCallsCount = newValue
}
}
}
}
var forgetRoomCalled: Bool {
return forgetRoomCallsCount > 0
}
var forgetRoomUnderlyingReturnValue: Result<Void, RoomProxyError>!
var forgetRoomReturnValue: Result<Void, RoomProxyError>! {
get {
if Thread.isMainThread {
return forgetRoomUnderlyingReturnValue
} else {
var returnValue: Result<Void, RoomProxyError>? = nil
DispatchQueue.main.sync {
returnValue = forgetRoomUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
forgetRoomUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
forgetRoomUnderlyingReturnValue = newValue
}
}
}
}
var forgetRoomClosure: (() async -> Result<Void, RoomProxyError>)?
func forgetRoom() async -> Result<Void, RoomProxyError> {
forgetRoomCallsCount += 1
if let forgetRoomClosure = forgetRoomClosure {
return await forgetRoomClosure()
} else {
return forgetRoomReturnValue
}
}
}
class RoomProxyMock: RoomProxyProtocol, @unchecked Sendable {
var id: String {