new account fixes

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-06-08 13:49:04 -07:00
parent 23bb7c7f18
commit 6bca9eb2be
9 changed files with 45 additions and 12 deletions

View File

@@ -64,6 +64,8 @@ class FollowersModel: ObservableObject {
} }
case .notice(let msg): case .notice(let msg):
print("followingmodel notice: \(msg)") print("followingmodel notice: \(msg)")
case .eose:
break
} }
} }
} }

View File

@@ -64,6 +64,8 @@ class FollowingModel {
} }
case .notice(let msg): case .notice(let msg):
print("followingmodel notice: \(msg)") print("followingmodel notice: \(msg)")
case .eose:
break
} }
} }
} }

View File

@@ -176,6 +176,9 @@ class HomeModel: ObservableObject {
case .notice(let msg): case .notice(let msg):
//self.events.insert(NostrEvent(content: "NOTICE from \(relay_id): \(msg)", pubkey: "system"), at: 0) //self.events.insert(NostrEvent(content: "NOTICE from \(relay_id): \(msg)", pubkey: "system"), at: 0)
print(msg) print(msg)
case .eose:
break
} }
} }
} }
@@ -395,11 +398,15 @@ func process_metadata_event(profiles: Profiles, ev: NostrEvent) {
func process_contact_event(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) { func process_contact_event(pool: RelayPool, contacts: Contacts, pubkey: String, ev: NostrEvent) {
load_our_contacts(contacts: contacts, our_pubkey: pubkey, ev: ev) load_our_contacts(contacts: contacts, our_pubkey: pubkey, ev: ev)
load_our_relays(pool: pool, ev: ev) load_our_relays(our_pubkey: pubkey, pool: pool, ev: ev)
add_contact_if_friend(contacts: contacts, ev: ev) add_contact_if_friend(contacts: contacts, ev: ev)
} }
func load_our_relays(pool: RelayPool, ev: NostrEvent) { func load_our_relays(our_pubkey: String, pool: RelayPool, ev: NostrEvent) {
guard ev.pubkey == our_pubkey else {
return
}
guard let decoded = decode_json_relays(ev.content) else { guard let decoded = decode_json_relays(ev.content) else {
return return
} }

View File

@@ -17,6 +17,7 @@ class ProfileModel: ObservableObject {
var seen_event: Set<String> = Set() var seen_event: Set<String> = Set()
var sub_id = UUID().description var sub_id = UUID().description
var prof_subid = UUID().description
func get_follow_target() -> FollowTarget { func get_follow_target() -> FollowTarget {
if let contacts = contacts { if let contacts = contacts {
@@ -33,24 +34,30 @@ class ProfileModel: ObservableObject {
func unsubscribe() { func unsubscribe() {
print("unsubscribing from profile \(pubkey) with sub_id \(sub_id)") print("unsubscribing from profile \(pubkey) with sub_id \(sub_id)")
damus.pool.unsubscribe(sub_id: sub_id) damus.pool.unsubscribe(sub_id: sub_id)
damus.pool.unsubscribe(sub_id: prof_subid)
} }
func subscribe() { func subscribe() {
var text_filter = NostrFilter.filter_kinds([
NostrKind.text.rawValue
])
var profile_filter = NostrFilter.filter_kinds([ var profile_filter = NostrFilter.filter_kinds([
NostrKind.text.rawValue,
NostrKind.boost.rawValue,
NostrKind.metadata.rawValue,
NostrKind.contacts.rawValue, NostrKind.contacts.rawValue,
NostrKind.metadata.rawValue,
NostrKind.boost.rawValue,
NostrKind.like.rawValue NostrKind.like.rawValue
]) ])
profile_filter.authors = [pubkey]
profile_filter.limit = 1000
let filters = [profile_filter] profile_filter.authors = [pubkey]
text_filter.authors = [pubkey]
text_filter.limit = 1000
print("subscribing to profile \(pubkey) with sub_id \(sub_id)") print("subscribing to profile \(pubkey) with sub_id \(sub_id)")
print_filters(relay_id: "profile", filters: [filters]) print_filters(relay_id: "profile", filters: [[text_filter], [profile_filter]])
damus.pool.subscribe(sub_id: sub_id, filters: filters, handler: handle_event) damus.pool.subscribe(sub_id: sub_id, filters: [text_filter], handler: handle_event)
damus.pool.subscribe(sub_id: prof_subid, filters: [profile_filter], handler: handle_event)
} }
func handle_profile_contact_event(_ ev: NostrEvent) { func handle_profile_contact_event(_ ev: NostrEvent) {
@@ -86,6 +93,8 @@ class ProfileModel: ObservableObject {
add_event(ev) add_event(ev)
case .notice(let notice): case .notice(let notice):
notify(.notice, notice) notify(.notice, notice)
case .eose:
break
} }
} }
} }

View File

@@ -51,6 +51,8 @@ class SearchHomeModel: ObservableObject {
} }
case .notice(let msg): case .notice(let msg):
print("search home notice: \(msg)") print("search home notice: \(msg)")
case .eose:
break
} }
} }
} }

View File

@@ -91,6 +91,9 @@ func handle_subid_event(pool: RelayPool, sub_id: String, relay_id: String, ev: N
pool.reconnect(to: [relay_id]) pool.reconnect(to: [relay_id])
} }
break break
case .eose:
break
} }
} }
} }

View File

@@ -10,6 +10,7 @@ import Foundation
enum NostrResponse: Decodable { enum NostrResponse: Decodable {
case event(String, NostrEvent) case event(String, NostrEvent)
case notice(String) case notice(String)
case eose
init(from decoder: Decoder) throws { init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer() var container = try decoder.unkeyedContainer()
@@ -32,6 +33,9 @@ enum NostrResponse: Decodable {
let msg = try container.decode(String.self) let msg = try container.decode(String.self)
self = .notice(msg) self = .notice(msg)
return return
} else if typ == "EOSE" {
self = .eose
return
} }
throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "expected EVENT or NOTICE, got \(typ)")) throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "expected EVENT or NOTICE, got \(typ)"))

View File

@@ -13,11 +13,13 @@ struct ProfilePictureSelector: View {
var body: some View { var body: some View {
let highlight: Highlight = .custom(Color.white, 2.0) let highlight: Highlight = .custom(Color.white, 2.0)
ZStack { ZStack {
ProfilePicView(pubkey: pubkey, size: 80.0, highlight: highlight, image_cache: ImageCache(), profiles: Profiles()) /*
Image(systemName: "camera") Image(systemName: "camera")
.font(.title) .font(.title)
.foregroundColor(.white) .foregroundColor(.white)
*/
ProfilePicView(pubkey: pubkey, size: 80.0, highlight: highlight, image_cache: ImageCache(), profiles: Profiles())
} }
} }
} }

View File

@@ -121,6 +121,8 @@ struct SaveKeysView: View {
print(msg) print(msg)
case .event: case .event:
print("event in signup?") print("event in signup?")
case .eose:
break
} }
} }
} }