Skip to content

Commit

Permalink
async load room preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Feb 6, 2025
1 parent 922ebf4 commit dc4fa6a
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 44 deletions.
62 changes: 57 additions & 5 deletions ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5952,12 +5952,48 @@ class ElementCallWidgetDriverMock: ElementCallWidgetDriverProtocol, @unchecked S
}
}
class InvitedRoomProxyMock: InvitedRoomProxyProtocol, @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 inviter: RoomMemberProxyProtocol?
var infoThrowableError: Error?
var infoClosure: (() async throws -> BaseRoomInfoProxyProtocol)?
var inviterCallsCount = 0
var inviterCalled: Bool {
return inviterCallsCount > 0
}

var inviter: RoomMemberProxyProtocol? {
get async throws {
if let error = inviterThrowableError {
throw error
}
inviterCallsCount += 1
if let inviterClosure = inviterClosure {
return try await inviterClosure()
} else {
return underlyingInviter
}
}
}
var underlyingInviter: RoomMemberProxyProtocol?
var inviterThrowableError: Error?
var inviterClosure: (() async throws -> RoomMemberProxyProtocol?)?
var id: String {
get { return underlyingId }
set(value) { underlyingId = value }
Expand Down Expand Up @@ -10528,11 +10564,27 @@ class KnockRequestProxyMock: KnockRequestProxyProtocol, @unchecked Sendable {
}
}
class KnockedRoomProxyMock: KnockedRoomProxyProtocol, @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
4 changes: 2 additions & 2 deletions ElementX/Sources/Mocks/InvitedRoomProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ extension InvitedRoomProxyMock {
convenience init(_ configuration: InvitedRoomProxyMockConfiguration) {
self.init()
id = configuration.id
inviter = configuration.inviter
info = RoomInfoProxy(roomInfo: .init(configuration))
underlyingInviter = configuration.inviter
underlyingInfo = RoomInfoProxy(roomInfo: .init(configuration))
}
}

Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/KnockedRoomProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension KnockedRoomProxyMock {
convenience init(_ configuration: KnockedRoomProxyMockConfiguration) {
self.init()
id = configuration.id
info = RoomInfoProxy(roomInfo: .init(configuration))
underlyingInfo = RoomInfoProxy(roomInfo: .init(configuration))
}
}

Expand Down
9 changes: 6 additions & 3 deletions ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,12 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
switch await userSession.clientProxy.joinRoom(roomID, via: []) {
case .success:
actionsSubject.send(.presentRoom(roomIdentifier: roomID))
analyticsService.trackJoinedRoom(isDM: roomProxy.info.isDirect,
isSpace: roomProxy.info.isSpace,
activeMemberCount: UInt(roomProxy.info.activeMembersCount))
Task {
let info = try await roomProxy.info
analyticsService.trackJoinedRoom(isDM: info.isDirect,
isSpace: info.isSpace,
activeMemberCount: UInt(info.activeMembersCount))
}
case .failure:
displayError()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
}

hideLoadingIndicator()

await updateRoomDetails()
}

Expand All @@ -121,11 +120,12 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo
switch room {
case .joined(let joinedRoomProxy):
roomInfo = joinedRoomProxy.infoPublisher.value
roomInfo = joinedRoomProxy.infoPublisher.value
case .invited(let invitedRoomProxy):
inviter = invitedRoomProxy.inviter.map(RoomInviterDetails.init)
roomInfo = invitedRoomProxy.info
inviter = try? await invitedRoomProxy.inviter.map(RoomInviterDetails.init)
roomInfo = try? await invitedRoomProxy.info
case .knocked(let knockedRoomProxy):
roomInfo = knockedRoomProxy.info
roomInfo = try? await knockedRoomProxy.info
if let roomSummaryProvider = clientProxy.roomSummaryProvider {
membershipStateChangeCancellable = roomSummaryProvider.roomListPublisher
.compactMap { summaries -> Void? in
Expand Down
11 changes: 4 additions & 7 deletions ElementX/Sources/Services/Client/ClientProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -916,14 +916,12 @@ class ClientProxy: ClientProxyProtocol {

switch roomListItem.membership() {
case .invited:
return try await .invited(InvitedRoomProxy(roomListItem: roomListItem,
roomPreview: roomListItem.previewRoom(via: []),
ownUserID: userID))
return .invited(InvitedRoomProxy(roomListItem: roomListItem,
ownUserID: userID))
case .knocked:
if appSettings.knockingEnabled {
return try await .knocked(KnockedRoomProxy(roomListItem: roomListItem,
roomPreview: roomListItem.previewRoom(via: []),
ownUserID: userID))
return .knocked(KnockedRoomProxy(roomListItem: roomListItem,
ownUserID: userID))
}
return nil
case .joined:
Expand All @@ -940,7 +938,6 @@ class ClientProxy: ClientProxyProtocol {
return .left
case .banned:
return try await .banned(BannedRoomProxy(roomListItem: roomListItem,
roomPreview: roomListItem.previewRoom(via: []),
ownUserID: userID))
}
} catch {
Expand Down
5 changes: 2 additions & 3 deletions ElementX/Sources/Services/Room/BannedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ class BannedRoomProxy: BannedRoomProxyProtocol {
lazy var id = info.id

init(roomListItem: RoomListItemProtocol,
roomPreview: RoomPreviewProtocol,
ownUserID: String) throws {
ownUserID: String) async throws {
self.roomListItem = roomListItem
self.roomPreview = roomPreview
roomPreview = try await roomListItem.previewRoom(via: [])
self.ownUserID = ownUserID
info = try RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
}
Expand Down
34 changes: 25 additions & 9 deletions ElementX/Sources/Services/Room/InvitedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,39 @@ import UIKit

class InvitedRoomProxy: InvitedRoomProxyProtocol {
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())
}
}

var inviter: RoomMemberProxyProtocol? {
get async throws {
try await roomPreview.inviter().map(RoomMemberProxy.init)
}
}

let ownUserID: String
let inviter: RoomMemberProxyProtocol?

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

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

func rejectInvitation() async -> Result<Void, RoomProxyError> {
Expand Down
26 changes: 19 additions & 7 deletions ElementX/Sources/Services/Room/KnockedRoomProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,33 @@ import MatrixRustSDK

class KnockedRoomProxy: KnockedRoomProxyProtocol {
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,
roomPreview: RoomPreviewProtocol,
ownUserID: String) throws {
ownUserID: String) {
self.roomListItem = roomListItem
self.roomPreview = roomPreview
self.ownUserID = ownUserID
info = try RoomPreviewInfoProxy(roomPreviewInfo: roomPreview.info())
roomPreviewTask = Task {
try await roomListItem.previewRoom(via: [])
}
}

func cancelKnock() async -> Result<Void, RoomProxyError> {
Expand Down
6 changes: 3 additions & 3 deletions ElementX/Sources/Services/Room/RoomProxyProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ protocol RoomProxyProtocol {

// sourcery: AutoMockable
protocol InvitedRoomProxyProtocol: RoomProxyProtocol {
var info: BaseRoomInfoProxyProtocol { get }
var inviter: RoomMemberProxyProtocol? { get }
var info: BaseRoomInfoProxyProtocol { get async throws }
var inviter: RoomMemberProxyProtocol? { get async throws }
func rejectInvitation() async -> Result<Void, RoomProxyError>
}

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

Expand Down

0 comments on commit dc4fa6a

Please sign in to comment.