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

@@ -8,13 +8,13 @@
import SwiftUI
struct SuggestedUser: Codable {
let pubkey: String
let pubkey: Pubkey
let name: String
let about: String
let pfp: URL
let profile: Profile
init?(profile: Profile, pubkey: String) {
init?(profile: Profile, pubkey: Pubkey) {
guard let name = profile.name,
let about = profile.about,
@@ -64,7 +64,7 @@ struct SuggestedUserView_Previews: PreviewProvider {
static var previews: some View {
let profile = Profile(name: "klabo", about: "A person who likes nostr a lot and I like to tell people about myself in very long-winded ways that push the limits of UI and almost break things", picture: "https://primal.b-cdn.net/media-cache?s=m&a=1&u=https%3A%2F%2Fpbs.twimg.com%2Fprofile_images%2F1599994711430742017%2F33zLk9Wi_400x400.jpg")
let user = SuggestedUser(profile: profile, pubkey: "abcd")!
let user = SuggestedUser(profile: profile, pubkey: test_pubkey)!
List {
SuggestedUserView(user: user, damus_state: test_damus_state())
}

View File

@@ -11,7 +11,7 @@ import Combine
struct SuggestedUserGroup: Identifiable, Codable {
let id = UUID()
let title: String
let users: [String]
let users: [Pubkey]
enum CodingKeys: String, CodingKey {
case title, users
@@ -34,7 +34,7 @@ class SuggestedUsersViewModel: ObservableObject {
subscribeToSuggestedProfiles(pubkeys: pubkeys)
}
func suggestedUser(pubkey: String) -> SuggestedUser? {
func suggestedUser(pubkey: Pubkey) -> SuggestedUser? {
if let profile = damus_state.profiles.lookup(id: pubkey),
let user = SuggestedUser(profile: profile, pubkey: pubkey) {
return user
@@ -42,7 +42,7 @@ class SuggestedUsersViewModel: ObservableObject {
return nil
}
func follow(pubkeys: [String]) {
func follow(pubkeys: [Pubkey]) {
for pubkey in pubkeys {
notify(.follow(.pubkey(pubkey)))
}
@@ -66,17 +66,16 @@ class SuggestedUsersViewModel: ObservableObject {
}
}
private func getPubkeys(groups: [SuggestedUserGroup]) -> [String] {
var pubkeys: [String] = []
private func getPubkeys(groups: [SuggestedUserGroup]) -> [Pubkey] {
var pubkeys: [Pubkey] = []
for group in groups {
pubkeys.append(contentsOf: group.users)
}
return pubkeys
}
private func subscribeToSuggestedProfiles(pubkeys: [String]) {
let filter = NostrFilter(kinds: [.metadata],
authors: pubkeys)
private func subscribeToSuggestedProfiles(pubkeys: [Pubkey]) {
let filter = NostrFilter(kinds: [.metadata], authors: pubkeys)
damus_state.pool.subscribe(sub_id: sub_id, filters: [filter], handler: handle_event)
}