2022-01-27 14:23:39 +01:00
|
|
|
//
|
|
|
|
// Persistence.swift
|
|
|
|
// Persistence
|
|
|
|
//
|
|
|
|
// Created by Cirno MainasuK on 2021-8-18.
|
|
|
|
// Copyright © 2021 Twidere. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
2023-11-23 13:58:56 +01:00
|
|
|
public enum Persistence {
|
2023-12-28 22:39:24 +01:00
|
|
|
case searchHistory(UserIdentifier)
|
2023-12-27 10:35:00 +01:00
|
|
|
case homeTimeline(UserIdentifier)
|
|
|
|
case notificationsMentions(UserIdentifier)
|
|
|
|
case notificationsAll(UserIdentifier)
|
2023-12-28 22:39:24 +01:00
|
|
|
case accounts(UserIdentifier)
|
2023-12-13 15:07:16 +01:00
|
|
|
|
|
|
|
private func uniqueUserDomainIdentifier(for userIdentifier: UserIdentifier) -> String {
|
|
|
|
"\(userIdentifier.userID)@\(userIdentifier.domain)"
|
|
|
|
}
|
|
|
|
|
2023-11-23 15:07:37 +01:00
|
|
|
private var filename: String {
|
2023-11-23 13:58:56 +01:00
|
|
|
switch self {
|
2023-12-28 22:39:24 +01:00
|
|
|
case .searchHistory(let userIdentifier):
|
2024-02-20 17:41:10 +01:00
|
|
|
return "search_history_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
2023-12-27 10:35:00 +01:00
|
|
|
case let .homeTimeline(userIdentifier):
|
2023-12-28 22:39:24 +01:00
|
|
|
return "home_timeline_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
2023-12-27 10:35:00 +01:00
|
|
|
case let .notificationsMentions(userIdentifier):
|
2023-12-28 13:47:07 +01:00
|
|
|
return "notifications_mentions_\(userIdentifier.uniqueUserDomainIdentifier)"
|
2023-12-27 10:35:00 +01:00
|
|
|
case let .notificationsAll(userIdentifier):
|
2023-12-13 15:07:16 +01:00
|
|
|
return "notifications_all_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
2023-12-28 22:39:24 +01:00
|
|
|
case .accounts(let userIdentifier):
|
|
|
|
return "account_\(uniqueUserDomainIdentifier(for: userIdentifier))"
|
2023-11-23 13:58:56 +01:00
|
|
|
}
|
|
|
|
}
|
2023-11-23 15:07:37 +01:00
|
|
|
|
|
|
|
public func filepath(baseURL: URL) -> URL {
|
|
|
|
baseURL
|
|
|
|
.appending(path: filename)
|
|
|
|
.appendingPathExtension("json")
|
|
|
|
}
|
2023-11-23 13:58:56 +01:00
|
|
|
}
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|