Also broadcast event's user profile

This should help propagation of user profiles

Changelog-Changed: Broadcast now also broadcasts event user's profile
This commit is contained in:
William Casarin
2023-04-03 09:47:15 -07:00
parent c9c51c6d4a
commit cc190c3618
4 changed files with 11 additions and 4 deletions

View File

@@ -18,6 +18,7 @@ var BOOTSTRAP_RELAYS = [
struct TimestampedProfile { struct TimestampedProfile {
let profile: Profile let profile: Profile
let timestamp: Int64 let timestamp: Int64
let event: NostrEvent
} }
enum Sheets: Identifiable { enum Sheets: Identifiable {
@@ -382,7 +383,13 @@ struct ContentView: View {
} }
.onReceive(handle_notify(.broadcast_event)) { obj in .onReceive(handle_notify(.broadcast_event)) { obj in
let ev = obj.object as! NostrEvent let ev = obj.object as! NostrEvent
self.damus_state?.pool.send(.event(ev)) guard let ds = self.damus_state else {
return
}
ds.postbox.send(ev)
if let profile = ds.profiles.profiles[ev.pubkey] {
ds.postbox.send(profile.event)
}
} }
.onReceive(handle_notify(.unfollow)) { notif in .onReceive(handle_notify(.unfollow)) { notif in
guard let privkey = self.privkey else { guard let privkey = self.privkey else {

View File

@@ -667,7 +667,7 @@ func process_metadata_event(our_pubkey: String, profiles: Profiles, ev: NostrEve
} }
} }
let tprof = TimestampedProfile(profile: profile, timestamp: ev.created_at) let tprof = TimestampedProfile(profile: profile, timestamp: ev.created_at, event: ev)
profiles.add(id: ev.pubkey, profile: tprof) profiles.add(id: ev.pubkey, profile: tprof)
if let nip05 = profile.nip05, old_nip05 != profile.nip05 { if let nip05 = profile.nip05, old_nip05 != profile.nip05 {

View File

@@ -172,7 +172,7 @@ func make_preview_profiles(_ pubkey: String) -> Profiles {
let profiles = Profiles() let profiles = Profiles()
let picture = "http://cdn.jb55.com/img/red-me.jpg" let picture = "http://cdn.jb55.com/img/red-me.jpg"
let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com") let profile = Profile(name: "jb55", display_name: "William Casarin", about: "It's me", picture: picture, banner: "", website: "https://jb55.com", lud06: nil, lud16: nil, nip05: "jb55.com")
let ts_profile = TimestampedProfile(profile: profile, timestamp: 0) let ts_profile = TimestampedProfile(profile: profile, timestamp: 0, event: test_event)
profiles.add(id: pubkey, profile: ts_profile) profiles.add(id: pubkey, profile: ts_profile)
return profiles return profiles
} }

View File

@@ -480,7 +480,7 @@ func test_damus_state() -> DamusState {
let damus = DamusState.empty let damus = DamusState.empty
let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io") let prof = Profile(name: "damus", display_name: "damus", about: "iOS app!", picture: "https://damus.io/img/logo.png", banner: "", website: "https://damus.io", lud06: nil, lud16: "jb55@sendsats.lol", nip05: "damus.io")
let tsprof = TimestampedProfile(profile: prof, timestamp: 0) let tsprof = TimestampedProfile(profile: prof, timestamp: 0, event: test_event)
damus.profiles.add(id: pubkey, profile: tsprof) damus.profiles.add(id: pubkey, profile: tsprof)
return damus return damus
} }