thread: remote subscriptions working
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -12,8 +12,8 @@ default-run = "notedeck"
|
|||||||
crate-type = ["lib", "cdylib"]
|
crate-type = ["lib", "cdylib"]
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
#nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "04e5917b44b0112ecfd0eb93e8a1e2c81fce1d75" }
|
nostrdb = { git = "https://github.com/damus-io/nostrdb-rs", rev = "385a1af481ff8c08949a885248544483a52acbeb" }
|
||||||
nostrdb = { path = "/Users/jb55/dev/github/damus-io/nostrdb-rs" }
|
#nostrdb = { path = "/Users/jb55/dev/github/damus-io/nostrdb-rs" }
|
||||||
#nostrdb = "0.3.4"
|
#nostrdb = "0.3.4"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -72,6 +72,12 @@ impl RelayPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn unsubscribe(&mut self, subid: String) {
|
||||||
|
for relay in &mut self.relays {
|
||||||
|
relay.relay.send(&ClientMessage::close(subid.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn subscribe(&mut self, subid: String, filter: Vec<Filter>) {
|
pub fn subscribe(&mut self, subid: String, filter: Vec<Filter>) {
|
||||||
for relay in &mut self.relays {
|
for relay in &mut self.relays {
|
||||||
relay.relay.subscribe(subid.clone(), filter.clone());
|
relay.relay.subscribe(subid.clone(), filter.clone());
|
||||||
|
|||||||
12
src/app.rs
12
src/app.rs
@@ -901,18 +901,21 @@ fn render_panel(ctx: &egui::Context, app: &mut Damus, timeline_ind: usize) {
|
|||||||
|
|
||||||
/// Local thread unsubscribe
|
/// Local thread unsubscribe
|
||||||
fn thread_unsubscribe(app: &mut Damus, id: &[u8; 32]) {
|
fn thread_unsubscribe(app: &mut Damus, id: &[u8; 32]) {
|
||||||
let unsubscribe = {
|
let (unsubscribe, remote_subid) = {
|
||||||
let txn = Transaction::new(&app.ndb).expect("txn");
|
let txn = Transaction::new(&app.ndb).expect("txn");
|
||||||
let root_id = crate::note::root_note_id_from_selected_id(app, &txn, id);
|
let root_id = crate::note::root_note_id_from_selected_id(app, &txn, id);
|
||||||
|
|
||||||
let thread = app.threads.thread_mut(&app.ndb, &txn, root_id).get_ptr();
|
let thread = app.threads.thread_mut(&app.ndb, &txn, root_id).get_ptr();
|
||||||
let unsub = thread.decrement_sub();
|
let unsub = thread.decrement_sub();
|
||||||
|
|
||||||
|
let mut remote_subid: Option<String> = None;
|
||||||
if let Ok(DecrementResult::LastSubscriber(_subid)) = unsub {
|
if let Ok(DecrementResult::LastSubscriber(_subid)) = unsub {
|
||||||
*thread.subscription_mut() = None;
|
*thread.subscription_mut() = None;
|
||||||
|
remote_subid = thread.remote_subscription().to_owned();
|
||||||
|
*thread.remote_subscription_mut() = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsub
|
(unsub, remote_subid)
|
||||||
};
|
};
|
||||||
|
|
||||||
match unsubscribe {
|
match unsubscribe {
|
||||||
@@ -926,6 +929,11 @@ fn thread_unsubscribe(app: &mut Damus, id: &[u8; 32]) {
|
|||||||
app.ndb.subscription_count()
|
app.ndb.subscription_count()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unsub from remote
|
||||||
|
if let Some(subid) = remote_subid {
|
||||||
|
app.pool.unsubscribe(subid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(DecrementResult::ActiveSubscribers) => {
|
Ok(DecrementResult::ActiveSubscribers) => {
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ impl Thread {
|
|||||||
self.sub.as_ref()
|
self.sub.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remote_subscription(&self) -> Option<&String> {
|
pub fn remote_subscription(&self) -> &Option<String> {
|
||||||
self.remote_sub.as_ref()
|
&self.remote_sub
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remote_subscription_mut(&mut self) -> &mut Option<String> {
|
pub fn remote_subscription_mut(&mut self) -> &mut Option<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user