From d3bb1ad93f3f1626fbd490c5e244e32832646926 Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 8 Mar 2020 11:19:23 +0100 Subject: [PATCH] Cleanup API Class --- .../java/app/fedilab/android/client/API.java | 1064 ++++------------- 1 file changed, 231 insertions(+), 833 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/API.java b/app/src/main/java/app/fedilab/android/client/API.java index e3d7367fd..4af1e9b8c 100644 --- a/app/src/main/java/app/fedilab/android/client/API.java +++ b/app/src/main/java/app/fedilab/android/client/API.java @@ -57,7 +57,6 @@ import java.util.regex.Pattern; import app.fedilab.android.R; import app.fedilab.android.activities.MainActivity; -import app.fedilab.android.asynctasks.RetrieveOpenCollectiveAsyncTask; import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask; import app.fedilab.android.client.Entities.Account; import app.fedilab.android.client.Entities.AccountAdmin; @@ -113,7 +112,6 @@ public class API { private Attachment attachment; private List accounts; private List statuses; - private List conversations; private int tootPerPage, accountPerPage, notificationPerPage; private int actionCode; private String instance; @@ -415,9 +413,7 @@ public class API { i++; statuses.add(status); } - } catch (JSONException e) { - e.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } return statuses; @@ -429,7 +425,7 @@ public class API { * @param resobj JSONObject * @return HowToVideo */ - private static HowToVideo parseHowTo(Context context, JSONObject resobj) { + private static HowToVideo parseHowTo(JSONObject resobj) { HowToVideo howToVideo = new HowToVideo(); try { howToVideo.setId(resobj.get("id").toString()); @@ -463,9 +459,7 @@ public class API { schedule.setAttachmentList(attachements); schedule.setId(jsonObject.get("id").toString()); schedule.setScheduled_at(Helper.mstStringToDate(context, jsonObject.get("scheduled_at").toString())); - } catch (JSONException e) { - e.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } return schedule; @@ -495,9 +489,7 @@ public class API { schedule.setScheduled_at(Helper.mstStringToDate(context, jsonArray.getJSONObject(i).get("scheduled_at").toString())); i++; } - } catch (JSONException e) { - e.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } return schedules; @@ -519,9 +511,7 @@ public class API { JSONObject resobj = jsonArray.getJSONObject(i); Status status = parseStatuses(context, resobj); i++; - if (status != null) { - statuses.add(status); - } + statuses.add(status); } } catch (JSONException e) { @@ -532,10 +522,9 @@ public class API { /** * Parse a poll - * - * @param context - * @param resobj - * @return + * @param context Context + * @param resobj JSONObject + * @return Poll */ private static Poll parsePoll(Context context, JSONObject resobj) { Poll poll = new Poll(); @@ -608,22 +597,20 @@ public class API { if (resobj.has("media_attachments")) { JSONArray arrayAttachement = resobj.getJSONArray("media_attachments"); - if (arrayAttachement != null) { - for (int j = 0; j < arrayAttachement.length(); j++) { - JSONObject attObj = arrayAttachement.getJSONObject(j); - Attachment attachment = new Attachment(); - attachment.setId(attObj.get("id").toString()); - attachment.setPreview_url(attObj.get("preview_url").toString()); - attachment.setRemote_url(attObj.get("remote_url").toString()); - attachment.setType(attObj.get("type").toString()); - attachment.setText_url(attObj.get("text_url").toString()); - attachment.setUrl(attObj.get("url").toString()); - try { - attachment.setDescription(attObj.get("description").toString()); - } catch (JSONException ignore) { - } - attachments.add(attachment); + for (int j = 0; j < arrayAttachement.length(); j++) { + JSONObject attObj = arrayAttachement.getJSONObject(j); + Attachment attachment = new Attachment(); + attachment.setId(attObj.get("id").toString()); + attachment.setPreview_url(attObj.get("preview_url").toString()); + attachment.setRemote_url(attObj.get("remote_url").toString()); + attachment.setType(attObj.get("type").toString()); + attachment.setText_url(attObj.get("text_url").toString()); + attachment.setUrl(attObj.get("url").toString()); + try { + attachment.setDescription(attObj.get("description").toString()); + } catch (JSONException ignore) { } + attachments.add(attachment); } } try { @@ -636,41 +623,35 @@ public class API { //Retrieves mentions List mentions = new ArrayList<>(); JSONArray arrayMention = resobj.getJSONArray("mentions"); - if (arrayMention != null) { - for (int j = 0; j < arrayMention.length(); j++) { - JSONObject menObj = arrayMention.getJSONObject(j); - Mention mention = new Mention(); - mention.setId(menObj.get("id").toString()); - mention.setUrl(menObj.get("url").toString()); - mention.setAcct(menObj.get("acct").toString()); - mention.setUsername(menObj.get("username").toString()); - mentions.add(mention); - } + for (int j = 0; j < arrayMention.length(); j++) { + JSONObject menObj = arrayMention.getJSONObject(j); + Mention mention = new Mention(); + mention.setId(menObj.get("id").toString()); + mention.setUrl(menObj.get("url").toString()); + mention.setAcct(menObj.get("acct").toString()); + mention.setUsername(menObj.get("username").toString()); + mentions.add(mention); } status.setMentions(mentions); //Retrieves tags List tags = new ArrayList<>(); JSONArray arrayTag = resobj.getJSONArray("tags"); - if (arrayTag != null) { - for (int j = 0; j < arrayTag.length(); j++) { - JSONObject tagObj = arrayTag.getJSONObject(j); - Tag tag = new Tag(); - tag.setName(tagObj.get("name").toString()); - tag.setUrl(tagObj.get("url").toString()); - tags.add(tag); - } + for (int j = 0; j < arrayTag.length(); j++) { + JSONObject tagObj = arrayTag.getJSONObject(j); + Tag tag = new Tag(); + tag.setName(tagObj.get("name").toString()); + tag.setUrl(tagObj.get("url").toString()); + tags.add(tag); } status.setTags(tags); //Retrieves emjis List emojiList = new ArrayList<>(); try { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseEmojis(emojisObj); + emojiList.add(emojis); } status.setEmojis(emojiList); } catch (Exception e) { @@ -679,10 +660,9 @@ public class API { //Retrieve Application Application application = new Application(); try { - if (resobj.getJSONObject("application") != null) { - application.setName(resobj.getJSONObject("application").getString("name")); - application.setWebsite(resobj.getJSONObject("application").getString("website")); - } + resobj.getJSONObject("application"); + application.setName(resobj.getJSONObject("application").getString("name")); + application.setWebsite(resobj.getJSONObject("application").getString("website")); } catch (Exception e) { application = new Application(); } @@ -691,38 +671,38 @@ public class API { status.setAccount(parseAccountResponse(context, resobj.getJSONObject("account"))); status.setContent(context, resobj.get("content").toString()); if (!resobj.isNull("favourites_count")) { - status.setFavourites_count(Integer.valueOf(resobj.get("favourites_count").toString())); + status.setFavourites_count(resobj.getInt("favourites_count")); } else { status.setFavourites_count(0); } if (!resobj.isNull("reblogs_count")) { - status.setReblogs_count(Integer.valueOf(resobj.get("reblogs_count").toString())); + status.setReblogs_count(resobj.getInt("reblogs_count")); } else { status.setReblogs_count(0); } try { - status.setReplies_count(Integer.valueOf(resobj.get("replies_count").toString())); + status.setReplies_count(resobj.getInt("replies_count")); } catch (Exception e) { status.setReplies_count(-1); } try { - status.setReblogged(Boolean.valueOf(resobj.get("reblogged").toString())); + status.setReblogged(resobj.getBoolean("reblogged")); } catch (Exception e) { status.setReblogged(false); } try { - status.setFavourited(Boolean.valueOf(resobj.get("favourited").toString())); + status.setFavourited(resobj.getBoolean("favourited")); } catch (Exception e) { status.setFavourited(false); } try { - status.setMuted(Boolean.valueOf(resobj.get("muted").toString())); + status.setMuted(resobj.getBoolean("muted")); } catch (Exception e) { status.setMuted(false); } try { - status.setPinned(Boolean.valueOf(resobj.get("pinned").toString())); + status.setPinned(resobj.getBoolean("pinned")); } catch (JSONException e) { status.setPinned(false); } @@ -761,9 +741,7 @@ public class API { status.setPoll(poll); } - } catch (JSONException ignored) { - ignored.printStackTrace(); - } catch (ParseException e) { + } catch (JSONException | ParseException e) { e.printStackTrace(); } status.setViewType(context); @@ -776,7 +754,6 @@ public class API { * @param resobj JSONObject * @return Status */ - @SuppressWarnings("InfiniteRecursion") private static Status parseSchedule(Context context, JSONObject resobj) { Status status = new Status(); try { @@ -800,7 +777,7 @@ public class API { * @param jsonArray JSONArray * @return List */ - public static List parseNotes(Context context, String instance, JSONArray jsonArray) { + private static List parseNotes(Context context, String instance, JSONArray jsonArray) { List statuses = new ArrayList<>(); try { @@ -825,8 +802,7 @@ public class API { * @param resobj JSONObject * @return Status */ - @SuppressWarnings("InfiniteRecursion") - public static Status parseNotes(Context context, String instance, JSONObject resobj) { + private static Status parseNotes(Context context, String instance, JSONObject resobj) { Status status = new Status(); try { @@ -835,7 +811,8 @@ public class API { status.setCreated_at(Helper.mstStringToDate(context, resobj.get("createdAt").toString())); status.setIn_reply_to_id(resobj.get("replyId").toString()); status.setSensitive(false); - if (resobj.get("cw") != null && !resobj.get("cw").toString().equals("null")) + resobj.get("cw"); + if (!resobj.get("cw").toString().equals("null")) status.setSpoiler_text(resobj.get("cw").toString()); try { status.setVisibility(resobj.get("visibility").toString()); @@ -848,29 +825,27 @@ public class API { if (resobj.has("media")) { JSONArray arrayAttachement = resobj.getJSONArray("media"); ArrayList attachments = new ArrayList<>(); - if (arrayAttachement != null) { - for (int j = 0; j < arrayAttachement.length(); j++) { - JSONObject attObj = arrayAttachement.getJSONObject(j); - Attachment attachment = new Attachment(); - attachment.setId(attObj.get("id").toString()); - attachment.setPreview_url(attObj.get("thumbnailUrl").toString()); - attachment.setRemote_url(attObj.get("url").toString()); - if (attObj.get("type").toString().contains("/")) { - attachment.setType(attObj.get("type").toString().split("/")[0]); - } else - attachment.setType(attObj.get("type").toString()); - attachment.setText_url(attObj.get("url").toString()); - attachment.setUrl(attObj.get("url").toString()); - if (attObj.get("isSensitive").toString().equals("true")) { - status.setSensitive(true); - } - try { - attachment.setDescription(attObj.get("comment").toString()); - } catch (JSONException ignore) { - ignore.printStackTrace(); - } - attachments.add(attachment); + for (int j = 0; j < arrayAttachement.length(); j++) { + JSONObject attObj = arrayAttachement.getJSONObject(j); + Attachment attachment = new Attachment(); + attachment.setId(attObj.get("id").toString()); + attachment.setPreview_url(attObj.get("thumbnailUrl").toString()); + attachment.setRemote_url(attObj.get("url").toString()); + if (attObj.get("type").toString().contains("/")) { + attachment.setType(attObj.get("type").toString().split("/")[0]); + } else + attachment.setType(attObj.get("type").toString()); + attachment.setText_url(attObj.get("url").toString()); + attachment.setUrl(attObj.get("url").toString()); + if (attObj.get("isSensitive").toString().equals("true")) { + status.setSensitive(true); } + try { + attachment.setDescription(attObj.get("comment").toString()); + } catch (JSONException e) { + e.printStackTrace(); + } + attachments.add(attachment); } status.setMedia_attachments(attachments); } else { @@ -886,16 +861,16 @@ public class API { //Retrieves mentions List mentions = new ArrayList<>(); - status.setAccount(parseMisskeyAccountResponse(context, instance, resobj.getJSONObject("user"))); + status.setAccount(parseMisskeyAccountResponse(instance, resobj.getJSONObject("user"))); status.setContent(context, resobj.get("text").toString()); try { - status.setReplies_count(Integer.valueOf(resobj.get("repliesCount").toString())); + status.setReplies_count(resobj.getInt("repliesCount")); } catch (Exception e) { status.setReplies_count(-1); } try { - status.setFavourited(Boolean.valueOf(resobj.get("isFavorited").toString())); + status.setFavourited(resobj.getBoolean("isFavorited")); } catch (Exception e) { status.setFavourited(false); } @@ -905,7 +880,8 @@ public class API { status.setBookmarked(false); } try { - if (resobj.getJSONObject("renoteId") != null && !resobj.getJSONObject("renoteId").toString().equals("null")) + resobj.getJSONObject("renoteId"); + if (!resobj.getJSONObject("renoteId").toString().equals("null")) status.setReblog(parseStatuses(context, resobj.getJSONObject("renote"))); } catch (Exception ignored) { } @@ -915,14 +891,12 @@ public class API { List tags = new ArrayList<>(); if (resobj.has("tags")) { JSONArray arrayTag = resobj.getJSONArray("tags"); - if (arrayTag != null) { - for (int j = 0; j < arrayTag.length(); j++) { - JSONObject tagObj = arrayTag.getJSONObject(j); - Tag tag = new Tag(); - tag.setName(tagObj.get("name").toString()); - tag.setUrl(tagObj.get("url").toString()); - tags.add(tag); - } + for (int j = 0; j < arrayTag.length(); j++) { + JSONObject tagObj = arrayTag.getJSONObject(j); + Tag tag = new Tag(); + tag.setName(tagObj.get("name").toString()); + tag.setUrl(tagObj.get("url").toString()); + tags.add(tag); } } status.setTags(tags); @@ -931,12 +905,10 @@ public class API { List emojiList = new ArrayList<>(); if (resobj.has("emojis")) { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseMisskeyEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseMisskeyEmojis(emojisObj); + emojiList.add(emojis); } status.setEmojis(emojiList); } @@ -944,10 +916,9 @@ public class API { //Retrieve Application Application application = new Application(); try { - if (resobj.getJSONObject("application") != null) { - application.setName(resobj.getJSONObject("application").getString("name")); - application.setWebsite(resobj.getJSONObject("application").getString("website")); - } + resobj.getJSONObject("application"); + application.setName(resobj.getJSONObject("application").getString("name")); + application.setWebsite(resobj.getJSONObject("application").getString("website")); } catch (Exception e) { application = new Application(); } @@ -1036,11 +1007,11 @@ public class API { account.setCreated_at(new Date()); if (resobj.has("followersCount")) - account.setFollowers_count(Integer.valueOf(resobj.get("followersCount").toString())); + account.setFollowers_count(resobj.getInt("followersCount")); else account.setFollowers_count(0); if (resobj.has("followingCount")) - account.setFollowing_count(Integer.valueOf(resobj.get("followingCount").toString())); + account.setFollowing_count(resobj.getInt("followingCount")); else account.setFollowing_count(0); account.setStatuses_count(0); @@ -1125,8 +1096,8 @@ public class API { report.setAction_taken_by_account(parseAccountAdminResponse(context, resobj.getJSONObject("action_taken_by_account"))); } report.setStatuses(parseStatuses(context, resobj.getJSONArray("statuses"))); - } catch (Exception ignored) { - ignored.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } return report; } @@ -1212,8 +1183,8 @@ public class API { } else { accountAdmin.setApproved(true); } - } catch (Exception ignored) { - ignored.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } return accountAdmin; } @@ -1241,17 +1212,17 @@ public class API { account.setCreated_at(new Date()); } if (!resobj.isNull("followers_count")) { - account.setFollowers_count(Integer.valueOf(resobj.get("followers_count").toString())); + account.setFollowers_count(resobj.getInt("followers_count")); } else { account.setFollowers_count(0); } if (!resobj.isNull("following_count")) { - account.setFollowing_count(Integer.valueOf(resobj.get("following_count").toString())); + account.setFollowing_count(resobj.getInt("following_count")); } else { account.setFollowing_count(0); } if (!resobj.isNull("statuses_count")) { - account.setStatuses_count(Integer.valueOf(resobj.get("statuses_count").toString())); + account.setStatuses_count(resobj.getInt("statuses_count")); } else { account.setStatuses_count(0); } @@ -1289,16 +1260,15 @@ public class API { JSONArray fields = resobj.getJSONArray("fields"); LinkedHashMap fieldsMap = new LinkedHashMap<>(); LinkedHashMap fieldsMapVerified = new LinkedHashMap<>(); - if (fields != null) { - for (int j = 0; j < fields.length(); j++) { - fieldsMap.put(fields.getJSONObject(j).getString("name"), fields.getJSONObject(j).getString("value")); - try { - fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), (fields.getJSONObject(j).getString("verified_at") != null && !fields.getJSONObject(j).getString("verified_at").equals("null"))); - } catch (Exception e) { - fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), false); - } - + for (int j = 0; j < fields.length(); j++) { + fieldsMap.put(fields.getJSONObject(j).getString("name"), fields.getJSONObject(j).getString("value")); + try { + fields.getJSONObject(j).getString("verified_at"); + fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), !fields.getJSONObject(j).getString("verified_at").equals("null")); + } catch (Exception e) { + fieldsMapVerified.put(fields.getJSONObject(j).getString("name"), false); } + } account.setFields(fieldsMap); account.setFieldsVerified(fieldsMapVerified); @@ -1310,12 +1280,10 @@ public class API { List emojiList = new ArrayList<>(); try { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseEmojis(emojisObj); + emojiList.add(emojis); } account.setEmojis(emojiList); } catch (Exception e) { @@ -1347,48 +1315,6 @@ public class API { return account; } - /** - * Parse json response an unique account - * - * @param resobj JSONObject - * @return Account - */ - @SuppressWarnings("InfiniteRecursion") - private static Account parseOpencollectiveAccountResponse(Context context, RetrieveOpenCollectiveAsyncTask.Type type, JSONObject resobj) { - - Account account = new Account(); - try { - account.setId(resobj.get("MemberId").toString()); - account.setUuid(resobj.get("MemberId").toString()); - account.setUsername(resobj.get("name").toString()); - account.setAcct(resobj.get("tier").toString()); - account.setDisplay_name(resobj.get("name").toString()); - account.setLocked(false); - account.setCreated_at(Helper.opencollectivetStringToDate(context, resobj.get("createdAt").toString())); - account.setFollowers_count(0); - account.setFollowing_count(0); - account.setStatuses_count(0); - account.setNote(resobj.get("description").toString()); - account.setBot(false); - account.setMoved_to_account(null); - account.setUrl(resobj.get("profile").toString()); - account.setAvatar(resobj.get("image").toString()); - account.setAvatar_static(resobj.get("image").toString()); - account.setHeader(null); - account.setHeader_static(null); - if (resobj.get("role").toString().equals("BACKER")) - account.setSocial("OPENCOLLECTIVE_BACKER"); - else if (resobj.get("role").toString().equals("SPONSOR")) - account.setSocial("OPENCOLLECTIVE_SPONSOR"); - else - account.setSocial("OPENCOLLECTIVE"); - - } catch (JSONException ignored) { - } catch (ParseException e) { - e.printStackTrace(); - } - return account; - } /** * Parse json response an unique account @@ -1396,14 +1322,13 @@ public class API { * @param resobj JSONObject * @return Account */ - @SuppressWarnings("InfiniteRecursion") - private static Account parseMisskeyAccountResponse(Context context, String instance, JSONObject resobj) { + private static Account parseMisskeyAccountResponse(String instance, JSONObject resobj) { Account account = new Account(); try { account.setId(resobj.get("id").toString()); account.setUsername(resobj.get("username").toString()); - String host = null; + String host; String acct; if (resobj.isNull("host")) { acct = resobj.get("username").toString(); @@ -1427,17 +1352,15 @@ public class API { List emojiList = new ArrayList<>(); if (resobj.has("emojis")) { JSONArray emojisTag = resobj.getJSONArray("emojis"); - if (emojisTag != null) { - for (int j = 0; j < emojisTag.length(); j++) { - JSONObject emojisObj = emojisTag.getJSONObject(j); - Emojis emojis = parseEmojis(emojisObj); - emojiList.add(emojis); - } + for (int j = 0; j < emojisTag.length(); j++) { + JSONObject emojisObj = emojisTag.getJSONObject(j); + Emojis emojis = parseEmojis(emojisObj); + emojiList.add(emojis); } } account.setEmojis(emojiList); - } catch (JSONException ignored) { - ignored.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); } return account; } @@ -1611,7 +1534,7 @@ public class API { if (eventType == XmlPullParser.TEXT && status != null) { if (xpp.getText() != null) { try { - DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz"); + DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); Date date = formatter.parse(xpp.getText()); status.setCreated_at(date); } catch (ParseException e) { @@ -1626,12 +1549,9 @@ public class API { String description = xpp.getText(); Pattern imgPattern = Pattern.compile("]*src=\"([^\"]+)\"[^>]*>"); Matcher matcher = imgPattern.matcher(description); - List imgs = new ArrayList<>(); - int i = 1; ArrayList attachments = new ArrayList<>(); while (matcher.find()) { description = description.replaceAll(Pattern.quote(matcher.group()), ""); - imgs.add("[media_" + i + "]|" + matcher.group(1)); Attachment attachment = new Attachment(); attachment.setType("image"); attachment.setDescription(""); @@ -1691,9 +1611,7 @@ public class API { JSONObject resobj = jsonArray.getJSONObject(i); IdentityProof identityProof = parseIdentityProof(context, resobj); i++; - if (identityProof != null) { - identityProofs.add(identityProof); - } + identityProofs.add(identityProof); } } catch (JSONException e) { @@ -1766,8 +1684,7 @@ public class API { } else { try { id = URLEncoder.encode(id, "UTF-8"); - } catch (UnsupportedEncodingException e) { - } + } catch (UnsupportedEncodingException ignored) {} params = new HashMap<>(); params.put("query", id); endpoint = "/admin/users"; @@ -1826,7 +1743,7 @@ public class API { if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { accountAdmins = parseAccountAdminResponse(new JSONArray(response)); - if (accountAdmins != null && accountAdmins.size() > 0) { + if (accountAdmins.size() > 0) { Account accountpleroma = getAccount(accountAdmins.get(0).getId()); if (accountpleroma != null) { accountAdmins.get(0).setAccount(accountpleroma); @@ -1850,17 +1767,11 @@ public class API { apiResponse.setReports(reports); break; } - } catch (IOException e) { - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (IOException | NoSuchAlgorithmException | KeyManagementException | JSONException e) { e.printStackTrace(); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); } return apiResponse; } @@ -1987,15 +1898,19 @@ public class API { String response = null; switch (http_action) { case "POST": + assert url_action != null; response = new HttpsConnection(context, this.instance).post(url_action, 10, params, prefKeyOauthTokenT); break; case "PATCH": - response = new HttpsConnection(context, this.instance).patch(url_action, 10, params, null, null, null, null, prefKeyOauthTokenT); + assert url_action != null; + response = new HttpsConnection(context, this.instance).patch(url_action, 10, null, null, null, null, null, prefKeyOauthTokenT); break; case "PUT": + assert url_action != null; response = new HttpsConnection(context, this.instance).put(url_action, 10, params, prefKeyOauthTokenT); break; case "DELETE": + assert url_action != null; new HttpsConnection(context, this.instance).delete(url_action, 10, params, prefKeyOauthTokenT); break; } @@ -2104,14 +2019,13 @@ public class API { response = new HttpsConnection(context, this.instance).get(nodeInfo.getHref(), 30, null, null); JSONObject resobj = new JSONObject(response); JSONObject jsonObject = resobj.getJSONObject("software"); - String name = null; - name = jsonObject.getString("name").toUpperCase(); + String name = jsonObject.getString("name").toUpperCase(); instanceNodeInfo.setName(name); instanceNodeInfo.setVersion(jsonObject.getString("version")); instanceNodeInfo.setOpenRegistrations(resobj.getBoolean("openRegistrations")); } } catch (JSONException e) { - + e.printStackTrace(); } } catch (IOException | JSONException | NoSuchAlgorithmException | KeyManagementException e) { e.printStackTrace(); @@ -2347,11 +2261,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { e.printStackTrace(); setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return apiResponse; @@ -2447,15 +2357,7 @@ public class API { newValues.put("access_token", token); newValues.put("refresh_token", refresh_token); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } catch (HttpsConnection.HttpsConnectionException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) { e.printStackTrace(); } return newValues; @@ -2489,48 +2391,12 @@ public class API { params.put("password", accountCreation.getPassword()); params.put("agreement", "true"); params.put("locale", Locale.getDefault().getLanguage()); - response = new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/accounts"), 30, params, app_token); - - /*res = new JSONObject(response); - String access_token = res.getString("access_token"); - prefKeyOauthTokenT = access_token; - - response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/verify_credentials"), 10, null, prefKeyOauthTokenT); - account = parseAccountResponse(context, new JSONObject(response)); - if( account.getSocial().equals("PLEROMA")){ - isPleromaAdmin(account.getAcct()); - } - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - account.setToken(access_token); - account.setClient_id(client_id); - account.setClient_secret(client_secret); - account.setRefresh_token(null); - account.setInstance(instance); - SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); - boolean userExists = new AccountDAO(context, db).userExist(account); - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putString(Helper.PREF_KEY_ID, account.getId()); - editor.putBoolean(Helper.PREF_IS_MODERATOR, account.isModerator()); - editor.putBoolean(Helper.PREF_IS_ADMINISTRATOR, account.isAdmin()); - editor.putString(Helper.PREF_INSTANCE, instance); - editor.apply(); - if( userExists) - new AccountDAO(context, db).updateAccountCredential(account); - else { - if( account.getUsername() != null && account.getCreated_at() != null) - new AccountDAO(context, db).insertAccount(account); - }*/ - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + new HttpsConnection(context, this.instance).post(getAbsoluteUrl("/accounts"), 30, params, app_token); + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); } return apiResponse; } @@ -2550,13 +2416,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } return account; @@ -2580,17 +2440,11 @@ public class API { try { String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/accounts/relationships"), 10, params, prefKeyOauthTokenT); relationships = parseRelationshipResponse(new JSONArray(response)); - if (relationships != null && relationships.size() > 0) + if (relationships.size() > 0) relationship = relationships.get(0); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } return relationship; @@ -2619,13 +2473,7 @@ public class API { apiResponse.setMax_id(httpsConnection.getMax_id()); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setRelationships(relationships); @@ -2708,6 +2556,7 @@ public class API { params.put("max_id", max_id); if (since_id != null) params.put("since_id", since_id); + //noinspection ConstantConditions if (0 < limit || limit > 40) limit = 40; if (onlyMedia) @@ -2763,13 +2612,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setAccounts(accounts); @@ -2800,13 +2643,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setAccounts(accounts); @@ -2829,13 +2666,7 @@ public class API { statuses.add(status); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -2860,13 +2691,7 @@ public class API { statuses.add(status); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -2887,13 +2712,7 @@ public class API { statusContext = parseContext(new JSONObject(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } return statusContext; @@ -2913,13 +2732,7 @@ public class API { statuses = parseStatuses(context, new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -2973,7 +2786,7 @@ public class API { if (0 > limit || limit > 80) limit = 80; params.put("limit", String.valueOf(limit)); - conversations = new ArrayList<>(); + List conversations = new ArrayList<>(); try { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); String response = httpsConnection.get(getAbsoluteUrl("/conversations"), 10, params, prefKeyOauthTokenT); @@ -2982,13 +2795,7 @@ public class API { conversations = parseConversations(new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setConversations(conversations); @@ -3031,13 +2838,7 @@ public class API { statuses = parseStatuses(context, new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -3063,14 +2864,6 @@ public class API { return getHomeTimeline(null, since_id, null, tootPerPage); } - /** - * Retrieves home timeline for the account from a min Id value *synchronously* - * - * @return APIResponse - */ - public APIResponse getHomeTimelineMinId(String min_id) { - return getHomeTimeline(null, null, min_id, tootPerPage); - } /** * Retrieves home timeline from cache the account *synchronously* @@ -3126,6 +2919,7 @@ public class API { * @param limit int limit - max value 40 * @return APIResponse */ + @SuppressWarnings("SameParameterValue") private APIResponse getHomeTimeline(String max_id, String since_id, String min_id, int limit) { HashMap params = new HashMap<>(); @@ -3177,11 +2971,10 @@ public class API { String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/identity_proofs", userId)), 10, null, prefKeyOauthTokenT); identityProofs = parseIdentityProof(context, new JSONArray(response)); - } catch (UnknownHostException e) { - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); + } catch (HttpsConnection.HttpsConnectionException e) { + setError(e.getStatusCode(), e); } if (apiResponse == null) apiResponse = new APIResponse(); @@ -3215,15 +3008,7 @@ public class API { apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId()); } } - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } catch (HttpsConnection.HttpsConnectionException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -3248,15 +3033,7 @@ public class API { apiResponse.setSince_id(httpsConnection.getSince_id()); apiResponse.setMax_id(httpsConnection.getMax_id()); statuses = parseStatuses(context, new JSONArray(response)); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } catch (HttpsConnection.HttpsConnectionException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -3279,13 +3056,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setAccounts(accounts); @@ -3307,13 +3078,7 @@ public class API { peertubes = parsePeertube(instance, jsonArray); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setPeertubes(peertubes); @@ -3410,13 +3175,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setPeertubes(peertubes); @@ -3437,13 +3196,7 @@ public class API { statuses = parseSinglePeertubeComments(context, instance, jsonObject); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -3465,13 +3218,7 @@ public class API { howToVideos = parseHowTos(jsonArray); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setHowToVideos(howToVideos); @@ -3547,19 +3294,13 @@ public class API { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); String response = httpsConnection.postMisskey("https://" + instance + "/api/notes", 10, params, null); statuses = parseNotes(context, instance, new JSONArray(response)); - if (statuses != null && statuses.size() > 0) { + if (statuses.size() > 0) { apiResponse.setSince_id(statuses.get(0).getId()); apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId()); } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -3675,22 +3416,14 @@ public class API { apiResponse.setSince_id(httpsConnection.getSince_id()); apiResponse.setMax_id(httpsConnection.getMax_id()); List tmp_status = parseStatuses(context, new JSONArray(response)); - if (tmp_status != null && tmp_status.size() > 0) { + if (tmp_status.size() > 0) { for (Status status : tmp_status) { if (status.getAccount().getAcct().equals("fedilab")) { statuses.add(status); } } } - } catch (IOException e) { - e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (HttpsConnection.HttpsConnectionException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (IOException | NoSuchAlgorithmException | KeyManagementException | HttpsConnection.HttpsConnectionException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -3717,6 +3450,7 @@ public class API { * @param limit int limit - max value 40 * @return APIResponse */ + @SuppressWarnings("SameParameterValue") private APIResponse getDiscoverTimeline(boolean local, String max_id, String since_id, int limit) { HashMap params = new HashMap<>(); @@ -3740,13 +3474,7 @@ public class API { statuses = parseStatuses(context, new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -3927,13 +3655,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -4008,7 +3730,7 @@ public class API { apiResponse.setSince_id(httpsConnection.getSince_id()); apiResponse.setMax_id(httpsConnection.getMax_id()); accounts = parseAccountResponse(new JSONArray(response)); - if (accounts != null && accounts.size() == 1) { + if (accounts.size() == 1) { if (accounts.get(0).getAcct() == null) { Throwable error = new Throwable(context.getString(R.string.toast_error)); setError(500, error); @@ -4016,46 +3738,13 @@ public class API { } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setAccounts(accounts); return apiResponse; } - /** - * Retrieves opencollective accounts *synchronously* - * - * @return APIResponse - */ - public Results getOpencollectiveAccounts(RetrieveOpenCollectiveAsyncTask.Type type) { - - results = new Results(); - accounts = new ArrayList<>(); - try { - HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); - String response = httpsConnection.get("https://opencollective.com/mastalab/members/all.json", 10, null, prefKeyOauthTokenT); - accounts = parseOpencollectiveAccountResponse(context, type, new JSONArray(response)); - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } - results.setAccounts(accounts); - return results; - } /** * Retrieves blocked domains for the authenticated account *synchronously* @@ -4079,13 +3768,7 @@ public class API { domains = parseDomains(new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setDomains(domains); @@ -4110,11 +3793,7 @@ public class API { actionCode = httpsConnection.getActionCode(); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return actionCode; @@ -4158,13 +3837,7 @@ public class API { accounts = parseAccountResponse(new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setAccounts(accounts); @@ -4209,13 +3882,7 @@ public class API { statuses = parseStatuses(context, new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -4282,11 +3949,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return actionCode; @@ -4503,20 +4166,17 @@ public class API { new TimelineCacheDAO(context, db).remove(targetedId); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } } return actionCode; } + @SuppressWarnings("unused") public int reportStatus(List statuses, String comment, boolean forward) { String action; - HashMap params = null; + HashMap params; action = "/reports"; params = new HashMap<>(); params.put("account_id", statuses.get(0).getAccount().getId()); @@ -4535,11 +4195,7 @@ public class API { actionCode = httpsConnection.getActionCode(); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return actionCode; @@ -4565,13 +4221,18 @@ public class API { try { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); String response = null; - int responseCode = -1; - if (call.equals("GET")) - response = httpsConnection.get(getAbsoluteUrl("/scheduled_statuses/"), 10, null, prefKeyOauthTokenT); - else if (call.equals("PUT")) - response = httpsConnection.put(getAbsoluteUrl(String.format("/scheduled_statuses/%s", targetedId)), 10, params, prefKeyOauthTokenT); - else if (call.equals("DELETE")) - responseCode = httpsConnection.delete(getAbsoluteUrl(String.format("/scheduled_statuses/%s", targetedId)), 10, null, prefKeyOauthTokenT); + + switch (call) { + case "GET": + response = httpsConnection.get(getAbsoluteUrl("/scheduled_statuses/"), 10, null, prefKeyOauthTokenT); + break; + case "PUT": + response = httpsConnection.put(getAbsoluteUrl(String.format("/scheduled_statuses/%s", targetedId)), 10, params, prefKeyOauthTokenT); + break; + case "DELETE": + httpsConnection.delete(getAbsoluteUrl(String.format("/scheduled_statuses/%s", targetedId)), 10, null, prefKeyOauthTokenT); + break; + } if (call.equals("GET")) { apiResponse.setSince_id(httpsConnection.getSince_id()); apiResponse.setMax_id(httpsConnection.getMax_id()); @@ -4590,7 +4251,7 @@ public class API { st.setUserId(userId); st.setStatus(schedule.getStatus()); storedStatus.add(st); - } else if (response != null && call.equals("GET")) { + } else if (response != null) { List scheduleList = parseSchedule(context, new JSONArray(response)); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); @@ -4611,13 +4272,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStoredStatuses(storedStatus); @@ -4627,9 +4282,9 @@ public class API { /** * Public api call to submit a vote * - * @param pollId - * @param choices - * @return + * @param pollId String + * @param choices int[] + * @return Poll */ public Poll submiteVote(String pollId, int[] choices) { JsonObject jsonObject = new JsonObject(); @@ -4762,11 +4417,7 @@ public class API { new HttpsConnection(context, this.instance).post(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return apiResponse; @@ -4831,13 +4482,7 @@ public class API { notifications = parseNotificationResponse(new JSONArray(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setNotifications(notifications); @@ -4986,13 +4631,7 @@ public class API { attachment = parseAttachmentResponse(new JSONObject(response)); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } return attachment; @@ -5099,13 +4738,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } return apiResponse; @@ -5152,13 +4785,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setAccounts(accounts); @@ -5200,7 +4827,7 @@ public class API { boolean isAdmin; try { HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); - String response = httpsConnection.get(String.format(Helper.getLiveInstanceWithProtocol(context) + "/api/pleroma/admin/permission_group/%s/admin", nickname), 10, null, prefKeyOauthTokenT); + httpsConnection.get(String.format(Helper.getLiveInstanceWithProtocol(context) + "/api/pleroma/admin/permission_group/%s/admin", nickname), 10, null, prefKeyOauthTokenT); //Call didn't return a 404, so the account is admin isAdmin = true; } catch (Exception e) { @@ -5211,27 +4838,6 @@ public class API { editor.apply(); } - /** - * Retrieves Pleroma emoji *synchronously* - * - * @return APIResponse - */ - private APIResponse getCustomPleromaEmoji() { - List emojis = new ArrayList<>(); - try { - HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); - String response = httpsConnection.get(Helper.getLiveInstanceWithProtocol(context) + "/api/pleroma/emoji", 10, null, prefKeyOauthTokenT); - emojis = parsePleromaEmojis(new JSONObject(response)); - - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { - e.printStackTrace(); - } - apiResponse.setEmojis(emojis); - return apiResponse; - } - /** * Get filters for the user * @@ -5261,7 +4867,6 @@ public class API { * * @return APIResponse */ - @SuppressWarnings("unused") public APIResponse getFilters(String filterId) { List filters = new ArrayList<>(); @@ -5305,13 +4910,7 @@ public class API { filters.add(resfilter); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setFilters(filters); @@ -5332,11 +4931,7 @@ public class API { actionCode = httpsConnection.getActionCode(); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return actionCode; @@ -5368,13 +4963,7 @@ public class API { filters.add(resfilter); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setFilters(filters); @@ -5401,54 +4990,7 @@ public class API { return apiResponse; } - /** - * Get lists for the user - * - * @return APIResponse - */ - public APIResponse getListsRemote(String prefKeyOauthTokenT) { - apiResponse = new APIResponse(); - List lists = new ArrayList<>(); - try { - String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl("/lists"), 5, null, prefKeyOauthTokenT); - lists = parseLists(new JSONArray(response)); - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { - e.printStackTrace(); - } - apiResponse.setLists(lists); - return apiResponse; - } - /** - * Get lists for a user by its id - * - * @return APIResponse - */ - @SuppressWarnings("unused") - public APIResponse getLists(String userId) { - - List lists = new ArrayList<>(); - app.fedilab.android.client.Entities.List list; - try { - String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl(String.format("/accounts/%s/lists", userId)), 10, null, prefKeyOauthTokenT); - list = parseList(new JSONObject(response)); - lists.add(list); - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } - apiResponse.setLists(lists); - return apiResponse; - } /** * Retrieves list timeline *synchronously* @@ -5479,13 +5021,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -5516,49 +5052,13 @@ public class API { apiResponse.setMax_id(httpsConnection.getMax_id()); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setAccounts(accounts); return apiResponse; } - /** - * Get a list - * - * @param id String, id of the list - * @return APIResponse - */ - @SuppressWarnings("unused") - public APIResponse getList(String id) { - - List lists = new ArrayList<>(); - app.fedilab.android.client.Entities.List list; - try { - String response = new HttpsConnection(context, this.instance).get(getAbsoluteUrl(String.format("/lists/%s", id)), 10, null, prefKeyOauthTokenT); - list = parseList(new JSONObject(response)); - lists.add(list); - } catch (HttpsConnection.HttpsConnectionException e) { - setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { - e.printStackTrace(); - } - apiResponse.setLists(lists); - return apiResponse; - } - /** * Add an account in a list * @@ -5566,8 +5066,6 @@ public class API { * @param account_ids String, account to add * @return APIResponse */ - //TODO: it is unclear what is returned here - //TODO: improves doc https://github.com/tootsuite/documentation/blob/4bb149c73f40fa58fd7265a336703dd2d83efb1c/Using-the-API/API.md#addingremoving-accounts-tofrom-a-list public APIResponse addAccountToList(String id, String[] account_ids) { HashMap params = new HashMap<>(); @@ -5582,11 +5080,7 @@ public class API { new HttpsConnection(context, this.instance).post(getAbsoluteUrl(String.format("/lists/%s/accounts", id)), 10, params, prefKeyOauthTokenT); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException e) { e.printStackTrace(); } return apiResponse; @@ -5614,11 +5108,7 @@ public class API { } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); e.printStackTrace(); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { + } catch (NoSuchAlgorithmException | KeyManagementException | IOException e) { e.printStackTrace(); } return actionCode; @@ -5642,13 +5132,7 @@ public class API { lists.add(list); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setLists(lists); @@ -5674,13 +5158,7 @@ public class API { lists.add(list); } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setLists(lists); @@ -5724,13 +5202,7 @@ public class API { } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -5757,13 +5229,7 @@ public class API { } } catch (HttpsConnection.HttpsConnectionException e) { setError(e.getStatusCode(), e); - } catch (NoSuchAlgorithmException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } catch (KeyManagementException e) { - e.printStackTrace(); - } catch (JSONException e) { + } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { e.printStackTrace(); } apiResponse.setStatuses(statuses); @@ -5843,7 +5309,7 @@ public class API { while (i < jsonArray.length()) { JSONObject resobj = jsonArray.getJSONObject(i); - HowToVideo howToVideo = parseHowTo(context, resobj); + HowToVideo howToVideo = parseHowTo(resobj); i++; howToVideos.add(howToVideo); } @@ -5965,7 +5431,6 @@ public class API { * @param resobj JSONObject * @return Conversation */ - @SuppressWarnings("InfiniteRecursion") private Conversation parseConversation(Context context, JSONObject resobj) { Conversation conversation = new Conversation(); try { @@ -6072,7 +5537,7 @@ public class API { * @param jsonArray JSONArray * @return List */ - public List parseInstanceReg(JSONArray jsonArray) { + private List parseInstanceReg(JSONArray jsonArray) { List instanceRegs = new ArrayList<>(); try { @@ -6112,31 +5577,6 @@ public class API { return instanceReg; } - /** - * Parse Pleroma emojis - * - * @param jsonObject JSONObject - * @return List of emojis - */ - private List parsePleromaEmojis(JSONObject jsonObject) { - List emojis = new ArrayList<>(); - Iterator iter = jsonObject.keys(); - while (iter.hasNext()) { - String shortcode = iter.next(); - try { - String url = (String) jsonObject.get(shortcode); - Emojis emojisObj = new Emojis(); - emojisObj.setVisible_in_picker(true); - emojisObj.setShortcode(shortcode); - emojisObj.setStatic_url(Helper.getLiveInstanceWithProtocol(context) + url); - emojisObj.setUrl(Helper.getLiveInstanceWithProtocol(context) + url); - emojis.add(emojisObj); - } catch (JSONException ignored) { - } - } - return emojis; - } - /** * Parse emojis * @@ -6160,27 +5600,6 @@ public class API { return emojis; } - /** - * Parse emojis - * - * @param jsonArray JSONArray - * @return List of emojis - */ - private List parseMisskeyEmojis(JSONArray jsonArray) { - List emojis = new ArrayList<>(); - try { - int i = 0; - while (i < jsonArray.length()) { - JSONObject resobj = jsonArray.getJSONObject(i); - Emojis emojis1 = parseMisskeyEmojis(resobj); - emojis.add(emojis1); - i++; - } - } catch (JSONException e) { - setDefaultError(e); - } - return emojis; - } /** * Parse Filters @@ -6216,10 +5635,9 @@ public class API { try { filter.setId(resobj.get("id").toString()); - if (resobj.get("phrase").toString() == null) - return null; filter.setPhrase(resobj.get("phrase").toString()); - if (resobj.get("expires_at") != null && !resobj.get("expires_at").toString().equals("null")) + resobj.get("expires_at"); + if (!resobj.get("expires_at").toString().equals("null")) filter.setSetExpires_at(Helper.mstStringToDate(context, resobj.get("expires_at").toString())); filter.setWhole_word(Boolean.parseBoolean(resobj.get("whole_word").toString())); filter.setIrreversible(Boolean.parseBoolean(resobj.get("irreversible").toString())); @@ -6227,14 +5645,12 @@ public class API { contextString = contextString.replaceAll("\\[", ""); contextString = contextString.replaceAll("]", ""); contextString = contextString.replaceAll("\"", ""); - if (contextString != null) { - String[] context = contextString.split(","); - if (contextString.length() > 0) { - ArrayList finalContext = new ArrayList<>(); - for (String c : context) - finalContext.add(c.trim()); - filter.setContext(finalContext); - } + String[] context = contextString.split(","); + if (contextString.length() > 0) { + ArrayList finalContext = new ArrayList<>(); + for (String c : context) + finalContext.add(c.trim()); + filter.setContext(finalContext); } return filter; } catch (Exception ignored) { @@ -6350,24 +5766,6 @@ public class API { return accounts; } - private List parseOpencollectiveAccountResponse(Context context, RetrieveOpenCollectiveAsyncTask.Type type, JSONArray jsonArray) { - List accounts = new ArrayList<>(); - try { - int i = 0; - while (i < jsonArray.length()) { - JSONObject resobj = jsonArray.getJSONObject(i); - Account account = parseOpencollectiveAccountResponse(context, type, resobj); - if (type == RetrieveOpenCollectiveAsyncTask.Type.BACKERS && account.getSocial() != null && account.getSocial().equals("OPENCOLLECTIVE_BACKER")) - accounts.add(account); - else if (type == RetrieveOpenCollectiveAsyncTask.Type.SPONSORS && account.getSocial() != null && account.getSocial().equals("OPENCOLLECTIVE_SPONSOR")) - accounts.add(account); - i++; - } - } catch (JSONException e) { - setDefaultError(e); - } - return accounts; - } /** * Parse json response an unique relationship @@ -6380,22 +5778,22 @@ public class API { Relationship relationship = new Relationship(); try { relationship.setId(resobj.get("id").toString()); - relationship.setFollowing(Boolean.valueOf(resobj.get("following").toString())); - relationship.setFollowed_by(Boolean.valueOf(resobj.get("followed_by").toString())); - relationship.setBlocking(Boolean.valueOf(resobj.get("blocking").toString())); - relationship.setMuting(Boolean.valueOf(resobj.get("muting").toString())); + relationship.setFollowing(resobj.getBoolean("following")); + relationship.setFollowed_by(resobj.getBoolean("followed_by")); + relationship.setBlocking(resobj.getBoolean("blocking")); + relationship.setMuting(resobj.getBoolean("muting")); try { - relationship.setMuting_notifications(Boolean.valueOf(resobj.get("muting_notifications").toString())); + relationship.setMuting_notifications(resobj.getBoolean("muting_notifications")); } catch (Exception ignored) { relationship.setMuting_notifications(true); } try { - relationship.setEndorsed(Boolean.valueOf(resobj.get("endorsed").toString())); + relationship.setEndorsed(resobj.getBoolean("endorsed")); } catch (Exception ignored) { relationship.setMuting_notifications(false); } try { - relationship.setShowing_reblogs(Boolean.valueOf(resobj.get("showing_reblogs").toString())); + relationship.setShowing_reblogs(resobj.getBoolean("showing_reblogs")); } catch (Exception ignored) { relationship.setMuting_notifications(false); } @@ -6404,7 +5802,7 @@ public class API { } catch (Exception ignored) { relationship.setBlocked_by(false); } - relationship.setRequested(Boolean.valueOf(resobj.get("requested").toString())); + relationship.setRequested(resobj.getBoolean("requested")); } catch (JSONException e) { setDefaultError(e); }