Pass the full room into the invited room proxy and stop automatically retrieving the preview

- this will help speed up leaving invites but also stop fetching previews twice in the join room screen
This commit is contained in:
Stefan Ceriu
2025-05-23 11:59:38 +03:00
committed by Stefan Ceriu
parent 29cfcb0b85
commit a7c4a32285
3 changed files with 86 additions and 20 deletions
@@ -1,4 +1,4 @@
// Generated using Sourcery 2.2.6 — https://github.com/krzysztofzablocki/Sourcery
// Generated using Sourcery 2.2.7 — https://github.com/krzysztofzablocki/Sourcery
// DO NOT EDIT
// swiftlint:disable all
@@ -13286,6 +13286,75 @@ open class RoomSDKMock: MatrixRustSDK.Room, @unchecked Sendable {
}
}
//MARK: - inviter
open var inviterThrowableError: Error?
var inviterUnderlyingCallsCount = 0
open var inviterCallsCount: Int {
get {
if Thread.isMainThread {
return inviterUnderlyingCallsCount
} else {
var returnValue: Int? = nil
DispatchQueue.main.sync {
returnValue = inviterUnderlyingCallsCount
}
return returnValue!
}
}
set {
if Thread.isMainThread {
inviterUnderlyingCallsCount = newValue
} else {
DispatchQueue.main.sync {
inviterUnderlyingCallsCount = newValue
}
}
}
}
open var inviterCalled: Bool {
return inviterCallsCount > 0
}
var inviterUnderlyingReturnValue: RoomMember?
open var inviterReturnValue: RoomMember? {
get {
if Thread.isMainThread {
return inviterUnderlyingReturnValue
} else {
var returnValue: RoomMember?? = nil
DispatchQueue.main.sync {
returnValue = inviterUnderlyingReturnValue
}
return returnValue!
}
}
set {
if Thread.isMainThread {
inviterUnderlyingReturnValue = newValue
} else {
DispatchQueue.main.sync {
inviterUnderlyingReturnValue = newValue
}
}
}
}
open var inviterClosure: (() async throws -> RoomMember?)?
open override func inviter() async throws -> RoomMember? {
if let error = inviterThrowableError {
throw error
}
inviterCallsCount += 1
if let inviterClosure = inviterClosure {
return try await inviterClosure()
} else {
return inviterReturnValue
}
}
//MARK: - isDirect
var isDirectUnderlyingCallsCount = 0
@@ -908,9 +908,12 @@ class ClientProxy: ClientProxyProtocol {
switch roomListItem.membership() {
case .invited:
return try await .invited(InvitedRoomProxy(roomListItem: roomListItem,
roomPreview: roomListItem.previewRoom(via: []),
ownUserID: userID))
guard let room = try client.getRoom(roomId: roomID) else {
MXLog.error("Could not find room with ID: \(roomID)")
return nil
}
return try await .invited(InvitedRoomProxy(room: room))
case .knocked:
if appSettings.knockingEnabled {
return try await .knocked(KnockedRoomProxy(roomListItem: roomListItem,
@@ -10,31 +10,25 @@ import MatrixRustSDK
import UIKit
class InvitedRoomProxy: InvitedRoomProxyProtocol {
private let roomListItem: RoomListItemProtocol
private let roomPreview: RoomPreviewProtocol
private let room: Room
// A room identifier is constant and lazy stops it from being fetched
// multiple times over FFI
lazy var id: String = info.id
let ownUserID: String
lazy var id: String = room.id()
lazy var ownUserID: String = room.ownUserId()
let info: BaseRoomInfoProxyProtocol
let inviter: RoomMemberProxyProtocol?
init(room: Room) async throws {
self.room = room
init(roomListItem: RoomListItemProtocol,
roomPreview: RoomPreviewProtocol,
ownUserID: String) async throws {
self.roomListItem = roomListItem
self.roomPreview = roomPreview
self.ownUserID = ownUserID
info = try RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
inviter = await roomPreview.inviter().map(RoomMemberProxy.init)
info = try await RoomInfoProxy(roomInfo: room.roomInfo())
inviter = try? await room.inviter().map(RoomMemberProxy.init)
}
func rejectInvitation() async -> Result<Void, RoomProxyError> {
do {
return try await .success(roomPreview.leave())
return try await .success(room.leave())
} catch {
MXLog.error("Failed rejecting invitiation with error: \(error)")
return .failure(.sdkError(error))