Fix actions for redacted, not sent and media messages (#771)

* Fix actions for redacted, not sent and media messages

* Make `EventDebugInfoView` sections fill max width

* Don't display action list if there are no actions to display

---------

Co-authored-by: ElementBot <benoitm+elementbot@element.io>
This commit is contained in:
Jorge Martin Espinosa 2023-07-05 16:08:17 +02:00 committed by GitHub
parent 2cd8e41f70
commit 78a26c034e
28 changed files with 270 additions and 72 deletions

View file

@ -71,7 +71,7 @@ interface MatrixRoom : Closeable {
suspend fun sendMessage(message: String): Result<Unit>
suspend fun editMessage(originalEventId: EventId, message: String): Result<Unit>
suspend fun editMessage(originalEventId: EventId?, transactionId: String?, message: String): Result<Unit>
suspend fun replyMessage(eventId: EventId, message: String): Result<Unit>

View file

@ -34,6 +34,7 @@ import io.element.android.libraries.matrix.api.room.MessageEventType
import io.element.android.libraries.matrix.api.room.StateEventType
import io.element.android.libraries.matrix.api.room.roomMembers
import io.element.android.libraries.matrix.api.timeline.MatrixTimeline
import io.element.android.libraries.matrix.api.timeline.item.event.EventSendState
import io.element.android.libraries.matrix.api.timeline.item.event.EventType
import io.element.android.libraries.matrix.impl.core.toProgressWatcher
import io.element.android.libraries.matrix.impl.room.location.toInner
@ -46,6 +47,7 @@ import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
@ -209,11 +211,16 @@ class RustMatrixRoom(
}
}
override suspend fun editMessage(originalEventId: EventId, message: String): Result<Unit> = withContext(coroutineDispatchers.io) {
val transactionId = genTransactionId()
// val content = messageEventContentFromMarkdown(message)
runCatching {
innerRoom.edit(/* TODO use content */ message, originalEventId.value, transactionId)
override suspend fun editMessage(originalEventId: EventId?, transactionId: String?, message: String): Result<Unit> = withContext(coroutineDispatchers.io) {
if (originalEventId != null) {
runCatching {
innerRoom.edit(/* TODO use content */ message, originalEventId.value, transactionId)
}
} else {
runCatching {
transactionId?.let { cancelSend(it) }
innerRoom.send(messageEventContentFromMarkdown(message), genTransactionId())
}
}
}

View file

@ -110,4 +110,8 @@ class RustMatrixTimeline(
innerRoom.sendReadReceipt(eventId = eventId.value)
}
}
fun getItemById(eventId: EventId): MatrixTimelineItem.Event? {
return _timelineItems.value.firstOrNull { (it as? MatrixTimelineItem.Event)?.eventId == eventId } as? MatrixTimelineItem.Event
}
}

View file

@ -81,6 +81,7 @@ class FakeMatrixRoom(
private var reportContentResult = Result.success(Unit)
private var sendLocationResult = Result.success(Unit)
private var progressCallbackValues = emptyList<Pair<Long, Long>>()
val editMessageCalls = mutableListOf<String>()
var sendMediaCount = 0
private set
@ -174,11 +175,8 @@ class FakeMatrixRoom(
return cancelSendResult
}
var editMessageParameter: String? = null
private set
override suspend fun editMessage(originalEventId: EventId, message: String): Result<Unit> {
editMessageParameter = message
override suspend fun editMessage(originalEventId: EventId?, transactionId: String?, message: String): Result<Unit> {
editMessageCalls += message
return Result.success(Unit)
}

View file

@ -25,11 +25,11 @@ sealed interface MessageComposerMode : Parcelable {
@Parcelize
data class Normal(val content: CharSequence?) : MessageComposerMode
sealed class Special(open val eventId: EventId, open val defaultContent: CharSequence) :
sealed class Special(open val eventId: EventId?, open val defaultContent: CharSequence) :
MessageComposerMode
@Parcelize
data class Edit(override val eventId: EventId, override val defaultContent: CharSequence) :
data class Edit(override val eventId: EventId?, override val defaultContent: CharSequence, val transactionId: String?) :
Special(eventId, defaultContent)
@Parcelize

View file

@ -473,7 +473,7 @@ private fun EditContentToPreview() {
TextComposer(
onSendMessage = {},
onComposerTextChange = {},
composerMode = MessageComposerMode.Edit(EventId("$1234"), "Some text"),
composerMode = MessageComposerMode.Edit(EventId("$1234"), "Some text", "1234"),
onResetComposerMode = {},
composerCanSendMessage = true,
composerText = "A message",