From 299c6af27ac34918f738c4ac64db754ebb2448d4 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Sun, 8 May 2022 19:02:54 +0100 Subject: [PATCH] fixing message starts being cutoff due to expecting a reply tag to exist --- .../st/matrix/sync/internal/sync/RoomEventCreator.kt | 5 ----- .../st/matrix/sync/internal/sync/RoomEventFactory.kt | 12 +++++++++++- 2 files changed, 11 insertions(+), 6 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 4d15423..09fd61e 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 @@ -162,11 +162,6 @@ internal class TimelineEventMapper( } -private fun String.stripTags() = this.substring(this.indexOf("") + "".length) - .trim() - .replace("", "") - .replace("", "") - private fun ApiTimelineEvent.TimelineMessage.isEdit() = this.content.relation?.relationType == "m.replace" && this.content.relation?.eventId != null private fun ApiTimelineEvent.TimelineMessage.isReply() = this.content.relation?.inReplyTo != null private fun ApiTimelineEvent.TimelineMessage.asTextContent() = this.content as ApiTimelineEvent.TimelineMessage.Content.Text diff --git a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt index a7d186d..f1e3ef3 100644 --- a/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt +++ b/matrix/services/sync/src/main/kotlin/app/dapk/st/matrix/sync/internal/sync/RoomEventFactory.kt @@ -53,9 +53,19 @@ internal class RoomEventFactory( } } -private fun String.stripTags() = this.substring(this.indexOf("") + "".length) + +private fun String.indexOfOrNull(string: String) = this.indexOf(string).takeIf { it != -1 } + +fun String.stripTags() = this + .run { + this.indexOfOrNull("")?.let { + this.substring(it + "".length) + } ?: this + } .trim() .replace("", "") .replace("", "") + .replace(""", "\"") + .replace("'", "'") private fun ApiTimelineEvent.TimelineMessage.asTextContent() = this.content as ApiTimelineEvent.TimelineMessage.Content.Text