refactor: add Pubkey, Privkey, NoteId string aliases

This is a non-behavioral change in preparation for the actual switchover
from Strings to Ids. The purpose of this kit is to reduce the size of
the switchover commit which is going to be very large.
This commit is contained in:
William Casarin
2023-07-31 03:57:26 -07:00
parent f9d21ef901
commit 7040235605
101 changed files with 427 additions and 426 deletions

View File

@@ -40,7 +40,7 @@ class ActionBarModel: ObservableObject {
self.our_reply = our_reply
}
func update(damus: DamusState, evid: String) {
func update(damus: DamusState, evid: NoteId) {
self.likes = damus.likes.counts[evid] ?? 0
self.boosts = damus.boosts.counts[evid] ?? 0
self.zaps = damus.zaps.event_counts[evid] ?? 0

View File

@@ -7,18 +7,18 @@
import Foundation
fileprivate func get_bookmarks_key(pubkey: String) -> String {
fileprivate func get_bookmarks_key(pubkey: Pubkey) -> String {
pk_setting_key(pubkey, key: "bookmarks")
}
func load_bookmarks(pubkey: String) -> [NostrEvent] {
func load_bookmarks(pubkey: Pubkey) -> [NostrEvent] {
let key = get_bookmarks_key(pubkey: pubkey)
return (UserDefaults.standard.stringArray(forKey: key) ?? []).compactMap {
event_from_json(dat: $0)
}
}
func save_bookmarks(pubkey: String, current_value: [NostrEvent], value: [NostrEvent]) -> Bool {
func save_bookmarks(pubkey: Pubkey, current_value: [NostrEvent], value: [NostrEvent]) -> Bool {
let uniq_bookmarks = uniq(value)
if uniq_bookmarks != current_value {
@@ -32,8 +32,8 @@ func save_bookmarks(pubkey: String, current_value: [NostrEvent], value: [NostrEv
class BookmarksManager: ObservableObject {
private let pubkey: String
private let pubkey: Pubkey
private var _bookmarks: [NostrEvent]
var bookmarks: [NostrEvent] {
get {
@@ -47,7 +47,7 @@ class BookmarksManager: ObservableObject {
}
}
init(pubkey: String) {
init(pubkey: Pubkey) {
self._bookmarks = load_bookmarks(pubkey: pubkey)
self.pubkey = pubkey
}

View File

@@ -9,21 +9,21 @@ import Foundation
class Contacts {
private var friends: Set<String> = Set()
private var friend_of_friends: Set<String> = Set()
private var friends: Set<Pubkey> = Set()
private var friend_of_friends: Set<Pubkey> = Set()
/// Tracks which friends are friends of a given pubkey.
private var pubkey_to_our_friends = [String : Set<String>]()
private var muted: Set<String> = Set()
let our_pubkey: String
private var pubkey_to_our_friends = [Pubkey : Set<Pubkey>]()
private var muted: Set<Pubkey> = Set()
let our_pubkey: Pubkey
var event: NostrEvent?
var mutelist: NostrEvent?
init(our_pubkey: String) {
init(our_pubkey: Pubkey) {
self.our_pubkey = our_pubkey
}
func is_muted(_ pk: String) -> Bool {
func is_muted(_ pk: Pubkey) -> Bool {
return muted.contains(pk)
}
@@ -58,7 +58,7 @@ class Contacts {
}
}
func remove_friend(_ pubkey: String) {
func remove_friend(_ pubkey: Pubkey) {
friends.remove(pubkey)
pubkey_to_our_friends.forEach {
@@ -66,7 +66,7 @@ class Contacts {
}
}
func get_friend_list() -> Set<String> {
func get_friend_list() -> Set<Pubkey> {
return friends
}
@@ -75,7 +75,7 @@ class Contacts {
return Set(ev.referenced_hashtags.map({ $0.ref_id.string() }))
}
func add_friend_pubkey(_ pubkey: String) {
func add_friend_pubkey(_ pubkey: Pubkey) {
friends.insert(pubkey)
}
@@ -88,7 +88,7 @@ class Contacts {
// Exclude themself and us.
if contact.pubkey != our_pubkey && contact.pubkey != pk {
if pubkey_to_our_friends[pk] == nil {
pubkey_to_our_friends[pk] = Set<String>()
pubkey_to_our_friends[pk] = Set<Pubkey>()
}
pubkey_to_our_friends[pk]?.insert(contact.pubkey)
@@ -96,28 +96,28 @@ class Contacts {
}
}
func is_friend_of_friend(_ pubkey: String) -> Bool {
func is_friend_of_friend(_ pubkey: Pubkey) -> Bool {
return friend_of_friends.contains(pubkey)
}
func is_in_friendosphere(_ pubkey: String) -> Bool {
func is_in_friendosphere(_ pubkey: Pubkey) -> Bool {
return friends.contains(pubkey) || friend_of_friends.contains(pubkey)
}
func is_friend(_ pubkey: String) -> Bool {
func is_friend(_ pubkey: Pubkey) -> Bool {
return friends.contains(pubkey)
}
func is_friend_or_self(_ pubkey: String) -> Bool {
func is_friend_or_self(_ pubkey: Pubkey) -> Bool {
return pubkey == our_pubkey || is_friend(pubkey)
}
func follow_state(_ pubkey: String) -> FollowState {
func follow_state(_ pubkey: Pubkey) -> FollowState {
return is_friend(pubkey) ? .follows : .unfollows
}
/// Gets the list of pubkeys of our friends who follow the given pubkey.
func get_friended_followers(_ pubkey: String) -> [String] {
func get_friended_followers(_ pubkey: Pubkey) -> [Pubkey] {
return Array((pubkey_to_our_friends[pubkey] ?? Set()))
}
}

View File

@@ -12,8 +12,8 @@ class CreateAccountModel: ObservableObject {
@Published var real_name: String = ""
@Published var nick_name: String = ""
@Published var about: String = ""
@Published var pubkey: String = ""
@Published var privkey: String = ""
@Published var pubkey: Pubkey = .empty
@Published var privkey: Privkey = .empty
@Published var profile_image: URL? = nil
var pubkey_bech32: String {

View File

@@ -50,7 +50,7 @@ struct DamusState {
return stored
}
var pubkey: String {
var pubkey: Pubkey {
return keypair.pubkey
}

View File

@@ -16,11 +16,11 @@ class DirectMessageModel: ObservableObject {
@Published var draft: String = ""
let pubkey: String
let pubkey: Pubkey
var is_request = false
var our_pubkey: String
var our_pubkey: Pubkey
func determine_is_request() -> Bool {
for event in events {
if event.pubkey == our_pubkey {
@@ -31,7 +31,7 @@ class DirectMessageModel: ObservableObject {
return true
}
init(events: [NostrEvent] = [], our_pubkey: String, pubkey: String) {
init(events: [NostrEvent] = [], our_pubkey: Pubkey, pubkey: Pubkey) {
self.events = events
self.our_pubkey = our_pubkey
self.pubkey = pubkey

View File

@@ -11,10 +11,10 @@ class DirectMessagesModel: ObservableObject {
@Published var dms: [DirectMessageModel] = []
@Published var loading: Bool = false
@Published var open_dm: Bool = false
@Published private(set) var active_model: DirectMessageModel = DirectMessageModel(our_pubkey: "", pubkey: "")
let our_pubkey: String
init(our_pubkey: String) {
@Published private(set) var active_model: DirectMessageModel = DirectMessageModel(our_pubkey: .empty, pubkey: .empty)
let our_pubkey: Pubkey
init(our_pubkey: Pubkey) {
self.our_pubkey = our_pubkey
}
@@ -30,14 +30,14 @@ class DirectMessagesModel: ObservableObject {
self.active_model = model
}
func set_active_dm(_ pubkey: String) {
func set_active_dm(_ pubkey: Pubkey) {
for model in self.dms where model.pubkey == pubkey {
self.set_active_dm_model(model)
break
}
}
func lookup_or_create(_ pubkey: String) -> DirectMessageModel {
func lookup_or_create(_ pubkey: Pubkey) -> DirectMessageModel {
if let dm = lookup(pubkey) {
return dm
}
@@ -47,7 +47,7 @@ class DirectMessagesModel: ObservableObject {
return new
}
func lookup(_ pubkey: String) -> DirectMessageModel? {
func lookup(_ pubkey: Pubkey) -> DirectMessageModel? {
for dm in dms {
if pubkey == dm.pubkey {
return dm

View File

@@ -10,14 +10,14 @@ import Foundation
class EventsModel: ObservableObject {
let state: DamusState
let target: String
let target: NoteId
let kind: NostrKind
let sub_id = UUID().uuidString
let profiles_id = UUID().uuidString
@Published var events: [NostrEvent] = []
init(state: DamusState, target: String, kind: NostrKind) {
init(state: DamusState, target: NoteId, kind: NostrKind) {
self.state = state
self.target = target
self.kind = kind

View File

@@ -9,11 +9,11 @@ import Foundation
class FollowersModel: ObservableObject {
let damus_state: DamusState
let target: String
@Published var contacts: [String]? = nil
var has_contact: Set<String> = Set()
let target: Pubkey
@Published var contacts: [Pubkey]? = nil
var has_contact: Set<Pubkey> = Set()
let sub_id: String = UUID().description
let profiles_id: String = UUID().description
@@ -24,14 +24,13 @@ class FollowersModel: ObservableObject {
return contacts.count
}
init(damus_state: DamusState, target: String) {
init(damus_state: DamusState, target: Pubkey) {
self.damus_state = damus_state
self.target = target
}
func get_filter() -> NostrFilter {
NostrFilter(kinds: [.contacts],
pubkeys: [target])
NostrFilter(kinds: [.contacts], pubkeys: [target])
}
func subscribe() {

View File

@@ -11,18 +11,18 @@ class FollowingModel {
let damus_state: DamusState
var needs_sub: Bool = true
let contacts: [String]
let contacts: [Pubkey]
let sub_id: String = UUID().description
init(damus_state: DamusState, contacts: [String]) {
init(damus_state: DamusState, contacts: [Pubkey]) {
self.damus_state = damus_state
self.contacts = contacts
}
func get_filter() -> NostrFilter {
var f = NostrFilter(kinds: [.metadata])
f.authors = self.contacts.reduce(into: Array<String>()) { acc, pk in
f.authors = self.contacts.reduce(into: Array<Pubkey>()) { acc, pk in
// don't fetch profiles we already have
if damus_state.profiles.has_fresh_profile(id: pk) {
return

View File

@@ -29,7 +29,7 @@ enum Resubscribe {
}
enum HomeResubFilter {
case pubkey(String)
case pubkey(Pubkey)
case hashtag(String)
init?(from: ReferencedId) {
@@ -63,9 +63,10 @@ class HomeModel {
var damus_state: DamusState
var has_event: [String: Set<String>] = [:]
var deleted_events: Set<String> = Set()
var channels: [String: NostrEvent] = [:]
// NDBTODO: let's get rid of this entirely, let nostrdb handle it
var has_event: [String: Set<NoteId>] = [:]
var deleted_events: Set<NoteId> = Set()
var last_event_of_kind: [String: [UInt32: NostrEvent]] = [:]
var done_init: Bool = false
var incoming_dms: [NostrEvent] = []
@@ -109,7 +110,7 @@ class HomeModel {
return damus_state.dms
}
func has_sub_id_event(sub_id: String, ev_id: String) -> Bool {
func has_sub_id_event(sub_id: String, ev_id: NoteId) -> Bool {
if !has_event.keys.contains(sub_id) {
has_event[sub_id] = Set()
return false
@@ -502,13 +503,13 @@ class HomeModel {
pool.send(.unsubscribe(home_subid))
}
func get_friends() -> [String] {
func get_friends() -> [Pubkey] {
var friends = damus_state.contacts.get_friend_list()
friends.insert(damus_state.pubkey)
return Array(friends)
}
func subscribe_to_home_filters(friends fs: [String]? = nil, relay_id: String? = nil) {
func subscribe_to_home_filters(friends fs: [Pubkey]? = nil, relay_id: String? = nil) {
// TODO: separate likes?
var home_filter_kinds: [NostrKind] = [
.text, .longform, .boost
@@ -782,7 +783,7 @@ func print_filters(relay_id: String?, filters groups: [[NostrFilter]]) {
print("-----")
}
func process_metadata_profile(our_pubkey: String, profiles: Profiles, profile: Profile, ev: NostrEvent) {
func process_metadata_profile(our_pubkey: Pubkey, profiles: Profiles, profile: Profile, ev: NostrEvent) {
var old_nip05: String? = nil
let mprof = profiles.lookup_with_timestamp(id: ev.pubkey)
@@ -847,7 +848,7 @@ func guard_valid_event(events: EventCache, ev: NostrEvent, callback: @escaping (
}
}
func process_metadata_event(events: EventCache, our_pubkey: String, profiles: Profiles, ev: NostrEvent, completion: ((Profile?) -> Void)? = nil) {
func process_metadata_event(events: EventCache, our_pubkey: Pubkey, profiles: Profiles, ev: NostrEvent, completion: ((Profile?) -> Void)? = nil) {
guard_valid_event(events: events, ev: ev) {
DispatchQueue.global(qos: .background).async {
guard let profile: Profile = decode_data(Data(ev.content.utf8)) else {
@@ -865,8 +866,8 @@ func process_metadata_event(events: EventCache, our_pubkey: String, profiles: Pr
}
}
func robohash(_ pk: String) -> String {
return "https://robohash.org/" + pk
func robohash(_ pk: Pubkey) -> String {
return "https://robohash.org/" + pk.hex()
}
func load_our_stuff(state: DamusState, ev: NostrEvent) {
@@ -1171,7 +1172,7 @@ func zap_notification_body(profiles: Profiles, zap: Zap, locale: Locale = Locale
}
}
func create_in_app_profile_zap_notification(profiles: Profiles, zap: Zap, locale: Locale = Locale.current, profile_id: String) {
func create_in_app_profile_zap_notification(profiles: Profiles, zap: Zap, locale: Locale = Locale.current, profile_id: Pubkey) {
let content = UNMutableNotificationContent()
content.title = zap_notification_title(zap)
@@ -1192,7 +1193,7 @@ func create_in_app_profile_zap_notification(profiles: Profiles, zap: Zap, locale
}
}
func create_in_app_event_zap_notification(profiles: Profiles, zap: Zap, locale: Locale = Locale.current, evId: String) {
func create_in_app_event_zap_notification(profiles: Profiles, zap: Zap, locale: Locale = Locale.current, evId: NoteId) {
let content = UNMutableNotificationContent()
content.title = zap_notification_title(zap)
@@ -1213,7 +1214,7 @@ func create_in_app_event_zap_notification(profiles: Profiles, zap: Zap, locale:
}
}
func render_notification_content_preview(cache: EventCache, ev: NostrEvent, profiles: Profiles, privkey: String?) -> String {
func render_notification_content_preview(cache: EventCache, ev: NostrEvent, profiles: Profiles, privkey: Privkey?) -> String {
let prefix_len = 50
let artifacts = cache.get_cache_data(ev.id).artifacts.artifacts ?? render_note_content(ev: ev, profiles: profiles, privkey: privkey)
@@ -1329,7 +1330,7 @@ enum ProcessZapResult {
// securely get the zap target's pubkey. this can be faked so we need to be
// careful
func get_zap_target_pubkey(ev: NostrEvent, events: EventCache) -> String? {
func get_zap_target_pubkey(ev: NostrEvent, events: EventCache) -> Pubkey? {
let etags = ev.referenced_ids
guard let etag = etags.first else {
@@ -1409,7 +1410,7 @@ func process_zap_event(damus_state: DamusState, ev: NostrEvent, completion: @esc
}
fileprivate func process_zap_event_with_zapper(damus_state: DamusState, ev: NostrEvent, zapper: String) -> Zap? {
fileprivate func process_zap_event_with_zapper(damus_state: DamusState, ev: NostrEvent, zapper: Pubkey) -> Zap? {
let our_keypair = damus_state.keypair
guard let zap = Zap.from_zap_event(zap_ev: ev, zapper: zapper, our_privkey: our_keypair.privkey) else {

View File

@@ -13,16 +13,16 @@ enum CountResult {
}
class EventCounter {
var counts: [String: Int] = [:]
var user_events: [String: Set<String>] = [:]
var our_events: [String: NostrEvent] = [:]
var our_pubkey: String
init(our_pubkey: String) {
var counts: [NoteId: Int] = [:]
var user_events: [Pubkey: Set<NoteId>] = [:]
var our_events: [NoteId: NostrEvent] = [:]
var our_pubkey: Pubkey
init(our_pubkey: Pubkey) {
self.our_pubkey = our_pubkey
}
func add_event(_ ev: NostrEvent, target: String) -> CountResult {
func add_event(_ ev: NostrEvent, target: NoteId) -> CountResult {
let pubkey = ev.pubkey
if self.user_events[pubkey] == nil {

View File

@@ -9,6 +9,6 @@ import Foundation
struct Counted {
let event: NostrEvent
let id: String
let id: NoteId
let total: Int
}

View File

@@ -7,16 +7,16 @@
import Foundation
fileprivate func getMutedThreadsKey(pubkey: String) -> String {
fileprivate func getMutedThreadsKey(pubkey: Pubkey) -> String {
pk_setting_key(pubkey, key: "muted_threads")
}
func loadMutedThreads(pubkey: String) -> [String] {
func loadMutedThreads(pubkey: Pubkey) -> [NoteId] {
let key = getMutedThreadsKey(pubkey: pubkey)
return UserDefaults.standard.stringArray(forKey: key) ?? []
}
func saveMutedThreads(pubkey: String, currentValue: [String], value: [String]) -> Bool {
func saveMutedThreads(pubkey: Pubkey, currentValue: [NoteId], value: [NoteId]) -> Bool {
let uniqueMutedThreads = Array(Set(value))
if uniqueMutedThreads != currentValue {
@@ -31,9 +31,9 @@ class MutedThreadsManager: ObservableObject {
private let keypair: Keypair
private var _mutedThreadsSet: Set<String>
private var _mutedThreads: [String]
var mutedThreads: [String] {
private var _mutedThreadsSet: Set<NoteId>
private var _mutedThreads: [NoteId]
var mutedThreads: [NoteId] {
get {
return _mutedThreads
}
@@ -51,7 +51,7 @@ class MutedThreadsManager: ObservableObject {
self.keypair = keypair
}
func isMutedThread(_ ev: NostrEvent, privkey: String?) -> Bool {
func isMutedThread(_ ev: NostrEvent, privkey: Privkey?) -> Bool {
return _mutedThreadsSet.contains(ev.thread_id(privkey: privkey))
}

View File

@@ -10,8 +10,8 @@ import Foundation
class ZapGroup {
var zaps: [Zapping] = []
var msat_total: Int64 = 0
var zappers = Set<String>()
var zappers = Set<Pubkey>()
var last_event_at: UInt32 {
guard let first = zaps.first else {
return 0

View File

@@ -8,10 +8,10 @@
import Foundation
enum NotificationItem {
case repost(String, EventGroup)
case reaction(String, EventGroup)
case repost(NoteId, EventGroup)
case reaction(NoteId, EventGroup)
case profile_zap(ZapGroup)
case event_zap(String, ZapGroup)
case event_zap(NoteId, ZapGroup)
case reply(NostrEvent)
var is_reply: NostrEvent? {
@@ -104,23 +104,23 @@ class NotificationsModel: ObservableObject, ScrollQueue {
var should_queue: Bool = true
// mappings from events to
var zaps: [String: ZapGroup] = [:]
var zaps: [NoteId: ZapGroup] = [:]
var profile_zaps = ZapGroup()
var reactions: [String: EventGroup] = [:]
var reposts: [String: EventGroup] = [:]
var reactions: [NoteId: EventGroup] = [:]
var reposts: [NoteId: EventGroup] = [:]
var replies: [NostrEvent] = []
var has_reply = Set<String>()
var has_ev = Set<String>()
var has_reply = Set<NoteId>()
var has_ev = Set<NoteId>()
@Published var notifications: [NotificationItem] = []
func set_should_queue(_ val: Bool) {
self.should_queue = val
}
func uniq_pubkeys() -> [String] {
var pks = Set<String>()
func uniq_pubkeys() -> [Pubkey] {
var pks = Set<Pubkey>()
for ev in incoming_events {
pks.insert(ev.pubkey)
}

View File

@@ -14,14 +14,14 @@ class ProfileModel: ObservableObject, Equatable {
@Published var progress: Int = 0
var events: EventHolder
let pubkey: String
let pubkey: Pubkey
let damus: DamusState
var seen_event: Set<String> = Set()
var seen_event: Set<NoteId> = Set()
var sub_id = UUID().description
var prof_subid = UUID().description
init(pubkey: String, damus: DamusState) {
init(pubkey: Pubkey, damus: DamusState) {
self.pubkey = pubkey
self.damus = damus
self.events = EventHolder(on_queue: { ev in
@@ -29,7 +29,7 @@ class ProfileModel: ObservableObject, Equatable {
})
}
func follows(pubkey: String) -> Bool {
func follows(pubkey: Pubkey) -> Bool {
guard let contacts = self.contacts else {
return false
}

View File

@@ -9,6 +9,6 @@ import Foundation
struct ProfileUpdate {
let pubkey: String
let pubkey: Pubkey
let profile: Profile
}

View File

@@ -10,7 +10,7 @@ import Foundation
final class ReactionsModel: EventsModel {
init(state: DamusState, target: String) {
init(state: DamusState, target: NoteId) {
super.init(state: state, target: target, kind: .like)
}
}

View File

@@ -8,13 +8,13 @@
import Foundation
struct ReplyDesc {
let pubkeys: [String]
let pubkeys: [Pubkey]
let others: Int
}
func make_reply_description(_ tags: [[String]]) -> ReplyDesc {
var c = 0
var ns: [String] = []
var ns: [Pubkey] = []
var i = tags.count - 1
while i >= 0 {

View File

@@ -8,20 +8,20 @@
import Foundation
class ReplyMap {
var replies: [String: Set<String>] = [:]
func lookup(_ id: String) -> Set<String>? {
var replies: [NoteId: Set<NoteId>] = [:]
func lookup(_ id: NoteId) -> Set<NoteId>? {
return replies[id]
}
private func ensure_set(id: String) {
private func ensure_set(id: NoteId) {
if replies[id] == nil {
replies[id] = Set()
}
}
@discardableResult
func add(id: String, reply_id: String) -> Bool {
func add(id: NoteId, reply_id: NoteId) -> Bool {
ensure_set(id: id)
if (replies[id]!).contains(reply_id) {
return false

View File

@@ -31,12 +31,12 @@ enum ReportType: String, CustomStringConvertible, CaseIterable {
}
struct ReportNoteTarget {
let pubkey: String
let note_id: String
let pubkey: Pubkey
let note_id: NoteId
}
enum ReportTarget {
case user(String)
case user(Pubkey)
case note(ReportNoteTarget)
static func note(pubkey: Pubkey, note_id: NoteId) -> ReportTarget {
@@ -54,9 +54,10 @@ struct Report {
func create_report_tags(target: ReportTarget, type: ReportType) -> [[String]] {
switch target {
case .user(let pubkey):
return [["p", pubkey, type.rawValue]]
return [["p", pubkey.hex(), type.rawValue]]
case .note(let notet):
return [["e", notet.note_id, type.rawValue], ["p", notet.pubkey]]
return [["e", notet.note_id.hex(), type.rawValue],
["p", notet.pubkey.hex()]]
}
}

View File

@@ -9,7 +9,7 @@ import Foundation
final class RepostsModel: EventsModel {
init(state: DamusState, target: String) {
init(state: DamusState, target: NoteId) {
super.init(state: state, target: target, kind: .boost)
}
}

View File

@@ -13,7 +13,7 @@ class SearchHomeModel: ObservableObject {
var events: EventHolder
@Published var loading: Bool = false
var seen_pubkey: Set<String> = Set()
var seen_pubkey: Set<Pubkey> = Set()
let damus_state: DamusState
let base_subid = UUID().description
let profiles_subid = UUID().description
@@ -91,7 +91,7 @@ class SearchHomeModel: ObservableObject {
}
}
func find_profiles_to_fetch(profiles: Profiles, load: PubkeysToLoad, cache: EventCache) -> [String] {
func find_profiles_to_fetch(profiles: Profiles, load: PubkeysToLoad, cache: EventCache) -> [Pubkey] {
switch load {
case .from_events(let events):
return find_profiles_to_fetch_from_events(profiles: profiles, events: events, cache: cache)
@@ -100,13 +100,13 @@ func find_profiles_to_fetch(profiles: Profiles, load: PubkeysToLoad, cache: Even
}
}
func find_profiles_to_fetch_from_keys(profiles: Profiles, pks: [String]) -> [String] {
func find_profiles_to_fetch_from_keys(profiles: Profiles, pks: [Pubkey]) -> [Pubkey] {
Array(Set(pks.filter { pk in !profiles.has_fresh_profile(id: pk) }))
}
func find_profiles_to_fetch_from_events(profiles: Profiles, events: [NostrEvent], cache: EventCache) -> [String] {
var pubkeys = Set<String>()
func find_profiles_to_fetch_from_events(profiles: Profiles, events: [NostrEvent], cache: EventCache) -> [Pubkey] {
var pubkeys = Set<Pubkey>()
for ev in events {
// lookup profiles from boosted events
if ev.known_kind == .boost, let bev = ev.get_inner_event(cache: cache), !profiles.has_fresh_profile(id: bev.pubkey) {
@@ -123,7 +123,7 @@ func find_profiles_to_fetch_from_events(profiles: Profiles, events: [NostrEvent]
enum PubkeysToLoad {
case from_events([NostrEvent])
case from_keys([String])
case from_keys([Pubkey])
}
func load_profiles(profiles_subid: String, relay_id: String, load: PubkeysToLoad, damus_state: DamusState) {

View File

@@ -128,7 +128,7 @@ class ThreadModel: ObservableObject {
}
func get_top_zap(events: EventCache, evid: String) -> Zapping? {
func get_top_zap(events: EventCache, evid: NoteId) -> Zapping? {
return events.get_cache_data(evid).zaps_model.zaps.first(where: { zap in
!zap.request.marked_hidden
})

View File

@@ -11,15 +11,15 @@ import Foundation
/// Optimized for fast searches of substrings by using a Trie.
/// Optimal for performing user searches that could be initiated by typing quickly on a keyboard into a text input field.
class UserSearchCache {
private let trie = Trie<String>()
private let trie = Trie<Pubkey>()
func search(key: String) -> [String] {
func search(key: String) -> [Pubkey] {
let results = trie.find(key: key)
return results
}
/// Computes the differences between an old profile, if it exists, and a new profile, and updates the user search cache accordingly.
func updateProfile(id: String, profiles: Profiles, oldProfile: Profile?, newProfile: Profile) {
func updateProfile(id: Pubkey, profiles: Profiles, oldProfile: Profile?, newProfile: Profile) {
// Remove searchable keys tied to the old profile if they differ from the new profile
// to keep the trie clean without empty nodes while avoiding excessive graph searching.
if let oldProfile {
@@ -38,7 +38,7 @@ class UserSearchCache {
}
/// Adds a profile to the user search cache.
private func addProfile(id: String, profiles: Profiles, profile: Profile) {
private func addProfile(id: Pubkey, profiles: Profiles, profile: Profile) {
// Searchable by name.
if let name = profile.name {
trie.insert(key: name.lowercased(), value: id)
@@ -56,7 +56,7 @@ class UserSearchCache {
}
/// Computes the diffences between an old contacts event and a new contacts event for our own user, and updates the search cache accordingly.
func updateOwnContactsPetnames(id: String, oldEvent: NostrEvent?, newEvent: NostrEvent) {
func updateOwnContactsPetnames(id: Pubkey, oldEvent: NostrEvent?, newEvent: NostrEvent) {
guard newEvent.known_kind == .contacts && newEvent.pubkey == id else {
return
}

View File

@@ -11,7 +11,7 @@ import UIKit
let fallback_zap_amount = 1000
func setting_property_key(key: String) -> String {
return pk_setting_key(UserSettingsStore.pubkey ?? "", key: key)
return pk_setting_key(UserSettingsStore.pubkey ?? .empty, key: key)
}
func setting_get_property_value<T>(key: String, scoped_key: String, default_value: T) -> T {
@@ -63,7 +63,7 @@ func setting_set_property_value<T: Equatable>(scoped_key: String, old_value: T,
private var value: T
init(key: String, default_value: T) {
self.key = pk_setting_key(UserSettingsStore.pubkey ?? "", key: key)
self.key = pk_setting_key(UserSettingsStore.pubkey ?? .empty, key: key)
if let loaded = UserDefaults.standard.string(forKey: self.key), let val = T.init(from: loaded) {
self.value = val
} else if let loaded = UserDefaults.standard.string(forKey: key), let val = T.init(from: loaded) {
@@ -91,7 +91,7 @@ func setting_set_property_value<T: Equatable>(scoped_key: String, old_value: T,
}
class UserSettingsStore: ObservableObject {
static var pubkey: String? = nil
static var pubkey: Pubkey? = nil
static var shared: UserSettingsStore? = nil
static var bool_options = Set<String>()
@@ -261,6 +261,6 @@ class UserSettingsStore: ObservableObject {
}
}
func pk_setting_key(_ pubkey: String, key: String) -> String {
return "\(pubkey)_\(key)"
func pk_setting_key(_ pubkey: Pubkey, key: String) -> String {
return "\(pubkey.hex())_\(key)"
}