From f010d75872763547ecbe621ae3e8eb967950453f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 13 Mar 2018 15:18:03 +0300 Subject: core: cleanup unused message properties --- juick-core/src/main/java/com/juick/Group.java | 28 ---------- juick-core/src/main/java/com/juick/Message.java | 62 +--------------------- juick-core/src/main/java/com/juick/Place.java | 32 ----------- .../com/juick/formatters/PlainTextFormatter.java | 4 +- .../src/main/java/com/juick/util/MessageUtils.java | 42 ++++++++++++++- .../src/test/java/com/juick/MessageTest.java | 40 +++++++------- .../java/com/juick/components/Notifications.java | 3 +- .../com/juick/service/MessagesServiceImpl.java | 8 +-- .../java/com/juick/service/MessageServiceTest.java | 3 +- .../main/java/com/juick/server/XMPPConnection.java | 4 +- .../com/juick/server/api/rss/MessagesView.java | 2 +- .../java/com/juick/www/controllers/Messages.java | 32 ++--------- .../java/com/juick/www/controllers/NewMessage.java | 3 +- .../pebble/extension/FormatterExtension.java | 1 - .../extension/filters/FormatRepliesFilter.java | 48 ----------------- src/test/java/com/juick/tests/MessageTests.java | 3 +- 16 files changed, 82 insertions(+), 233 deletions(-) delete mode 100644 juick-core/src/main/java/com/juick/Group.java delete mode 100644 juick-core/src/main/java/com/juick/Place.java delete mode 100644 juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatRepliesFilter.java diff --git a/juick-core/src/main/java/com/juick/Group.java b/juick-core/src/main/java/com/juick/Group.java deleted file mode 100644 index 917e35dd..00000000 --- a/juick-core/src/main/java/com/juick/Group.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.juick; - -/** - * - * @author Ugnich Anton - */ -public class Group { - - public String Name = null; - public int GID = 0; - public int UsersCnt = 0; -} diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java index 0d91cc63..699920f6 100644 --- a/juick-core/src/main/java/com/juick/Message.java +++ b/juick-core/src/main/java/com/juick/Message.java @@ -21,13 +21,13 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.juick.xml.adapters.SimpleDateAdapter; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.ToStringBuilder; import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.List; /** * @author Ugnich Anton @@ -67,30 +67,13 @@ public class Message implements Comparable { private Photo photo; @XmlTransient private Attachment attachment; - public String Video = null; - public Place Place = null; private int likes; - public final List childs; private User to; private Recommendation Recommendation; private String replyQuote; public Message() { tags = new ArrayList<>(); - childs = new ArrayList<>(); - } - - public void parseTags(String strTags) { - if (StringUtils.isNotEmpty(strTags)) { - Set tagSet = new TreeSet<>(tags); - for (String str : strTags.split(" ")) { - Tag tag = new Tag(str); - if (!tagSet.contains(tag)) { - tags.add(tag); - tagSet.add(tag); - } - } - } } @Override @@ -140,47 +123,6 @@ public class Message implements Comparable { return cmp; } - @JsonIgnore - public int getChildsCount() { - int cnt = childs.size(); - for (Message child : childs) { - cnt += child.getChildsCount(); - } - return cnt; - } - - public void cleanupChilds() { - if (!childs.isEmpty()) { - for (Message child : childs) { - child.cleanupChilds(); - } - childs.clear(); - } - } - - @JsonIgnore - public String getTagsString() { - StringBuilder builder = new StringBuilder(); - if (!tags.isEmpty()) { - for (Tag Tag : tags) - builder.append(" *").append(Tag.getName()); - - if (FriendsOnly) - builder.append(" *friends"); - - if (privacy == -2) - builder.append(" *private"); - else if (privacy == -1) - builder.append(" *friends"); - else if (privacy == 2) - builder.append(" *public"); - - if (ReadOnly) - builder.append(" *readonly"); - } - return builder.toString(); - } - @JsonProperty("mid") @XmlAttribute(name = "mid") public int getMid() { diff --git a/juick-core/src/main/java/com/juick/Place.java b/juick-core/src/main/java/com/juick/Place.java deleted file mode 100644 index 9960d984..00000000 --- a/juick-core/src/main/java/com/juick/Place.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ -package com.juick; - -/** - * - * @author Ugnich Anton - */ -public class Place { - - public int pid = 0; - public double lat = 0; - public double lon = 0; - public String name = null; - public int users = 0; - public int messages = 0; - public int distance = 0; -} diff --git a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java index e41ab1f7..4e95e6c2 100644 --- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java +++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java @@ -41,7 +41,7 @@ public class PlainTextFormatter { String title = isReply ? "Reply by @" : "@"; String subtitle = isReply ? markdown ? MessageUtils.escapeMarkdown(StringUtils.defaultString(jmsg.getReplyQuote())) : jmsg.getReplyQuote() - : markdown ? MessageUtils.getMarkdownTags(jmsg) : jmsg.getTagsString(); + : markdown ? MessageUtils.getMarkdownTags(jmsg) : MessageUtils.getTagsString(jmsg); sb.append(title).append(markdown ? String.format("[%s](https://juick.com/%s/)", jmsg.getUser().getName(), jmsg.getUser().getName()) : jmsg.getUser().getName()).append(":\n") .append(subtitle).append("\n"); if (markdown) { @@ -73,7 +73,7 @@ public class PlainTextFormatter { sb.append(txt); } return String.format("@%s:%s\n%s\n#%s (%s%s) %s", - m.getUser().getName(), m.getTagsString(), sb.toString(), formatPostNumber(m), timeAgo, repliesCount, formatUrl(m)); + m.getUser().getName(), MessageUtils.getTagsString(m), sb.toString(), formatPostNumber(m), timeAgo, repliesCount, formatUrl(m)); } public static String formatUrl(com.juick.Message jmsg) { diff --git a/juick-core/src/main/java/com/juick/util/MessageUtils.java b/juick-core/src/main/java/com/juick/util/MessageUtils.java index 9c156c51..ce9415ea 100644 --- a/juick-core/src/main/java/com/juick/util/MessageUtils.java +++ b/juick-core/src/main/java/com/juick/util/MessageUtils.java @@ -24,6 +24,10 @@ import org.apache.commons.lang3.StringUtils; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -148,7 +152,7 @@ public class MessageUtils { StringBuilder sb = new StringBuilder(); boolean isReply = jmsg.getRid() > 0; String title = isReply ? "Reply by @" : "@"; - String subtitle = isReply ? "
" + jmsg.getReplyQuote() + "
" : "" + jmsg.getTagsString() + ""; + String subtitle = isReply ? "
" + jmsg.getReplyQuote() + "
" : "" + getTagsString(jmsg) + ""; boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code")); sb.append(title).append(jmsg.getUser().getName()).append(":

") @@ -217,4 +221,40 @@ public class MessageUtils { public static boolean replyStartsWithQuote(Message msg) { return msg.getRid() > 0 && StringUtils.defaultString(msg.getText()).startsWith(">"); } + public static List parseTags(String strTags) { + List tags = new ArrayList<>(); + if (StringUtils.isNotEmpty(strTags)) { + Set tagSet = new TreeSet<>(tags); + for (String str : strTags.split(" ")) { + Tag tag = new Tag(str); + if (!tagSet.contains(tag)) { + tags.add(tag); + tagSet.add(tag); + } + } + } + return tags; + } + public static String getTagsString(Message msg) { + StringBuilder builder = new StringBuilder(); + List tags = msg.getTags(); + if (!tags.isEmpty()) { + for (Tag Tag : tags) + builder.append(" *").append(Tag.getName()); + + if (msg.FriendsOnly) + builder.append(" *friends"); + + if (msg.getPrivacy() == -2) + builder.append(" *private"); + else if (msg.getPrivacy() == -1) + builder.append(" *friends"); + else if (msg.getPrivacy() == 2) + builder.append(" *public"); + + if (msg.ReadOnly) + builder.append(" *readonly"); + } + return builder.toString(); + } } diff --git a/juick-core/src/test/java/com/juick/MessageTest.java b/juick-core/src/test/java/com/juick/MessageTest.java index 3bdac9be..45c5730c 100644 --- a/juick-core/src/test/java/com/juick/MessageTest.java +++ b/juick-core/src/test/java/com/juick/MessageTest.java @@ -17,11 +17,11 @@ package com.juick; +import com.juick.util.MessageUtils; import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Test; import rocks.xmpp.addr.Jid; -import rocks.xmpp.core.XmppException; import rocks.xmpp.core.session.Extension; import rocks.xmpp.core.session.XmppSession; import rocks.xmpp.core.session.XmppSessionConfiguration; @@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.*; public class MessageTest { @Test - public void equalsShouldBeReturnCorrectResult() throws Exception { + public void equalsShouldBeReturnCorrectResult() { Message message1 = new Message(); Message message2 = new Message(); @@ -75,7 +75,7 @@ public class MessageTest { } @Test - public void compareShouldBeReturnCorrectResult() throws Exception { + public void compareShouldBeReturnCorrectResult() { Message message1 = new Message(); message1.setMid(RandomUtils.nextInt()); @@ -96,7 +96,7 @@ public class MessageTest { } @Test - public void messageWithGreaterMidShouldBeLessThenMesageWithLessMid() throws Exception { + public void messageWithGreaterMidShouldBeLessThenMesageWithLessMid() { Message message1 = new Message(); message1.setMid(RandomUtils.nextInt()); @@ -112,7 +112,7 @@ public class MessageTest { } @Test - public void messageWithGreaterRidAndEqualsMidShouldBeGreaterThenMessageWithLessRid() throws Exception { + public void messageWithGreaterRidAndEqualsMidShouldBeGreaterThenMessageWithLessRid() { Message message1 = new Message(); message1.setMid(RandomUtils.nextInt()); @@ -128,41 +128,41 @@ public class MessageTest { } @Test - public void tagsStringShouldBeEmptyIfNoTags() throws Exception { + public void tagsStringShouldBeEmptyIfNoTags() { Message message = new Message(); - assertThat(message.getTagsString(), isEmptyString()); + assertThat(MessageUtils.getTagsString(message), isEmptyString()); message.FriendsOnly = true; - assertThat(message.getTagsString(), isEmptyString()); + assertThat(MessageUtils.getTagsString(message), isEmptyString()); message.Hidden = true; message.ReadOnly = true; - assertThat(message.getTagsString(), isEmptyString()); + assertThat(MessageUtils.getTagsString(message), isEmptyString()); - message.parseTags(" "); + message.setTags(MessageUtils.parseTags(" ")); - assertThat(message.getTagsString(), isEmptyString()); + assertThat(MessageUtils.getTagsString(message), isEmptyString()); } @Test - public void tagsStringShouldHasNoTagDuplicates() throws Exception { + public void tagsStringShouldHasNoTagDuplicates() { Message message = new Message(); - message.parseTags("test"); + message.setTags(MessageUtils.parseTags("test")); - assertThat(StringUtils.countMatches(message.getTagsString(), "*test"), equalTo(1)); + assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1)); - message.parseTags("test test"); + message.setTags(MessageUtils.parseTags("test test")); - assertThat(StringUtils.countMatches(message.getTagsString(), "*test"), equalTo(1)); + assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1)); - message.parseTags("test test ab test"); + message.setTags(MessageUtils.parseTags("test test ab test")); - assertThat(StringUtils.countMatches(message.getTagsString(), "*test"), equalTo(1)); - assertThat(StringUtils.countMatches(message.getTagsString(), "*ab"), equalTo(1)); + assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*test"), equalTo(1)); + assertThat(StringUtils.countMatches(MessageUtils.getTagsString(message), "*ab"), equalTo(1)); } @Test public void tagsShouldBeDeserializedFromXml() throws JAXBException { @@ -171,7 +171,7 @@ public class MessageTest { .build(); XmppSession xmpp = new XmppSession("juick.com", configuration) { @Override - public void connect(Jid from) throws XmppException { + public void connect(Jid from) { } diff --git a/juick-notifications/src/main/java/com/juick/components/Notifications.java b/juick-notifications/src/main/java/com/juick/components/Notifications.java index 0402f36c..1513428b 100644 --- a/juick-notifications/src/main/java/com/juick/components/Notifications.java +++ b/juick-notifications/src/main/java/com/juick/components/Notifications.java @@ -23,6 +23,7 @@ import com.juick.ExternalToken; import com.juick.User; import com.juick.formatters.PlainTextFormatter; import com.juick.server.component.MessageEvent; +import com.juick.util.MessageUtils; import com.turo.pushy.apns.ApnsClient; import com.turo.pushy.apns.PushNotificationResponse; import com.turo.pushy.apns.util.ApnsPayloadBuilder; @@ -143,7 +144,7 @@ public class Notifications implements NotificationClientListener, AutoCloseable, try { String text1 = "@" + jmsg.getUser().getName(); if (!jmsg.getTags().isEmpty()) { - text1 += ":" + StringEscapeUtils.escapeXml11(jmsg.getTagsString()); + text1 += ":" + StringEscapeUtils.escapeXml11(MessageUtils.getTagsString(jmsg)); } String text2 = StringEscapeUtils.escapeXml11(StringUtils.defaultString(jmsg.getText())); String xml = "" diff --git a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java index fd93a5e1..9c252f1f 100644 --- a/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server-jdbc/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -85,15 +85,11 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ msg.FriendsOnly = msg.getPrivacy() < 0; msg.setReplies(rs.getInt(11)); msg.setAttachmentType(rs.getString(12)); - if (rs.getDouble(13) != 0) { - msg.Place = new com.juick.Place(); - msg.Place.lat = rs.getDouble(14); - msg.Place.lon = rs.getDouble(15); - } + // TODO: reorder after place deletion msg.setLikes(rs.getInt(16)); msg.Hidden = rs.getBoolean(17); String tagsStr = rs.getString(18); - msg.parseTags(tagsStr); + msg.setTags(MessageUtils.parseTags(tagsStr)); msg.setRepliesBy(rs.getString(19)); msg.setText(rs.getString(20)); msg.setReplyQuote(MessageUtils.formatQuote(rs.getString(21))); diff --git a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java index d24a6281..d9f095ac 100644 --- a/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java +++ b/juick-server-jdbc/src/test/java/com/juick/service/MessageServiceTest.java @@ -24,6 +24,7 @@ import com.juick.configuration.DataConfiguration; import com.juick.configuration.RepositoryConfiguration; import com.juick.server.helpers.AnonymousUser; import com.juick.server.helpers.TagStats; +import com.juick.util.MessageUtils; import org.apache.commons.lang3.StringUtils; import org.junit.*; import org.junit.runner.RunWith; @@ -190,7 +191,7 @@ public class MessageServiceTest extends AbstractJUnit4SpringContextTests { assertEquals("db tags should not be escaped", dbTagName, htmlTag.getName()); int mid4 = messagesService.createMessage(user_id, "yoyoyo", null, null); Message msg4 = messagesService.getMessage(mid4); - assertEquals("tags string should be empty", StringUtils.EMPTY, msg4.getTagsString()); + assertEquals("tags string should be empty", StringUtils.EMPTY, MessageUtils.getTagsString(msg4)); messagesService.deleteMessage(user_id, mid4); } @Test diff --git a/juick-server/src/main/java/com/juick/server/XMPPConnection.java b/juick-server/src/main/java/com/juick/server/XMPPConnection.java index edc547eb..ef0291c0 100644 --- a/juick-server/src/main/java/com/juick/server/XMPPConnection.java +++ b/juick-server/src/main/java/com/juick/server/XMPPConnection.java @@ -292,7 +292,7 @@ public class XMPPConnection implements AutoCloseable { } } com.juick.Message fullMsg = messagesService.getMessage(jmsg.getMid()); - String txt = "@" + jmsg.getUser().getName() + ":" + fullMsg.getTagsString() + "\n"; + String txt = "@" + jmsg.getUser().getName() + ":" + MessageUtils.getTagsString(fullMsg) + "\n"; String attachmentUrl = MessageUtils.attachmentUrl(fullMsg); if (StringUtils.isNotEmpty(attachmentUrl)) { txt += attachmentUrl + "\n"; @@ -362,7 +362,7 @@ public class XMPPConnection implements AutoCloseable { recomm.getMid(), jmsg.getUser().getUid()); String txt = "Recommended by @" + recomm.getUser().getName() + ":\n"; - txt += "@" + jmsg.getUser().getName() + ":" + jmsg.getTagsString() + "\n"; + txt += "@" + jmsg.getUser().getName() + ":" + MessageUtils.getTagsString(jmsg) + "\n"; String attachmentUrl = MessageUtils.attachmentUrl(jmsg); if (StringUtils.isNotEmpty(attachmentUrl)) { txt += attachmentUrl + "\n"; diff --git a/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java b/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java index 3ee458c8..7be9ec09 100644 --- a/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java +++ b/juick-server/src/main/java/com/juick/server/api/rss/MessagesView.java @@ -109,7 +109,7 @@ public class MessagesView extends AbstractRssFeedView { private Item createRssItem(Message msg) { Item item = new Item(); String messageUrl = String.format("http://juick.com/%s/%d", msg.getUser().getName(), msg.getMid()); - String messageTitle = String.format("@%s: %s", msg.getUser().getName(), msg.getTagsString()); + String messageTitle = String.format("@%s: %s", msg.getUser().getName(), MessageUtils.getTagsString(msg)); boolean isCode = msg.getTags().stream().anyMatch(t -> t.getName().equals("code")); String messageDescription = isCode ? MessageUtils.formatMessageCode(StringUtils.defaultString(msg.getText())) : MessageUtils.formatMessage(StringUtils.defaultString(msg.getText())); diff --git a/juick-www/src/main/java/com/juick/www/controllers/Messages.java b/juick-www/src/main/java/com/juick/www/controllers/Messages.java index 11dafda3..ea66e711 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/Messages.java +++ b/juick-www/src/main/java/com/juick/www/controllers/Messages.java @@ -16,6 +16,7 @@ */ package com.juick.www.controllers; +import com.juick.Message; import com.juick.Tag; import com.juick.formatters.PlainTextFormatter; import com.juick.server.util.HttpForbiddenException; @@ -23,6 +24,7 @@ import com.juick.server.util.HttpNotFoundException; import com.juick.server.util.UserUtils; import com.juick.server.util.WebUtils; import com.juick.service.*; +import com.juick.util.MessageUtils; import com.juick.www.Utils; import org.apache.commons.codec.CharEncoding; import org.apache.commons.lang3.StringUtils; @@ -533,7 +535,7 @@ public class Messages { } model.addAttribute("msg", msg); - String title = msg.getUser().getName() + ": " + msg.getTagsString(); + String title = msg.getUser().getName() + ": " + MessageUtils.getTagsString(msg); model.addAttribute("title", title); model.addAttribute("visitor", visitor); @@ -576,26 +578,11 @@ public class Messages { List replies = messagesService.getReplies(msg.getMid()); List blUIDs = new ArrayList<>(); - for (int i = 0; i < replies.size(); i++) { - com.juick.Message reply = replies.get(i); + for (Message reply : replies) { if (reply.getUser().getUid() != msg.getUser().getUid() && !blUIDs.contains(reply.getUser().getUid())) { blUIDs.add(reply.getUser().getUid()); } - if (reply.getReplyto() > 0) { - boolean added = false; - for (int n = 0; n < replies.size(); n++) { - if (replies.get(n).getRid() == reply.getReplyto()) { - replies.get(n).childs.add(reply); - added = true; - break; - } - } - if (!added) { - reply.setReplyto(0); - } - } - reply.VisitorCanComment = visitor.getUid() > 0; if (visitor.getUid() > 0) { boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid(); @@ -604,18 +591,7 @@ public class Messages { && msg.VisitorCanComment && (isReplyAuthor || !userService.isInBLAny(visitor.getUid(), reply.getUser().getUid()))); } } - - boolean foldable = false; - if (replies.size() > 10) { - for (int i = 0; i < replies.size() - 1; i++) { - if (replies.get(i).getChildsCount() > 1) { - foldable = true; - break; - } - } - } model.addAttribute("replies", replies); - model.addAttribute("foldable", foldable); model.addAttribute("showAdv", visitor.getUid() == 0); UriComponents builder = ServletUriComponentsBuilder.fromCurrentRequestUri().build(); String queryString = builder.getQuery(); diff --git a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java index 4d3b4351..6d7de920 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java +++ b/juick-www/src/main/java/com/juick/www/controllers/NewMessage.java @@ -22,6 +22,7 @@ import com.juick.User; import com.juick.server.helpers.AnonymousUser; import com.juick.server.util.*; import com.juick.service.*; +import com.juick.util.MessageUtils; import com.juick.www.WebApp; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StringEscapeUtils; @@ -148,7 +149,7 @@ public class NewMessage { } if (webApp.getXmpp() != null) { - xmsg.setBody("@" + jmsg.getUser().getName() + ":" + jmsg.getTagsString() + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid); + xmsg.setBody("@" + jmsg.getUser().getName() + ":" + MessageUtils.getTagsString(jmsg) + "\n" + body + "\n\n#" + mid + " http://juick.com/" + mid); xmsg.setTo(Jid.of("juick@s2s.juick.com")); webApp.getXmpp().send(xmsg); diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java index c8244df4..9189c2be 100644 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java +++ b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/FormatterExtension.java @@ -30,7 +30,6 @@ public class FormatterExtension extends AbstractExtension { public Map getFilters() { Map filters = new HashMap<>(); filters.put("formatMessage", new FormatMessageFilter()); - filters.put("formatReplies", new FormatRepliesFilter()); filters.put("prettyTime", new PrettyTimeFilter()); filters.put("timestamp", new TimestampFilter()); filters.put("tagsList", new TagsListFilter()); diff --git a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatRepliesFilter.java b/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatRepliesFilter.java deleted file mode 100644 index f375ecdb..00000000 --- a/juick-www/src/main/java/com/mitchellbosecke/pebble/extension/filters/FormatRepliesFilter.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2008-2017, Juick - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.mitchellbosecke.pebble.extension.filters; - -import com.juick.Message; -import com.mitchellbosecke.pebble.extension.Filter; - -import java.util.List; -import java.util.Map; - -public class FormatRepliesFilter implements Filter { - @Override - public Object apply(Object input, Map args) { - if (input instanceof Message) { - int replies = ((Message)input).getChildsCount(); - int ld = replies % 10; - int lh = replies % 100; - if ((lh < 10 || lh > 20) && ld == 1) { - return replies + " ответ"; - } else if ((lh < 10 || lh > 20) && ld > 1 && ld < 5) { - return replies + " ответа"; - } else { - return replies + " ответов"; - } - } - throw new IllegalArgumentException("invalid input"); - } - - @Override - public List getArgumentNames() { - return null; - } -} diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java index 2cc8fed2..0baf53b6 100644 --- a/src/test/java/com/juick/tests/MessageTests.java +++ b/src/test/java/com/juick/tests/MessageTests.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.juick.Message; import com.juick.util.DateFormattersHolder; +import com.juick.util.MessageUtils; import org.apache.commons.codec.CharEncoding; import org.json.JSONObject; import org.junit.Test; @@ -49,7 +50,7 @@ public class MessageTests { public void messageParserSerializer() throws ParseException, ParserConfigurationException, IOException, SAXException, JAXBException { Message msg = new Message(); - msg.parseTags("test test" + (char) 0xA0 + "2 test3"); + msg.setTags(MessageUtils.parseTags("test test" + (char) 0xA0 + "2 test3")); assertEquals("First tag must be", "test", msg.getTags().get(0).getName()); assertEquals("Third tag must be", "test3", msg.getTags().get(2).getName()); assertEquals("Count of tags must be", 3, msg.getTags().size()); -- cgit v1.2.3