Upload + new api endpoints

This commit is contained in:
Thomas 2021-01-26 18:47:15 +01:00
parent 043beeecaf
commit 025f78994c
10 changed files with 476 additions and 289 deletions

View File

@ -541,9 +541,9 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
String scheme = sharedpreferences.getString(Helper.SET_ONION_SCHEME + Helper.getLiveInstance(activity), "https"); String scheme = sharedpreferences.getString(Helper.SET_ONION_SCHEME + Helper.getLiveInstance(activity), "https");
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null); String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
int maxUploadRetryTimes = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3); int maxUploadRetryTimes = sharedpreferences.getInt(Helper.MAX_UPLOAD_IMG_RETRY_TIMES, 3);
String url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/v1/media"; String url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/pixelfed/v1/media";
if (pixelfedStory) { if (pixelfedStory) {
url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/stories/v1/add"; url = scheme + "://" + Helper.getLiveInstance(activity) + "/api/pixelfed/stories/v1/add";
} }
UploadNotificationConfig uploadConfig = new UploadNotificationConfig(); UploadNotificationConfig uploadConfig = new UploadNotificationConfig();
uploadConfig uploadConfig
@ -551,7 +551,11 @@ public abstract class BasePixelfedComposeActivity extends BaseActivity implement
uploadConfig.getProgress().message = activity.getString(R.string.uploading); uploadConfig.getProgress().message = activity.getString(R.string.uploading);
uploadConfig.getCompleted().autoClear = true; uploadConfig.getCompleted().autoClear = true;
MultipartUploadRequest request = new MultipartUploadRequest(activity, uploadId, url); MultipartUploadRequest request = new MultipartUploadRequest(activity, uploadId, url);
request.addHeader("Authorization", "Bearer " + token); String cookie = token.split("\\|")[1];
request.addHeader("cookie", cookie);
String[] tokens = token.split("\\|")[0].split(";");
request.addHeader("x-xsrf-token", tokens[0].replace("X-XSRF-TOKEN= ", ""));
request.addHeader("x-csrf-token", tokens[1].replace("X-CSRF-TOKEN= ", ""));
request.setNotificationConfig(uploadConfig); request.setNotificationConfig(uploadConfig);
request.addFileToUpload(uri.toString().replace("file://", ""), "file"); request.addFileToUpload(uri.toString().replace("file://", ""), "file");
if (!pixelfedStory) { if (!pixelfedStory) {

View File

@ -81,7 +81,7 @@ public class UpdateAccountInfoByIDAsyncTask {
account.setClient_secret(accountOld.getClient_secret()); account.setClient_secret(accountOld.getClient_secret());
new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account); new AccountDAO(this.contextReference.get(), db).updateAccountCredential(account);
} }
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) { if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
new API(contextReference.get()).refreshToken(account); new API(contextReference.get()).refreshToken(account);
} }
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) { if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {

View File

@ -22,9 +22,11 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -40,6 +42,7 @@ import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.net.HttpURLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
@ -1463,6 +1466,8 @@ public class API {
account.setAvatar(resobj.getString("avatar")); account.setAvatar(resobj.getString("avatar"));
if (resobj.has("avatar_static")) if (resobj.has("avatar_static"))
account.setAvatar_static(resobj.getString("avatar_static")); account.setAvatar_static(resobj.getString("avatar_static"));
else
account.setAvatar_static(resobj.getString("avatar"));
if (resobj.has("header")) if (resobj.has("header"))
account.setHeader(resobj.getString("header")); account.setHeader(resobj.getString("header"));
if (resobj.has("header_static")) if (resobj.has("header_static"))
@ -1507,17 +1512,21 @@ public class API {
//Retrieves emjis //Retrieves emjis
List<Emojis> emojiList = new ArrayList<>(); List<Emojis> emojiList = new ArrayList<>();
try { if (resobj.has("emojis")) {
JSONArray emojisTag = resobj.getJSONArray("emojis"); try {
for (int j = 0; j < emojisTag.length(); j++) { JSONArray emojisTag = resobj.getJSONArray("emojis");
JSONObject emojisObj = emojisTag.getJSONObject(j); for (int j = 0; j < emojisTag.length(); j++) {
Emojis emojis = parseEmojis(emojisObj); JSONObject emojisObj = emojisTag.getJSONObject(j);
emojiList.add(emojis); Emojis emojis = parseEmojis(emojisObj);
emojiList.add(emojis);
}
account.setEmojis(emojiList);
} catch (Exception e) {
account.setEmojis(new ArrayList<>());
e.printStackTrace();
} }
account.setEmojis(emojiList); } else {
} catch (Exception e) {
account.setEmojis(new ArrayList<>()); account.setEmojis(new ArrayList<>());
e.printStackTrace();
} }
if (resobj.has("source")) { if (resobj.has("source")) {
JSONObject source = resobj.getJSONObject("source"); JSONObject source = resobj.getJSONObject("source");
@ -2473,7 +2482,7 @@ public class API {
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
requestParams.put("display_name", display_name); requestParams.put("display_name", display_name);
} }
if (note != null) if (note != null && MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON)
try { try {
requestParams.put("note", URLEncoder.encode(note, "UTF-8")); requestParams.put("note", URLEncoder.encode(note, "UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
@ -2780,13 +2789,20 @@ public class API {
params.put("max_id", max_id); params.put("max_id", max_id);
if (since_id != null) if (since_id != null)
params.put("since_id", since_id); params.put("since_id", since_id);
//noinspection ConstantConditions
if (0 < limit || limit > 40) if (0 < limit || limit > 40)
limit = 40; limit = 40;
if (onlyMedia)
params.put("only_media", Boolean.toString(true));
if (pinned) if (pinned)
params.put("pinned", Boolean.toString(true)); params.put("pinned", Boolean.toString(true));
if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
limit = 20;
params.put("only_media", Boolean.toString(true));
if (max_id == null) {
params.put("min_id", "1");
}
} else {
if (onlyMedia)
params.put("only_media", Boolean.toString(true));
}
params.put("exclude_replies", Boolean.toString(exclude_replies)); params.put("exclude_replies", Boolean.toString(exclude_replies));
params.put("limit", String.valueOf(limit)); params.put("limit", String.valueOf(limit));
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
@ -2795,12 +2811,12 @@ public class API {
params.put("tagged", tag.toLowerCase()); params.put("tagged", tag.toLowerCase());
} }
statuses = new ArrayList<>(); statuses = new ArrayList<>();
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/statuses", accountId)), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl(String.format("/accounts/%s/statuses", accountId)), 10, params, prefKeyOauthTokenT);
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id()); setStatusesMaxId(httpsConnection, statuses);
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -2831,8 +2847,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/reblogged_by", statusId)), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/reblogged_by", statusId)), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response)); accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id()); setAccountsMaxId(httpsConnection, accounts);
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -2862,8 +2877,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/favourited_by", statusId)), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl(String.format("/statuses/%s/favourited_by", statusId)), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response)); accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id()); setAccountsMaxId(httpsConnection, accounts);
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -2952,9 +2966,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUr2l(String.format("/status/%s/replies", statusId)), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUr2l(String.format("/status/%s/replies", statusId)), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -3058,9 +3071,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/timelines/direct"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/timelines/direct"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -3159,13 +3171,12 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/timelines/home"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/timelines/home"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
if (since_id == null) { if (since_id == null) {
statuses = parseStatusesForCache(context, new JSONArray(response)); statuses = parseStatusesForCache(context, new JSONArray(response));
} else { } else {
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
} }
setStatusesMaxId(httpsConnection, statuses);
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
if (since_id == null) { if (since_id == null) {
getHomeTimelineCache(max_id); getHomeTimelineCache(max_id);
@ -3252,9 +3263,9 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrlRemote(remoteInstance, "/timelines/public/"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrlRemote(remoteInstance, "/timelines/public/"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException | HttpsConnection.HttpsConnectionException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -3262,6 +3273,58 @@ public class API {
return apiResponse; return apiResponse;
} }
private void setStatusesMaxId(HttpsConnection httpsConnection, List<Status> statuses) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} else {
if (statuses.size() > 0) {
if (statuses.get(0).getId() != null && statuses.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
apiResponse.setSince_id(String.valueOf(statuses.get(0).getId()));
apiResponse.setMax_id(String.valueOf(statuses.get(statuses.size() - 1).getId()));
} else {
apiResponse.setSince_id(statuses.get(0).getId());
apiResponse.setMax_id(statuses.get(statuses.size() - 1).getId());
}
}
}
}
private void setNotificationsMaxId(HttpsConnection httpsConnection, List<Notification> notifications) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} else {
if (notifications.size() > 0) {
if (notifications.get(0).getId() != null && notifications.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
apiResponse.setSince_id(String.valueOf(notifications.get(0).getId()));
apiResponse.setMax_id(String.valueOf(notifications.get(notifications.size() - 1).getId()));
} else {
apiResponse.setSince_id(notifications.get(0).getId());
apiResponse.setMax_id(notifications.get(notifications.size() - 1).getId());
}
}
}
}
private void setAccountsMaxId(HttpsConnection httpsConnection, List<Account> accounts) {
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
} else {
if (accounts.size() > 0) {
if (accounts.get(0).getId() != null && accounts.get(0).getId().matches("-?\\d+(\\.\\d+)?")) {
apiResponse.setSince_id(String.valueOf(accounts.get(0).getId()));
apiResponse.setMax_id(String.valueOf(accounts.get(accounts.size() - 1).getId()));
} else {
apiResponse.setSince_id(accounts.get(0).getId());
apiResponse.setMax_id(accounts.get(accounts.size() - 1).getId());
}
}
}
}
/** /**
* Retrieves Peertube videos from an instance *synchronously* * Retrieves Peertube videos from an instance *synchronously*
* *
@ -3608,9 +3671,8 @@ public class API {
else else
url = getAbsoluteUrlRemoteInstance(instanceName); url = getAbsoluteUrlRemoteInstance(instanceName);
String response = httpsConnection.get(url, 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(url, 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -3640,9 +3702,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get("https://toot.fedilab.app/api/v1/timelines/tag/fedilab", 10, params, prefKeyOauthTokenT); String response = httpsConnection.get("https://toot.fedilab.app/api/v1/timelines/tag/fedilab", 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
List<Status> tmp_status = parseStatuses(context, new JSONArray(response)); List<Status> tmp_status = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, tmp_status);
if (tmp_status.size() > 0) { if (tmp_status.size() > 0) {
for (Status status : tmp_status) { for (Status status : tmp_status) {
if (status.getAccount().getAcct().equals("apps")) { if (status.getAccount().getAcct().equals("apps")) {
@ -3696,9 +3757,8 @@ public class API {
String url; String url;
url = getAbsoluteUr2l("/discover/posts"); url = getAbsoluteUr2l("/discover/posts");
String response = httpsConnection.get(url, 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(url, 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -3879,9 +3939,8 @@ public class API {
response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/tag/%s", query)), 10, params, prefKeyOauthTokenT); response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/tag/%s", query)), 10, params, prefKeyOauthTokenT);
else else
response = httpsConnection.get(getAbsoluteUrlRemote(instance, String.format("/timelines/tag/%s", query)), 10, params, null); response = httpsConnection.get(getAbsoluteUrlRemote(instance, String.format("/timelines/tag/%s", query)), 10, params, null);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -3957,9 +4016,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
accounts = parseAccountResponse(new JSONArray(response)); accounts = parseAccountResponse(new JSONArray(response));
setAccountsMaxId(httpsConnection, accounts);
if (accounts.size() == 1) { if (accounts.size() == 1) {
if (accounts.get(0).getAcct() == null) { if (accounts.get(0).getAcct() == null) {
Throwable error = new Throwable(context.getString(R.string.toast_error)); Throwable error = new Throwable(context.getString(R.string.toast_error));
@ -4061,9 +4119,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/follow_requests"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/follow_requests"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
accounts = parseAccountResponse(new JSONArray(response)); accounts = parseAccountResponse(new JSONArray(response));
setAccountsMaxId(httpsConnection, accounts);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4106,9 +4163,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/favourites"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/favourites"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4156,9 +4212,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/bookmarks"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/bookmarks"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4257,10 +4312,22 @@ public class API {
HashMap<String, String> params = null; HashMap<String, String> params = null;
switch (statusAction) { switch (statusAction) {
case FAVOURITE: case FAVOURITE:
action = String.format("/statuses/%s/favourite", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/favourite", targetedId);
} else {
action = "/i/like";
params = new HashMap<>();
params.put("item", targetedId);
}
break; break;
case UNFAVOURITE: case UNFAVOURITE:
action = String.format("/statuses/%s/unfavourite", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/unfavourite", targetedId);
} else {
action = "/i/like";
params = new HashMap<>();
params.put("item", targetedId);
}
break; break;
case BOOKMARK: case BOOKMARK:
action = String.format("/statuses/%s/bookmark", targetedId); action = String.format("/statuses/%s/bookmark", targetedId);
@ -4269,13 +4336,32 @@ public class API {
action = String.format("/statuses/%s/unbookmark", targetedId); action = String.format("/statuses/%s/unbookmark", targetedId);
break; break;
case REBLOG: case REBLOG:
action = String.format("/statuses/%s/reblog", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/reblog", targetedId);
} else {
action = "/i/share";
params = new HashMap<>();
params.put("item", targetedId);
}
break; break;
case UNREBLOG: case UNREBLOG:
action = String.format("/statuses/%s/unreblog", targetedId);
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s/unreblog", targetedId);
} else {
action = "/i/share";
params = new HashMap<>();
params.put("item", targetedId);
}
break; break;
case FOLLOW: case FOLLOW:
action = String.format("/accounts/%s/follow", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/follow", targetedId);
} else {
action = "/i/follow";
params = new HashMap<>();
params.put("item", targetedId);
}
break; break;
case NOTIFY_FOR_ACCOUNT: case NOTIFY_FOR_ACCOUNT:
params = new HashMap<>(); params = new HashMap<>();
@ -4293,10 +4379,22 @@ public class API {
params.put("uri", targetedId); params.put("uri", targetedId);
break; break;
case UNFOLLOW: case UNFOLLOW:
action = String.format("/accounts/%s/unfollow", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/unfollow", targetedId);
} else {
action = "/i/follow";
params = new HashMap<>();
params.put("item", targetedId);
}
break; break;
case BLOCK: case BLOCK:
action = String.format("/accounts/%s/block", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/block", targetedId);
} else {
action = "/i/block";
params = new HashMap<>();
params.put("item", targetedId);
}
break; break;
case BLOCK_DOMAIN: case BLOCK_DOMAIN:
action = "/domain_blocks"; action = "/domain_blocks";
@ -4307,10 +4405,24 @@ public class API {
action = String.format("/accounts/%s/unblock", targetedId); action = String.format("/accounts/%s/unblock", targetedId);
break; break;
case MUTE: case MUTE:
action = String.format("/accounts/%s/mute", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/mute", targetedId);
} else {
action = "/i/mute";
params = new HashMap<>();
params.put("item", targetedId);
params.put("type", "user");
}
break; break;
case UNMUTE: case UNMUTE:
action = String.format("/accounts/%s/unmute", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/accounts/%s/unmute", targetedId);
} else {
action = "/i/unmute";
params = new HashMap<>();
params.put("item", targetedId);
params.put("type", "user");
}
break; break;
case MUTE_CONVERSATION: case MUTE_CONVERSATION:
action = String.format("/statuses/%s/mute", targetedId); action = String.format("/statuses/%s/mute", targetedId);
@ -4347,7 +4459,14 @@ public class API {
action = String.format("/accounts/%s/follow", targetedId); action = String.format("/accounts/%s/follow", targetedId);
break; break;
case UNSTATUS: case UNSTATUS:
action = String.format("/statuses/%s", targetedId); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
action = String.format("/statuses/%s", targetedId);
} else {
action = "/i/delete";
params = new HashMap<>();
params.put("item", targetedId);
params.put("type", "status");
}
break; break;
case REMOVE_REACTION: case REMOVE_REACTION:
case ADD_REACTION: case ADD_REACTION:
@ -4415,7 +4534,13 @@ public class API {
&& statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) { && statusAction != StatusAction.ADD_PLEROMA_REACTION && statusAction != StatusAction.REMOVE_PLEROMA_REACTION) {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String resp = httpsConnection.post(getAbsoluteUrl(action), 10, params, prefKeyOauthTokenT); String url;
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
url = getAbsoluteUrl(action);
} else {
url = "https://" + Helper.getLiveInstance(context) + action;
}
String resp = httpsConnection.post(getAbsoluteUrl(url), 10, params, prefKeyOauthTokenT);
actionCode = httpsConnection.getActionCode(); actionCode = httpsConnection.getActionCode();
if (statusAction == StatusAction.REBLOG || statusAction == StatusAction.UNREBLOG || statusAction == StatusAction.FAVOURITE || statusAction == StatusAction.UNFAVOURITE) { if (statusAction == StatusAction.REBLOG || statusAction == StatusAction.UNREBLOG || statusAction == StatusAction.FAVOURITE || statusAction == StatusAction.UNFAVOURITE) {
Bundle b = new Bundle(); Bundle b = new Bundle();
@ -4647,45 +4772,66 @@ public class API {
public APIResponse postStatusAction(Status status) { public APIResponse postStatusAction(Status status) {
JsonObject jsonObject = new JsonObject(); JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("status", status.getContent()); String url;
if (status.getContentType() != null) url = getAbsoluteUrl("/statuses");
jsonObject.addProperty("content_type", status.getContentType());
if (status.getIn_reply_to_id() != null) if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
jsonObject.addProperty("in_reply_to_id", status.getIn_reply_to_id()); jsonObject.addProperty("status", status.getContent());
if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) { if (status.getContentType() != null)
JsonArray mediaArray = new JsonArray(); jsonObject.addProperty("content_type", status.getContentType());
for (Attachment attachment : status.getMedia_attachments()) if (status.getIn_reply_to_id() != null)
mediaArray.add(attachment.getId()); jsonObject.addProperty("in_reply_to_id", status.getIn_reply_to_id());
jsonObject.add("media_ids", mediaArray); if (status.getMedia_attachments() != null && status.getMedia_attachments().size() > 0) {
} JsonArray mediaArray = new JsonArray();
if (status.getScheduled_at() != null) for (Attachment attachment : status.getMedia_attachments())
jsonObject.addProperty("scheduled_at", status.getScheduled_at()); mediaArray.add(attachment.getId());
if (status.isSensitive()) jsonObject.add("media_ids", mediaArray);
jsonObject.addProperty("sensitive", status.isSensitive()); }
if (status.getSpoiler_text() != null) if (status.getScheduled_at() != null)
jsonObject.addProperty("spoiler_text", status.getSpoiler_text()); jsonObject.addProperty("scheduled_at", status.getScheduled_at());
if (status.isSensitive())
jsonObject.addProperty("sensitive", status.isSensitive());
if (status.getSpoiler_text() != null)
jsonObject.addProperty("spoiler_text", status.getSpoiler_text());
if (status.getPoll() != null) {
JsonObject poll = new JsonObject();
JsonArray options = new JsonArray();
for (PollOptions option : status.getPoll().getOptionsList()) {
if (!option.getTitle().isEmpty())
options.add(option.getTitle());
}
poll.add("options", options);
poll.addProperty("expires_in", status.getPoll().getExpires_in());
poll.addProperty("multiple", status.getPoll().isMultiple());
jsonObject.add("poll", poll);
}
jsonObject.addProperty("visibility", status.getVisibility());
} else {
if (status.getIn_reply_to_id() != null) {
url = "https://" + Helper.getLiveInstance(context) + "/i/comment";
jsonObject.addProperty("comment", status.getContent());
jsonObject.addProperty("item", status.getIn_reply_to_id());
jsonObject.addProperty("sensitive", status.isSensitive());
} else {
url = "https://" + Helper.getLiveInstance(context) + "/api/local/status/compose";
jsonObject.addProperty("caption", status.getContent());
jsonObject.addProperty("comments_disabled", status.getContent());
jsonObject.addProperty("cw", status.isSensitive());
jsonObject.addProperty("visibility", status.getVisibility());
String attachments = new Gson().toJson(status.getMedia_attachments());
jsonObject.addProperty("media", attachments);
if (status.getPoll() != null) {
JsonObject poll = new JsonObject();
JsonArray options = new JsonArray();
for (PollOptions option : status.getPoll().getOptionsList()) {
if (!option.getTitle().isEmpty())
options.add(option.getTitle());
} }
poll.add("options", options);
poll.addProperty("expires_in", status.getPoll().getExpires_in());
poll.addProperty("multiple", status.getPoll().isMultiple());
jsonObject.add("poll", poll);
} }
jsonObject.addProperty("visibility", status.getVisibility());
statuses = new ArrayList<>(); statuses = new ArrayList<>();
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.postJson(getAbsoluteUrl("/statuses"), 10, jsonObject, prefKeyOauthTokenT); String response = httpsConnection.postJson(url, 10, jsonObject, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
Status statusreturned = parseStatuses(context, new JSONObject(response)); Status statusreturned = parseStatuses(context, new JSONObject(response));
statuses.add(statusreturned); statuses.add(statusreturned);
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -4776,9 +4922,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/notifications"), 15, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/notifications"), 15, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
notifications = parseNotificationResponse(new JSONArray(response)); notifications = parseNotificationResponse(new JSONArray(response));
setNotificationsMaxId(httpsConnection, notifications);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -4799,13 +4944,19 @@ public class API {
private APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, String since_id, int limit, boolean display) { private APIResponse getNotifications(DisplayNotificationsFragment.Type type, String max_id, String since_id, int limit, boolean display) {
HashMap<String, String> params = new HashMap<>(); HashMap<String, String> params = new HashMap<>();
if (max_id != null)
params.put("max_id", max_id); if (MainActivity.social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
if (since_id != null) params.put("pg", "true");
params.put("since_id", since_id); params.put("page", max_id);
if (0 > limit || limit > 30) } else {
limit = 30; if (max_id != null)
params.put("limit", String.valueOf(limit)); params.put("max_id", max_id);
if (since_id != null)
params.put("since_id", since_id);
if (0 > limit || limit > 30)
limit = 30;
params.put("limit", String.valueOf(limit));
}
if (context == null) { if (context == null) {
apiResponse = new APIResponse(); apiResponse = new APIResponse();
@ -4908,13 +5059,11 @@ public class API {
} }
List<Notification> notifications = new ArrayList<>(); List<Notification> notifications = new ArrayList<>();
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/notifications"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/notifications"), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
notifications = parseNotificationResponse(new JSONArray(response)); notifications = parseNotificationResponse(new JSONArray(response));
setNotificationsMaxId(httpsConnection, notifications);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
e.printStackTrace(); e.printStackTrace();
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
@ -5096,8 +5245,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl("/accounts/search"), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl("/accounts/search"), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response)); accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id()); setAccountsMaxId(httpsConnection, accounts);
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -5329,9 +5477,8 @@ public class API {
try { try {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/list/%s", list_id)), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl(String.format("/timelines/list/%s", list_id)), 10, params, prefKeyOauthTokenT);
apiResponse.setSince_id(httpsConnection.getSince_id());
apiResponse.setMax_id(httpsConnection.getMax_id());
statuses = parseStatuses(context, new JSONArray(response)); statuses = parseStatuses(context, new JSONArray(response));
setStatusesMaxId(httpsConnection, statuses);
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
e.printStackTrace(); e.printStackTrace();
@ -5362,8 +5509,7 @@ public class API {
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance); HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
String response = httpsConnection.get(getAbsoluteUrl(String.format("/lists/%s/accounts", listId)), 10, params, prefKeyOauthTokenT); String response = httpsConnection.get(getAbsoluteUrl(String.format("/lists/%s/accounts", listId)), 10, params, prefKeyOauthTokenT);
accounts = parseAccountResponse(new JSONArray(response)); accounts = parseAccountResponse(new JSONArray(response));
apiResponse.setSince_id(httpsConnection.getSince_id()); setAccountsMaxId(httpsConnection, accounts);
apiResponse.setMax_id(httpsConnection.getMax_id());
} catch (HttpsConnection.HttpsConnectionException e) { } catch (HttpsConnection.HttpsConnectionException e) {
setError(e.getStatusCode(), e); setError(e.getStatusCode(), e);
} catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) { } catch (NoSuchAlgorithmException | IOException | KeyManagementException | JSONException e) {
@ -6117,7 +6263,9 @@ public class API {
} catch (Exception ignored) { } catch (Exception ignored) {
relationship.setDomain_blocking(false); relationship.setDomain_blocking(false);
} }
relationship.setNote(resobj.getString("note")); if (resobj.has("note")) {
relationship.setNote(resobj.getString("note"));
}
try { try {
relationship.setNotifying(resobj.getBoolean("notifying")); relationship.setNotifying(resobj.getBoolean("notifying"));
} catch (Exception ignored) { } catch (Exception ignored) {

View File

@ -22,7 +22,7 @@ import android.os.Parcelable;
* Manages Media * Manages Media
*/ */
@SuppressWarnings("unused")
public class Attachment implements Parcelable { public class Attachment implements Parcelable {
public static final Creator<Attachment> CREATOR = new Creator<Attachment>() { public static final Creator<Attachment> CREATOR = new Creator<Attachment>() {
@ -46,6 +46,7 @@ public class Attachment implements Parcelable {
private String text_url; private String text_url;
private String description; private String description;
private String local_path; private String local_path;
private boolean is_nsfw = false;
public Attachment() { public Attachment() {
@ -62,6 +63,7 @@ public class Attachment implements Parcelable {
this.text_url = in.readString(); this.text_url = in.readString();
this.description = in.readString(); this.description = in.readString();
this.local_path = in.readString(); this.local_path = in.readString();
this.is_nsfw = in.readByte() != 0;
} }
public int getViewId() { public int getViewId() {
@ -144,6 +146,14 @@ public class Attachment implements Parcelable {
this.local_path = local_path; this.local_path = local_path;
} }
public boolean isIs_nsfw() {
return is_nsfw;
}
public void setIs_nsfw(boolean is_nsfw) {
this.is_nsfw = is_nsfw;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;
@ -161,5 +171,6 @@ public class Attachment implements Parcelable {
dest.writeString(this.text_url); dest.writeString(this.text_url);
dest.writeString(this.description); dest.writeString(this.description);
dest.writeString(this.local_path); dest.writeString(this.local_path);
dest.writeByte(this.is_nsfw ? (byte) 1 : (byte) 0);
} }
} }

View File

@ -59,8 +59,10 @@ import java.util.regex.Pattern;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.activities.MainActivity;
import app.fedilab.android.activities.SlideMediaActivity; import app.fedilab.android.activities.SlideMediaActivity;
import app.fedilab.android.activities.TootActivity; import app.fedilab.android.activities.TootActivity;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.client.Entities.Error; import app.fedilab.android.client.Entities.Error;
import app.fedilab.android.helper.FileNameCleaner; import app.fedilab.android.helper.FileNameCleaner;
import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.Helper;
@ -128,6 +130,22 @@ public class HttpsConnection {
} }
private void setToken(MultipartUploadRequest multipartUploadRequest, String token) {
if (token != null) {
if (token.startsWith("Basic "))
multipartUploadRequest.addHeader("Authorization", token);
else if (token.startsWith("X-XSRF-TOKEN")) {
String cookie = token.split("\\|")[1];
multipartUploadRequest.addHeader("cookie", cookie);
String[] tokens = token.split("\\|")[0].split(";");
multipartUploadRequest.addHeader("x-xsrf-token", tokens[0].replace("X-XSRF-TOKEN= ", ""));
multipartUploadRequest.addHeader("x-csrf-token", tokens[1].replace("X-CSRF-TOKEN= ", ""));
} else
multipartUploadRequest.addHeader("Authorization", "Bearer " + token);
}
}
private void setToken(String token) { private void setToken(String token) {
if (token != null) { if (token != null) {
@ -145,16 +163,6 @@ public class HttpsConnection {
} }
} }
private String getToken(String token) {
if (token != null) {
if (token.startsWith("Basic "))
return token;
else if (token.startsWith("X-XSRF-TOKEN"))
return token;
else
return "Bearer " + token;
} else return null;
}
/** /**
* Get calls * Get calls
@ -658,9 +666,9 @@ public class HttpsConnection {
} else { } else {
m.addFileToUpload(file.getPath(), "header"); m.addFileToUpload(file.getPath(), "header");
} }
m.addParameter("name", filename) MultipartUploadRequest multipartUploadRequest = m.addParameter("name", filename);
.addHeader("Authorization", getToken(token)) setToken(multipartUploadRequest, token);
.setNotificationConfig(uploadConfig) multipartUploadRequest.setNotificationConfig(uploadConfig)
.setDelegate(new UploadStatusDelegate() { .setDelegate(new UploadStatusDelegate() {
@Override @Override
public void onProgress(Context context, UploadInfo uploadInfo) { public void onProgress(Context context, UploadInfo uploadInfo) {
@ -724,10 +732,7 @@ public class HttpsConnection {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance)); ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
} }
httpURLConnection.setRequestMethod("PATCH"); httpURLConnection.setRequestMethod("PATCH");
if (token != null && !token.startsWith("Basic ")) setToken(token);
httpURLConnection.setRequestProperty("Authorization", getToken(token));
else if (token != null && token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", token);
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
httpURLConnection.setDoOutput(true); httpURLConnection.setDoOutput(true);
@ -805,10 +810,7 @@ public class HttpsConnection {
if (httpURLConnection instanceof HttpsURLConnection) { if (httpURLConnection instanceof HttpsURLConnection) {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance)); ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
} }
if (token != null && !token.startsWith("Basic ")) setToken(token);
httpURLConnection.setRequestProperty("Authorization", getToken(token));
else if (token != null && token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", token);
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); httpURLConnection.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length));
httpURLConnection.setRequestMethod("PUT"); httpURLConnection.setRequestMethod("PUT");
@ -878,10 +880,7 @@ public class HttpsConnection {
if (httpURLConnection instanceof HttpsURLConnection) { if (httpURLConnection instanceof HttpsURLConnection) {
((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance)); ((HttpsURLConnection) httpURLConnection).setSSLSocketFactory(new TLSSocketFactory(this.instance));
} }
if (token != null && !token.startsWith("Basic ")) setToken(token);
httpURLConnection.setRequestProperty("Authorization", getToken(token));
else if (token != null && token.startsWith("Basic "))
httpURLConnection.setRequestProperty("Authorization", token);
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpURLConnection.setRequestMethod("DELETE"); httpURLConnection.setRequestMethod("DELETE");
httpURLConnection.setConnectTimeout(timeout * 1000); httpURLConnection.setConnectTimeout(timeout * 1000);
@ -932,27 +931,28 @@ public class HttpsConnection {
if (httpURLConnection == null) if (httpURLConnection == null)
return; return;
Map<String, List<String>> map = httpURLConnection.getHeaderFields(); Map<String, List<String>> map = httpURLConnection.getHeaderFields();
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
for (Map.Entry<String, List<String>> entry : map.entrySet()) { for (Map.Entry<String, List<String>> entry : map.entrySet()) {
if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) { if (entry.toString().startsWith("Link") || entry.toString().startsWith("link")) {
Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*"); Pattern patternMaxId = Pattern.compile("max_id=([0-9a-zA-Z]+).*");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString()); Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) { if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1); max_id = matcherMaxId.group(1);
}
if (entry.toString().startsWith("Link")) {
Pattern patternSinceId = Pattern.compile("since_id=([0-9a-zA-Z]+).*");
Matcher matcherSinceId = patternSinceId.matcher(entry.toString());
if (matcherSinceId.find()) {
since_id = matcherSinceId.group(1);
} }
if (entry.toString().startsWith("Link")) {
Pattern patternSinceId = Pattern.compile("since_id=([0-9a-zA-Z]+).*");
Matcher matcherSinceId = patternSinceId.matcher(entry.toString());
if (matcherSinceId.find()) {
since_id = matcherSinceId.group(1);
}
} }
} else if (entry.toString().startsWith("Min-Id") || entry.toString().startsWith("min-id")) { } else if (entry.toString().startsWith("Min-Id") || entry.toString().startsWith("min-id")) {
Pattern patternMaxId = Pattern.compile("min-id=\\[([0-9a-zA-Z]+).*]"); Pattern patternMaxId = Pattern.compile("min-id=\\[([0-9a-zA-Z]+).*]");
Matcher matcherMaxId = patternMaxId.matcher(entry.toString()); Matcher matcherMaxId = patternMaxId.matcher(entry.toString());
if (matcherMaxId.find()) { if (matcherMaxId.find()) {
max_id = matcherMaxId.group(1); max_id = matcherMaxId.group(1);
}
} }
} }
} }

View File

@ -33,6 +33,7 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -825,131 +826,130 @@ public abstract class BaseNotificationsListAdapter extends RecyclerView.Adapter<
popup.setOnMenuItemClickListener(item -> { popup.setOnMenuItemClickListener(item -> {
AlertDialog.Builder builderInner; AlertDialog.Builder builderInner;
final API.StatusAction doAction; final API.StatusAction doAction;
switch (item.getItemId()) { int itemId = item.getItemId();
case R.id.action_remove: if (itemId == R.id.action_remove) {
builderInner = new AlertDialog.Builder(context, style); builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[0]); builderInner.setTitle(stringArrayConf[0]);
doAction = API.StatusAction.UNSTATUS; doAction = API.StatusAction.UNSTATUS;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
else else
builderInner.setMessage(Html.fromHtml(status.getContent())); builderInner.setMessage(Html.fromHtml(status.getContent()));
break; } else if (itemId == R.id.action_mute) {
case R.id.action_mute: builderInner = new AlertDialog.Builder(context, style);
builderInner = new AlertDialog.Builder(context, style); builderInner.setTitle(stringArrayConf[0]);
builderInner.setTitle(stringArrayConf[0]); doAction = API.StatusAction.MUTE;
doAction = API.StatusAction.MUTE; } else if (itemId == R.id.action_mute_conversation) {
break; if (status.isMuted())
case R.id.action_mute_conversation: doAction = API.StatusAction.UNMUTE_CONVERSATION;
if (status.isMuted()) else
doAction = API.StatusAction.UNMUTE_CONVERSATION; doAction = API.StatusAction.MUTE_CONVERSATION;
else new PostActionAsyncTask(context, doAction, status.getId(), BaseNotificationsListAdapter.this);
doAction = API.StatusAction.MUTE_CONVERSATION; return true;
new PostActionAsyncTask(context, doAction, status.getId(), BaseNotificationsListAdapter.this); } else if (itemId == R.id.action_open_browser) {
return true; Helper.openBrowser(context, status.getUrl());
case R.id.action_open_browser: return true;
Helper.openBrowser(context, status.getUrl()); } else if (itemId == R.id.action_admin) {
return true; String account_id = status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId();
case R.id.action_admin: Intent intent = new Intent(context, AccountReportActivity.class);
String account_id = status.getReblog() != null ? status.getReblog().getAccount().getId() : status.getAccount().getId(); Bundle b = new Bundle();
Intent intent = new Intent(context, AccountReportActivity.class); b.putString("account_id", account_id);
Bundle b = new Bundle(); intent.putExtras(b);
b.putString("account_id", account_id); context.startActivity(intent);
intent.putExtras(b); return true;
context.startActivity(intent); } else if (itemId == R.id.action_stats) {
return true; notificationStatusChart(status);
case R.id.action_stats: return true;
notificationStatusChart(status); } else if (itemId == R.id.action_info) {
return true; Bundle b;
case R.id.action_info: Intent intent;
intent = new Intent(context, TootInfoActivity.class); intent = new Intent(context, TootInfoActivity.class);
b = new Bundle(); b = new Bundle();
if (status.getReblog() != null) { if (status.getReblog() != null) {
b.putString("toot_id", status.getReblog().getId()); b.putString("toot_id", status.getReblog().getId());
b.putInt("toot_reblogs_count", status.getReblog().getReblogs_count()); b.putInt("toot_reblogs_count", status.getReblog().getReblogs_count());
b.putInt("toot_favorites_count", status.getReblog().getFavourites_count()); b.putInt("toot_favorites_count", status.getReblog().getFavourites_count());
} else { } else {
b.putString("toot_id", status.getId()); b.putString("toot_id", status.getId());
b.putInt("toot_reblogs_count", status.getReblogs_count()); b.putInt("toot_reblogs_count", status.getReblogs_count());
b.putInt("toot_favorites_count", status.getFavourites_count()); b.putInt("toot_favorites_count", status.getFavourites_count());
} }
intent.putExtras(b); intent.putExtras(b);
context.startActivity(intent); context.startActivity(intent);
return true; return true;
case R.id.action_block_domain: } else if (itemId == R.id.action_block_domain) {
builderInner = new AlertDialog.Builder(context, style); builderInner = new AlertDialog.Builder(context, style);
builderInner.setTitle(stringArrayConf[3]); builderInner.setTitle(stringArrayConf[3]);
doAction = API.StatusAction.BLOCK_DOMAIN; doAction = API.StatusAction.BLOCK_DOMAIN;
String domain = status.getAccount().getAcct().split("@")[1]; String domain = status.getAccount().getAcct().split("@")[1];
builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain)); builderInner.setMessage(context.getString(R.string.block_domain_confirm_message, domain));
break; } else if (itemId == R.id.action_block) {
case R.id.action_block: builderInner = new AlertDialog.Builder(context, style);
builderInner = new AlertDialog.Builder(context, style); builderInner.setTitle(stringArrayConf[1]);
builderInner.setTitle(stringArrayConf[1]); doAction = API.StatusAction.BLOCK;
doAction = API.StatusAction.BLOCK; } else if (itemId == R.id.action_report) {
break; builderInner = new AlertDialog.Builder(context, style);
case R.id.action_report: builderInner.setTitle(stringArrayConf[2]);
builderInner = new AlertDialog.Builder(context, style); doAction = API.StatusAction.REPORT;
builderInner.setTitle(stringArrayConf[2]); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
doAction = API.StatusAction.REPORT; builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) else
builderInner.setMessage(Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY)); builderInner.setMessage(Html.fromHtml(status.getContent()));
else } else if (itemId == R.id.action_copy) {
builderInner.setMessage(Html.fromHtml(status.getContent())); ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
break; String content;
case R.id.action_copy: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString();
String content; else
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) content = Html.fromHtml(status.getContent()).toString();
content = Html.fromHtml(status.getContent(), Html.FROM_HTML_MODE_LEGACY).toString(); ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content);
else assert clipboard != null;
content = Html.fromHtml(status.getContent()).toString(); clipboard.setPrimaryClip(clip);
ClipData clip = ClipData.newPlainText(Helper.CLIP_BOARD, content); Toasty.info(context, context.getString(R.string.clipboard), Toast.LENGTH_LONG).show();
assert clipboard != null; return true;
} else if (itemId == R.id.action_copy_link) {
ClipData clip;
ClipboardManager clipboard;
clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl());
if (clipboard != null) {
clipboard.setPrimaryClip(clip); clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.clipboard), Toast.LENGTH_LONG).show(); Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show();
return true; }
case R.id.action_copy_link: return true;
clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); } else if (itemId == R.id.action_share) {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via));
sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl());
sendIntent.setType("text/plain");
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with)));
return true;
} else if (itemId == R.id.action_custom_sharing) {
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class);
Bundle bCustomSharing = new Bundle();
if (status.getReblog() != null) {
bCustomSharing.putParcelable("status", status.getReblog());
} else {
bCustomSharing.putParcelable("status", status);
clip = ClipData.newPlainText(Helper.CLIP_BOARD, status.getReblog() != null ? status.getReblog().getUrl() : status.getUrl()); }
if (clipboard != null) { intentCustomSharing.putExtras(bCustomSharing);
clipboard.setPrimaryClip(clip); context.startActivity(intentCustomSharing);
Toasty.info(context, context.getString(R.string.clipboard_url), Toast.LENGTH_LONG).show(); return true;
} } else if (itemId == R.id.action_mention) {
return true; Handler handler = new Handler();
case R.id.action_share: handler.postDelayed(() -> {
Intent sendIntent = new Intent(Intent.ACTION_SEND); Intent intent1 = new Intent(context, TootActivity.class);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.shared_via)); Bundle b1 = new Bundle();
sendIntent.putExtra(Intent.EXTRA_TEXT, status.getUrl()); b1.putString("tootMention", (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct());
sendIntent.setType("text/plain"); b1.putString("urlMention", (status.getReblog() != null) ? status.getReblog().getUrl() : status.getUrl());
context.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.share_with))); intent1.putExtras(b1);
return true; context.startActivity(intent1);
case R.id.action_custom_sharing: }, 500);
Intent intentCustomSharing = new Intent(context, CustomSharingActivity.class); return true;
Bundle bCustomSharing = new Bundle(); } else {
if (status.getReblog() != null) { return true;
bCustomSharing.putParcelable("status", status.getReblog());
} else {
bCustomSharing.putParcelable("status", status);
}
intentCustomSharing.putExtras(bCustomSharing);
context.startActivity(intentCustomSharing);
return true;
case R.id.action_mention:
Handler handler = new Handler();
handler.postDelayed(() -> {
Intent intent1 = new Intent(context, TootActivity.class);
Bundle b1 = new Bundle();
b1.putString("tootMention", (status.getReblog() != null) ? status.getReblog().getAccount().getAcct() : status.getAccount().getAcct());
b1.putString("urlMention", (status.getReblog() != null) ? status.getReblog().getUrl() : status.getUrl());
intent1.putExtras(b1);
context.startActivity(intent1);
}, 500);
return true;
default:
return true;
} }
//Text for report //Text for report

View File

@ -24,6 +24,7 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.text.InputFilter; import android.text.InputFilter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -39,6 +40,9 @@ import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityOptionsCompat; import androidx.core.app.ActivityOptionsCompat;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaderFactory;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.target.CustomTarget;
import com.bumptech.glide.request.transition.Transition; import com.bumptech.glide.request.transition.Transition;
@ -115,15 +119,19 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
} else { } else {
url = attachments.get(position).getPreview_url(); url = attachments.get(position).getPreview_url();
} }
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String cookie = token.split("\\|")[1];
LazyHeaders.Builder builder = new LazyHeaders.Builder()
.addHeader("Cookie", cookie);
GlideUrl glideUrl = new GlideUrl(url, builder.build());
if (expand_media || !isSensitive || (status != null && status.isAttachmentShown())) { if (expand_media || !isSensitive || (status != null && status.isAttachmentShown())) {
Glide.with(viewHolder.imageViewBackground.getContext()) Glide.with(viewHolder.imageViewBackground.getContext())
.load(url) .load(glideUrl)
.thumbnail(0.1f) .thumbnail(0.1f)
.into(viewHolder.imageViewBackground); .into(viewHolder.imageViewBackground);
} else { } else {
Glide.with(viewHolder.imageViewBackground.getContext()) Glide.with(viewHolder.imageViewBackground.getContext())
.load(url) .load(glideUrl)
.thumbnail(0.1f) .thumbnail(0.1f)
.apply(new RequestOptions().transform(new BlurTransformation(50, 3))) .apply(new RequestOptions().transform(new BlurTransformation(50, 3)))
.into(viewHolder.imageViewBackground); .into(viewHolder.imageViewBackground);
@ -198,9 +206,14 @@ public class SliderAdapter extends SliderViewAdapter<SliderAdapter.SliderAdapter
final EditText input = popup_media_description.findViewById(R.id.media_description); final EditText input = popup_media_description.findViewById(R.id.media_description);
input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)}); input.setFilters(new InputFilter[]{new InputFilter.LengthFilter(1500)});
final ImageView media_picture = popup_media_description.findViewById(R.id.media_picture); final ImageView media_picture = popup_media_description.findViewById(R.id.media_picture);
String token = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
String cookie = token.split("\\|")[1];
LazyHeaders.Builder builder = new LazyHeaders.Builder()
.addHeader("Cookie", cookie);
GlideUrl glideUrl = new GlideUrl(attachment.getUrl(), builder.build());
Glide.with(contextWeakReference.get()) Glide.with(contextWeakReference.get())
.asBitmap() .asBitmap()
.load(attachment.getUrl()) .load(glideUrl)
.into(new CustomTarget<Bitmap>() { .into(new CustomTarget<Bitmap>() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override @Override

View File

@ -24,6 +24,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -96,7 +97,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_notifications, container, false); rootView = inflater.inflate(R.layout.fragment_notifications, container, false);
max_id = null; if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
max_id = null;
} else {
max_id = "1";
}
context = getContext(); context = getContext();
firstLoad = true; firstLoad = true;
flag_loading = true; flag_loading = true;
@ -288,7 +293,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
} }
int previousPosition = notifications.size(); int previousPosition = notifications.size();
max_id = apiResponse.getMax_id(); if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
max_id = apiResponse.getMax_id();
} else {
max_id = String.valueOf(Integer.parseInt(max_id) + 1);
}
List<Notification> notifications = apiResponse.getNotifications(); List<Notification> notifications = apiResponse.getNotifications();
if (!swiped && firstLoad && (notifications == null || notifications.size() == 0)) if (!swiped && firstLoad && (notifications == null || notifications.size() == 0))
@ -381,7 +390,11 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
void refreshAll() { void refreshAll() {
if (context == null) if (context == null)
return; return;
max_id = null; if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
max_id = null;
} else {
max_id = "1";
}
firstLoad = true; firstLoad = true;
flag_loading = true; flag_loading = true;
swiped = true; swiped = true;

View File

@ -632,12 +632,7 @@ public class DisplayStatusFragment extends Fragment implements OnPostActionInter
//At this point all statuses are in "List<Status> statuses" //At this point all statuses are in "List<Status> statuses"
//Pagination for Pixelfed //Pagination for Pixelfed
if (instanceType.equals("PIXELFED")) { if (type == RetrieveFeedsAsyncTask.Type.SEARCH && !tag.contains("_cache_")) {
if (max_id == null)
max_id = "1";
//max_id needs to work like an offset
max_id = String.valueOf(Integer.parseInt(max_id) + 1);
} else if (type == RetrieveFeedsAsyncTask.Type.SEARCH && !tag.contains("_cache_")) {
if (max_id == null) if (max_id == null)
max_id = "0"; max_id = "0";
max_id = String.valueOf(Integer.parseInt(max_id) + 20); max_id = String.valueOf(Integer.parseInt(max_id) + 20);

View File

@ -3013,6 +3013,9 @@ public class BaseHelper {
SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(APP_PREFS, Context.MODE_PRIVATE);
boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false); boolean disableGif = sharedpreferences.getBoolean(SET_DISABLE_GIF, false);
String url = disableGif ? account.getAvatar_static() : account.getAvatar(); String url = disableGif ? account.getAvatar_static() : account.getAvatar();
if (account.getAvatar_static() == null || account.getAvatar_static().toLowerCase().trim().compareTo("null") == 0) {
url = account.getAvatar();
}
if (url != null && url.startsWith("/")) { if (url != null && url.startsWith("/")) {
url = getLiveInstanceWithProtocol(context) + url; url = getLiveInstanceWithProtocol(context) + url;
} }