From c79570d81287c1c1aae269d48c47d441072ef6fd Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Wed, 3 Jun 2020 22:28:36 -0400 Subject: [PATCH] Decode original post title, and display if the post is reblogged --- MobileFort/MobileFort/Common.swift | 23 +++++++++++++++++++++++ MobileFort/MobileFort/ContentView.swift | 8 +++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/MobileFort/MobileFort/Common.swift b/MobileFort/MobileFort/Common.swift index b7e0418..5ab2393 100644 --- a/MobileFort/MobileFort/Common.swift +++ b/MobileFort/MobileFort/Common.swift @@ -10,6 +10,12 @@ struct Media: Decodable, Identifiable { let url: String } +struct OriginalPost: Decodable, Identifiable { + let id: Int + + let title: String? +} + struct Post: Decodable, Identifiable { let id: Int @@ -19,4 +25,21 @@ struct Post: Decodable, Identifiable { let postType: PostType let media: [Media] + + let username: String + let originalUsername: String? + + let originalPost: OriginalPost? + + func isReblogged() -> Bool { + return originalUsername != nil + } + + func getTitle() -> String? { + if isReblogged() { + return originalPost?.title + } else { + return title + } + } } diff --git a/MobileFort/MobileFort/ContentView.swift b/MobileFort/MobileFort/ContentView.swift index 4aed22f..1aca524 100644 --- a/MobileFort/MobileFort/ContentView.swift +++ b/MobileFort/MobileFort/ContentView.swift @@ -12,10 +12,12 @@ struct PostView: View { var body: some View { VStack { - Text(String(post.id)) + if post.isReblogged() { + Text("Reblogged from " + post.originalUsername!) + } - if post.title != nil { - Text(post.title!) + if post.getTitle() != nil { + Text(post.getTitle()!) } VStack {