Skip to content

Commit

Permalink
Hide a room's Call button when already joined to the call.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Aug 21, 2024
1 parent eac1a08 commit ae1facc
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 10 deletions.
5 changes: 5 additions & 0 deletions ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
private let roomTimelineControllerFactory: RoomTimelineControllerFactoryProtocol
private let navigationStackCoordinator: NavigationStackCoordinator
private let emojiProvider: EmojiProviderProtocol
private let ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>
private let appMediator: AppMediatorProtocol
private let appSettings: AppSettings
private let analytics: AnalyticsService
Expand Down Expand Up @@ -90,6 +91,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
roomTimelineControllerFactory: RoomTimelineControllerFactoryProtocol,
navigationStackCoordinator: NavigationStackCoordinator,
emojiProvider: EmojiProviderProtocol,
ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>,
appMediator: AppMediatorProtocol,
appSettings: AppSettings,
analytics: AnalyticsService,
Expand All @@ -100,6 +102,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
self.roomTimelineControllerFactory = roomTimelineControllerFactory
self.navigationStackCoordinator = navigationStackCoordinator
self.emojiProvider = emojiProvider
self.ongoingCallRoomIDPublisher = ongoingCallRoomIDPublisher
self.appMediator = appMediator
self.appSettings = appSettings
self.analytics = analytics
Expand Down Expand Up @@ -580,6 +583,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
voiceMessageMediaManager: userSession.voiceMessageMediaManager,
emojiProvider: emojiProvider,
completionSuggestionService: completionSuggestionService,
ongoingCallRoomIDPublisher: ongoingCallRoomIDPublisher,
appMediator: appMediator,
appSettings: appSettings,
composerDraftService: composerDraftService)
Expand Down Expand Up @@ -1350,6 +1354,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
roomTimelineControllerFactory: roomTimelineControllerFactory,
navigationStackCoordinator: navigationStackCoordinator,
emojiProvider: emojiProvider,
ongoingCallRoomIDPublisher: ongoingCallRoomIDPublisher,
appMediator: appMediator,
appSettings: appSettings,
analytics: analytics,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
roomTimelineControllerFactory: roomTimelineControllerFactory,
navigationStackCoordinator: detailNavigationStackCoordinator,
emojiProvider: EmojiProvider(),
ongoingCallRoomIDPublisher: elementCallService.ongoingCallRoomIDPublisher,
appMediator: appMediator,
appSettings: appSettings,
analytics: analytics,
Expand Down Expand Up @@ -580,7 +581,7 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {

private var callScreenPictureInPictureController: AVPictureInPictureController?
private func presentCallScreen(configuration: ElementCallConfiguration) {
guard elementCallService.ongoingCallRoomID != configuration.callRoomID else {
guard elementCallService.ongoingCallRoomIDPublisher.value != configuration.callRoomID else {
MXLog.info("Returning to existing call.")
callScreenPictureInPictureController?.stopPictureInPicture()
return
Expand Down
5 changes: 4 additions & 1 deletion ElementX/Sources/Mocks/ElementCallServiceMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
import Combine
import Foundation

struct ElementCallServiceMockConfiguration { }
struct ElementCallServiceMockConfiguration {
var ongoingCallRoomID: String?
}

extension ElementCallServiceMock {
convenience init(_ configuration: ElementCallServiceMockConfiguration) {
self.init()

underlyingActions = PassthroughSubject().eraseToAnyPublisher()
underlyingOngoingCallRoomIDPublisher = .init(.init(configuration.ongoingCallRoomID))
}
}
6 changes: 5 additions & 1 deletion ElementX/Sources/Mocks/Generated/GeneratedMocks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4894,7 +4894,11 @@ class ElementCallServiceMock: ElementCallServiceProtocol {
set(value) { underlyingActions = value }
}
var underlyingActions: AnyPublisher<ElementCallServiceAction, Never>!
var ongoingCallRoomID: String?
var ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never> {
get { return underlyingOngoingCallRoomIDPublisher }
set(value) { underlyingOngoingCallRoomIDPublisher = value }
}
var underlyingOngoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>!

//MARK: - setClientProxy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct RoomScreenCoordinatorParameters {
let voiceMessageMediaManager: VoiceMessageMediaManagerProtocol
let emojiProvider: EmojiProviderProtocol
let completionSuggestionService: CompletionSuggestionServiceProtocol
let ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>
let appMediator: AppMediatorProtocol
let appSettings: AppSettings
let composerDraftService: ComposerDraftServiceProtocol
Expand Down Expand Up @@ -64,6 +65,7 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
init(parameters: RoomScreenCoordinatorParameters) {
roomViewModel = RoomScreenViewModel(roomProxy: parameters.roomProxy,
mediaProvider: parameters.mediaProvider,
ongoingCallRoomIDPublisher: parameters.ongoingCallRoomIDPublisher,
appMediator: parameters.appMediator,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics)
Expand Down
1 change: 1 addition & 0 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct RoomScreenViewState: BindableState {

var canJoinCall = false
var hasOngoingCall: Bool
var shouldShowCallButton = true

var bindings: RoomScreenViewStateBindings
}
Expand Down
14 changes: 12 additions & 2 deletions ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol

init(roomProxy: JoinedRoomProxyProtocol,
mediaProvider: MediaProviderProtocol,
ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>,
appMediator: AppMediatorProtocol,
appSettings: AppSettings,
analyticsService: AnalyticsService) {
Expand All @@ -68,7 +69,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
bindings: .init()),
mediaProvider: mediaProvider)

setupSubscriptions()
setupSubscriptions(ongoingCallRoomIDPublisher: ongoingCallRoomIDPublisher)
}

override func process(viewAction: RoomScreenViewAction) {
Expand All @@ -93,7 +94,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
state.lastScrollDirection = direction
}

private func setupSubscriptions() {
private func setupSubscriptions(ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never>) {
let roomInfoSubscription = roomProxy
.actionsPublisher
.filter { $0 == .roomInfoUpdate }
Expand Down Expand Up @@ -135,6 +136,14 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
self?.setupPinnedEventsTimelineProviderIfNeeded()
}
.store(in: &cancellables)

ongoingCallRoomIDPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] ongoingCallRoomID in
guard let self else { return }
state.shouldShowCallButton = ongoingCallRoomID != roomProxy.id
}
.store(in: &cancellables)
}

private func buildPinnedEventContents(timelineItems: [TimelineItemProxy]) {
Expand Down Expand Up @@ -186,6 +195,7 @@ extension RoomScreenViewModel {
static func mock(roomProxyMock: JoinedRoomProxyMock) -> RoomScreenViewModel {
RoomScreenViewModel(roomProxy: roomProxyMock,
mediaProvider: MockMediaProvider(),
ongoingCallRoomIDPublisher: .init(.init(nil)),
appMediator: AppMediatorMock.default,
appSettings: ServiceLocator.shared.settings,
analyticsService: ServiceLocator.shared.analytics)
Expand Down
6 changes: 4 additions & 2 deletions ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ struct RoomScreen: View {

if !ProcessInfo.processInfo.isiOSAppOnMac {
ToolbarItem(placement: .primaryAction) {
callButton
.disabled(roomContext.viewState.canJoinCall == false)
if roomContext.viewState.shouldShowCallButton {
callButton
.disabled(roomContext.viewState.canJoinCall == false)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe

private var endUnansweredCallTask: Task<Void, Never>?

private var ongoingCallID: CallID?
private var ongoingCallID: CallID? {
didSet { ongoingCallRoomIDSubject.send(ongoingCallID?.roomID) }
}

var ongoingCallRoomID: String? { ongoingCallID?.roomID }
let ongoingCallRoomIDSubject = CurrentValueSubject<String?, Never>(nil)
var ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never> {
ongoingCallRoomIDSubject.asCurrentValuePublisher()
}

private let actionsSubject: PassthroughSubject<ElementCallServiceAction, Never> = .init()
var actions: AnyPublisher<ElementCallServiceAction, Never> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ enum ElementCallServiceAction {
protocol ElementCallServiceProtocol {
var actions: AnyPublisher<ElementCallServiceAction, Never> { get }

var ongoingCallRoomID: String? { get }
var ongoingCallRoomIDPublisher: CurrentValuePublisher<String?, Never> { get }

func setClientProxy(_ clientProxy: ClientProxyProtocol)

Expand Down
Loading

0 comments on commit ae1facc

Please sign in to comment.