mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-03-28 12:35:27 +00:00
Record quote toots that have failed to load so that we don't try and load them again. (#1119)
* Record quote toots that have failed to load so that we don't try and load them again. Fixes 1: Repeated visible insertion and removal of placeholder quote toot. 2: Link hijacking of inline status viewer allowing links to be followed as regular URLs * Move set * Add back to routeur check --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
parent
7207a188ce
commit
bd1593a107
4 changed files with 37 additions and 28 deletions
|
@ -68,6 +68,7 @@ public class RouterPath: ObservableObject {
|
|||
@Published public var path: [RouterDestination] = []
|
||||
@Published public var presentedSheet: SheetDestination?
|
||||
|
||||
|
||||
public init() {}
|
||||
|
||||
public func navigate(to: RouterDestination) {
|
||||
|
@ -94,12 +95,14 @@ public class RouterPath: ObservableObject {
|
|||
client.hasConnection(with: url),
|
||||
let id = Int(url.lastPathComponent)
|
||||
{
|
||||
if url.absoluteString.contains(client.server) {
|
||||
navigate(to: .statusDetail(id: String(id)))
|
||||
} else {
|
||||
navigate(to: .remoteStatusDetail(url: url))
|
||||
if !StatusEmbedCache.shared.badStatusesURLs.contains(url) {
|
||||
if url.absoluteString.contains(client.server) {
|
||||
navigate(to: .statusDetail(id: String(id)))
|
||||
} else {
|
||||
navigate(to: .remoteStatusDetail(url: url))
|
||||
}
|
||||
return .handled
|
||||
}
|
||||
return .handled
|
||||
}
|
||||
return urlHandler?(url) ?? .systemAction
|
||||
}
|
||||
|
|
22
Packages/Env/Sources/Env/StatusEmbedCache.swift
Normal file
22
Packages/Env/Sources/Env/StatusEmbedCache.swift
Normal file
|
@ -0,0 +1,22 @@
|
|||
import Foundation
|
||||
import Models
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
public class StatusEmbedCache {
|
||||
public static let shared = StatusEmbedCache()
|
||||
|
||||
private var cache: [URL: Status] = [:]
|
||||
|
||||
public var badStatusesURLs = Set<URL>()
|
||||
|
||||
private init() {}
|
||||
|
||||
public func set(url: URL, status: Status) {
|
||||
cache[url] = status
|
||||
}
|
||||
|
||||
public func get(url: URL) -> Status? {
|
||||
cache[url]
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
import Foundation
|
||||
import Models
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
class StatusEmbedCache {
|
||||
static let shared = StatusEmbedCache()
|
||||
|
||||
private var cache: [URL: Status] = [:]
|
||||
|
||||
private init() {}
|
||||
|
||||
func set(url: URL, status: Status) {
|
||||
cache[url] = status
|
||||
}
|
||||
|
||||
func get(url: URL) -> Status? {
|
||||
cache[url]
|
||||
}
|
||||
}
|
|
@ -181,8 +181,8 @@ public class StatusRowViewModel: ObservableObject {
|
|||
let content = status.reblog?.content ?? status.content
|
||||
if !content.statusesURLs.isEmpty,
|
||||
let url = content.statusesURLs.first,
|
||||
client.hasConnection(with: url)
|
||||
{
|
||||
!StatusEmbedCache.shared.badStatusesURLs.contains(url),
|
||||
client.hasConnection(with: url) {
|
||||
return url
|
||||
}
|
||||
return nil
|
||||
|
@ -197,7 +197,7 @@ public class StatusRowViewModel: ObservableObject {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if let embed = StatusEmbedCache.shared.get(url: url) {
|
||||
isEmbedLoading = false
|
||||
embeddedStatus = embed
|
||||
|
@ -220,12 +220,16 @@ public class StatusRowViewModel: ObservableObject {
|
|||
if let embed {
|
||||
StatusEmbedCache.shared.set(url: url, status: embed)
|
||||
}
|
||||
else {
|
||||
StatusEmbedCache.shared.badStatusesURLs.insert(url)
|
||||
}
|
||||
withAnimation {
|
||||
embeddedStatus = embed
|
||||
isEmbedLoading = false
|
||||
}
|
||||
} catch {
|
||||
isEmbedLoading = false
|
||||
StatusEmbedCache.shared.badStatusesURLs.insert(url)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue