Skip to content

Commit

Permalink
Introduce a new RoomProxyType and treat rooms differently based on th…
Browse files Browse the repository at this point in the history
…eir membership state
  • Loading branch information
stefanceriu committed Aug 21, 2024
1 parent e0ba992 commit e281a3f
Show file tree
Hide file tree
Showing 97 changed files with 3,536 additions and 3,255 deletions.
20 changes: 12 additions & 8 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,15 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
guard let roomID = content.userInfo[NotificationConstants.UserInfoKey.roomIdentifier] as? String else {
return
}
let roomProxy = await userSession.clientProxy.roomForIdentifier(roomID)
switch await roomProxy?.timeline.sendMessage(replyText,
html: nil,
intentionalMentions: .empty) {

guard case let .joined(roomProxy) = await userSession.clientProxy.roomForIdentifier(roomID) else {
MXLog.error("Tried to reply in an unjoined room: \(roomID)")
return
}

switch await roomProxy.timeline.sendMessage(replyText,
html: nil,
intentionalMentions: .empty) {
case .success:
break
default:
Expand Down
26 changes: 11 additions & 15 deletions ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SwiftUI
import UserNotifications

enum RoomFlowCoordinatorAction: Equatable {
case presentCallScreen(roomProxy: RoomProxyProtocol)
case presentCallScreen(roomProxy: JoinedRoomProxyProtocol)
case finished

static func == (lhs: RoomFlowCoordinatorAction, rhs: RoomFlowCoordinatorAction) -> Bool {
Expand Down Expand Up @@ -63,7 +63,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol

private var roomProxy: RoomProxyProtocol!
private var roomProxy: JoinedRoomProxyProtocol!

private var roomScreenCoordinator: RoomScreenCoordinator?
private weak var joinRoomScreenCoordinator: JoinRoomScreenCoordinator?
Expand Down Expand Up @@ -139,7 +139,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {

Task {
if roomProxy == nil {
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomID) else {
guard case let .joined(roomProxy) = await userSession.clientProxy.roomForIdentifier(roomID) else {
return
}

Expand Down Expand Up @@ -173,7 +173,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
}

private func presentCallScreen(roomID: String) async {
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomID) else {
guard case let .joined(roomProxy) = await userSession.clientProxy.roomForIdentifier(roomID) else {
return
}

Expand All @@ -183,13 +183,13 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
private func handleRoomRoute(roomID: String, via: [String], focussedEventID: String? = nil, animated: Bool) async {
guard roomID == self.roomID else { fatalError("Navigation route doesn't belong to this room flow.") }

guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomID) else {
guard let room = await userSession.clientProxy.roomForIdentifier(roomID) else {
stateMachine.tryEvent(.presentJoinRoomScreen(via: via), userInfo: EventUserInfo(animated: animated))
return
}

switch roomProxy.membership {
case .joined:
switch room {
case .joined(let roomProxy):
await storeAndSubscribeToRoomProxy(roomProxy)
stateMachine.tryEvent(.presentRoom(focussedEventID: focussedEventID), userInfo: EventUserInfo(animated: animated))
default:
Expand All @@ -207,7 +207,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {

// MARK: - Private

private func storeAndSubscribeToRoomProxy(_ roomProxy: RoomProxyProtocol) async {
private func storeAndSubscribeToRoomProxy(_ roomProxy: JoinedRoomProxyProtocol) async {
if let oldRoomProxy = self.roomProxy {
if oldRoomProxy.id != roomProxy.id {
fatalError("Trying to create different room proxies for the same flow coordinator")
Expand All @@ -216,11 +216,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
MXLog.warning("Found an existing proxy, returning.")
return
}

guard roomProxy.membership == .joined else {
fatalError("Requesting room details for an unjoined room")
}


await roomProxy.subscribeForUpdates()

// Make sure not to set this until after the subscription has succeeded, otherwise the
Expand Down Expand Up @@ -658,7 +654,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
Task { [weak self] in
guard let self else { return }

if let roomProxy = await userSession.clientProxy.roomForIdentifier(roomID) {
if case let .joined(roomProxy) = await userSession.clientProxy.roomForIdentifier(roomID) {
await storeAndSubscribeToRoomProxy(roomProxy)
stateMachine.tryEvent(.presentRoom(focussedEventID: nil), userInfo: EventUserInfo(animated: animated))

Expand Down Expand Up @@ -1300,7 +1296,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
}
}

private func inviteUsers(_ users: [String], in room: RoomProxyProtocol) {
private func inviteUsers(_ users: [String], in room: JoinedRoomProxyProtocol) {
navigationStackCoordinator.setSheetCoordinator(nil)

Task {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ enum RoomRolesAndPermissionsFlowCoordinatorAction: Equatable {
}

struct RoomRolesAndPermissionsFlowCoordinatorParameters {
let roomProxy: RoomProxyProtocol
let roomProxy: JoinedRoomProxyProtocol
let mediaProvider: MediaProviderProtocol
let navigationStackCoordinator: NavigationStackCoordinator
let userIndicatorController: UserIndicatorControllerProtocol
let analytics: AnalyticsService
}

class RoomRolesAndPermissionsFlowCoordinator: FlowCoordinatorProtocol {
private let roomProxy: RoomProxyProtocol
private let roomProxy: JoinedRoomProxyProtocol
private let navigationStackCoordinator: NavigationStackCoordinator
private let mediaProvider: MediaProviderProtocol
private let userIndicatorController: UserIndicatorControllerProtocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
}

private func presentCallScreen(roomID: String) async {
guard let roomProxy = await userSession.clientProxy.roomForIdentifier(roomID) else {
guard case let .joined(roomProxy) = await userSession.clientProxy.roomForIdentifier(roomID) else {
return
}

presentCallScreen(roomProxy: roomProxy)
}

private func presentCallScreen(roomProxy: RoomProxyProtocol) {
private func presentCallScreen(roomProxy: JoinedRoomProxyProtocol) {
let colorScheme: ColorScheme = appMediator.windowManager.mainWindow.traitCollection.userInterfaceStyle == .light ? .light : .dark
presentCallScreen(configuration: .init(roomProxy: roomProxy,
clientProxy: userSession.clientProxy,
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/Mocks/ClientProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ extension ClientProxyMock {
return nil
}

return await RoomProxyMock(.init(id: room.id, name: room.name))
return await .joined(JoinedRoomProxyMock(.init(id: room.id, name: room.name)))
}
}
}
Loading

0 comments on commit e281a3f

Please sign in to comment.