2018-08-17 02:39:16 +00:00
|
|
|
//
|
|
|
|
// StatusTableViewCell.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/16/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2018-08-17 02:39:16 +00:00
|
|
|
|
2018-09-30 23:29:52 +00:00
|
|
|
protocol StatusTableViewCellDelegate: TuskerNavigationDelegate {
|
2018-08-27 19:23:59 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 23:49:31 +00:00
|
|
|
class StatusTableViewCell: UITableViewCell, PreferencesAdaptive {
|
2018-08-17 02:39:16 +00:00
|
|
|
|
2018-08-27 19:23:59 +00:00
|
|
|
var delegate: StatusTableViewCellDelegate?
|
|
|
|
|
2018-08-17 02:39:16 +00:00
|
|
|
@IBOutlet weak var displayNameLabel: UILabel!
|
|
|
|
@IBOutlet weak var usernameLabel: UILabel!
|
2018-08-26 18:49:22 +00:00
|
|
|
@IBOutlet weak var contentLabel: StatusContentLabel!
|
2018-08-21 23:23:27 +00:00
|
|
|
@IBOutlet weak var avatarImageView: UIImageView!
|
2018-08-29 00:11:31 +00:00
|
|
|
@IBOutlet weak var reblogLabel: UILabel!
|
2018-08-31 17:46:33 +00:00
|
|
|
@IBOutlet weak var timestampLabel: UILabel!
|
2018-09-02 20:59:20 +00:00
|
|
|
@IBOutlet weak var attachmentsView: UIView!
|
2018-09-09 01:35:40 +00:00
|
|
|
@IBOutlet weak var favoriteButton: UIButton!
|
|
|
|
@IBOutlet weak var reblogButton: 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!
|
|
|
|
var rebloggerID: String?
|
2018-08-18 03:09:59 +00:00
|
|
|
|
2018-09-09 01:35:40 +00:00
|
|
|
var favorited: Bool = false {
|
|
|
|
didSet {
|
|
|
|
favoriteButton.tintColor = favorited ? UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) : tintColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var reblogged: Bool = false {
|
|
|
|
didSet {
|
|
|
|
reblogButton.tintColor = reblogged ? UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) : tintColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-21 23:23:27 +00:00
|
|
|
var avatarURL: URL?
|
2018-08-31 17:46:33 +00:00
|
|
|
var updateTimestampWorkItem: DispatchWorkItem?
|
2018-09-02 20:59:20 +00:00
|
|
|
var attachmentDataTasks: [URLSessionDataTask] = []
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
override func awakeFromNib() {
|
|
|
|
displayNameLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
|
|
displayNameLabel.isUserInteractionEnabled = true
|
|
|
|
usernameLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
|
|
usernameLabel.isUserInteractionEnabled = true
|
2018-08-29 00:11:31 +00:00
|
|
|
reblogLabel.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(reblogLabelPressed)))
|
|
|
|
reblogLabel.isUserInteractionEnabled = true
|
2018-08-28 01:27:34 +00:00
|
|
|
avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
|
|
|
|
avatarImageView.isUserInteractionEnabled = true
|
|
|
|
avatarImageView.layer.masksToBounds = true
|
2018-09-02 20:59:20 +00:00
|
|
|
attachmentsView.layer.cornerRadius = 5
|
|
|
|
attachmentsView.layer.masksToBounds = true
|
2018-10-01 19:14:09 +00:00
|
|
|
contentLabel.navigationDelegate = self
|
2018-08-28 01:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 23:49:31 +00:00
|
|
|
func updateUIForPreferences() {
|
2018-09-18 16:59:07 +00:00
|
|
|
guard let account = MastodonCache.account(for: accountID) else { fatalError("") }
|
2018-08-28 23:49:31 +00:00
|
|
|
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
|
2018-09-18 16:59:07 +00:00
|
|
|
if let rebloggerID = rebloggerID,
|
|
|
|
let reblogger = MastodonCache.account(for: rebloggerID) {
|
2018-08-29 01:18:58 +00:00
|
|
|
reblogLabel.text = "Reblogged by \(reblogger.realDisplayName)"
|
|
|
|
}
|
|
|
|
displayNameLabel.text = account.realDisplayName
|
2018-08-28 23:49:31 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 01:57:46 +00:00
|
|
|
func updateUI(for statusID: String) {
|
|
|
|
self.statusID = statusID
|
2018-09-18 16:59:07 +00:00
|
|
|
guard let status = MastodonCache.status(for: statusID) else { fatalError("Missing cached status \(statusID)") }
|
2018-08-18 03:09:59 +00:00
|
|
|
|
|
|
|
let account: Account
|
|
|
|
if let reblog = status.reblog {
|
|
|
|
account = reblog.account
|
2018-09-18 16:59:07 +00:00
|
|
|
rebloggerID = status.account.id
|
2018-08-29 00:11:31 +00:00
|
|
|
reblogLabel.isHidden = false
|
2018-08-18 03:09:59 +00:00
|
|
|
} else {
|
|
|
|
account = status.account
|
2018-08-29 00:11:31 +00:00
|
|
|
reblogLabel.isHidden = true
|
2018-09-18 16:59:07 +00:00
|
|
|
rebloggerID = nil
|
2018-08-18 03:09:59 +00:00
|
|
|
}
|
2018-09-18 16:59:07 +00:00
|
|
|
self.accountID = account.id
|
2018-08-28 01:27:34 +00:00
|
|
|
|
2018-08-28 23:49:31 +00:00
|
|
|
|
|
|
|
updateUIForPreferences()
|
|
|
|
|
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-10-02 17:42:37 +00:00
|
|
|
ImageCache.avatars.get(account.avatar) { (image) in
|
2018-09-11 14:52:21 +00:00
|
|
|
DispatchQueue.main.async {
|
|
|
|
self.avatarImageView.image = image
|
|
|
|
self.avatarURL = nil
|
2018-08-21 23:23:27 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-31 17:46:33 +00:00
|
|
|
updateTimestamp()
|
2018-08-21 23:23:27 +00:00
|
|
|
|
2018-09-11 14:52:21 +00:00
|
|
|
let attachments = status.attachments.filter({ $0.kind == .image })
|
2018-09-02 20:59:20 +00:00
|
|
|
if attachments.count > 0 {
|
|
|
|
attachmentsView.isHidden = false
|
|
|
|
let width = attachmentsView.bounds.width
|
|
|
|
let height: CGFloat = 200
|
|
|
|
switch attachments.count {
|
|
|
|
case 1:
|
|
|
|
addAttachmentView(frame: CGRect(x: 0, y: 0, width: width, height: height), attachment: attachments[0])
|
|
|
|
case 2:
|
|
|
|
addAttachmentView(frame: CGRect(x: 0, y: 0, width: width / 2 - 4, height: height), attachment: attachments[0])
|
|
|
|
addAttachmentView(frame: CGRect(x: width / 2 + 4, y: 0, width: width / 2 - 4, height: height), attachment: attachments[1])
|
|
|
|
case 3:
|
|
|
|
addAttachmentView(frame: CGRect(x: 0, y: 0, width: width / 2 - 4, height: height), attachment: attachments[0])
|
|
|
|
addAttachmentView(frame: CGRect(x: width / 2 + 4, y: 0, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[1])
|
|
|
|
addAttachmentView(frame: CGRect(x: width / 2 + 4, y: height / 2 + 4, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[2])
|
|
|
|
case 4:
|
|
|
|
addAttachmentView(frame: CGRect(x: 0, y: 0, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[0])
|
|
|
|
addAttachmentView(frame: CGRect(x: 0, y: height / 2 + 4, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[1])
|
|
|
|
addAttachmentView(frame: CGRect(x: width / 2 + 4, y: 0, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[2])
|
|
|
|
addAttachmentView(frame: CGRect(x: width / 2 + 4, y: height / 2 + 4, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[3])
|
|
|
|
default:
|
|
|
|
fatalError("Too many attachments")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
attachmentsView.isHidden = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-09 01:35:40 +00:00
|
|
|
let realStatus = status.reblog ?? status
|
|
|
|
favorited = realStatus.favourited ?? false
|
|
|
|
reblogged = realStatus.reblogged ?? false
|
|
|
|
|
2018-09-18 01:57:46 +00:00
|
|
|
contentLabel.statusID = statusID
|
2018-08-18 03:09:59 +00:00
|
|
|
}
|
2018-08-21 23:23:27 +00:00
|
|
|
|
2018-08-31 17:46:33 +00:00
|
|
|
func updateTimestamp() {
|
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-08-31 17:46:33 +00:00
|
|
|
timestampLabel.text = status.createdAt.timeAgoString()
|
|
|
|
let delay: DispatchTimeInterval?
|
|
|
|
switch status.createdAt.timeAgo().1 {
|
|
|
|
case .second:
|
|
|
|
delay = .seconds(10)
|
|
|
|
case .minute:
|
|
|
|
delay = .seconds(60)
|
|
|
|
default:
|
|
|
|
delay = nil
|
|
|
|
}
|
|
|
|
if let delay = delay {
|
|
|
|
updateTimestampWorkItem = DispatchWorkItem {
|
|
|
|
self.updateTimestamp()
|
|
|
|
}
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + delay, execute: updateTimestampWorkItem!)
|
|
|
|
} else {
|
|
|
|
updateTimestampWorkItem = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-02 20:59:20 +00:00
|
|
|
func addAttachmentView(frame: CGRect, attachment: Attachment) {
|
|
|
|
let attachmentView = AttachmentView(frame: frame, attachment: attachment)
|
|
|
|
attachmentView.delegate = self
|
|
|
|
attachmentsView.addSubview(attachmentView)
|
|
|
|
}
|
|
|
|
|
2018-08-21 23:23:27 +00:00
|
|
|
override func prepareForReuse() {
|
|
|
|
if let url = avatarURL {
|
2018-10-02 17:42:37 +00:00
|
|
|
ImageCache.avatars.cancel(url)
|
2018-08-21 23:23:27 +00:00
|
|
|
}
|
2018-08-31 17:46:33 +00:00
|
|
|
updateTimestampWorkItem?.cancel()
|
|
|
|
updateTimestampWorkItem = nil
|
2018-09-02 20:59:20 +00:00
|
|
|
attachmentsView.subviews.forEach { view in
|
|
|
|
(view as? AttachmentView)?.task?.cancel()
|
2018-09-03 20:54:03 +00:00
|
|
|
view.removeFromSuperview()
|
2018-09-02 20:59:20 +00:00
|
|
|
}
|
2018-08-21 23:23:27 +00:00
|
|
|
}
|
2018-08-17 02:39:16 +00:00
|
|
|
|
2018-09-03 20:54:03 +00:00
|
|
|
override func setSelected(_ selected: Bool, animated: Bool) {
|
|
|
|
super.setSelected(selected, animated: animated)
|
|
|
|
|
|
|
|
if selected {
|
2018-09-18 01:57:46 +00:00
|
|
|
delegate?.selected(status: statusID)
|
2018-09-03 20:54:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 02:30:19 +00:00
|
|
|
@IBAction func replyPressed(_ sender: Any) {
|
2018-09-18 01:57:46 +00:00
|
|
|
delegate?.reply(to: statusID)
|
2018-08-31 02:30:19 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 01:27:34 +00:00
|
|
|
@objc func accountPressed() {
|
2018-09-18 16:59:07 +00:00
|
|
|
delegate?.selected(account: accountID)
|
2018-08-28 01:27:34 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 00:11:31 +00:00
|
|
|
@objc func reblogLabelPressed() {
|
2018-09-18 16:59:07 +00:00
|
|
|
guard let rebloggerID = rebloggerID else { return }
|
|
|
|
delegate?.selected(account: rebloggerID)
|
2018-08-29 00:11:31 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 01:35:40 +00:00
|
|
|
@IBAction func favoritePressed(_ sender: Any) {
|
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)
|
|
|
|
MastodonController.shared.client.run(request) { response in
|
2018-09-09 01:35:40 +00:00
|
|
|
DispatchQueue.main.async {
|
2018-09-15 17:01:13 +00:00
|
|
|
self.favorited = realStatus.favourited ?? false
|
2018-09-11 14:52:21 +00:00
|
|
|
if case .success = response {
|
2018-09-17 23:22:37 +00:00
|
|
|
self.favorited = realStatus.favourited ?? 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func reblogPressed(_ sender: Any) {
|
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)
|
|
|
|
MastodonController.shared.client.run(request) { response in
|
2018-09-11 14:52:21 +00:00
|
|
|
self.reblogged = realStatus.reblogged ?? false
|
2018-09-09 01:35:40 +00:00
|
|
|
DispatchQueue.main.async {
|
2018-09-11 14:52:21 +00:00
|
|
|
if case .success = response {
|
2018-09-18 01:57:46 +00:00
|
|
|
self.reblogged = realStatus.reblogged ?? 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-11 22:17:48 +00:00
|
|
|
@IBAction func morePressed(_ sender: Any) {
|
2018-09-30 23:29:52 +00:00
|
|
|
delegate?.showMoreOptions(forStatus: statusID)
|
2018-09-11 22:17:48 +00:00
|
|
|
}
|
|
|
|
|
2018-08-17 02:39:16 +00:00
|
|
|
}
|
2018-08-27 16:40:22 +00:00
|
|
|
|
2018-09-15 17:01:13 +00:00
|
|
|
extension StatusTableViewCell: TableViewSwipeActionProvider {
|
|
|
|
|
|
|
|
static var favoriteActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 137/131, height: 30)).image { _ in
|
|
|
|
UIImage(named: "Favorite")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 137/131, height: 30))
|
|
|
|
}
|
|
|
|
static var reblogActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 927/558, height: 30)).image { _ in
|
|
|
|
UIImage(named: "Reblog")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 927/558, height: 30))
|
|
|
|
}
|
|
|
|
static var replyActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 205/151, height: 30)).image { _ in
|
|
|
|
UIImage(named: "Reply")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 205/151, height: 30))
|
|
|
|
}
|
|
|
|
static var moreActionImage: UIImage = UIGraphicsImageRenderer(size: CGSize(width: 30 * 2/1, height: 30)).image { _ in
|
|
|
|
UIImage(named: "More")!.draw(in: CGRect(x: 0, y: 0, width: 30 * 2/1, height: 30))
|
|
|
|
}
|
|
|
|
|
|
|
|
func leadingSwipeActionsConfiguration() -> UISwipeActionsConfiguration? {
|
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-15 17:01:13 +00:00
|
|
|
let favoriteTitle: String
|
2018-09-17 23:37:58 +00:00
|
|
|
let favoriteRequest: Request<Status>
|
2018-09-15 17:01:13 +00:00
|
|
|
let favoriteColor: UIColor
|
|
|
|
if status.favourited ?? false {
|
|
|
|
favoriteTitle = "Unfavorite"
|
2018-09-17 23:37:58 +00:00
|
|
|
favoriteRequest = Status.unfavourite(status)
|
2018-09-15 17:01:13 +00:00
|
|
|
favoriteColor = UIColor(displayP3Red: 235/255, green: 77/255, blue: 62/255, alpha: 1)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
favoriteTitle = "Favorite"
|
2018-09-17 23:37:58 +00:00
|
|
|
favoriteRequest = Status.favourite(status)
|
2018-09-15 17:01:13 +00:00
|
|
|
favoriteColor = UIColor(displayP3Red: 1, green: 204/255, blue: 0, alpha: 1)
|
|
|
|
}
|
|
|
|
let favorite = UIContextualAction(style: .normal, title: favoriteTitle) { (action, view, completion) in
|
2018-09-17 23:37:58 +00:00
|
|
|
MastodonController.shared.client.run(favoriteRequest, completion: { response in
|
2018-09-15 17:01:13 +00:00
|
|
|
DispatchQueue.main.async {
|
2018-09-18 01:57:46 +00:00
|
|
|
guard case let .success(status, _) = response else {
|
2018-09-15 17:01:13 +00:00
|
|
|
completion(false)
|
2018-09-18 01:57:46 +00:00
|
|
|
return
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
2018-09-18 01:57:46 +00:00
|
|
|
completion(true)
|
2018-09-18 16:59:07 +00:00
|
|
|
MastodonCache.add(status: status)
|
2018-09-18 01:57:46 +00:00
|
|
|
self.updateUI(for: self.statusID)
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
2018-09-17 23:37:58 +00:00
|
|
|
})
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
|
|
|
favorite.image = StatusTableViewCell.favoriteActionImage
|
|
|
|
favorite.backgroundColor = favoriteColor
|
|
|
|
|
|
|
|
let reblogTitle: String
|
2018-09-17 23:37:58 +00:00
|
|
|
let reblogRequest: Request<Status>
|
2018-09-15 17:01:13 +00:00
|
|
|
let reblogColor: UIColor
|
|
|
|
if status.reblogged ?? false {
|
|
|
|
reblogTitle = "Unreblog"
|
2018-09-17 23:37:58 +00:00
|
|
|
reblogRequest = Status.unreblog(status)
|
2018-09-15 17:01:13 +00:00
|
|
|
reblogColor = UIColor(displayP3Red: 235/255, green: 77/255, blue: 62/255, alpha: 1)
|
|
|
|
} else {
|
|
|
|
reblogTitle = "Reblog"
|
2018-09-17 23:37:58 +00:00
|
|
|
reblogRequest = Status.reblog(status)
|
2018-09-15 17:01:13 +00:00
|
|
|
reblogColor = tintColor
|
|
|
|
}
|
|
|
|
let reblog = UIContextualAction(style: .normal, title: reblogTitle) { (action, view, completion) in
|
2018-09-17 23:37:58 +00:00
|
|
|
MastodonController.shared.client.run(reblogRequest, completion: { response in
|
2018-09-15 17:01:13 +00:00
|
|
|
DispatchQueue.main.async {
|
2018-09-18 01:57:46 +00:00
|
|
|
guard case let .success(status, _) = response else {
|
2018-09-15 17:01:13 +00:00
|
|
|
completion(false)
|
2018-09-18 01:57:46 +00:00
|
|
|
return
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
2018-09-18 01:57:46 +00:00
|
|
|
completion(true)
|
2018-09-18 16:59:07 +00:00
|
|
|
MastodonCache.add(status: status)
|
2018-09-18 01:57:46 +00:00
|
|
|
self.updateUI(for: self.statusID)
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
2018-09-17 23:37:58 +00:00
|
|
|
})
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
|
|
|
reblog.image = StatusTableViewCell.reblogActionImage
|
|
|
|
reblog.backgroundColor = reblogColor
|
|
|
|
|
|
|
|
return UISwipeActionsConfiguration(actions: [favorite, reblog])
|
|
|
|
}
|
|
|
|
|
|
|
|
func trailingSwipeActionsConfiguration() -> UISwipeActionsConfiguration? {
|
|
|
|
let reply = UIContextualAction(style: .normal, title: "Reply") { (action, view, completion) in
|
|
|
|
completion(true)
|
2018-09-18 01:57:46 +00:00
|
|
|
self.delegate?.reply(to: self.statusID)
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
|
|
|
reply.image = StatusTableViewCell.replyActionImage
|
|
|
|
reply.backgroundColor = tintColor
|
|
|
|
let more = UIContextualAction(style: .normal, title: "More") { (action, view, completion) in
|
|
|
|
completion(true)
|
2018-09-30 23:29:52 +00:00
|
|
|
self.delegate?.showMoreOptions(forStatus: self.statusID)
|
2018-09-15 17:01:13 +00:00
|
|
|
}
|
|
|
|
more.image = StatusTableViewCell.moreActionImage
|
|
|
|
more.backgroundColor = .gray
|
|
|
|
return UISwipeActionsConfiguration(actions: [reply, more])
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-01 19:14:09 +00:00
|
|
|
extension StatusTableViewCell: ContentLabelNavigationDelegate {
|
2018-08-27 16:40:22 +00:00
|
|
|
func selected(mention: Mention) {
|
2018-08-27 19:23:59 +00:00
|
|
|
delegate?.selected(mention: mention)
|
2018-08-27 16:40:22 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 14:52:21 +00:00
|
|
|
func selected(tag: Hashtag) {
|
2018-08-27 19:23:59 +00:00
|
|
|
delegate?.selected(tag: tag)
|
2018-08-27 16:40:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func selected(url: URL) {
|
2018-08-27 19:23:59 +00:00
|
|
|
delegate?.selected(url: url)
|
2018-08-27 16:40:22 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-02 20:59:20 +00:00
|
|
|
|
|
|
|
extension StatusTableViewCell: AttachmentViewDelegate {
|
|
|
|
func showLargeAttachment(for attachmentView: AttachmentView) {
|
2018-09-02 22:22:29 +00:00
|
|
|
delegate?.showLargeImage(attachmentView.image!, description: attachmentView.attachment.description, animatingFrom: attachmentView)
|
2018-09-02 20:59:20 +00:00
|
|
|
}
|
|
|
|
}
|