blocks: pass keypair instead of privkey to avoid pubkey gen
Generating a pubkey is quite slow, so pass a keypair instead of privkey
This commit is contained in:
@@ -17,7 +17,7 @@ struct DMView: View {
|
||||
|
||||
var Mention: some View {
|
||||
Group {
|
||||
if let mention = first_eref_mention(ev: event, privkey: damus_state.keypair.privkey) {
|
||||
if let mention = first_eref_mention(ev: event, keypair: damus_state.keypair) {
|
||||
BuilderEventView(damus: damus_state, event_id: mention.ref)
|
||||
} else {
|
||||
EmptyView()
|
||||
|
||||
@@ -10,11 +10,11 @@ import SwiftUI
|
||||
struct ReplyPart: View {
|
||||
let events: EventCache
|
||||
let event: NostrEvent
|
||||
let privkey: Privkey?
|
||||
let keypair: Keypair
|
||||
let profiles: Profiles
|
||||
|
||||
var replying_to: NostrEvent? {
|
||||
guard let note_ref = event.event_refs(privkey).first(where: { evref in evref.is_direct_reply != nil })?.is_direct_reply else {
|
||||
guard let note_ref = event.event_refs(keypair).first(where: { evref in evref.is_direct_reply != nil })?.is_direct_reply else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ struct ReplyPart: View {
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if event_is_reply(event.event_refs(privkey)) {
|
||||
if event_is_reply(event.event_refs(keypair)) {
|
||||
ReplyDescription(event: event, replying_to: replying_to, profiles: profiles)
|
||||
} else {
|
||||
EmptyView()
|
||||
@@ -34,6 +34,6 @@ struct ReplyPart: View {
|
||||
|
||||
struct ReplyPart_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ReplyPart(events: test_damus_state().events, event: test_note, privkey: nil, profiles: test_damus_state().profiles)
|
||||
ReplyPart(events: test_damus_state().events, event: test_note, keypair: Keypair(pubkey: .empty, privkey: nil), profiles: test_damus_state().profiles)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ struct MenuItems: View {
|
||||
let bookmarked = bookmarks.isBookmarked(event)
|
||||
self._isBookmarked = State(initialValue: bookmarked)
|
||||
|
||||
let muted_thread = muted_threads.isMutedThread(event, privkey: keypair.privkey)
|
||||
let muted_thread = muted_threads.isMutedThread(event, keypair: keypair)
|
||||
self._isMutedThread = State(initialValue: muted_thread)
|
||||
|
||||
self.bookmarks = bookmarks
|
||||
@@ -68,7 +68,7 @@ struct MenuItems: View {
|
||||
var body: some View {
|
||||
Group {
|
||||
Button {
|
||||
UIPasteboard.general.string = event.get_content(keypair.privkey)
|
||||
UIPasteboard.general.string = event.get_content(keypair)
|
||||
} label: {
|
||||
Label(NSLocalizedString("Copy text", comment: "Context menu option for copying the text from an note."), image: "copy2")
|
||||
}
|
||||
@@ -106,7 +106,7 @@ struct MenuItems: View {
|
||||
if event.known_kind != .dm {
|
||||
Button {
|
||||
self.muted_threads.updateMutedThread(event)
|
||||
let muted = self.muted_threads.isMutedThread(event, privkey: self.keypair.privkey)
|
||||
let muted = self.muted_threads.isMutedThread(event, keypair: self.keypair)
|
||||
isMutedThread = muted
|
||||
} label: {
|
||||
let imageName = isMutedThread ? "mute" : "mute"
|
||||
|
||||
@@ -39,7 +39,7 @@ struct EventShell<Content: View>: View {
|
||||
return nil
|
||||
}
|
||||
|
||||
return first_eref_mention(ev: event, privkey: state.keypair.privkey)
|
||||
return first_eref_mention(ev: event, keypair: state.keypair)
|
||||
}
|
||||
|
||||
func Mention(_ mention: Mention<NoteId>) -> some View {
|
||||
@@ -71,7 +71,7 @@ struct EventShell<Content: View>: View {
|
||||
UserStatusView(status: state.profiles.profile_data(pubkey).status, show_general: state.settings.show_general_statuses, show_music: state.settings.show_music_statuses)
|
||||
|
||||
if !options.contains(.no_replying_to) {
|
||||
ReplyPart(events: state.events, event: event, privkey: state.keypair.privkey, profiles: state.profiles)
|
||||
ReplyPart(events: state.events, event: event, keypair: state.keypair, profiles: state.profiles)
|
||||
}
|
||||
|
||||
content
|
||||
@@ -98,7 +98,7 @@ struct EventShell<Content: View>: View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
EventTop(state: state, event: event, pubkey: pubkey, is_anon: is_anon)
|
||||
UserStatusView(status: state.profiles.profile_data(pubkey).status, show_general: state.settings.show_general_statuses, show_music: state.settings.show_music_statuses)
|
||||
ReplyPart(events: state.events, event: event, privkey: state.keypair.privkey, profiles: state.profiles)
|
||||
ReplyPart(events: state.events, event: event, keypair: state.keypair, profiles: state.profiles)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
|
||||
@@ -76,8 +76,8 @@ let test_longform_event = LongformEvent.parse(from: NostrEvent(
|
||||
struct LongformView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
let st = test_damus_state()
|
||||
let artifacts = render_note_content(ev: test_longform_event.event, profiles: st.profiles, privkey: nil)
|
||||
|
||||
let artifacts = render_note_content(ev: test_longform_event.event, profiles: st.profiles, keypair: Keypair(pubkey: .empty, privkey: nil))
|
||||
|
||||
let model = NoteArtifactsModel(state: .loaded(artifacts))
|
||||
ScrollView {
|
||||
LongformView(state: st, event: test_longform_event, artifacts: model)
|
||||
|
||||
@@ -18,11 +18,11 @@ struct MutedEventView: View {
|
||||
self.damus_state = damus_state
|
||||
self.event = event
|
||||
self.selected = selected
|
||||
self._shown = State(initialValue: should_show_event(privkey: damus_state.keypair.privkey, hellthreads: damus_state.muted_threads, contacts: damus_state.contacts, ev: event))
|
||||
self._shown = State(initialValue: should_show_event(keypair: damus_state.keypair, hellthreads: damus_state.muted_threads, contacts: damus_state.contacts, ev: event))
|
||||
}
|
||||
|
||||
var should_mute: Bool {
|
||||
return !should_show_event(privkey: damus_state.keypair.privkey, hellthreads: damus_state.muted_threads, contacts: damus_state.contacts, ev: event)
|
||||
return !should_show_event(keypair: damus_state.keypair, hellthreads: damus_state.muted_threads, contacts: damus_state.contacts, ev: event)
|
||||
}
|
||||
|
||||
var MutedBox: some View {
|
||||
|
||||
@@ -19,7 +19,7 @@ struct SelectedEventView: View {
|
||||
@StateObject var bar: ActionBarModel
|
||||
|
||||
var replying_to: NostrEvent? {
|
||||
guard let note_ref = event.event_refs(damus.keypair.privkey).first(where: { evref in evref.is_direct_reply != nil })?.is_direct_reply else {
|
||||
guard let note_ref = event.event_refs(damus.keypair).first(where: { evref in evref.is_direct_reply != nil })?.is_direct_reply else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -50,14 +50,14 @@ struct SelectedEventView: View {
|
||||
.minimumScaleFactor(0.75)
|
||||
.lineLimit(1)
|
||||
|
||||
if event_is_reply(event.event_refs(damus.keypair.privkey)) {
|
||||
if event_is_reply(event.event_refs(damus.keypair)) {
|
||||
ReplyDescription(event: event, replying_to: replying_to, profiles: damus.profiles)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
EventBody(damus_state: damus, event: event, size: size, options: [.wide])
|
||||
|
||||
if let mention = first_eref_mention(ev: event, privkey: damus.keypair.privkey) {
|
||||
if let mention = first_eref_mention(ev: event, keypair: damus.keypair) {
|
||||
BuilderEventView(damus: damus, event_id: mention.ref)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ struct NoteContentView: View {
|
||||
@ObservedObject var settings: UserSettingsStore
|
||||
|
||||
var note_artifacts: NoteArtifacts {
|
||||
return self.artifacts_model.state.artifacts ?? .separated(.just_content(event.get_content(damus_state.keypair.privkey)))
|
||||
return self.artifacts_model.state.artifacts ?? .separated(.just_content(event.get_content(damus_state.keypair)))
|
||||
}
|
||||
|
||||
init(damus_state: DamusState, event: NostrEvent, show_images: Bool, size: EventViewKind, options: EventViewOptions) {
|
||||
@@ -180,7 +180,7 @@ struct NoteContentView: View {
|
||||
}
|
||||
await preload_event(plan: plan, state: damus_state)
|
||||
} else if force_artifacts {
|
||||
let arts = render_note_content(ev: event, profiles: damus_state.profiles, privkey: damus_state.keypair.privkey)
|
||||
let arts = render_note_content(ev: event, profiles: damus_state.profiles, keypair: damus_state.keypair)
|
||||
self.artifacts_model.state = .loaded(arts)
|
||||
}
|
||||
}
|
||||
@@ -228,7 +228,7 @@ struct NoteContentView: View {
|
||||
var body: some View {
|
||||
ArtifactContent
|
||||
.onReceive(handle_notify(.profile_updated)) { profile in
|
||||
let blocks = event.blocks(damus_state.keypair.privkey)
|
||||
let blocks = event.blocks(damus_state.keypair)
|
||||
for block in blocks.blocks {
|
||||
switch block {
|
||||
case .mention(let m):
|
||||
@@ -394,8 +394,8 @@ func note_artifact_is_separated(kind: NostrKind?) -> Bool {
|
||||
return kind != .longform
|
||||
}
|
||||
|
||||
func render_note_content(ev: NostrEvent, profiles: Profiles, privkey: Privkey?) -> NoteArtifacts {
|
||||
let blocks = ev.blocks(privkey)
|
||||
func render_note_content(ev: NostrEvent, profiles: Profiles, keypair: Keypair) -> NoteArtifacts {
|
||||
let blocks = ev.blocks(keypair)
|
||||
|
||||
if ev.known_kind == .longform {
|
||||
return .longform(LongformContent(ev.content))
|
||||
|
||||
@@ -50,7 +50,7 @@ struct SearchHomeView: View {
|
||||
damus: damus_state,
|
||||
show_friend_icon: true,
|
||||
filter: { ev in
|
||||
if damus_state.muted_threads.isMutedThread(ev, privkey: self.damus_state.keypair.privkey) {
|
||||
if damus_state.muted_threads.isMutedThread(ev, keypair: self.damus_state.keypair) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ struct ThreadView: View {
|
||||
@Environment(\.dismiss) var dismiss
|
||||
|
||||
var parent_events: [NostrEvent] {
|
||||
state.events.parent_events(event: thread.event, privkey: state.keypair.privkey)
|
||||
state.events.parent_events(event: thread.event, keypair: state.keypair)
|
||||
}
|
||||
|
||||
var child_events: [NostrEvent] {
|
||||
@@ -34,7 +34,7 @@ struct ThreadView: View {
|
||||
selected: false)
|
||||
.padding(.horizontal)
|
||||
.onTapGesture {
|
||||
thread.set_active_event(parent_event, privkey: self.state.keypair.privkey)
|
||||
thread.set_active_event(parent_event, keypair: self.state.keypair)
|
||||
scroll_to_event(scroller: reader, id: parent_event.id, delay: 0.1, animate: false)
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ struct ThreadView: View {
|
||||
)
|
||||
.padding(.horizontal)
|
||||
.onTapGesture {
|
||||
thread.set_active_event(child_event, privkey: state.keypair.privkey)
|
||||
thread.set_active_event(child_event, keypair: state.keypair)
|
||||
scroll_to_event(scroller: reader, id: child_event.id, delay: 0.1, animate: false)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user