diff --git a/crates/coop/src/chatspace.rs b/crates/coop/src/chatspace.rs index 45be89d..4310d47 100644 --- a/crates/coop/src/chatspace.rs +++ b/crates/coop/src/chatspace.rs @@ -2,7 +2,10 @@ use std::sync::Arc; use account::Account; use anyhow::Error; -use global::get_client; +use global::{ + constants::{DEFAULT_MODAL_WIDTH, DEFAULT_SIDEBAR_WIDTH, IMAGE_CACHE_LIMIT}, + get_client, +}; use gpui::{ div, image_cache, impl_internal_actions, prelude::FluentBuilder, px, App, AppContext, Axis, 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::new(window, cx) } @@ -162,7 +161,7 @@ impl ChatSpace { ); 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); }); @@ -234,7 +233,7 @@ impl ChatSpace { window.open_modal(cx, move |modal, _, _| { modal .title("Profile") - .width(px(MODAL_WIDTH)) + .width(px(DEFAULT_MODAL_WIDTH)) .child(profile.clone()) }) } @@ -244,7 +243,7 @@ impl ChatSpace { window.open_modal(cx, move |modal, _, _| { modal .title("Direct Messages") - .width(px(MODAL_WIDTH)) + .width(px(DEFAULT_MODAL_WIDTH)) .child(compose.clone()) }) } @@ -252,7 +251,7 @@ impl ChatSpace { let relays = relays::init(window, cx); window.open_modal(cx, move |this, _, _| { - this.width(px(MODAL_WIDTH)) + this.width(px(DEFAULT_MODAL_WIDTH)) .title("Edit your Messaging Relays") .child(relays.clone()) }); @@ -261,7 +260,7 @@ impl ChatSpace { let relays = relays::init(window, cx); window.open_modal(cx, move |this, _, _| { - this.width(px(MODAL_WIDTH)) + this.width(px(DEFAULT_MODAL_WIDTH)) .title("Your Messaging Relays are not configured") .child(relays.clone()) }); @@ -295,7 +294,7 @@ impl Render for ChatSpace { .relative() .size_full() .child( - image_cache(cache_provider("image-cache", IMAGE_CACHE_SIZE)) + image_cache(cache_provider("image-cache", IMAGE_CACHE_LIMIT)) .size_full() .child( div() diff --git a/crates/coop/src/main.rs b/crates/coop/src/main.rs index e42ffe8..3fcc05f 100644 --- a/crates/coop/src/main.rs +++ b/crates/coop/src/main.rs @@ -7,8 +7,8 @@ use futures::{select, FutureExt}; use global::constants::APP_NAME; use global::{ constants::{ - ALL_MESSAGES_SUB_ID, APP_ID, APP_PUBKEY, BOOTSTRAP_RELAYS, NEW_MESSAGE_SUB_ID, - SEARCH_RELAYS, + ALL_MESSAGES_SUB_ID, APP_ID, APP_PUBKEY, BOOTSTRAP_RELAYS, METADATA_BATCH_LIMIT, + METADATA_BATCH_TIMEOUT, NEW_MESSAGE_SUB_ID, SEARCH_RELAYS, }, get_client, }; @@ -111,20 +111,18 @@ fn main() { // Handle batch metadata app.background_executor() .spawn(async move { - const BATCH_SIZE: usize = 20; - const BATCH_TIMEOUT: Duration = Duration::from_millis(300); - let mut batch: HashSet = HashSet::new(); 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! { pubkeys = batch_rx.recv().fuse() => { match pubkeys { Ok(keys) => { batch.extend(keys); - if batch.len() >= BATCH_SIZE { + if batch.len() >= METADATA_BATCH_LIMIT { sync_metadata(mem::take(&mut batch), client, opts).await; } } diff --git a/crates/coop/src/views/sidebar/mod.rs b/crates/coop/src/views/sidebar/mod.rs index c6b32e7..0f16ec9 100644 --- a/crates/coop/src/views/sidebar/mod.rs +++ b/crates/coop/src/views/sidebar/mod.rs @@ -521,6 +521,7 @@ impl Render for Sidebar { .child( div() .px_1() + .w_full() .flex() .flex_col() .gap_1() @@ -528,6 +529,7 @@ impl Render for Sidebar { div() .mb_1() .px_2() + .w_full() .flex() .justify_between() .items_center() @@ -559,7 +561,7 @@ impl Render for Sidebar { ), ) .when(chats.wait_for_eose, |this| { - this.px_2().children(self.render_skeleton(6)) + this.children(self.render_skeleton(6)) }) .map(|this| { if let Some(rooms) = local_result { diff --git a/crates/global/src/constants.rs b/crates/global/src/constants.rs index 955570a..2f0461e 100644 --- a/crates/global/src/constants.rs +++ b/crates/global/src/constants.rs @@ -2,23 +2,37 @@ pub const APP_NAME: &str = "Coop"; pub const APP_ID: &str = "su.reya.coop"; pub const APP_PUBKEY: &str = "b1813fb01274b32cc5db6d1198e7c79dda0fb430899f63c7064f651a41d44f2b"; -/// Bootstrap relays +/// Bootstrap Relays. pub const BOOTSTRAP_RELAYS: [&str; 4] = [ "wss://relay.damus.io", "wss://relay.primal.net", "wss://user.kindpag.es", "wss://relaydiscovery.com", ]; - -/// Search relays +/// Search Relays. 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"; +/// Unique ID for all messages subscription. 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"; -/// NIP96 Media Server +/// NIP96 Media Server. pub const NIP96_SERVER: &str = "https://nostrmedia.com";