cleanup of the RTCNotificationState enum

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

View file

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

View file

@ -106,10 +106,10 @@ class TimelineItemContentFactory(
is UnableToDecryptContent -> utdFactory.create(itemContent)
is CallNotifyContent -> TimelineItemRtcNotificationContent(
callIntent = itemContent.callIntent,
state = when {
itemContent.declinedBy.isEmpty().not() && itemContent.declinedBy.any { it == sessionId } -> RtcNotificationState.DeclinedByMe
itemContent.declinedBy.isEmpty().not() -> RtcNotificationState.Declined
else -> RtcNotificationState.None
state = if (itemContent.declinedBy.isNotEmpty()) {
RtcNotificationState.Declined(itemContent.declinedBy.any { it == sessionId })
} else {
RtcNotificationState.Started
}
)
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.timeline.item.event.EventType
// For now this is just an enum, but could be a
// sealed class if we need the list of users who declined.
enum class RtcNotificationState {
/** Some users have declined */
Declined,
// State of the call, for now only isDeclined but in the future could be missed, active.
sealed class RtcNotificationState {
/** Some users have declined, byMe indicates if the current user is one of them. */
data class Declined(val byMe: Boolean) : RtcNotificationState()
/** I have declined this call */
DeclinedByMe,
// Future sates could be `Missed`? `ongoing`...
None
object Started : RtcNotificationState()
}
class TimelineItemRtcNotificationContent(

View file

@ -58,10 +58,14 @@ class DefaultMessageSummaryFormatter(
is TimelineItemAudioContent -> context.getString(CommonStrings.common_audio)
is TimelineItemLegacyCallInviteContent -> context.getString(CommonStrings.common_unsupported_call)
is TimelineItemRtcNotificationContent -> when (content.state) {
RtcNotificationState.Declined ->
context.getString(CommonStrings.common_call_declined)
RtcNotificationState.DeclinedByMe -> context.getString(CommonStrings.common_call_you_declined)
RtcNotificationState.None -> context.getString(CommonStrings.common_call_started)
is RtcNotificationState.Declined -> {
if (content.state.byMe) {
context.getString(CommonStrings.common_call_you_declined)
} 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