removing manual redacted text fallback and using empty instead

This commit is contained in:
Adam Brown 2022-11-04 09:15:02 +00:00
parent 7a426ab1e7
commit d3070d578a
5 changed files with 20 additions and 17 deletions

View File

@ -96,7 +96,7 @@ internal class TimelineEventMapper(
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 ?: "")
private suspend fun ApiTimelineEvent.TimelineMessage.handleEdit(editedEventId: EventId, lookup: Lookup): RoomEvent? {
return lookup(editedEventId).fold(
@ -148,7 +148,7 @@ internal class TimelineEventMapper(
is ApiTimelineEvent.TimelineMessage.Content.Text -> original.toTextMessage(
utcTimestamp = incomingEdit.utcTimestamp,
content = incomingEdit.asTextContent().let { it.formattedBody ?: it.body }?.removePrefix(" * ") ?: "redacted",
content = incomingEdit.asTextContent().let { it.formattedBody ?: it.body }?.removePrefix(" * ") ?: "",
edited = true,
)
@ -158,7 +158,7 @@ internal class TimelineEventMapper(
}
private fun RoomEvent.Message.edited(edit: ApiTimelineEvent.TimelineMessage) = this.copy(
content = richMessageParser.parse(edit.asTextContent().let { it.formattedBody ?: it.body }?.removePrefix(" * ") ?: "redacted"),
content = richMessageParser.parse(edit.asTextContent().let { it.formattedBody ?: it.body }?.removePrefix(" * ") ?: ""),
edited = true,
)
@ -167,7 +167,7 @@ internal class TimelineEventMapper(
is ApiTimelineEvent.TimelineMessage.Content.Image -> source.toImageMessage(userCredentials, roomId)
is ApiTimelineEvent.TimelineMessage.Content.Text -> source.toTextMessage(
roomId,
content = source.asTextContent().formattedBody ?: source.content.body ?: "redacted"
content = source.asTextContent().formattedBody ?: source.content.body ?: ""
)
ApiTimelineEvent.TimelineMessage.Content.Ignored -> throw IllegalStateException()
@ -175,7 +175,7 @@ internal class TimelineEventMapper(
}
private suspend fun ApiTimelineEvent.TimelineMessage.toTextMessage(
content: String = this.asTextContent().formattedBody ?: this.asTextContent().body ?: "redacted",
content: String = this.asTextContent().formattedBody ?: this.asTextContent().body ?: "",
edited: Boolean = false,
utcTimestamp: Long = this.utcTimestamp,
) = with(roomEventFactory) { toTextMessage(roomId, content, edited, utcTimestamp) }

View File

@ -37,15 +37,20 @@ internal class PartBuilder {
fun build(): List<RichText.Part> {
flushNormalBuffer()
val last = parts.last()
if (last is RichText.Part.Normal) {
parts.removeLast()
val newContent = last.content.trimEnd()
if (newContent.isNotEmpty()) {
parts.add(last.copy(content = newContent))
return when(parts.isEmpty()) {
true -> parts
else -> {
val last = parts.last()
if (last is RichText.Part.Normal) {
parts.removeLast()
val newContent = last.content.trimEnd()
if (newContent.isNotEmpty()) {
parts.add(last.copy(content = newContent))
}
}
parts
}
}
return parts
}
private fun flushNormalBuffer() {

View File

@ -95,5 +95,4 @@ private fun RoomEvent.Encrypted.toText(text: String) = RoomEvent.Message(
this.author,
this.meta,
this.edited,
this.redacted,
)

View File

@ -88,7 +88,7 @@ internal class RoomEventCreatorTest {
}
@Test
fun `given text event without body then maps to redacted room message`() = runTest {
fun `given text event without body then maps to empty room message`() = runTest {
fakeRoomMembersService.givenMember(A_ROOM_ID, A_SENDER.id, A_SENDER)
val result = with(roomEventCreator) { A_TEXT_EVENT_WITHOUT_CONTENT.toRoomEvent(A_USER_CREDENTIALS, A_ROOM_ID, EMPTY_LOOKUP) }
@ -96,7 +96,7 @@ internal class RoomEventCreatorTest {
result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = A_TEXT_EVENT_WITHOUT_CONTENT.id,
utcTimestamp = A_TEXT_EVENT_WITHOUT_CONTENT.utcTimestamp,
content = RichText.of("redacted"),
content = RichText(emptyList()),
author = A_SENDER,
)
}

View File

@ -34,8 +34,7 @@ fun anEncryptedRoomMessageEvent(
meta: MessageMeta = MessageMeta.FromServer,
encryptedContent: RoomEvent.Encrypted.MegOlmV1 = aMegolmV1(),
edited: Boolean = false,
redacted: Boolean = false,
) = RoomEvent.Encrypted(eventId, utcTimestamp, author, meta, edited, redacted, encryptedContent)
) = RoomEvent.Encrypted(eventId, utcTimestamp, author, meta, edited, encryptedContent)
fun aMegolmV1(
cipherText: CipherText = CipherText("a-cipher"),