actually add PreviewCache oops
This commit is contained in:
35
damus/Util/PreviewCache.swift
Normal file
35
damus/Util/PreviewCache.swift
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// PreviewCache.swift
|
||||||
|
// damus
|
||||||
|
//
|
||||||
|
// Created by William Casarin on 2023-01-02.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import LinkPresentation
|
||||||
|
|
||||||
|
enum Preview {
|
||||||
|
case value(LinkViewRepresentable)
|
||||||
|
case failed
|
||||||
|
}
|
||||||
|
|
||||||
|
class PreviewCache {
|
||||||
|
var previews: [String: Preview]
|
||||||
|
|
||||||
|
func lookup(_ evid: String) -> Preview? {
|
||||||
|
return previews[evid]
|
||||||
|
}
|
||||||
|
|
||||||
|
func store(evid: String, preview: LinkViewRepresentable?) {
|
||||||
|
switch preview {
|
||||||
|
case .none:
|
||||||
|
previews[evid] = .failed
|
||||||
|
case .some(let meta):
|
||||||
|
previews[evid] = .value(meta)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
self.previews = [:]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user