mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-04-27 02:14:45 +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 path: [RouterDestination] = []
|
||||||
@Published public var presentedSheet: SheetDestination?
|
@Published public var presentedSheet: SheetDestination?
|
||||||
|
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
public func navigate(to: RouterDestination) {
|
public func navigate(to: RouterDestination) {
|
||||||
|
@ -94,12 +95,14 @@ public class RouterPath: ObservableObject {
|
||||||
client.hasConnection(with: url),
|
client.hasConnection(with: url),
|
||||||
let id = Int(url.lastPathComponent)
|
let id = Int(url.lastPathComponent)
|
||||||
{
|
{
|
||||||
if url.absoluteString.contains(client.server) {
|
if !StatusEmbedCache.shared.badStatusesURLs.contains(url) {
|
||||||
navigate(to: .statusDetail(id: String(id)))
|
if url.absoluteString.contains(client.server) {
|
||||||
} else {
|
navigate(to: .statusDetail(id: String(id)))
|
||||||
navigate(to: .remoteStatusDetail(url: url))
|
} else {
|
||||||
|
navigate(to: .remoteStatusDetail(url: url))
|
||||||
|
}
|
||||||
|
return .handled
|
||||||
}
|
}
|
||||||
return .handled
|
|
||||||
}
|
}
|
||||||
return urlHandler?(url) ?? .systemAction
|
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
|
let content = status.reblog?.content ?? status.content
|
||||||
if !content.statusesURLs.isEmpty,
|
if !content.statusesURLs.isEmpty,
|
||||||
let url = content.statusesURLs.first,
|
let url = content.statusesURLs.first,
|
||||||
client.hasConnection(with: url)
|
!StatusEmbedCache.shared.badStatusesURLs.contains(url),
|
||||||
{
|
client.hasConnection(with: url) {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -197,7 +197,7 @@ public class StatusRowViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if let embed = StatusEmbedCache.shared.get(url: url) {
|
if let embed = StatusEmbedCache.shared.get(url: url) {
|
||||||
isEmbedLoading = false
|
isEmbedLoading = false
|
||||||
embeddedStatus = embed
|
embeddedStatus = embed
|
||||||
|
@ -220,12 +220,16 @@ public class StatusRowViewModel: ObservableObject {
|
||||||
if let embed {
|
if let embed {
|
||||||
StatusEmbedCache.shared.set(url: url, status: embed)
|
StatusEmbedCache.shared.set(url: url, status: embed)
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
StatusEmbedCache.shared.badStatusesURLs.insert(url)
|
||||||
|
}
|
||||||
withAnimation {
|
withAnimation {
|
||||||
embeddedStatus = embed
|
embeddedStatus = embed
|
||||||
isEmbedLoading = false
|
isEmbedLoading = false
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
isEmbedLoading = false
|
isEmbedLoading = false
|
||||||
|
StatusEmbedCache.shared.badStatusesURLs.insert(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue