1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Foundation
struct ModerationInput {
let author: Post.Author
var text = ""
var labels: [ModerationPolicy.Label] = []
var tags: [String] = []
var languages: [String] = []
var imageDescriptions: [URL: String] = [:]
var additionalText: [String] = []
func policyPost(isFollowing: Bool) -> ModerationPolicy.Post {
ModerationPolicy.Post(
author: .init(did: author.id, isFollowing: isFollowing, labels: author.moderationLabels),
text: text, tags: tags, languages: languages,
imageAltTexts: imageDescriptions.keys.sorted { $0.absoluteString < $1.absoluteString }.compactMap {
imageDescriptions[$0]
},
embeddedTexts: additionalText, labels: labels)
}
static func post(_ post: Post) -> Self {
Self(
author: post.author, text: post.text, labels: post.moderationLabels, tags: post.tags,
languages: post.languages, imageDescriptions: post.imageDescriptions,
additionalText: [post.externalTitle, post.externalDescription].compactMap { $0 }
+ post.pendingImages.map(\.altText))
}
static func quote(_ quote: Post.Quote, author: Post.Author) -> Self {
Self(
author: author, text: quote.text ?? "", labels: quote.moderationLabels, tags: quote.tags,
languages: quote.languages, imageDescriptions: quote.imageDescriptions,
additionalText: [quote.externalTitle, quote.externalDescription].compactMap { $0 })
}
static func quotedPost(_ post: Post) -> Self {
Self(
author: post.author, text: post.text, labels: post.moderationLabels, tags: post.tags,
languages: post.languages, imageDescriptions: post.imageDescriptions,
additionalText: [post.externalTitle, post.externalDescription].compactMap { $0 })
}
}
struct PreparedQuoteDecision {
let quote: Post.Quote
let fallback: Post?
let decision: ModerationPolicy.Decision?
}