feat: update report API endpoint

This commit is contained in:
CMK 2022-05-16 16:14:41 +08:00
parent ddc79d8050
commit 00cc131dd2
3 changed files with 40 additions and 3 deletions

View File

@ -165,7 +165,25 @@ extension ReportViewModel {
accountID: user.id,
statusIDs: statusIDs,
comment: comment,
forward: true
forward: true,
category: {
switch self.reportReasonViewModel.selectReason {
case .dislike: return nil
case .spam: return .spam
case .violateRule: return .violation
case .other: return .other
case .none: return nil
}
}(),
ruleIDs: {
switch self.reportReasonViewModel.selectReason {
case .violateRule:
guard let rule = self.reportServerRulesViewModel.selectRule else { return nil }
return [rule.id]
default:
return nil
}
}()
)
}

View File

@ -70,22 +70,39 @@ public extension Mastodon.API.Reports {
public var comment: String?
public let forward: Bool?
public let category: Category?
public let ruleIDs: [Mastodon.Entity.Instance.Rule.ID]?
enum CodingKeys: String, CodingKey {
case accountID = "account_id"
case statusIDs = "status_ids"
case comment
case forward
case category
case ruleIDs = "rule_ids"
}
public enum Category: String, Codable {
case spam
case violation
case other
}
public init(
accountID: Mastodon.Entity.Account.ID,
statusIDs: [Mastodon.Entity.Status.ID]?,
comment: String?,
forward: Bool?) {
forward: Bool?,
category: Category?,
ruleIDs: [Mastodon.Entity.Instance.Rule.ID]?
) {
self.accountID = accountID
self.statusIDs = statusIDs
self.comment = comment
self.forward = forward
self.category = category
self.ruleIDs = ruleIDs
}
}
}

View File

@ -106,7 +106,9 @@ extension Mastodon.Entity.Instance {
extension Mastodon.Entity.Instance {
public struct Rule: Codable, Hashable {
public let id: String
public typealias ID = String
public let id: ID
public let text: String
}
}