A WIP iOS app for Mastodon and Pleroma.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

//
// StatusCache.swift
// Tusker
//
// Created by Shadowfacts on 9/17/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import Foundation
import Pachyderm
class StatusCache {
static let cache = NSCache<NSString, Status>()
static func get(id: String) -> Status? {
return cache.object(forKey: id as NSString)
}
static func set(id: String, status: Status) {
cache.setObject(status, forKey: id as NSString)
}
static func get(id: String, completion: @escaping (Status?) -> Void) {
let request = MastodonController.shared.client.getStatus(id: id)
MastodonController.shared.client.run(request) { response in
guard case let .success(status, _) = response else {
completion(nil)
return
}
set(id: id, status: status)
completion(status)
}
}
static func add(_ status: Status) {
set(id: status.id, status: status)
}
static func addAll(_ statuses: [Status]) {
statuses.forEach { set(id: $0.id, status: $0) }
}
}