Voice Broadcast - Hide related voice message events

This commit is contained in:
Florian Renaud 2022-10-17 11:21:15 +02:00
parent ce14270fab
commit 5f35926ce6
3 changed files with 19 additions and 4 deletions

View File

@ -31,6 +31,7 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageContent
import org.matrix.android.sdk.api.session.room.model.message.MessagePollContent
import org.matrix.android.sdk.api.session.room.model.message.MessageStickerContent
import org.matrix.android.sdk.api.session.room.model.message.MessageType
import org.matrix.android.sdk.api.session.room.model.message.asMessageAudioEvent
import org.matrix.android.sdk.api.session.room.model.relation.RelationDefaultContent
import org.matrix.android.sdk.api.session.room.model.relation.shouldRenderInThread
import org.matrix.android.sdk.api.session.room.send.SendState
@ -357,6 +358,10 @@ fun Event.isAudioMessage(): Boolean {
}
}
fun Event.isVoiceMessage(): Boolean {
return this.asMessageAudioEvent()?.content?.voiceMessageIndicator != null
}
fun Event.isFileMessage(): Boolean {
return when (getMsgType()) {
MessageType.MSGTYPE_FILE -> true

View File

@ -323,7 +323,10 @@ class MessageItemFactory @Inject constructor(
informationData: MessageInformationData,
highlight: Boolean,
attributes: AbsMessageItem.Attributes
): MessageVoiceItem {
): MessageVoiceItem? {
val eventsGroup = params.eventsGroup?.let { VoiceBroadcastEventsGroup(it) }
if (eventsGroup != null && eventsGroup.getLastDisplayableEvent().eventId != params.event.eventId) return null
val fileUrl = getAudioFileUrl(messageContent, informationData)
val playbackControlButtonClickListener = createOnPlaybackButtonClickListener(messageContent, informationData, params)
@ -722,7 +725,7 @@ class MessageItemFactory @Inject constructor(
): MessageVoiceBroadcastItem? {
if (messageContent.voiceBroadcastState != VoiceBroadcastState.STARTED) return null
val voiceBroadcastEventsGroup = eventsGroup?.let { VoiceBroadcastEventsGroup(it) } ?: return null
val mostRecentEvent = voiceBroadcastEventsGroup.getLastEvent()
val mostRecentEvent = voiceBroadcastEventsGroup.getLastDisplayableEvent()
val mostRecentMessageContent = (mostRecentEvent.getVectorLastMessageContent() as? MessageVoiceBroadcastInfoContent) ?: return null
return MessageVoiceBroadcastItem_()
.attributes(attributes)

View File

@ -22,6 +22,9 @@ 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.RelationType
import org.matrix.android.sdk.api.session.events.model.getRelationContent
import org.matrix.android.sdk.api.session.events.model.isVoiceMessage
import org.matrix.android.sdk.api.session.events.model.toModel
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
@ -61,6 +64,10 @@ class TimelineEventsGroups {
EventType.isCallEvent(type) -> (content?.get("call_id") as? String)
type == VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO -> root.asVoiceBroadcastEvent()?.reference?.eventId
type == EventType.STATE_ROOM_WIDGET || type == EventType.STATE_ROOM_WIDGET_LEGACY -> root.stateKey
type == EventType.MESSAGE && root.isVoiceMessage() -> {
// Group voice messages with a reference to an eventId
root.getRelationContent()?.takeIf { it.type == RelationType.REFERENCE }?.eventId
}
else -> {
null
}
@ -134,8 +141,8 @@ class CallSignalingEventsGroup(private val group: TimelineEventsGroup) {
}
class VoiceBroadcastEventsGroup(private val group: TimelineEventsGroup) {
fun getLastEvent(): TimelineEvent {
fun getLastDisplayableEvent(): TimelineEvent {
return group.events.find { it.root.asVoiceBroadcastEvent()?.content?.voiceBroadcastState == VoiceBroadcastState.STOPPED }
?: group.events.maxBy { it.root.originServerTs ?: 0L }
?: group.events.filter { it.root.type == VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO }.maxBy { it.root.originServerTs ?: 0L }
}
}