Use new endpoint to delete voice broadcast with relations

This commit is contained in:
Florian Renaud 2023-01-24 11:38:07 +01:00
parent 0704fc5e15
commit b0460ebcc0
3 changed files with 20 additions and 6 deletions

View file

@ -20,6 +20,7 @@ import im.vector.app.features.voicebroadcast.VoiceBroadcastConstants
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 im.vector.app.features.voicebroadcast.model.isVoiceBroadcast
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.room.model.message.MessageContent
@ -49,3 +50,7 @@ fun TimelineEvent.getVectorLastMessageContent(): MessageContent? {
else -> getLastMessageContent()
}
}
fun TimelineEvent.isVoiceBroadcast(): Boolean {
return root.isVoiceBroadcast()
}

View file

@ -32,6 +32,7 @@ import im.vector.app.R
import im.vector.app.SpaceStateHandler
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.extensions.isVoiceBroadcast
import im.vector.app.core.mvrx.runCatchingToAsync
import im.vector.app.core.platform.VectorViewModel
import im.vector.app.core.resources.BuildMeta
@ -859,12 +860,18 @@ class TimelineViewModel @AssistedInject constructor(
private fun handleRedactEvent(action: RoomDetailAction.RedactAction) {
val event = room?.getTimelineEvent(action.targetEventId) ?: return
if (event.isLiveLocation()) {
viewModelScope.launch {
redactLiveLocationShareEventUseCase.execute(event.root, room, action.reason)
when {
event.isLiveLocation() -> {
viewModelScope.launch {
redactLiveLocationShareEventUseCase.execute(event.root, room, action.reason)
}
}
event.isVoiceBroadcast() -> {
room.sendService().redactEvent(event.root, action.reason, listOf(RelationType.REFERENCE))
}
else -> {
room.sendService().redactEvent(event.root, action.reason)
}
} else {
room.sendService().redactEvent(event.root, action.reason)
}
}

View file

@ -49,7 +49,9 @@ value class VoiceBroadcastEvent(val root: Event) {
get() = root.content.toModel()
}
fun Event.isVoiceBroadcast() = type == VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO
/**
* Map a [VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO] state event to a [VoiceBroadcastEvent].
*/
fun Event.asVoiceBroadcastEvent() = if (type == VoiceBroadcastConstants.STATE_ROOM_VOICE_BROADCAST_INFO) VoiceBroadcastEvent(this) else null
fun Event.asVoiceBroadcastEvent() = if (isVoiceBroadcast()) VoiceBroadcastEvent(this) else null