chore: fix some gossip and nip4e bugs #23

Merged
reya merged 6 commits from fix-gossip into master 2026-03-18 08:21:40 +00:00
Showing only changes of commit 3276c88f63 - Show all commits

View File

@@ -16,7 +16,7 @@ use theme::ActiveTheme;
use ui::avatar::Avatar;
use ui::button::{Button, ButtonVariants};
use ui::notification::Notification;
use ui::{Disableable, IconName, Sizable, WindowExtension, h_flex, v_flex};
use ui::{Disableable, IconName, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
const IDENTIFIER: &str = "coop:device";
const MSG: &str = "You've requested an encryption key from another device. \
@@ -85,6 +85,9 @@ pub struct DeviceRegistry {
/// Whether the registry is waiting for encryption key approval from other devices
pub requesting: bool,
/// Whether there is a pending request for encryption key approval
pub has_pending_request: bool,
/// Async tasks
tasks: Vec<Task<Result<(), Error>>>,
@@ -130,6 +133,7 @@ impl DeviceRegistry {
Self {
subscribing: false,
requesting: false,
has_pending_request: false,
tasks: vec![],
_subscription: Some(subscription),
}
@@ -208,6 +212,12 @@ impl DeviceRegistry {
cx.notify();
}
/// Set whether there is a pending request for encryption key approval
fn set_has_pending_request(&mut self, pending: bool, cx: &mut Context<Self>) {
self.has_pending_request = pending;
cx.notify();
}
/// Set the decoupled encryption key for the current user
fn set_signer<S>(&mut self, new: S, cx: &mut Context<Self>)
where
@@ -674,15 +684,15 @@ impl DeviceRegistry {
/// Handle encryption request
fn ask_for_approval(&mut self, event: Event, window: &mut Window, cx: &mut Context<Self>) {
let notification = self.notification(event, cx);
// Ignore if there is already a pending request
if self.has_pending_request {
return;
}
self.set_has_pending_request(true, cx);
cx.spawn_in(window, async move |_this, cx| {
cx.update(|window, cx| {
// Show notification
let notification = self.notification(event, cx);
window.push_notification(notification, cx);
})
.ok();
})
.detach();
}
/// Build a notification for the encryption request.
@@ -719,13 +729,14 @@ impl DeviceRegistry {
.text_sm()
.child(
div()
.font_semibold()
.text_xs()
.text_color(cx.theme().text_muted)
.child(SharedString::from("Requester:")),
)
.child(
div()
.h_7()
.h_8()
.w_full()
.px_2()
.rounded(cx.theme().radius)
@@ -744,13 +755,14 @@ impl DeviceRegistry {
.text_sm()
.child(
div()
.font_semibold()
.text_xs()
.text_color(cx.theme().text_muted)
.child(SharedString::from("Client:")),
)
.child(
div()
.h_7()
.h_8()
.w_full()
.px_2()
.rounded(cx.theme().radius)