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:
@@ -9,12 +9,12 @@ import SwiftUI
|
||||
|
||||
struct EventDetailBar: View {
|
||||
let state: DamusState
|
||||
let target: String
|
||||
let target_pk: String
|
||||
|
||||
let target: NoteId
|
||||
let target_pk: Pubkey
|
||||
|
||||
@ObservedObject var bar: ActionBarModel
|
||||
|
||||
init(state: DamusState, target: String, target_pk: String) {
|
||||
init(state: DamusState, target: NoteId, target_pk: Pubkey) {
|
||||
self.state = state
|
||||
self.target = target
|
||||
self.target_pk = target_pk
|
||||
@@ -56,6 +56,6 @@ struct EventDetailBar: View {
|
||||
|
||||
struct EventDetailBar_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
EventDetailBar(state: test_damus_state(), target: "", target_pk: "")
|
||||
EventDetailBar(state: test_damus_state(), target: .empty, target_pk: .empty)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +63,12 @@ struct InnerBannerImageView: View {
|
||||
|
||||
struct BannerImageView: View {
|
||||
let disable_animation: Bool
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let profiles: Profiles
|
||||
|
||||
@State var banner: String?
|
||||
|
||||
init(pubkey: String, profiles: Profiles, disable_animation: Bool, banner: String? = nil) {
|
||||
init(pubkey: Pubkey, profiles: Profiles, disable_animation: Bool, banner: String? = nil) {
|
||||
self.pubkey = pubkey
|
||||
self.profiles = profiles
|
||||
self._banner = State(initialValue: banner)
|
||||
@@ -89,7 +89,7 @@ struct BannerImageView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func get_banner_url(banner: String?, pubkey: String, profiles: Profiles) -> URL? {
|
||||
func get_banner_url(banner: String?, pubkey: Pubkey, profiles: Profiles) -> URL? {
|
||||
let bannerUrlString = banner ?? profiles.lookup(id: pubkey)?.banner ?? ""
|
||||
if let url = URL(string: bannerUrlString) {
|
||||
return url
|
||||
@@ -98,12 +98,10 @@ func get_banner_url(banner: String?, pubkey: String, profiles: Profiles) -> URL?
|
||||
}
|
||||
|
||||
struct BannerImageView_Previews: PreviewProvider {
|
||||
static let pubkey = "ca48854ac6555fed8e439ebb4fa2d928410e0eef13fa41164ec45aaaa132d846"
|
||||
|
||||
static var previews: some View {
|
||||
BannerImageView(
|
||||
pubkey: pubkey,
|
||||
profiles: make_preview_profiles(pubkey),
|
||||
pubkey: test_pubkey,
|
||||
profiles: make_preview_profiles(test_pubkey),
|
||||
disable_animation: false
|
||||
)
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ struct CreateAccountView_Previews: PreviewProvider {
|
||||
}
|
||||
}
|
||||
|
||||
func KeyText(_ text: Binding<String>) -> some View {
|
||||
let decoded = hex_decode(text.wrappedValue)!
|
||||
func KeyText(_ pubkey: Binding<Pubkey>) -> some View {
|
||||
let decoded = hex_decode(pubkey.wrappedValue)!
|
||||
let bechkey = bech32_encode(hrp: PUBKEY_HRP, decoded)
|
||||
return Text(bechkey)
|
||||
.textSelection(.enabled)
|
||||
|
||||
@@ -13,7 +13,7 @@ struct DMChatView: View, KeyboardReadable {
|
||||
@ObservedObject var dms: DirectMessageModel
|
||||
@State var showPrivateKeyWarning: Bool = false
|
||||
|
||||
var pubkey: String {
|
||||
var pubkey: Pubkey {
|
||||
dms.pubkey
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ struct DMChatView: View, KeyboardReadable {
|
||||
}
|
||||
|
||||
func send_message() {
|
||||
let tags = [["p", pubkey]]
|
||||
let tags = [["p", pubkey.hex()]]
|
||||
let post_blocks = parse_post_blocks(content: dms.draft)
|
||||
let content = render_blocks(blocks: post_blocks)
|
||||
|
||||
@@ -190,7 +190,7 @@ enum EncEncoding {
|
||||
case bech32
|
||||
}
|
||||
|
||||
func encrypt_message(message: String, privkey: String, to_pk: String, encoding: EncEncoding = .base64) -> String? {
|
||||
func encrypt_message(message: String, privkey: Privkey, to_pk: Pubkey, encoding: EncEncoding = .base64) -> String? {
|
||||
let iv = random_bytes(count: 16).bytes
|
||||
guard let shared_sec = get_shared_secret(privkey: privkey, pubkey: to_pk) else {
|
||||
return nil
|
||||
@@ -209,7 +209,7 @@ func encrypt_message(message: String, privkey: String, to_pk: String, encoding:
|
||||
|
||||
}
|
||||
|
||||
func create_encrypted_event(_ message: String, to_pk: String, tags: [[String]], keypair: FullKeypair, created_at: UInt32, kind: UInt32) -> NostrEvent? {
|
||||
func create_encrypted_event(_ message: String, to_pk: Pubkey, tags: [[String]], keypair: FullKeypair, created_at: UInt32, kind: UInt32) -> NostrEvent? {
|
||||
let privkey = keypair.privkey
|
||||
|
||||
guard let enc_content = encrypt_message(message: message, privkey: privkey, to_pk: to_pk) else {
|
||||
@@ -219,7 +219,7 @@ func create_encrypted_event(_ message: String, to_pk: String, tags: [[String]],
|
||||
return NostrEvent(content: enc_content, keypair: keypair.to_keypair(), kind: kind, tags: tags, createdAt: created_at)
|
||||
}
|
||||
|
||||
func create_dm(_ message: String, to_pk: String, tags: [[String]], keypair: Keypair, created_at: UInt32? = nil) -> NostrEvent?
|
||||
func create_dm(_ message: String, to_pk: Pubkey, tags: [[String]], keypair: Keypair, created_at: UInt32? = nil) -> NostrEvent?
|
||||
{
|
||||
let created = created_at ?? UInt32(Date().timeIntervalSince1970)
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ struct EventView: View {
|
||||
let event: NostrEvent
|
||||
let options: EventViewOptions
|
||||
let damus: DamusState
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
|
||||
init(damus: DamusState, event: NostrEvent, pubkey: String? = nil, options: EventViewOptions = []) {
|
||||
init(damus: DamusState, event: NostrEvent, pubkey: Pubkey? = nil, options: EventViewOptions = []) {
|
||||
self.event = event
|
||||
self.options = options
|
||||
self.damus = damus
|
||||
@@ -54,7 +54,7 @@ struct EventView: View {
|
||||
}
|
||||
|
||||
// blame the porn bots for this code
|
||||
func should_show_images(settings: UserSettingsStore, contacts: Contacts, ev: NostrEvent, our_pubkey: String, booster_pubkey: String? = nil) -> Bool {
|
||||
func should_show_images(settings: UserSettingsStore, contacts: Contacts, ev: NostrEvent, our_pubkey: Pubkey, booster_pubkey: Pubkey? = nil) -> Bool {
|
||||
if settings.always_show_images {
|
||||
return true
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func should_show_images(settings: UserSettingsStore, contacts: Contacts, ev: Nos
|
||||
}
|
||||
|
||||
extension View {
|
||||
func pubkey_context_menu(bech32_pubkey: String) -> some View {
|
||||
func pubkey_context_menu(bech32_pubkey: Pubkey) -> some View {
|
||||
return self.contextMenu {
|
||||
Button {
|
||||
UIPasteboard.general.string = bech32_pubkey
|
||||
@@ -96,7 +96,7 @@ func format_date(_ created_at: UInt32) -> String {
|
||||
return dateFormatter.string(from: date)
|
||||
}
|
||||
|
||||
func make_actionbar_model(ev: String, damus: DamusState) -> ActionBarModel {
|
||||
func make_actionbar_model(ev: NoteId, damus: DamusState) -> ActionBarModel {
|
||||
let model = ActionBarModel.empty()
|
||||
model.update(damus: damus, evid: ev)
|
||||
return model
|
||||
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
|
||||
struct BuilderEventView: View {
|
||||
let damus: DamusState
|
||||
let event_id: String
|
||||
let event_id: NoteId
|
||||
@State var event: NostrEvent?
|
||||
@State var subscription_uuid: String = UUID().description
|
||||
|
||||
@@ -19,7 +19,7 @@ struct BuilderEventView: View {
|
||||
self.event_id = event.id
|
||||
}
|
||||
|
||||
init(damus: DamusState, event_id: String) {
|
||||
init(damus: DamusState, event_id: NoteId) {
|
||||
let event = damus.events.lookup(event_id)
|
||||
self.event_id = event_id
|
||||
self.damus = damus
|
||||
|
||||
@@ -10,10 +10,10 @@ import SwiftUI
|
||||
struct EventTop: View {
|
||||
let state: DamusState
|
||||
let event: NostrEvent
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let is_anon: Bool
|
||||
|
||||
init(state: DamusState, event: NostrEvent, pubkey: String, is_anon: Bool) {
|
||||
init(state: DamusState, event: NostrEvent, pubkey: Pubkey, is_anon: Bool) {
|
||||
self.state = state
|
||||
self.event = event
|
||||
self.pubkey = pubkey
|
||||
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
|
||||
struct ReplyPart: View {
|
||||
let event: NostrEvent
|
||||
let privkey: String?
|
||||
let privkey: Privkey?
|
||||
let profiles: Profiles
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
struct EventMenuContext: View {
|
||||
let event: NostrEvent
|
||||
let keypair: Keypair
|
||||
let target_pubkey: String
|
||||
let target_pubkey: Pubkey
|
||||
let bookmarks: BookmarksManager
|
||||
let muted_threads: MutedThreadsManager
|
||||
@ObservedObject var settings: UserSettingsStore
|
||||
@@ -44,7 +44,7 @@ struct EventMenuContext: View {
|
||||
struct MenuItems: View {
|
||||
let event: NostrEvent
|
||||
let keypair: Keypair
|
||||
let target_pubkey: String
|
||||
let target_pubkey: Pubkey
|
||||
let bookmarks: BookmarksManager
|
||||
let muted_threads: MutedThreadsManager
|
||||
@ObservedObject var settings: UserSettingsStore
|
||||
@@ -52,7 +52,7 @@ struct MenuItems: View {
|
||||
@State private var isBookmarked: Bool = false
|
||||
@State private var isMutedThread: Bool = false
|
||||
|
||||
init(event: NostrEvent, keypair: Keypair, target_pubkey: String, bookmarks: BookmarksManager, muted_threads: MutedThreadsManager, settings: UserSettingsStore) {
|
||||
init(event: NostrEvent, keypair: Keypair, target_pubkey: Pubkey, bookmarks: BookmarksManager, muted_threads: MutedThreadsManager, settings: UserSettingsStore) {
|
||||
let bookmarked = bookmarks.isBookmarked(event)
|
||||
self._isBookmarked = State(initialValue: bookmarked)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func eventview_pfp_size(_ size: EventViewKind) -> CGFloat {
|
||||
|
||||
struct EventProfile: View {
|
||||
let damus_state: DamusState
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let profile: Profile?
|
||||
let size: EventViewKind
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ import SwiftUI
|
||||
struct EventShell<Content: View>: View {
|
||||
let state: DamusState
|
||||
let event: NostrEvent
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let options: EventViewOptions
|
||||
let content: Content
|
||||
|
||||
init(state: DamusState, event: NostrEvent, pubkey: String, options: EventViewOptions, @ViewBuilder content: () -> Content) {
|
||||
init(state: DamusState, event: NostrEvent, pubkey: Pubkey, options: EventViewOptions, @ViewBuilder content: () -> Content) {
|
||||
self.state = state
|
||||
self.event = event
|
||||
self.options = options
|
||||
|
||||
@@ -12,7 +12,7 @@ struct SelectedEventView: View {
|
||||
let event: NostrEvent
|
||||
let size: EventViewKind
|
||||
|
||||
var pubkey: String {
|
||||
var pubkey: Pubkey {
|
||||
event.pubkey
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ struct EventViewOptions: OptionSet {
|
||||
struct TextEvent: View {
|
||||
let damus: DamusState
|
||||
let event: NostrEvent
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let options: EventViewOptions
|
||||
let evdata: EventData
|
||||
|
||||
init(damus: DamusState, event: NostrEvent, pubkey: String, options: EventViewOptions) {
|
||||
init(damus: DamusState, event: NostrEvent, pubkey: Pubkey, options: EventViewOptions) {
|
||||
self.damus = damus
|
||||
self.event = event
|
||||
self.pubkey = pubkey
|
||||
|
||||
@@ -26,7 +26,7 @@ struct FollowUserView: View {
|
||||
|
||||
struct FollowersYouKnowView: View {
|
||||
let damus_state: DamusState
|
||||
let friended_followers: [String]
|
||||
let friended_followers: [Pubkey]
|
||||
@ObservedObject var followers: FollowersModel
|
||||
|
||||
var body: some View {
|
||||
|
||||
@@ -15,7 +15,7 @@ struct ImagePicker: UIViewControllerRepresentable {
|
||||
|
||||
let uploader: MediaUploader
|
||||
let sourceType: UIImagePickerController.SourceType
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
@Binding var image_upload_confirm: Bool
|
||||
var imagesOnly: Bool = false
|
||||
let onImagePicked: (URL) -> Void
|
||||
|
||||
@@ -62,7 +62,7 @@ struct NavDismissBarView: View {
|
||||
}
|
||||
|
||||
struct ProfilePicImageView: View {
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let profiles: Profiles
|
||||
let disable_animation: Bool
|
||||
|
||||
@@ -90,12 +90,10 @@ struct ProfilePicImageView: View {
|
||||
}
|
||||
|
||||
struct ProfileZoomView_Previews: PreviewProvider {
|
||||
static let pubkey = "ca48854ac6555fed8e439ebb4fa2d928410e0eef13fa41164ec45aaaa132d846"
|
||||
|
||||
static var previews: some View {
|
||||
ProfilePicImageView(
|
||||
pubkey: pubkey,
|
||||
profiles: make_preview_profiles(pubkey),
|
||||
pubkey: test_pubkey,
|
||||
profiles: make_preview_profiles(test_pubkey),
|
||||
disable_animation: false
|
||||
)
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
import SwiftUI
|
||||
|
||||
enum ParsedKey {
|
||||
case pub(String)
|
||||
case priv(String)
|
||||
case pub(Pubkey)
|
||||
case priv(Privkey)
|
||||
case hex(String)
|
||||
case nip05(String)
|
||||
|
||||
@@ -203,7 +203,7 @@ func process_login(_ key: ParsedKey, is_pubkey: Bool) async throws {
|
||||
}
|
||||
}
|
||||
|
||||
func handle_privkey(_ privkey: String) throws {
|
||||
func handle_privkey(_ privkey: Privkey) throws {
|
||||
try save_privkey(privkey: privkey)
|
||||
|
||||
guard let pk = privkey_to_pubkey(privkey: privkey) else {
|
||||
@@ -231,7 +231,7 @@ struct NIP05Result: Decodable {
|
||||
}
|
||||
|
||||
struct NIP05User {
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let relays: [String]
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ import SwiftUI
|
||||
|
||||
struct MutelistView: View {
|
||||
let damus_state: DamusState
|
||||
@State var users: [String]
|
||||
@State var users: [Pubkey]
|
||||
|
||||
func RemoveAction(pubkey: String) -> some View {
|
||||
func RemoveAction(pubkey: Pubkey) -> some View {
|
||||
Button {
|
||||
guard let mutelist = damus_state.contacts.mutelist else {
|
||||
return
|
||||
|
||||
@@ -392,7 +392,7 @@ func note_artifact_is_separated(kind: NostrKind?) -> Bool {
|
||||
return kind != .longform
|
||||
}
|
||||
|
||||
func render_note_content(ev: NostrEvent, profiles: Profiles, privkey: String?) -> NoteArtifacts {
|
||||
func render_note_content(ev: NostrEvent, profiles: Profiles, privkey: Privkey?) -> NoteArtifacts {
|
||||
let blocks = ev.blocks(privkey)
|
||||
|
||||
if ev.known_kind == .longform {
|
||||
@@ -574,7 +574,7 @@ func classify_url(_ url: URL) -> UrlType {
|
||||
return .link(url)
|
||||
}
|
||||
|
||||
func lookup_cached_preview_size(previews: PreviewCache, evid: String) -> CGFloat? {
|
||||
func lookup_cached_preview_size(previews: PreviewCache, evid: NoteId) -> CGFloat? {
|
||||
guard case .value(let cached) = previews.lookup(evid) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ enum ReactingTo {
|
||||
case your_profile
|
||||
}
|
||||
|
||||
func determine_reacting_to(our_pubkey: String, ev: NostrEvent?) -> ReactingTo {
|
||||
func determine_reacting_to(our_pubkey: Pubkey, ev: NostrEvent?) -> ReactingTo {
|
||||
guard let ev else {
|
||||
return .your_profile
|
||||
}
|
||||
@@ -68,21 +68,21 @@ func determine_reacting_to(our_pubkey: String, ev: NostrEvent?) -> ReactingTo {
|
||||
return .tagged_in
|
||||
}
|
||||
|
||||
func event_author_name(profiles: Profiles, pubkey: String) -> String {
|
||||
func event_author_name(profiles: Profiles, pubkey: Pubkey) -> String {
|
||||
let alice_prof = profiles.lookup(id: pubkey)
|
||||
return Profile.displayName(profile: alice_prof, pubkey: pubkey).username.truncate(maxLength: 50)
|
||||
}
|
||||
|
||||
func event_group_unique_pubkeys(profiles: Profiles, group: EventGroupType) -> [String] {
|
||||
var seen = Set<String>()
|
||||
var sorted = [String]()
|
||||
func event_group_unique_pubkeys(profiles: Profiles, group: EventGroupType) -> [Pubkey] {
|
||||
var seen = Set<Pubkey>()
|
||||
var sorted = [Pubkey]()
|
||||
|
||||
if let zapgrp = group.zap_group {
|
||||
let zaps = zapgrp.zaps
|
||||
|
||||
for i in 0..<zaps.count {
|
||||
let zap = zapgrp.zaps[i]
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
|
||||
if zap.is_anon {
|
||||
pubkey = ANON_PUBKEY
|
||||
@@ -148,7 +148,7 @@ func event_group_unique_pubkeys(profiles: Profiles, group: EventGroupType) -> [S
|
||||
"zapped_your_profile_2" - returned when 2 zaps occurred to the current user's profile
|
||||
"zapped_your_profile_3" - returned when 3 or more zaps occurred to the current user's profile
|
||||
*/
|
||||
func reacting_to_text(profiles: Profiles, our_pubkey: String, group: EventGroupType, ev: NostrEvent?, pubkeys: [String], locale: Locale? = nil) -> String {
|
||||
func reacting_to_text(profiles: Profiles, our_pubkey: Pubkey, group: EventGroupType, ev: NostrEvent?, pubkeys: [Pubkey], locale: Locale? = nil) -> String {
|
||||
if group.events.count == 0 {
|
||||
return "??"
|
||||
}
|
||||
@@ -192,7 +192,7 @@ struct EventGroupView: View {
|
||||
let event: NostrEvent?
|
||||
let group: EventGroupType
|
||||
|
||||
func GroupDescription(_ pubkeys: [String]) -> some View {
|
||||
func GroupDescription(_ pubkeys: [Pubkey]) -> some View {
|
||||
Text(verbatim: "\(reacting_to_text(profiles: state.profiles, our_pubkey: state.pubkey, group: group, ev: event, pubkeys: pubkeys))")
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ enum FriendFilter: String, StringCodable {
|
||||
self.rawValue
|
||||
}
|
||||
|
||||
func filter(contacts: Contacts, pubkey: String) -> Bool {
|
||||
func filter(contacts: Contacts, pubkey: Pubkey) -> Bool {
|
||||
switch self {
|
||||
case .all:
|
||||
return true
|
||||
|
||||
@@ -9,8 +9,8 @@ import SwiftUI
|
||||
|
||||
struct ProfilePicturesView: View {
|
||||
let state: DamusState
|
||||
let pubkeys: [String]
|
||||
|
||||
let pubkeys: [Pubkey]
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
ForEach(pubkeys.prefix(8), id: \.self) { pubkey in
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class TagModel: ObservableObject {
|
||||
|
||||
enum PostTarget {
|
||||
case none
|
||||
case user(String)
|
||||
case user(Pubkey)
|
||||
}
|
||||
|
||||
enum PostAction {
|
||||
|
||||
@@ -9,9 +9,9 @@ import SwiftUI
|
||||
|
||||
struct SearchedUser: Identifiable {
|
||||
let profile: Profile?
|
||||
let pubkey: String
|
||||
|
||||
var id: String {
|
||||
let pubkey: Pubkey
|
||||
|
||||
var id: Pubkey {
|
||||
return pubkey
|
||||
}
|
||||
}
|
||||
@@ -151,7 +151,7 @@ func append_user_tag(tag: NSAttributedString, post: NSMutableAttributedString, w
|
||||
}
|
||||
|
||||
/// Generate a mention attributed string, including the internal damus:nostr: link
|
||||
func user_tag_attr_string(profile: Profile?, pubkey: String) -> NSMutableAttributedString {
|
||||
func user_tag_attr_string(profile: Profile?, pubkey: Pubkey) -> NSMutableAttributedString {
|
||||
let display_name = Profile.displayName(profile: profile, pubkey: pubkey)
|
||||
let name = display_name.username.truncate(maxLength: 50)
|
||||
let tagString = "@\(name)"
|
||||
|
||||
@@ -9,10 +9,10 @@ import SwiftUI
|
||||
|
||||
struct CondensedProfilePicturesView: View {
|
||||
let state: DamusState
|
||||
let pubkeys: [String]
|
||||
let pubkeys: [Pubkey]
|
||||
let maxPictures: Int
|
||||
|
||||
init(state: DamusState, pubkeys: [String], maxPictures: Int) {
|
||||
init(state: DamusState, pubkeys: [Pubkey], maxPictures: Int) {
|
||||
self.state = state
|
||||
self.pubkeys = pubkeys
|
||||
self.maxPictures = min(maxPictures, pubkeys.count)
|
||||
@@ -33,6 +33,6 @@ struct CondensedProfilePicturesView: View {
|
||||
|
||||
struct CondensedProfilePicturesView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CondensedProfilePicturesView(state: test_damus_state(), pubkeys: ["a", "b", "c", "d"], maxPictures: 3)
|
||||
CondensedProfilePicturesView(state: test_damus_state(), pubkeys: [test_pubkey, test_pubkey, test_pubkey, test_pubkey], maxPictures: 3)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class ImageUploadingObserver: ObservableObject {
|
||||
|
||||
struct EditPictureControl: View {
|
||||
let uploader: MediaUploader
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
@Binding var image_url: URL?
|
||||
@ObservedObject var uploadObserver: ImageUploadingObserver
|
||||
let callback: (URL?) -> Void
|
||||
@@ -120,12 +120,11 @@ struct EditPictureControl: View {
|
||||
|
||||
struct EditPictureControl_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let pubkey = "123"
|
||||
let url = Binding<URL?>.constant(URL(string: "https://damus.io")!)
|
||||
let observer = ImageUploadingObserver()
|
||||
ZStack {
|
||||
Color.gray
|
||||
EditPictureControl(uploader: .nostrBuild, pubkey: pubkey, image_url: url, uploadObserver: observer) { _ in
|
||||
EditPictureControl(uploader: .nostrBuild, pubkey: test_pubkey, image_url: url, uploadObserver: observer) { _ in
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
/// Profile Name used when displaying an event in the timeline
|
||||
struct EventProfileName: View {
|
||||
let damus_state: DamusState
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let profile: Profile?
|
||||
|
||||
@State var display_name: DisplayName?
|
||||
@@ -19,7 +19,7 @@ struct EventProfileName: View {
|
||||
|
||||
let size: EventViewKind
|
||||
|
||||
init(pubkey: String, profile: Profile?, damus: DamusState, size: EventViewKind = .normal) {
|
||||
init(pubkey: Pubkey, profile: Profile?, damus: DamusState, size: EventViewKind = .normal) {
|
||||
self.damus_state = damus
|
||||
self.pubkey = pubkey
|
||||
self.profile = profile
|
||||
|
||||
@@ -10,10 +10,10 @@ import SwiftUI
|
||||
struct MaybeAnonPfpView: View {
|
||||
let state: DamusState
|
||||
let is_anon: Bool
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let size: CGFloat
|
||||
|
||||
init(state: DamusState, is_anon: Bool, pubkey: String, size: CGFloat) {
|
||||
init(state: DamusState, is_anon: Bool, pubkey: Pubkey, size: CGFloat) {
|
||||
self.state = state
|
||||
self.is_anon = is_anon
|
||||
self.pubkey = pubkey
|
||||
|
||||
@@ -12,7 +12,7 @@ enum FriendType {
|
||||
case fof
|
||||
}
|
||||
|
||||
func get_friend_type(contacts: Contacts, pubkey: String) -> FriendType? {
|
||||
func get_friend_type(contacts: Contacts, pubkey: Pubkey) -> FriendType? {
|
||||
if contacts.is_friend_or_self(pubkey) {
|
||||
return .friend
|
||||
}
|
||||
@@ -26,7 +26,7 @@ func get_friend_type(contacts: Contacts, pubkey: String) -> FriendType? {
|
||||
|
||||
struct ProfileName: View {
|
||||
let damus_state: DamusState
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let profile: Profile?
|
||||
let prefix: String
|
||||
|
||||
@@ -36,7 +36,7 @@ struct ProfileName: View {
|
||||
@State var nip05: NIP05?
|
||||
@State var donation: Int?
|
||||
|
||||
init(pubkey: String, profile: Profile?, prefix: String = "", damus: DamusState, show_nip5_domain: Bool = true) {
|
||||
init(pubkey: Pubkey, profile: Profile?, prefix: String = "", damus: DamusState, show_nip5_domain: Bool = true) {
|
||||
self.pubkey = pubkey
|
||||
self.profile = profile
|
||||
self.prefix = prefix
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ProfileNameView: View {
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let profile: Profile?
|
||||
let follows_you: Bool
|
||||
let damus: DamusState
|
||||
|
||||
@@ -31,7 +31,7 @@ func pfp_line_width(_ h: Highlight) -> CGFloat {
|
||||
struct InnerProfilePicView: View {
|
||||
let url: URL?
|
||||
let fallbackUrl: URL?
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let size: CGFloat
|
||||
let highlight: Highlight
|
||||
let disable_animation: Bool
|
||||
@@ -67,7 +67,7 @@ struct InnerProfilePicView: View {
|
||||
}
|
||||
|
||||
struct ProfilePicView: View {
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
let size: CGFloat
|
||||
let highlight: Highlight
|
||||
let profiles: Profiles
|
||||
@@ -75,7 +75,7 @@ struct ProfilePicView: View {
|
||||
|
||||
@State var picture: String?
|
||||
|
||||
init(pubkey: String, size: CGFloat, highlight: Highlight, profiles: Profiles, disable_animation: Bool, picture: String? = nil) {
|
||||
init(pubkey: Pubkey, size: CGFloat, highlight: Highlight, profiles: Profiles, disable_animation: Bool, picture: String? = nil) {
|
||||
self.pubkey = pubkey
|
||||
self.profiles = profiles
|
||||
self.size = size
|
||||
@@ -98,7 +98,7 @@ struct ProfilePicView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func get_profile_url(picture: String?, pubkey: String, profiles: Profiles) -> URL {
|
||||
func get_profile_url(picture: String?, pubkey: Pubkey, profiles: Profiles) -> URL {
|
||||
let pic = picture ?? profiles.lookup(id: pubkey)?.picture ?? robohash(pubkey)
|
||||
if let url = URL(string: pic) {
|
||||
return url
|
||||
|
||||
@@ -13,7 +13,7 @@ struct EditProfilePictureView: View {
|
||||
|
||||
@State var profile_url: URL?
|
||||
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
var damus_state: DamusState?
|
||||
var size: CGFloat = 80.0
|
||||
let highlight: Highlight = .custom(Color.white, 2.0)
|
||||
@@ -52,7 +52,6 @@ struct EditProfilePictureView: View {
|
||||
|
||||
struct ProfilePictureSelector_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let test_pubkey = "ff48854ac6555fed8e439ebb4fa2d928410e0eef13fa41164ec45aaaa132d846"
|
||||
EditProfilePictureView(pubkey: test_pubkey, uploadObserver: ImageUploadingObserver()) { _ in
|
||||
//
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ func follow_btn_txt(_ fs: FollowState, follows_you: Bool) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
func followedByString(_ friend_intersection: [String], profiles: Profiles, locale: Locale = Locale.current) -> String {
|
||||
func followedByString(_ friend_intersection: [Pubkey], profiles: Profiles, locale: Locale = Locale.current) -> String {
|
||||
let bundle = bundleForLocale(locale: locale)
|
||||
let names: [String] = friend_intersection.prefix(3).map {
|
||||
let profile = profiles.lookup(id: $0)
|
||||
@@ -90,7 +90,7 @@ struct ProfileView: View {
|
||||
self._followers = StateObject(wrappedValue: followers)
|
||||
}
|
||||
|
||||
init(damus_state: DamusState, pubkey: String) {
|
||||
init(damus_state: DamusState, pubkey: Pubkey) {
|
||||
self.damus_state = damus_state
|
||||
self._profile = StateObject(wrappedValue: ProfileModel(pubkey: pubkey, damus: damus_state))
|
||||
self._followers = StateObject(wrappedValue: FollowersModel(damus_state: damus_state, target: pubkey))
|
||||
@@ -493,7 +493,7 @@ struct ProfileView_Previews: PreviewProvider {
|
||||
}
|
||||
|
||||
struct KeyView: View {
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
@@ -566,7 +566,7 @@ extension View {
|
||||
}
|
||||
}
|
||||
|
||||
func check_nip05_validity(pubkey: String, profiles: Profiles) {
|
||||
func check_nip05_validity(pubkey: Pubkey, profiles: Profiles) {
|
||||
guard let profile = profiles.lookup(id: pubkey),
|
||||
let nip05 = profile.nip05,
|
||||
profiles.is_validated(pubkey) == nil
|
||||
|
||||
@@ -9,7 +9,7 @@ import SwiftUI
|
||||
import CoreImage.CIFilterBuiltins
|
||||
|
||||
struct ProfileScanResult: Equatable {
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
|
||||
init(hex: String) {
|
||||
self.pubkey = hex
|
||||
@@ -42,7 +42,7 @@ struct ProfileScanResult: Equatable {
|
||||
|
||||
struct QRCodeView: View {
|
||||
let damus_state: DamusState
|
||||
@State var pubkey: String
|
||||
@State var pubkey: Pubkey
|
||||
|
||||
@Environment(\.presentationMode) var presentationMode
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
enum SearchState {
|
||||
case searching
|
||||
case found(NostrEvent)
|
||||
case found_profile(String)
|
||||
case found_profile(Pubkey)
|
||||
case not_found
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ struct MultiSearch {
|
||||
enum Search: Identifiable {
|
||||
case profiles([SearchedUser])
|
||||
case hashtag(String)
|
||||
case profile(String)
|
||||
case note(String)
|
||||
case profile(Pubkey)
|
||||
case note(NoteId)
|
||||
case nip05(String)
|
||||
case hex(String)
|
||||
case multi(MultiSearch)
|
||||
@@ -38,7 +38,7 @@ struct InnerSearchResults: View {
|
||||
let damus_state: DamusState
|
||||
let search: Search?
|
||||
|
||||
func ProfileSearchResult(pk: String) -> some View {
|
||||
func ProfileSearchResult(pk: Pubkey) -> some View {
|
||||
FollowUserView(target: .pubkey(pk), damus_state: damus_state)
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
struct SelectWalletView: View {
|
||||
let default_wallet: Wallet
|
||||
@Binding var active_sheet: Sheets?
|
||||
let our_pubkey: String
|
||||
let our_pubkey: Pubkey
|
||||
let invoice: String
|
||||
@State var invoice_copied: Bool = false
|
||||
|
||||
@@ -71,6 +71,6 @@ struct SelectWalletView_Previews: PreviewProvider {
|
||||
@State static var active_sheet: Sheets? = nil
|
||||
|
||||
static var previews: some View {
|
||||
SelectWalletView(default_wallet: .lnlink, active_sheet: $active_sheet, our_pubkey: "", invoice: "")
|
||||
SelectWalletView(default_wallet: .lnlink, active_sheet: $active_sheet, our_pubkey: test_pubkey, invoice: "")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ struct ZapTypePicker: View {
|
||||
@Binding var zap_type: ZapType
|
||||
@ObservedObject var settings: UserSettingsStore
|
||||
let profiles: Profiles
|
||||
let pubkey: String
|
||||
let pubkey: Pubkey
|
||||
|
||||
@Environment(\.colorScheme) var colorScheme
|
||||
|
||||
@@ -106,11 +106,11 @@ struct ZapTypePicker_Previews: PreviewProvider {
|
||||
@State static var zap_type: ZapType = .pub
|
||||
static var previews: some View {
|
||||
let ds = test_damus_state()
|
||||
ZapTypePicker(zap_type: $zap_type, settings: ds.settings, profiles: ds.profiles, pubkey: "bob")
|
||||
ZapTypePicker(zap_type: $zap_type, settings: ds.settings, profiles: ds.profiles, pubkey: test_pubkey)
|
||||
}
|
||||
}
|
||||
|
||||
func zap_type_desc(type: ZapType, profiles: Profiles, pubkey: String) -> String {
|
||||
func zap_type_desc(type: ZapType, profiles: Profiles, pubkey: Pubkey) -> String {
|
||||
switch type {
|
||||
case .pub:
|
||||
return NSLocalizedString("Everyone will see that you zapped", comment: "Description of public zap type where the zap is sent publicly and identifies the user who sent it.")
|
||||
|
||||
@@ -9,8 +9,8 @@ import SwiftUI
|
||||
|
||||
struct ZapUserView: View {
|
||||
let state: DamusState
|
||||
let pubkey: String
|
||||
|
||||
let pubkey: Pubkey
|
||||
|
||||
var body: some View {
|
||||
HStack(alignment: .center) {
|
||||
Text("Zap")
|
||||
|
||||
Reference in New Issue
Block a user