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

View File

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

View File

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

View File

@ -88,7 +88,7 @@ internal class RoomEventCreatorTest {
} }
@Test @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) 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) } 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( result shouldBeEqualTo aMatrixRoomMessageEvent(
eventId = A_TEXT_EVENT_WITHOUT_CONTENT.id, eventId = A_TEXT_EVENT_WITHOUT_CONTENT.id,
utcTimestamp = A_TEXT_EVENT_WITHOUT_CONTENT.utcTimestamp, utcTimestamp = A_TEXT_EVENT_WITHOUT_CONTENT.utcTimestamp,
content = RichText.of("redacted"), content = RichText(emptyList()),
author = A_SENDER, author = A_SENDER,
) )
} }

View File

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