From 312b2408d72d11caf4d88cfbf07157ead220347f Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Sat, 6 Oct 2018 21:26:54 +0300
Subject: Replies formatting for anonymous users
---
.../pebble/extension/filters/FormatMessageFilter.java | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
(limited to 'juick-server/src/main/java/com/mitchellbosecke/pebble')
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("@%s",
+ msg.getTo().getUri().toASCIIString(), msg.getTo().getName()) : String.format("@%s", 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");
}
--
cgit v1.2.3