1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-08 07:57:28 +00:00

backup user argument for GraphQL feed

This commit is contained in:
Austin Huang 2021-03-21 21:35:18 -04:00
parent e9239c31b0
commit af3ec4ba26
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
4 changed files with 37 additions and 44 deletions

View File

@ -133,7 +133,7 @@ public final class PostFetcher extends AsyncTask<Void, Void, Media> {
// feedModelBuilder.setSliderItems(postModels);
// }
// return feedModelBuilder.build();
return ResponseBodyUtils.parseGraphQLItem(media);
return ResponseBodyUtils.parseGraphQLItem(media, null);
}
} catch (Exception e) {
// if (logCollector != null) {

View File

@ -49,7 +49,7 @@ public class ProfilePostFetchService implements PostFetcher.PostFetchService {
}
};
if (isLoggedIn) profileService.fetchPosts(profileModel.getPk(), nextMaxId, cb);
else graphQLService.fetchProfilePosts(profileModel.getPk(), 30, nextMaxId, cb);
else graphQLService.fetchProfilePosts(profileModel.getPk(), 30, nextMaxId, profileModel, cb);
}
@Override

View File

@ -675,7 +675,8 @@ public final class ResponseBodyUtils {
// return feedModelBuilder.build();
// }
public static Media parseGraphQLItem(final JSONObject itemJson) throws JSONException {
// the "user" argument can be null, it's used because instagram redacts user details from responses
public static Media parseGraphQLItem(final JSONObject itemJson, final User backup) throws JSONException {
if (itemJson == null) {
return null;
}
@ -728,41 +729,28 @@ public final class ResponseBodyUtils {
width = dimensions.optInt("width");
}
String thumbnailUrl = null;
try {
thumbnailUrl = feedItem.getJSONArray("display_resources")
.getJSONObject(0)
.getString("src");
} catch (JSONException ignored) {}
// final FeedModel.Builder feedModelBuilder = new FeedModel.Builder()
// .setProfileModel(profileModel)
// .setItemType(isVideo ? MediaItemType.MEDIA_TYPE_VIDEO
// : MediaItemType.MEDIA_TYPE_IMAGE)
// .setViewCount(videoViews)
// .setPostId(feedItem.getString(Constants.EXTRAS_ID))
// .setDisplayUrl(resourceUrl)
// .setThumbnailUrl(thumbnailUrl != null ? thumbnailUrl : displayUrl)
// .setShortCode(feedItem.getString(Constants.EXTRAS_SHORTCODE))
// .setPostCaption(captionText)
// .setCommentsCount(commentsCount)
// .setTimestamp(feedItem.optLong("taken_at_timestamp", -1))
// .setLiked(feedItem.optBoolean("viewer_has_liked"))
// .setBookmarked(feedItem.optBoolean("viewer_has_saved"))
// .setLikesCount(likesCount)
// .setLocationName(locationName)
// .setLocationId(String.valueOf(locationId))
// .setImageHeight(height)
// .setImageWidth(width);
final JSONArray displayResources = feedItem.getJSONArray("display_resources");
final List<MediaCandidate> candidates = new ArrayList<MediaCandidate>();
for (int i = 0; i < displayResources.length(); i++) {
final JSONObject displayResource = displayResources.getJSONObject(i);
candidates.add(new MediaCandidate(
displayResource.getInt("config_width"),
displayResource.getInt("config_height"),
displayResource.getString("src")
));
}
final ImageVersions2 imageVersions2 = new ImageVersions2(candidates);
User user = null;
User user = backup;
long userId = -1;
if (feedItem.has("owner")) {
if (feedItem.has("owner") && user == null) {
final JSONObject owner = feedItem.getJSONObject("owner");
final FriendshipStatus friendshipStatus = new FriendshipStatus(
false,
false,
false,
false,
owner.optBoolean("is_private"),
false,
false,
false,
false,
@ -774,7 +762,7 @@ public final class ResponseBodyUtils {
userId,
owner.optString(Constants.EXTRAS_USERNAME),
owner.optString("full_name"),
owner.optBoolean("is_private"),
false,
owner.optString("profile_pic_url"),
null,
friendshipStatus,
@ -783,13 +771,6 @@ public final class ResponseBodyUtils {
null, null, null, null);
}
final String id = feedItem.getString(Constants.EXTRAS_ID);
final ImageVersions2 imageVersions2 = new ImageVersions2(
Collections.singletonList(new MediaCandidate(
width,
height,
isVideo ? thumbnailUrl : resourceUrl
))
);
VideoVersion videoVersion = null;
if (isVideo) {
videoVersion = new VideoVersion(
@ -821,7 +802,7 @@ public final class ResponseBodyUtils {
for (int i = 0; i < children.length(); i++) {
final JSONObject child = children.optJSONObject(i);
if (child == null) continue;
final Media media = parseGraphQLItem(child);
final Media media = parseGraphQLItem(child, null);
media.setIsSidecarChild(true);
childItems.add(media);
}

View File

@ -56,6 +56,7 @@ public class GraphQLService extends BaseService {
final String variables,
final String arg1,
final String arg2,
final User backup,
final ServiceCallback<PostsFetchResponse> callback) {
final Map<String, String> queryMap = new HashMap<>();
queryMap.put("query_hash", queryHash);
@ -66,7 +67,7 @@ public class GraphQLService extends BaseService {
public void onResponse(@NonNull final Call<String> call, @NonNull final Response<String> response) {
try {
// Log.d(TAG, "onResponse: body: " + response.body());
final PostsFetchResponse postsFetchResponse = parsePostResponse(response, arg1, arg2);
final PostsFetchResponse postsFetchResponse = parsePostResponse(response, arg1, arg2, backup);
if (callback != null) {
callback.onSuccess(postsFetchResponse);
}
@ -96,6 +97,7 @@ public class GraphQLService extends BaseService {
"\"after\":\"" + (maxId == null ? "" : maxId) + "\"}",
Constants.EXTRAS_LOCATION,
"edge_location_to_media",
null,
callback);
}
@ -108,12 +110,14 @@ public class GraphQLService extends BaseService {
"\"after\":\"" + (maxId == null ? "" : maxId) + "\"}",
Constants.EXTRAS_HASHTAG,
"edge_hashtag_to_media",
null,
callback);
}
public void fetchProfilePosts(final long profileId,
final int postsPerPage,
final String maxId,
final User backup,
final ServiceCallback<PostsFetchResponse> callback) {
fetch("18a7b935ab438c4514b1f742d8fa07a7",
"{\"id\":\"" + profileId + "\"," +
@ -121,6 +125,7 @@ public class GraphQLService extends BaseService {
"\"after\":\"" + (maxId == null ? "" : maxId) + "\"}",
Constants.EXTRAS_USER,
"edge_owner_to_timeline_media",
backup,
callback);
}
@ -134,21 +139,28 @@ public class GraphQLService extends BaseService {
"\"after\":\"" + (maxId == null ? "" : maxId) + "\"}",
Constants.EXTRAS_USER,
"edge_user_to_photos_of_you",
null,
callback);
}
@NonNull
private PostsFetchResponse parsePostResponse(@NonNull final Response<String> response, @NonNull final String arg1, @NonNull final String arg2)
private PostsFetchResponse parsePostResponse(@NonNull final Response<String> response,
@NonNull final String arg1,
@NonNull final String arg2,
final User backup)
throws JSONException {
if (TextUtils.isEmpty(response.body())) {
Log.e(TAG, "parseResponse: feed response body is empty with status code: " + response.code());
return new PostsFetchResponse(Collections.emptyList(), false, null);
}
return parseResponseBody(response.body(), arg1, arg2);
return parseResponseBody(response.body(), arg1, arg2, backup);
}
@NonNull
private PostsFetchResponse parseResponseBody(@NonNull final String body, @NonNull final String arg1, @NonNull final String arg2)
private PostsFetchResponse parseResponseBody(@NonNull final String body,
@NonNull final String arg1,
@NonNull final String arg2,
final User backup)
throws JSONException {
final List<Media> items = new ArrayList<>();
final JSONObject timelineFeed = new JSONObject(body)
@ -174,7 +186,7 @@ public class GraphQLService extends BaseService {
if (itemJson == null) {
continue;
}
final Media media = ResponseBodyUtils.parseGraphQLItem(itemJson);
final Media media = ResponseBodyUtils.parseGraphQLItem(itemJson, backup);
if (media != null) {
items.add(media);
}