From 1a2830588131173d8fbfeb1fe03c466b4cf30e46 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Wed, 30 Nov 2016 16:49:11 +0300
Subject: juick-core: fix attachment serialization
---
juick-core/src/main/java/com/juick/Message.java | 33 ++++++++++++++++-----
juick-core/src/main/java/com/juick/Photo.java | 34 ++++++++++++++++++++++
.../com/juick/formatters/PlainTextFormatter.java | 4 +--
juick-rss/src/main/java/com/juick/rss/Main.java | 6 ++--
.../java/com/juick/server/MessagesQueries.java | 4 +--
.../com/juick/service/MessagesServiceImpl.java | 4 +--
.../src/main/java/com/juick/www/PageTemplates.java | 6 ++--
.../src/main/java/com/juick/www/UserThread.java | 12 ++++----
.../com/juick/xmpp/extensions/JuickMessage.java | 6 ++--
.../java/com/juick/json/MessageSerializer.java | 13 +++++++--
.../java/com/juick/tests/SerializationTests.java | 15 +++++-----
11 files changed, 98 insertions(+), 39 deletions(-)
create mode 100644 juick-core/src/main/java/com/juick/Photo.java
diff --git a/juick-core/src/main/java/com/juick/Message.java b/juick-core/src/main/java/com/juick/Message.java
index b5fc2b89..d3f28e22 100644
--- a/juick-core/src/main/java/com/juick/Message.java
+++ b/juick-core/src/main/java/com/juick/Message.java
@@ -57,9 +57,9 @@ public class Message implements Comparable {
@XmlTransient
public int Replies = 0;
public String RepliesBy = null;
+ private String attachmentType;
@XmlTransient
- public String AttachmentType = null;
- public String Photo = null;
+ private Photo photo;
public String Video = null;
public Place Place = null;
@XmlTransient
@@ -87,8 +87,8 @@ public class Message implements Comparable {
ReadOnly = msg.ReadOnly;
Hidden = msg.Hidden;
Replies = msg.Replies;
- AttachmentType = msg.AttachmentType;
- Photo = msg.Photo;
+ attachmentType = msg.attachmentType;
+ photo = msg.photo;
Video = msg.Video;
Place = msg.Place;
Likes = msg.Likes;
@@ -157,15 +157,16 @@ public class Message implements Comparable {
}
}
+ @JsonIgnore
public String getAttachmentURL() {
- if (AttachmentType != null) {
+ if (attachmentType != null) {
String url = "http://i.juick.com/";
- url += AttachmentType.equals("mp4") ? "video" : "photos-1024";
+ url += attachmentType.equals("mp4") ? "video" : "photos-1024";
url += "/" + getMid();
if (getRid() > 0) {
url += "-" + getRid();
}
- url += "." + AttachmentType;
+ url += "." + attachmentType;
return url;
} else {
return null;
@@ -309,4 +310,22 @@ public class Message implements Comparable {
public void setPrivacy(int privacy) {
this.privacy = privacy;
}
+
+ public Photo getPhoto() {
+ return photo;
+ }
+
+ public void setPhoto(Photo photo) {
+ this.photo = photo;
+ }
+
+ @XmlAttribute(name = "attach")
+ @JsonProperty("attach")
+ public String getAttachmentType() {
+ return attachmentType;
+ }
+
+ public void setAttachmentType(String attachmentType) {
+ this.attachmentType = attachmentType;
+ }
}
diff --git a/juick-core/src/main/java/com/juick/Photo.java b/juick-core/src/main/java/com/juick/Photo.java
new file mode 100644
index 00000000..010d81a4
--- /dev/null
+++ b/juick-core/src/main/java/com/juick/Photo.java
@@ -0,0 +1,34 @@
+package com.juick;
+
+/**
+ * Created by vitalyster on 30.11.2016.
+ */
+public class Photo {
+ private String small;
+ private String medium;
+ private String thumbnail;
+
+ public String getSmall() {
+ return small;
+ }
+
+ public void setSmall(String small) {
+ this.small = small;
+ }
+
+ public String getMedium() {
+ return medium;
+ }
+
+ public void setMedium(String medium) {
+ this.medium = medium;
+ }
+
+ public String getThumbnail() {
+ return thumbnail;
+ }
+
+ public void setThumbnail(String thumbnail) {
+ this.thumbnail = thumbnail;
+ }
+}
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 be2c6838..c6e9022a 100644
--- a/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
+++ b/juick-core/src/main/java/com/juick/formatters/PlainTextFormatter.java
@@ -11,8 +11,8 @@ public class PlainTextFormatter {
String subtitle = isReply ? jmsg.getReplyQuote() : jmsg.getTagsString();
sb.append(title).append(jmsg.getUser().getName()).append(":\n")
.append(subtitle).append("\n").append(jmsg.getText()).append("\n");
- if (jmsg.Photo != null) {
- sb.append(jmsg.Photo);
+ if (jmsg.getPhoto() != null) {
+ sb.append(jmsg.getAttachmentURL());
}
return sb.toString();
}
diff --git a/juick-rss/src/main/java/com/juick/rss/Main.java b/juick-rss/src/main/java/com/juick/rss/Main.java
index 04d87729..adb20a0d 100644
--- a/juick-rss/src/main/java/com/juick/rss/Main.java
+++ b/juick-rss/src/main/java/com/juick/rss/Main.java
@@ -146,11 +146,11 @@ public class Main extends HttpServlet {
out.println("" + StringEscapeUtils.escapeHtml4(msg.getTags().get(n).getName()) + "");
}
}
- if (msg.AttachmentType != null) {
- if (msg.AttachmentType.equals("jpg")) {
+ if (msg.getAttachmentType() != null) {
+ if (msg.getAttachmentType().equals("jpg")) {
out.println("");
out.println("");
- } else if (msg.AttachmentType.equals("png")) {
+ } else if (msg.getAttachmentType().equals("png")) {
out.println("");
out.println("");
}
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 9d4284bc..fd1e5b51 100644
--- a/juick-server/src/main/java/com/juick/server/MessagesQueries.java
+++ b/juick-server/src/main/java/com/juick/server/MessagesQueries.java
@@ -61,7 +61,7 @@ public class MessagesQueries {
msg.setPrivacy(rs.getInt(10));
msg.FriendsOnly = msg.getPrivacy() < 0;
msg.Replies = rs.getInt(11);
- msg.AttachmentType = rs.getString(12);
+ msg.setAttachmentType(rs.getString(12));
if (rs.getDouble(13) != 0) {
msg.Place = new com.juick.Place();
msg.Place.lat = rs.getDouble(14);
@@ -279,7 +279,7 @@ public class MessagesQueries {
msg.getUser().setName(rs.getString(2));
msg.setReplyto(rs.getInt(3));
msg.setDate(rs.getTimestamp(4));
- msg.AttachmentType = rs.getString(5);
+ msg.setAttachmentType(rs.getString(5));
msg.setText(rs.getString(6));
String quote = rs.getString(7);
if (!StringUtils.isEmpty(quote)) {
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 422c9616..948e9137 100644
--- a/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
+++ b/juick-server/src/main/java/com/juick/service/MessagesServiceImpl.java
@@ -62,7 +62,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
msg.setPrivacy(rs.getInt(10));
msg.FriendsOnly = msg.getPrivacy() < 0;
msg.Replies = rs.getInt(11);
- msg.AttachmentType = rs.getString(12);
+ msg.setAttachmentType(rs.getString(12));
if (rs.getDouble(13) != 0) {
msg.Place = new com.juick.Place();
msg.Place.lat = rs.getDouble(14);
@@ -311,7 +311,7 @@ public class MessagesServiceImpl extends BaseJdbcService implements MessagesServ
msg.getUser().setName(rs.getString(2));
msg.setReplyto(rs.getInt(3));
msg.setDate(rs.getTimestamp(4));
- msg.AttachmentType = rs.getString(5);
+ msg.setAttachmentType(rs.getString(5));
msg.setText(rs.getString(6));
String quote = rs.getString(7);
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 74b8b543..180e852f 100644
--- a/juick-www/src/main/java/com/juick/www/PageTemplates.java
+++ b/juick-www/src/main/java/com/juick/www/PageTemplates.java
@@ -329,12 +329,12 @@ public class PageTemplates {
out.println("
" + tagsStr + "
");
out.println(" ");
- if (msg.AttachmentType != null) {
- String fname = msg.getMid() + "." + msg.AttachmentType;
+ if (msg.getAttachmentType() != null) {
+ String fname = msg.getMid() + "." + msg.getAttachmentType();
out.println("
");
}
out.println(" " + txt + "
");
- if (msg.AttachmentType != null) {
+ if (msg.getAttachmentType() != null) {
out.println(" ");
}
out.print("