Some fixes in API

This commit is contained in:
stom79 2019-02-03 15:16:48 +01:00
parent 0f821c8f78
commit 7ddf7f7e1e
1 changed files with 29 additions and 15 deletions

View File

@ -1785,7 +1785,9 @@ public class GNUAPI {
status.setSpoiler_text(null); status.setSpoiler_text(null);
status.setVisibility("public"); status.setVisibility("public");
status.setLanguage(resobj.isNull("geo")?null:resobj.getString("geo")); status.setLanguage(resobj.isNull("geo")?null:resobj.getString("geo"));
status.setUrl(resobj.get("external_url").toString()); if( resobj.has("external_url"))
status.setUrl(resobj.get("external_url").toString());
//Retrieves attachments //Retrieves attachments
try { try {
@ -1798,19 +1800,23 @@ public class GNUAPI {
//Retrieves mentions //Retrieves mentions
List<Mention> mentions = new ArrayList<>(); List<Mention> mentions = new ArrayList<>();
JSONArray arrayMention = resobj.getJSONArray("attentions"); if( resobj.has("attentions")) {
if( arrayMention != null){ JSONArray arrayMention = resobj.getJSONArray("attentions");
for(int j = 0 ; j < arrayMention.length() ; j++){ if (arrayMention != null) {
JSONObject menObj = arrayMention.getJSONObject(j); for (int j = 0; j < arrayMention.length(); j++) {
Mention mention = new Mention(); JSONObject menObj = arrayMention.getJSONObject(j);
mention.setId(menObj.get("id").toString()); Mention mention = new Mention();
mention.setUrl(menObj.get("profileurl").toString()); mention.setId(menObj.get("id").toString());
mention.setAcct(menObj.get("screen_name").toString()); mention.setUrl(menObj.get("profileurl").toString());
mention.setUsername(menObj.get("fullname").toString()); mention.setAcct(menObj.get("screen_name").toString());
mentions.add(mention); mention.setUsername(menObj.get("fullname").toString());
mentions.add(mention);
}
} }
status.setMentions(mentions);
}else{
status.setMentions(new ArrayList<>());
} }
status.setMentions(mentions);
//Retrieves tags //Retrieves tags
status.setTags(null); status.setTags(null);
//Retrieves emjis //Retrieves emjis
@ -1825,11 +1831,18 @@ public class GNUAPI {
}catch (Exception e){ }catch (Exception e){
application = new Application(); application = new Application();
} }
Log.v(Helper.TAG,resobj.toString());
status.setApplication(application); status.setApplication(application);
status.setAccount(parseAccountResponse(context, resobj.getJSONObject("user"))); status.setAccount(parseAccountResponse(context, resobj.getJSONObject("user")));
status.setContent(resobj.get("statusnet_html").toString()); status.setContent(resobj.get("statusnet_html").toString());
status.setFavourites_count(Integer.valueOf(resobj.get("fave_num").toString())); if(resobj.has("fave_num"))
status.setReblogs_count(Integer.valueOf(resobj.get("repeat_num").toString())); status.setFavourites_count(Integer.valueOf(resobj.get("fave_num").toString()));
else
status.setFavourites_count(0);
if(resobj.has("repeat_num"))
status.setReblogs_count(Integer.valueOf(resobj.get("repeat_num").toString()));
else
status.setReblogs_count(0);
status.setReplies_count(0); status.setReplies_count(0);
try { try {
status.setReblogged(Boolean.valueOf(resobj.get("repeated").toString())); status.setReblogged(Boolean.valueOf(resobj.get("repeated").toString()));
@ -2042,7 +2055,8 @@ public class GNUAPI {
Attachment attachment = new Attachment(); Attachment attachment = new Attachment();
try { try {
attachment.setId(resobj.get("id").toString()); if(resobj.has("id") )
attachment.setId(resobj.get("id").toString());
attachment.setType(resobj.get("mimetype").toString()); attachment.setType(resobj.get("mimetype").toString());
attachment.setUrl(resobj.get("url").toString()); attachment.setUrl(resobj.get("url").toString());
try { try {