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); // feedModelBuilder.setSliderItems(postModels);
// } // }
// return feedModelBuilder.build(); // return feedModelBuilder.build();
return ResponseBodyUtils.parseGraphQLItem(media); return ResponseBodyUtils.parseGraphQLItem(media, null);
} }
} catch (Exception e) { } catch (Exception e) {
// if (logCollector != null) { // if (logCollector != null) {

View File

@ -49,7 +49,7 @@ public class ProfilePostFetchService implements PostFetcher.PostFetchService {
} }
}; };
if (isLoggedIn) profileService.fetchPosts(profileModel.getPk(), nextMaxId, cb); 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 @Override

View File

@ -675,7 +675,8 @@ public final class ResponseBodyUtils {
// return feedModelBuilder.build(); // 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) { if (itemJson == null) {
return null; return null;
} }
@ -728,41 +729,28 @@ public final class ResponseBodyUtils {
width = dimensions.optInt("width"); width = dimensions.optInt("width");
} }
String thumbnailUrl = null; String thumbnailUrl = null;
try { final JSONArray displayResources = feedItem.getJSONArray("display_resources");
thumbnailUrl = feedItem.getJSONArray("display_resources") final List<MediaCandidate> candidates = new ArrayList<MediaCandidate>();
.getJSONObject(0) for (int i = 0; i < displayResources.length(); i++) {
.getString("src"); final JSONObject displayResource = displayResources.getJSONObject(i);
} catch (JSONException ignored) {} candidates.add(new MediaCandidate(
// final FeedModel.Builder feedModelBuilder = new FeedModel.Builder() displayResource.getInt("config_width"),
// .setProfileModel(profileModel) displayResource.getInt("config_height"),
// .setItemType(isVideo ? MediaItemType.MEDIA_TYPE_VIDEO displayResource.getString("src")
// : MediaItemType.MEDIA_TYPE_IMAGE) ));
// .setViewCount(videoViews) }
// .setPostId(feedItem.getString(Constants.EXTRAS_ID)) final ImageVersions2 imageVersions2 = new ImageVersions2(candidates);
// .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);
User user = null; User user = backup;
long userId = -1; long userId = -1;
if (feedItem.has("owner")) { if (feedItem.has("owner") && user == null) {
final JSONObject owner = feedItem.getJSONObject("owner"); final JSONObject owner = feedItem.getJSONObject("owner");
final FriendshipStatus friendshipStatus = new FriendshipStatus( final FriendshipStatus friendshipStatus = new FriendshipStatus(
false, false,
false, false,
false, false,
false, false,
owner.optBoolean("is_private"), false,
false, false,
false, false,
false, false,
@ -774,7 +762,7 @@ public final class ResponseBodyUtils {
userId, userId,
owner.optString(Constants.EXTRAS_USERNAME), owner.optString(Constants.EXTRAS_USERNAME),
owner.optString("full_name"), owner.optString("full_name"),
owner.optBoolean("is_private"), false,
owner.optString("profile_pic_url"), owner.optString("profile_pic_url"),
null, null,
friendshipStatus, friendshipStatus,
@ -783,13 +771,6 @@ public final class ResponseBodyUtils {
null, null, null, null); null, null, null, null);
} }
final String id = feedItem.getString(Constants.EXTRAS_ID); 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; VideoVersion videoVersion = null;
if (isVideo) { if (isVideo) {
videoVersion = new VideoVersion( videoVersion = new VideoVersion(
@ -821,7 +802,7 @@ public final class ResponseBodyUtils {
for (int i = 0; i < children.length(); i++) { for (int i = 0; i < children.length(); i++) {
final JSONObject child = children.optJSONObject(i); final JSONObject child = children.optJSONObject(i);
if (child == null) continue; if (child == null) continue;
final Media media = parseGraphQLItem(child); final Media media = parseGraphQLItem(child, null);
media.setIsSidecarChild(true); media.setIsSidecarChild(true);
childItems.add(media); childItems.add(media);
} }

View File

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