chore: fix some gossip and nip4e bugs #23
@@ -16,7 +16,7 @@ use theme::ActiveTheme;
|
|||||||
use ui::avatar::Avatar;
|
use ui::avatar::Avatar;
|
||||||
use ui::button::{Button, ButtonVariants};
|
use ui::button::{Button, ButtonVariants};
|
||||||
use ui::notification::Notification;
|
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 IDENTIFIER: &str = "coop:device";
|
||||||
const MSG: &str = "You've requested an encryption key from another 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
|
/// Whether the registry is waiting for encryption key approval from other devices
|
||||||
pub requesting: bool,
|
pub requesting: bool,
|
||||||
|
|
||||||
|
/// Whether there is a pending request for encryption key approval
|
||||||
|
pub has_pending_request: bool,
|
||||||
|
|
||||||
/// Async tasks
|
/// Async tasks
|
||||||
tasks: Vec<Task<Result<(), Error>>>,
|
tasks: Vec<Task<Result<(), Error>>>,
|
||||||
|
|
||||||
@@ -130,6 +133,7 @@ impl DeviceRegistry {
|
|||||||
Self {
|
Self {
|
||||||
subscribing: false,
|
subscribing: false,
|
||||||
requesting: false,
|
requesting: false,
|
||||||
|
has_pending_request: false,
|
||||||
tasks: vec![],
|
tasks: vec![],
|
||||||
_subscription: Some(subscription),
|
_subscription: Some(subscription),
|
||||||
}
|
}
|
||||||
@@ -208,6 +212,12 @@ impl DeviceRegistry {
|
|||||||
cx.notify();
|
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
|
/// Set the decoupled encryption key for the current user
|
||||||
fn set_signer<S>(&mut self, new: S, cx: &mut Context<Self>)
|
fn set_signer<S>(&mut self, new: S, cx: &mut Context<Self>)
|
||||||
where
|
where
|
||||||
@@ -674,15 +684,15 @@ impl DeviceRegistry {
|
|||||||
|
|
||||||
/// Handle encryption request
|
/// Handle encryption request
|
||||||
fn ask_for_approval(&mut self, event: Event, window: &mut Window, cx: &mut Context<Self>) {
|
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| {
|
// Show notification
|
||||||
cx.update(|window, cx| {
|
let notification = self.notification(event, cx);
|
||||||
window.push_notification(notification, cx);
|
window.push_notification(notification, cx);
|
||||||
})
|
|
||||||
.ok();
|
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a notification for the encryption request.
|
/// Build a notification for the encryption request.
|
||||||
@@ -719,13 +729,14 @@ impl DeviceRegistry {
|
|||||||
.text_sm()
|
.text_sm()
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
|
.font_semibold()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child(SharedString::from("Requester:")),
|
.child(SharedString::from("Requester:")),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.h_7()
|
.h_8()
|
||||||
.w_full()
|
.w_full()
|
||||||
.px_2()
|
.px_2()
|
||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
@@ -744,13 +755,14 @@ impl DeviceRegistry {
|
|||||||
.text_sm()
|
.text_sm()
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
|
.font_semibold()
|
||||||
.text_xs()
|
.text_xs()
|
||||||
.text_color(cx.theme().text_muted)
|
.text_color(cx.theme().text_muted)
|
||||||
.child(SharedString::from("Client:")),
|
.child(SharedString::from("Client:")),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
div()
|
div()
|
||||||
.h_7()
|
.h_8()
|
||||||
.w_full()
|
.w_full()
|
||||||
.px_2()
|
.px_2()
|
||||||
.rounded(cx.theme().radius)
|
.rounded(cx.theme().radius)
|
||||||
|
|||||||
Reference in New Issue
Block a user