local thread subscriptions
This adds local nostrdb thread subscriptions. When navigating to a thread, we first check to see if we have any active nostrdb subscriptions for that thread. If not, we create a new subscription. If we do, we re-use that subscription. This works by storing thread state in the Threads struct in the Damus application state. When we pop a route, we check to see if its a thread route. If it is, then we try to unsubscribe, but only if that is the last remaining subscriber for that thread, as there could be more than one. Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
32
src/note.rs
32
src/note.rs
@@ -1,4 +1,5 @@
|
||||
use nostrdb::{NoteKey, QueryResult};
|
||||
use crate::Damus;
|
||||
use nostrdb::{NoteKey, QueryResult, Transaction};
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||
@@ -35,3 +36,32 @@ impl PartialOrd for NoteRef {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn root_note_id_from_selected_id<'a>(
|
||||
app: &mut Damus,
|
||||
txn: &'a Transaction,
|
||||
selected_note_id: &'a [u8; 32],
|
||||
) -> &'a [u8; 32] {
|
||||
let selected_note_key = if let Ok(key) = app
|
||||
.ndb
|
||||
.get_notekey_by_id(txn, selected_note_id)
|
||||
.map(NoteKey::new)
|
||||
{
|
||||
key
|
||||
} else {
|
||||
return selected_note_id;
|
||||
};
|
||||
|
||||
let note = if let Ok(note) = app.ndb.get_note_by_key(txn, selected_note_key) {
|
||||
note
|
||||
} else {
|
||||
return selected_note_id;
|
||||
};
|
||||
|
||||
app.note_cache_mut()
|
||||
.cached_note_or_insert(selected_note_key, ¬e)
|
||||
.reply
|
||||
.borrow(note.tags())
|
||||
.root()
|
||||
.map_or_else(|| selected_note_id, |nr| nr.id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user