From 82b000a4df10510e928044b892af879fbca31e6f Mon Sep 17 00:00:00 2001 From: SmellyGhost <60049391+Smelly-Ghost@users.noreply.github.com> Date: Thu, 9 Jul 2026 17:48:42 -0700 Subject: [PATCH] Update MediaDownload.xm --- src/Features/Media/MediaDownload.xm | 47 +++++++++++++++++++---------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/Features/Media/MediaDownload.xm b/src/Features/Media/MediaDownload.xm index 88a92158..f06460f3 100644 --- a/src/Features/Media/MediaDownload.xm +++ b/src/Features/Media/MediaDownload.xm @@ -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(self.delegate, "_configuration"); - if (!_configuration) return; - - photo = MSHookIvar(_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(self.delegate, "_configuration"); + if (_configuration) { + photo = MSHookIvar(_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 @@ -365,4 +380,4 @@ static void initDownloaders () { fileExtension:[[imageUrl lastPathComponent] pathExtension] hudLabel:@"Loading"]; } -%end \ No newline at end of file +%end