From d3070d578ab3650b6fe7f9cf49888f037887e7bf Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Nov 2022 09:15:02 +0000 Subject: [PATCH] removing manual redacted text fallback and using empty instead --- .../sync/internal/sync/RoomEventCreator.kt | 10 +++++----- .../sync/internal/sync/message/PartBuilder.kt | 19 ++++++++++++------- .../internal/room/RoomEventsDecrypterTest.kt | 1 - .../internal/sync/RoomEventCreatorTest.kt | 4 ++-- .../kotlin/fixture/RoomEventFixture.kt | 3 +-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreator.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreator.kt index 74c7622..24fcef9 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreator.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreator.kt @@ -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) } diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt index 2cbf4e1..e71a548 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/message/PartBuilder.kt @@ -37,15 +37,20 @@ internal class PartBuilder { fun build(): List { 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() { diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt index dea7f06..ee3bbd0 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/room/RoomEventsDecrypterTest.kt @@ -95,5 +95,4 @@ private fun RoomEvent.Encrypted.toText(text: String) = RoomEvent.Message( this.author, this.meta, this.edited, - this.redacted, ) \ No newline at end of file diff --git a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt index 45ab70b..1cff200 100644 --- a/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt +++ b/matrix/services/sync/src/test/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventCreatorTest.kt @@ -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, ) } diff --git a/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt b/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt index 4228454..0d20981 100644 --- a/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt +++ b/matrix/services/sync/src/testFixtures/kotlin/fixture/RoomEventFixture.kt @@ -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"),