diff options
author | Vitaly Takmazov | 2018-10-06 21:26:54 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-10-06 21:26:54 +0300 |
commit | 312b2408d72d11caf4d88cfbf07157ead220347f (patch) | |
tree | b3c66d350ed6513526f37aa5a4d1df9600191f98 /juick-server/src/main/java/com/mitchellbosecke/pebble | |
parent | 8706a64c522ecfcd54577b4aac575a5ca4dba124 (diff) |
Replies formatting for anonymous users
Diffstat (limited to 'juick-server/src/main/java/com/mitchellbosecke/pebble')
-rw-r--r-- | juick-server/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/juick-server/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java b/juick-server/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java index 5b5291f1..93f9fccb 100644 --- a/juick-server/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java +++ b/juick-server/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java @@ -18,6 +18,7 @@ package com.mitchellbosecke.pebble.extension.filters; import com.juick.Message; +import com.juick.model.AnonymousUser; import com.juick.util.MessageUtils; import com.mitchellbosecke.pebble.extension.Filter; import com.mitchellbosecke.pebble.extension.escaper.SafeString; @@ -27,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; import java.util.List; import java.util.Map; +import java.util.Optional; /** * Created by vitalyster on 04.05.2017. @@ -37,12 +39,14 @@ public class FormatMessageFilter implements Filter { if (input instanceof Message) { Message msg = (Message) input; boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code")); - String formatString = MessageUtils.replyStartsWithQuote(msg) ? "@%s,\n%s" : "@%s, %s"; - String msgTxt = msg.getRid() > 0 ? String.format(formatString, msg.getTo().getName(), StringUtils.defaultString(msg.getText())) - : StringUtils.defaultString(msg.getText()); - String formattedMessage = isCode ? MessageUtils.formatMessageCode(msgTxt) - : MessageUtils.formatMessage(msgTxt); - return new SafeString(formattedMessage); + String toUserString = msg.getTo().getUid() == 0 ? String.format("<a href=\"%s\" data-user-uri=\"1\">@%s</a>", + msg.getTo().getUri().toASCIIString(), msg.getTo().getName()) : String.format("<a href=\"https://juick.com/%s/\">@%s</a>", msg.getTo().getName(), msg.getTo().getName()); + String formatString = MessageUtils.replyStartsWithQuote(msg) ? "%s,\n%s" : "%s, %s"; + String formattedMessage = isCode ? MessageUtils.formatMessageCode(StringUtils.defaultString(msg.getText())) + : MessageUtils.formatMessage(StringUtils.defaultString(msg.getText())); + String msgTxt = msg.getRid() > 0 ? String.format(formatString, toUserString, formattedMessage) + : formattedMessage; + return new SafeString(msgTxt); } throw new IllegalArgumentException("invalid input"); } |