add nip4e settings
This commit is contained in:
31
Cargo.lock
generated
31
Cargo.lock
generated
@@ -327,7 +327,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "assets"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"gpui",
|
||||
@@ -661,7 +661,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "auto_update"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -1140,7 +1140,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chat"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -1163,7 +1163,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "chat_ui"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chat",
|
||||
@@ -1388,7 +1388,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "common"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bech32",
|
||||
@@ -1485,7 +1485,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "coop"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assets",
|
||||
@@ -1526,7 +1526,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "coop_web"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assets",
|
||||
@@ -1851,7 +1851,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "device"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -1863,6 +1863,7 @@ dependencies = [
|
||||
"person",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"settings",
|
||||
"smallvec",
|
||||
"smol",
|
||||
"state",
|
||||
@@ -5146,7 +5147,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "person"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -5940,7 +5941,7 @@ checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
|
||||
|
||||
[[package]]
|
||||
name = "relay_auth"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -6596,7 +6597,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "settings"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -6853,7 +6854,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "state"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -7203,7 +7204,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "theme"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"gpui",
|
||||
@@ -7340,7 +7341,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "title_bar"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
@@ -7733,7 +7734,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ui"
|
||||
version = "1.0.0-beta4"
|
||||
version = "1.0.0-beta5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"common",
|
||||
|
||||
@@ -10,6 +10,7 @@ state = { path = "../state" }
|
||||
person = { path = "../person" }
|
||||
ui = { path = "../ui" }
|
||||
theme = { path = "../theme" }
|
||||
settings = { path = "../settings" }
|
||||
|
||||
gpui.workspace = true
|
||||
nostr-sdk.workspace = true
|
||||
|
||||
@@ -11,6 +11,8 @@ use gpui::{
|
||||
};
|
||||
use nostr_sdk::prelude::*;
|
||||
use person::PersonRegistry;
|
||||
use settings::AppSettings;
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use state::{Announcement, CLIENT_NAME, NostrRegistry, StateEvent, TIMEOUT};
|
||||
use theme::ActiveTheme;
|
||||
use ui::avatar::Avatar;
|
||||
@@ -19,8 +21,6 @@ use ui::notification::{Notification, NotificationKind};
|
||||
use ui::{Disableable, Sizable, StyledExt, WindowExtension, h_flex, v_flex};
|
||||
|
||||
const IDENTIFIER: &str = "coop:device";
|
||||
const MSG: &str = "You've requested an encryption key from another device. \
|
||||
Approve to allow Coop to share with it.";
|
||||
|
||||
pub fn init(window: &mut Window, cx: &mut App) {
|
||||
DeviceRegistry::set_global(cx.new(|cx| DeviceRegistry::new(window, cx)), cx);
|
||||
@@ -67,7 +67,7 @@ pub struct DeviceRegistry {
|
||||
tasks: Vec<Task<Result<(), Error>>>,
|
||||
|
||||
/// Event subscription
|
||||
_subscription: Option<Subscription>,
|
||||
_subscriptions: SmallVec<[Subscription; 2]>,
|
||||
}
|
||||
|
||||
impl EventEmitter<DeviceEvent> for DeviceRegistry {}
|
||||
@@ -86,14 +86,28 @@ impl DeviceRegistry {
|
||||
/// Create a new device registry instance
|
||||
fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let settings = AppSettings::global(cx);
|
||||
let is_nip4e_enabled = settings.read(cx).is_nip4e_enabled();
|
||||
|
||||
// Subscribe to nostr state events
|
||||
let subscription = cx.subscribe_in(&nostr, window, |this, _e, event, _window, cx| {
|
||||
if event == &StateEvent::SignerSet {
|
||||
this.set_initializing(true, cx);
|
||||
this.get_announcement(cx);
|
||||
};
|
||||
});
|
||||
let mut subscriptions = smallvec![];
|
||||
|
||||
subscriptions.push(
|
||||
// Subscribe to nostr state events
|
||||
cx.observe(&settings, move |this, settings, cx| {
|
||||
if settings.read(cx).is_nip4e_enabled() {
|
||||
this.get_announcement(cx);
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
subscriptions.push(
|
||||
// Subscribe to nostr state events
|
||||
cx.subscribe(&nostr, move |this, _e, event, cx| {
|
||||
if event == &StateEvent::SignerSet && is_nip4e_enabled {
|
||||
this.get_announcement(cx);
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
cx.defer_in(window, |this, window, cx| {
|
||||
this.handle_notifications(window, cx);
|
||||
@@ -103,7 +117,7 @@ impl DeviceRegistry {
|
||||
initializing: true,
|
||||
pending_request: false,
|
||||
tasks: vec![],
|
||||
_subscription: Some(subscription),
|
||||
_subscriptions: subscriptions,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +233,9 @@ impl DeviceRegistry {
|
||||
let nostr = NostrRegistry::global(cx);
|
||||
let client = nostr.read(cx).client();
|
||||
|
||||
// Show the loading state
|
||||
self.set_initializing(true, cx);
|
||||
|
||||
let task: Task<Result<Event, Error>> = cx.background_spawn(async move {
|
||||
let signer = client.signer().context("Signer not found")?;
|
||||
let public_key = signer.get_public_key().await?;
|
||||
@@ -586,6 +603,9 @@ impl DeviceRegistry {
|
||||
|
||||
/// Build a notification for the encryption request.
|
||||
fn notification(&self, event: Event, cx: &Context<Self>) -> Notification {
|
||||
const MSG: &str = "You've requested an encryption key from another device. \
|
||||
Approve to allow Coop to share with it.";
|
||||
|
||||
let request = Announcement::from(&event);
|
||||
let persons = PersonRegistry::global(cx);
|
||||
let profile = persons.read(cx).get(&request.public_key(), cx);
|
||||
|
||||
@@ -40,6 +40,7 @@ setting_accessors! {
|
||||
pub theme_mode: ThemeMode,
|
||||
pub hide_avatar: bool,
|
||||
pub screening: bool,
|
||||
pub encryption_key: bool,
|
||||
pub auth_mode: AuthMode,
|
||||
pub trusted_relays: HashSet<RelayUrl>,
|
||||
pub room_configs: HashMap<u64, RoomConfig>,
|
||||
@@ -137,6 +138,11 @@ pub struct Settings {
|
||||
/// Enable screening for unknown chat requests
|
||||
pub screening: bool,
|
||||
|
||||
/// Enable decoupling encryption key
|
||||
///
|
||||
/// NIP-4e
|
||||
pub encryption_key: bool,
|
||||
|
||||
/// Authentication mode
|
||||
pub auth_mode: AuthMode,
|
||||
|
||||
@@ -157,6 +163,7 @@ impl Default for Settings {
|
||||
theme_mode: ThemeMode::default(),
|
||||
hide_avatar: false,
|
||||
screening: true,
|
||||
encryption_key: false,
|
||||
auth_mode: AuthMode::default(),
|
||||
trusted_relays: HashSet::default(),
|
||||
room_configs: HashMap::default(),
|
||||
@@ -301,6 +308,11 @@ impl AppSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if decoupling encryption key is enabled
|
||||
pub fn is_nip4e_enabled(&self) -> bool {
|
||||
self.values.encryption_key
|
||||
}
|
||||
|
||||
/// Check if the given relay is already authenticated
|
||||
pub fn trusted_relay(&self, url: &RelayUrl, _cx: &App) -> bool {
|
||||
self.values.trusted_relays.iter().any(|relay| {
|
||||
|
||||
Reference in New Issue
Block a user