1
Fork 0

Decode original post title, and display if the post is reblogged

This commit is contained in:
redstrate 2020-06-03 22:28:36 -04:00
parent 88fdc3ae62
commit c79570d812
2 changed files with 28 additions and 3 deletions

View file

@ -10,6 +10,12 @@ struct Media: Decodable, Identifiable {
let url: String let url: String
} }
struct OriginalPost: Decodable, Identifiable {
let id: Int
let title: String?
}
struct Post: Decodable, Identifiable { struct Post: Decodable, Identifiable {
let id: Int let id: Int
@ -19,4 +25,21 @@ struct Post: Decodable, Identifiable {
let postType: PostType let postType: PostType
let media: [Media] 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
}
}
} }

View file

@ -12,10 +12,12 @@ struct PostView: View {
var body: some View { var body: some View {
VStack { VStack {
Text(String(post.id)) if post.isReblogged() {
Text("Reblogged from " + post.originalUsername!)
}
if post.title != nil { if post.getTitle() != nil {
Text(post.title!) Text(post.getTitle()!)
} }
VStack { VStack {