2018-08-17 02:39:16 +00:00
|
|
|
//
|
2019-11-19 17:08:11 +00:00
|
|
|
// BaseStatusTableViewCell.swift
|
2018-08-17 02:39:16 +00:00
|
|
|
// Tusker
|
|
|
|
//
|
2019-11-19 17:08:11 +00:00
|
|
|
// Created by Shadowfacts on 11/19/19.
|
|
|
|
// Copyright © 2019 Shadowfacts. All rights reserved.
|
2018-08-17 02:39:16 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2019-11-19 17:08:11 +00:00
|
|
|
import Combine
|
2018-08-17 02:39:16 +00:00
|
|
|
|
2019-09-09 22:40:23 +00:00
|
|
|
protocol StatusTableViewCellDelegate: TuskerNavigationDelegate {
|
2019-11-28 23:36:58 +00:00
|
|
|
func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell)
|
2018-08-27 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
class BaseStatusTableViewCell: UITableViewCell {
|
2020-01-05 20:25:07 +00:00
|
|
|
|
2020-01-20 04:02:07 +00:00
|
|
|
weak var delegate: StatusTableViewCellDelegate? {
|
2018-10-12 01:20:58 +00:00
|
|
|
didSet {
|
2020-01-18 21:00:38 +00:00
|
|
|
contentTextView.navigationDelegate = delegate
|
2018-10-12 01:20:58 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-06 00:39:37 +00:00
|
|
|
var overrideMastodonController: MastodonController?
|
|
|
|
var mastodonController: MastodonController! { overrideMastodonController ?? delegate?.apiController }
|
2019-12-14 18:36:05 +00:00
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBOutlet weak var avatarImageView: UIImageView!
|
2020-03-02 00:40:32 +00:00
|
|
|
@IBOutlet weak var displayNameLabel: EmojiLabel!
|
2018-08-17 02:39:16 +00:00
|
|
|
@IBOutlet weak var usernameLabel: UILabel!
|
2020-03-12 01:56:35 +00:00
|
|
|
@IBOutlet weak var contentWarningLabel: EmojiLabel!
|
2019-09-09 22:40:23 +00:00
|
|
|
@IBOutlet weak var collapseButton: UIButton!
|
2020-01-18 21:00:38 +00:00
|
|
|
@IBOutlet weak var contentTextView: StatusContentTextView!
|
2019-06-16 23:02:18 +00:00
|
|
|
@IBOutlet weak var attachmentsView: AttachmentsContainerView!
|
2019-09-27 00:53:22 +00:00
|
|
|
@IBOutlet weak var replyButton: UIButton!
|
2018-09-09 01:35:40 +00:00
|
|
|
@IBOutlet weak var favoriteButton: UIButton!
|
|
|
|
@IBOutlet weak var reblogButton: UIButton!
|
2019-09-27 00:53:22 +00:00
|
|
|
@IBOutlet weak var moreButton: UIButton!
|
2018-08-17 02:39:16 +00:00
|
|
|
|
2018-09-18 01:57:46 +00:00
|
|
|
var statusID: String!
|
2018-09-18 16:59:07 +00:00
|
|
|
var accountID: String!
|
2019-11-19 17:08:11 +00:00
|
|
|
|
|
|
|
var favorited = false {
|
2018-09-09 01:35:40 +00:00
|
|
|
didSet {
|
|
|
|
favoriteButton.tintColor = favorited ? UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) : tintColor
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 17:08:11 +00:00
|
|
|
var reblogged = false {
|
2018-09-09 01:35:40 +00:00
|
|
|
didSet {
|
|
|
|
reblogButton.tintColor = reblogged ? UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) : tintColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-28 23:36:58 +00:00
|
|
|
var statusState: StatusState!
|
2019-09-09 22:40:23 +00:00
|
|
|
var collapsible = false {
|
|
|
|
didSet {
|
|
|
|
collapseButton.isHidden = !collapsible
|
2019-11-28 23:36:58 +00:00
|
|
|
statusState?.collapsible = collapsible
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var collapsed = false {
|
|
|
|
didSet {
|
|
|
|
statusState?.collapsed = collapsed
|
2019-09-09 22:40:23 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-19 03:23:15 +00:00
|
|
|
var showStatusAutomatically = false
|
|
|
|
|
2020-01-25 15:06:27 +00:00
|
|
|
private var avatarRequest: ImageCache.Request?
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
private var statusUpdater: Cancellable?
|
|
|
|
private var accountUpdater: Cancellable?
|
|
|
|
|
2019-08-02 03:01:15 +00:00
|
|
|
deinit {
|
|
|
|
statusUpdater?.cancel()
|
|
|
|
accountUpdater?.cancel()
|
|
|
|
}
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
override func awakeFromNib() {
|
2019-11-19 17:08:11 +00:00
|
|
|
super.awakeFromNib()
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
displayNameLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
|
|
usernameLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
|
|
avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
avatarImageView.layer.masksToBounds = true
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-06-16 23:02:18 +00:00
|
|
|
attachmentsView.delegate = self
|
2018-09-02 20:59:20 +00:00
|
|
|
attachmentsView.layer.cornerRadius = 5
|
|
|
|
attachmentsView.layer.masksToBounds = true
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-09-09 22:40:23 +00:00
|
|
|
collapseButton.layer.masksToBounds = true
|
|
|
|
collapseButton.layer.cornerRadius = 5
|
2019-08-02 03:01:15 +00:00
|
|
|
|
2020-01-18 21:00:38 +00:00
|
|
|
accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!]
|
2019-09-27 00:53:22 +00:00
|
|
|
attachmentsView.isAccessibilityElement = true
|
|
|
|
|
2019-08-03 00:05:47 +00:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(updateUIForPreferences), name: .preferencesChanged, object: nil)
|
2020-01-06 00:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open func createObserversIfNecessary() {
|
|
|
|
if statusUpdater == nil {
|
|
|
|
statusUpdater = mastodonController.cache.statusSubject
|
2020-01-20 04:14:51 +00:00
|
|
|
.filter { [unowned self] in $0.id == self.statusID }
|
2020-01-06 00:54:28 +00:00
|
|
|
.receive(on: DispatchQueue.main)
|
2020-01-20 04:14:51 +00:00
|
|
|
.sink { [unowned self] in self.updateStatusState(status: $0) }
|
2020-01-06 00:54:28 +00:00
|
|
|
}
|
2019-08-03 00:05:47 +00:00
|
|
|
|
2020-01-06 00:54:28 +00:00
|
|
|
if accountUpdater == nil {
|
|
|
|
accountUpdater = mastodonController.cache.accountSubject
|
2020-01-20 04:14:51 +00:00
|
|
|
.filter { [unowned self] in $0.id == self.accountID }
|
2020-01-06 00:54:28 +00:00
|
|
|
.receive(on: DispatchQueue.main)
|
2020-01-20 04:14:51 +00:00
|
|
|
.sink { [unowned self] in self.updateUI(account: $0) }
|
2020-01-06 00:54:28 +00:00
|
|
|
}
|
2018-08-28 01:27:34 +00:00
|
|
|
}
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-11-28 23:36:58 +00:00
|
|
|
func updateUI(statusID: String, state: StatusState) {
|
2020-01-06 00:54:28 +00:00
|
|
|
createObserversIfNecessary()
|
|
|
|
|
|
|
|
guard let status = mastodonController.cache.status(for: statusID) else {
|
2019-11-19 17:08:11 +00:00
|
|
|
fatalError("Missing cached status")
|
|
|
|
}
|
2019-08-02 03:01:15 +00:00
|
|
|
self.statusID = statusID
|
2019-11-28 23:36:58 +00:00
|
|
|
self.statusState = state
|
2018-08-18 03:09:59 +00:00
|
|
|
|
2018-10-31 02:07:54 +00:00
|
|
|
let account = status.account
|
2018-09-18 16:59:07 +00:00
|
|
|
self.accountID = account.id
|
2019-08-02 03:01:15 +00:00
|
|
|
updateUI(account: account)
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2018-08-28 23:49:31 +00:00
|
|
|
updateUIForPreferences()
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-08-02 03:01:15 +00:00
|
|
|
attachmentsView.updateUI(status: status)
|
2019-09-27 00:53:22 +00:00
|
|
|
attachmentsView.isAccessibilityElement = status.attachments.count > 0
|
|
|
|
attachmentsView.accessibilityLabel = String(format: NSLocalizedString("%d attachments", comment: "status attachments count accessibility label"), status.attachments.count)
|
2019-11-19 17:08:11 +00:00
|
|
|
|
|
|
|
updateStatusState(status: status)
|
|
|
|
|
2020-01-18 21:00:38 +00:00
|
|
|
contentTextView.statusID = statusID
|
2019-09-09 22:40:23 +00:00
|
|
|
|
2019-11-29 02:22:13 +00:00
|
|
|
contentWarningLabel.text = status.spoilerText
|
|
|
|
contentWarningLabel.isHidden = status.spoilerText.isEmpty
|
2020-03-12 01:56:35 +00:00
|
|
|
if !contentWarningLabel.isHidden {
|
|
|
|
contentWarningLabel.setEmojis(status.emojis, identifier: statusID)
|
|
|
|
}
|
2019-11-29 02:22:13 +00:00
|
|
|
|
2019-11-28 23:36:58 +00:00
|
|
|
if state.unknown {
|
|
|
|
collapsible = !status.spoilerText.isEmpty
|
|
|
|
var shouldCollapse = collapsible
|
|
|
|
if !shouldCollapse,
|
2020-01-18 21:00:38 +00:00
|
|
|
let text = contentTextView.text,
|
2019-11-28 23:36:58 +00:00
|
|
|
text.count > 500 {
|
|
|
|
collapsible = true
|
|
|
|
shouldCollapse = true
|
|
|
|
}
|
|
|
|
if collapsible && showStatusAutomatically {
|
|
|
|
shouldCollapse = false
|
|
|
|
}
|
|
|
|
setCollapsed(shouldCollapse, animated: false)
|
|
|
|
|
|
|
|
state.collapsible = collapsible
|
|
|
|
state.collapsed = shouldCollapse
|
|
|
|
} else {
|
|
|
|
collapsible = state.collapsible!
|
|
|
|
setCollapsed(state.collapsed!, animated: false)
|
2019-11-17 23:36:19 +00:00
|
|
|
}
|
2019-08-02 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
func updateStatusState(status: Status) {
|
2019-08-02 03:01:15 +00:00
|
|
|
favorited = status.favourited ?? false
|
|
|
|
reblogged = status.reblogged ?? false
|
2019-09-27 00:53:22 +00:00
|
|
|
|
|
|
|
if favorited {
|
|
|
|
favoriteButton.accessibilityLabel = NSLocalizedString("Undo Favorite", comment: "undo favorite button accessibility label")
|
|
|
|
} else {
|
|
|
|
favoriteButton.accessibilityLabel = NSLocalizedString("Favorite", comment: "favorite button accessibility label")
|
|
|
|
}
|
|
|
|
if reblogged {
|
|
|
|
reblogButton.accessibilityLabel = NSLocalizedString("Undo Reblog", comment: "undo reblog button accessibility label")
|
|
|
|
} else {
|
|
|
|
reblogButton.accessibilityLabel = NSLocalizedString("Reblog", comment: "reblog button accessibility label")
|
|
|
|
}
|
2019-08-02 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
func updateUI(account: Account) {
|
2018-08-18 03:09:59 +00:00
|
|
|
usernameLabel.text = "@\(account.acct)"
|
2018-08-21 23:23:27 +00:00
|
|
|
avatarImageView.image = nil
|
2020-01-25 15:06:27 +00:00
|
|
|
avatarRequest = ImageCache.avatars.get(account.avatar) { [weak self] (data) in
|
|
|
|
guard let self = self, let data = data, self.accountID == account.id else { return }
|
2018-09-11 14:52:21 +00:00
|
|
|
DispatchQueue.main.async {
|
2018-11-09 20:48:08 +00:00
|
|
|
self.avatarImageView.image = UIImage(data: data)
|
2018-08-21 23:23:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-18 03:09:59 +00:00
|
|
|
}
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-08-03 00:05:47 +00:00
|
|
|
@objc func updateUIForPreferences() {
|
2020-01-06 00:54:28 +00:00
|
|
|
guard let account = mastodonController.cache.account(for: accountID) else { return }
|
2019-08-03 00:05:47 +00:00
|
|
|
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
|
2020-03-02 00:40:32 +00:00
|
|
|
displayNameLabel.updateForAccountDisplayName(account: account)
|
2020-01-06 00:54:28 +00:00
|
|
|
attachmentsView.contentHidden = Preferences.shared.blurAllMedia || (mastodonController.cache.status(for: statusID)?.sensitive ?? false)
|
2019-08-03 00:05:47 +00:00
|
|
|
}
|
2018-08-21 23:23:27 +00:00
|
|
|
|
|
|
|
override func prepareForReuse() {
|
2019-11-19 17:08:11 +00:00
|
|
|
super.prepareForReuse()
|
|
|
|
|
2020-01-25 15:06:27 +00:00
|
|
|
avatarRequest?.cancel()
|
2019-11-17 17:52:42 +00:00
|
|
|
attachmentsView.attachmentViews.allObjects.forEach { $0.removeFromSuperview() }
|
2019-11-19 03:23:15 +00:00
|
|
|
showStatusAutomatically = false
|
2018-08-21 23:23:27 +00:00
|
|
|
}
|
2018-08-17 02:39:16 +00:00
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func collapseButtonPressed() {
|
2019-09-09 22:40:23 +00:00
|
|
|
setCollapsed(!collapsed, animated: true)
|
2019-11-28 23:36:58 +00:00
|
|
|
delegate?.statusCellCollapsedStateChanged(self)
|
2019-09-09 22:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func setCollapsed(_ collapsed: Bool, animated: Bool) {
|
|
|
|
self.collapsed = collapsed
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2020-01-18 21:00:38 +00:00
|
|
|
contentTextView.isHidden = collapsed
|
2019-09-09 22:40:23 +00:00
|
|
|
attachmentsView.isHidden = attachmentsView.attachments.count == 0 || collapsed
|
2019-11-19 17:08:11 +00:00
|
|
|
|
|
|
|
let buttonImage = UIImage(systemName: collapsed ? "chevron.down" : "chevron.up")!
|
2019-09-09 22:40:23 +00:00
|
|
|
|
|
|
|
if animated, let buttonImageView = collapseButton.imageView {
|
|
|
|
// we need to use a keyframe animation for this, because we want to control the direction the chevron rotates
|
|
|
|
// when rotating ±π, UIKit will always rotate in the same direction
|
|
|
|
// using a keyframe to set an intermediate point in the animation allows us to force a specific direction
|
|
|
|
UIView.animateKeyframes(withDuration: 0.2, delay: 0, options: .calculationModeLinear, animations: {
|
|
|
|
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.5) {
|
|
|
|
buttonImageView.transform = CGAffineTransform(rotationAngle: collapsed ? .pi / 2 : -.pi / 2)
|
|
|
|
}
|
|
|
|
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
|
|
|
|
buttonImageView.transform = CGAffineTransform(rotationAngle: .pi)
|
|
|
|
}
|
|
|
|
}, completion: { (finished) in
|
|
|
|
buttonImageView.transform = .identity
|
|
|
|
self.collapseButton.setImage(buttonImage, for: .normal)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
collapseButton.setImage(buttonImage, for: .normal)
|
|
|
|
}
|
2019-09-27 00:53:22 +00:00
|
|
|
|
|
|
|
if collapsed {
|
|
|
|
collapseButton.accessibilityLabel = NSLocalizedString("Expand Status", comment: "expand status button accessibility label")
|
|
|
|
} else {
|
|
|
|
collapseButton.accessibilityLabel = NSLocalizedString("Collapse Status", comment: "collapse status button accessibility label")
|
|
|
|
}
|
2019-11-19 17:08:11 +00:00
|
|
|
|
2019-09-09 22:40:23 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func replyPressed() {
|
2018-09-18 01:57:46 +00:00
|
|
|
delegate?.reply(to: statusID)
|
2018-08-31 02:30:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func favoritePressed() {
|
2020-01-06 00:54:28 +00:00
|
|
|
guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
|
2018-09-18 01:57:46 +00:00
|
|
|
|
2018-09-17 23:22:37 +00:00
|
|
|
let oldValue = favorited
|
2018-09-09 01:35:40 +00:00
|
|
|
favorited = !favorited
|
|
|
|
|
|
|
|
let realStatus: Status = status.reblog ?? status
|
2018-09-17 23:22:37 +00:00
|
|
|
let request = (favorited ? Status.favourite : Status.unfavourite)(realStatus)
|
2020-01-06 00:39:37 +00:00
|
|
|
mastodonController.run(request) { response in
|
2018-09-09 01:35:40 +00:00
|
|
|
DispatchQueue.main.async {
|
2019-08-02 00:03:49 +00:00
|
|
|
if case let .success(newStatus, _) = response {
|
|
|
|
self.favorited = newStatus.favourited ?? false
|
2020-01-06 00:54:28 +00:00
|
|
|
self.mastodonController.cache.add(status: newStatus)
|
2018-09-11 14:52:21 +00:00
|
|
|
UIImpactFeedbackGenerator(style: .light).impactOccurred()
|
|
|
|
} else {
|
2018-09-17 23:22:37 +00:00
|
|
|
self.favorited = oldValue
|
2018-09-11 14:52:21 +00:00
|
|
|
print("Couldn't favorite status \(realStatus.id)")
|
|
|
|
// todo: display error message
|
|
|
|
UINotificationFeedbackGenerator().notificationOccurred(.error)
|
|
|
|
return
|
|
|
|
}
|
2018-09-09 01:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func reblogPressed() {
|
2020-01-06 00:54:28 +00:00
|
|
|
guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
|
2018-09-18 01:57:46 +00:00
|
|
|
|
|
|
|
let oldValue = reblogged
|
2018-09-09 01:35:40 +00:00
|
|
|
reblogged = !reblogged
|
|
|
|
|
|
|
|
let realStatus: Status = status.reblog ?? status
|
2018-09-17 23:22:37 +00:00
|
|
|
let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus)
|
2020-01-06 00:39:37 +00:00
|
|
|
mastodonController.run(request) { response in
|
2018-09-09 01:35:40 +00:00
|
|
|
DispatchQueue.main.async {
|
2019-08-02 00:03:49 +00:00
|
|
|
if case let .success(newStatus, _) = response {
|
|
|
|
self.reblogged = newStatus.reblogged ?? false
|
2020-01-06 00:54:28 +00:00
|
|
|
self.mastodonController.cache.add(status: newStatus)
|
2018-09-11 14:52:21 +00:00
|
|
|
UIImpactFeedbackGenerator(style: .light).impactOccurred()
|
|
|
|
} else {
|
2018-09-18 01:57:46 +00:00
|
|
|
self.reblogged = oldValue
|
2018-09-11 14:52:21 +00:00
|
|
|
print("Couldn't reblog status \(realStatus.id)")
|
|
|
|
// todo: display error message
|
|
|
|
UINotificationFeedbackGenerator().notificationOccurred(.error)
|
|
|
|
}
|
2018-09-09 01:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func morePressed() {
|
2020-01-18 02:29:53 +00:00
|
|
|
delegate?.showMoreOptions(forStatus: statusID, sourceView: moreButton)
|
2018-09-11 22:17:48 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@objc func accountPressed() {
|
|
|
|
delegate?.selected(account: accountID)
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
func getStatusCellPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {
|
|
|
|
return nil
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
extension BaseStatusTableViewCell: AttachmentViewDelegate {
|
2019-07-28 02:45:11 +00:00
|
|
|
func showAttachmentsGallery(startingAt index: Int) {
|
2020-01-06 00:54:28 +00:00
|
|
|
guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
|
2019-06-17 02:39:46 +00:00
|
|
|
let sourceViews = status.attachments.map(attachmentsView.getAttachmentView(for:))
|
2019-07-28 02:45:11 +00:00
|
|
|
delegate?.showGallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index)
|
2018-09-02 20:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
2018-10-12 01:20:58 +00:00
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
extension BaseStatusTableViewCell: MenuPreviewProvider {
|
2019-12-14 18:36:05 +00:00
|
|
|
var navigationDelegate: TuskerNavigationDelegate? { return delegate }
|
|
|
|
|
2019-06-04 21:04:37 +00:00
|
|
|
func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? {
|
2020-01-05 20:25:07 +00:00
|
|
|
guard let mastodonController = mastodonController else { return nil }
|
2018-10-12 01:20:58 +00:00
|
|
|
if avatarImageView.frame.contains(location) {
|
2020-01-18 02:29:53 +00:00
|
|
|
return (
|
2020-01-18 23:56:36 +00:00
|
|
|
content: { ProfileTableViewController(accountID: self.accountID, mastodonController: mastodonController) },
|
2020-01-18 02:29:53 +00:00
|
|
|
actions: { self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) }
|
|
|
|
)
|
2018-10-12 01:20:58 +00:00
|
|
|
} else if attachmentsView.frame.contains(location) {
|
|
|
|
let attachmentsViewLocation = attachmentsView.convert(location, from: self)
|
2020-02-29 00:47:38 +00:00
|
|
|
if let attachmentView = attachmentsView.attachmentViews.allObjects.first(where: { $0.frame.contains(attachmentsViewLocation) }) {
|
|
|
|
return (
|
|
|
|
content: {
|
|
|
|
let attachments = self.attachmentsView.attachments!
|
|
|
|
let sourceViews = attachments.map(self.attachmentsView.getAttachmentView(for:))
|
|
|
|
let startIndex = sourceViews.firstIndex(of: attachmentView)!
|
|
|
|
return self.delegate?.gallery(attachments: attachments, sourceViews: sourceViews, startIndex: startIndex)
|
|
|
|
},
|
|
|
|
actions: { [] }
|
|
|
|
)
|
2018-10-12 01:20:58 +00:00
|
|
|
}
|
2020-03-03 03:31:37 +00:00
|
|
|
}
|
2019-11-19 17:08:11 +00:00
|
|
|
return self.getStatusCellPreviewProviders(for: location, sourceViewController: sourceViewController)
|
2018-10-12 01:20:58 +00:00
|
|
|
}
|
|
|
|
}
|