comment #411 - Prepare endpoints + entities
This commit is contained in:
parent
cbd74ffc8d
commit
8aab488a94
|
@ -62,6 +62,7 @@ import app.fedilab.android.client.Entities.Account;
|
|||
import app.fedilab.android.client.Entities.AccountAdmin;
|
||||
import app.fedilab.android.client.Entities.AccountCreation;
|
||||
import app.fedilab.android.client.Entities.AdminAction;
|
||||
import app.fedilab.android.client.Entities.Announcement;
|
||||
import app.fedilab.android.client.Entities.Application;
|
||||
import app.fedilab.android.client.Entities.Attachment;
|
||||
import app.fedilab.android.client.Entities.Card;
|
||||
|
@ -81,6 +82,7 @@ import app.fedilab.android.client.Entities.Notification;
|
|||
import app.fedilab.android.client.Entities.Peertube;
|
||||
import app.fedilab.android.client.Entities.Poll;
|
||||
import app.fedilab.android.client.Entities.PollOptions;
|
||||
import app.fedilab.android.client.Entities.Reaction;
|
||||
import app.fedilab.android.client.Entities.Relationship;
|
||||
import app.fedilab.android.client.Entities.Report;
|
||||
import app.fedilab.android.client.Entities.Results;
|
||||
|
@ -520,6 +522,132 @@ public class API {
|
|||
return statuses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse json response for several reactions
|
||||
*
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Reaction>
|
||||
*/
|
||||
private static List<Reaction> parseReaction(JSONArray jsonArray) {
|
||||
List<Reaction> reactions = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length()) {
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Reaction reaction = parseReaction(resobj);
|
||||
i++;
|
||||
reactions.add(reaction);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return reactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a reaction
|
||||
* @param resobj JSONObject
|
||||
* @return Reaction
|
||||
*/
|
||||
private static Reaction parseReaction(JSONObject resobj) {
|
||||
Reaction reaction = new Reaction();
|
||||
try {
|
||||
reaction.setName(resobj.getString("name"));
|
||||
reaction.setCount(resobj.getInt("count"));
|
||||
reaction.setMe(resobj.getBoolean("me"));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return reaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse json response for several announcements
|
||||
*
|
||||
* @param jsonArray JSONArray
|
||||
* @return List<Announcement>
|
||||
*/
|
||||
private static List<Announcement> parseAnnouncement(Context context, JSONArray jsonArray) {
|
||||
|
||||
List<Announcement> announcements = new ArrayList<>();
|
||||
try {
|
||||
int i = 0;
|
||||
while (i < jsonArray.length()) {
|
||||
|
||||
JSONObject resobj = jsonArray.getJSONObject(i);
|
||||
Announcement announcement = parseAnnouncement(context, resobj);
|
||||
i++;
|
||||
announcements.add(announcement);
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return announcements;
|
||||
}
|
||||
/**
|
||||
* Parse an annoucement
|
||||
* @param context Context
|
||||
* @param resobj JSONObject
|
||||
* @return Announcement
|
||||
*/
|
||||
private static Announcement parseAnnouncement(Context context, JSONObject resobj) {
|
||||
Announcement announcement = new Announcement();
|
||||
try {
|
||||
announcement.setId(resobj.getString("id"));
|
||||
announcement.setContent(resobj.getString("content"));
|
||||
announcement.setPublishedAt(Helper.mstStringToDate(context, resobj.getString("published_at")));
|
||||
announcement.setUpdatedAt(Helper.mstStringToDate(context, resobj.getString("updated_at")));
|
||||
announcement.setStartAt(Helper.mstStringToDate(context, resobj.getString("starts_at")));
|
||||
announcement.setEndAt(Helper.mstStringToDate(context, resobj.getString("ends_at")));
|
||||
announcement.setRead(resobj.getBoolean("read"));
|
||||
|
||||
announcement.setReactions(parseReaction(resobj.getJSONArray("reactions")));
|
||||
|
||||
List<Mention> mentions = new ArrayList<>();
|
||||
JSONArray arrayMention = resobj.getJSONArray("mentions");
|
||||
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);
|
||||
}
|
||||
announcement.setMentions(mentions);
|
||||
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
JSONArray arrayTag = resobj.getJSONArray("tags");
|
||||
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);
|
||||
}
|
||||
announcement.setTags(tags);
|
||||
|
||||
List<Emojis> emojiList = new ArrayList<>();
|
||||
try {
|
||||
JSONArray emojisTag = resobj.getJSONArray("emojis");
|
||||
for (int j = 0; j < emojisTag.length(); j++) {
|
||||
JSONObject emojisObj = emojisTag.getJSONObject(j);
|
||||
Emojis emojis = parseEmojis(emojisObj);
|
||||
emojiList.add(emojis);
|
||||
}
|
||||
announcement.setEmojis(emojiList);
|
||||
} catch (Exception e) {
|
||||
announcement.setEmojis(new ArrayList<>());
|
||||
}
|
||||
|
||||
} catch (JSONException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return announcement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a poll
|
||||
* @param context Context
|
||||
|
@ -3889,6 +4017,27 @@ public class API {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves announcements for the authenticated account *synchronously*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getAnnouncements() {
|
||||
|
||||
List<Announcement> announcements = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.get(getAbsoluteUrl("/announcements"), 10, null, null);
|
||||
announcements = parseAnnouncement(context, new JSONArray(response));
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setAnnouncements(announcements);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves bookmarked status for the authenticated account *synchronously*
|
||||
*
|
||||
|
@ -3990,7 +4139,7 @@ public class API {
|
|||
* @param comment String comment for the report
|
||||
* @return in status code - Should be equal to 200 when action is done
|
||||
*/
|
||||
private int postAction(StatusAction statusAction, String targetedId, Status status, String comment) {
|
||||
private int postAction(StatusAction statusAction, String targetedId, Status status, String comment) {
|
||||
|
||||
String action;
|
||||
HashMap<String, String> params = null;
|
||||
|
@ -4078,6 +4227,10 @@ public class API {
|
|||
case UNSTATUS:
|
||||
action = String.format("/statuses/%s", targetedId);
|
||||
break;
|
||||
case REMOVE_REACTION:
|
||||
case ADD_REACTION:
|
||||
action = String.format("announcements/%s/reactions/%s", targetedId, comment);
|
||||
break;
|
||||
case AUTHORIZE:
|
||||
action = String.format("/follow_requests/%s/authorize", targetedId);
|
||||
break;
|
||||
|
@ -4128,7 +4281,7 @@ public class API {
|
|||
default:
|
||||
return -1;
|
||||
}
|
||||
if (statusAction != StatusAction.UNSTATUS) {
|
||||
if (statusAction != StatusAction.UNSTATUS && statusAction != StatusAction.ADD_REACTION && statusAction != StatusAction.REMOVE_REACTION) {
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String resp = httpsConnection.post(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT);
|
||||
|
@ -4157,13 +4310,25 @@ public class API {
|
|||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if(statusAction == StatusAction.ADD_REACTION){
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
httpsConnection.put(getAbsoluteUrl(action), 10, null, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
httpsConnection.delete(getAbsoluteUrl(action), 10, null, prefKeyOauthTokenT);
|
||||
actionCode = httpsConnection.getActionCode();
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new TimelineCacheDAO(context, db).remove(targetedId);
|
||||
if( statusAction != StatusAction.REMOVE_REACTION) {
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new TimelineCacheDAO(context, db).remove(targetedId);
|
||||
}
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException | IOException | KeyManagementException e) {
|
||||
|
@ -6000,7 +6165,9 @@ public class API {
|
|||
PEERTUBEDELETEVIDEO,
|
||||
UPDATESERVERSCHEDULE,
|
||||
DELETESCHEDULED,
|
||||
REFRESHPOLL
|
||||
REFRESHPOLL,
|
||||
ADD_REACTION,
|
||||
REMOVE_REACTION
|
||||
}
|
||||
|
||||
public enum accountPrivacy {
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
|||
|
||||
import app.fedilab.android.client.Entities.Account;
|
||||
import app.fedilab.android.client.Entities.AccountAdmin;
|
||||
import app.fedilab.android.client.Entities.Announcement;
|
||||
import app.fedilab.android.client.Entities.Context;
|
||||
import app.fedilab.android.client.Entities.Conversation;
|
||||
import app.fedilab.android.client.Entities.Emojis;
|
||||
|
@ -54,6 +55,7 @@ public class APIResponse {
|
|||
private List<Conversation> conversations = null;
|
||||
private List<Notification> notifications = null;
|
||||
private List<Relationship> relationships = null;
|
||||
private List<Announcement> announcements = null;
|
||||
private String targetedId = null;
|
||||
private Results results = null;
|
||||
private List<HowToVideo> howToVideos = null;
|
||||
|
@ -320,4 +322,12 @@ public class APIResponse {
|
|||
public void setIdentityProofs(List<IdentityProof> identityProofs) {
|
||||
this.identityProofs = identityProofs;
|
||||
}
|
||||
|
||||
public List<Announcement> getAnnouncements() {
|
||||
return announcements;
|
||||
}
|
||||
|
||||
public void setAnnouncements(List<Announcement> announcements) {
|
||||
this.announcements = announcements;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,130 @@
|
|||
package app.fedilab.android.client.Entities;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Announcement {
|
||||
private String id;
|
||||
private String content;
|
||||
private Date startAt;
|
||||
private Date endAt;
|
||||
private boolean all_day;
|
||||
private Date publishedAt;
|
||||
private Date updatedAt;
|
||||
private boolean read;
|
||||
private java.util.List<Mention> mentions;
|
||||
private java.util.List<Tag> tags;
|
||||
private java.util.List<Emojis> emojis;
|
||||
private java.util.List<Reaction> reactions;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Date getStartAt() {
|
||||
return startAt;
|
||||
}
|
||||
|
||||
public void setStartAt(Date startAt) {
|
||||
this.startAt = startAt;
|
||||
}
|
||||
|
||||
public Date getEndAt() {
|
||||
return endAt;
|
||||
}
|
||||
|
||||
public void setEndAt(Date endAt) {
|
||||
this.endAt = endAt;
|
||||
}
|
||||
|
||||
public boolean isAll_day() {
|
||||
return all_day;
|
||||
}
|
||||
|
||||
public void setAll_day(boolean all_day) {
|
||||
this.all_day = all_day;
|
||||
}
|
||||
|
||||
public Date getPublishedAt() {
|
||||
return publishedAt;
|
||||
}
|
||||
|
||||
public void setPublishedAt(Date publishedAt) {
|
||||
this.publishedAt = publishedAt;
|
||||
}
|
||||
|
||||
public Date getUpdatedAt() {
|
||||
return updatedAt;
|
||||
}
|
||||
|
||||
public void setUpdatedAt(Date updatedAt) {
|
||||
this.updatedAt = updatedAt;
|
||||
}
|
||||
|
||||
public boolean isRead() {
|
||||
return read;
|
||||
}
|
||||
|
||||
public void setRead(boolean read) {
|
||||
this.read = read;
|
||||
}
|
||||
|
||||
public List<Mention> getMentions() {
|
||||
return mentions;
|
||||
}
|
||||
|
||||
public void setMentions(List<Mention> mentions) {
|
||||
this.mentions = mentions;
|
||||
}
|
||||
|
||||
public List<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public List<Emojis> getEmojis() {
|
||||
return emojis;
|
||||
}
|
||||
|
||||
public void setEmojis(List<Emojis> emojis) {
|
||||
this.emojis = emojis;
|
||||
}
|
||||
|
||||
public List<Reaction> getReactions() {
|
||||
return reactions;
|
||||
}
|
||||
|
||||
public void setReactions(List<Reaction> reactions) {
|
||||
this.reactions = reactions;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package app.fedilab.android.client.Entities;
|
||||
/* Copyright 2020 Thomas Schneider
|
||||
*
|
||||
* This file is a part of Fedilab
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||
* see <http://www.gnu.org/licenses>. */
|
||||
public class Reaction {
|
||||
private String name;
|
||||
private int count;
|
||||
private boolean me;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public boolean isMe() {
|
||||
return me;
|
||||
}
|
||||
|
||||
public void setMe(boolean me) {
|
||||
this.me = me;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue