Merge pull request #805 from marysaka/fix/reduce-attachment-constraints

Accept missing metadata on attachments
This commit is contained in:
Nathan Mattes 2022-12-26 19:46:51 +01:00 committed by GitHub
commit 6c6978c524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 7 deletions

View File

@ -51,14 +51,28 @@ extension Mastodon.Entity.Status {
guard let mediaAttachments = mediaAttachments else { return [] }
let attachments = mediaAttachments.compactMap { media -> MastodonAttachment? in
guard let kind = media.attachmentKind,
let meta = media.meta,
let original = meta.original,
let width = original.width, // audio has width/height
let height = original.height
guard let kind = media.attachmentKind
else { return nil }
let durationMS: Int? = original.duration.flatMap { Int($0 * 1000) }
let width: Int;
let height: Int;
let durationMS: Int?;
if let meta = media.meta,
let original = meta.original,
let originalWidth = original.width,
let originalHeight = original.height {
width = originalWidth // audio has width/height
height = originalHeight
durationMS = original.duration.map { Int($0 * 1000) }
}
else {
// In case metadata field is missing, use default values.
width = 32;
height = 32;
durationMS = nil;
}
return MastodonAttachment(
id: media.id,
kind: kind,