From 85f607c995fc746aaedce43ae1f0b4a8852c3452 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Thu, 4 Jul 2024 18:49:51 -0500 Subject: [PATCH] Fix direct reply Always nuke XHTML when setting body to a string, instead of doing hacky workarounds --- .../eu/siacs/conversations/entities/Message.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index c43a98d6a3ebe300af3ff107d2bf5e1d2ef1f40b..296728d7a5a72c26ef0436f967df0643abc87745 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -424,8 +424,6 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable clearReplyReact(); if (body == null) body = new SpannableStringBuilder(getBody(true)); - final Element html = getOrMakeHtml(); - html.clearChildren(); setBody(QuoteHelper.quote(MessageUtils.prepareQuote(replyTo)) + "\n"); final String replyId = replyTo.replyId(); @@ -620,7 +618,8 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable } public synchronized void setBody(Spanned span) { - setBody(span == null ? null : span.toString()); + // Don't bother removing, we'll edit below + setBodyPreserveXHTML(span == null ? null : span.toString()); if (span == null || SpannedToXHTML.isPlainText(span)) { this.payloads.remove(getHtml(true)); } else { @@ -636,13 +635,18 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable if (html != null) addPayload(html); } - public synchronized void setBody(String body) { + private synchronized void setBodyPreserveXHTML(String body) { this.body = body; this.isGeoUri = null; this.isEmojisOnly = null; this.treatAsDownloadable = null; } + public synchronized void setBody(String body) { + setBodyPreserveXHTML(body); + this.payloads.remove(getHtml(true)); + } + public synchronized void appendBody(Spanned append) { if (!SpannedToXHTML.isPlainText(append) || getHtml() != null) { final Element body = getOrMakeHtml();