aboutsummaryrefslogtreecommitdiff
path: root/src/com/juick/json/Message.java
diff options
context:
space:
mode:
authorGravatar Ugnich Anton2012-01-22 23:01:24 +0700
committerGravatar Ugnich Anton2012-01-22 23:01:24 +0700
commitcbcc5a5e4c1edd4689c756a2548a5087201ee74e (patch)
treea6b0d603af873ba3de7830121c3aedaa99f3f6c1 /src/com/juick/json/Message.java
parentbd7cfe95f4d15719f31e17d9aee6830066644948 (diff)
toJSON()
Diffstat (limited to 'src/com/juick/json/Message.java')
-rw-r--r--src/com/juick/json/Message.java54
1 files changed, 51 insertions, 3 deletions
diff --git a/src/com/juick/json/Message.java b/src/com/juick/json/Message.java
index 83a8624f..da817a01 100644
--- a/src/com/juick/json/Message.java
+++ b/src/com/juick/json/Message.java
@@ -29,10 +29,10 @@ import org.json.JSONObject;
*
* @author Ugnich Anton
*/
-public class Message extends com.juick.Message {
+public class Message {
- public static Message parseJSON(JSONObject json) throws JSONException {
- Message jmsg = new Message();
+ public static com.juick.Message parseJSON(JSONObject json) throws JSONException {
+ com.juick.Message jmsg = new com.juick.Message();
jmsg.MID = json.getInt("mid");
if (json.has("rid")) {
jmsg.RID = json.getInt("rid");
@@ -67,4 +67,52 @@ public class Message extends com.juick.Message {
return jmsg;
}
+
+ public static JSONObject toJSON(com.juick.Message msg) {
+ JSONObject json = new JSONObject();
+
+ try {
+ if (msg.MID > 0) {
+ json.put("mid", msg.MID);
+ }
+ if (msg.RID > 0) {
+ json.put("rid", msg.RID);
+ }
+ if (msg.Text != null) {
+ json.put("body", msg.Text);
+ }
+ if (msg.Timestamp != null) {
+ json.put("timestamp", msg.Timestamp);
+ }
+ if (msg.User != null) {
+ json.put("user", com.juick.json.User.toJSON(msg.User));
+ }
+ if (msg.tags != null && msg.tags.size() > 0) {
+ json.put("tags", new JSONArray(msg.tags));
+ }
+ if (msg.replies > 0) {
+ json.put("replies", msg.replies);
+ }
+ if (msg.place != null) {
+ json.put("place", com.juick.json.Place.toJSON(msg.place));
+ }
+ if (msg.AttachmentType != null) {
+ String fname = msg.MID + (msg.RID > 0 ? "-" + msg.RID : "") + "." + msg.AttachmentType;
+ if (msg.AttachmentType.equals("jpg")) {
+ 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) {
+ }
+
+ return json;
+ }
}