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
|
|
|
|
2018-10-12 01:20:58 +00:00
|
|
|
var delegate: StatusTableViewCellDelegate? {
|
|
|
|
didSet {
|
|
|
|
contentLabel.navigationDelegate = delegate
|
|
|
|
}
|
|
|
|
}
|
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!
|
2018-08-17 02:39:16 +00:00
|
|
|
@IBOutlet weak var displayNameLabel: UILabel!
|
|
|
|
@IBOutlet weak var usernameLabel: UILabel!
|
2019-09-09 22:40:23 +00:00
|
|
|
@IBOutlet weak var contentWarningLabel: UILabel!
|
|
|
|
@IBOutlet weak var collapseButton: UIButton!
|
2018-08-26 18:49:22 +00:00
|
|
|
@IBOutlet weak var contentLabel: StatusContentLabel!
|
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
|
|
|
|
|
2018-08-21 23:23:27 +00:00
|
|
|
var avatarURL: URL?
|
2018-09-02 20:59:20 +00:00
|
|
|
var attachmentDataTasks: [URLSessionDataTask] = []
|
|
|
|
|
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
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentLabel!, 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)
|
|
|
|
|
2019-08-02 03:01:15 +00:00
|
|
|
statusUpdater = MastodonCache.statusSubject
|
2019-09-05 18:24:13 +00:00
|
|
|
.filter { $0.id == self.statusID }
|
2019-08-02 03:01:15 +00:00
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink(receiveValue: updateStatusState(status:))
|
|
|
|
|
|
|
|
accountUpdater = MastodonCache.accountSubject
|
|
|
|
.filter { $0.id == self.accountID }
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink(receiveValue: updateUI(account:))
|
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) {
|
2019-11-19 17:08:11 +00:00
|
|
|
guard let status = MastodonCache.status(for: statusID) else {
|
|
|
|
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)
|
|
|
|
|
|
|
|
contentLabel.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
|
|
|
|
|
2019-11-28 23:36:58 +00:00
|
|
|
if state.unknown {
|
|
|
|
collapsible = !status.spoilerText.isEmpty
|
|
|
|
var shouldCollapse = collapsible
|
|
|
|
if !shouldCollapse,
|
|
|
|
let text = contentLabel.text,
|
|
|
|
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
|
2018-09-11 14:52:21 +00:00
|
|
|
avatarURL = account.avatar
|
2018-11-09 20:48:08 +00:00
|
|
|
ImageCache.avatars.get(account.avatar) { (data) in
|
2019-11-19 17:08:11 +00:00
|
|
|
guard let data = data, self.avatarURL == account.avatar 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-09-11 14:52:21 +00:00
|
|
|
self.avatarURL = nil
|
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() {
|
2019-11-19 17:08:11 +00:00
|
|
|
guard let account = MastodonCache.account(for: accountID) else { return }
|
2019-08-03 00:05:47 +00:00
|
|
|
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
|
|
|
|
displayNameLabel.text = account.realDisplayName
|
|
|
|
}
|
2018-08-21 23:23:27 +00:00
|
|
|
|
|
|
|
override func prepareForReuse() {
|
2019-11-19 17:08:11 +00:00
|
|
|
super.prepareForReuse()
|
|
|
|
|
|
|
|
if let avatarURL = avatarURL {
|
|
|
|
ImageCache.avatars.cancel(avatarURL)
|
2018-08-21 23:23:27 +00:00
|
|
|
}
|
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
|
|
|
|
2019-09-09 22:40:23 +00:00
|
|
|
contentLabel.isHidden = collapsed
|
|
|
|
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() {
|
2018-09-18 16:59:07 +00:00
|
|
|
guard let status = MastodonCache.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
|
|
|
|
MastodonCache.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() {
|
2018-09-18 16:59:07 +00:00
|
|
|
guard let status = MastodonCache.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
|
|
|
|
MastodonCache.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() {
|
2018-09-30 23:29:52 +00:00
|
|
|
delegate?.showMoreOptions(forStatus: statusID)
|
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) {
|
2019-06-15 00:23:03 +00:00
|
|
|
guard let status = MastodonCache.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-05 20:25:07 +00:00
|
|
|
return (content: {
|
|
|
|
ProfileTableViewController(accountID: self.accountID, mastodonController: mastodonController)
|
|
|
|
}, actions: {
|
|
|
|
self.actionsForProfile(accountID: self.accountID)
|
|
|
|
})
|
2018-10-12 01:20:58 +00:00
|
|
|
} else if attachmentsView.frame.contains(location) {
|
|
|
|
let attachmentsViewLocation = attachmentsView.convert(location, from: self)
|
2019-11-19 17:08:11 +00:00
|
|
|
if let attachmentView = attachmentsView.attachmentViews.allObjects.first(where: { $0.frame.contains(attachmentsViewLocation) }),
|
2019-11-17 19:45:38 +00:00
|
|
|
let image = attachmentView.image {
|
2018-10-12 01:20:58 +00:00
|
|
|
let description = attachmentView.attachment.description
|
2019-06-04 21:04:37 +00:00
|
|
|
return (content: { self.delegate?.largeImage(image, description: description, sourceView: attachmentView) }, actions: { [] })
|
2018-10-12 01:20:58 +00:00
|
|
|
}
|
|
|
|
} else if contentLabel.frame.contains(location),
|
2019-06-04 21:04:37 +00:00
|
|
|
let link = contentLabel.getLink(atPoint: contentLabel.convert(location, from: self)) {
|
|
|
|
return (
|
|
|
|
content: { self.contentLabel.getViewController(forLink: link.url, inRange: link.range) },
|
|
|
|
actions: {
|
|
|
|
let text = (self.contentLabel.text! as NSString).substring(with: link.range)
|
|
|
|
if let mention = self.contentLabel.getMention(for: link.url, text: text) {
|
|
|
|
return self.actionsForProfile(accountID: mention.id)
|
|
|
|
} else if let hashtag = self.contentLabel.getHashtag(for: link.url, text: text) {
|
|
|
|
return self.actionsForHashtag(hashtag)
|
|
|
|
} else {
|
|
|
|
return self.actionsForURL(link.url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2018-10-12 01:20:58 +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
|
|
|
}
|
|
|
|
}
|