Skip to content

Commit

Permalink
feat(StatusEditHistory): load remote history
Browse files Browse the repository at this point in the 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.
  • Loading branch information
FineFindus committed Apr 30, 2024
1 parent d5cd016 commit 7269788
Showing 1 changed file with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -54,12 +55,45 @@ protected void doLoadData(int offset, int count){
public void onSuccess(List<Status> 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<Status> 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<Status> 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<StatusDisplayItem> buildDisplayItems(Status s){
List<StatusDisplayItem> items=new ArrayList<>();
Expand Down

0 comments on commit 7269788

Please sign in to comment.