From 8c1d825bf30d641247064063cfcc75a59bc5ab41 Mon Sep 17 00:00:00 2001 From: kosyak Date: Sat, 18 May 2024 14:33:48 +0200 Subject: [PATCH] fix reply text handling --- .../siacs/conversations/entities/Message.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index abf2bda06..90eee7026 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -841,7 +841,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable public SpannableStringBuilder getBodyForDisplaying() { if (replyMessage != null) { try { - return new SpannableStringBuilder(MessageUtils.filterLtrRtl(getReplyText(replyMessage) + "\n" + removeReplyFallback(this)).trim()); + return new SpannableStringBuilder(MessageUtils.filterLtrRtl(getReplyText(replyMessage) + "\n" + removeReplyFallback(this, replyMessage)).trim()); } catch (IndexOutOfBoundsException e) { return new SpannableStringBuilder(MessageUtils.filterLtrRtl(this.body).trim()); } @@ -859,7 +859,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable } private StringBuilder getReplyText(Message message) { - StringBuilder reply = removeReplyFallback(message); + StringBuilder reply = removeReplyFallback(message, message.replyMessage); reply.insert(0, '>'); for (int i=0;i replyFallback = message.getFallbacks("urn:xmpp:reply:0"); - if (replyFallback.size() == 0) { - return sb; + if (replyMessage != null && replyMessage.edits.isEmpty()) { + sb.replace(0, replyMessage.body.codePointCount(0, replyMessage.body.length()) + 3, ""); + } else { + List replyFallback = message.getFallbacks("urn:xmpp:reply:0"); + if (replyFallback.isEmpty()) { + return sb; + } + + Element bodyFallback = replyFallback.get(0).findChild("body"); + int startCodePoint = Integer.parseInt(bodyFallback.getAttribute("start")); + int endCodePoint = Integer.parseInt(bodyFallback.getAttribute("end")); + + if (startCodePoint < 0) return sb; + if (endCodePoint > sb.length()) return sb; + + sb.replace(message.body.offsetByCodePoints(0, startCodePoint), message.body.offsetByCodePoints(0, endCodePoint), ""); } - Element bodyFallback = replyFallback.get(0).findChild("body"); - int startCodePoint = Integer.parseInt(bodyFallback.getAttribute("start")); - int endCodePoint = Integer.parseInt(bodyFallback.getAttribute("end")); - - if (startCodePoint < 0) return sb; - if (endCodePoint > sb.length()) return sb; - - sb.replace(message.body.offsetByCodePoints(0, startCodePoint), message.body.offsetByCodePoints(0, endCodePoint), ""); return sb; }