From 7269788831ea89d95e2beb09e24ec7d31e872ba4 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Tue, 30 Apr 2024 19:10:03 +0200 Subject: [PATCH 1/2] feat(StatusEditHistory): load remote history Sometimes the server sends only the latest status instead of the full history. Try to avoid this by requesting the history directly from the server. --- .../fragments/StatusEditHistoryFragment.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java index 819f58a77b..6a1dbe9e77 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java @@ -3,8 +3,8 @@ import android.app.Activity; import android.net.Uri; import android.os.Bundle; -import android.view.View; +import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.statuses.GetStatusEditHistory; import org.joinmastodon.android.model.FilterContext; @@ -13,7 +13,6 @@ import org.joinmastodon.android.ui.displayitems.ReblogOrReplyLineStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.StatusDisplayItem; import org.joinmastodon.android.ui.text.HtmlParser; -import org.joinmastodon.android.ui.utils.InsetStatusItemDecoration; import org.joinmastodon.android.ui.utils.UiUtils; import java.time.ZoneId; @@ -26,6 +25,8 @@ import java.util.Objects; import java.util.stream.Collectors; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; import name.fraser.neil.plaintext.diff_match_patch; @@ -54,12 +55,45 @@ protected void doLoadData(int offset, int count){ public void onSuccess(List result){ if(getActivity()==null) return; Collections.sort(result, Comparator.comparing((Status s)->s.createdAt).reversed()); + if(result.size()<=1&& GlobalUserPreferences.allowRemoteLoading) { + //server send only a single edit, which is always the original status + //try to get the complete history from the remote server + loadRemoteData(result); + return; + } onDataLoaded(result, false); } }) .exec(accountID); } + void loadRemoteData(List prevData){ + String remoteURL = Uri.parse(url).getHost(); + String[] parts=url.split("/"); + + if(parts.length==0||remoteURL==null) { + onDataLoaded(prevData, false); + return; + } + + new GetStatusEditHistory(parts[parts.length-1]) + .setCallback(new Callback<>(){ + @Override + public void onSuccess(List result){ + if(getActivity()==null) return; + Collections.sort(result, Comparator.comparing((Status s)->s.createdAt).reversed()); + onDataLoaded(result, false); + } + + @Override + public void onError(ErrorResponse errorResponse){ + //fallback to previously loaded data + onDataLoaded(prevData, false); + } + }) + .execNoAuth(remoteURL); + } + @Override protected List buildDisplayItems(Status s){ List items=new ArrayList<>(); From 2dbfe88397540dbfc47e5975a65709659a6f0467 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sun, 5 May 2024 21:00:07 +0200 Subject: [PATCH 2/2] feat(StatusEditHistory): display subtitle on failed remote loading --- .../android/fragments/StatusEditHistoryFragment.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java index 6a1dbe9e77..0e6bf1ac9f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/StatusEditHistoryFragment.java @@ -73,6 +73,7 @@ void loadRemoteData(List prevData){ if(parts.length==0||remoteURL==null) { onDataLoaded(prevData, false); + setSubtitle(getContext().getString(R.string.sk_no_remote_info_hint)); return; } @@ -89,6 +90,7 @@ public void onSuccess(List result){ public void onError(ErrorResponse errorResponse){ //fallback to previously loaded data onDataLoaded(prevData, false); + setSubtitle(getContext().getString(R.string.sk_no_remote_info_hint)); } }) .execNoAuth(remoteURL);