Support for ongoing voice vs video call + joining (#5399)

This commit is contained in:
Valere Fedronic
2026-04-21 11:11:52 +02:00
committed by GitHub
parent d9013208dd
commit d49a6e5a5d
31 changed files with 185 additions and 54 deletions
@@ -719,8 +719,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
stateMachine.tryEvent(.startMembersFlow(entryPoint: .roomMember(userID: userID)))
case .presentMessageForwarding(let forwardingItem):
stateMachine.tryEvent(.presentMessageForwarding(forwardingItem: forwardingItem))
case .presentCallScreen:
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: false))
case .presentCallScreen(let isVoiceCall):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: isVoiceCall))
case .presentPinnedEventsTimeline:
stateMachine.tryEvent(.presentPinnedEventsTimeline)
case .presentResolveSendFailure(failure: let failure, sendHandle: let sendHandle):
@@ -529,8 +529,8 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
guard let self else { return }
switch action {
case .presentCallScreen(let roomProxy, _):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: false))
case .presentCallScreen(let roomProxy, let isVoiceCall):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: isVoiceCall))
case .verifyUser(let userID):
actionsSubject.send(.verifyUser(userID: userID))
case .continueWithSpaceFlow(let spaceRoomListProxy):
@@ -557,8 +557,8 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
switch actions {
case .finished:
stateMachine.tryEvent(.stopMembersFlow)
case .presentCallScreen(let roomProxy, _):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: false))
case .presentCallScreen(let roomProxy, let isVoiceCall):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: isVoiceCall))
case .verifyUser(let userID):
actionsSubject.send(.verifyUser(userID: userID))
}
@@ -581,8 +581,8 @@ class SpaceFlowCoordinator: FlowCoordinatorProtocol {
if leftRoom {
stateMachine.tryEvent(.leftSpace)
}
case .presentCallScreen(let roomProxy):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: false))
case .presentCallScreen(let roomProxy, let isVoiceCall):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: isVoiceCall))
case .verifyUser(userID: let userID):
actionsSubject.send(.verifyUser(userID: userID))
}
@@ -11,7 +11,7 @@ import SwiftState
enum SpaceSettingsFlowCoordinatorAction {
case finished(leftRoom: Bool)
case presentCallScreen(roomProxy: JoinedRoomProxyProtocol)
case presentCallScreen(roomProxy: JoinedRoomProxyProtocol, isVoiceCall: Bool)
case verifyUser(userID: String)
}
@@ -395,8 +395,8 @@ final class SpaceSettingsFlowCoordinator: FlowCoordinatorProtocol {
switch action {
case .finished:
stateMachine.tryEvent(.stopMembersListFlow)
case .presentCallScreen(let roomProxy, _):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy))
case .presentCallScreen(let roomProxy, let isVoiceCall):
actionsSubject.send(.presentCallScreen(roomProxy: roomProxy, isVoiceCall: isVoiceCall))
case .verifyUser(let userID):
actionsSubject.send(.verifyUser(userID: userID))
}
@@ -15238,6 +15238,7 @@ class RoomInfoProxyMock: RoomInfoProxyProtocol, @unchecked Sendable {
set(value) { underlyingHasRoomCall = value }
}
var underlyingHasRoomCall: Bool!
var activeRoomCallIntent: CallIntent?
var activeRoomCallParticipants: [String] = []
var isMarkedUnread: Bool {
get { return underlyingIsMarkedUnread }
@@ -92,6 +92,7 @@ extension RoomSummary {
canonicalAlias: canonicalAlias,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -119,6 +120,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -141,6 +143,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: "#foundation-and-empire:matrix.org",
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -163,6 +166,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -185,6 +189,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -207,6 +212,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: true,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -229,6 +235,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: "#prelude-foundation:matrix.org",
alternativeAliases: [],
hasOngoingCall: true,
activeCallIntent: .audio,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -251,6 +258,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: true),
@@ -273,6 +281,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -328,6 +337,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: "#footest:somewhere.org",
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -350,6 +360,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -375,6 +386,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: "#footest:somewhere.org",
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false),
@@ -397,6 +409,7 @@ extension Array where Element == RoomSummary {
canonicalAlias: nil,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -0,0 +1,30 @@
//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
import MatrixRustSDK
enum CallIntent: Codable, CaseIterable {
case video, audio
}
extension CallIntent {
// periphery:ignore - Unused, but added to detect new cases when updating the SDK.
init(rustCallIntent: MatrixRustSDK.RtcCallIntent) {
switch rustCallIntent {
case .audio: self = .audio
case .video: self = .video
}
}
var rustCallIntent: MatrixRustSDK.RtcCallIntent {
switch self {
case .audio: .audio
case .video: .video
}
}
}
@@ -10,8 +10,9 @@ import Compound
import SwiftUI
struct JoinCallButton: View {
let isVoiceCall: Bool
let action: () -> Void
var body: some View {
if #available(iOS 26, *) {
glassButton
@@ -25,7 +26,7 @@ struct JoinCallButton: View {
// Use an HStack on iOS 26 as .labelStyle(.titleAndIcon) doesn't
// seem to have any effect on a label in the navigation bar 🤷‍♂️
HStack(spacing: 6) {
CompoundIcon(\.videoCallSolid)
CompoundIcon(isVoiceCall ? \.voiceCallSolid : \.videoCallSolid)
Text(L10n.actionJoin)
.padding(.trailing, 4)
}
@@ -66,9 +67,20 @@ struct JoinCallButton_Previews: PreviewProvider {
Color.clear
.toolbar {
ToolbarItem(placement: .confirmationAction) {
JoinCallButton { }
JoinCallButton(isVoiceCall: false) { }
}
}
}
.previewDisplayName("Join Video Call")
ElementNavigationStack {
Color.clear
.toolbar {
ToolbarItem(placement: .confirmationAction) {
JoinCallButton(isVoiceCall: true) { }
}
}
}
.previewDisplayName("Join Audio Call")
}
}
@@ -160,6 +160,10 @@ struct HomeScreenViewStateBindings {
var spaceFiltersViewModel: ChatsSpaceFiltersScreenViewModel?
}
enum CallBadgeType {
case voice, video, none
}
struct HomeScreenRoom: Identifiable, Equatable {
enum RoomType: Equatable {
case placeholder
@@ -190,7 +194,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
let isDotShown: Bool
let isMentionShown: Bool
let isMuteShown: Bool
let isCallShown: Bool
let callBadgeType: CallBadgeType
}
let name: String
@@ -228,7 +232,7 @@ struct HomeScreenRoom: Identifiable, Equatable {
HomeScreenRoom(id: UUID().uuidString,
roomID: nil,
type: .placeholder,
badges: .init(isDotShown: false, isMentionShown: false, isMuteShown: false, isCallShown: false),
badges: .init(isDotShown: false, isMentionShown: false, isMuteShown: false, callBadgeType: .none),
name: "Placeholder room name",
isDirect: false,
isHighlighted: false,
@@ -252,9 +256,12 @@ extension HomeScreenRoom {
let isDotShown = hasUnreadMessages || summary.hasUnreadMentions || summary.hasUnreadNotifications || summary.isMarkedUnread || isUnseenInvite
let isMentionShown = summary.hasUnreadMentions && !summary.isMuted
let isMuteShown = summary.isMuted
let isCallShown = summary.hasOngoingCall
let isHighlighted = summary.isMarkedUnread || (!summary.isMuted && (summary.hasUnreadNotifications || summary.hasUnreadMentions)) || isUnseenInvite
let callBadge = if summary.hasOngoingCall {
summary.activeCallIntent == .audio ? CallBadgeType.voice : CallBadgeType.video
} else { CallBadgeType.none }
let type: HomeScreenRoom.RoomType = switch summary.joinRequestType {
case .invite(let inviter): .invite(inviterDetails: inviter.map(RoomInviterDetails.init))
case .knock: .knock
@@ -267,7 +274,7 @@ extension HomeScreenRoom {
badges: .init(isDotShown: isDotShown,
isMentionShown: isMentionShown,
isMuteShown: isMuteShown,
isCallShown: isCallShown),
callBadgeType: callBadge),
name: summary.name,
isDirect: summary.isDirect,
isHighlighted: isHighlighted,
@@ -235,6 +235,7 @@ private extension HomeScreenRoom {
canonicalAlias: "#footest:somewhere.org",
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -270,6 +271,7 @@ private extension HomeScreenRoom {
canonicalAlias: alias,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -167,6 +167,7 @@ private extension HomeScreenRoom {
canonicalAlias: "#footest:somewhere.org",
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -199,6 +200,7 @@ private extension HomeScreenRoom {
canonicalAlias: alias,
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -119,11 +119,16 @@ struct HomeScreenRoomCell: View {
Spacer()
HStack(spacing: 8) {
if room.badges.isCallShown {
CompoundIcon(\.videoCallSolid, size: .xSmall, relativeTo: .compound.bodySM)
if room.badges.callBadgeType == .voice {
CompoundIcon(\.voiceCallSolid, size: .xSmall, relativeTo: .compound.bodySM)
.accessibilityLabel(L10n.a11yNotificationsOngoingCall)
}
if room.badges.callBadgeType == .video {
CompoundIcon(\.videoCallSolid, size: .xSmall, relativeTo: .compound.bodySM)
.accessibilityLabel(L10n.a11yNotificationsOngoingCall)
}
if room.badges.isMuteShown {
CompoundIcon(\.notificationsOffSolid, size: .custom(15), relativeTo: .compound.bodyMD)
.accessibilityLabel(L10n.a11yNotificationsMuted)
@@ -253,6 +258,7 @@ struct HomeScreenRoomCell_Previews: PreviewProvider, TestablePreview {
canonicalAlias: "#foundation-and-empire:matrix.org",
alternativeAliases: [],
hasOngoingCall: false,
activeCallIntent: nil,
isMarkedUnread: false,
isFavourite: false,
isTombstoned: false)
@@ -7,7 +7,6 @@
//
import Foundation
import MatrixRustSDK
import OrderedCollections
enum RoomScreenViewModelAction: Equatable {
@@ -60,6 +59,8 @@ struct RoomScreenViewState: BindableState {
var canJoinCall = false
/// Whether or not this room currently has a call in progress.
var hasOngoingCall: Bool
/// The ongoing call nature (audio or video), null if not advertised by the participants
var activeRoomCallIntent: CallIntent?
/// Whether or not the user is already part of a call in another room.
var isParticipatingInOngoingCall = false
var shouldShowCallButton: Bool {
@@ -345,6 +345,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
state.roomTitle = roomInfo.displayName ?? roomProxy.id
state.roomAvatar = roomInfo.avatar
state.hasOngoingCall = roomInfo.hasRoomCall
state.activeRoomCallIntent = roomInfo.activeRoomCallIntent
state.hasSuccessor = roomInfo.successor != nil
let pinnedEventIDs = roomInfo.pinnedEventIDs
@@ -15,8 +15,8 @@ struct RoomCallControlsToolbar: ToolbarContent {
var body: some ToolbarContent {
if viewState.hasOngoingCall {
ToolbarItem(placement: .primaryAction) {
JoinCallButton {
onCallTap(false)
JoinCallButton(isVoiceCall: viewState.activeRoomCallIntent == .audio) {
onCallTap(viewState.activeRoomCallIntent == .audio)
}
.accessibilityIdentifier(A11yIdentifiers.roomScreen.joinCall)
.disabled(!viewState.canJoinCall)
@@ -61,16 +61,21 @@ struct RoomCallControlsToolbar_Previews: PreviewProvider {
ElementNavigationStack {
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: false, canJoinCall: false)) { _ in } }
}
ElementNavigationStack {
Color.clear.toolbar { RoomCallControlsToolbar(viewState: .mock(hasOngoingCall: true, activeRoomCallIntent: .audio)) { _ in } }
}
}
.previewDisplayName("All states")
}
}
private extension RoomScreenViewState {
static func mock(hasOngoingCall: Bool, isDirectOneToOneRoom: Bool = false, canJoinCall: Bool = true) -> RoomScreenViewState {
static func mock(hasOngoingCall: Bool, isDirectOneToOneRoom: Bool = false, canJoinCall: Bool = true, activeRoomCallIntent: CallIntent? = nil) -> RoomScreenViewState {
RoomScreenViewState(roomAvatar: .room(id: "mock", name: "Mock Room", avatarURL: nil),
canJoinCall: canJoinCall,
hasOngoingCall: hasOngoingCall, isDirectOneToOneRoom: isDirectOneToOneRoom,
hasOngoingCall: hasOngoingCall,
activeRoomCallIntent: activeRoomCallIntent,
isDirectOneToOneRoom: isDirectOneToOneRoom,
hasSuccessor: false)
}
}
@@ -110,6 +110,17 @@ struct RoomInfoProxy: RoomInfoProxyProtocol {
roomInfo.hasRoomCall
}
var activeRoomCallIntent: CallIntent? {
switch roomInfo.activeRoomCallConsensusIntent {
case .full(let intent):
return .init(rustCallIntent: intent)
case .partial(intent: let intent, _, _):
return .init(rustCallIntent: intent)
case .none:
return nil
}
}
var activeRoomCallParticipants: [String] {
roomInfo.activeRoomCallParticipants
}
@@ -51,6 +51,7 @@ protocol RoomInfoProxyProtocol: BaseRoomInfoProxyProtocol {
var notificationCount: Int { get }
var cachedUserDefinedNotificationMode: RoomNotificationMode? { get }
var hasRoomCall: Bool { get }
var activeRoomCallIntent: CallIntent? { get }
var activeRoomCallParticipants: [String] { get }
var isMarkedUnread: Bool { get }
var unreadMessagesCount: UInt { get }
@@ -57,6 +57,7 @@ struct RoomSummary {
let alternativeAliases: Set<String>
let hasOngoingCall: Bool
let activeCallIntent: CallIntent?
let isMarkedUnread: Bool
let isFavourite: Bool
@@ -140,6 +141,7 @@ extension RoomSummary {
canonicalAlias = nil
alternativeAliases = []
hasOngoingCall = false
activeCallIntent = nil
joinRequestType = nil
isMarkedUnread = false
@@ -313,6 +313,15 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
default: nil
}
let activeCallIntent: RtcCallIntent? = switch roomInfo.activeRoomCallConsensusIntent {
case .full(let intent):
intent
case .partial(intent: let intent, _, _):
intent
case .none:
nil
}
return RoomSummary(room: room,
id: roomInfo.id,
joinRequestType: joinRequestType,
@@ -332,6 +341,7 @@ class RoomSummaryProvider: RoomSummaryProviderProtocol {
canonicalAlias: roomInfo.canonicalAlias,
alternativeAliases: .init(roomInfo.alternativeAliases),
hasOngoingCall: roomInfo.hasRoomCall,
activeCallIntent: activeCallIntent.map { .init(rustCallIntent: $0) },
isMarkedUnread: roomInfo.isMarkedUnread,
isFavourite: roomInfo.isFavourite,
isTombstoned: roomInfo.successorRoom != nil)