From 7ca543e42f44f1c71d51bc5286e1ff0a012acd77 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 24 May 2020 10:52:34 +0200 Subject: [PATCH] replace /me when quoting messages. fixes #3669 --- .../siacs/conversations/entities/Contact.java | 10 ++++++++++ .../siacs/conversations/entities/Message.java | 4 ++-- .../conversations/utils/MessageUtils.java | 20 ++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index eccd222e0..d37646f78 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -143,6 +143,16 @@ public class Contact implements ListItem, Blockable { } } + public String getPublicDisplayName() { + if (!TextUtils.isEmpty(this.presenceName)) { + return this.presenceName; + } else if (jid.getLocal() != null) { + return JidHelper.localPartOrFallback(jid); + } else { + return jid.getDomain().toEscapedString(); + } + } + public String getProfilePhoto() { return this.photoUri; } diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 567d694eb..4263a6ef8 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -643,8 +643,8 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable !this.isOOb() && !message.treatAsDownloadable() && !this.treatAsDownloadable() && - !message.getBody().startsWith(ME_COMMAND) && - !this.getBody().startsWith(ME_COMMAND) && + !message.hasMeCommand() && + !this.hasMeCommand() && !this.bodyIsOnlyEmojis() && !message.bodyIsOnlyEmojis() && ((this.axolotlFingerprint == null && message.axolotlFingerprint == null) || this.axolotlFingerprint.equals(message.getFingerprint())) && diff --git a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java index e5e4fbd97..e8ae07e68 100644 --- a/src/main/java/eu/siacs/conversations/utils/MessageUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/MessageUtils.java @@ -29,10 +29,13 @@ package eu.siacs.conversations.utils; +import com.google.common.base.Strings; + import java.net.MalformedURLException; import java.net.URL; import java.util.regex.Pattern; +import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.http.AesGcmURLStreamHandler; import eu.siacs.conversations.http.P1S3UrlStreamHandler; @@ -45,7 +48,22 @@ public class MessageUtils { public static String prepareQuote(Message message) { final StringBuilder builder = new StringBuilder(); - final String body = message.getMergedBody().toString(); + final String body; + if (message.hasMeCommand()) { + final String nick; + if (message.getStatus() == Message.STATUS_RECEIVED) { + if (message.getConversation().getMode() == Conversational.MODE_MULTI) { + nick = Strings.nullToEmpty(message.getCounterpart().getResource()); + } else { + nick = message.getContact().getPublicDisplayName(); + } + } else { + nick = UIHelper.getMessageDisplayName(message); + } + body = nick + " " + message.getBody().substring(Message.ME_COMMAND.length()); + } else { + body = message.getMergedBody().toString();; + } for (String line : body.split("\n")) { if (line.length() <= 0) { continue;