chore: adjust global consts

This commit is contained in:
2025-05-18 16:00:28 +07:00
parent 443dbc82a6
commit 71fbd97bad
4 changed files with 38 additions and 25 deletions

View File

@@ -2,7 +2,10 @@ use std::sync::Arc;
use account::Account; use account::Account;
use anyhow::Error; use anyhow::Error;
use global::get_client; use global::{
constants::{DEFAULT_MODAL_WIDTH, DEFAULT_SIDEBAR_WIDTH, IMAGE_CACHE_LIMIT},
get_client,
};
use gpui::{ use gpui::{
div, image_cache, impl_internal_actions, prelude::FluentBuilder, px, App, AppContext, Axis, div, image_cache, impl_internal_actions, prelude::FluentBuilder, px, App, AppContext, Axis,
Context, Entity, InteractiveElement, IntoElement, ParentElement, Render, Styled, Subscription, Context, Entity, InteractiveElement, IntoElement, ParentElement, Render, Styled, Subscription,
@@ -26,10 +29,6 @@ use crate::{
}, },
}; };
const IMAGE_CACHE_SIZE: usize = 200;
const MODAL_WIDTH: f32 = 420.;
const SIDEBAR_WIDTH: f32 = 280.;
pub fn init(window: &mut Window, cx: &mut App) -> Entity<ChatSpace> { pub fn init(window: &mut Window, cx: &mut App) -> Entity<ChatSpace> {
ChatSpace::new(window, cx) ChatSpace::new(window, cx)
} }
@@ -162,7 +161,7 @@ impl ChatSpace {
); );
self.dock.update(cx, |this, cx| { self.dock.update(cx, |this, cx| {
this.set_left_dock(left, Some(px(SIDEBAR_WIDTH)), true, window, cx); this.set_left_dock(left, Some(px(DEFAULT_SIDEBAR_WIDTH)), true, window, cx);
this.set_center(center, window, cx); this.set_center(center, window, cx);
}); });
@@ -234,7 +233,7 @@ impl ChatSpace {
window.open_modal(cx, move |modal, _, _| { window.open_modal(cx, move |modal, _, _| {
modal modal
.title("Profile") .title("Profile")
.width(px(MODAL_WIDTH)) .width(px(DEFAULT_MODAL_WIDTH))
.child(profile.clone()) .child(profile.clone())
}) })
} }
@@ -244,7 +243,7 @@ impl ChatSpace {
window.open_modal(cx, move |modal, _, _| { window.open_modal(cx, move |modal, _, _| {
modal modal
.title("Direct Messages") .title("Direct Messages")
.width(px(MODAL_WIDTH)) .width(px(DEFAULT_MODAL_WIDTH))
.child(compose.clone()) .child(compose.clone())
}) })
} }
@@ -252,7 +251,7 @@ impl ChatSpace {
let relays = relays::init(window, cx); let relays = relays::init(window, cx);
window.open_modal(cx, move |this, _, _| { window.open_modal(cx, move |this, _, _| {
this.width(px(MODAL_WIDTH)) this.width(px(DEFAULT_MODAL_WIDTH))
.title("Edit your Messaging Relays") .title("Edit your Messaging Relays")
.child(relays.clone()) .child(relays.clone())
}); });
@@ -261,7 +260,7 @@ impl ChatSpace {
let relays = relays::init(window, cx); let relays = relays::init(window, cx);
window.open_modal(cx, move |this, _, _| { window.open_modal(cx, move |this, _, _| {
this.width(px(MODAL_WIDTH)) this.width(px(DEFAULT_MODAL_WIDTH))
.title("Your Messaging Relays are not configured") .title("Your Messaging Relays are not configured")
.child(relays.clone()) .child(relays.clone())
}); });
@@ -295,7 +294,7 @@ impl Render for ChatSpace {
.relative() .relative()
.size_full() .size_full()
.child( .child(
image_cache(cache_provider("image-cache", IMAGE_CACHE_SIZE)) image_cache(cache_provider("image-cache", IMAGE_CACHE_LIMIT))
.size_full() .size_full()
.child( .child(
div() div()

View File

@@ -7,8 +7,8 @@ use futures::{select, FutureExt};
use global::constants::APP_NAME; use global::constants::APP_NAME;
use global::{ use global::{
constants::{ constants::{
ALL_MESSAGES_SUB_ID, APP_ID, APP_PUBKEY, BOOTSTRAP_RELAYS, NEW_MESSAGE_SUB_ID, ALL_MESSAGES_SUB_ID, APP_ID, APP_PUBKEY, BOOTSTRAP_RELAYS, METADATA_BATCH_LIMIT,
SEARCH_RELAYS, METADATA_BATCH_TIMEOUT, NEW_MESSAGE_SUB_ID, SEARCH_RELAYS,
}, },
get_client, get_client,
}; };
@@ -111,20 +111,18 @@ fn main() {
// Handle batch metadata // Handle batch metadata
app.background_executor() app.background_executor()
.spawn(async move { .spawn(async move {
const BATCH_SIZE: usize = 20;
const BATCH_TIMEOUT: Duration = Duration::from_millis(300);
let mut batch: HashSet<PublicKey> = HashSet::new(); let mut batch: HashSet<PublicKey> = HashSet::new();
loop { loop {
let mut timeout = Box::pin(Timer::after(BATCH_TIMEOUT).fuse()); let mut timeout =
Box::pin(Timer::after(Duration::from_millis(METADATA_BATCH_TIMEOUT)).fuse());
select! { select! {
pubkeys = batch_rx.recv().fuse() => { pubkeys = batch_rx.recv().fuse() => {
match pubkeys { match pubkeys {
Ok(keys) => { Ok(keys) => {
batch.extend(keys); batch.extend(keys);
if batch.len() >= BATCH_SIZE { if batch.len() >= METADATA_BATCH_LIMIT {
sync_metadata(mem::take(&mut batch), client, opts).await; sync_metadata(mem::take(&mut batch), client, opts).await;
} }
} }

View File

@@ -521,6 +521,7 @@ impl Render for Sidebar {
.child( .child(
div() div()
.px_1() .px_1()
.w_full()
.flex() .flex()
.flex_col() .flex_col()
.gap_1() .gap_1()
@@ -528,6 +529,7 @@ impl Render for Sidebar {
div() div()
.mb_1() .mb_1()
.px_2() .px_2()
.w_full()
.flex() .flex()
.justify_between() .justify_between()
.items_center() .items_center()
@@ -559,7 +561,7 @@ impl Render for Sidebar {
), ),
) )
.when(chats.wait_for_eose, |this| { .when(chats.wait_for_eose, |this| {
this.px_2().children(self.render_skeleton(6)) this.children(self.render_skeleton(6))
}) })
.map(|this| { .map(|this| {
if let Some(rooms) = local_result { if let Some(rooms) = local_result {

View File

@@ -2,23 +2,37 @@ pub const APP_NAME: &str = "Coop";
pub const APP_ID: &str = "su.reya.coop"; pub const APP_ID: &str = "su.reya.coop";
pub const APP_PUBKEY: &str = "b1813fb01274b32cc5db6d1198e7c79dda0fb430899f63c7064f651a41d44f2b"; pub const APP_PUBKEY: &str = "b1813fb01274b32cc5db6d1198e7c79dda0fb430899f63c7064f651a41d44f2b";
/// Bootstrap relays /// Bootstrap Relays.
pub const BOOTSTRAP_RELAYS: [&str; 4] = [ pub const BOOTSTRAP_RELAYS: [&str; 4] = [
"wss://relay.damus.io", "wss://relay.damus.io",
"wss://relay.primal.net", "wss://relay.primal.net",
"wss://user.kindpag.es", "wss://user.kindpag.es",
"wss://relaydiscovery.com", "wss://relaydiscovery.com",
]; ];
/// Search Relays.
/// Search relays
pub const SEARCH_RELAYS: [&str; 1] = ["wss://relay.nostr.band"]; pub const SEARCH_RELAYS: [&str; 1] = ["wss://relay.nostr.band"];
/// Subscriptions /// Unique ID for new message subscription.
pub const NEW_MESSAGE_SUB_ID: &str = "listen_new_giftwraps"; pub const NEW_MESSAGE_SUB_ID: &str = "listen_new_giftwraps";
/// Unique ID for all messages subscription.
pub const ALL_MESSAGES_SUB_ID: &str = "listen_all_giftwraps"; pub const ALL_MESSAGES_SUB_ID: &str = "listen_all_giftwraps";
/// Image Resizer Service /// Total metadata requests will be grouped.
pub const METADATA_BATCH_LIMIT: usize = 200;
/// Maximum timeout for grouping metadata requests.
pub const METADATA_BATCH_TIMEOUT: u64 = 300;
/// Default width for all modals.
pub const DEFAULT_MODAL_WIDTH: f32 = 420.;
/// Default width of the sidebar.
pub const DEFAULT_SIDEBAR_WIDTH: f32 = 280.;
/// Total remote images will be cached
pub const IMAGE_CACHE_LIMIT: usize = 50;
/// Image Resizer Service.
/// Use for resize all remote images (ex: avatar, banner,...) on-the-fly.
pub const IMAGE_SERVICE: &str = "https://wsrv.nl"; pub const IMAGE_SERVICE: &str = "https://wsrv.nl";
/// NIP96 Media Server /// NIP96 Media Server.
pub const NIP96_SERVER: &str = "https://nostrmedia.com"; pub const NIP96_SERVER: &str = "https://nostrmedia.com";