diff options
author | Vitaly Takmazov | 2016-12-01 23:14:16 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-12-01 23:23:10 +0300 |
commit | a797587800b68821a810fa3d833352dc272d42f7 (patch) | |
tree | 75bdd94be017b7c5adcf4551f717a7a872e81816 | |
parent | 8b29dc19a288cf50246af0a3834d45e07da51642 (diff) |
juick-server: fix serialization, vNext
4 files changed, 50 insertions, 22 deletions
diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java index 0bb75c57..702b74e5 100644 --- a/juick-core/src/main/java/com/juick/Message.java +++ b/juick-core/src/main/java/com/juick/Message.java @@ -21,6 +21,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.juick.xml.adapters.SimpleDateAdapter; +import org.apache.commons.lang3.StringUtils; import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @@ -42,28 +43,30 @@ public class Message implements Comparable { private List<Tag> Tags = new ArrayList<>(); private Date date; @XmlTransient + @JsonIgnore public int TimeAgo = 0; @JsonIgnore private int privacy = 1; @XmlTransient + @JsonIgnore public boolean FriendsOnly = false; @XmlTransient + @JsonIgnore public boolean ReadOnly = false; @XmlTransient + @JsonIgnore public boolean Hidden = false; @JsonIgnore @XmlTransient public boolean VisitorCanComment = true; private int replies = 0; - public String RepliesBy = null; + private String repliesBy; private String attachmentType; @XmlTransient private Photo photo; public String Video = null; public Place Place = null; - @XmlTransient - public int Likes = 0; - private boolean liked = false; + private int likes; public List<Message> childs = new ArrayList<>(); private PM PM; private Recommendation Recommendation; @@ -90,8 +93,7 @@ public class Message implements Comparable { photo = msg.photo; Video = msg.Video; Place = msg.Place; - Likes = msg.Likes; - setLiked(msg.isLiked()); + setLikes(msg.getLikes()); childs = msg.childs; PM = msg.PM; Recommendation = msg.Recommendation; @@ -138,7 +140,7 @@ public class Message implements Comparable { return 0; } - + @JsonIgnore public int getChildsCount() { int cnt = childs.size(); for (Message child : childs) { @@ -265,15 +267,6 @@ public class Message implements Comparable { } @XmlTransient - public boolean isLiked() { - return liked; - } - - public void setLiked(boolean liked) { - this.liked = liked; - } - - @XmlTransient public String getReplyQuote() { return replyQuote; } @@ -336,4 +329,39 @@ public class Message implements Comparable { public void setReplies(int replies) { this.replies = replies; } + @XmlTransient + public int getLikes() { + return likes; + } + + public void setLikes(int likes) { + this.likes = likes; + } + + @JsonProperty("repliesby") + public String getRepliesBy() { + return repliesBy; + } + + public void setRepliesBy(String repliesBy) { + this.repliesBy = repliesBy; + } + @JsonProperty("photo") + @XmlTransient + public Photo getPhotoURLs() { + if (StringUtils.isNotBlank(attachmentType)) { + Photo photo = new Photo(); + if (rid > 0) { + photo.setSmall(String.format("https://i.juick.com/photos-512/%d-%d.%s", mid, rid, attachmentType)); + photo.setMedium(String.format("https://i.juick.com/photos-1024/%d-%d.%s", mid, rid, attachmentType)); + photo.setThumbnail(String.format("https://i.juick.com/ps/%d-%d.%s", mid, rid, attachmentType)); + } else { + photo.setSmall(String.format("https://i.juick.com/photos-512/%d.%s", mid, attachmentType)); + photo.setMedium(String.format("https://i.juick.com/photos-1024/%d.%s", mid, attachmentType)); + photo.setThumbnail(String.format("https://i.juick.com/ps/%d.%s", mid, attachmentType)); + } + return photo; + } + return null; + } } diff --git a/juick-server/src/main/java/com/juick/server/MessagesQueries.java b/juick-server/src/main/java/com/juick/server/MessagesQueries.java index b028ec34..cac36979 100644 --- a/juick-server/src/main/java/com/juick/server/MessagesQueries.java +++ b/juick-server/src/main/java/com/juick/server/MessagesQueries.java @@ -68,14 +68,14 @@ public class MessagesQueries { msg.Place.lat = rs.getDouble(14); msg.Place.lon = rs.getDouble(15); } - msg.Likes = rs.getInt(16); + msg.setLikes(rs.getInt(16)); msg.Hidden = rs.getBoolean(17); // parse tags string String tagsStr = rs.getString(18); if (tagsStr != null) { Arrays.stream(tagsStr.split(" ")).forEach(t -> msg.getTags().add(new Tag(t))); } - msg.RepliesBy = rs.getString(19); + msg.setRepliesBy(rs.getString(19)); msg.setText(rs.getString(20)); msg.setReplyQuote(MessageUtils.formatQuote(rs.getString(21))); return msg; 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 537219d6..aa3e454f 100644 --- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java +++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java @@ -67,14 +67,14 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ msg.Place.lat = rs.getDouble(14); msg.Place.lon = rs.getDouble(15); } - msg.Likes = rs.getInt(16); + msg.setLikes(rs.getInt(16)); msg.Hidden = rs.getBoolean(17); // parse tags string String tagsStr = rs.getString(18); if (tagsStr != null) { Arrays.stream(tagsStr.split(" ")).forEach(t -> msg.getTags().add(new Tag(t))); } - msg.RepliesBy = rs.getString(19); + msg.setRepliesBy(rs.getString(19)); msg.setText(rs.getString(20)); msg.setReplyQuote(MessageUtils.formatQuote(rs.getString(21))); return msg; diff --git a/juick-www/src/main/java/com/juick/www/PageTemplates.java b/juick-www/src/main/java/com/juick/www/PageTemplates.java index 685c81fe..1939b48f 100644 --- a/juick-www/src/main/java/com/juick/www/PageTemplates.java +++ b/juick-www/src/main/java/com/juick/www/PageTemplates.java @@ -360,8 +360,8 @@ public class PageTemplates { out.println("</nav>"); out.print(" <nav class=\"s\">"); - if (msg.Likes > 0) { - out.print("<a href=\"/" + msg.getUser().getName() + "/" + msg.getMid() + "\" class=\"likes\"><i data-icon=\"ei-heart\" data-size=\"s\"></i> " + msg.Likes + "</a>"); + if (msg.getLikes() > 0) { + out.print("<a href=\"/" + msg.getUser().getName() + "/" + msg.getMid() + "\" class=\"likes\"><i data-icon=\"ei-heart\" data-size=\"s\"></i> " + msg.getLikes() + "</a>"); } if (msg.getReplies() > 0) { out.print("<a href=\"/" + msg.getUser().getName() + "/" + msg.getMid() + "\" class=\"replies\"><i data-icon=\"ei-comment\" data-size=\"s\"></i> " + msg.getReplies() + "</a>"); |