forked from shadowfacts/Tusker
47 lines
1.7 KiB
Swift
47 lines
1.7 KiB
Swift
//
|
|
// PushNotification.swift
|
|
// Pachyderm
|
|
//
|
|
// Created by Shadowfacts on 4/9/24.
|
|
//
|
|
|
|
import Foundation
|
|
import WebURL
|
|
|
|
public struct PushNotification: Decodable {
|
|
public let accessToken: String
|
|
public let preferredLocale: String
|
|
public let notificationID: String
|
|
public let notificationType: Notification.Kind
|
|
public let icon: WebURL
|
|
public let title: String
|
|
public let body: String
|
|
|
|
public init(from decoder: any Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
self.accessToken = try container.decode(String.self, forKey: .accessToken)
|
|
self.preferredLocale = try container.decode(String.self, forKey: .preferredLocale)
|
|
// this should be a string, but mastodon encodes it as a json number
|
|
if let s = try? container.decode(String.self, forKey: .notificationID) {
|
|
self.notificationID = s
|
|
} else {
|
|
let i = try container.decode(Int.self, forKey: .notificationID)
|
|
self.notificationID = i.description
|
|
}
|
|
self.notificationType = try container.decode(Notification.Kind.self, forKey: .notificationType)
|
|
self.icon = try container.decode(WebURL.self, forKey: .icon)
|
|
self.title = try container.decode(String.self, forKey: .title)
|
|
self.body = try container.decode(String.self, forKey: .body)
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case accessToken = "access_token"
|
|
case preferredLocale = "preferred_locale"
|
|
case notificationID = "notification_id"
|
|
case notificationType = "notification_type"
|
|
case icon
|
|
case title
|
|
case body
|
|
}
|
|
}
|