From 3384d2af148751430a51756ce9658e0a4636a6d0 Mon Sep 17 00:00:00 2001 From: kernelkind Date: Fri, 3 Jan 2025 17:44:47 -0500 Subject: [PATCH] new profile responses Signed-off-by: kernelkind --- crates/notedeck_columns/src/profile.rs | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/crates/notedeck_columns/src/profile.rs b/crates/notedeck_columns/src/profile.rs index 229ab957..abcb7d3b 100644 --- a/crates/notedeck_columns/src/profile.rs +++ b/crates/notedeck_columns/src/profile.rs @@ -1,11 +1,12 @@ -use enostr::{Filter, Pubkey}; -use nostrdb::{FilterBuilder, Ndb, ProfileRecord, Transaction}; +use enostr::{Filter, FullKeypair, Pubkey}; +use nostrdb::{FilterBuilder, Ndb, Note, NoteBuilder, ProfileRecord, Transaction}; use notedeck::{filter::default_limit, FilterState, MuteFun, NoteCache, NoteRef}; use crate::{ multi_subscriber::MultiSubscriber, notes_holder::NotesHolder, + profile_state::ProfileState, timeline::{copy_notes_into_timeline, PubkeySource, Timeline, TimelineKind, TimelineTab}, }; @@ -155,3 +156,35 @@ impl NotesHolder for Profile { self.multi_subscriber = Some(subscriber); } } + +pub struct SaveProfileChanges { + pub kp: FullKeypair, + pub state: ProfileState, +} + +impl SaveProfileChanges { + pub fn new(kp: FullKeypair, state: ProfileState) -> Self { + Self { kp, state } + } + pub fn to_note(&self) -> Note { + let sec = &self.kp.secret_key.to_secret_bytes(); + add_client_tag(NoteBuilder::new()) + .kind(0) + .content(&self.state.to_json()) + .sign(sec) + .build() + .expect("should build") + } +} + +fn add_client_tag(builder: NoteBuilder<'_>) -> NoteBuilder<'_> { + builder + .start_tag() + .tag_str("client") + .tag_str("Damus Notedeck") +} + +pub enum ProfileAction { + Edit(FullKeypair), + SaveChanges(SaveProfileChanges), +}