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-06-17 03:00:39 +00:00
|
|
|
@IBOutlet weak var visibilityImageView: UIImageView!
|
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?
|
|
|
|
|
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
|
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
|
|
|
|
|
2020-07-06 03:00:57 +00:00
|
|
|
#if SDK_IOS_14
|
2020-06-27 17:13:04 +00:00
|
|
|
if #available(iOS 14.0, *) {
|
|
|
|
moreButton.showsMenuAsPrimaryAction = true
|
|
|
|
}
|
2020-07-06 03:00:57 +00:00
|
|
|
#endif
|
2020-06-27 17:13:04 +00:00
|
|
|
|
2020-06-16 03:22:34 +00:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
|
2020-01-06 00:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open func createObserversIfNecessary() {
|
2020-05-02 16:45:28 +00:00
|
|
|
if statusUpdater == nil {
|
|
|
|
statusUpdater = mastodonController.persistentContainer.statusSubject
|
|
|
|
.filter { [unowned self] in $0 == self.statusID }
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { [unowned self] in
|
2020-08-15 21:37:56 +00:00
|
|
|
if let mastodonController = mastodonController,
|
|
|
|
let status = mastodonController.persistentContainer.status(for: $0) {
|
2020-05-02 16:45:28 +00:00
|
|
|
self.updateStatusState(status: status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if accountUpdater == nil {
|
|
|
|
accountUpdater = mastodonController.persistentContainer.accountSubject
|
|
|
|
.filter { [unowned self] in $0 == self.accountID }
|
|
|
|
.receive(on: DispatchQueue.main)
|
|
|
|
.sink { [unowned self] in
|
2020-08-15 21:37:56 +00:00
|
|
|
if let mastodonController = mastodonController,
|
|
|
|
let account = mastodonController.persistentContainer.account(for: $0) {
|
2020-05-02 16:45:28 +00:00
|
|
|
self.updateUI(account: 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) {
|
2020-01-06 00:54:28 +00:00
|
|
|
createObserversIfNecessary()
|
|
|
|
|
2020-04-12 16:54:27 +00:00
|
|
|
guard let status = mastodonController.persistentContainer.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)
|
2020-06-16 03:22:34 +00:00
|
|
|
updateUIForPreferences(account: account)
|
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-06-16 03:22:34 +00:00
|
|
|
contentTextView.setTextFrom(status: status)
|
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
|
|
|
|
2020-06-17 02:47:30 +00:00
|
|
|
let reblogDisabled: Bool
|
2020-06-24 20:41:01 +00:00
|
|
|
switch mastodonController.instance?.instanceType {
|
|
|
|
case nil:
|
|
|
|
// todo: this handle a race condition in instance public timelines
|
|
|
|
// a somewhat better solution would be waiting to load the timeline until after the instance is loaded
|
|
|
|
reblogDisabled = true
|
2020-06-17 02:47:30 +00:00
|
|
|
case .mastodon:
|
|
|
|
reblogDisabled = status.visibility == .private || status.visibility == .direct
|
|
|
|
case .pleroma:
|
|
|
|
// Pleroma allows 'Boost to original audience' for your own private posts
|
|
|
|
reblogDisabled = status.visibility == .direct || (status.visibility == .private && status.account.id != mastodonController.account.id)
|
|
|
|
}
|
|
|
|
reblogButton.isEnabled = !reblogDisabled
|
2020-06-17 22:00:13 +00:00
|
|
|
|
|
|
|
updateStatusIconsForPreferences(status)
|
2020-06-17 02:47:30 +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
|
|
|
}
|
|
|
|
|
2020-04-12 16:54:27 +00:00
|
|
|
func updateStatusState(status: StatusMO) {
|
|
|
|
favorited = status.favourited
|
|
|
|
reblogged = status.reblogged
|
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")
|
|
|
|
}
|
2020-06-27 17:13:04 +00:00
|
|
|
|
2020-07-06 03:00:57 +00:00
|
|
|
#if SDK_IOS_14
|
2020-06-27 17:13:04 +00:00
|
|
|
if #available(iOS 14.0, *) {
|
|
|
|
// keep menu in sync with changed states e.g. bookmarked, muted
|
|
|
|
moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: actionsForStatus(statusID: statusID, sourceView: moreButton))
|
|
|
|
}
|
2020-07-06 03:00:57 +00:00
|
|
|
#endif
|
2019-08-02 03:01:15 +00:00
|
|
|
}
|
|
|
|
|
2020-04-12 16:54:27 +00:00
|
|
|
func updateUI(account: AccountMO) {
|
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
|
2018-09-11 14:52:21 +00:00
|
|
|
DispatchQueue.main.async {
|
2020-04-12 16:54:27 +00:00
|
|
|
guard let self = self, let data = data, self.accountID == account.id else { return }
|
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
|
|
|
|
2020-06-16 03:22:34 +00:00
|
|
|
@objc func preferencesChanged() {
|
2020-06-17 22:00:13 +00:00
|
|
|
guard let mastodonController = mastodonController,
|
|
|
|
let account = mastodonController.persistentContainer.account(for: accountID),
|
|
|
|
let status = mastodonController.persistentContainer.status(for: statusID) else { return }
|
2020-06-16 03:22:34 +00:00
|
|
|
updateUIForPreferences(account: account)
|
2020-06-17 22:00:13 +00:00
|
|
|
updateStatusIconsForPreferences(status)
|
2020-06-16 03:22:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func updateUIForPreferences(account: AccountMO) {
|
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-04-12 16:54:27 +00:00
|
|
|
attachmentsView.contentHidden = Preferences.shared.blurAllMedia || (mastodonController.persistentContainer.status(for: statusID)?.sensitive ?? false)
|
2019-08-03 00:05:47 +00:00
|
|
|
}
|
2018-08-21 23:23:27 +00:00
|
|
|
|
2020-06-17 22:00:13 +00:00
|
|
|
func updateStatusIconsForPreferences(_ status: StatusMO) {
|
|
|
|
visibilityImageView.isHidden = !Preferences.shared.alwaysShowStatusVisibilityIcon
|
|
|
|
if Preferences.shared.alwaysShowStatusVisibilityIcon {
|
|
|
|
visibilityImageView.image = UIImage(systemName: status.visibility.unfilledImageName)
|
|
|
|
visibilityImageView.accessibilityLabel = String(format: NSLocalizedString("Visibility: %@", comment: "status visibility indicator accessibility label"), status.visibility.displayName)
|
|
|
|
}
|
|
|
|
let reblogButtonImage: UIImage
|
|
|
|
if Preferences.shared.alwaysShowStatusVisibilityIcon || reblogButton.isEnabled {
|
|
|
|
reblogButtonImage = UIImage(systemName: "repeat")!
|
|
|
|
} else {
|
|
|
|
reblogButtonImage = UIImage(systemName: status.visibility.imageName)!
|
|
|
|
}
|
|
|
|
reblogButton.setImage(reblogButtonImage, for: .normal)
|
|
|
|
}
|
|
|
|
|
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() {
|
2020-08-31 23:28:50 +00:00
|
|
|
delegate?.compose(inReplyToID: statusID)
|
2018-08-31 02:30:19 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 17:08:11 +00:00
|
|
|
@IBAction func favoritePressed() {
|
2020-05-02 23:52:35 +00:00
|
|
|
guard let status = mastodonController.persistentContainer.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
|
|
|
|
|
2020-05-02 23:52:35 +00:00
|
|
|
let realStatus = status.reblog ?? status
|
2020-04-27 23:32:16 +00:00
|
|
|
let request = (favorited ? Status.favourite : Status.unfavourite)(realStatus.id)
|
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 {
|
2020-05-11 21:57:50 +00:00
|
|
|
self.favorited = newStatus.favourited ?? false
|
2020-05-02 23:52:35 +00:00
|
|
|
self.mastodonController.persistentContainer.addOrUpdate(status: newStatus, incrementReferenceCount: false)
|
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-05-02 23:52:35 +00:00
|
|
|
guard let status = mastodonController.persistentContainer.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
|
|
|
|
|
2020-05-02 23:52:35 +00:00
|
|
|
let realStatus = status.reblog ?? status
|
2020-04-27 23:32:16 +00:00
|
|
|
let request = (reblogged ? Status.reblog : Status.unreblog)(realStatus.id)
|
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 {
|
2020-05-11 21:57:50 +00:00
|
|
|
self.reblogged = newStatus.reblogged ?? false
|
2020-05-02 23:52:35 +00:00
|
|
|
self.mastodonController.persistentContainer.addOrUpdate(status: newStatus, incrementReferenceCount: false)
|
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 {
|
2020-03-21 02:48:28 +00:00
|
|
|
func attachmentViewGallery(startingAt index: Int) -> UIViewController {
|
2020-04-12 16:54:27 +00:00
|
|
|
guard let status = mastodonController.persistentContainer.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:))
|
2020-03-21 02:48:28 +00:00
|
|
|
return delegate!.gallery(attachments: status.attachments, sourceViews: sourceViews, startIndex: index)
|
|
|
|
}
|
|
|
|
|
|
|
|
func attachmentViewPresent(_ vc: UIViewController, animated: Bool) {
|
|
|
|
delegate?.show(vc)
|
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-07-05 20:17:56 +00:00
|
|
|
content: { ProfileViewController(accountID: self.accountID, mastodonController: mastodonController) },
|
2020-01-18 02:29:53 +00:00
|
|
|
actions: { self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) }
|
|
|
|
)
|
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
|
|
|
}
|
|
|
|
}
|