Skip to content

Commit e764d5a

Browse files
committed
Use the websiteName in the card when available
1 parent 9699e93 commit e764d5a

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

MastodonSDK/Sources/CoreDataStack/Entity/Mastodon/Card.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ public final class Card: NSManagedObject {
5656
@NSManaged public private(set) var status: Status
5757
}
5858

59+
extension Card {
60+
public var websiteName: String? {
61+
if let authorName, !authorName.isEmpty {
62+
return authorName
63+
} else if let host = url?.host {
64+
return host
65+
}
66+
return nil
67+
}
68+
}
69+
5970
extension Card {
6071

6172
@discardableResult

MastodonSDK/Sources/MastodonUI/View/Content/StatusCardControl.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public final class StatusCardControl: UIControl {
3131
private let dividerView = UIView()
3232
private let imageView = UIImageView()
3333
private let titleLabel = UILabel()
34-
private let linkLabel = UILabel()
34+
private let siteNameLabel = UILabel()
3535
private lazy var showEmbedButton: UIButton = {
3636
var configuration = UIButton.Configuration.gray()
3737
configuration.background.visualEffect = UIBlurEffect(style: .systemUltraThinMaterial)
@@ -87,9 +87,9 @@ public final class StatusCardControl: UIControl {
8787
titleLabel.textColor = Asset.Colors.Label.primary.color
8888
titleLabel.font = .preferredFont(forTextStyle: .body)
8989

90-
linkLabel.numberOfLines = 1
91-
linkLabel.textColor = Asset.Colors.Label.secondary.color
92-
linkLabel.font = .preferredFont(forTextStyle: .subheadline)
90+
siteNameLabel.numberOfLines = 1
91+
siteNameLabel.textColor = Asset.Colors.Label.secondary.color
92+
siteNameLabel.font = .preferredFont(forTextStyle: .subheadline)
9393

9494
imageView.tintColor = Asset.Colors.Label.secondary.color
9595
imageView.contentMode = .scaleAspectFill
@@ -100,7 +100,7 @@ public final class StatusCardControl: UIControl {
100100
imageView.setContentCompressionResistancePriority(.zero, for: .vertical)
101101

102102
labelStackView.addArrangedSubview(titleLabel)
103-
labelStackView.addArrangedSubview(linkLabel)
103+
labelStackView.addArrangedSubview(siteNameLabel)
104104
labelStackView.layoutMargins = .init(top: 10, left: 10, bottom: 10, right: 10)
105105
labelStackView.isLayoutMarginsRelativeArrangement = true
106106
labelStackView.axis = .vertical
@@ -139,14 +139,14 @@ public final class StatusCardControl: UIControl {
139139

140140
public func configure(card: Card) {
141141
let title = card.title.trimmingCharacters(in: .whitespacesAndNewlines)
142-
if let host = card.url?.host {
143-
accessibilityLabel = "\(title) \(host)"
142+
if let websiteName = card.websiteName {
143+
accessibilityLabel = "\(title) \(websiteName)"
144144
} else {
145145
accessibilityLabel = title
146146
}
147147

148148
titleLabel.text = title
149-
linkLabel.text = card.url?.host
149+
siteNameLabel.text = card.websiteName
150150
imageView.contentMode = .center
151151

152152
imageView.sd_setImage(

0 commit comments

Comments
 (0)