notify: switch over to new typesafe notifications

This commit is contained in:
William Casarin
2023-07-30 10:50:41 -07:00
parent 80063af19a
commit b40c595a7c
39 changed files with 129 additions and 289 deletions

View File

@@ -35,14 +35,14 @@ class Contacts {
let new = Set(ev.referenced_pubkeys.map({ $0.ref_id }))
let diff = old.symmetricDifference(new)
var new_mutes = Array<String>()
var new_unmutes = Array<String>()
var new_mutes = Set<Pubkey>()
var new_unmutes = Set<Pubkey>()
for d in diff {
if new.contains(d) {
new_mutes.append(d.string())
new_mutes.insert(d.string())
} else {
new_unmutes.append(d.string())
new_unmutes.insert(d.string())
}
}
@@ -50,11 +50,11 @@ class Contacts {
self.muted = Set(ev.referenced_pubkeys.map({ $0.ref_id.string() }))
if new_mutes.count > 0 {
notify(.new_mutes, new_mutes)
notify(.new_mutes(new_mutes))
}
if new_unmutes.count > 0 {
notify(.new_unmutes, new_unmutes)
notify(.new_unmutes(new_unmutes))
}
}

View File

@@ -7,17 +7,14 @@
import Foundation
enum FollowTarget {
case pubkey(String)
case pubkey(Pubkey)
case contact(NostrEvent)
var pubkey: String {
var pubkey: Pubkey {
switch self {
case .pubkey(let pk):
return pk
case .contact(let ev):
return ev.pubkey
case .pubkey(let pk): return pk
case .contact(let ev): return ev.pubkey
}
}
}

View File

@@ -328,8 +328,8 @@ class HomeModel {
break
case .success(let n):
let boosted = Counted(event: ev, id: e, total: n)
notify(.boosted, boosted)
notify(.update_stats, e)
notify(.reposted(boosted))
notify(.update_stats(note_id: e))
}
}
@@ -349,8 +349,8 @@ class HomeModel {
case .success(let n):
handle_notification(ev: ev)
let liked = Counted(event: ev, id: e.ref_id, total: n)
notify(.liked, liked)
notify(.update_stats, e.ref_id)
notify(.liked(liked))
notify(.update_stats(note_id: e.ref_id))
}
}
@@ -716,12 +716,12 @@ func load_our_contacts(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent)
let diff = new_refs.symmetricDifference(old_refs)
for ref in diff {
if new_refs.contains(ref) {
notify(.followed, ref)
notify(.followed(ref))
if ref.key == "p" {
contacts.add_friend_pubkey(ref.ref_id)
}
} else {
notify(.unfollowed, ref)
notify(.unfollowed(ref))
if ref.key == "p" {
contacts.remove_friend(ref.ref_id)
}
@@ -817,7 +817,7 @@ func process_metadata_profile(our_pubkey: String, profiles: Profiles, profile: P
}
if changed {
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
notify(.profile_updated(pubkey: ev.pubkey, profile: profile))
}
}
@@ -933,7 +933,7 @@ func load_our_relays(state: DamusState, m_old_ev: NostrEvent?, ev: NostrEvent) {
if changed {
save_bootstrap_relays(pubkey: state.pubkey, relays: Array(new))
state.pool.connect()
notify(.relays_changed, ())
notify(.relays_changed)
}
}

View File

@@ -60,11 +60,11 @@ class MutedThreadsManager: ObservableObject {
if isMutedThread(ev, privkey: keypair.privkey) {
mutedThreads = mutedThreads.filter { $0 != threadId }
_mutedThreadsSet.remove(threadId)
notify(.unmute_thread, ev)
notify(.unmute_thread(ev))
} else {
mutedThreads.append(threadId)
_mutedThreadsSet.insert(threadId)
notify(.mute_thread, ev)
notify(.mute_thread(ev))
}
}
}

View File

@@ -38,12 +38,17 @@ struct ReportNoteTarget {
enum ReportTarget {
case user(String)
case note(ReportNoteTarget)
static func note(pubkey: Pubkey, note_id: NoteId) -> ReportTarget {
return .note(ReportNoteTarget(pubkey: pubkey, note_id: note_id))
}
}
struct Report {
let type: ReportType
let target: ReportTarget
let message: String
}
func create_report_tags(target: ReportTarget, type: ReportType) -> [[String]] {

View File

@@ -57,7 +57,7 @@ class WalletModel: ObservableObject {
func connect(_ nwc: WalletConnectURL) {
self.settings.nostr_wallet_connect = nwc.to_url().absoluteString
notify(.attached_wallet, nwc)
notify(.attached_wallet(nwc))
self.connect_state = .existing(nwc)
self.previous_state = .existing(nwc)
}