Aggregate voice broadcast state events
This commit is contained in:
parent
b286a52f5b
commit
cc1bb23406
|
@ -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.LocationPinProvider
|
||||||
import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory
|
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.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.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.AbsMessageItem
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.MessageAudioItem
|
import im.vector.app.features.home.room.detail.timeline.item.MessageAudioItem
|
||||||
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.settings.VectorPreferences
|
||||||
import im.vector.app.features.voice.AudioWaveformView
|
import im.vector.app.features.voice.AudioWaveformView
|
||||||
import im.vector.app.features.voicebroadcast.model.MessageVoiceBroadcastInfoContent
|
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 im.vector.lib.core.utils.epoxy.charsequence.toEpoxyCharSequence
|
||||||
import me.gujun.android.span.span
|
import me.gujun.android.span.span
|
||||||
import org.matrix.android.sdk.api.MatrixUrls.isMxcUrl
|
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 MessagePollContent -> buildPollItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
is MessageLocationContent -> buildLocationItem(messageContent, informationData, highlight, attributes)
|
is MessageLocationContent -> buildLocationItem(messageContent, informationData, highlight, attributes)
|
||||||
is MessageBeaconInfoContent -> liveLocationShareMessageItemFactory.create(params.event, 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)
|
else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback, attributes)
|
||||||
}
|
}
|
||||||
return messageItem?.apply {
|
return messageItem?.apply {
|
||||||
|
@ -712,14 +715,19 @@ class MessageItemFactory @Inject constructor(
|
||||||
|
|
||||||
private fun buildVoiceBroadcastItem(
|
private fun buildVoiceBroadcastItem(
|
||||||
messageContent: MessageVoiceBroadcastInfoContent,
|
messageContent: MessageVoiceBroadcastInfoContent,
|
||||||
|
eventsGroup: TimelineEventsGroup?,
|
||||||
highlight: Boolean,
|
highlight: Boolean,
|
||||||
callback: TimelineEventController.Callback?,
|
callback: TimelineEventController.Callback?,
|
||||||
attributes: AbsMessageItem.Attributes,
|
attributes: AbsMessageItem.Attributes,
|
||||||
): MessageVoiceBroadcastItem? {
|
): 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_()
|
return MessageVoiceBroadcastItem_()
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
.highlighted(highlight)
|
.highlighted(highlight)
|
||||||
.voiceBroadcastState(messageContent.voiceBroadcastState)
|
.voiceBroadcastState(mostRecentMessageContent.voiceBroadcastState)
|
||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||||
.callback(callback)
|
.callback(callback)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
package im.vector.app.features.home.room.detail.timeline.helper
|
package im.vector.app.features.home.room.detail.timeline.helper
|
||||||
|
|
||||||
import im.vector.app.core.utils.TextUtils
|
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.extensions.orFalse
|
||||||
import org.matrix.android.sdk.api.session.events.model.EventType
|
import org.matrix.android.sdk.api.session.events.model.EventType
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
|
@ -54,14 +57,20 @@ class TimelineEventsGroups {
|
||||||
private fun TimelineEvent.getGroupIdOrNull(): String? {
|
private fun TimelineEvent.getGroupIdOrNull(): String? {
|
||||||
val type = root.getClearType()
|
val type = root.getClearType()
|
||||||
val content = root.getClearContent()
|
val content = root.getClearContent()
|
||||||
return if (EventType.isCallEvent(type)) {
|
return when {
|
||||||
(content?.get("call_id") as? String)
|
EventType.isCallEvent(type) -> (content?.get("call_id") as? String)
|
||||||
} else if (type == EventType.STATE_ROOM_WIDGET || type == EventType.STATE_ROOM_WIDGET_LEGACY) {
|
type == STATE_ROOM_VOICE_BROADCAST_INFO -> {
|
||||||
root.stateKey
|
root.content.toModel<MessageVoiceBroadcastInfoContent>()
|
||||||
} else {
|
?.takeUnless { it.voiceBroadcastState == VoiceBroadcastState.STARTED }
|
||||||
|
?.relatesTo?.eventId
|
||||||
|
?: eventId
|
||||||
|
}
|
||||||
|
type == EventType.STATE_ROOM_WIDGET || type == EventType.STATE_ROOM_WIDGET_LEGACY -> root.stateKey
|
||||||
|
else -> {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun clear() {
|
fun clear() {
|
||||||
groups.clear()
|
groups.clear()
|
||||||
|
@ -128,3 +137,11 @@ class CallSignalingEventsGroup(private val group: TimelineEventsGroup) {
|
||||||
return group.events.firstOrNull { it.root.getClearType() == EventType.CALL_REJECT }
|
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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@ abstract class MessageVoiceBroadcastItem : AbsMessageItem<MessageVoiceBroadcastI
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var voiceBroadcastState: VoiceBroadcastState? = null
|
var voiceBroadcastState: VoiceBroadcastState? = null
|
||||||
|
|
||||||
|
override fun isCacheable(): Boolean = false
|
||||||
|
|
||||||
override fun bind(holder: Holder) {
|
override fun bind(holder: Holder) {
|
||||||
super.bind(holder)
|
super.bind(holder)
|
||||||
bindVoiceBroadcastItem(holder)
|
bindVoiceBroadcastItem(holder)
|
||||||
|
|
Loading…
Reference in New Issue