Aggregate voice broadcast state events

This commit is contained in:
Florian Renaud 2022-10-04 11:22:20 +02:00
parent b286a52f5b
commit cc1bb23406
3 changed files with 35 additions and 8 deletions

View file

@ -43,7 +43,9 @@ import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStat
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider
import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory
import im.vector.app.features.home.room.detail.timeline.helper.MessageItemAttributesFactory
import im.vector.app.features.home.room.detail.timeline.helper.TimelineEventsGroup
import im.vector.app.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
import im.vector.app.features.home.room.detail.timeline.helper.VoiceBroadcastEventsGroup
import im.vector.app.features.home.room.detail.timeline.item.AbsMessageItem
import im.vector.app.features.home.room.detail.timeline.item.MessageAudioItem
import im.vector.app.features.home.room.detail.timeline.item.MessageAudioItem_
@ -81,6 +83,7 @@ import im.vector.app.features.media.VideoContentRenderer
import im.vector.app.features.settings.VectorPreferences
import im.vector.app.features.voice.AudioWaveformView
import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent
import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState
import im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
import me.gujun.android.span.span
import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl
@ -200,7 +203,7 @@ class MessageItemFactory @Inject constructor(
is MessagePollContent -> buildPollItem(messageContent, informationData, highlight, callback, attributes)
is MessageLocationContent -> buildLocationItem(messageContent, informationData, highlight, attributes)
is MessageBeaconInfoContent -> liveLocationShareMessageItemFactory.create(params.event, highlight, attributes)
is MessageVoiceBroadcastInfoContent -> buildVoiceBroadcastItem(messageContent, highlight, callback, attributes)
is MessageVoiceBroadcastInfoContent -> buildVoiceBroadcastItem(messageContent, params.eventsGroup, highlight, callback, attributes)
else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback, attributes)
}
return messageItem?.apply {
@ -712,14 +715,19 @@ class MessageItemFactory @Inject constructor(
private fun buildVoiceBroadcastItem(
messageContent: MessageVoiceBroadcastInfoContent,
eventsGroup: TimelineEventsGroup?,
highlight: Boolean,
callback: TimelineEventController.Callback?,
attributes: AbsMessageItem.Attributes,
): MessageVoiceBroadcastItem? {
if (messageContent.voiceBroadcastState != VoiceBroadcastState.STARTED) return null
val voiceBroadcastEventsGroup = eventsGroup?.let { VoiceBroadcastEventsGroup(it) } ?: return null
val mostRecentEvent = voiceBroadcastEventsGroup.getLastEvent()
val mostRecentMessageContent = (mostRecentEvent.getVectorLastMessageContent() as? MessageVoiceBroadcastInfoContent) ?: return null
return MessageVoiceBroadcastItem_()
.attributes(attributes)
.highlighted(highlight)
.voiceBroadcastState(messageContent.voiceBroadcastState)
.voiceBroadcastState(mostRecentMessageContent.voiceBroadcastState)
.leftGuideline(avatarSizeProvider.leftGuideline)
.callback(callback)
}

View file

@ -17,6 +17,9 @@
package im.vector.app.features.home.room.detail.timeline.helper
import im.vector.app.core.utils.TextUtils
import im.vector.app.features.voicebroadcast.STATE_ROOM_VOICE_BROADCAST_INFO
import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent
import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.session.events.model.EventType
import org.matrix.android.sdk.api.session.events.model.toModel
@ -54,12 +57,18 @@ class TimelineEventsGroups {
private fun TimelineEvent.getGroupIdOrNull(): String? {
val type = root.getClearType()
val content = root.getClearContent()
return if (EventType.isCallEvent(type)) {
(content?.get("call_id") as? String)
} else if (type == EventType.STATE_ROOM_WIDGET || type == EventType.STATE_ROOM_WIDGET_LEGACY) {
root.stateKey
} else {
null
return when {
EventType.isCallEvent(type) -> (content?.get("call_id") as? String)
type == STATE_ROOM_VOICE_BROADCAST_INFO -> {
root.content.toModel<MessageVoiceBroadcastInfoContent>()
?.takeUnless { it.voiceBroadcastState == VoiceBroadcastState.STARTED }
?.relatesTo?.eventId
?: eventId
}
type == EventType.STATE_ROOM_WIDGET || type == EventType.STATE_ROOM_WIDGET_LEGACY -> root.stateKey
else -> {
null
}
}
}
@ -128,3 +137,11 @@ class CallSignalingEventsGroup(private val group: TimelineEventsGroup) {
return group.events.firstOrNull { it.root.getClearType() == EventType.CALL_REJECT }
}
}
class VoiceBroadcastEventsGroup(private val group: TimelineEventsGroup) {
fun getLastEvent(): TimelineEvent {
return group.events
.find { it.root.getClearContent().toModel<MessageVoiceBroadcastInfoContent>()?.voiceBroadcastState == VoiceBroadcastState.STOPPED }
?: group.events.maxBy { it.root.originServerTs ?: 0L }
}
}

View file

@ -35,6 +35,8 @@ abstract class MessageVoiceBroadcastItem : AbsMessageItem<MessageVoiceBroadcastI
@EpoxyAttribute
var voiceBroadcastState: VoiceBroadcastState? = null
override fun isCacheable(): Boolean = false
override fun bind(holder: Holder) {
super.bind(holder)
bindVoiceBroadcastItem(holder)