mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonCore/Persistence/Persistence.swift

62 lines
1.8 KiB
Swift
Raw Normal View History

//
// Persistence.swift
// Persistence
//
// Created by Cirno MainasuK on 2021-8-18.
// Copyright © 2021 Twidere. All rights reserved.
//
import Foundation
public enum Persistence {
case searchHistory(UserIdentifier)
case homeTimeline(UserIdentifier)
case notificationsMentions(UserIdentifier)
case notificationsAll(UserIdentifier)
case accounts(UserIdentifier)
private func uniqueUserDomainIdentifier(for userIdentifier: UserIdentifier) -> String {
"\(userIdentifier.userID)@\(userIdentifier.domain)"
}
2023-11-23 15:07:37 +01:00
private var filename: String {
switch self {
case .searchHistory(let userIdentifier):
2024-02-20 17:41:10 +01:00
return "search_history_\(uniqueUserDomainIdentifier(for: userIdentifier))"
case let .homeTimeline(userIdentifier):
return "home_timeline_\(uniqueUserDomainIdentifier(for: userIdentifier))"
case let .notificationsMentions(userIdentifier):
2023-12-28 13:47:07 +01:00
return "notifications_mentions_\(userIdentifier.uniqueUserDomainIdentifier)"
case let .notificationsAll(userIdentifier):
return "notifications_all_\(uniqueUserDomainIdentifier(for: userIdentifier))"
case .accounts(let userIdentifier):
return "account_\(uniqueUserDomainIdentifier(for: userIdentifier))"
}
}
2023-11-23 15:07:37 +01:00
public func filepath(baseURL: URL) -> URL {
baseURL
.appending(path: filename)
.appendingPathExtension("json")
}
}
extension Persistence {
public enum MastodonUser { }
public enum Status { }
public enum SearchHistory { }
public enum Notification { }
}
extension Persistence {
public class PersistCache<T> {
var dictionary: [String : T] = [:]
public init(dictionary: [String : T] = [:]) {
self.dictionary = dictionary
}
}
}