43 lines
1.3 KiB
Swift
43 lines
1.3 KiB
Swift
//
|
|
// 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.getData(status.account.avatar),
|
|
let image = UIImage(data: data) {
|
|
metadata.iconProvider = NSItemProvider(object: image)
|
|
}
|
|
return metadata
|
|
}
|
|
|
|
}
|