commit bb6a09179edd0e59beeeb39043344b5fd612cb45
parent 49f64e7f4954ee612d8fc96ca40e60869436e5c3
Author: Terry Yiu <963907+tyiu@users.noreply.github.com>
Date: Sat, 28 Jan 2023 22:22:26 -0500
Fix bug with copying user pubkey
Co-authored-by: William Casarin <jb55@jb55.com>
Changelog-Fixed: Fixed bug where copying pubkey from context menu only copied your own pubkey
Closes: #425
Diffstat:
7 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/damus/Models/DamusState.swift b/damus/Models/DamusState.swift
@@ -22,7 +22,7 @@ struct DamusState {
var pubkey: String {
return keypair.pubkey
}
-
+
var is_privkey_user: Bool {
keypair.privkey != nil
}
diff --git a/damus/Views/ChatroomView.swift b/damus/Views/ChatroomView.swift
@@ -24,7 +24,7 @@ struct ChatroomView: View {
next_ev: ind == count-1 ? nil : thread.events[ind+1],
damus_state: damus
)
- .event_context_menu(ev, keypair: damus.keypair)
+ .event_context_menu(ev, privkey: damus.keypair.privkey, pubkey: ev.pubkey)
.onTapGesture {
if thread.initial_event.id == ev.id {
//dismiss()
diff --git a/damus/Views/DMChatView.swift b/damus/Views/DMChatView.swift
@@ -19,7 +19,7 @@ struct DMChatView: View {
VStack(alignment: .leading) {
ForEach(Array(zip(dms.events, dms.events.indices)), id: \.0.id) { (ev, ind) in
DMView(event: dms.events[ind], damus_state: damus_state)
- .event_context_menu(ev, keypair: damus_state.keypair)
+ .event_context_menu(ev, privkey: damus_state.keypair.privkey, pubkey: ev.pubkey)
}
EndBlock(height: 80)
}
diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift
@@ -129,7 +129,7 @@ struct EventView: View {
.id(event.id)
.frame(maxWidth: .infinity, minHeight: PFP_SIZE)
.padding([.bottom], 2)
- .event_context_menu(event, keypair: damus.keypair)
+ .event_context_menu(event, privkey: damus.keypair.privkey, pubkey: pubkey)
}
}
@@ -171,9 +171,9 @@ extension View {
}
}
- func event_context_menu(_ event: NostrEvent, keypair: Keypair) -> some View {
+ func event_context_menu(_ event: NostrEvent, privkey: String?, pubkey: String) -> some View {
return self.contextMenu {
- EventMenuContext(event: event, keypair: keypair)
+ EventMenuContext(event: event, privkey: privkey, pubkey: pubkey)
}
}
diff --git a/damus/Views/Events/EmbeddedEventView.swift b/damus/Views/Events/EmbeddedEventView.swift
@@ -23,7 +23,7 @@ struct EmbeddedEventView: View {
EventBody(damus_state: damus_state, event: event, size: .small)
}
- .event_context_menu(event, keypair: damus_state.keypair)
+ .event_context_menu(event, privkey: damus_state.keypair.privkey, pubkey: pubkey)
}
}
diff --git a/damus/Views/Events/EventMenu.swift b/damus/Views/Events/EventMenu.swift
@@ -9,18 +9,19 @@ import SwiftUI
struct EventMenuContext: View {
let event: NostrEvent
- let keypair: Keypair
+ let privkey: String?
+ let pubkey: String
var body: some View {
Button {
- UIPasteboard.general.string = event.get_content(keypair.privkey)
+ UIPasteboard.general.string = event.get_content(privkey)
} label: {
Label(NSLocalizedString("Copy Text", comment: "Context menu option for copying the text from an note."), systemImage: "doc.on.doc")
}
Button {
- UIPasteboard.general.string = keypair.pubkey_bech32
+ UIPasteboard.general.string = bech32_pubkey(event.pubkey)
} label: {
Label(NSLocalizedString("Copy User Pubkey", comment: "Context menu option for copying the ID of the user who created the note."), systemImage: "person")
}
@@ -44,7 +45,7 @@ struct EventMenuContext: View {
}
// Only allow reporting if logged in with private key and the currently viewed profile is not the logged in profile.
- if keypair.pubkey != event.pubkey && keypair.privkey != nil {
+ if pubkey != event.pubkey && privkey != nil {
Button(role: .destructive) {
let target: ReportTarget = .note(ReportNoteTarget(pubkey: event.pubkey, note_id: event.id))
notify(.report, target)
diff --git a/damus/Views/Events/SelectedEventView.swift b/damus/Views/Events/SelectedEventView.swift
@@ -49,7 +49,7 @@ struct SelectedEventView: View {
.padding([.top], 4)
}
.padding([.leading], 2)
- .event_context_menu(event, keypair: damus.keypair)
+ .event_context_menu(event, privkey: damus.keypair.privkey, pubkey: event.pubkey)
}
}
}