diff options
Diffstat (limited to 'juick-core/src/main')
3 files changed, 58 insertions, 44 deletions
diff --git a/juick-core/src/main/java/com/juick/json/JSONSerializer.java b/juick-core/src/main/java/com/juick/json/JSONSerializer.java index 142cacf0..3dc9e04e 100644 --- a/juick-core/src/main/java/com/juick/json/JSONSerializer.java +++ b/juick-core/src/main/java/com/juick/json/JSONSerializer.java @@ -17,6 +17,25 @@ import org.json.JSONObject; */ public abstract class JSONSerializer<T> { + public enum URIScheme { + Plain, + Secure + } + + private URIScheme uriScheme; + + public URIScheme getUriScheme() { + return uriScheme; + } + + public void setUriScheme(URIScheme uriScheme) { + this.uriScheme = uriScheme; + } + + public JSONSerializer() { + this.uriScheme = URIScheme.Plain; + } + /** * * @param json diff --git a/juick-core/src/main/java/com/juick/json/MessageSerializer.java b/juick-core/src/main/java/com/juick/json/MessageSerializer.java index d5adfa6e..9da828c9 100644 --- a/juick-core/src/main/java/com/juick/json/MessageSerializer.java +++ b/juick-core/src/main/java/com/juick/json/MessageSerializer.java @@ -126,9 +126,10 @@ public class MessageSerializer extends JSONSerializer<Message> { if (msg.AttachmentType != null) { String fname = msg.getMID() + (msg.getRID() > 0 ? "-" + msg.getRID() : "") + "." + msg.AttachmentType; JSONObject photo = new JSONObject(); - photo.put("thumbnail", "http://i.juick.com/ps/" + fname); - photo.put("small", "http://i.juick.com/photos-512/" + fname); - photo.put("medium", "http://i.juick.com/photos-1024/" + fname); + String protocol = getUriScheme() == URIScheme.Plain ? "http:" : "https:"; + photo.put("thumbnail", protocol + "//i.juick.com/ps/" + fname); + photo.put("small", protocol + "//i.juick.com/photos-512/" + fname); + photo.put("medium", protocol + "//i.juick.com/photos-1024/" + fname); json.put("photo", photo); } } catch (JSONException e) { diff --git a/juick-core/src/main/java/com/juick/server/MessagesQueries.java b/juick-core/src/main/java/com/juick/server/MessagesQueries.java index 3c848f54..b39de0ed 100644 --- a/juick-core/src/main/java/com/juick/server/MessagesQueries.java +++ b/juick-core/src/main/java/com/juick/server/MessagesQueries.java @@ -46,34 +46,34 @@ public class MessagesQueries { public Message mapRow(ResultSet rs, int rowNum) throws SQLException { Message msg = new Message(); msg.setMID(rs.getInt(1)); - msg.setUser(new User()); - msg.getUser().setUID(rs.getInt(2)); - msg.getUser().setUName(rs.getString(3)); - msg.TimeAgo = rs.getInt(4); - msg.setDate(rs.getTimestamp(5)); - msg.ReadOnly = rs.getBoolean(6); - msg.Privacy = rs.getInt(7); + msg.setRID(rs.getInt(2)); + msg.ReplyTo = rs.getInt(3); + User user = new User(); + user.setUID(rs.getInt(4)); + user.setUName(rs.getString(5)); + user.Banned = rs.getBoolean(6); + msg.setUser(user); + msg.TimeAgo = rs.getInt(7); + msg.setDate(rs.getTimestamp(8)); + msg.ReadOnly = rs.getBoolean(9); + msg.Privacy = rs.getInt(10); msg.FriendsOnly = msg.Privacy < 0; - msg.Replies = rs.getInt(8); - msg.AttachmentType = rs.getString(9); - //if (rs.getInt(10) > 0) { - // msg.Place = PlacesQueries.getPlace(sql, rs.getInt(9)); - //} - if (rs.getDouble(10) != 0) { + msg.Replies = rs.getInt(11); + msg.AttachmentType = rs.getString(12); + if (rs.getDouble(13) != 0) { msg.Place = new com.juick.Place(); - msg.Place.lat = rs.getDouble(11); - msg.Place.lon = rs.getDouble(12); + msg.Place.lat = rs.getDouble(14); + msg.Place.lon = rs.getDouble(15); } - msg.Likes = rs.getInt(13); - msg.Hidden = rs.getBoolean(14); + msg.Likes = rs.getInt(16); + msg.Hidden = rs.getBoolean(17); // parse tags string - String tagsStr = rs.getString(15); + String tagsStr = rs.getString(18); if (tagsStr != null) { - Arrays.asList(tagsStr.split(" ")) - .stream().forEach(t -> msg.Tags.add(new Tag(t))); + Arrays.stream(tagsStr.split(" ")).forEach(t -> msg.Tags.add(new Tag(t))); } - msg.RepliesBy = rs.getString(16); - msg.setText(rs.getString(17)); + msg.RepliesBy = rs.getString(19); + msg.setText(rs.getString(20)); return msg; } } @@ -234,7 +234,8 @@ public class MessagesQueries { public static com.juick.Message getMessage(JdbcTemplate sql, int mid) { try { - return sql.queryForObject("SELECT messages.message_id,messages.user_id,users.nick," + return sql.queryForObject("SELECT messages.message_id, 0 as rid, 0 as replyto, " + + "messages.user_id,users.nick, 0 as banned, " + "TIMESTAMPDIFF(MINUTE,messages.ts,NOW())," + "messages.ts," + "messages.readonly,messages.privacy,messages.replies," @@ -570,7 +571,8 @@ public class MessagesQueries { public static List<com.juick.Message> getMessages(JdbcTemplate sql, List<Integer> mids) { if (!mids.isEmpty()) { - return sql.query("SELECT messages.message_id,messages.user_id,users.nick," + return sql.query("SELECT messages.message_id, 0 as rid, 0 as replyto, " + + "messages.user_id,users.nick, 0 as banned, " + "TIMESTAMPDIFF(MINUTE,messages.ts,NOW())," + "messages.ts," + "messages.readonly,messages.privacy,messages.replies," @@ -588,24 +590,16 @@ public class MessagesQueries { } public static List<com.juick.Message> getReplies(JdbcTemplate sql, int mid) { - return sql.query("SELECT replies.reply_id,replies.replyto,replies.user_id,users.nick,users.banned,replies.txt," + - "TIMESTAMPDIFF(MINUTE,replies.ts,NOW()),replies.ts,replies.attach FROM replies INNER JOIN users " + + return sql.query("SELECT 0 as mid, replies.reply_id,replies.replyto, " + + "replies.user_id,users.nick,users.banned, " + + "TIMESTAMPDIFF(MINUTE,replies.ts,NOW()),replies.ts," + + "0 as readonly, 0 as privacy, 0 as replies," + + "replies.attach, 0 as place_id, 0 as lat," + + "0 as lon, 0 as likes, 0 as hidden," + + "NULL as tags,NULL as repliesby, replies.txt " + + "FROM replies INNER JOIN users " + "ON replies.user_id=users.id WHERE replies.message_id=? ORDER BY replies.reply_id ASC", - new Object[]{mid}, (rs, num) -> { - com.juick.Message msg = new com.juick.Message(); - msg.setMID(mid); - msg.setRID(rs.getInt(1)); - msg.ReplyTo = rs.getInt(2); - msg.setUser(new User()); - msg.getUser().setUID(rs.getInt(3)); - msg.getUser().setUName(rs.getString(4)); - msg.getUser().Banned = rs.getBoolean(5); - msg.setText(rs.getString(6)); - msg.TimeAgo = rs.getInt(7); - msg.setDate(rs.getTimestamp(8)); - msg.AttachmentType = rs.getString(9); - return msg; - }); + new MessageMapper(), mid); } public static boolean setMessagePopular(JdbcTemplate sql, int mid, int popular) { |