2021-05-07 12:25:57 +02:00
|
|
|
//
|
|
|
|
// Emojis.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-5-7.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
|
|
|
|
2021-06-14 23:09:50 +02:00
|
|
|
protocol EmojiContainer {
|
2021-05-07 12:25:57 +02:00
|
|
|
var emojisData: Data? { get }
|
|
|
|
}
|
|
|
|
|
2021-06-14 23:09:50 +02:00
|
|
|
extension EmojiContainer {
|
2021-05-07 12:25:57 +02:00
|
|
|
|
|
|
|
static func encode(emojis: [Mastodon.Entity.Emoji]) -> Data? {
|
|
|
|
return try? JSONEncoder().encode(emojis)
|
|
|
|
}
|
|
|
|
|
|
|
|
var emojis: [Mastodon.Entity.Emoji]? {
|
|
|
|
let decoder = JSONDecoder()
|
|
|
|
return emojisData.flatMap { try? decoder.decode([Mastodon.Entity.Emoji].self, from: $0) }
|
|
|
|
}
|
|
|
|
|
|
|
|
var emojiDict: MastodonStatusContent.EmojiDict {
|
|
|
|
var dict = MastodonStatusContent.EmojiDict()
|
|
|
|
for emoji in emojis ?? [] {
|
|
|
|
guard let url = URL(string: emoji.url) else { continue }
|
|
|
|
dict[emoji.shortcode] = url
|
|
|
|
}
|
|
|
|
return dict
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|