Show more metadata for posts (#1200)

* Show first image when sharing (#1199)

* Don't share custom metadata (#1199)

🤦 that was way to easy, thanks docs!

* If we only share an URL, we don't need metadata (#1199)
This commit is contained in:
Nathan Mattes 2024-02-09 11:14:51 +01:00 committed by GitHub
parent a90d5ea084
commit 23a505b321
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 34 additions and 55 deletions

View File

@ -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 = "<group>"; };
855149C929606D6400943D96 /* PortraitAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortraitAlertController.swift; sourceTree = "<group>"; };
85904C01293BC0EB0011C817 /* ImageProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageProvider.swift; sourceTree = "<group>"; };
85904C03293BC1940011C817 /* URLActivityItemWithMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLActivityItemWithMetadata.swift; sourceTree = "<group>"; };
85904C03293BC1940011C817 /* URLActivityItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLActivityItem.swift; sourceTree = "<group>"; };
85BC11B22932414900E191CD /* AltTextViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AltTextViewController.swift; sourceTree = "<group>"; };
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 = "<group>"; };
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 */,

View File

@ -0,0 +1,25 @@
//
// URLActivityItem.swift
// Mastodon
//
// Created by Jed Fox on 2022-12-03.
//
import UIKit
import LinkPresentation
class URLActivityItem: NSObject, UIActivityItemSource {
let url: URL
init(url: URL) {
self.url = url
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
return url
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
return url
}
}

View File

@ -1,33 +0,0 @@
//
// URLActivityItemWithMetadata.swift
// Mastodon
//
// Created by Jed Fox on 2022-12-03.
//
import UIKit
import LinkPresentation
class URLActivityItemWithMetadata: NSObject, UIActivityItemSource {
init(url: URL, configureMetadata: (LPLinkMetadata) -> Void) {
self.url = url
self.metadata = LPLinkMetadata()
metadata.url = url
configureMetadata(metadata)
}
let url: URL
let metadata: LPLinkMetadata
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
url
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
url
}
func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
metadata
}
}

View File

@ -62,17 +62,10 @@ 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
}
] as [Any]
URLActivityItem(url: url)
]
}()
var applicationActivities: [UIActivity] = [

View File

@ -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: []
)