1
Fork 0
This repository has been archived on 2025-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
mobilefort/MobileFort/Common/Common.swift

86 lines
1.9 KiB
Swift
Raw Normal View History

2020-06-03 21:45:44 -04:00
import Foundation
enum PostType: String, Decodable {
case text, picture
}
2020-06-03 21:56:33 -04:00
struct Media: Decodable, Identifiable {
let id: Int
let url: String
}
struct OriginalPost: Decodable, Identifiable {
let id: Int
let title: String?
2020-06-04 06:07:18 -04:00
let content: String
}
2020-06-03 21:45:44 -04:00
struct Post: Decodable, Identifiable {
let id: Int
let title: String?
let content: String
let postType: PostType
2020-06-03 21:56:33 -04:00
let media: [Media]
let username: String
let originalUsername: String?
let originalPost: OriginalPost?
2020-06-03 23:17:23 -04:00
let avatarUrl: String
func isReblogged() -> Bool {
return originalUsername != nil
}
func getTitle() -> String? {
if isReblogged() {
return originalPost?.title
} else {
return title
}
}
2020-06-04 06:07:18 -04:00
func getContent() -> String {
if isReblogged() {
return originalPost!.content
} else {
return content
}
}
2020-06-03 21:45:44 -04:00
}
2020-06-03 22:42:37 -04:00
struct ParsedPostContainer {
let post: Post
let contentAttributed: NSMutableAttributedString
}
2020-06-03 23:17:23 -04:00
let mediaURL = "https://homepages.cae.wisc.edu/~ece533/images/airplane.png"
2020-06-03 22:42:37 -04:00
let testMedia = Media(id: 0,
2020-06-03 23:17:23 -04:00
url: mediaURL)
2020-06-03 22:42:37 -04:00
let fooPost = Post(id: 0,
title: "Foo",
content: "",
postType: .picture,
media: [testMedia],
username: "foobar",
originalUsername: nil,
2020-06-03 23:17:23 -04:00
originalPost: nil,
avatarUrl: mediaURL)
2020-06-03 22:42:37 -04:00
let fooPostReblog = Post(id: 1,
title: nil,
content: "",
postType: .picture,
media: [testMedia],
username: "foobar",
originalUsername: "foobar2",
2020-06-03 23:17:23 -04:00
originalPost: nil,
avatarUrl: mediaURL)