Fix bug with post detail refreshing

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2023-07-22 16:36:15 +02:00
parent 258ff290bb
commit c756342ce6
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
3 changed files with 12 additions and 11 deletions

View File

@ -24,6 +24,9 @@ public interface LemmyAPI {
@GET("api/v3/community")
Call<String> communityInfo(@Query("name") String name, @Query("auth") String access_token);
@GET("api/v3/post")
Call<String> postInfo(@Query("id") Integer postID, @Query("comment_id") Integer comment_id, @Query("auth") String access_token);
@GET("api/v3/user")
ListenableFuture<Response<String>> getUserPosts(
@Query("username") String username,

View File

@ -6,8 +6,8 @@ import androidx.annotation.NonNull;
import java.util.concurrent.Executor;
import eu.toldi.infinityforlemmy.apis.LemmyAPI;
import eu.toldi.infinityforlemmy.apis.RedditAPI;
import eu.toldi.infinityforlemmy.utils.APIUtils;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
@ -17,11 +17,9 @@ public class FetchPost {
public static void fetchPost(Executor executor, Handler handler, Retrofit retrofit, String id, String accessToken,
FetchPostListener fetchPostListener) {
Call<String> postCall;
if (accessToken == null) {
postCall = retrofit.create(RedditAPI.class).getPost(id);
} else {
postCall = retrofit.create(RedditAPI.class).getPostOauth(id, APIUtils.getOAuthHeader(accessToken));
}
// Use LemmyAPI.postInfo() instead of RedditAPI.getPost()
postCall = retrofit.create(LemmyAPI.class).postInfo(Integer.parseInt(id), null, accessToken);
postCall.enqueue(new Callback<>() {
@Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {

View File

@ -98,13 +98,13 @@ public class ParsePost {
executor.execute(() -> {
try {
JSONArray allData = new JSONArray(response).getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY).getJSONArray(JSONUtils.CHILDREN_KEY);
JSONObject allData = new JSONObject(response).getJSONObject("post_view");
if (allData.length() == 0) {
handler.post(parsePostListener::onParsePostFail);
return;
}
JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY);
Post post = parseBasicData(data);
Post post = parseBasicData(allData);
handler.post(() -> parsePostListener.onParsePostSuccess(post));
} catch (JSONException e) {
e.printStackTrace();