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 20, 2024
1 parent 6616d17 commit 1396140
Show file tree
Hide file tree
Showing 98 changed files with 3,524 additions and 3,238 deletions.
44 changes: 28 additions & 16 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 @@ -559,7 +559,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
// MARK: Calls

private var callScreenPictureInPictureController: AVPictureInPictureController?
private func presentCallScreen(roomProxy: RoomProxyProtocol) {
private func presentCallScreen(roomProxy: JoinedRoomProxyProtocol) {
guard elementCallService.ongoingCallRoomID != roomProxy.id else {
MXLog.info("Returning to existing call.")
callScreenPictureInPictureController?.stopPictureInPicture()
Expand Down Expand Up @@ -601,7 +601,7 @@ 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
}

Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Mocks/ClientProxyMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ extension ClientProxyMock {

roomForIdentifierClosure = { [weak self] identifier in
guard let room = self?.roomSummaryProvider?.roomListPublisher.value.first(where: { $0.id == identifier }) else {
return nil
fatalError()
}

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 1396140

Please sign in to comment.