From 69dac97f8810b4db64bd8f1c09dd966c9f7a6029 Mon Sep 17 00:00:00 2001 From: Bohdan Horbeshko Date: Sat, 16 Dec 2023 19:06:40 +0200 Subject: [PATCH] show replies not starting with > --- .../conversations/parser/MessageParser.java | 7 +++- .../ui/adapter/MessageAdapter.java | 38 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index 588f081b7..486550918 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -599,7 +599,12 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); for (Element el : packet.getChildren()) { - if (el.getName().equals("reply") && el.getNamespace() != null && el.getNamespace().equals("urn:xmpp:reply:0")) { + String name = el.getName(); + String ns = el.getNamespace(); + if ( + ("reply".equals(name) && "urn:xmpp:reply:0".equals(ns)) || + ("fallback".equals(name) && "urn:xmpp:fallback:0".equals(ns)) + ) { message.addPayload(el); } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index e8cf71adf..c557223a2 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -87,6 +87,7 @@ import eu.siacs.conversations.utils.MessageUtils; import eu.siacs.conversations.utils.StylingHelper; import eu.siacs.conversations.utils.TimeFrameUtils; import eu.siacs.conversations.utils.UIHelper; +import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xmpp.Jid; import eu.siacs.conversations.xmpp.mam.MamReference; @@ -458,8 +459,11 @@ public class MessageAdapter extends ArrayAdapter { */ public boolean handleTextQuotes(SpannableStringBuilder body, boolean darkBackground, boolean highlightReply, Message message) { boolean startsWithQuote = false; - int quoteDepth = 1; + int quoteDepth = 0; while (QuoteHelper.bodyContainsQuoteStart(body) && quoteDepth <= Config.QUOTE_MAX_DEPTH) { + if (quoteDepth == 0) { + quoteDepth = 1; + } char previous = '\n'; int lineStart = -1; int lineTextStart = -1; @@ -504,6 +508,38 @@ public class MessageAdapter extends ArrayAdapter { } quoteDepth++; } + if (quoteDepth == 0 && highlightReply) { + // Quote was not detected, use a reply anyway if provided + int start = -1; + int end = -1; + for (Element el : message.getPayloads()) { + if ("fallback".equals(el.getName()) && "urn:xmpp:fallback:0".equals(el.getNamespace()) && "urn:xmpp:reply:0".equals(el.getAttribute("for"))) { + Element bodyEl = el.findChild("body", "urn:xmpp:fallback:0"); + if (bodyEl != null) { + String startString = bodyEl.getAttribute("start"); + String endString = bodyEl.getAttribute("end"); + try { + start = Integer.parseInt(startString); + end = Integer.parseInt(endString); + } catch (final NumberFormatException ignored) { + } + } + break; + } + } + if (start == -1 && end == -1) { + // Quirk for messages which were saved without the fallback element + final String quirk = "reply\n"; + body.insert(0, quirk); + start = 0; + end = quirk.length(); + } else if (start == -1) { + start = 0; + } else if (end == -1) { + end = body.length(); + } + applyQuoteSpan(body, start, end, darkBackground, true, message); + } return startsWithQuote; }