From 7da7bcdfd5aa490e4c913f2d0568ed53f901c967 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Sat, 6 Aug 2022 13:52:36 -0700 Subject: [PATCH] make robohash a function Signed-off-by: William Casarin --- damus/Models/HomeModel.swift | 6 +++++- damus/Views/ProfilePicView.swift | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift index 5b69ee6d..c0d90e52 100644 --- a/damus/Models/HomeModel.swift +++ b/damus/Models/HomeModel.swift @@ -506,7 +506,7 @@ func process_metadata_event(image_cache: ImageCache, profiles: Profiles, ev: Nos profiles.add(id: ev.pubkey, profile: tprof) // load pfps asap - let picture = tprof.profile.picture ?? "https://robohash.org/\(ev.pubkey)" + let picture = tprof.profile.picture ?? robohash(ev.pubkey) if let url = URL(string: picture) { Task.init(priority: .background) { let res = await load_image(cache: image_cache, from: url) @@ -520,6 +520,10 @@ func process_metadata_event(image_cache: ImageCache, profiles: Profiles, ev: Nos notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile)) } +func robohash(_ pk: String) -> String { + return "https://robohash.org/" + pk +} + func process_contact_event(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) { load_our_contacts(contacts: contacts, our_pubkey: pubkey, ev: ev) load_our_relays(our_pubkey: pubkey, pool: pool, ev: ev) diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift index f8a3a4d2..88ea3c86 100644 --- a/damus/Views/ProfilePicView.swift +++ b/damus/Views/ProfilePicView.swift @@ -76,7 +76,7 @@ struct ProfilePicView: View { var MainContent: some View { Group { - let picture = picture ?? profiles.lookup(id: pubkey)?.picture ?? "https://robohash.org/\(pubkey).png" + let picture = picture ?? profiles.lookup(id: pubkey)?.picture ?? robohash(pubkey) if let pic_url = URL(string: picture) { ProfilePic(pic_url) } else {