Skip to content

Commit

Permalink
wip fedimint recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
jb55 committed May 4, 2024
1 parent 3221537 commit 6b647d2
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

[build]
rustflags = ["--cfg", "tokio_unstable"]
rustdocflags = ["--cfg", "tokio_unstable"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ src/camera.rs
*.txt
/tags
*.mdb
multimint
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ crate-type = ["lib", "cdylib"]
[dependencies]
#egui-android = { git = "https://github.com/jb55/egui-android.git" }
egui = "0.27.2"
eframe = { version = "0.27.2", default-features = false, features = [ "glow", "wgpu", "android-native-activity" ] }
#eframe = { version = "0.26.0", default-features = false, features = [ "glow", "android-native-activity" ] }
#eframe = { version = "0.27.2", default-features = false, features = [ "glow", "wgpu", "android-native-activity" ] }
eframe = { version = "0.27.2", default-features = false, features = [ "glow", "android-native-activity" ] }
#eframe = "0.22.0"
egui_extras = { version = "0.27.2", features = ["all_loaders"] }
ehttp = "0.2.0"
Expand All @@ -41,6 +41,8 @@ strum = "0.26"
strum_macros = "0.26"
bitflags = "2.5.0"
egui_virtual_list = "0.3.0"
multimint = "0.3.4"
anyhow = "1.0.82"


[features]
Expand Down
5 changes: 4 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let

in
mkShell ({
buildInputs = [] ++ pkgs.lib.optional use_android [
buildInputs = [rustPlatform.bindgenHook rocksdb] ++ pkgs.lib.optional use_android [

android-sdk
];
nativeBuildInputs = [
Expand All @@ -33,6 +34,7 @@ mkShell ({
rustfmt
libiconv
pkg-config
gdb
#cmake
fontconfig
openssl
Expand All @@ -52,6 +54,7 @@ mkShell ({
darwin.apple_sdk.frameworks.AppKit
];

LIBCLANG_PATH="${pkgs.llvmPackages.libclang.lib}/lib";
ANDROID_NDK_ROOT = android-ndk-path;
} // (if !stdenv.isDarwin then {
LD_LIBRARY_PATH="${x11libs}";
Expand Down
46 changes: 45 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ use crate::timeline;
use crate::timeline::{NoteRef, Timeline};
use crate::ui::is_mobile;
use crate::Result;
use tokio::task::spawn_blocking;

use std::str::FromStr;

use multimint::fedimint_core::api::InviteCode;
use multimint::fedimint_core::config::FederationId;
use multimint::MultiMint;

use egui::{Context, Frame, Margin, Style};
use egui_extras::{Size, StripBuilder};

use enostr::{ClientMessage, Filter, Pubkey, RelayEvent, RelayMessage};
use nostrdb::{BlockType, Config, Mention, Ndb, Note, NoteKey, Transaction};
use nostrdb::{BlockType, Config, Mention, Ndb, Note, NoteKey, ProfileKey, Transaction};

use std::collections::{HashMap, HashSet};
use std::hash::Hash;
Expand Down Expand Up @@ -42,6 +49,9 @@ pub struct Damus {
pub img_cache: ImageCache,
pub ndb: Ndb,

mint: MultiMint,
mint_recs: HashMap<FederationId, HashSet<[u8; 32]>>,

frame_history: crate::frame_history::FrameHistory,
}

Expand Down Expand Up @@ -298,6 +308,35 @@ fn setup_initial_nostrdb_subs(damus: &mut Damus) -> Result<()> {
filters,
timeline.filter[0].limit.unwrap_or(200) as i32,
)?;

for result in &res {
if result.note.kind() == 38000 {
for tag in result.note.tags() {
if tag.count() < 2 {
continue;
}
if tag.get_unchecked(0).variant().str() == Some("u") {
let inv_str = if let Some(s) = tag.get_unchecked(1).variant().str() {
s
} else {
continue;
};

if let Ok(code) = InviteCode::from_str(inv_str) {
let fed_id = code.federation_id();
damus
.mint_recs
.entry(fed_id)
.or_insert_with(|| HashSet::new())
.insert(result.note.pubkey().to_owned());
}
}
}
}
}

println!("{:?}", damus.mint_recs);

timeline.notes = res
.iter()
.map(|qr| NoteRef {
Expand Down Expand Up @@ -430,6 +469,7 @@ impl Damus {
pub fn new<P: AsRef<Path>>(
cc: &eframe::CreationContext<'_>,
data_path: P,
mint: MultiMint,
args: Vec<String>,
) -> Self {
// This is also where you can customized the look at feel of egui using
Expand Down Expand Up @@ -461,13 +501,17 @@ impl Damus {

let mut config = Config::new();
config.set_ingester_threads(2);
let mint_recs = HashMap::new();

Self {
state: DamusState::Initializing,
pool: RelayPool::new(),
img_cache: ImageCache::new(imgcache_dir),
note_cache: HashMap::new(),
timelines,
textmode: false,
mint,
mint_recs,
ndb: Ndb::new(data_path.as_ref().to_str().expect("db path ok"), &config).expect("ndb"),
//compose: "".to_string(),
frame_history: FrameHistory::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/app_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub fn create_themed_visuals(theme: ColorTheme, default: Visuals) -> Visuals {
},
extreme_bg_color: theme.extreme_bg_color,
error_fg_color: theme.err_fg_color,
window_rounding: Rounding::same(32.0),
window_rounding: Rounding::same(8.0),
window_fill: theme.window_fill,
window_shadow: Shadow {
offset: [0.0, 8.0].into(),
Expand Down
13 changes: 9 additions & 4 deletions src/bin/notedeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use notedeck::app_creation::generate_native_options;
use notedeck::Damus;
use multimint::MultiMint;
use notedeck::Error;

use std::path::PathBuf;

// Entry point for wasm
//#[cfg(target_arch = "wasm32")]
Expand All @@ -10,15 +14,16 @@ use notedeck::Damus;
// Desktop
#[cfg(not(target_arch = "wasm32"))]
#[tokio::main]
async fn main() {
async fn main() -> Result<(), Error> {
// Log to stdout (if you run with `RUST_LOG=debug`).
tracing_subscriber::fmt::init();

let _res = eframe::run_native(
let mint = MultiMint::new("multimint".into()).await?;
eframe::run_native(
"Damus NoteDeck",
generate_native_options(),
Box::new(|cc| Box::new(Damus::new(cc, ".", std::env::args().collect()))),
);
Box::new(|cc| Box::new(Damus::new(cc, ".", mint, std::env::args().collect()))),
).map_err(|e| Error::Generic(format!("{:?}", e)))
}

#[cfg(target_arch = "wasm32")]
Expand Down
17 changes: 17 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum Error {
Nostr(enostr::Error),
Ndb(nostrdb::Error),
Image(image::error::ImageError),
Anyhow(anyhow::Error),
//Eframe(eframe::Error),
Generic(String),
}

Expand All @@ -25,6 +27,7 @@ impl fmt::Display for Error {
Self::Image(e) => write!(f, "{e}"),
Self::Generic(e) => write!(f, "{e}"),
Self::Io(e) => write!(f, "{e}"),
Self::Anyhow(e) => write!(f, "{e}"),
}
}
}
Expand All @@ -47,12 +50,26 @@ impl From<image::error::ImageError> for Error {
}
}

impl From<anyhow::Error> for Error {
fn from(err: anyhow::Error) -> Self {
Error::Anyhow(err)
}
}

impl From<enostr::Error> for Error {
fn from(err: enostr::Error) -> Self {
Error::Nostr(err)
}
}

/*
impl From<eframe::Error> for Error {
fn from(err: eframe::Error) -> Self {
Error::Eframe(err)
}
}
*/

impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err)
Expand Down

0 comments on commit 6b647d2

Please sign in to comment.