Voice Broadcast - Hide related voice message events
This commit is contained in:
parent
ce14270fab
commit
5f35926ce6
|
@ -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.MessagePollContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageStickerContent
|
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.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.RelationDefaultContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.relation.shouldRenderInThread
|
import org.matrix.android.sdk.api.session.room.model.relation.shouldRenderInThread
|
||||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
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 {
|
fun Event.isFileMessage(): Boolean {
|
||||||
return when (getMsgType()) {
|
return when (getMsgType()) {
|
||||||
MessageType.MSGTYPE_FILE -> true
|
MessageType.MSGTYPE_FILE -> true
|
||||||
|
|
|
@ -323,7 +323,10 @@ class MessageItemFactory @Inject constructor(
|
||||||
informationData: MessageInformationData,
|
informationData: MessageInformationData,
|
||||||
highlight: Boolean,
|
highlight: Boolean,
|
||||||
attributes: AbsMessageItem.Attributes
|
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 fileUrl = getAudioFileUrl(messageContent, informationData)
|
||||||
val playbackControlButtonClickListener = createOnPlaybackButtonClickListener(messageContent, informationData, params)
|
val playbackControlButtonClickListener = createOnPlaybackButtonClickListener(messageContent, informationData, params)
|
||||||
|
|
||||||
|
@ -722,7 +725,7 @@ class MessageItemFactory @Inject constructor(
|
||||||
): MessageVoiceBroadcastItem? {
|
): MessageVoiceBroadcastItem? {
|
||||||
if (messageContent.voiceBroadcastState != VoiceBroadcastState.STARTED) return null
|
if (messageContent.voiceBroadcastState != VoiceBroadcastState.STARTED) return null
|
||||||
val voiceBroadcastEventsGroup = eventsGroup?.let { VoiceBroadcastEventsGroup(it) } ?: 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
|
val mostRecentMessageContent = (mostRecentEvent.getVectorLastMessageContent() as? MessageVoiceBroadcastInfoContent) ?: return null
|
||||||
return MessageVoiceBroadcastItem_()
|
return MessageVoiceBroadcastItem_()
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
|
|
|
@ -22,6 +22,9 @@ import im.vector.app.features.voicebroadcast.model.VoiceBroadcastState
|
||||||
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent
|
import im.vector.app.features.voicebroadcast.model.asVoiceBroadcastEvent
|
||||||
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.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.events.model.toModel
|
||||||
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
|
import org.matrix.android.sdk.api.session.room.model.call.CallInviteContent
|
||||||
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
|
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)
|
EventType.isCallEvent(type) -> (content?.get("call_id") as? String)
|
||||||
type == VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO -> root.asVoiceBroadcastEvent()?.reference?.eventId
|
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.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 -> {
|
else -> {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
@ -134,8 +141,8 @@ class CallSignalingEventsGroup(private val group: TimelineEventsGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
class VoiceBroadcastEventsGroup(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 }
|
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 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue