public void parsePointAPIMessagePost(PointMessage msg, JSONObject p)
     throws JSONException, ParseException {
   PointUser pu = new PointUser();
   msg.User = pu;
   JSONObject author = p.getJSONObject("author");
   pu.UName = author.getString("login");
   pu.FullName = author.getString("name");
   pu.UID = author.getInt("id");
   if (author.has("avatar") && author.get("avatar") != JSONObject.NULL)
     pu.avatarUrl = author.getString("avatar");
   msg.Text = p.getString("text");
   String createdStr = p.getString("created");
   msg.Timestamp = parsePointAPIDate(createdStr);
   msg.tags = new Vector<String>();
   if (p.has("tags")) {
     JSONArray tagso = p.getJSONArray("tags");
     for (int i = 0; i < tagso.length(); i++) {
       msg.tags.add(tagso.getString(i));
     }
   }
   if (p.has("files")) {
     JSONArray fileso = p.getJSONArray("files");
     for (int i = 0; i < fileso.length(); i++) {
       msg.Text += "\n@\n" + fileso.getString(i);
     }
   }
   msg.setMID(new PointMessageID(pu.UName, p.getString("id"), 0));
   msg.replies = p.getInt("comments_count");
   msg.microBlogCode = PointMessageID.CODE;
 }
 public ArrayList<JuickMessage> parseAPIPostAndReplies(String jsonStr) {
   ArrayList<JuickMessage> retval = new ArrayList<JuickMessage>();
   try {
     JSONObject jo = new JSONObject(new JSONTokener(new FastStringReader(jsonStr)));
     JSONObject post = jo.getJSONObject("post");
     PointMessage msg = new PointMessage();
     parsePointAPIMessagePost(msg, post);
     retval.add(msg);
     JSONArray comments = jo.getJSONArray("comments");
     for (int i = 0; i < comments.length(); i++) {
       JSONObject comment = comments.getJSONObject(i);
       PointMessage comm = new PointMessage();
       try {
         parsePointAPIComment(comment, comm, msg);
         retval.add(comm);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   } catch (JSONException e) {
     e.printStackTrace();
   } catch (ParseException e) {
     e.printStackTrace();
   }
   return retval;
 }
 private void parsePointAPIMessage(JSONObject post, PointMessage msg)
     throws JSONException, ParseException {
   JSONObject p = post.getJSONObject("post");
   parsePointAPIMessagePost(msg, p);
   PointMessageID mid = (PointMessageID) msg.getMID();
   mid.uid = post.getInt("uid");
   msg.source = post.toString();
   msg.subscribed = post.getBoolean("subscribed");
 }
 @Override
 public void getChildren(
     MessageID mid,
     Utils.Notification notification,
     Utils.Function<Void, ArrayList<JuickMessage>> cont) {
   String midString = ((BnwMessageID) mid).getId();
   final String jsonStr =
       httpClientService
           .getJSON(
               "http://ipv4.bnw.im/api/show?message=" + midString + "&replies=1", notification)
           .getResult();
   if (jsonStr != null) {
     try {
       JSONObject fullThread = new JSONObject(jsonStr);
       JSONObject root = fullThread.getJSONObject("message");
       ArrayList<BNWMessage> msgs = new ArrayList<BNWMessage>();
       msgs.add(initFromJSON(root));
       JSONArray replies = fullThread.getJSONArray("replies");
       HashMap<String, Integer> numbersRemap = new HashMap<String, Integer>();
       int replyNo = 1;
       for (int i = 0; i < replies.length(); i++) {
         BNWMessage reply = initFromJSON(replies.getJSONObject(i));
         msgs.add(reply);
         reply.setRID(replyNo);
         numbersRemap.put(reply.getRIDString(), replyNo);
         replyNo++;
       }
       for (int i = 1; i < msgs.size(); i++) {
         BNWMessage msg = msgs.get(i);
         String replyToString = msg.getReplyToString();
         if (replyToString == null) {
           msg.setReplyTo(0);
         } else {
           Integer prevComment = numbersRemap.get(replyToString);
           if (prevComment == null) prevComment = 0;
           msg.setReplyTo(prevComment);
         }
       }
       cont.apply(new ArrayList<JuickMessage>(msgs));
     } catch (JSONException e) {
       cont.apply(new ArrayList<JuickMessage>());
     }
   } else {
     cont.apply(new ArrayList<JuickMessage>());
   }
 }
 private void parsePointAPIComment(JSONObject comm, PointMessage msg, PointMessage parent)
     throws JSONException, ParseException {
   PointUser pu = new PointUser();
   msg.User = pu;
   JSONObject author = comm.getJSONObject("author");
   pu.UName = author.getString("login");
   pu.FullName = author.getString("name");
   pu.UID = author.getInt("id");
   if (author.has("avatar") && author.get("avatar") != JSONObject.NULL) {
     pu.avatarUrl = author.getString("avatar");
   }
   msg.Text = comm.getString("text");
   msg.is_rec = comm.getBoolean("is_rec");
   msg.Timestamp = parsePointAPIDate(comm.getString("created"));
   msg.setMID(parent.getMID());
   msg.setRID(comm.getInt("id"));
   Object toCommentId = comm.get("to_comment_id");
   if (toCommentId != JSONObject.NULL) {
     msg.setReplyTo(comm.getInt("to_comment_id"));
   }
   msg.microBlogCode = PointMessageID.CODE;
 }