2018-09-11 14:52:21 +00:00
|
|
|
//
|
|
|
|
// Emoji.swift
|
|
|
|
// Pachyderm
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 9/8/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2022-02-04 04:11:29 +00:00
|
|
|
import WebURL
|
2018-09-11 14:52:21 +00:00
|
|
|
|
2023-02-19 20:23:25 +00:00
|
|
|
public struct Emoji: Codable, Sendable {
|
2019-02-10 02:12:31 +00:00
|
|
|
public let shortcode: String
|
2022-02-04 04:11:29 +00:00
|
|
|
// these shouldn't need to be WebURLs as they're not external resources,
|
|
|
|
// but some instances (pleroma?) has emoji urls that Foundation considers malformed so we use WebURL to be more lenient
|
|
|
|
public let url: WebURL
|
|
|
|
public let staticURL: WebURL
|
2019-02-10 02:12:31 +00:00
|
|
|
public let visibleInPicker: Bool
|
2022-11-29 03:13:06 +00:00
|
|
|
public let category: String?
|
2018-09-11 14:52:21 +00:00
|
|
|
|
2023-02-19 20:23:25 +00:00
|
|
|
public init(from decoder: Decoder) throws {
|
2020-11-11 17:45:13 +00:00
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
|
|
|
self.shortcode = try container.decode(String.self, forKey: .shortcode)
|
2022-02-04 04:11:29 +00:00
|
|
|
self.url = try container.decode(WebURL.self, forKey: .url)
|
|
|
|
self.staticURL = try container.decode(WebURL.self, forKey: .staticURL)
|
2020-11-11 17:45:13 +00:00
|
|
|
self.visibleInPicker = try container.decode(Bool.self, forKey: .visibleInPicker)
|
2022-11-29 03:13:06 +00:00
|
|
|
self.category = try container.decodeIfPresent(String.self, forKey: .category)
|
2020-11-11 17:45:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-11 14:52:21 +00:00
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
|
|
case shortcode
|
|
|
|
case url
|
|
|
|
case staticURL = "static_url"
|
2019-02-10 02:12:31 +00:00
|
|
|
case visibleInPicker = "visible_in_picker"
|
2022-11-29 03:13:06 +00:00
|
|
|
case category
|
2018-09-11 14:52:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Emoji: CustomDebugStringConvertible {
|
|
|
|
public var debugDescription: String {
|
|
|
|
return ":\(shortcode):"
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 01:41:05 +00:00
|
|
|
|
|
|
|
extension Emoji: Equatable {
|
|
|
|
public static func ==(lhs: Emoji, rhs: Emoji) -> Bool {
|
|
|
|
return lhs.shortcode == rhs.shortcode && lhs.url == rhs.url
|
|
|
|
}
|
|
|
|
}
|