From 3081b96a410f91b0a7df447765f2551a49dc7fff Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Wed, 20 Dec 2023 19:07:14 +0100 Subject: [PATCH] If we only share an URL, we don't need metadata (#1199) --- Mastodon.xcodeproj/project.pbxproj | 8 ++++---- ...thMetadata.swift => URLActivityItem.swift} | 17 ++++++----------- .../Provider/DataSourceFacade+Status.swift | 19 ++++--------------- ...Provider+StatusTableViewCellDelegate.swift | 8 +------- 4 files changed, 15 insertions(+), 37 deletions(-) rename Mastodon/Helper/{URLActivityItemWithMetadata.swift => URLActivityItem.swift} (57%) diff --git a/Mastodon.xcodeproj/project.pbxproj b/Mastodon.xcodeproj/project.pbxproj index ca2738797..46fb7fa44 100644 --- a/Mastodon.xcodeproj/project.pbxproj +++ b/Mastodon.xcodeproj/project.pbxproj @@ -122,7 +122,7 @@ 855149C8295F1C5F00943D96 /* UIInterfaceOrientationMask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 855149C7295F1C5F00943D96 /* UIInterfaceOrientationMask.swift */; }; 855149CA29606D6400943D96 /* PortraitAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 855149C929606D6400943D96 /* PortraitAlertController.swift */; }; 85904C02293BC0EB0011C817 /* ImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85904C01293BC0EB0011C817 /* ImageProvider.swift */; }; - 85904C04293BC1940011C817 /* URLActivityItemWithMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85904C03293BC1940011C817 /* URLActivityItemWithMetadata.swift */; }; + 85904C04293BC1940011C817 /* URLActivityItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85904C03293BC1940011C817 /* URLActivityItem.swift */; }; 85BC11B32932414900E191CD /* AltTextViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 85BC11B22932414900E191CD /* AltTextViewController.swift */; }; 9E44C7202967AD17004B2A72 /* MastodonSDKDynamic in Frameworks */ = {isa = PBXBuildFile; productRef = 9E44C71F2967AD17004B2A72 /* MastodonSDKDynamic */; }; 9E44C7222967AD17004B2A72 /* MastodonSDKDynamic in Embed Frameworks */ = {isa = PBXBuildFile; productRef = 9E44C71F2967AD17004B2A72 /* MastodonSDKDynamic */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; @@ -766,7 +766,7 @@ 855149C7295F1C5F00943D96 /* UIInterfaceOrientationMask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIInterfaceOrientationMask.swift; sourceTree = ""; }; 855149C929606D6400943D96 /* PortraitAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortraitAlertController.swift; sourceTree = ""; }; 85904C01293BC0EB0011C817 /* ImageProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageProvider.swift; sourceTree = ""; }; - 85904C03293BC1940011C817 /* URLActivityItemWithMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLActivityItemWithMetadata.swift; sourceTree = ""; }; + 85904C03293BC1940011C817 /* URLActivityItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLActivityItem.swift; sourceTree = ""; }; 85BC11B22932414900E191CD /* AltTextViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AltTextViewController.swift; sourceTree = ""; }; 8850E70A1D5FF51432E43653 /* Pods-Mastodon-MastodonUITests.asdk - release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mastodon-MastodonUITests.asdk - release.xcconfig"; path = "Target Support Files/Pods-Mastodon-MastodonUITests/Pods-Mastodon-MastodonUITests.asdk - release.xcconfig"; sourceTree = ""; }; 89FE8B85A00419CEF4678056 /* Pods_MastodonTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MastodonTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -2921,7 +2921,7 @@ children = ( DBF3B7402733EB9400E21627 /* MastodonLocalCode.swift */, 85904C01293BC0EB0011C817 /* ImageProvider.swift */, - 85904C03293BC1940011C817 /* URLActivityItemWithMetadata.swift */, + 85904C03293BC1940011C817 /* URLActivityItem.swift */, 855149C929606D6400943D96 /* PortraitAlertController.swift */, ); path = Helper; @@ -3650,7 +3650,7 @@ 62FD27D52893708A00B205C5 /* BookmarkViewModel+Diffable.swift in Sources */, DB72602725E36A6F00235243 /* MastodonServerRulesViewModel.swift in Sources */, 2D364F7225E66D7500204FDC /* MastodonResendEmailViewController.swift in Sources */, - 85904C04293BC1940011C817 /* URLActivityItemWithMetadata.swift in Sources */, + 85904C04293BC1940011C817 /* URLActivityItem.swift in Sources */, DB68A06325E905E000CFDF14 /* UIApplication.swift in Sources */, DB02CDAB26256A9500D0A2AF /* ThreadReplyLoaderTableViewCell.swift in Sources */, DBEFCD80282A2AA900C0ABEA /* ReportServerRulesViewModel.swift in Sources */, diff --git a/Mastodon/Helper/URLActivityItemWithMetadata.swift b/Mastodon/Helper/URLActivityItem.swift similarity index 57% rename from Mastodon/Helper/URLActivityItemWithMetadata.swift rename to Mastodon/Helper/URLActivityItem.swift index f0b0cd359..7e63a781c 100644 --- a/Mastodon/Helper/URLActivityItemWithMetadata.swift +++ b/Mastodon/Helper/URLActivityItem.swift @@ -1,5 +1,5 @@ // -// URLActivityItemWithMetadata.swift +// URLActivityItem.swift // Mastodon // // Created by Jed Fox on 2022-12-03. @@ -8,17 +8,12 @@ import UIKit import LinkPresentation -class URLActivityItemWithMetadata: NSObject, UIActivityItemSource { - init(url: URL, configureMetadata: (LPLinkMetadata) -> Void) { - self.url = url - self.metadata = LPLinkMetadata() - metadata.url = url - metadata.originalURL = url - configureMetadata(metadata) - } - +class URLActivityItem: NSObject, UIActivityItemSource { let url: URL - let metadata: LPLinkMetadata + + init(url: URL) { + self.url = url + } func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { return url diff --git a/Mastodon/Protocol/Provider/DataSourceFacade+Status.swift b/Mastodon/Protocol/Provider/DataSourceFacade+Status.swift index 94b7db058..3140dc70c 100644 --- a/Mastodon/Protocol/Provider/DataSourceFacade+Status.swift +++ b/Mastodon/Protocol/Provider/DataSourceFacade+Status.swift @@ -62,23 +62,12 @@ extension DataSourceFacade { status: MastodonStatus ) async throws -> UIActivityViewController { var activityItems: [Any] = { - guard let url = URL(string: status.entity.url ?? status.entity.uri) - else { return [] } + guard let url = URL(string: status.entity.url ?? status.entity.uri) else { return [] } return [ - URLActivityItemWithMetadata(url: url) { metadata in - metadata.title = "\(status.entity.account.displayName) (@\(status.entity.account.acctWithDomain))" - metadata.iconProvider = ImageProvider( - url: status.entity.account.avatarImageURLWithFallback(domain: status.entity.account.domain ?? ""), - filter: ScaledToSizeFilter(size: CGSize.authorAvatarButtonSize) - ).itemProvider - - if let firstAssetURL = status.attachments.first?.previewURL, let url = URL(string: firstAssetURL) { - metadata.imageProvider = ImageProvider(url: url).itemProvider - } - } - ] as [Any] + URLActivityItem(url: url) + ] }() - + var applicationActivities: [UIActivity] = [ SafariActivity(sceneCoordinator: dependency.coordinator), // open URL ] diff --git a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift index 57360f0c6..8ae264a20 100644 --- a/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift +++ b/Mastodon/Protocol/Provider/DataSourceProvider+StatusTableViewCellDelegate.swift @@ -202,13 +202,7 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte DispatchQueue.main.async { let activityViewController = UIActivityViewController( activityItems: [ - URLActivityItemWithMetadata(url: url) { metadata in - metadata.title = card.title - - if let image = card.image, let url = URL(string: image) { - metadata.iconProvider = ImageProvider(url: url, filter: nil).itemProvider - } - } + URLActivityItem(url: url) ], applicationActivities: [] )