Compare commits

..

No commits in common. "e61823b78fef150c73eba27cfa0b5ef55231e798" and "aced0a63c95714fb82185fa9d57ad2391b980245" have entirely different histories.

2 changed files with 14 additions and 96 deletions

View File

@ -18,21 +18,12 @@ public class Instance: Decodable {
public let thumbnail: URL? public let thumbnail: URL?
public let languages: [String]? public let languages: [String]?
public let stats: Stats? public let stats: Stats?
public let configuration: Configuration?
// pleroma doesn't currently implement these // pleroma doesn't currently implement these
public let contactAccount: Account? public let contactAccount: Account?
// superseded by mastodon's configuration.statuses.max_characters, still used by older instances & pleroma // MARK: Unofficial additions to the Mastodon API.
let maxTootCharacters: Int? public let maxStatusCharacters: Int?
let pollLimits: PollsConfiguration?
public var maxStatusCharacters: Int? {
configuration?.statuses.maxCharacters ?? maxTootCharacters
}
public var pollsConfiguration: PollsConfiguration? {
configuration?.polls ?? pollLimits
}
// we need a custom decoder, because all API-compatible implementations don't return some data in the same format // we need a custom decoder, because all API-compatible implementations don't return some data in the same format
public required init(from decoder: Decoder) throws { public required init(from decoder: Decoder) throws {
@ -53,18 +44,14 @@ public class Instance: Decodable {
self.stats = try? container.decodeIfPresent(Stats.self, forKey: .stats) self.stats = try? container.decodeIfPresent(Stats.self, forKey: .stats)
self.thumbnail = try? container.decodeIfPresent(URL.self, forKey: .thumbnail) self.thumbnail = try? container.decodeIfPresent(URL.self, forKey: .thumbnail)
if let maxStatusCharacters = try? container.decodeIfPresent(Int.self, forKey: .maxStatusCharacters) {
self.configuration = try? container.decodeIfPresent(Configuration.self, forKey: .configuration) self.maxStatusCharacters = maxStatusCharacters
} else if let str = try? container.decodeIfPresent(String.self, forKey: .maxStatusCharacters),
if let maxTootCharacters = try? container.decodeIfPresent(Int.self, forKey: .maxTootCharacters) { let maxStatusCharacters = Int(str, radix: 10) {
self.maxTootCharacters = maxTootCharacters self.maxStatusCharacters = maxStatusCharacters
} else if let str = try? container.decodeIfPresent(String.self, forKey: .maxTootCharacters),
let maxTootCharacters = Int(str, radix: 10) {
self.maxTootCharacters = maxTootCharacters
} else { } else {
self.maxTootCharacters = nil self.maxStatusCharacters = nil
} }
self.pollLimits = try? container.decodeIfPresent(PollsConfiguration.self, forKey: .pollLimits)
} }
@ -78,16 +65,15 @@ public class Instance: Decodable {
case thumbnail case thumbnail
case languages case languages
case stats case stats
case configuration
case contactAccount = "contact_account" case contactAccount = "contact_account"
case maxTootCharacters = "max_toot_chars" case maxStatusCharacters = "max_toot_chars"
case pollLimits = "poll_limits"
} }
} }
extension Instance { extension Instance {
public struct Stats: Decodable { public class Stats: Decodable {
public let domainCount: Int? public let domainCount: Int?
public let statusCount: Int? public let statusCount: Int?
public let userCount: Int? public let userCount: Int?
@ -99,68 +85,3 @@ extension Instance {
} }
} }
} }
extension Instance {
public struct Configuration: Decodable {
public let statuses: StatusesConfiguration
public let mediaAttachments: MediaAttachmentsConfiguration
/// Use Instance.pollsConfiguration to support older instance that don't have this nested
let polls: PollsConfiguration
private enum CodingKeys: String, CodingKey {
case statuses
case mediaAttachments = "media_attachments"
case polls
}
}
}
extension Instance {
public struct StatusesConfiguration: Decodable {
public let maxCharacters: Int
public let maxMediaAttachments: Int
public let charactersReservedPerURL: Int
private enum CodingKeys: String, CodingKey {
case maxCharacters = "max_characters"
case maxMediaAttachments = "max_media_attachments"
case charactersReservedPerURL = "characters_reserved_per_url"
}
}
}
extension Instance {
public struct MediaAttachmentsConfiguration: Decodable {
public let supportedMIMETypes: [String]
public let imageSizeLimit: Int
public let imageMatrixLimit: Int
public let videoSizeLimit: Int
public let videoFrameRateLimit: Int
public let videoMatrixLimit: Int
private enum CodingKeys: String, CodingKey {
case supportedMIMETypes = "supported_mime_types"
case imageSizeLimit = "image_size_limit"
case imageMatrixLimit = "image_matrix_limit"
case videoSizeLimit = "video_size_limit"
case videoFrameRateLimit = "video_frame_rate_limit"
case videoMatrixLimit = "video_matrix_limit"
}
}
}
extension Instance {
public struct PollsConfiguration: Decodable {
public let maxOptions: Int
public let maxCharactersPerOption: Int
public let minExpiration: TimeInterval
public let maxExpiration: TimeInterval
private enum CodingKeys: String, CodingKey {
case maxOptions = "max_options"
case maxCharactersPerOption = "max_characters_per_option"
case minExpiration = "min_expiration"
case maxExpiration = "max_expiration"
}
}
}

View File

@ -143,14 +143,11 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate, LargeIma
let notchedDeviceTopInsets: [CGFloat] = [ let notchedDeviceTopInsets: [CGFloat] = [
44, // iPhone X, Xs, Xs Max, 11 Pro, 11 Pro Max 44, // iPhone X, Xs, Xs Max, 11 Pro, 11 Pro Max
48, // iPhone XR, 11 48, // iPhone XR, 11
47, // iPhone 12, 12 Pro, 12 Pro Max, 13, 13 Pro, 13 Pro Max 47, // iPhone 12, 12 Pro, 12 Pro Max
50, // iPhone 12 mini, 13 mini 50, // iPhone 12 mini
] ]
if notchedDeviceTopInsets.contains(view.safeAreaInsets.top) { if notchedDeviceTopInsets.contains(view.safeAreaInsets.top) {
// the notch width is not the same for the iPhones 13, let notchWidth: CGFloat = 209
// but what we actually want is the same offset from the edges
// since the corner radius didn't change
let notchWidth: CGFloat = 210
let earWidth = (view.bounds.width - notchWidth) / 2 let earWidth = (view.bounds.width - notchWidth) / 2
let offset = (earWidth - shareButton.bounds.width) / 2 let offset = (earWidth - shareButton.bounds.width) / 2
shareButtonLeadingConstraint.constant = offset shareButtonLeadingConstraint.constant = offset