Prevent redundant status database lookups

This commit is contained in:
Shadowfacts 2020-06-15 23:22:34 -04:00
parent d27bddb2ca
commit 5d751cd994
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 21 additions and 21 deletions

View File

@ -43,7 +43,7 @@ class ComposeStatusReplyView: UIView {
displayNameLabel.updateForAccountDisplayName(account: status.account)
usernameLabel.text = "@\(status.account.acct)"
statusContentTextView.overrideMastodonController = mastodonController
statusContentTextView.statusID = status.id
statusContentTextView.setTextFrom(status: status)
avatarRequest = ImageCache.avatars.get(status.account.avatar) { [weak self] (data) in
guard let self = self, let data = data else { return }

View File

@ -86,7 +86,7 @@ class BaseStatusTableViewCell: UITableViewCell {
accessibilityElements = [displayNameLabel!, contentWarningLabel!, collapseButton!, contentTextView!, attachmentsView!]
attachmentsView.isAccessibilityElement = true
NotificationCenter.default.addObserver(self, selector: #selector(updateUIForPreferences), name: .preferencesChanged, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(preferencesChanged), name: .preferencesChanged, object: nil)
}
open func createObserversIfNecessary() {
@ -125,8 +125,7 @@ class BaseStatusTableViewCell: UITableViewCell {
let account = status.account
self.accountID = account.id
updateUI(account: account)
updateUIForPreferences()
updateUIForPreferences(account: account)
attachmentsView.updateUI(status: status)
attachmentsView.isAccessibilityElement = status.attachments.count > 0
@ -134,7 +133,7 @@ class BaseStatusTableViewCell: UITableViewCell {
updateStatusState(status: status)
contentTextView.statusID = statusID
contentTextView.setTextFrom(status: status)
contentWarningLabel.text = status.spoilerText
contentWarningLabel.isHidden = status.spoilerText.isEmpty
@ -191,8 +190,12 @@ class BaseStatusTableViewCell: UITableViewCell {
}
}
@objc func updateUIForPreferences() {
@objc func preferencesChanged() {
guard let mastodonController = mastodonController, let account = mastodonController.persistentContainer.account(for: accountID) else { return }
updateUIForPreferences(account: account)
}
func updateUIForPreferences(account: AccountMO) {
avatarImageView.layer.cornerRadius = Preferences.shared.avatarStyle.cornerRadius(for: avatarImageView)
displayNameLabel.updateForAccountDisplayName(account: account)
attachmentsView.contentHidden = Preferences.shared.blurAllMedia || (mastodonController.persistentContainer.status(for: statusID)?.sensitive ?? false)

View File

@ -63,8 +63,8 @@ class ConversationMainStatusTableViewCell: BaseStatusTableViewCell {
profileAccessibilityElement.accessibilityLabel = account.displayNameWithoutCustomEmoji
}
@objc override func updateUIForPreferences() {
super.updateUIForPreferences()
override func updateUIForPreferences(account: AccountMO) {
super.updateUIForPreferences(account: account)
favoriteAndReblogCountStackView.isHidden = !Preferences.shared.showFavoriteAndReblogCounts
}

View File

@ -69,6 +69,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
status = rebloggedStatus
realStatusID = rebloggedStatus.id
reblogLabel.isHidden = false
updateRebloggerLabel(reblogger: status.account)
} else {
reblogStatusID = nil
rebloggerID = nil
@ -85,8 +86,8 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
timestampLabel.isHidden = !pinImageView.isHidden
}
@objc override func updateUIForPreferences() {
super.updateUIForPreferences()
@objc override func preferencesChanged() {
super.preferencesChanged()
if let rebloggerID = rebloggerID,
let reblogger = mastodonController.persistentContainer.account(for: rebloggerID) {
updateRebloggerLabel(reblogger: reblogger)

View File

@ -11,16 +11,12 @@ import Pachyderm
class StatusContentTextView: ContentTextView {
var statusID: String? {
didSet {
guard let statusID = statusID else { return }
guard let mastodonController = mastodonController,
let status = mastodonController.persistentContainer.status(for: statusID) else {
fatalError("Can't set StatusContentTextView text without cached status for \(statusID)")
}
setTextFromHtml(status.content)
setEmojis(status.emojis)
}
private var statusID: String?
func setTextFrom(status: StatusMO) {
statusID = status.id
setTextFromHtml(status.content)
setEmojis(status.emojis)
}
override func getMention(for url: URL, text: String) -> Mention? {