2021-03-15 07:40:10 +01:00
|
|
|
//
|
|
|
|
// EmojiService.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-15.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Combine
|
|
|
|
import MastodonSDK
|
|
|
|
|
2022-09-30 13:28:09 +02:00
|
|
|
public final class EmojiService {
|
2021-03-15 07:40:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
weak var apiService: APIService?
|
|
|
|
|
2021-06-11 22:37:54 +02:00
|
|
|
let workingQueue = DispatchQueue(label: "org.joinmastodon.app.EmojiService.working-queue")
|
2021-03-15 12:25:44 +01:00
|
|
|
private(set) var customEmojiViewModelDict: [String: CustomEmojiViewModel] = [:]
|
2021-03-15 07:40:10 +01:00
|
|
|
|
|
|
|
init(apiService: APIService) {
|
|
|
|
self.apiService = apiService
|
|
|
|
}
|
2021-03-15 12:25:44 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension EmojiService {
|
|
|
|
|
2022-10-08 07:43:06 +02:00
|
|
|
public func dequeueCustomEmojiViewModel(for domain: String) -> CustomEmojiViewModel? {
|
2021-03-15 12:25:44 +01:00
|
|
|
var _customEmojiViewModel: CustomEmojiViewModel?
|
|
|
|
workingQueue.sync {
|
|
|
|
if let viewModel = customEmojiViewModelDict[domain] {
|
|
|
|
_customEmojiViewModel = viewModel
|
|
|
|
} else {
|
|
|
|
let viewModel = CustomEmojiViewModel(domain: domain, service: self)
|
|
|
|
_customEmojiViewModel = viewModel
|
|
|
|
|
|
|
|
// trigger loading
|
|
|
|
viewModel.stateMachine.enter(CustomEmojiViewModel.LoadState.Loading.self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return _customEmojiViewModel
|
|
|
|
}
|
|
|
|
|
2021-03-15 07:40:10 +01:00
|
|
|
}
|
|
|
|
|