commit a04df88ff6e0afbe9e5c3135219d060ba6bb7143
parent 8dc829791e5f364081257292cd9967252c07a898
Author: William Casarin <jb55@jb55.com>
Date: Mon, 1 Jul 2024 06:42:04 -0700
initial note posting
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
9 files changed, 70 insertions(+), 45 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
@@ -437,12 +437,6 @@ dependencies = [
]
[[package]]
-name = "bitcoin-private"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "73290177011694f38ec25e165d0387ab7ea749a4b81cd4c80dae5988229f7a57"
-
-[[package]]
name = "bitcoin_hashes"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -450,15 +444,6 @@ checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4"
[[package]]
name = "bitcoin_hashes"
-version = "0.12.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5d7066118b13d4b20b23645932dfb3a81ce7e29f95726c2036fa33cd7b092501"
-dependencies = [
- "bitcoin-private",
-]
-
-[[package]]
-name = "bitcoin_hashes"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b"
@@ -2440,8 +2425,8 @@ dependencies = [
[[package]]
name = "nostrdb"
-version = "0.3.3"
-source = "git+https://github.com/damus-io/nostrdb-rs?rev=5733ece62b8495db8624a21637bacd12ebb22b2c#5733ece62b8495db8624a21637bacd12ebb22b2c"
+version = "0.3.4"
+source = "git+https://github.com/damus-io/nostrdb-rs?rev=ee8afeeb0b6695fca6d27dd0b74a8dc159e37b95#ee8afeeb0b6695fca6d27dd0b74a8dc159e37b95"
dependencies = [
"bindgen",
"cc",
@@ -3415,7 +3400,7 @@ version = "0.28.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10"
dependencies = [
- "bitcoin_hashes 0.12.0",
+ "bitcoin_hashes 0.13.0",
"rand",
"secp256k1-sys",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
@@ -46,8 +46,8 @@ serde_json = "1.0.89"
env_logger = "0.10.0"
puffin_egui = { version = "0.27.0", optional = true }
puffin = { version = "0.19.0", optional = true }
-nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "5733ece62b8495db8624a21637bacd12ebb22b2c" }
-#nostrdb = "0.3.3"
+nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "ee8afeeb0b6695fca6d27dd0b74a8dc159e37b95" }
+#nostrdb = "0.3.4"
hex = "0.4.3"
base32 = "0.4.0"
strum = "0.26"
diff --git a/enostr/src/lib.rs b/enostr/src/lib.rs
@@ -1,6 +1,5 @@
mod client;
mod error;
-mod event;
mod filter;
mod keypair;
mod note;
diff --git a/src/app.rs b/src/app.rs
@@ -1,7 +1,7 @@
use crate::account_manager::AccountManager;
use crate::app_creation::setup_cc;
use crate::app_style::user_requested_visuals_change;
-use crate::draft::{DraftSource, Drafts};
+use crate::draft::Drafts;
use crate::error::Error;
use crate::frame_history::FrameHistory;
use crate::imgcache::ImageCache;
@@ -14,7 +14,7 @@ use crate::ui::{self, AccountSelectionWidget, DesktopGlobalPopup};
use crate::ui::{DesktopSidePanel, RelayView, View};
use crate::Result;
use egui_nav::{Nav, NavAction};
-use enostr::RelayPool;
+use enostr::{RelayPool, SecretKey};
use std::cell::RefCell;
use std::rc::Rc;
@@ -268,7 +268,7 @@ impl<'a> UnknownId<'a> {
fn get_unknown_note_ids<'a>(
ndb: &Ndb,
- cached_note: &CachedNote,
+ _cached_note: &CachedNote,
txn: &'a Transaction,
note: &Note<'a>,
note_key: NoteKey,
@@ -281,6 +281,7 @@ fn get_unknown_note_ids<'a>(
}
// pull notes that notes are replying to
+ /* TODO: FIX tags lifetime
if cached_note.reply.root.is_some() {
let note_reply = cached_note.reply.borrow(note.tags());
if let Some(root) = note_reply.root() {
@@ -297,6 +298,7 @@ fn get_unknown_note_ids<'a>(
}
}
}
+ */
let blocks = ndb.get_blocks_by_key(txn, note_key)?;
for block in blocks.iter(note) {
@@ -943,20 +945,6 @@ fn render_nav(routes: Vec<Route>, timeline_ind: usize, app: &mut Damus, ui: &mut
.show(ui, |ui, nav| match nav.top() {
Route::Timeline(_n) => {
let app = &mut app_ctx.borrow_mut();
-
- if timeline_ind == 0 {
- // show a postbox in the first timeline
-
- // TODO: don't show the post box if we have no accounts
- let poster = app
- .account_manager
- .get_selected_account_index()
- .unwrap_or(0);
-
- if let Ok(txn) = Transaction::new(&app.ndb) {
- ui::PostView::new(app, DraftSource::Compose, poster).ui(&txn, ui);
- }
- }
timeline::timeline_view(ui, app, timeline_ind);
}
diff --git a/src/lib.rs b/src/lib.rs
@@ -19,6 +19,7 @@ mod key_storage;
pub mod login_manager;
mod macos_key_storage;
mod notecache;
+mod post;
mod profile;
pub mod relay_pool_manager;
mod result;
diff --git a/src/post.rs b/src/post.rs
@@ -0,0 +1,17 @@
+use nostrdb::NoteBuilder;
+
+pub struct NewPost {
+ pub content: String,
+ pub account: usize,
+}
+
+impl NewPost {
+ pub fn to_note(&self, seckey: &[u8; 32]) -> nostrdb::Note {
+ NoteBuilder::new()
+ .kind(1)
+ .content(&self.content)
+ .sign(seckey)
+ .build()
+ .expect("note should be ok")
+ }
+}
diff --git a/src/timeline.rs b/src/timeline.rs
@@ -1,4 +1,6 @@
+use crate::draft::DraftSource;
use crate::notecache::CachedNote;
+use crate::ui::note::PostAction;
use crate::{ui, Damus};
use crate::route::Route;
@@ -14,7 +16,7 @@ use std::cell::RefCell;
use std::cmp::Ordering;
use std::rc::Rc;
-use log::{debug, warn};
+use tracing::{debug, info, warn};
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub struct NoteRef {
@@ -265,6 +267,43 @@ pub fn timeline_view(ui: &mut egui::Ui, app: &mut Damus, timeline: usize) {
let row_height = ui.fonts(|f| f.row_height(&font_id)) + ui.spacing().item_spacing.y;
*/
+ if timeline == 0 {
+ // show a postbox in the first timeline
+
+ if let Some(account) = app.account_manager.get_selected_account_index() {
+ if app
+ .account_manager
+ .get_selected_account()
+ .map_or(false, |a| a.secret_key.is_some())
+ {
+ if let Ok(txn) = Transaction::new(&app.ndb) {
+ let response =
+ ui::PostView::new(app, DraftSource::Compose, account).ui(&txn, ui);
+
+ if let Some(action) = response.action {
+ match action {
+ PostAction::Post(np) => {
+ let seckey = app
+ .account_manager
+ .get_account(account)
+ .unwrap()
+ .secret_key
+ .as_ref()
+ .unwrap()
+ .to_secret_bytes();
+
+ let note = np.to_note(&seckey);
+ let raw_msg = format!("[\"EVENT\",{}]", note.json().unwrap());
+ info!("sending {}", raw_msg);
+ app.pool.send(&enostr::ClientMessage::raw(raw_msg));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
tabs_ui(&mut app.timelines[timeline], ui);
// need this for some reason??
diff --git a/src/ui/note/mod.rs b/src/ui/note/mod.rs
@@ -5,7 +5,7 @@ pub mod reply;
pub use contents::NoteContents;
pub use options::NoteOptions;
-pub use post::PostView;
+pub use post::{PostAction, PostResponse, PostView};
pub use reply::PostReplyView;
use crate::{colors, notecache::CachedNote, ui, ui::View, Damus};
diff --git a/src/ui/note/post.rs b/src/ui/note/post.rs
@@ -1,5 +1,6 @@
use crate::app::Damus;
use crate::draft::{Draft, DraftSource};
+use crate::post::NewPost;
use crate::ui;
use crate::ui::{Preview, PreviewConfig, View};
use egui::widgets::text_edit::TextEdit;
@@ -13,11 +14,6 @@ pub struct PostView<'app, 'd> {
id_source: Option<egui::Id>,
}
-pub struct NewPost {
- pub content: String,
- pub account: usize,
-}
-
pub enum PostAction {
Post(NewPost),
}