From 8a911f238b9ade018baf9675773b67d79896a8d2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 11 Sep 2022 22:19:54 -0400 Subject: [PATCH] Fix emojis getting set without setting emoji identifier --- .../Explore/FeaturedProfileCollectionViewCell.swift | 2 +- Tusker/Views/BaseEmojiLabel.swift | 1 + Tusker/Views/ContentTextView.swift | 4 ++-- Tusker/Views/EmojiLabel.swift | 8 ++------ Tusker/Views/Profile Header/ProfileHeaderView.swift | 4 ++-- Tusker/Views/StatusContentTextView.swift | 3 +-- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift b/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift index b68c984c..9eaf8df2 100644 --- a/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift +++ b/Tusker/Screens/Explore/FeaturedProfileCollectionViewCell.swift @@ -52,7 +52,7 @@ class FeaturedProfileCollectionViewCell: UICollectionViewCell { displayNameLabel.updateForAccountDisplayName(account: account) noteTextView.setTextFromHtml(account.note) - noteTextView.setEmojis(account.emojis) + noteTextView.setEmojis(account.emojis, identifier: account.id) avatarImageView.image = nil if let avatar = account.avatar { diff --git a/Tusker/Views/BaseEmojiLabel.swift b/Tusker/Views/BaseEmojiLabel.swift index 5bac38a5..2ceb237e 100644 --- a/Tusker/Views/BaseEmojiLabel.swift +++ b/Tusker/Views/BaseEmojiLabel.swift @@ -24,6 +24,7 @@ extension BaseEmojiLabel { // blergh precondition(Thread.isMainThread) + emojiIdentifier = identifier emojiRequests.forEach { $0.cancel() } emojiRequests = [] diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index 16cc458f..a8d44f29 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -57,8 +57,8 @@ class ContentTextView: LinkTextView, BaseEmojiLabel { } // MARK: - Emojis - func setEmojis(_ emojis: [Emoji]) { - replaceEmojis(in: attributedText!, emojis: emojis, identifier: emojiIdentifier) { attributedString, didReplaceEmojis in + func setEmojis(_ emojis: [Emoji], identifier: String?) { + replaceEmojis(in: attributedText!, emojis: emojis, identifier: identifier) { attributedString, didReplaceEmojis in guard didReplaceEmojis else { return } diff --git a/Tusker/Views/EmojiLabel.swift b/Tusker/Views/EmojiLabel.swift index 25f87264..2f13e31e 100644 --- a/Tusker/Views/EmojiLabel.swift +++ b/Tusker/Views/EmojiLabel.swift @@ -21,13 +21,9 @@ class EmojiLabel: UILabel, BaseEmojiLabel { func setEmojis(_ emojis: [Emoji], identifier: String) { guard emojis.count > 0, let attributedText = attributedText else { return } - self.emojiIdentifier = identifier - emojiRequests.forEach { $0.cancel() } - emojiRequests = [] - hasEmojis = true - - replaceEmojis(in: attributedText.string, emojis: emojis, identifier: identifier) { [weak self] (newAttributedText, _) in + replaceEmojis(in: attributedText.string, emojis: emojis, identifier: identifier) { [weak self] (newAttributedText, didReplaceEmojis) in guard let self = self, self.emojiIdentifier == identifier else { return } + self.hasEmojis = didReplaceEmojis self.attributedText = newAttributedText self.setNeedsLayout() self.setNeedsDisplay() diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.swift b/Tusker/Views/Profile Header/ProfileHeaderView.swift index f717b83a..bb223171 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderView.swift @@ -110,7 +110,7 @@ class ProfileHeaderView: UIView { noteTextView.navigationDelegate = delegate noteTextView.setTextFromHtml(account.note) - noteTextView.setEmojis(account.emojis) + noteTextView.setEmojis(account.emojis, identifier: account.id) // don't show relationship label for the user's own account if accountID != mastodonController.account?.id { @@ -148,7 +148,7 @@ class ProfileHeaderView: UIView { valueTextView.isSelectable = false valueTextView.font = .systemFont(ofSize: 17) valueTextView.setTextFromHtml(field.value) - valueTextView.setEmojis(account.emojis) + valueTextView.setEmojis(account.emojis, identifier: account.id) valueTextView.textAlignment = .left valueTextView.awakeFromNib() valueTextView.navigationDelegate = delegate diff --git a/Tusker/Views/StatusContentTextView.swift b/Tusker/Views/StatusContentTextView.swift index 132cbe52..d6eaa204 100644 --- a/Tusker/Views/StatusContentTextView.swift +++ b/Tusker/Views/StatusContentTextView.swift @@ -16,9 +16,8 @@ class StatusContentTextView: ContentTextView { func setTextFrom(status: StatusMO) { statusID = status.id - emojiIdentifier = status.id setTextFromHtml(status.content) - setEmojis(status.emojis) + setEmojis(status.emojis, identifier: status.id) } override func getMention(for url: URL, text: String) -> Mention? {