aboutsummaryrefslogtreecommitdiff
path: root/juick-core/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-03-13 15:18:03 +0300
committerGravatar Vitaly Takmazov2018-03-13 15:18:03 +0300
commitf010d75872763547ecbe621ae3e8eb967950453f (patch)
tree385d3f0a960e10c7fd054fcb71ea280142495d31 /juick-core/src/main
parentcd7e11563721d223b30f9b9edaa8295c2c97c6f7 (diff)
core: cleanup unused message properties
Diffstat (limited to 'juick-core/src/main')
-rw-r--r--juick-core/src/main/java/com/juick/Group.java28
-rw-r--r--juick-core/src/main/java/com/juick/Message.java62
-rw-r--r--juick-core/src/main/java/com/juick/Place.java32
-rw-r--r--juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java4
-rw-r--r--juick-core/src/main/java/com/juick/util/MessageUtils.java42
5 files changed, 45 insertions, 123 deletions
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 <http://www.gnu.org/licenses/>.
- */
-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<Message> 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<Tag> 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 <http://www.gnu.org/licenses/>.
- */
-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 ? "<b>Reply by @" : "<b>@";
- String subtitle = isReply ? "<blockquote>" + jmsg.getReplyQuote() + "</blockquote>" : "<i>" + jmsg.getTagsString() + "</i>";
+ String subtitle = isReply ? "<blockquote>" + jmsg.getReplyQuote() + "</blockquote>" : "<i>" + getTagsString(jmsg) + "</i>";
boolean isCode = jmsg.getTags().stream().anyMatch(t -> t.getName().equals("code"));
sb.append(title).append(jmsg.getUser().getName()).append(":</b></br/>")
@@ -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<Tag> parseTags(String strTags) {
+ List<Tag> tags = new ArrayList<>();
+ if (StringUtils.isNotEmpty(strTags)) {
+ Set<Tag> 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<Tag> 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();
+ }
}