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-28 13:41:41 +02:00
|
|
|
import MastodonMeta
|
2021-05-07 12:25:57 +02:00
|
|
|
|
2021-06-14 23:09:50 +02:00
|
|
|
protocol EmojiContainer {
|
2021-05-07 12:25:57 +02:00
|
|
|
var emojisData: Data? { get }
|
|
|
|
}
|
|
|
|
|
2021-07-23 13:33:05 +02:00
|
|
|
// FIXME: `Mastodon.Entity.Account` extension
|
|
|
|
|
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) }
|
|
|
|
}
|
2021-06-28 13:41:41 +02:00
|
|
|
|
|
|
|
var emojiMeta: MastodonContent.Emojis {
|
2021-07-23 13:33:05 +02:00
|
|
|
let isAnimated = !UserDefaults.shared.preferredStaticEmoji
|
|
|
|
|
2021-06-28 13:41:41 +02:00
|
|
|
var dict = MastodonContent.Emojis()
|
|
|
|
for emoji in emojis ?? [] {
|
2021-07-23 13:33:05 +02:00
|
|
|
dict[emoji.shortcode] = isAnimated ? emoji.url : emoji.staticURL
|
2021-06-28 13:41:41 +02:00
|
|
|
}
|
|
|
|
return dict
|
|
|
|
}
|
2021-05-07 12:25:57 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|