mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
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:
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// 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 Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
class BannedRoomProxy: BannedRoomProxyProtocol {
|
||||
private let roomListItem: RoomListItemProtocol
|
||||
private let roomPreview: RoomPreviewProtocol
|
||||
let info: BaseRoomInfoProxyProtocol
|
||||
let ownUserID: String
|
||||
|
||||
// A room identifier is constant and lazy stops it from being fetched
|
||||
// multiple times over FFI
|
||||
lazy var id = info.id
|
||||
|
||||
init(roomListItem: RoomListItemProtocol,
|
||||
roomPreview: RoomPreviewProtocol,
|
||||
ownUserID: String) throws {
|
||||
self.roomListItem = roomListItem
|
||||
self.roomPreview = roomPreview
|
||||
self.ownUserID = ownUserID
|
||||
info = try RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
|
||||
}
|
||||
|
||||
func forgetRoom() async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
return try await .success(roomPreview.forget())
|
||||
} catch {
|
||||
MXLog.error("Failed forgetting the room with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,14 +32,4 @@ final class RoomPreviewProxy: RoomPreviewProxyProtocol {
|
||||
senderRoomMember: senderRoomMember)
|
||||
}
|
||||
}
|
||||
|
||||
func forgetRoom() async -> Result<Void, RoomProxyError> {
|
||||
do {
|
||||
try await roomPreview.forget()
|
||||
return .success(())
|
||||
} catch {
|
||||
MXLog.error("Failed forgetting the room with error: \(error)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,4 @@ import Foundation
|
||||
protocol RoomPreviewProxyProtocol {
|
||||
var info: RoomPreviewInfoProxy { get }
|
||||
var ownMembershipDetails: RoomMembershipDetailsProxyProtocol? { get async }
|
||||
|
||||
/// Use this function to forget the room, should only be used if the current user membership is `banned`
|
||||
func forgetRoom() async -> Result<Void, RoomProxyError>
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ enum RoomProxyType {
|
||||
case joined(JoinedRoomProxyProtocol)
|
||||
case invited(InvitedRoomProxyProtocol)
|
||||
case knocked(KnockedRoomProxyProtocol)
|
||||
case banned
|
||||
case banned(BannedRoomProxyProtocol)
|
||||
case left
|
||||
}
|
||||
|
||||
@@ -45,6 +45,12 @@ protocol KnockedRoomProxyProtocol: RoomProxyProtocol {
|
||||
func cancelKnock() async -> Result<Void, RoomProxyError>
|
||||
}
|
||||
|
||||
// sourcery: AutoMockable
|
||||
protocol BannedRoomProxyProtocol: RoomProxyProtocol {
|
||||
var info: BaseRoomInfoProxyProtocol { get }
|
||||
func forgetRoom() async -> Result<Void, RoomProxyError>
|
||||
}
|
||||
|
||||
enum JoinedRoomProxyAction: Equatable {
|
||||
case roomInfoUpdate
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user