Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions src/Features/Media/MediaDownload.xm
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,47 @@ static void initDownloaders () {
%new - (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
if (sender.state != UIGestureRecognizerStateBegan) return;

// Get photo instance
IGPhoto *photo;

if ([self.delegate isKindOfClass:%c(IGFeedItemPhotoCell)]) {
IGFeedItemPhotoCellConfiguration *_configuration = MSHookIvar<IGFeedItemPhotoCellConfiguration *>(self.delegate, "_configuration");
if (!_configuration) return;

photo = MSHookIvar<IGPhoto *>(_configuration, "_photo");
NSURL *photoUrl = nil;

// 1. Try our direct FLEX discovery route first (safest for 437.x carousels)
if ([self respondsToSelector:@selector(imageSpecifier)]) {
IGImageSpecifier *specifier = [self imageSpecifier];
if (specifier && specifier.url) {
photoUrl = specifier.url;
}
}
else if ([self.delegate isKindOfClass:%c(IGFeedItemPagePhotoCell)]) {
IGFeedItemPagePhotoCell *pagePhotoCell = self.delegate;

photo = pagePhotoCell.pagePhotoPost.photo;
// 2. If the direct specifier route fails, fall back to the original delegate methods
if (!photoUrl) {
IGPhoto *photo = nil;
if ([self.delegate isKindOfClass:%c(IGFeedItemPhotoCell)]) {
IGFeedItemPhotoCellConfiguration *_configuration = MSHookIvar<IGFeedItemPhotoCellConfiguration *>(self.delegate, "_configuration");
if (_configuration) {
photo = MSHookIvar<IGPhoto *>(_configuration, "_photo");
}
}
else if ([self.delegate isKindOfClass:%c(IGFeedItemPagePhotoCell)]) {
IGFeedItemPagePhotoCell *pagePhotoCell = self.delegate;
if ([pagePhotoCell respondsToSelector:@selector(pagePhotoPost)]) {
photo = pagePhotoCell.pagePhotoPost.photo;
}
}

if (photo) {
photoUrl = [SCIUtils getPhotoUrl:photo];
}
}

NSURL *photoUrl = [SCIUtils getPhotoUrl:photo];
// Error handling if both extraction attempts hit a dead end
if (!photoUrl) {
[SCIUtils showErrorHUDWithDescription:@"Could not extract photo url from post"];

return;
}

// Download image & show in share menu
// Download image & pass it to the delivery engine
initDownloaders();
[imageDownloadDelegate downloadFileWithURL:photoUrl
fileExtension:[[photoUrl lastPathComponent]pathExtension]
fileExtension:[[photoUrl lastPathComponent] pathExtension]
hudLabel:nil];
}
%end
Expand Down Expand Up @@ -365,4 +380,4 @@ static void initDownloaders () {
fileExtension:[[imageUrl lastPathComponent] pathExtension]
hudLabel:@"Loading"];
}
%end
%end
Loading