From 8d1d8d845beb6bc6c99d90722169b77c3dff91e7 Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Fri, 30 Aug 2013 13:48:38 +0700 Subject: Messages --- src/com/juick/json/Message.java | 12 +++++++----- src/com/juick/json/Messages.java | 27 +++++++++++++++++++++++++++ src/com/juick/json/User.java | 6 ++++++ src/com/juick/json/Users.java | 2 +- 4 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 src/com/juick/json/Messages.java (limited to 'src/com/juick') diff --git a/src/com/juick/json/Message.java b/src/com/juick/json/Message.java index c1beebc4..18cc375e 100644 --- a/src/com/juick/json/Message.java +++ b/src/com/juick/json/Message.java @@ -83,6 +83,8 @@ public class Message { } if (msg.Timestamp != null) { json.put("timestamp", msg.Timestamp); + } else if (msg.TimestampString != null) { + json.put("timestamp", msg.TimestampString); } if (msg.User != null) { json.put("user", com.juick.json.User.toJSON(msg.User)); @@ -98,16 +100,16 @@ public class Message { } if (msg.AttachmentType != null) { String fname = msg.MID + (msg.RID > 0 ? "-" + msg.RID : "") + "." + msg.AttachmentType; - if (msg.AttachmentType.equals("jpg")) { + if (msg.AttachmentType.equals("mp4")) { + JSONObject video = new JSONObject(); + video.put("mp4", "http://i.juick.com/video/" + fname); + json.put("video", video); + } else { JSONObject photo = new JSONObject(); photo.put("thumbnail", "http://i.juick.com/ps/" + fname); photo.put("small", "http://i.juick.com/photo-512/" + fname); photo.put("medium", "http://i.juick.com/photo-1024/" + fname); json.put("photo", photo); - } else { - JSONObject video = new JSONObject(); - video.put("mp4", "http://i.juick.com/video/" + fname); - json.put("video", video); } } } catch (JSONException e) { diff --git a/src/com/juick/json/Messages.java b/src/com/juick/json/Messages.java new file mode 100644 index 00000000..a1879b09 --- /dev/null +++ b/src/com/juick/json/Messages.java @@ -0,0 +1,27 @@ +package com.juick.json; + +import java.util.ArrayList; +import java.util.Iterator; + +/** + * + * @author ugnich + */ +public class Messages { + + public static String arrayToString(ArrayList messages) { + String json = "["; + + Iterator i = messages.iterator(); + while (i.hasNext()) { + com.juick.Message m = i.next(); + if (json.length() > 1) { + json += ","; + } + json += Message.toJSON(m).toString(); + } + + json += "]"; + return json; + } +} diff --git a/src/com/juick/json/User.java b/src/com/juick/json/User.java index 43ee4803..dd3143c6 100644 --- a/src/com/juick/json/User.java +++ b/src/com/juick/json/User.java @@ -49,6 +49,12 @@ public class User { if (user.FullName != null) { json.put("fullname", user.FullName); } + if (user.JID != null) { + json.put("jid", user.JID); + } + if (user.MessagesCount > 0) { + json.put("MessagesCount", user.MessagesCount); + } } catch (JSONException e) { } diff --git a/src/com/juick/json/Users.java b/src/com/juick/json/Users.java index eda89ccb..0e486f74 100644 --- a/src/com/juick/json/Users.java +++ b/src/com/juick/json/Users.java @@ -22,7 +22,7 @@ public class Users { if (json.length() > 1) { json += ","; } - json += "{\"uid\":" + u.UID + ",\"uname\":\"" + u.UName + "\"}"; + json += User.toJSON(u).toString(); } json += "]"; -- cgit v1.2.3