diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index c1af2a33..4f287394 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -170,6 +170,8 @@ D68015422401A74600D6103B /* MediaPrefsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68015412401A74600D6103B /* MediaPrefsView.swift */; }; D681E4D3246E2AFF0053414F /* MuteConversationActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D2246E2AFF0053414F /* MuteConversationActivity.swift */; }; D681E4D5246E2BC30053414F /* UnmuteConversationActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D4246E2BC30053414F /* UnmuteConversationActivity.swift */; }; + D681E4D7246E32290053414F /* StatusActivityItemSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D6246E32290053414F /* StatusActivityItemSource.swift */; }; + D681E4D9246E346E0053414F /* AccountActivityItemSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D681E4D8246E346E0053414F /* AccountActivityItemSource.swift */; }; D68232F72464F4FD00325FB8 /* ComposeDrawingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68232F62464F4FD00325FB8 /* ComposeDrawingViewController.swift */; }; D68FEC4F232C5BC300C84F23 /* SegmentedPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D68FEC4E232C5BC300C84F23 /* SegmentedPageViewController.swift */; }; D693DE5723FE1A6A0061E07D /* EnhancedNavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D693DE5623FE1A6A0061E07D /* EnhancedNavigationViewController.swift */; }; @@ -471,6 +473,8 @@ D68015412401A74600D6103B /* MediaPrefsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPrefsView.swift; sourceTree = ""; }; D681E4D2246E2AFF0053414F /* MuteConversationActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MuteConversationActivity.swift; sourceTree = ""; }; D681E4D4246E2BC30053414F /* UnmuteConversationActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnmuteConversationActivity.swift; sourceTree = ""; }; + D681E4D6246E32290053414F /* StatusActivityItemSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusActivityItemSource.swift; sourceTree = ""; }; + D681E4D8246E346E0053414F /* AccountActivityItemSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountActivityItemSource.swift; sourceTree = ""; }; D68232F62464F4FD00325FB8 /* ComposeDrawingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeDrawingViewController.swift; sourceTree = ""; }; D68FEC4E232C5BC300C84F23 /* SegmentedPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedPageViewController.swift; sourceTree = ""; }; D693DE5623FE1A6A0061E07D /* EnhancedNavigationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnhancedNavigationViewController.swift; sourceTree = ""; }; @@ -1137,6 +1141,8 @@ D6AEBB3F2321640F00E5038B /* Activities */ = { isa = PBXGroup; children = ( + D681E4D6246E32290053414F /* StatusActivityItemSource.swift */, + D681E4D8246E346E0053414F /* AccountActivityItemSource.swift */, D6AEBB3D2321638100E5038B /* UIActivity+Types.swift */, D6AEBB422321685E00E5038B /* OpenInSafariActivity.swift */, D64BC19123C271D9000D0238 /* MastodonActivity.swift */, @@ -1781,6 +1787,7 @@ D66362752137068A00C9CBA2 /* Visibility+Helpers.swift in Sources */, D6DFC6A0242C4CCC00ACC392 /* WeakArray.swift in Sources */, D6C693FC2162FE6F007D6A6D /* LoadingViewController.swift in Sources */, + D681E4D7246E32290053414F /* StatusActivityItemSource.swift in Sources */, D646C95A213B5D0500269FB5 /* LargeImageInteractionController.swift in Sources */, D6A3BC7C232195C600FD64D5 /* ActionNotificationGroupTableViewCell.swift in Sources */, D6F953EC212519E700CF0F2B /* TimelineTableViewController.swift in Sources */, @@ -1800,6 +1807,7 @@ 0427037C22B316B9000D31B6 /* SilentActionPrefs.swift in Sources */, D6AEBB3E2321638100E5038B /* UIActivity+Types.swift in Sources */, D61AC1D5232E9FA600C54D2D /* InstanceSelectorTableViewController.swift in Sources */, + D681E4D9246E346E0053414F /* AccountActivityItemSource.swift in Sources */, D626493F23C101C500612E6E /* AlbumAssetCollectionViewController.swift in Sources */, D68015422401A74600D6103B /* MediaPrefsView.swift in Sources */, D6757A7E2157E02600721E32 /* XCBRequestSpec.swift in Sources */, diff --git a/Tusker/Activities/AccountActivityItemSource.swift b/Tusker/Activities/AccountActivityItemSource.swift new file mode 100644 index 00000000..ed32e529 --- /dev/null +++ b/Tusker/Activities/AccountActivityItemSource.swift @@ -0,0 +1,39 @@ +// +// AccountActivityItemSource.swift +// Tusker +// +// Created by Shadowfacts on 5/14/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import UIKit +import LinkPresentation + +class AccountActivityItemSource: NSObject, UIActivityItemSource { + let account: AccountMO + + init(_ account: AccountMO) { + self.account = account + } + + func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { + return account + } + + func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { + return account + } + + func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { + let metadata = LPLinkMetadata() + metadata.originalURL = account.url + metadata.url = account.url + metadata.title = "\(account.displayName) (@\(account.username)@\(account.url.host!)" + if let data = ImageCache.avatars.get(account.avatar), + let image = UIImage(data: data) { + metadata.iconProvider = NSItemProvider(object: image) + } + return metadata + } + +} diff --git a/Tusker/Activities/StatusActivityItemSource.swift b/Tusker/Activities/StatusActivityItemSource.swift new file mode 100644 index 00000000..dc0d78c9 --- /dev/null +++ b/Tusker/Activities/StatusActivityItemSource.swift @@ -0,0 +1,42 @@ +// +// StatusActivityItemSource.swift +// Tusker +// +// Created by Shadowfacts on 5/14/20. +// Copyright © 2020 Shadowfacts. All rights reserved. +// + +import UIKit +import LinkPresentation +import SwiftSoup + +class StatusActivityItemSource: NSObject, UIActivityItemSource { + let status: StatusMO + + init(_ status: StatusMO) { + self.status = status + } + + func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any { + return status + } + + func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? { + return status + } + + func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? { + let metadata = LPLinkMetadata() + metadata.originalURL = status.url! + metadata.url = status.url! + let doc = try! SwiftSoup.parse(status.content) + let content = try! doc.text() + metadata.title = "\(status.account.displayName): \"\(content)\"" + if let data = ImageCache.avatars.get(status.account.avatar), + let image = UIImage(data: data) { + metadata.iconProvider = NSItemProvider(object: image) + } + return metadata + } + +} diff --git a/Tusker/Screens/Profile/ProfileTableViewController.swift b/Tusker/Screens/Profile/ProfileTableViewController.swift index 85890d16..f7b1b539 100644 --- a/Tusker/Screens/Profile/ProfileTableViewController.swift +++ b/Tusker/Screens/Profile/ProfileTableViewController.swift @@ -297,7 +297,7 @@ extension ProfileTableViewController: ProfileHeaderTableViewCellDelegate { } DispatchQueue.main.async { - let activityController = UIActivityViewController(activityItems: [account.url, account], applicationActivities: customActivities) + let activityController = UIActivityViewController(activityItems: [account.url, AccountActivityItemSource(account)], applicationActivities: customActivities) activityController.completionWithItemsHandler = OpenInSafariActivity.completionHandler(viewController: self, url: account.url) activityController.popoverPresentationController?.sourceView = cell.moreButtonVisualEffectView self.present(activityController, animated: true) diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index ab5fbc75..f97dee56 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -217,14 +217,21 @@ extension TuskerNavigationDelegate where Self: UIViewController { customActivites.insert(pinned ? UnpinStatusActivity() : PinStatusActivity(), at: 1) } - let activityController = UIActivityViewController(activityItems: [url, status], applicationActivities: customActivites) + let activityController = UIActivityViewController(activityItems: [url, StatusActivityItemSource(status)], applicationActivities: customActivites) activityController.completionWithItemsHandler = OpenInSafariActivity.completionHandler(viewController: self, url: url) return activityController } private func moreOptions(forAccount accountID: String) -> UIActivityViewController { guard let account = apiController.persistentContainer.account(for: accountID) else { fatalError("Missing cached account \(accountID)") } - return moreOptions(forURL: account.url) + + let customActivities: [UIActivity] = [ + OpenInSafariActivity(), + ] + + let activityController = UIActivityViewController(activityItems: [account.url, AccountActivityItemSource(account)], applicationActivities: customActivities) + activityController.completionWithItemsHandler = OpenInSafariActivity.completionHandler(viewController: self, url: account.url) + return activityController } func showMoreOptions(forStatus statusID: String, sourceView: UIView?) {