From cc4174a695f0e0ba2f46792dabd181a3d77aec6b Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Sat, 4 Apr 2026 09:15:31 +0700 Subject: [PATCH] . --- crates/chat/src/lib.rs | 2 +- crates/chat/src/message.rs | 2 +- crates/chat/src/room.rs | 2 +- crates/chat_ui/src/lib.rs | 2 +- crates/common/src/display.rs | 23 +++++------------------ crates/common/src/event.rs | 6 +++--- crates/coop/src/dialogs/connect.rs | 2 +- crates/coop/src/dialogs/screening.rs | 14 +++++++------- crates/coop/src/sidebar/mod.rs | 2 +- crates/device/src/lib.rs | 4 ++-- crates/person/src/lib.rs | 2 +- crates/relay_auth/src/lib.rs | 4 ++-- 12 files changed, 26 insertions(+), 39 deletions(-) diff --git a/crates/chat/src/lib.rs b/crates/chat/src/lib.rs index c036d39..75825e6 100644 --- a/crates/chat/src/lib.rs +++ b/crates/chat/src/lib.rs @@ -6,7 +6,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::time::Duration; use anyhow::{Context as AnyhowContext, Error, anyhow}; -use common::EventUtils; +use common::EventExt; use device::{DeviceEvent, DeviceRegistry}; use fuzzy_matcher::FuzzyMatcher; use fuzzy_matcher::skim::SkimMatcherV2; diff --git a/crates/chat/src/message.rs b/crates/chat/src/message.rs index cf4b293..de91023 100644 --- a/crates/chat/src/message.rs +++ b/crates/chat/src/message.rs @@ -1,7 +1,7 @@ use std::hash::Hash; use std::ops::Range; -use common::{EventUtils, NostrParser}; +use common::{EventExt, NostrParser}; use gpui::SharedString; use nostr_sdk::prelude::*; diff --git a/crates/chat/src/room.rs b/crates/chat/src/room.rs index ea69c2d..ee1d79f 100644 --- a/crates/chat/src/room.rs +++ b/crates/chat/src/room.rs @@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher}; use std::time::Duration; use anyhow::{Error, anyhow}; -use common::EventUtils; +use common::EventExt; use gpui::{App, AppContext, Context, EventEmitter, SharedString, Task}; use itertools::Itertools; use nostr_sdk::prelude::*; diff --git a/crates/chat_ui/src/lib.rs b/crates/chat_ui/src/lib.rs index e81de04..b66fa39 100644 --- a/crates/chat_ui/src/lib.rs +++ b/crates/chat_ui/src/lib.rs @@ -4,7 +4,7 @@ use std::sync::Arc; pub use actions::*; use anyhow::{Context as AnyhowContext, Error}; use chat::{ChatRegistry, Message, RenderedMessage, Room, RoomEvent, SendReport, SendStatus}; -use common::RenderedTimestamp; +use common::TimestampExt; use gpui::prelude::FluentBuilder; use gpui::{ AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle, diff --git a/crates/common/src/display.rs b/crates/common/src/display.rs index 79ed85f..a288168 100644 --- a/crates/common/src/display.rs +++ b/crates/common/src/display.rs @@ -1,11 +1,10 @@ use std::sync::Arc; -use anyhow::{Error, anyhow}; use chrono::{Local, TimeZone}; use gpui::{Image, ImageFormat, SharedString}; use nostr_sdk::prelude::*; -use qrcode::render::svg; use qrcode::QrCode; +use qrcode::render::svg; const NOW: &str = "now"; const SECONDS_IN_MINUTE: i64 = 60; @@ -13,12 +12,12 @@ const MINUTES_IN_HOUR: i64 = 60; const HOURS_IN_DAY: i64 = 24; const DAYS_IN_MONTH: i64 = 30; -pub trait RenderedTimestamp { +pub trait TimestampExt { fn to_human_time(&self) -> SharedString; fn to_ago(&self) -> SharedString; } -impl RenderedTimestamp for Timestamp { +impl TimestampExt for Timestamp { fn to_human_time(&self) -> SharedString { let input_time = match Local.timestamp_opt(self.as_secs() as i64, 0) { chrono::LocalResult::Single(time) => time, @@ -61,23 +60,11 @@ impl RenderedTimestamp for Timestamp { } } -pub trait TextUtils { - fn to_public_key(&self) -> Result; +pub trait StringExt { fn to_qr(&self) -> Option>; } -impl> TextUtils for T { - fn to_public_key(&self) -> Result { - let s = self.as_ref(); - if s.starts_with("nprofile1") { - Ok(Nip19Profile::from_bech32(s)?.public_key) - } else if s.starts_with("npub1") { - Ok(PublicKey::parse(s)?) - } else { - Err(anyhow!("Invalid public key")) - } - } - +impl> StringExt for T { fn to_qr(&self) -> Option> { let s = self.as_ref(); let code = QrCode::new(s).unwrap(); diff --git a/crates/common/src/event.rs b/crates/common/src/event.rs index 03833c7..194cddf 100644 --- a/crates/common/src/event.rs +++ b/crates/common/src/event.rs @@ -3,12 +3,12 @@ use std::hash::{DefaultHasher, Hash, Hasher}; use itertools::Itertools; use nostr_sdk::prelude::*; -pub trait EventUtils { +pub trait EventExt { fn uniq_id(&self) -> u64; fn extract_public_keys(&self) -> Vec; } -impl EventUtils for Event { +impl EventExt for Event { fn uniq_id(&self) -> u64 { let mut hasher = DefaultHasher::new(); let mut pubkeys: Vec = self.extract_public_keys(); @@ -25,7 +25,7 @@ impl EventUtils for Event { } } -impl EventUtils for UnsignedEvent { +impl EventExt for UnsignedEvent { fn uniq_id(&self) -> u64 { let mut hasher = DefaultHasher::new(); let mut pubkeys: Vec = vec![]; diff --git a/crates/coop/src/dialogs/connect.rs b/crates/coop/src/dialogs/connect.rs index 8176587..537cdc1 100644 --- a/crates/coop/src/dialogs/connect.rs +++ b/crates/coop/src/dialogs/connect.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use std::time::Duration; -use common::TextUtils; +use common::StringExt; use gpui::prelude::FluentBuilder; use gpui::{ AppContext, Context, Entity, Image, IntoElement, ParentElement, Render, SharedString, Styled, diff --git a/crates/coop/src/dialogs/screening.rs b/crates/coop/src/dialogs/screening.rs index 07e5af0..3a13e7a 100644 --- a/crates/coop/src/dialogs/screening.rs +++ b/crates/coop/src/dialogs/screening.rs @@ -2,21 +2,21 @@ use std::collections::HashMap; use std::time::Duration; use anyhow::{Context as AnyhowContext, Error}; -use common::RenderedTimestamp; +use common::TimestampExt; use gpui::prelude::FluentBuilder; use gpui::{ - div, px, relative, uniform_list, App, AppContext, Context, Div, Entity, InteractiveElement, - IntoElement, ParentElement, Render, SharedString, Styled, Subscription, Task, Window, + App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, ParentElement, Render, + SharedString, Styled, Subscription, Task, Window, div, px, relative, uniform_list, }; use nostr_sdk::prelude::*; -use person::{shorten_pubkey, Person, PersonRegistry}; -use smallvec::{smallvec, SmallVec}; -use state::{NostrAddress, NostrRegistry, BOOTSTRAP_RELAYS, TIMEOUT}; +use person::{Person, PersonRegistry, shorten_pubkey}; +use smallvec::{SmallVec, smallvec}; +use state::{BOOTSTRAP_RELAYS, NostrAddress, NostrRegistry, TIMEOUT}; use theme::ActiveTheme; use ui::avatar::Avatar; use ui::button::{Button, ButtonVariants}; use ui::indicator::Indicator; -use ui::{h_flex, v_flex, Icon, IconName, Sizable, StyledExt, WindowExtension}; +use ui::{Icon, IconName, Sizable, StyledExt, WindowExtension, h_flex, v_flex}; pub fn init(public_key: PublicKey, window: &mut Window, cx: &mut App) -> Entity { cx.new(|cx| Screening::new(public_key, window, cx)) diff --git a/crates/coop/src/sidebar/mod.rs b/crates/coop/src/sidebar/mod.rs index 902c28b..3cb3f9f 100644 --- a/crates/coop/src/sidebar/mod.rs +++ b/crates/coop/src/sidebar/mod.rs @@ -4,7 +4,7 @@ use std::time::Duration; use anyhow::{Context as AnyhowContext, Error}; use chat::{ChatEvent, ChatRegistry, Room, RoomKind}; -use common::{DebouncedDelay, RenderedTimestamp}; +use common::{DebouncedDelay, TimestampExt}; use entry::RoomEntry; use gpui::prelude::FluentBuilder; use gpui::{ diff --git a/crates/device/src/lib.rs b/crates/device/src/lib.rs index d3efb1b..add0642 100644 --- a/crates/device/src/lib.rs +++ b/crates/device/src/lib.rs @@ -14,9 +14,9 @@ use person::PersonRegistry; use state::{Announcement, NostrRegistry, StateEvent, TIMEOUT, app_name}; use theme::ActiveTheme; use ui::avatar::Avatar; -use ui::button::{Button, ButtonVariants}; +use ui::button::Button; use ui::notification::{Notification, NotificationKind}; -use ui::{Disableable, IconName, Sizable, StyledExt, WindowExtension, h_flex, v_flex}; +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. \ diff --git a/crates/person/src/lib.rs b/crates/person/src/lib.rs index 7f969c4..3f72f99 100644 --- a/crates/person/src/lib.rs +++ b/crates/person/src/lib.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use std::time::Duration; use anyhow::{Error, anyhow}; -use common::EventUtils; +use common::EventExt; use gpui::{App, AppContext, Context, Entity, Global, Task, Window}; use nostr_sdk::prelude::*; use smallvec::{SmallVec, smallvec}; diff --git a/crates/relay_auth/src/lib.rs b/crates/relay_auth/src/lib.rs index c75977d..4bac09a 100644 --- a/crates/relay_auth/src/lib.rs +++ b/crates/relay_auth/src/lib.rs @@ -15,9 +15,9 @@ use settings::{AppSettings, AuthMode}; use smallvec::{SmallVec, smallvec}; use state::NostrRegistry; use theme::ActiveTheme; -use ui::button::{Button, ButtonVariants}; +use ui::button::Button; use ui::notification::{Notification, NotificationKind}; -use ui::{Disableable, IconName, Sizable, WindowExtension, v_flex}; +use ui::{Disableable, WindowExtension, v_flex}; const AUTH_MESSAGE: &str = "Approve the authentication request to allow Coop to continue sending or receiving events.";