mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-26 02:01:02 +00:00
Remove Sendable conformance on Client as it's not needed
This commit is contained in:
parent
03d60d2236
commit
65e63c4586
5 changed files with 15 additions and 15 deletions
|
@ -57,8 +57,8 @@ struct AccountSettingsView: View {
|
||||||
Label("settings.account.cached-posts-\(String(cachedPostsCount))", systemImage: "internaldrive")
|
Label("settings.account.cached-posts-\(String(cachedPostsCount))", systemImage: "internaldrive")
|
||||||
Button("settings.account.action.delete-cache", role: .destructive) {
|
Button("settings.account.action.delete-cache", role: .destructive) {
|
||||||
Task {
|
Task {
|
||||||
await TimelineCache.shared.clearCache(for: appAccountsManager.currentClient)
|
await TimelineCache.shared.clearCache(for: appAccountsManager.currentClient.id)
|
||||||
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient)
|
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ struct AccountSettingsView: View {
|
||||||
if let token = appAccount.oauthToken {
|
if let token = appAccount.oauthToken {
|
||||||
Task {
|
Task {
|
||||||
let client = Client(server: appAccount.server, oauthToken: token)
|
let client = Client(server: appAccount.server, oauthToken: token)
|
||||||
await TimelineCache.shared.clearCache(for: client)
|
await TimelineCache.shared.clearCache(for: client.id)
|
||||||
if let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token }) {
|
if let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token }) {
|
||||||
await sub.deleteSubscription()
|
await sub.deleteSubscription()
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ struct AccountSettingsView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.task {
|
.task {
|
||||||
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient)
|
cachedPostsCount = await TimelineCache.shared.cachedPostsCount(for: appAccountsManager.currentClient.id)
|
||||||
}
|
}
|
||||||
.navigationTitle(account.safeDisplayName)
|
.navigationTitle(account.safeDisplayName)
|
||||||
.scrollContentBackground(.hidden)
|
.scrollContentBackground(.hidden)
|
||||||
|
|
|
@ -106,7 +106,7 @@ struct SettingsTabs: View {
|
||||||
let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token })
|
let sub = pushNotifications.subscriptions.first(where: { $0.account.token == token })
|
||||||
{
|
{
|
||||||
let client = Client(server: account.server, oauthToken: token)
|
let client = Client(server: account.server, oauthToken: token)
|
||||||
await TimelineCache.shared.clearCache(for: client)
|
await TimelineCache.shared.clearCache(for: client.id)
|
||||||
await sub.deleteSubscription()
|
await sub.deleteSubscription()
|
||||||
appAccountsManager.delete(account: account)
|
appAccountsManager.delete(account: account)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Foundation
|
||||||
import Models
|
import Models
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
public final class Client: ObservableObject, Equatable, Identifiable, Hashable, @unchecked Sendable {
|
public final class Client: ObservableObject, Equatable, Identifiable, Hashable {
|
||||||
public static func == (lhs: Client, rhs: Client) -> Bool {
|
public static func == (lhs: Client, rhs: Client) -> Bool {
|
||||||
lhs.isAuth == rhs.isAuth &&
|
lhs.isAuth == rhs.isAuth &&
|
||||||
lhs.server == rhs.server &&
|
lhs.server == rhs.server &&
|
||||||
|
|
|
@ -6,8 +6,8 @@ import SwiftUI
|
||||||
public actor TimelineCache {
|
public actor TimelineCache {
|
||||||
public static let shared: TimelineCache = .init()
|
public static let shared: TimelineCache = .init()
|
||||||
|
|
||||||
private func storageFor(_ client: Client) -> SQLiteStorageEngine {
|
private func storageFor(_ client: String) -> SQLiteStorageEngine {
|
||||||
SQLiteStorageEngine.default(appendingPath: client.id)
|
SQLiteStorageEngine.default(appendingPath: client)
|
||||||
}
|
}
|
||||||
|
|
||||||
private let decoder = JSONDecoder()
|
private let decoder = JSONDecoder()
|
||||||
|
@ -15,18 +15,18 @@ public actor TimelineCache {
|
||||||
|
|
||||||
private init() {}
|
private init() {}
|
||||||
|
|
||||||
public func cachedPostsCount(for client: Client) async -> Int {
|
public func cachedPostsCount(for client: String) async -> Int {
|
||||||
await storageFor(client).allKeys().count
|
await storageFor(client).allKeys().count
|
||||||
}
|
}
|
||||||
|
|
||||||
public func clearCache(for client: Client) async {
|
public func clearCache(for client: String) async {
|
||||||
let engine = storageFor(client)
|
let engine = storageFor(client)
|
||||||
do {
|
do {
|
||||||
try await engine.removeAllData()
|
try await engine.removeAllData()
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
func set(statuses: [Status], client: Client) async {
|
func set(statuses: [Status], client: String) async {
|
||||||
guard !statuses.isEmpty else { return }
|
guard !statuses.isEmpty else { return }
|
||||||
let statuses = statuses.prefix(upTo: min(600, statuses.count - 1)).map { $0 }
|
let statuses = statuses.prefix(upTo: min(600, statuses.count - 1)).map { $0 }
|
||||||
do {
|
do {
|
||||||
|
@ -39,7 +39,7 @@ public actor TimelineCache {
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStatuses(for client: Client) async -> [Status]? {
|
func getStatuses(for client: String) async -> [Status]? {
|
||||||
let engine = storageFor(client)
|
let engine = storageFor(client)
|
||||||
do {
|
do {
|
||||||
return try await engine
|
return try await engine
|
||||||
|
|
|
@ -13,7 +13,7 @@ class TimelineViewModel: ObservableObject {
|
||||||
timelineTask?.cancel()
|
timelineTask?.cancel()
|
||||||
timelineTask = Task {
|
timelineTask = Task {
|
||||||
if timeline == .latest, let client {
|
if timeline == .latest, let client {
|
||||||
await cache.clearCache(for: client)
|
await cache.clearCache(for: client.id)
|
||||||
timeline = .home
|
timeline = .home
|
||||||
}
|
}
|
||||||
if oldValue != timeline {
|
if oldValue != timeline {
|
||||||
|
@ -137,13 +137,13 @@ class TimelineViewModel: ObservableObject {
|
||||||
extension TimelineViewModel {
|
extension TimelineViewModel {
|
||||||
private func cacheHome() async {
|
private func cacheHome() async {
|
||||||
if let client, timeline == .home {
|
if let client, timeline == .home {
|
||||||
await cache.set(statuses: datasource.get(), client: client)
|
await cache.set(statuses: datasource.get(), client: client.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getCachedStatuses() async -> [Status]? {
|
private func getCachedStatuses() async -> [Status]? {
|
||||||
if let client {
|
if let client {
|
||||||
return await cache.getStatuses(for: client)
|
return await cache.getStatuses(for: client.id)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue