2018-09-11 10:52:21 -04:00
|
|
|
//
|
|
|
|
// Notification.swift
|
|
|
|
// Pachyderm
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/9/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2018-09-17 19:22:37 -04:00
|
|
|
public class Notification: Decodable {
|
2018-09-11 10:52:21 -04:00
|
|
|
public let id: String
|
|
|
|
public let kind: Kind
|
|
|
|
public let createdAt: Date
|
|
|
|
public let account: Account
|
|
|
|
public let status: Status?
|
|
|
|
|
2020-03-02 19:08:31 -05:00
|
|
|
public required init(from decoder: Decoder) throws {
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
|
|
|
self.id = try container.decode(String.self, forKey: .id)
|
|
|
|
if let kind = try? container.decode(Kind.self, forKey: .kind) {
|
|
|
|
self.kind = kind
|
|
|
|
} else {
|
|
|
|
self.kind = .unknown
|
|
|
|
}
|
|
|
|
self.createdAt = try container.decode(Date.self, forKey: .createdAt)
|
|
|
|
self.account = try container.decode(Account.self, forKey: .account)
|
|
|
|
if container.contains(.status) {
|
|
|
|
self.status = try container.decode(Status.self, forKey: .status)
|
|
|
|
} else {
|
|
|
|
self.status = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 16:08:25 -04:00
|
|
|
public static func dismiss(id notificationID: String) -> Request<Empty> {
|
2018-09-17 19:22:37 -04:00
|
|
|
return Request<Empty>(method: .post, path: "/api/v1/notifications/dismiss", body: .parameters([
|
2019-09-16 16:08:25 -04:00
|
|
|
"id" => notificationID
|
2018-09-11 10:52:21 -04:00
|
|
|
]))
|
|
|
|
}
|
|
|
|
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
|
|
case id
|
|
|
|
case kind = "type"
|
|
|
|
case createdAt = "created_at"
|
|
|
|
case account
|
|
|
|
case status
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Notification {
|
2019-09-14 12:04:06 -04:00
|
|
|
public enum Kind: String, Decodable, CaseIterable {
|
2018-09-11 10:52:21 -04:00
|
|
|
case mention
|
|
|
|
case reblog
|
|
|
|
case favourite
|
|
|
|
case follow
|
2020-01-04 23:13:23 -05:00
|
|
|
case followRequest = "follow_request"
|
2020-03-02 19:08:31 -05:00
|
|
|
case unknown
|
2018-09-11 10:52:21 -04:00
|
|
|
}
|
|
|
|
}
|
2019-09-05 14:33:10 -04:00
|
|
|
|
|
|
|
extension Notification: Identifiable {}
|