Compare commits

..

5 Commits

4 changed files with 28 additions and 16 deletions

View File

@ -10,11 +10,12 @@ import Foundation
import Pachyderm
struct InstanceFeatures {
private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; Pleroma (.*)\\)")
private static let pleromaVersionRegex = try! NSRegularExpression(pattern: "\\(compatible; pleroma (.*)\\)", options: .caseInsensitive)
private(set) var instanceType = InstanceType.mastodon
private(set) var version: Version?
private(set) var pleromaVersion: Version?
private(set) var hometownVersion: Version?
private(set) var maxStatusChars = 500
var localOnlyPosts: Bool {
@ -30,7 +31,7 @@ struct InstanceFeatures {
}
var boostToOriginalAudience: Bool {
instanceType == .pleroma || instanceType == .mastodon
instanceType == .pleroma || instanceType.isMastodon
}
var profilePinnedStatuses: Bool {
@ -38,15 +39,15 @@ struct InstanceFeatures {
}
var trends: Bool {
instanceType == .mastodon
instanceType.isMastodon
}
var trendingStatusesAndLinks: Bool {
instanceType == .mastodon && hasVersion(3, 5, 0)
instanceType.isMastodon && hasVersion(3, 5, 0)
}
var reblogVisibility: Bool {
(instanceType == .mastodon && hasVersion(2, 8, 0))
(instanceType.isMastodon && hasVersion(2, 8, 0))
|| (instanceType == .pleroma && hasPleromaVersion(2, 0, 0))
}
@ -55,24 +56,31 @@ struct InstanceFeatures {
}
mutating func update(instance: Instance, nodeInfo: NodeInfo?) {
var version: Version?
let ver = instance.version.lowercased()
if ver.contains("glitch") {
instanceType = .glitch
} else if nodeInfo?.software.name == "hometown" {
instanceType = .hometown
// like "1.0.6+3.5.2"
let parts = ver.split(separator: "+")
if parts.count == 2 {
version = Version(string: String(parts[1]))
hometownVersion = Version(string: String(parts[0]))
}
} else if ver.contains("pleroma") {
instanceType = .pleroma
if let match = InstanceFeatures.pleromaVersionRegex.firstMatch(in: ver, range: NSRange(location: 0, length: ver.utf16.count)) {
pleromaVersion = Version(string: (ver as NSString).substring(with: match.range(at: 1)))
}
} else if ver.contains("pixelfed") {
instanceType = .pixelfed
} else {
instanceType = .mastodon
}
version = Version(string: ver)
if let match = InstanceFeatures.pleromaVersionRegex.firstMatch(in: ver, range: NSRange(location: 0, length: ver.utf16.count)) {
pleromaVersion = Version(string: (ver as NSString).substring(with: match.range(at: 1)))
}
self.version = version ?? Version(string: ver)
maxStatusChars = instance.maxStatusCharacters ?? 500
}

View File

@ -50,7 +50,7 @@ class ReblogService {
}
} else {
image = nil
reblogVisibilityActions = []
reblogVisibilityActions = nil
}
let preview = ConfirmReblogStatusPreviewView(status: status)

View File

@ -76,6 +76,7 @@ class CustomAlertController: UIViewController {
let titleLabel = UILabel()
titleLabel.text = config.title
titleLabel.font = UIFont(descriptor: .preferredFontDescriptor(withTextStyle: .body).withSymbolicTraits(.traitBold)!, size: 0)
titleLabel.adjustsFontForContentSizeCategory = true
titleLabel.numberOfLines = 0
titleLabel.textAlignment = .center
stack.addArrangedSubview(titleLabel)
@ -361,13 +362,14 @@ class CustomAlertActionButton: UIControl {
let label = UILabel()
label.text = title
label.textColor = .tintColor
switch action.style {
case .cancel:
label.adjustsFontForContentSizeCategory = true
if case .cancel = action.style {
label.font = UIFont(descriptor: .preferredFontDescriptor(withTextStyle: .body).withSymbolicTraits(.traitBold)!, size: 0)
case .destructive:
} else {
label.font = .preferredFont(forTextStyle: .body)
}
if case .destructive = action.style {
label.textColor = .systemRed
default:
break
}
titleView.addArrangedSubview(label)
}

View File

@ -55,6 +55,7 @@ class ConfirmReblogStatusPreviewView: UIView {
let displayNameLabel = EmojiLabel()
displayNameLabel.font = UIFont(descriptor: .preferredFontDescriptor(withTextStyle: .caption1).addingAttributes([.traits: [UIFontDescriptor.TraitKey.weight: UIFont.Weight.semibold]]), size: 0)
displayNameLabel.adjustsFontSizeToFitWidth = true
displayNameLabel.adjustsFontForContentSizeCategory = true
displayNameLabel.updateForAccountDisplayName(account: status.account)
vStack.addArrangedSubview(displayNameLabel)
@ -64,6 +65,7 @@ class ConfirmReblogStatusPreviewView: UIView {
contentView.isScrollEnabled = false
contentView.backgroundColor = nil
contentView.textContainerInset = .zero
contentView.adjustsFontForContentSizeCategory = true
// remove the extra line spacing applied by StatusContentTextView because, since we're using a smaller font, the regular 2pt looks big
contentView.paragraphStyle = .default
// TODO: line limit