Skip to content

Commit

Permalink
Use VoiceBroadcastEvent wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Renaud committed Oct 6, 2022
1 parent d596a46 commit 2813300
Showing 1 changed file with 3 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ 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 im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent
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
Expand Down Expand Up @@ -59,12 +59,7 @@ class TimelineEventsGroups {
val content = root.getClearContent()
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 == STATE_ROOM_VOICE_BROADCAST_INFO -> root.asVoiceBroadcastEvent()?.reference?.eventId
type == EventType.STATE_ROOM_WIDGET || type == EventType.STATE_ROOM_WIDGET_LEGACY -> root.stateKey
else -> {
null
Expand Down Expand Up @@ -140,8 +135,7 @@ class CallSignalingEventsGroup(private val group: TimelineEventsGroup) {

class VoiceBroadcastEventsGroup(private val group: TimelineEventsGroup) {
fun getLastEvent(): TimelineEvent {
return group.events
.find { it.root.getClearContent().toModel<MessageVoiceBroadcastInfoContent>()?.voiceBroadcastState == VoiceBroadcastState.STOPPED }
return group.events.find { it.root.asVoiceBroadcastEvent()?.content?.voiceBroadcastState == VoiceBroadcastState.STOPPED }
?: group.events.maxBy { it.root.originServerTs ?: 0L }
}
}

0 comments on commit 2813300

Please sign in to comment.