Preload profile pictures while scrolling
Changelog-Added: Preload profile pictures while scrolling
This commit is contained in:
@@ -132,6 +132,9 @@ struct ImageCarousel: View {
|
|||||||
.imageFill(for: geo.size, max: maxHeight, fill: fillHeight) { fill in
|
.imageFill(for: geo.size, max: maxHeight, fill: fillHeight) { fill in
|
||||||
state.previews.cache_image_meta(evid: evid, image_fill: fill)
|
state.previews.cache_image_meta(evid: evid, image_fill: fill)
|
||||||
// blur hash can be discarded when we have the url
|
// blur hash can be discarded when we have the url
|
||||||
|
// NOTE: this is the wrong place for this... we need to remove
|
||||||
|
// it when the image is loaded in memory. This may happen
|
||||||
|
// earlier than this (by the preloader, etc)
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
|
||||||
state.events.lookup_img_metadata(url: url)?.state = .not_needed
|
state.events.lookup_img_metadata(url: url)?.state = .not_needed
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,11 +337,32 @@ func get_preload_plan(cache: EventData, ev: NostrEvent, our_keypair: Keypair, se
|
|||||||
return PreloadPlan(data: cache, event: ev, load_artifacts: load_artifacts, load_translations: load_translations, load_preview: load_preview)
|
return PreloadPlan(data: cache, event: ev, load_artifacts: load_artifacts, load_translations: load_translations, load_preview: load_preview)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func preload_image(url: URL) {
|
||||||
|
if ImageCache.default.isCached(forKey: url.absoluteString) {
|
||||||
|
print("Preloaded image \(url.absoluteString) found in cache")
|
||||||
|
// looks like we already have it cached. no download needed
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Preloading image \(url.absoluteString)")
|
||||||
|
|
||||||
|
KingfisherManager.shared.retrieveImage(with: ImageResource(downloadURL: url)) { val in
|
||||||
|
print("Preloaded image \(url.absoluteString)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func preload_event(plan: PreloadPlan, profiles: Profiles, our_keypair: Keypair, settings: UserSettingsStore) async {
|
func preload_event(plan: PreloadPlan, profiles: Profiles, our_keypair: Keypair, settings: UserSettingsStore) async {
|
||||||
var artifacts: NoteArtifacts? = plan.data.artifacts.artifacts
|
var artifacts: NoteArtifacts? = plan.data.artifacts.artifacts
|
||||||
|
|
||||||
print("Preloading event \(plan.event.content)")
|
print("Preloading event \(plan.event.content)")
|
||||||
|
|
||||||
|
// preload pfp
|
||||||
|
if let profile = profiles.lookup(id: plan.event.pubkey),
|
||||||
|
let picture = profile.picture,
|
||||||
|
let url = URL(string: picture) {
|
||||||
|
preload_image(url: url)
|
||||||
|
}
|
||||||
|
|
||||||
if artifacts == nil && plan.load_artifacts {
|
if artifacts == nil && plan.load_artifacts {
|
||||||
let arts = render_note_content(ev: plan.event, profiles: profiles, privkey: our_keypair.privkey)
|
let arts = render_note_content(ev: plan.event, profiles: profiles, privkey: our_keypair.privkey)
|
||||||
artifacts = arts
|
artifacts = arts
|
||||||
@@ -352,10 +373,7 @@ func preload_event(plan: PreloadPlan, profiles: Profiles, our_keypair: Keypair,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for url in arts.images {
|
for url in arts.images {
|
||||||
print("Preloading image \(url.absoluteString)")
|
preload_image(url: url)
|
||||||
KingfisherManager.shared.retrieveImage(with: ImageResource(downloadURL: url)) { val in
|
|
||||||
print("Finished preloading image \(url.absoluteString)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user