From 7eebb6226717bcc87e51b367601d738fc9205e68 Mon Sep 17 00:00:00 2001 From: Mary Date: Wed, 21 Dec 2022 23:06:49 +0100 Subject: [PATCH 1/2] Accept missing metadata on attachments Akkoma/Pleroma (and Friendica until recently) aren't providing attachment meta information like width or height. Because Mastodon app enforced those fields to be present, attachments would be filtered out. This commit change the behaviour of Mastodon.Entity.Status.mastodonAttachments by allowing those values to be missing and use default values instead. --- .../CoreDataStack/Status+Property.swift | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift index c4508a997..ca4fa9fc9 100644 --- a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift +++ b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift @@ -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.flatMap { 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, From deb977707ac2ca6e8a0ccee2230abf07218b2ac1 Mon Sep 17 00:00:00 2001 From: Mary Date: Sun, 25 Dec 2022 12:04:59 +0100 Subject: [PATCH 2/2] Address comments --- .../Extension/CoreDataStack/Status+Property.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift index ca4fa9fc9..9e92e0d2c 100644 --- a/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift +++ b/MastodonSDK/Sources/MastodonCore/Extension/CoreDataStack/Status+Property.swift @@ -62,9 +62,9 @@ extension Mastodon.Entity.Status { let original = meta.original, let originalWidth = original.width, let originalHeight = original.height { - width = originalWidth; // audio has width/height - height = originalHeight; - durationMS = original.duration.flatMap { Int($0 * 1000) } + 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.