Compare commits
No commits in common. "cc401fce8c96b29e49fddc2fb536c484c6e0c444" and "3ea1ad5622f6e9ae5b9fe7c77ddd21a6a2df696e" have entirely different histories.
cc401fce8c
...
3ea1ad5622
|
@ -7,12 +7,11 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import WebURL
|
||||
|
||||
public final class Status: StatusProtocol, Decodable {
|
||||
public let id: String
|
||||
public let uri: String
|
||||
public let url: WebURL?
|
||||
public let url: URL?
|
||||
public let account: Account
|
||||
public let inReplyToID: String?
|
||||
public let inReplyToAccountID: String?
|
||||
|
|
|
@ -289,7 +289,6 @@
|
|||
D6CA6A92249FAD8900AD45C1 /* AudioSessionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6CA6A91249FAD8900AD45C1 /* AudioSessionHelper.swift */; };
|
||||
D6CA6A94249FADE700AD45C1 /* GalleryPlayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6CA6A93249FADE700AD45C1 /* GalleryPlayerViewController.swift */; };
|
||||
D6CA8CDA2962231F0050C433 /* ArrayUniqueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6CA8CD92962231F0050C433 /* ArrayUniqueTests.swift */; };
|
||||
D6CA8CDE296387310050C433 /* SaveToPhotosActivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6CA8CDD296387310050C433 /* SaveToPhotosActivity.swift */; };
|
||||
D6D12B2F2925D66500D528E1 /* TimelineGapCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D12B2E2925D66500D528E1 /* TimelineGapCollectionViewCell.swift */; };
|
||||
D6D12B56292D57E800D528E1 /* AccountCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D12B55292D57E800D528E1 /* AccountCollectionViewCell.swift */; };
|
||||
D6D12B58292D5B2C00D528E1 /* StatusActionAccountListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6D12B57292D5B2C00D528E1 /* StatusActionAccountListViewController.swift */; };
|
||||
|
@ -675,7 +674,6 @@
|
|||
D6CA6A91249FAD8900AD45C1 /* AudioSessionHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioSessionHelper.swift; sourceTree = "<group>"; };
|
||||
D6CA6A93249FADE700AD45C1 /* GalleryPlayerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryPlayerViewController.swift; sourceTree = "<group>"; };
|
||||
D6CA8CD92962231F0050C433 /* ArrayUniqueTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrayUniqueTests.swift; sourceTree = "<group>"; };
|
||||
D6CA8CDD296387310050C433 /* SaveToPhotosActivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SaveToPhotosActivity.swift; sourceTree = "<group>"; };
|
||||
D6D12B2E2925D66500D528E1 /* TimelineGapCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineGapCollectionViewCell.swift; sourceTree = "<group>"; };
|
||||
D6D12B55292D57E800D528E1 /* AccountCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCollectionViewCell.swift; sourceTree = "<group>"; };
|
||||
D6D12B57292D5B2C00D528E1 /* StatusActionAccountListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusActionAccountListViewController.swift; sourceTree = "<group>"; };
|
||||
|
@ -1301,7 +1299,6 @@
|
|||
D681E4D8246E346E0053414F /* AccountActivityItemSource.swift */,
|
||||
D6AEBB3D2321638100E5038B /* UIActivity+Types.swift */,
|
||||
D6AEBB422321685E00E5038B /* OpenInSafariActivity.swift */,
|
||||
D6CA8CDD296387310050C433 /* SaveToPhotosActivity.swift */,
|
||||
);
|
||||
path = Activities;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1977,7 +1974,6 @@
|
|||
D6E9CDA8281A427800BBC98E /* PostService.swift in Sources */,
|
||||
D6B053A223BD2C0600A066FA /* AssetPickerViewController.swift in Sources */,
|
||||
D6EE63FB2551F7F60065485C /* StatusCollapseButton.swift in Sources */,
|
||||
D6CA8CDE296387310050C433 /* SaveToPhotosActivity.swift in Sources */,
|
||||
D6B936712829F72900237D0E /* NSManagedObjectContext+Helpers.swift in Sources */,
|
||||
D68A76EE295369C7001DA1B3 /* AcknowledgementsView.swift in Sources */,
|
||||
D627944A23A6AD6100D38C68 /* BookmarksTableViewController.swift in Sources */,
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
//
|
||||
// SaveToPhotosActivity.swift
|
||||
// Tusker
|
||||
//
|
||||
// Created by Shadowfacts on 1/2/23.
|
||||
// Copyright © 2023 Shadowfacts. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import UniformTypeIdentifiers
|
||||
import Photos
|
||||
|
||||
class SaveToPhotosActivity: UIActivity {
|
||||
|
||||
override class var activityCategory: UIActivity.Category {
|
||||
return .action
|
||||
}
|
||||
override var activityType: UIActivity.ActivityType? {
|
||||
return .saveToPhotos
|
||||
}
|
||||
|
||||
override var activityTitle: String? {
|
||||
return "Save to Photos"
|
||||
}
|
||||
override var activityImage: UIImage? {
|
||||
UIImage(systemName: "square.and.arrow.down")
|
||||
}
|
||||
|
||||
override func canPerform(withActivityItems activityItems: [Any]) -> Bool {
|
||||
return activityItems.contains(where: {
|
||||
if let url = $0 as? URL,
|
||||
let type = UTType(filenameExtension: url.pathExtension){
|
||||
return type.conforms(to: .movie) || type.conforms(to: .video) || type.conforms(to: .image)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private var url: URL?
|
||||
private var type: UTType?
|
||||
|
||||
override func prepare(withActivityItems activityItems: [Any]) {
|
||||
for case let url as URL in activityItems {
|
||||
self.url = url
|
||||
type = UTType(filenameExtension: url.pathExtension)!
|
||||
}
|
||||
}
|
||||
|
||||
override func perform() {
|
||||
guard let url,
|
||||
let type else {
|
||||
return
|
||||
}
|
||||
PHPhotoLibrary.requestAuthorization(for: .addOnly) { status in
|
||||
guard case .authorized = status else {
|
||||
return
|
||||
}
|
||||
PHPhotoLibrary.shared().performChanges {
|
||||
if type.conforms(to: .movie) || type.conforms(to: .video) {
|
||||
_ = PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: url)
|
||||
} else {
|
||||
_ = PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: url)
|
||||
}
|
||||
} completionHandler: { _, _ in
|
||||
self.activityDidFinish(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -11,6 +11,5 @@ import UIKit
|
|||
extension UIActivity.ActivityType {
|
||||
|
||||
static let openInSafari = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).open_in_safari")
|
||||
static let saveToPhotos = UIActivity.ActivityType("\(Bundle.main.bundleIdentifier!).save_to_photos")
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
import Foundation
|
||||
import CoreData
|
||||
import Pachyderm
|
||||
import WebURLFoundationExtras
|
||||
|
||||
@objc(StatusMO)
|
||||
public final class StatusMO: NSManagedObject, StatusProtocol {
|
||||
|
@ -128,7 +127,7 @@ extension StatusMO {
|
|||
self.sensitive = status.sensitive
|
||||
self.spoilerText = status.spoilerText
|
||||
self.uri = status.uri
|
||||
self.url = status.url != nil ? URL(status.url!) : nil
|
||||
self.url = status.url
|
||||
self.visibility = status.visibility
|
||||
self.poll = status.poll
|
||||
self.localOnly = status.localOnly ?? false
|
||||
|
|
|
@ -211,10 +211,7 @@ class MainSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDelegate
|
|||
}
|
||||
|
||||
func logoutCurrent() {
|
||||
guard let account = window?.windowScene?.session.mastodonController?.accountInfo else {
|
||||
return
|
||||
}
|
||||
LocalData.shared.removeAccount(account)
|
||||
LocalData.shared.removeAccount(LocalData.shared.getMostRecentAccount()!)
|
||||
if LocalData.shared.onboardingComplete {
|
||||
activateAccount(LocalData.shared.accounts.first!, animated: false)
|
||||
} else {
|
||||
|
|
|
@ -15,7 +15,7 @@ class AccountListViewController: UIViewController, CollectionViewController {
|
|||
private let accountIDs: [String]
|
||||
|
||||
var collectionView: UICollectionView! {
|
||||
view as? UICollectionView
|
||||
view as! UICollectionView
|
||||
}
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
|
||||
|
||||
|
|
|
@ -31,20 +31,13 @@ class LargeImageImageContentView: UIImageView, LargeImageContentView {
|
|||
|
||||
var animationImage: UIImage? { image! }
|
||||
var activityItemsForSharing: [Any] {
|
||||
guard let data else {
|
||||
return []
|
||||
}
|
||||
return [ImageActivityItemSource(data: data, url: url, image: image)]
|
||||
[image!]
|
||||
}
|
||||
weak var owner: LargeImageViewController?
|
||||
|
||||
private let url: URL
|
||||
private let data: Data?
|
||||
private var sourceData: Data?
|
||||
|
||||
init(url: URL, data: Data?, image: UIImage) {
|
||||
self.url = url
|
||||
self.data = data
|
||||
|
||||
init(image: UIImage) {
|
||||
super.init(image: image)
|
||||
|
||||
contentMode = .scaleAspectFit
|
||||
|
@ -86,7 +79,7 @@ class LargeImageImageContentView: UIImageView, LargeImageContentView {
|
|||
}
|
||||
|
||||
func grayscaleStateChanged() {
|
||||
guard let data else {
|
||||
guard let data = sourceData else {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -115,15 +108,12 @@ extension LargeImageImageContentView: ImageAnalysisInteractionDelegate {
|
|||
class LargeImageGifContentView: GIFImageView, LargeImageContentView {
|
||||
var animationImage: UIImage? { image }
|
||||
var activityItemsForSharing: [Any] {
|
||||
[ImageActivityItemSource(data: gifController!.gifData, url: url, image: image)]
|
||||
// todo: should gifs share the data?
|
||||
[image].compactMap { $0 }
|
||||
}
|
||||
weak var owner: LargeImageViewController?
|
||||
|
||||
private let url: URL
|
||||
|
||||
init(url: URL, gifController: GIFController) {
|
||||
self.url = url
|
||||
|
||||
init(gifController: GIFController) {
|
||||
super.init(image: gifController.lastFrame?.image)
|
||||
|
||||
contentMode = .scaleAspectFit
|
||||
|
@ -148,22 +138,22 @@ class LargeImageGifContentView: GIFImageView, LargeImageContentView {
|
|||
class LargeImageGifvContentView: GifvAttachmentView, LargeImageContentView {
|
||||
private(set) var animationImage: UIImage?
|
||||
var activityItemsForSharing: [Any] {
|
||||
[GifvActivityItemSource(asset: asset, attachment: attachment)]
|
||||
// todo: what should we share for gifvs?
|
||||
// some SO posts indicate that just sharing a URL to the video should work, but that may need to be a local URL?
|
||||
[]
|
||||
}
|
||||
weak var owner: LargeImageViewController?
|
||||
|
||||
private let attachment: Attachment
|
||||
private let asset: AVURLAsset
|
||||
|
||||
private var videoSize: CGSize?
|
||||
override var intrinsicContentSize: CGSize {
|
||||
videoSize ?? CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric)
|
||||
}
|
||||
|
||||
|
||||
init(attachment: Attachment, source: UIImageView) {
|
||||
precondition(attachment.kind == .gifv)
|
||||
|
||||
self.attachment = attachment
|
||||
self.asset = AVURLAsset(url: attachment.url)
|
||||
|
||||
super.init(asset: asset, gravity: .resizeAspect)
|
||||
|
@ -194,78 +184,4 @@ class LargeImageGifvContentView: GifvAttachmentView, LargeImageContentView {
|
|||
func grayscaleStateChanged() {
|
||||
// no-op, GifvAttachmentView observes the grayscale state itself
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileprivate class ImageActivityItemSource: NSObject, UIActivityItemSource {
|
||||
let data: Data
|
||||
let url: URL
|
||||
let image: UIImage?
|
||||
|
||||
init(data: Data, url: URL, image: UIImage?) {
|
||||
self.data = data
|
||||
self.url = url
|
||||
self.image = image
|
||||
}
|
||||
|
||||
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
|
||||
return url
|
||||
}
|
||||
|
||||
func activityViewController(_ activityViewController: UIActivityViewController, thumbnailImageForActivityType activityType: UIActivity.ActivityType?, suggestedSize size: CGSize) -> UIImage? {
|
||||
return image
|
||||
}
|
||||
|
||||
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
|
||||
do {
|
||||
let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent(url.lastPathComponent)
|
||||
try data.write(to: tempURL)
|
||||
return tempURL
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func activityViewController(_ activityViewController: UIActivityViewController, dataTypeIdentifierForActivityType activityType: UIActivity.ActivityType?) -> String {
|
||||
return (UTType(filenameExtension: url.pathExtension) ?? .image).identifier
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate class GifvActivityItemSource: NSObject, UIActivityItemSource {
|
||||
let asset: AVAsset
|
||||
let attachment: Attachment
|
||||
|
||||
init(asset: AVAsset, attachment: Attachment) {
|
||||
self.asset = asset
|
||||
self.attachment = attachment
|
||||
}
|
||||
|
||||
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
|
||||
return attachment.url
|
||||
}
|
||||
|
||||
func activityViewController(_ activityViewController: UIActivityViewController, thumbnailImageForActivityType activityType: UIActivity.ActivityType?, suggestedSize size: CGSize) -> UIImage? {
|
||||
let generator = AVAssetImageGenerator(asset: self.asset)
|
||||
generator.appliesPreferredTrackTransform = true
|
||||
if let image = try? generator.copyCGImage(at: .zero, actualTime: nil) {
|
||||
return UIImage(cgImage: image)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
|
||||
do {
|
||||
let data = try Data(contentsOf: attachment.url)
|
||||
let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent(attachment.url.lastPathComponent)
|
||||
try data.write(to: tempURL)
|
||||
return tempURL
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func activityViewController(_ activityViewController: UIActivityViewController, dataTypeIdentifierForActivityType activityType: UIActivity.ActivityType?) -> String {
|
||||
return (UTType(filenameExtension: attachment.url.pathExtension) ?? .video).identifier
|
||||
}
|
||||
}
|
||||
|
|
|
@ -381,7 +381,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
|
|||
}
|
||||
|
||||
@IBAction func sharePressed(_ sender: Any) {
|
||||
let activityVC = UIActivityViewController(activityItems: contentView.activityItemsForSharing, applicationActivities: [SaveToPhotosActivity()])
|
||||
let activityVC = UIActivityViewController(activityItems: contentView.activityItemsForSharing, applicationActivities: nil)
|
||||
activityVC.popoverPresentationController?.sourceView = shareImage
|
||||
present(activityVC, animated: true)
|
||||
}
|
||||
|
|
|
@ -135,12 +135,12 @@ class LoadingLargeImageViewController: UIViewController, LargeImageAnimatableVie
|
|||
// is it possible for the source view's gif controller to have different data than we just got?
|
||||
// should this be a property set by the animation controller instead?
|
||||
let gifController = (animationSourceView as? GIFImageView)?.gifController ?? GIFController(gifData: data)
|
||||
content = LargeImageGifContentView(url: url, gifController: gifController)
|
||||
content = LargeImageGifContentView(gifController: gifController)
|
||||
} else {
|
||||
if let transformedImage = ImageGrayscalifier.convertIfNecessary(url: url, image: image) {
|
||||
content = LargeImageImageContentView(url: url, data: data, image: transformedImage)
|
||||
content = LargeImageImageContentView(image: transformedImage)
|
||||
} else {
|
||||
content = LargeImageImageContentView(url: url, data: data, image: image)
|
||||
content = LargeImageImageContentView(image: image)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,7 +167,7 @@ class LoadingLargeImageViewController: UIViewController, LargeImageAnimatableVie
|
|||
let grayscale = ImageGrayscalifier.convert(url: nil, cgImage: source) {
|
||||
image = grayscale
|
||||
}
|
||||
setContent(LargeImageImageContentView(url: url, data: nil, image: image))
|
||||
setContent(LargeImageImageContentView(image: image))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,27 +58,30 @@ extension ToastConfiguration {
|
|||
// TODO: this is a bizarre place to do this, but code path covers basically all errors
|
||||
switch error.type {
|
||||
case .invalidRequest, .invalidResponse, .invalidModel(_), .mastodonError(_):
|
||||
let event = Event(error: error)
|
||||
event.message = SentryMessage(formatted: "\(title): \(error)")
|
||||
event.tags = [
|
||||
"request_method": error.requestMethod.name,
|
||||
"request_endpoint": error.requestEndpoint.description,
|
||||
]
|
||||
switch error.type {
|
||||
case .invalidRequest:
|
||||
event.tags!["error_type"] = "invalid_request"
|
||||
case .invalidResponse:
|
||||
event.tags!["error_type"] = "invalid_response"
|
||||
case .invalidModel(let error):
|
||||
event.tags!["error_type"] = "invalid_model"
|
||||
event.tags!["underlying_error"] = String(describing: error)
|
||||
case .mastodonError(let error):
|
||||
event.tags!["error_type"] = "mastodon_error"
|
||||
event.tags!["underlying_error"] = error
|
||||
default:
|
||||
break
|
||||
SentrySDK.capture(error: error) { scope in
|
||||
scope.setFingerprint([String(describing: error)])
|
||||
let crumb = Breadcrumb(level: .error, category: "error")
|
||||
crumb.message = title
|
||||
crumb.data = [
|
||||
"request_method": error.requestMethod.name,
|
||||
"request_endpoint": error.requestEndpoint.description,
|
||||
]
|
||||
switch error.type {
|
||||
case .invalidRequest:
|
||||
crumb.data!["error_type"] = "invalid_request"
|
||||
case .invalidResponse:
|
||||
crumb.data!["error_type"] = "invalid_response"
|
||||
case .invalidModel(let error):
|
||||
crumb.data!["error_type"] = "invalid_model"
|
||||
crumb.data!["underlying_error"] = String(describing: error)
|
||||
case .mastodonError(let error):
|
||||
crumb.data!["error_type"] = "mastodon_error"
|
||||
crumb.data!["underlying_error"] = error
|
||||
default:
|
||||
break
|
||||
}
|
||||
scope.add(crumb)
|
||||
}
|
||||
SentrySDK.capture(event: event)
|
||||
default:
|
||||
break
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue