Use account as only existing criterium (IOS-284)

This commit is contained in:
Nathan Mattes 2024-06-30 12:23:33 +02:00
parent a3b4528862
commit 495332e021
2 changed files with 14 additions and 15 deletions

View File

@ -17,7 +17,7 @@ import MastodonSDK
public protocol StatusCardControlDelegate: AnyObject {
func statusCardControl(_ statusCardControl: StatusCardControl, didTapURL url: URL)
func statusCardControl(_ statusCardControl: StatusCardControl, didTapAuthor author: Mastodon.Entity.Card.Author)
func statusCardControl(_ statusCardControl: StatusCardControl, didTapAuthor author: Mastodon.Entity.Account)
func statusCardControlMenu(_ statusCardControl: StatusCardControl) -> [LabeledAction]?
}
@ -67,7 +67,7 @@ public final class StatusCardControl: UIControl {
private var dividerConstraint: NSLayoutConstraint?
private var authorDividerConstraint: NSLayoutConstraint?
private var author: Mastodon.Entity.Card.Author?
private var author: Mastodon.Entity.Account?
private var url: URL?
public override var isHighlighted: Bool {
@ -216,19 +216,22 @@ public final class StatusCardControl: UIControl {
publisherLabel.isHidden = true
}
if let author = card.authors?.first, author.name?.isEmpty == false, author.url?.isEmpty == false {
if let author = card.authors?.first, let account = author.account {
// , , author.url?.isEmpty == false
authorAccountButton.configuration?.title = author.name
authorAccountButton.isHidden = false
authorLabel.isHidden = true
byLabel.isHidden = false
mastodonLogoImageView.isHidden = (author.account == nil)
self.author = author
mastodonLogoImageView.isHidden = false
self.author = account
authorAccountButton.addTarget(self, action: #selector(StatusCardControl.profileTapped(_:)), for: .touchUpInside)
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(StatusCardControl.contentTapped(_:)))
headerContentStackView.addGestureRecognizer(tapGestureRecognizer)
} else {
if let authorName = card.authorName, authorName.isEmpty == false {
if let author = card.authors?.first, let authorName = author.name, authorName.isEmpty == false {
authorLabel.text = "by \(authorName)"
} else if let authorName = card.authorName, authorName.isEmpty == false {
authorLabel.text = "by \(authorName)"
} else {
authorLabel.text = url?.host
@ -362,7 +365,7 @@ public final class StatusCardControl: UIControl {
@objc private func profileTapped(_ sender: UIButton) {
guard let author else { return }
delegate?.statusCardControl(self,didTapAuthor: author)
delegate?.statusCardControl(self, didTapAuthor: author)
}
@objc private func contentTapped(_ sender: Any) {

View File

@ -791,14 +791,10 @@ extension StatusView: MastodonMenuDelegate {
// MARK: StatusCardControlDelegate
extension StatusView: StatusCardControlDelegate {
public func statusCardControl(_ statusCardControl: StatusCardControl, didTapAuthor author: MastodonSDK.Mastodon.Entity.Card.Author) {
if let authorAccount = author.account {
//TODO: Profile to Author-profile
print("Show \(authorAccount.displayName)")
} else if let authorURLString = author.url, let authorURL = URL(string: authorURLString) {
//TODO: Coordinate to url
print("open \(authorURLString)")
}
public func statusCardControl(_ statusCardControl: StatusCardControl, didTapAuthor author: Mastodon.Entity.Account) {
//TODO: Profile to Author-profile
print("Show \(author.displayName)")
}
public func statusCardControl(_ statusCardControl: StatusCardControl, didTapURL url: URL) {