From 61548167967e18b4e217af6d75dff5bee13cf39b Mon Sep 17 00:00:00 2001 From: Valere Date: Wed, 29 Apr 2026 16:21:36 +0200 Subject: [PATCH] cleanup of the RTCNotificationState enum --- .../components/TimelineItemCallNotifyView.kt | 24 +++++++++---------- .../event/TimelineItemContentFactory.kt | 8 +++---- .../TimelineItemRtcNotificationContent.kt | 15 ++++-------- .../DefaultMessageSummaryFormatter.kt | 12 ++++++---- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemCallNotifyView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemCallNotifyView.kt index c11aab08ff..f4d0d97495 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemCallNotifyView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/components/TimelineItemCallNotifyView.kt @@ -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, diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentFactory.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentFactory.kt index 64320622ba..2d884d75fd 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentFactory.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/factories/event/TimelineItemContentFactory.kt @@ -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 diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemRtcNotificationContent.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemRtcNotificationContent.kt index df1c9f5693..c09ccd1d21 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemRtcNotificationContent.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/model/event/TimelineItemRtcNotificationContent.kt @@ -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( diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/DefaultMessageSummaryFormatter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/DefaultMessageSummaryFormatter.kt index 5437711bb7..210e123595 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/DefaultMessageSummaryFormatter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/utils/messagesummary/DefaultMessageSummaryFormatter.kt @@ -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