feat: Update call started timeline item + declined support

This commit is contained in:
Valere 2026-04-24 11:37:00 +02:00
parent d215354e64
commit f0dc4eeace
9 changed files with 138 additions and 42 deletions

View file

@ -55,6 +55,7 @@ class DefaultRoomLatestEventFormatter(
private val profileChangeContentFormatter: ProfileChangeContentFormatter,
private val stateContentFormatter: StateContentFormatter,
private val permalinkParser: PermalinkParser,
private val rtcNotificationContentFormatter: RtcNotificationContentFormatter,
) : RoomLatestEventFormatter {
override fun format(
latestEvent: LatestEventValue.Local,
@ -121,7 +122,7 @@ class DefaultRoomLatestEventFormatter(
message.prefixIfNeeded(senderDisambiguatedDisplayName, isDmRoom, isOutgoing)
}
is LegacyCallInviteContent -> sp.getString(CommonStrings.common_unsupported_call)
is CallNotifyContent -> sp.getString(CommonStrings.common_call_started)
is CallNotifyContent -> rtcNotificationContentFormatter.format(content, isDmRoom)
}?.take(DEFAULT_SAFE_LENGTH)
}

View file

@ -0,0 +1,39 @@
/*
* Copyright (c) 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.
*/
package io.element.android.libraries.eventformatter.impl
import dev.zacsweers.metro.Inject
import io.element.android.libraries.matrix.api.MatrixClient
import io.element.android.libraries.matrix.api.timeline.item.event.CallNotifyContent
import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.services.toolbox.api.strings.StringProvider
@Inject
class RtcNotificationContentFormatter(
private val matrixClient: MatrixClient,
private val sp: StringProvider,
) {
fun format(
content: CallNotifyContent,
isDm: Boolean,
): CharSequence {
return if (isDm) {
val isDeclined = content.declinedBy.isNotEmpty()
val isDeclinedByMe = content.declinedBy.any { matrixClient.isMe(it) }
if (isDeclinedByMe) {
sp.getString(CommonStrings.common_call_you_declined)
} else if (isDeclined) {
sp.getString(CommonStrings.common_call_declined)
} else {
sp.getString(CommonStrings.common_call_started)
}
} else {
sp.getString(CommonStrings.common_call_started)
}
}
}