Prepare disk cache for Timeline
This commit is contained in:
parent
86937e65fe
commit
3c0ffdb1ae
|
@ -1,11 +1,11 @@
|
|||
import Foundation
|
||||
|
||||
public struct Account: Decodable, Identifiable, Equatable, Hashable {
|
||||
public struct Account: Codable, Identifiable, Equatable, Hashable {
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
|
||||
public struct Field: Decodable, Equatable, Identifiable {
|
||||
public struct Field: Codable, Equatable, Identifiable {
|
||||
public var id: String {
|
||||
value.asRawText + name
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public struct Account: Decodable, Identifiable, Equatable, Hashable {
|
|||
public let verifiedAt: String?
|
||||
}
|
||||
|
||||
public struct Source: Decodable, Equatable {
|
||||
public struct Source: Codable, Equatable {
|
||||
public let privacy: Visibility
|
||||
public let sensitive: Bool
|
||||
public let language: String?
|
||||
|
|
|
@ -2,7 +2,7 @@ import Foundation
|
|||
import SwiftSoup
|
||||
import SwiftUI
|
||||
|
||||
public struct HTMLString: Decodable, Equatable, Hashable {
|
||||
public struct HTMLString: Codable, Equatable, Hashable {
|
||||
public var htmlValue: String = ""
|
||||
public var asMarkdown: String = ""
|
||||
public var asRawText: String = ""
|
||||
|
@ -61,6 +61,11 @@ public struct HTMLString: Decodable, Equatable, Hashable {
|
|||
asSafeMarkdownAttributedString = AttributedString(stringLiteral: htmlValue)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(htmlValue)
|
||||
}
|
||||
|
||||
private mutating func handleNode(node: SwiftSoup.Node ) {
|
||||
|
||||
|
||||
|
@ -146,6 +151,4 @@ public struct HTMLString: Decodable, Equatable, Hashable {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ protocol StatusUI {
|
|||
var uiShouldHighlight: Bool? { get set }
|
||||
}
|
||||
|
||||
public struct Status: AnyStatus, Decodable, Identifiable, Equatable, Hashable, StatusUI {
|
||||
public struct Status: AnyStatus, Codable, Identifiable, Equatable, Hashable, StatusUI {
|
||||
public var viewId: String {
|
||||
id + createdAt + (editedAt ?? "")
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public struct Status: AnyStatus, Decodable, Identifiable, Equatable, Hashable, S
|
|||
}
|
||||
}
|
||||
|
||||
public struct ReblogStatus: AnyStatus, Decodable, Identifiable, Equatable, Hashable {
|
||||
public struct ReblogStatus: AnyStatus, Codable, Identifiable, Equatable, Hashable {
|
||||
public var viewId: String {
|
||||
id + createdAt + (editedAt ?? "")
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import SwiftUI
|
|||
public class Client: ObservableObject, Equatable, Identifiable, Hashable {
|
||||
public static func == (lhs: Client, rhs: Client) -> Bool {
|
||||
lhs.isAuth == rhs.isAuth &&
|
||||
lhs.server == rhs.server &&
|
||||
lhs.oauthToken?.accessToken == rhs.oauthToken?.accessToken
|
||||
lhs.server == rhs.server &&
|
||||
lhs.oauthToken?.accessToken == rhs.oauthToken?.accessToken
|
||||
}
|
||||
|
||||
public enum Version: String {
|
||||
|
@ -19,7 +19,7 @@ public class Client: ObservableObject, Equatable, Identifiable, Hashable {
|
|||
}
|
||||
|
||||
public var id: String {
|
||||
"\(isAuth)\(server)\(oauthToken?.accessToken ?? "")"
|
||||
"\(isAuth)\(server)\(oauthToken?.createdAt ?? 0)"
|
||||
}
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
|
|
@ -156,7 +156,9 @@ extension TimelineViewModel: StatusesFetcher {
|
|||
|
||||
// If we get statuses from the cache for the home timeline, we displays those.
|
||||
// Else we fetch top most page from the API.
|
||||
if let cachedStatuses = await getCachedStatuses(), timeline == .home {
|
||||
if let cachedStatuses = await getCachedStatuses(),
|
||||
!cachedStatuses.isEmpty,
|
||||
timeline == .home {
|
||||
statuses = cachedStatuses
|
||||
withAnimation {
|
||||
statusesState = .display(statuses: statuses, nextPageState: statuses.count < 20 ? .none : .hasNextPage)
|
||||
|
|
Loading…
Reference in New Issue