chore: improve logout behavior (#118)

* resubscribe on logout

* .

* .
This commit is contained in:
reya
2025-08-10 10:43:28 +07:00
committed by GitHub
parent 5011becacb
commit ca622d1262
5 changed files with 95 additions and 88 deletions

View File

@@ -111,55 +111,9 @@ impl ChatSpace {
subscriptions.push(cx.observe_in(
&client_keys,
window,
|_this: &mut Self, state, window, cx| {
|this: &mut Self, state, window, cx| {
if !state.read(cx).has_keys() {
let title = SharedString::new(t!("startup.client_keys_warning"));
let desc = SharedString::new(t!("startup.client_keys_desc"));
window.open_modal(cx, move |this, _window, cx| {
this.overlay_closable(false)
.show_close(false)
.keyboard(false)
.confirm()
.button_props(
ModalButtonProps::default()
.cancel_text(t!("startup.create_new_keys"))
.ok_text(t!("common.allow")),
)
.child(
div()
.w_full()
.h_40()
.flex()
.flex_col()
.gap_1()
.items_center()
.justify_center()
.text_center()
.text_sm()
.child(
div()
.font_semibold()
.text_color(cx.theme().text_muted)
.child(title.clone()),
)
.child(desc.clone()),
)
.on_cancel(|_, _window, cx| {
ClientKeys::global(cx).update(cx, |this, cx| {
this.new_keys(cx);
});
// true: Close modal
true
})
.on_ok(|_, window, cx| {
ClientKeys::global(cx).update(cx, |this, cx| {
this.load(window, cx);
});
// true: Close modal
true
})
});
this.render_client_keys_modal(window, cx);
}
},
));
@@ -301,8 +255,13 @@ impl ChatSpace {
}
fn on_sign_out(&mut self, _ev: &Logout, window: &mut Window, cx: &mut Context<Self>) {
let registry = Registry::global(cx);
let identity = Identity::global(cx);
// TODO: save current session?
registry.update(cx, |this, cx| {
this.reset(cx);
});
identity.update(cx, |this, cx| {
this.unload(window, cx);
});
@@ -326,6 +285,56 @@ impl ChatSpace {
});
}
fn render_client_keys_modal(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let title = SharedString::new(t!("startup.client_keys_warning"));
let desc = SharedString::new(t!("startup.client_keys_desc"));
window.open_modal(cx, move |this, _window, cx| {
this.overlay_closable(false)
.show_close(false)
.keyboard(false)
.confirm()
.button_props(
ModalButtonProps::default()
.cancel_text(t!("startup.create_new_keys"))
.ok_text(t!("common.allow")),
)
.child(
div()
.w_full()
.h_40()
.flex()
.flex_col()
.gap_1()
.items_center()
.justify_center()
.text_center()
.text_sm()
.child(
div()
.font_semibold()
.text_color(cx.theme().text_muted)
.child(title.clone()),
)
.child(desc.clone()),
)
.on_cancel(|_, _window, cx| {
ClientKeys::global(cx).update(cx, |this, cx| {
this.new_keys(cx);
});
// true: Close modal
true
})
.on_ok(|_, window, cx| {
ClientKeys::global(cx).update(cx, |this, cx| {
this.load(window, cx);
});
// true: Close modal
true
})
});
}
fn render_titlebar_left_side(
&mut self,
_window: &mut Window,

View File

@@ -358,8 +358,6 @@ async fn handle_nostr_notifications(
let client = nostr_client();
let auto_close = SubscribeAutoCloseOptions::default().exit_policy(ReqExitPolicy::ExitOnEOSE);
let mut notifications = client.notifications();
let mut processed_relay_list = false;
let mut processed_inbox_relay = false;
while let Ok(notification) = notifications.recv().await {
let RelayPoolNotification::Message { message, .. } = notification else {
@@ -379,11 +377,6 @@ async fn handle_nostr_notifications(
Kind::RelayList => {
// Get metadata for event's pubkey that matches the current user's pubkey
if let Ok(true) = is_from_current_user(&event).await {
match processed_relay_list {
true => continue,
false => processed_relay_list = true,
}
let sub_id = SubscriptionId::new("metadata");
let filter = Filter::new()
.kinds(vec![Kind::Metadata, Kind::ContactList, Kind::InboxRelays])
@@ -398,11 +391,6 @@ async fn handle_nostr_notifications(
}
Kind::InboxRelays => {
if let Ok(true) = is_from_current_user(&event).await {
match processed_inbox_relay {
true => continue,
false => processed_inbox_relay = true,
}
// Get all inbox relays
let relays = event
.tags
@@ -423,8 +411,6 @@ async fn handle_nostr_notifications(
_ = client.connect_relay(relay).await;
}
log::info!("Connected to messaging relays");
let filter = Filter::new().kind(Kind::GiftWrap).pubkey(event.pubkey);
let sub_id = SubscriptionId::new("gift-wrap");
@@ -436,7 +422,7 @@ async fn handle_nostr_notifications(
.await
.is_ok()
{
log::info!("Subscribing to gift wrap events in: {relays:?}");
log::info!("Subscribing to messages in: {relays:?}");
}
}
}