aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-10-06 23:39:10 +0300
committerGravatar Vitaly Takmazov2018-10-06 23:39:10 +0300
commite882914b29f384d3f530865737cc7de3790e5b0e (patch)
treeb87b0a1055903084882bae4c8eedfbd554687105
parent0b065e1e0547885294d03df54d178587d801a15a (diff)
HTML replies
-rw-r--r--juick-common/src/main/java/com/juick/Message.java9
-rw-r--r--juick-common/src/main/java/com/juick/model/ResponseReply.java9
-rw-r--r--juick-server/src/main/java/com/juick/server/ActivityPubManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/EmailManager.java2
-rw-r--r--juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java2
-rw-r--r--juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java22
-rw-r--r--juick-server/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatMessageFilter.java3
-rw-r--r--juick-server/src/main/resources/db/migration/V1.8__html reply.sql1
8 files changed, 39 insertions, 11 deletions
diff --git a/juick-common/src/main/java/com/juick/Message.java b/juick-common/src/main/java/com/juick/Message.java
index de419b9b..a5efb05c 100644
--- a/juick-common/src/main/java/com/juick/Message.java
+++ b/juick-common/src/main/java/com/juick/Message.java
@@ -77,6 +77,7 @@ public class Message implements Comparable {
private Set<Reaction> reactions;
private boolean service;
private URI replyUri;
+ private boolean html;
private Set<String> recommendations;
@@ -357,4 +358,12 @@ public class Message implements Comparable {
public void setReplyUri(URI replyUri) {
this.replyUri = replyUri;
}
+
+ public boolean isHtml() {
+ return html;
+ }
+
+ public void setHtml(boolean html) {
+ this.html = html;
+ }
}
diff --git a/juick-common/src/main/java/com/juick/model/ResponseReply.java b/juick-common/src/main/java/com/juick/model/ResponseReply.java
index acc5db71..183c6f72 100644
--- a/juick-common/src/main/java/com/juick/model/ResponseReply.java
+++ b/juick-common/src/main/java/com/juick/model/ResponseReply.java
@@ -30,6 +30,7 @@ public class ResponseReply {
private String description;
private Date pubDate;
private String attachmentType;
+ private boolean html;
public String getMuname() {
return muname;
@@ -86,4 +87,12 @@ public class ResponseReply {
public void setAttachmentType(String attachmentType) {
this.attachmentType = attachmentType;
}
+
+ public boolean isHtml() {
+ return html;
+ }
+
+ public void setHtml(boolean html) {
+ this.html = html;
+ }
}
diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
index 4adfafea..c1790deb 100644
--- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
+++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java
@@ -196,7 +196,7 @@ public class ActivityPubManager implements ActivityListener, NotificationListene
note.setCc(Collections.singletonList(followersUri(msg.getUser())));
}
note.setPublished(msg.getTimestamp());
- note.setContent(MessageUtils.formatMessage(msg.getText()));
+ note.setContent(msg.isHtml() ? msg.getText() : MessageUtils.formatMessage(msg.getText()));
if (StringUtils.isNotBlank(msg.getAttachmentType())) {
Image attachment = new Image();
attachment.setId(msg.getAttachment().getMedium().getUrl());
diff --git a/juick-server/src/main/java/com/juick/server/EmailManager.java b/juick-server/src/main/java/com/juick/server/EmailManager.java
index 726da4b9..1cdafac6 100644
--- a/juick-server/src/main/java/com/juick/server/EmailManager.java
+++ b/juick-server/src/main/java/com/juick/server/EmailManager.java
@@ -114,7 +114,7 @@ public class EmailManager implements NotificationListener {
String htmlText = String.format("%s<br /><br />--<br />You are receiving this because you are subscribed to this user" +
", discussion, tag or mentioned. Reply to this email directly or <a href=\"%s\"><img src=\"https://api.juick.com/thread/mark_read/%d-%d.gif?hash=%s\" />view it</a> on Juick." +
"<br /><a href=\"https://juick.com/settings?hash=%s\">Configure or disable notifications</a>",
- MessageUtils.formatHtml(msg), formatUrl(msg),
+ msg.isHtml() ? msg.getText() : MessageUtils.formatHtml(msg), formatUrl(msg),
msg.getMid(), msg.getRid(), hash, hash);
sendEmail(email, subject, plainText, htmlText, headers);
}
diff --git a/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java b/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
index f9d7109e..a0ab801e 100644
--- a/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
+++ b/juick-server/src/main/java/com/juick/server/api/rss/RepliesView.java
@@ -78,7 +78,7 @@ public class RepliesView extends AbstractRssFeedView {
Item item = new Item();
String messageUrl = String.format("http://juick.com/m/%d#%d", msg.getMid(), msg.getRid());
String messageTitle = String.format("@%s:", msg.getUname());
- String messageDescription = MessageUtils.formatMessage(msg.getDescription());
+ String messageDescription = msg.isHtml() ? msg.getDescription() : MessageUtils.formatMessage(msg.getDescription());
item.setLink(messageUrl);
//item.setGuid(messageUrl);
item.setTitle(messageTitle);
diff --git a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
index a6a38e2b..0b0a11ae 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -100,6 +100,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
msg.setTo(quoteUser);
msg.setUpdatedAt(rs.getTimestamp(21).toInstant());
msg.setReplyUri(URI.create(Optional.ofNullable(rs.getString(24)).orElse(StringUtils.EMPTY)));
+ msg.setHtml(rs.getBoolean(25));
if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
try {
imagesService.setAttachmentMetadata(baseImagesUrl, msg);
@@ -337,7 +338,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.readonly, messages.privacy, messages.replies,"
+ "messages.attach, COUNT(DISTINCT favorites.user_id) as likes, messages.hidden,"
+ "txt.tags, txt.repliesby, txt.txt, '' as q, messages.updated as updated, 0 as to_uid, "
- + "NULL as to_name, txt.updated_at, '' as user_uri, '' as to_uri, '' as reply_uri FROM messages "
+ + "NULL as to_name, txt.updated_at, '' as user_uri, '' as to_uri, '' as reply_uri, 0 as html FROM messages "
+ "INNER JOIN users ON messages.user_id = users.id "
+ "INNER JOIN messages_txt AS txt "
+ "ON messages.message_id = txt.message_id "
@@ -345,7 +346,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "ON messages.message_id = favorites.message_id AND favorites.like_id=1 "
+ "WHERE messages.message_id = ? "
+ "GROUP BY mid, rid, replyto, uid, nick, banned, messages.ts, readonly, "
- + "privacy, replies, attach, tags, repliesby, q, updated_at, user_uri, to_uri, reply_uri",
+ + "privacy, replies, attach, tags, repliesby, q, updated_at, user_uri, to_uri, reply_uri, html",
new MessageMapper(),
mid);
if (!list.isEmpty()) {
@@ -366,7 +367,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "replies.attach, replies.txt, IFNULL(q.txt,t.txt) as quote, "
+ "COALESCE(q.user_id, m.user_id) AS to_uid, COALESCE(qu.nick, mu.nick) AS to_name, "
+ "replies.updated_at, replies.user_uri as uri, "
- + "q.user_uri AS to_uri, replies.reply_uri AS reply_uri "
+ + "q.user_uri AS to_uri, replies.reply_uri AS reply_uri, replies.html "
+ "FROM replies LEFT JOIN users ON replies.user_id = users.id "
+ "LEFT JOIN replies q ON replies.message_id = q.message_id and replies.replyto = q.reply_id "
+ "LEFT JOIN messages_txt t ON replies.message_id = t.message_id "
@@ -404,6 +405,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
msg.setTo(quoteUser);
msg.setUpdatedAt(rs.getTimestamp(10).toInstant());
msg.setReplyUri(URI.create(Optional.ofNullable(rs.getString(12)).orElse(StringUtils.EMPTY)));
+ msg.setHtml(rs.getBoolean(13));
if (StringUtils.isNotEmpty(msg.getAttachmentType())) {
try {
imagesService.setAttachmentMetadata(baseImagesUrl, msg);
@@ -834,7 +836,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "messages.attach,COUNT(DISTINCT favorites.user_id) AS likes,messages.hidden,"
+ "messages_txt.tags,messages_txt.repliesby, messages_txt.txt, '' as q, "
+ "messages.updated, 0 as to_uid, NULL as to_name, messages_txt.updated_at, '' as user_uri, "
- + "'' as to_uri, '' as reply_uri "
+ + "'' as to_uri, '' as reply_uri, 0 as html "
+ "FROM (messages INNER JOIN messages_txt "
+ "ON messages.message_id=messages_txt.message_id) "
+ "INNER JOIN users ON messages.user_id=users.id "
@@ -843,7 +845,10 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
+ "LEFT JOIN banned "
+ "ON messages.message_id = banned.message_id "
+ "WHERE messages.message_id IN (:ids) GROUP BY "
- + "messages.message_id, rid, replyto, messages.user_id, users.nick, banned, messages.ts, messages.readonly, messages.privacy, messages.attach, messages.hidden, messages_txt.tags, messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name, updated_at, user_uri, reply_uri",
+ + "messages.message_id, rid, replyto, messages.user_id, users.nick, banned, messages.ts, "
+ + "messages.readonly, messages.privacy, messages.attach, messages.hidden, messages_txt.tags, "
+ + "messages_txt.repliesby, messages_txt.txt, q, messages.updated, to_uid, to_name, updated_at, "
+ + "user_uri, reply_uri, html",
new MapSqlParameterSource("ids", mids)
.addValue("uid", visitor.getUid()),
new MessageMapper());
@@ -912,7 +917,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
"NOW(), " +
"COALESCE(qw.user_id, m.user_id) as to_uid, COALESCE(qu.nick, mu.nick) as to_name, " +
"replies.updated_at, replies.user_uri as uri, " +
- "qw.user_uri as to_uri, replies.reply_uri " +
+ "qw.user_uri as to_uri, replies.reply_uri, replies.html " +
"FROM replies LEFT JOIN users " +
"ON replies.user_id = users.id " +
"LEFT JOIN replies qw ON replies.message_id = qw.message_id and replies.replyto = qw.reply_id " +
@@ -1027,7 +1032,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
public List<ResponseReply> getLastReplies(int hours) {
return getJdbcTemplate().query("SELECT users2.nick,replies.message_id,replies.reply_id," +
"users.nick,replies.txt," +
- "replies.ts,replies.attach,replies.ts+0 " +
+ "replies.ts,replies.attach,replies.ts+0, replies.html " +
"FROM ((replies INNER JOIN users ON replies.user_id=users.id) " +
"INNER JOIN messages ON replies.message_id=messages.message_id) " +
"INNER JOIN users AS users2 ON messages.user_id=users2.id " +
@@ -1040,6 +1045,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
reply.setDescription(rs.getString(5));
reply.setPubDate(rs.getTimestamp(6));
reply.setAttachmentType(rs.getString(7));
+ reply.setHtml(rs.getBoolean(8));
return reply;
}, -hours);
}
@@ -1097,7 +1103,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
@Override
public boolean updateReplyUri(Message reply, URI replyUri) {
- return jdbcTemplate.update("UPDATE replies SET reply_uri=? WHERE message_id=? AND reply_id=?",
+ return jdbcTemplate.update("UPDATE replies SET reply_uri=?, html=1 WHERE message_id=? AND reply_id=?",
replyUri.toASCIIString(), reply.getMid(), reply.getRid()) > 0;
}
}
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 93f9fccb..f347c1c3 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
@@ -38,6 +38,9 @@ public class FormatMessageFilter implements Filter {
public Object apply(Object input, Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {
if (input instanceof Message) {
Message msg = (Message) input;
+ if (msg.isHtml()) {
+ return new SafeString(msg.getText());
+ }
boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code"));
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());
diff --git a/juick-server/src/main/resources/db/migration/V1.8__html reply.sql b/juick-server/src/main/resources/db/migration/V1.8__html reply.sql
new file mode 100644
index 00000000..9f939971
--- /dev/null
+++ b/juick-server/src/main/resources/db/migration/V1.8__html reply.sql
@@ -0,0 +1 @@
+ALTER TABLE replies ADD COLUMN html tinyint(4) NOT NULL DEFAULT '0'; \ No newline at end of file