Fix a few more hitches
This commit is contained in:
@@ -651,60 +651,65 @@ func print_filters(relay_id: String?, filters groups: [[NostrFilter]]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func process_metadata_event(our_pubkey: String, profiles: Profiles, ev: NostrEvent) {
|
func process_metadata_event(our_pubkey: String, profiles: Profiles, ev: NostrEvent) {
|
||||||
guard let profile: Profile = decode_data(Data(ev.content.utf8)) else {
|
DispatchQueue.global(qos: .background).async {
|
||||||
return
|
guard let profile: Profile = decode_data(Data(ev.content.utf8)) else {
|
||||||
}
|
|
||||||
|
|
||||||
if our_pubkey == ev.pubkey && (profile.deleted ?? false) {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
notify(.deleted_account, ())
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var old_nip05: String? = nil
|
|
||||||
if let mprof = profiles.lookup_with_timestamp(id: ev.pubkey) {
|
|
||||||
old_nip05 = mprof.profile.nip05
|
|
||||||
if mprof.timestamp > ev.created_at {
|
|
||||||
// skip if we already have an newer profile
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
if our_pubkey == ev.pubkey && (profile.deleted ?? false) {
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
notify(.deleted_account, ())
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let tprof = TimestampedProfile(profile: profile, timestamp: ev.created_at, event: ev)
|
var old_nip05: String? = nil
|
||||||
profiles.add(id: ev.pubkey, profile: tprof)
|
if let mprof = profiles.lookup_with_timestamp(id: ev.pubkey) {
|
||||||
|
old_nip05 = mprof.profile.nip05
|
||||||
if let nip05 = profile.nip05, old_nip05 != profile.nip05 {
|
if mprof.timestamp > ev.created_at {
|
||||||
Task.detached(priority: .background) {
|
// skip if we already have an newer profile
|
||||||
let validated = await validate_nip05(pubkey: ev.pubkey, nip05_str: nip05)
|
return
|
||||||
if validated != nil {
|
}
|
||||||
print("validated nip05 for '\(nip05)'")
|
}
|
||||||
|
|
||||||
|
let tprof = TimestampedProfile(profile: profile, timestamp: ev.created_at, event: ev)
|
||||||
|
profiles.add(id: ev.pubkey, profile: tprof)
|
||||||
|
|
||||||
|
if let nip05 = profile.nip05, old_nip05 != profile.nip05 {
|
||||||
|
Task.detached(priority: .background) {
|
||||||
|
let validated = await validate_nip05(pubkey: ev.pubkey, nip05_str: nip05)
|
||||||
|
if validated != nil {
|
||||||
|
print("validated nip05 for '\(nip05)'")
|
||||||
|
}
|
||||||
|
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
profiles.validated[ev.pubkey] = validated
|
||||||
|
profiles.nip05_pubkey[nip05] = ev.pubkey
|
||||||
|
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
// load pfps asap
|
||||||
profiles.validated[ev.pubkey] = validated
|
let picture = tprof.profile.picture ?? robohash(ev.pubkey)
|
||||||
profiles.nip05_pubkey[nip05] = ev.pubkey
|
if URL(string: picture) != nil {
|
||||||
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
DispatchQueue.main.async {
|
||||||
|
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
let banner = tprof.profile.banner ?? ""
|
||||||
|
if URL(string: banner) != nil {
|
||||||
// load pfps asap
|
DispatchQueue.main.async {
|
||||||
let picture = tprof.profile.picture ?? robohash(ev.pubkey)
|
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
||||||
if URL(string: picture) != nil {
|
}
|
||||||
DispatchQueue.main.async {
|
}
|
||||||
|
|
||||||
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let banner = tprof.profile.banner ?? ""
|
|
||||||
if URL(string: banner) != nil {
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func robohash(_ pk: String) -> String {
|
func robohash(_ pk: String) -> String {
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class NostrEvent: Codable, Identifiable, CustomStringConvertible, Equatable, Has
|
|||||||
}
|
}
|
||||||
|
|
||||||
var too_big: Bool {
|
var too_big: Bool {
|
||||||
return self.content.count > 16000
|
return self.content.underestimatedCount > 16000
|
||||||
}
|
}
|
||||||
|
|
||||||
var should_show_event: Bool {
|
var should_show_event: Bool {
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ final class RelayConnection: WebSocketDelegate {
|
|||||||
self.isConnected = false
|
self.isConnected = false
|
||||||
|
|
||||||
case .text(let txt):
|
case .text(let txt):
|
||||||
if txt.count > 2000 {
|
if txt.underestimatedCount > 2000 {
|
||||||
DispatchQueue.global(qos: .default).async {
|
DispatchQueue.global(qos: .default).async {
|
||||||
if let ev = decode_nostr_event(txt: txt) {
|
if let ev = decode_nostr_event(txt: txt) {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|||||||
Reference in New Issue
Block a user