Compare commits
2 Commits
aced0a63c9
...
e61823b78f
Author | SHA1 | Date |
---|---|---|
Shadowfacts | e61823b78f | |
Shadowfacts | 4d52ac4d34 |
|
@ -18,12 +18,21 @@ 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?
|
||||||
|
|
||||||
// MARK: Unofficial additions to the Mastodon API.
|
// superseded by mastodon's configuration.statuses.max_characters, still used by older instances & pleroma
|
||||||
public let maxStatusCharacters: Int?
|
let maxTootCharacters: 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 {
|
||||||
|
@ -44,14 +53,18 @@ 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.maxStatusCharacters = maxStatusCharacters
|
self.configuration = try? container.decodeIfPresent(Configuration.self, forKey: .configuration)
|
||||||
} else if let str = try? container.decodeIfPresent(String.self, forKey: .maxStatusCharacters),
|
|
||||||
let maxStatusCharacters = Int(str, radix: 10) {
|
if let maxTootCharacters = try? container.decodeIfPresent(Int.self, forKey: .maxTootCharacters) {
|
||||||
self.maxStatusCharacters = maxStatusCharacters
|
self.maxTootCharacters = maxTootCharacters
|
||||||
|
} else if let str = try? container.decodeIfPresent(String.self, forKey: .maxTootCharacters),
|
||||||
|
let maxTootCharacters = Int(str, radix: 10) {
|
||||||
|
self.maxTootCharacters = maxTootCharacters
|
||||||
} else {
|
} else {
|
||||||
self.maxStatusCharacters = nil
|
self.maxTootCharacters = nil
|
||||||
}
|
}
|
||||||
|
self.pollLimits = try? container.decodeIfPresent(PollsConfiguration.self, forKey: .pollLimits)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,15 +78,16 @@ 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 maxStatusCharacters = "max_toot_chars"
|
case maxTootCharacters = "max_toot_chars"
|
||||||
|
case pollLimits = "poll_limits"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Instance {
|
extension Instance {
|
||||||
public class Stats: Decodable {
|
public struct 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?
|
||||||
|
@ -85,3 +99,68 @@ 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -143,11 +143,14 @@ 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
|
47, // iPhone 12, 12 Pro, 12 Pro Max, 13, 13 Pro, 13 Pro Max
|
||||||
50, // iPhone 12 mini
|
50, // iPhone 12 mini, 13 mini
|
||||||
]
|
]
|
||||||
if notchedDeviceTopInsets.contains(view.safeAreaInsets.top) {
|
if notchedDeviceTopInsets.contains(view.safeAreaInsets.top) {
|
||||||
let notchWidth: CGFloat = 209
|
// the notch width is not the same for the iPhones 13,
|
||||||
|
// 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
|
||||||
|
|
Loading…
Reference in New Issue