Browse Source

contact: update contact event on follow/unfollow

Signed-off-by: William Casarin <jb55@jb55.com>
profiles-everywhere
William Casarin 3 years ago
parent
commit
471f29f7ea
  1. 8
      damus/ContentView.swift
  2. 13
      damus/Models/Contacts.swift

8
damus/ContentView.swift

@ -248,12 +248,14 @@ struct ContentView: View {
let target = notif.object as! FollowTarget let target = notif.object as! FollowTarget
let pk = target.pubkey let pk = target.pubkey
if unfollow_user(pool: damus.pool, if let ev = unfollow_user(pool: damus.pool,
our_contacts: damus.contacts.event, our_contacts: damus.contacts.event,
pubkey: damus.pubkey, pubkey: damus.pubkey,
privkey: privkey, privkey: privkey,
unfollow: pk) { unfollow: pk) {
notify(.unfollowed, pk) notify(.unfollowed, pk)
damus.contacts.event = ev
damus.contacts.remove_friend(pk) damus.contacts.remove_friend(pk)
//friend_events = friend_events.filter { $0.pubkey != pk } //friend_events = friend_events.filter { $0.pubkey != pk }
} }
@ -268,13 +270,15 @@ struct ContentView: View {
return return
} }
if follow_user(pool: damus.pool, if let ev = follow_user(pool: damus.pool,
our_contacts: damus.contacts.event, our_contacts: damus.contacts.event,
pubkey: damus.pubkey, pubkey: damus.pubkey,
privkey: privkey, privkey: privkey,
follow: ReferencedId(ref_id: fnotify.pubkey, relay_id: nil, key: "p")) { follow: ReferencedId(ref_id: fnotify.pubkey, relay_id: nil, key: "p")) {
notify(.followed, fnotify.pubkey) notify(.followed, fnotify.pubkey)
damus_state?.contacts.event = ev
switch fnotify { switch fnotify {
case .pubkey(let pk): case .pubkey(let pk):
damus.contacts.add_friend_pubkey(pk) damus.contacts.add_friend_pubkey(pk)

13
damus/Models/Contacts.swift

@ -79,22 +79,23 @@ func create_contacts_content(_ relays: [RelayDescriptor]) -> String? {
} }
func follow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, privkey: String, follow: ReferencedId) -> Bool { func follow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, privkey: String, follow: ReferencedId) -> NostrEvent? {
guard let ev = follow_user_event(our_contacts: our_contacts, our_pubkey: pubkey, follow: follow) else { guard let ev = follow_user_event(our_contacts: our_contacts, our_pubkey: pubkey, follow: follow) else {
return false return nil
} }
ev.calculate_id() ev.calculate_id()
ev.sign(privkey: privkey) ev.sign(privkey: privkey)
pool.send(.event(ev)) pool.send(.event(ev))
return true return ev
} }
func unfollow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, privkey: String, unfollow: String) -> Bool { func unfollow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, privkey: String, unfollow: String) -> NostrEvent? {
guard let cs = our_contacts else { guard let cs = our_contacts else {
return false return nil
} }
let ev = unfollow_user_event(our_contacts: cs, our_pubkey: pubkey, unfollow: unfollow) let ev = unfollow_user_event(our_contacts: cs, our_pubkey: pubkey, unfollow: unfollow)
@ -103,7 +104,7 @@ func unfollow_user(pool: RelayPool, our_contacts: NostrEvent?, pubkey: String, p
pool.send(.event(ev)) pool.send(.event(ev))
return true return ev
} }
func unfollow_user_event(our_contacts: NostrEvent, our_pubkey: String, unfollow: String) -> NostrEvent { func unfollow_user_event(our_contacts: NostrEvent, our_pubkey: String, unfollow: String) -> NostrEvent {

Loading…
Cancel
Save