Skip to content

Commit

Permalink
wip huge refactor
Browse files Browse the repository at this point in the history
Signed-off-by: William Casarin <[email protected]>
  • Loading branch information
jb55 committed Sep 10, 2024
1 parent 772bfba commit cc2e046
Show file tree
Hide file tree
Showing 19 changed files with 871 additions and 635 deletions.
6 changes: 6 additions & 0 deletions src/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ impl AccountManager {
self.currently_selected_account
}

pub fn selected_or_first_nsec(&self) -> Option<&FullKeypair> {

Check failure on line 91 in src/account_manager.rs

View workflow job for this annotation

GitHub Actions / Clippy

cannot find type `FullKeypair` in this scope

Check failure on line 91 in src/account_manager.rs

View workflow job for this annotation

GitHub Actions / Check

cannot find type `FullKeypair` in this scope

Check failure on line 91 in src/account_manager.rs

View workflow job for this annotation

GitHub Actions / Test Suite

cannot find type `FullKeypair` in this scope
self.get_selected_account()
.and_then(|kp| kp.to_full())
.or_else(|| self.accounts.find_map(|a| a.to_full()));
}

pub fn get_selected_account(&self) -> Option<&UserAccount> {
if let Some(account_index) = self.currently_selected_account {
if let Some(account) = self.get_account(account_index) {
Expand Down
53 changes: 31 additions & 22 deletions src/actionbar.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::{
note::NoteRef,
route::Route,
thread::{Thread, ThreadResult},
column::Column,
notecache::NoteCache,
thread::{Thread, Threads, ThreadResult},
timeline::Timeline,

Check warning on line 7 in src/actionbar.rs

View workflow job for this annotation

GitHub Actions / Check

unused imports: `Damus` and `timeline::Timeline`

Check warning on line 7 in src/actionbar.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused imports: `Damus` and `timeline::Timeline`
Damus,
};
use enostr::NoteId;
use nostrdb::Transaction;
use enostr::{NoteId, RelayPool};
use nostrdb::{Transaction, Ndb};
use tracing::{error, info};
use uuid::Uuid;

Expand All @@ -30,26 +33,28 @@ pub enum BarResult {
/// the thread view. We don't have a concept of model/view/controller etc
/// in egui, but this is the closest thing to that.
fn open_thread(
app: &mut Damus,
ndb: &Ndb,
txn: &Transaction,
timeline: usize,
column: &mut Column,
note_cache: &mut NoteCache,
pool: &mut RelayPool,
threads: &mut Threads,
selected_note: &[u8; 32],
) -> Option<BarResult> {
{
let timeline = &mut app.timelines[timeline];
timeline
column
.routes
.push(Route::Thread(NoteId::new(selected_note.to_owned())));
timeline.navigating = true;
column.navigating = true;
}

let root_id = crate::note::root_note_id_from_selected_id(app, txn, selected_note);
let thread_res = app.threads.thread_mut(&app.ndb, txn, root_id);
let root_id = crate::note::root_note_id_from_selected_id(ndb, note_cache, txn, selected_note);
let thread_res = threads.thread_mut(ndb, txn, root_id);

let (thread, result) = match thread_res {
ThreadResult::Stale(thread) => {
// The thread is stale, let's update it
let notes = Thread::new_notes(&thread.view.notes, root_id, txn, &app.ndb);
let notes = Thread::new_notes(&thread.view.notes, root_id, txn, ndb);
let bar_result = if notes.is_empty() {
None
} else {
Expand All @@ -76,22 +81,22 @@ fn open_thread(
// an active subscription for this thread.
if thread.subscription().is_none() {
let filters = Thread::filters(root_id);
*thread.subscription_mut() = app.ndb.subscribe(&filters).ok();
*thread.subscription_mut() = ndb.subscribe(&filters).ok();

if thread.remote_subscription().is_some() {
error!("Found active remote subscription when it was not expected");
} else {
let subid = Uuid::new_v4().to_string();
*thread.remote_subscription_mut() = Some(subid.clone());
app.pool.subscribe(subid, filters);
pool.subscribe(subid, filters);
}

match thread.subscription() {
Some(_sub) => {
thread.subscribers += 1;
info!(
"Locally/remotely subscribing to thread. {} total active subscriptions, {} on this thread",
app.ndb.subscription_count(),
ndb.subscription_count(),
thread.subscribers,
);
}
Expand All @@ -104,7 +109,7 @@ fn open_thread(
thread.subscribers += 1;
info!(
"Re-using existing thread subscription. {} total active subscriptions, {} on this thread",
app.ndb.subscription_count(),
ndb.subscription_count(),
thread.subscribers,
)
}
Expand All @@ -115,22 +120,26 @@ fn open_thread(
impl BarAction {
pub fn execute(
self,
app: &mut Damus,
timeline: usize,
ndb: &Ndb,
column: &mut Column,
threads: &mut Threads,
note_cache: &mut NoteCache,
pool: &mut RelayPool,
replying_to: &[u8; 32],
txn: &Transaction,
) -> Option<BarResult> {
match self {
BarAction::Reply => {
let timeline = &mut app.timelines[timeline];
timeline
.routes
column
.routes_mut()
.push(Route::Reply(NoteId::new(replying_to.to_owned())));
timeline.navigating = true;
column.navigating = true;
None
}

BarAction::OpenThread => open_thread(app, txn, timeline, replying_to),
BarAction::OpenThread => {
open_thread(ndb, txn, column, note_cache, pool, threads, replying_to)
}
}
}
}
Expand Down
Loading

0 comments on commit cc2e046

Please sign in to comment.