fixing missing nested replies/images

This commit is contained in:
Adam Brown 2022-06-07 19:55:36 +01:00
parent 83c18a3715
commit c2c6296e9a

View File

@ -65,17 +65,13 @@ internal class TimelineEventMapper(
private suspend fun ApiTimelineEvent.TimelineMessage.handleReply(replyToId: EventId, lookup: Lookup): RoomEvent { private suspend fun ApiTimelineEvent.TimelineMessage.handleReply(replyToId: EventId, lookup: Lookup): RoomEvent {
val relationEvent = lookup(replyToId).fold( val relationEvent = lookup(replyToId).fold(
onApiTimelineEvent = { it.toTextMessage() }, onApiTimelineEvent = { it.toMessage() },
onRoomEvent = { it }, onRoomEvent = { it },
onEmpty = { null } onEmpty = { null }
) )
return when (relationEvent) { return when (relationEvent) {
null -> when (this.content) { null -> this.toMessage()
is ApiTimelineEvent.TimelineMessage.Content.Image -> this.toImageMessage()
is ApiTimelineEvent.TimelineMessage.Content.Text -> this.toFallbackTextMessage()
ApiTimelineEvent.TimelineMessage.Content.Ignored -> throw IllegalStateException()
}
else -> { else -> {
RoomEvent.Reply( RoomEvent.Reply(
message = roomEventFactory.mapToRoomEvent(this), message = roomEventFactory.mapToRoomEvent(this),
@ -89,6 +85,12 @@ internal class TimelineEventMapper(
} }
} }
private suspend fun ApiTimelineEvent.TimelineMessage.toMessage() = when (this.content) {
is ApiTimelineEvent.TimelineMessage.Content.Image -> this.toImageMessage()
is ApiTimelineEvent.TimelineMessage.Content.Text -> this.toFallbackTextMessage()
ApiTimelineEvent.TimelineMessage.Content.Ignored -> throw IllegalStateException()
}
private suspend fun ApiTimelineEvent.TimelineMessage.toFallbackTextMessage() = this.toTextMessage(content = this.asTextContent().body ?: "redacted") private suspend fun ApiTimelineEvent.TimelineMessage.toFallbackTextMessage() = this.toTextMessage(content = this.asTextContent().body ?: "redacted")
private suspend fun ApiTimelineEvent.TimelineMessage.handleEdit(editedEventId: EventId, lookup: Lookup): RoomEvent? { private suspend fun ApiTimelineEvent.TimelineMessage.handleEdit(editedEventId: EventId, lookup: Lookup): RoomEvent? {