From 80edce3d6c669bc7caef87c80b442ed1489f22cf Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Thu, 9 Mar 2023 10:42:07 +0100 Subject: [PATCH] Escape @room in reply fallback to avoid unintentional pings Closes https://github.com/SchildiChat/SchildiChat-android/issues/178 Change-Id: I8a545dd80d29802d1b35b0315fca89125c997f15 --- FEATURES.md | 1 + .../internal/session/room/send/LocalEchoEventFactory.kt | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/FEATURES.md b/FEATURES.md index c861d9d0c3..aa6c117c58 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -34,6 +34,7 @@ Here you can find some extra features and changes compared to Element Android (w - Render image reactions - Send freeform reactions - Render media captions ([MSC2530](https://github.com/matrix-org/matrix-spec-proposals/pull/2530)) +- Escape @room in the reply fallback to avoid unintentional room pings when replying - Branding (name, app icon, links) - Show a toast instead of a snackbar after copying text, in order to not block the input area right after copying diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt index b24ffa1f91..3259120cd6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/send/LocalEchoEventFactory.kt @@ -637,7 +637,7 @@ internal class LocalEchoEventFactory @Inject constructor( permalink, userLink, userId, - bodyFormatted, + bodyFormatted.escapeRoomPings(), finalReplyTextFormatted ) // @@ -726,7 +726,7 @@ internal class LocalEchoEventFactory @Inject constructor( append(originalSenderId) append(">") - val lines = body.text.split("\n") + val lines = body.text.escapeRoomPings().split("\n") lines.forEachIndexed { index, s -> if (index == 0) { append(" $s") @@ -739,6 +739,11 @@ internal class LocalEchoEventFactory @Inject constructor( } } + private fun String.escapeRoomPings(): String { + // Escape @room, so replying as moderator will not ping the whole room + return replace("@room", "@\u2060room") + } + private fun bodyForReply(timelineEvent: TimelineEvent, isRedactedEvent: Boolean = false): TextContent { val content = when (timelineEvent.root.getClearType()) { in EventType.POLL_END.values -> {