forked from shadowfacts/Tusker
Shadowfacts
b47b08fa95
Also, copy the state between screens, so e.g. expanding a status in the timeline and then opening that conversation already has that status expanded. This intentionally doesn't store the sensitive attachment visibility state, since showing text when not necessary is less dangerous than for images. (Possibly a preference for this in the future?) Closes #55
88 lines
3.4 KiB
Swift
88 lines
3.4 KiB
Swift
//
|
|
// ConversationMainStatusTableViewCell.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 8/28/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import Combine
|
|
import Pachyderm
|
|
|
|
class ConversationMainStatusTableViewCell: BaseStatusTableViewCell {
|
|
|
|
static let dateFormatter: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .medium
|
|
formatter.timeStyle = .medium
|
|
return formatter
|
|
}()
|
|
|
|
|
|
@IBOutlet weak var profileDetailContainerView: UIView!
|
|
@IBOutlet weak var favoriteAndReblogCountStackView: UIStackView!
|
|
@IBOutlet weak var totalFavoritesButton: UIButton!
|
|
@IBOutlet weak var totalReblogsButton: UIButton!
|
|
@IBOutlet weak var timestampAndClientLabel: UILabel!
|
|
|
|
var profileAccessibilityElement: UIAccessibilityElement!
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
|
|
profileAccessibilityElement = UIAccessibilityElement(accessibilityContainer: self)
|
|
profileAccessibilityElement.accessibilityFrameInContainerSpace = profileDetailContainerView.convert(profileDetailContainerView.frame, to: self)
|
|
accessibilityElements = [profileAccessibilityElement!, contentWarningLabel!, collapseButton!, contentLabel!, totalFavoritesButton!, totalReblogsButton!, timestampAndClientLabel!, replyButton!, favoriteButton!, reblogButton!, moreButton!]
|
|
}
|
|
|
|
override func updateUI(statusID: String, state: StatusState) {
|
|
super.updateUI(statusID: statusID, state: state)
|
|
guard let status = MastodonCache.status(for: statusID) else { fatalError() }
|
|
|
|
var timestampAndClientText = ConversationMainStatusTableViewCell.dateFormatter.string(from: status.createdAt)
|
|
if let application = status.application {
|
|
timestampAndClientText += " • \(application.name)"
|
|
}
|
|
timestampAndClientLabel.text = timestampAndClientText
|
|
}
|
|
|
|
override func updateStatusState(status: Status) {
|
|
super.updateStatusState(status: status)
|
|
|
|
// todo: localize me
|
|
totalFavoritesButton.setTitle("\(status.favouritesCount) Favorite\(status.favouritesCount == 1 ? "" : "s")", for: .normal)
|
|
totalReblogsButton.setTitle("\(status.reblogsCount) Reblog\(status.reblogsCount == 1 ? "" : "s")", for: .normal)
|
|
}
|
|
|
|
override func updateUI(account: Account) {
|
|
super.updateUI(account: account)
|
|
|
|
profileAccessibilityElement.accessibilityLabel = account.realDisplayName
|
|
}
|
|
|
|
@objc override func updateUIForPreferences() {
|
|
super.updateUIForPreferences()
|
|
|
|
favoriteAndReblogCountStackView.isHidden = !Preferences.shared.showFavoriteAndReblogCounts
|
|
}
|
|
|
|
@IBAction func totalFavoritesPressed() {
|
|
if let delegate = delegate {
|
|
// accounts aren't known, pass nil so the VC will load them
|
|
let vc = delegate.statusActionAccountList(action: .favorite, statusID: statusID, statusState: statusState.copy(), accountIDs: nil)
|
|
vc.showInacurateCountWarning = true
|
|
delegate.show(vc)
|
|
}
|
|
}
|
|
|
|
@IBAction func totalReblogsPressed() {
|
|
if let delegate = delegate {
|
|
// accounts aren't known, pass nil so the VC will load them
|
|
let vc = delegate.statusActionAccountList(action: .reblog, statusID: statusID, statusState: statusState.copy(), accountIDs: nil)
|
|
vc.showInacurateCountWarning = true
|
|
delegate.show(vc)
|
|
}
|
|
}
|
|
}
|