Skip to content

Commit

Permalink
applying the same logic for banned rooms
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Feb 6, 2025
1 parent dc4fa6a commit 289ad1f
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/BannedRoomProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension BannedRoomProxyMock {
convenience init(_ configuration: KnockedRoomProxyMockConfiguration) {
self.init()
id = configuration.id
info = RoomInfoProxy(roomInfo: .init(configuration))
underlyingInfo = RoomInfoProxy(roomInfo: .init(configuration))
}
}

Expand Down
20 changes: 18 additions & 2 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2048,11 +2048,27 @@ class AuthenticationClientBuilderMock: AuthenticationClientBuilderProtocol, @unc
}
}
class BannedRoomProxyMock: BannedRoomProxyProtocol, @unchecked Sendable {
var infoCallsCount = 0
var infoCalled: Bool {
return infoCallsCount > 0
}

var info: BaseRoomInfoProxyProtocol {
get { return underlyingInfo }
set(value) { underlyingInfo = value }
get async throws {
if let error = infoThrowableError {
throw error
}
infoCallsCount += 1
if let infoClosure = infoClosure {
return try await infoClosure()
} else {
return underlyingInfo
}
}
}
var underlyingInfo: BaseRoomInfoProxyProtocol!
var infoThrowableError: Error?
var infoClosure: (() async throws -> BaseRoomInfoProxyProtocol)?
var id: String {
get { return underlyingId }
set(value) { underlyingId = value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
}
}
case .banned(let bannedRoomProxy):
roomInfo = bannedRoomProxy.info
roomInfo = try? await bannedRoomProxy.info
default:
break
}
Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,8 @@ class ClientProxy: ClientProxyProtocol {
case .left:
return .left
case .banned:
return try await .banned(BannedRoomProxy(roomListItem: roomListItem,
ownUserID: userID))
return .banned(BannedRoomProxy(roomListItem: roomListItem,
ownUserID: userID))
}
} catch {
MXLog.error("Failed retrieving room: \(roomID), with error: \(error)")
Expand Down
23 changes: 17 additions & 6 deletions ElementX/Sources/Services/Room/BannedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,31 @@ import MatrixRustSDK

class BannedRoomProxy: BannedRoomProxyProtocol {
private let roomListItem: RoomListItemProtocol
private let roomPreview: RoomPreviewProtocol
let info: BaseRoomInfoProxyProtocol
private var roomPreview: RoomPreviewProtocol {
get async throws {
try await roomPreviewTask.value
}
}

private var roomPreviewTask: Task<RoomPreviewProtocol, Error>

var info: BaseRoomInfoProxyProtocol {
get async throws {
try await RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
}
}

let ownUserID: String

// A room identifier is constant and lazy stops it from being fetched
// multiple times over FFI
lazy var id = info.id
lazy var id = roomListItem.id()

init(roomListItem: RoomListItemProtocol,
ownUserID: String) async throws {
ownUserID: String) {
self.roomListItem = roomListItem
roomPreview = try await roomListItem.previewRoom(via: [])
self.ownUserID = ownUserID
info = try RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
roomPreviewTask = Task { try await roomListItem.previewRoom(via: []) }
}

func forgetRoom() async -> Result<Void, RoomProxyError> {
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protocol KnockedRoomProxyProtocol: RoomProxyProtocol {

// sourcery: AutoMockable
protocol BannedRoomProxyProtocol: RoomProxyProtocol {
var info: BaseRoomInfoProxyProtocol { get }
var info: BaseRoomInfoProxyProtocol { get async throws }
func forgetRoom() async -> Result<Void, RoomProxyError>
}

Expand Down

0 comments on commit 289ad1f

Please sign in to comment.