cleanup of the RTCNotificationState enum

This commit is contained in:
Valere 2026-04-29 16:21:36 +02:00
parent dfbe72ddb7
commit fbb0bb0173
4 changed files with 28 additions and 31 deletions

View file

@ -96,9 +96,10 @@ private fun getTextRes(
content: TimelineItemRtcNotificationContent content: TimelineItemRtcNotificationContent
): Int = if (timelineRoomInfo.isDm) { ): Int = if (timelineRoomInfo.isDm) {
when (content.state) { when (content.state) {
RtcNotificationState.Declined -> CommonStrings.common_call_declined is RtcNotificationState.Declined -> {
RtcNotificationState.DeclinedByMe -> CommonStrings.common_call_you_declined if (content.state.byMe) CommonStrings.common_call_you_declined else CommonStrings.common_call_declined
RtcNotificationState.None -> CommonStrings.common_call_started }
RtcNotificationState.Started -> CommonStrings.common_call_started
} }
} else { } else {
// Only show declined info in DMs // Only show declined info in DMs
@ -110,10 +111,7 @@ private fun getIcon(
timelineRoomInfo: TimelineRoomInfo, timelineRoomInfo: TimelineRoomInfo,
content: TimelineItemRtcNotificationContent content: TimelineItemRtcNotificationContent
): ImageVector { ): ImageVector {
val showAsDeclined = timelineRoomInfo.isDm && ( val showAsDeclined = timelineRoomInfo.isDm && content.state is RtcNotificationState.Declined
content.state == RtcNotificationState.Declined ||
content.state == RtcNotificationState.DeclinedByMe
)
val icon = if (showAsDeclined) { val icon = if (showAsDeclined) {
if (content.callIntent == CallIntent.AUDIO) CompoundIcons.VoiceCallDeclinedSolid() else CompoundIcons.VideoCallDeclinedSolid() if (content.callIntent == CallIntent.AUDIO) CompoundIcons.VoiceCallDeclinedSolid() else CompoundIcons.VideoCallDeclinedSolid()
} else { } else {
@ -127,12 +125,12 @@ private fun getIcon(
internal fun TimelineItemCallNotifyViewPreview() = ElementPreview { internal fun TimelineItemCallNotifyViewPreview() = ElementPreview {
Column(modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) { Column(modifier = Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(16.dp)) {
listOf( listOf(
aTimelineRoomInfo() to TimelineItemRtcNotificationContent(CallIntent.AUDIO, RtcNotificationState.None), aTimelineRoomInfo() to TimelineItemRtcNotificationContent(CallIntent.AUDIO, RtcNotificationState.Started),
aTimelineRoomInfo() to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.None), aTimelineRoomInfo() to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.Started),
aTimelineRoomInfo(isDm = true) to TimelineItemRtcNotificationContent(CallIntent.AUDIO, RtcNotificationState.Declined), aTimelineRoomInfo(isDm = true) to TimelineItemRtcNotificationContent(CallIntent.AUDIO, RtcNotificationState.Declined(false)),
aTimelineRoomInfo(isDm = true) to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.Declined), aTimelineRoomInfo(isDm = true) to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.Declined(false)),
aTimelineRoomInfo(isDm = true) to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.DeclinedByMe), aTimelineRoomInfo(isDm = true) to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.Declined(true)),
aTimelineRoomInfo(isDm = false) to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.None), aTimelineRoomInfo(isDm = false) to TimelineItemRtcNotificationContent(CallIntent.VIDEO, RtcNotificationState.Started),
).forEach { (info, content) -> ).forEach { (info, content) ->
TimelineItemCallNotifyView( TimelineItemCallNotifyView(
timelineRoomInfo = info, timelineRoomInfo = info,

View file

@ -106,10 +106,10 @@ class TimelineItemContentFactory(
is UnableToDecryptContent -> utdFactory.create(itemContent) is UnableToDecryptContent -> utdFactory.create(itemContent)
is CallNotifyContent -> TimelineItemRtcNotificationContent( is CallNotifyContent -> TimelineItemRtcNotificationContent(
callIntent = itemContent.callIntent, callIntent = itemContent.callIntent,
state = when { state = if (itemContent.declinedBy.isNotEmpty()) {
itemContent.declinedBy.isEmpty().not() && itemContent.declinedBy.any { it == sessionId } -> RtcNotificationState.DeclinedByMe RtcNotificationState.Declined(itemContent.declinedBy.any { it == sessionId })
itemContent.declinedBy.isEmpty().not() -> RtcNotificationState.Declined } else {
else -> RtcNotificationState.None RtcNotificationState.Started
} }
) )
is UnknownContent -> TimelineItemUnknownContent is UnknownContent -> TimelineItemUnknownContent

View file

@ -11,17 +11,12 @@ package io.element.android.features.messages.impl.timeline.model.event
import io.element.android.libraries.matrix.api.notification.CallIntent import io.element.android.libraries.matrix.api.notification.CallIntent
import io.element.android.libraries.matrix.api.timeline.item.event.EventType import io.element.android.libraries.matrix.api.timeline.item.event.EventType
// For now this is just an enum, but could be a // State of the call, for now only isDeclined but in the future could be missed, active.
// sealed class if we need the list of users who declined. sealed class RtcNotificationState {
enum class RtcNotificationState { /** Some users have declined, byMe indicates if the current user is one of them. */
/** Some users have declined */ data class Declined(val byMe: Boolean) : RtcNotificationState()
Declined,
/** I have declined this call */ object Started : RtcNotificationState()
DeclinedByMe,
// Future sates could be `Missed`? `ongoing`...
None
} }
class TimelineItemRtcNotificationContent( class TimelineItemRtcNotificationContent(

View file

@ -58,10 +58,14 @@ class DefaultMessageSummaryFormatter(
is TimelineItemAudioContent -> context.getString(CommonStrings.common_audio) is TimelineItemAudioContent -> context.getString(CommonStrings.common_audio)
is TimelineItemLegacyCallInviteContent -> context.getString(CommonStrings.common_unsupported_call) is TimelineItemLegacyCallInviteContent -> context.getString(CommonStrings.common_unsupported_call)
is TimelineItemRtcNotificationContent -> when (content.state) { is TimelineItemRtcNotificationContent -> when (content.state) {
RtcNotificationState.Declined -> is RtcNotificationState.Declined -> {
context.getString(CommonStrings.common_call_declined) if (content.state.byMe) {
RtcNotificationState.DeclinedByMe -> context.getString(CommonStrings.common_call_you_declined) context.getString(CommonStrings.common_call_you_declined)
RtcNotificationState.None -> context.getString(CommonStrings.common_call_started) } else {
context.getString(CommonStrings.common_call_declined)
}
}
RtcNotificationState.Started -> context.getString(CommonStrings.common_call_started)
} }
} }
// Truncate the message to a safe length to avoid crashes in Compose // Truncate the message to a safe length to avoid crashes in Compose