home: move subscriptions to timeline
This commit is contained in:
11
Cargo.lock
generated
11
Cargo.lock
generated
@@ -876,7 +876,6 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"shatter",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
@@ -978,7 +977,6 @@ dependencies = [
|
|||||||
"objc",
|
"objc",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pollster",
|
|
||||||
"puffin",
|
"puffin",
|
||||||
"raw-window-handle 0.5.2",
|
"raw-window-handle 0.5.2",
|
||||||
"raw-window-handle 0.6.0",
|
"raw-window-handle 0.6.0",
|
||||||
@@ -988,7 +986,6 @@ dependencies = [
|
|||||||
"wasm-bindgen-futures",
|
"wasm-bindgen-futures",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"web-time",
|
"web-time",
|
||||||
"wgpu",
|
|
||||||
"winapi",
|
"winapi",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
@@ -2666,12 +2663,6 @@ dependencies = [
|
|||||||
"windows-sys 0.52.0",
|
"windows-sys 0.52.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "pollster"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "powerfmt"
|
name = "powerfmt"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
@@ -4268,7 +4259,6 @@ dependencies = [
|
|||||||
"cfg_aliases",
|
"cfg_aliases",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"profiling",
|
"profiling",
|
||||||
"raw-window-handle 0.6.0",
|
"raw-window-handle 0.6.0",
|
||||||
@@ -4318,7 +4308,6 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
"ash",
|
"ash",
|
||||||
"bitflags 2.4.2",
|
"bitflags 2.4.2",
|
||||||
"block",
|
|
||||||
"cfg_aliases",
|
"cfg_aliases",
|
||||||
"core-graphics-types",
|
"core-graphics-types",
|
||||||
"glow",
|
"glow",
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ crate-type = ["lib", "cdylib"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
#egui-android = { git = "https://github.com/jb55/egui-android.git" }
|
#egui-android = { git = "https://github.com/jb55/egui-android.git" }
|
||||||
egui = "0.26.0"
|
egui = "0.26.0"
|
||||||
eframe = { version = "0.26.0", default-features = false, features = [ "glow", "wgpu", "android-native-activity" ] }
|
eframe = { version = "0.26.0", default-features = false, features = [ "glow", "android-native-activity" ] }
|
||||||
#eframe = "0.22.0"
|
#eframe = "0.22.0"
|
||||||
egui_extras = { version = "0.26.0", features = ["image", "svg"] }
|
egui_extras = { version = "0.26.0", features = ["image", "svg"] }
|
||||||
ehttp = "0.2.0"
|
ehttp = "0.2.0"
|
||||||
@@ -27,7 +27,6 @@ tracing = "0.1.40"
|
|||||||
enostr = { path = "enostr" }
|
enostr = { path = "enostr" }
|
||||||
serde_json = "1.0.89"
|
serde_json = "1.0.89"
|
||||||
env_logger = "0.10.0"
|
env_logger = "0.10.0"
|
||||||
shatter = "0.1.1"
|
|
||||||
puffin_egui = { version = "0.25.0", optional = true }
|
puffin_egui = { version = "0.25.0", optional = true }
|
||||||
puffin = { version = "0.19.0", optional = true }
|
puffin = { version = "0.19.0", optional = true }
|
||||||
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "e513b6ed516a9adf757c1f7ac26cd3d544c391b2" }
|
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "e513b6ed516a9adf757c1f7ac26cd3d544c391b2" }
|
||||||
|
|||||||
80
src/app.rs
80
src/app.rs
@@ -1,5 +1,6 @@
|
|||||||
use crate::abbrev;
|
use crate::abbrev;
|
||||||
use crate::contacts::Contacts;
|
use crate::contacts::Contacts;
|
||||||
|
use crate::error::Error;
|
||||||
use crate::fonts::{setup_fonts, setup_gossip_fonts};
|
use crate::fonts::{setup_fonts, setup_gossip_fonts};
|
||||||
use crate::frame_history::FrameHistory;
|
use crate::frame_history::FrameHistory;
|
||||||
use crate::images::fetch_img;
|
use crate::images::fetch_img;
|
||||||
@@ -71,14 +72,19 @@ impl Ord for NoteRef {
|
|||||||
|
|
||||||
struct Timeline {
|
struct Timeline {
|
||||||
pub notes: Vec<NoteRef>,
|
pub notes: Vec<NoteRef>,
|
||||||
|
pub subscription: Option<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Timeline {
|
impl Timeline {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let mut notes: Vec<NoteRef> = vec![];
|
let mut notes: Vec<NoteRef> = vec![];
|
||||||
notes.reserve(1000);
|
notes.reserve(1000);
|
||||||
|
let subscription: Option<Subscription> = None;
|
||||||
|
|
||||||
Timeline { notes }
|
Timeline {
|
||||||
|
notes,
|
||||||
|
subscription,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +96,6 @@ pub struct Damus {
|
|||||||
compose: String,
|
compose: String,
|
||||||
|
|
||||||
pool: RelayPool,
|
pool: RelayPool,
|
||||||
home_sub: Option<Subscription>,
|
|
||||||
|
|
||||||
timelines: Vec<Timeline>,
|
timelines: Vec<Timeline>,
|
||||||
|
|
||||||
@@ -174,36 +179,52 @@ fn try_process_event(damus: &mut Damus, ctx: &egui::Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do we have any new processed events?
|
for timeline in 0..damus.timelines.len() {
|
||||||
if let Some(ref sub) = damus.home_sub {
|
if let Err(err) = poll_notes_for_timeline(damus, timeline) {
|
||||||
let new_note_ids = damus.ndb.poll_for_notes(sub, 100);
|
error!("{}", err);
|
||||||
if new_note_ids.len() > 0 {
|
|
||||||
info!("{} new notes! {:?}", new_note_ids.len(), new_note_ids);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(txn) = Transaction::new(&damus.ndb) {
|
|
||||||
let new_refs = new_note_ids
|
|
||||||
.iter()
|
|
||||||
.map(|key| {
|
|
||||||
let note = damus
|
|
||||||
.ndb
|
|
||||||
.get_note_by_key(&txn, NoteKey::new(*key))
|
|
||||||
.expect("no note??");
|
|
||||||
NoteRef {
|
|
||||||
key: NoteKey::new(*key),
|
|
||||||
created_at: note.created_at(),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
damus.timelines[0].notes =
|
|
||||||
timeline::merge_sorted_vecs(&damus.timelines[0].notes, &new_refs);
|
|
||||||
} else {
|
|
||||||
error!("Transaction error when polling")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn poll_notes_for_timeline(damus: &mut Damus, timeline: usize) -> Result<()> {
|
||||||
|
let sub = if let Some(sub) = &damus.timelines[timeline].subscription {
|
||||||
|
sub
|
||||||
|
} else {
|
||||||
|
return Err(Error::NoActiveSubscription);
|
||||||
|
};
|
||||||
|
|
||||||
|
let new_note_ids = damus.ndb.poll_for_notes(&sub, 100);
|
||||||
|
if new_note_ids.len() > 0 {
|
||||||
|
info!("{} new notes! {:?}", new_note_ids.len(), new_note_ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
let txn = Transaction::new(&damus.ndb)?;
|
||||||
|
|
||||||
|
let mut pubkeys: HashSet<&[u8; 32]> = HashSet::new();
|
||||||
|
|
||||||
|
let new_refs = new_note_ids
|
||||||
|
.iter()
|
||||||
|
.map(|key| {
|
||||||
|
let note = damus
|
||||||
|
.ndb
|
||||||
|
.get_note_by_key(&txn, NoteKey::new(*key))
|
||||||
|
.expect("no note??");
|
||||||
|
|
||||||
|
pubkeys.insert(note.pubkey());
|
||||||
|
|
||||||
|
NoteRef {
|
||||||
|
key: NoteKey::new(*key),
|
||||||
|
created_at: note.created_at(),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
damus.timelines[timeline].notes =
|
||||||
|
timeline::merge_sorted_vecs(&damus.timelines[timeline].notes, &new_refs);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "profiling")]
|
#[cfg(feature = "profiling")]
|
||||||
fn setup_profiling() {
|
fn setup_profiling() {
|
||||||
puffin::set_scopes_on(true); // tell puffin to collect data
|
puffin::set_scopes_on(true); // tell puffin to collect data
|
||||||
@@ -212,7 +233,7 @@ fn setup_profiling() {
|
|||||||
fn setup_initial_nostrdb_subs(damus: &mut Damus) -> Result<()> {
|
fn setup_initial_nostrdb_subs(damus: &mut Damus) -> Result<()> {
|
||||||
let filter: nostrdb::Filter = crate::filter::convert_enostr_filter(&get_home_filter());
|
let filter: nostrdb::Filter = crate::filter::convert_enostr_filter(&get_home_filter());
|
||||||
let filters = vec![filter];
|
let filters = vec![filter];
|
||||||
damus.home_sub = Some(damus.ndb.subscribe(filters.clone())?);
|
damus.timelines[0].subscription = Some(damus.ndb.subscribe(filters.clone())?);
|
||||||
let txn = Transaction::new(&damus.ndb)?;
|
let txn = Transaction::new(&damus.ndb)?;
|
||||||
let res = damus.ndb.query(&txn, filters, 100)?;
|
let res = damus.ndb.query(&txn, filters, 100)?;
|
||||||
damus.timelines[0].notes = res
|
damus.timelines[0].notes = res
|
||||||
@@ -353,7 +374,6 @@ impl Damus {
|
|||||||
state: DamusState::Initializing,
|
state: DamusState::Initializing,
|
||||||
contacts: Contacts::new(),
|
contacts: Contacts::new(),
|
||||||
pool: RelayPool::new(),
|
pool: RelayPool::new(),
|
||||||
home_sub: None,
|
|
||||||
img_cache: HashMap::new(),
|
img_cache: HashMap::new(),
|
||||||
n_panels: 1,
|
n_panels: 1,
|
||||||
timelines: vec![Timeline::new()],
|
timelines: vec![Timeline::new()],
|
||||||
|
|||||||
24
src/error.rs
24
src/error.rs
@@ -1,26 +1,34 @@
|
|||||||
use shatter::parser;
|
use std::fmt;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
NoActiveSubscription,
|
||||||
Nostr(enostr::Error),
|
Nostr(enostr::Error),
|
||||||
Ndb(nostrdb::Error),
|
Ndb(nostrdb::Error),
|
||||||
Shatter(parser::Error),
|
|
||||||
Image(image::error::ImageError),
|
Image(image::error::ImageError),
|
||||||
Generic(String),
|
Generic(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Error {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
Self::NoActiveSubscription => {
|
||||||
|
write!(f, "subscription not active in timeline")
|
||||||
|
}
|
||||||
|
Self::Nostr(e) => write!(f, "{e}"),
|
||||||
|
Self::Ndb(e) => write!(f, "{e}"),
|
||||||
|
Self::Image(e) => write!(f, "{e}"),
|
||||||
|
Self::Generic(e) => write!(f, "{e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<String> for Error {
|
impl From<String> for Error {
|
||||||
fn from(s: String) -> Self {
|
fn from(s: String) -> Self {
|
||||||
Error::Generic(s)
|
Error::Generic(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<parser::Error> for Error {
|
|
||||||
fn from(s: parser::Error) -> Self {
|
|
||||||
Error::Shatter(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<nostrdb::Error> for Error {
|
impl From<nostrdb::Error> for Error {
|
||||||
fn from(e: nostrdb::Error) -> Self {
|
fn from(e: nostrdb::Error) -> Self {
|
||||||
Error::Ndb(e)
|
Error::Ndb(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user