forge
Explore
Log in

Don't you dare go Hollow

Simplify wire, server calls, net/share/voice and GUI state

Browse files at this commit

03e66865a1aa9f679196276efe6194c91699d9a9Ahmet Kaan GümüşParent: 189b6d8
  • refactor
    • simplify wire, server calls, net/share/voice and GUI state
    • fix ~60 bugs
Show full message
♻️ refactor: simplify wire, server calls, net/share/voice and GUI state; fix ~60 bugs

Wire (ALPN yumush/9): permission collapsed to is_member/is_moderator/is_admin/is_owner,
Suspension enum, admin_actions! macro, Field::Attachments, char-count message limit,
Close::on, datagram Gate→Pace, Tolerant CC sliding window.

Server: handlers take User (Me enum gone), request.rs → call/shared.rs, GetSettings served
directly, publish::direct for relay/stats without the DB lock, disconnect cleanup first,
zombie conn close, rooms Left/Why enums, release publish ordering + rollback, forge timeouts,
argon2 off the lock, DM delete on user delete, forwarded attachment deletes, backups in ms.
Suspend and timeout replace each other, so Account's single Suspension is always the truth.

Client: crate::worker (Worker/supervise), net receive.rs + discard() off-lock drops,
share/session split into send/watch, voice sound.rs + pipewire pw.rs, atomic config/cache
writes, instance lock, embed SSRF filter, update loop fix, Chat split into
Session/Admin/PollDraft with one Armed enum, one network handler (no handle_hidden),
keys.rs table, SAFE_EXTENSIONS for cached attachments, many GUI state fixes.
Palette removed: every view reads style::Tokens directly. Clippy clean apart from
argument-count lints.

Tooling: harness lib.sh (refuses a STATE path too long for pipewire sockets), per-port
scope name, focus ring off in niri.kdl, PID-safe traps, imports.sh in CI, workspace deps
consolidated, client thiserror dropped.

189 changed files +10664 -11033

Cargo.lockmodified+1 -1
@@ -1350,6 +1350,7 @@ name = "client"
1350 version = "0.1.0"1350 version = "0.1.0"
1351 dependencies = [1351 dependencies = [
1352 "ashpd 0.14.3",1352 "ashpd 0.14.3",
1353+ "bitcode",
1353 "bytes",1354 "bytes",
1354 "clap",1355 "clap",
1355 "common",1356 "common",
@@ -1392,7 +1393,6 @@ dependencies = [
1392 "spectrum",1393 "spectrum",
1393 "sys-locale",1394 "sys-locale",
1394 "sysinfo 0.40.4",1395 "sysinfo 0.40.4",
1395- "thiserror 2.0.21",
1396 "tokio",1396 "tokio",
1397 "toml 1.2.3+spec-1.1.0",1397 "toml 1.2.3+spec-1.1.0",
1398 "tracing",1398 "tracing",
Cargo.tomlmodified+26 -9
@@ -15,9 +15,6 @@ opt-level = 3
15 [profile.dev.package.spectrum]15 [profile.dev.package.spectrum]
16 opt-level = 316 opt-level = 3
17 17
18-[profile.dev.package.rustfft]
19-opt-level = 3
20-
21 [profile.harness]18 [profile.harness]
22 inherits = "dev"19 inherits = "dev"
23 opt-level = 320 opt-level = 3
@@ -28,14 +25,11 @@ overflow-checks = false
28 debug-assertions = true25 debug-assertions = true
29 26
30 [profile.release]27 [profile.release]
31-opt-level = 3
32 lto = "fat"28 lto = "fat"
33 codegen-units = 129 codegen-units = 1
34 panic = "abort"30 panic = "abort"
35 debug = false31 debug = false
36 strip = true32 strip = true
37-overflow-checks = false
38-incremental = false
39 33
40 [workspace.lints.rust]34 [workspace.lints.rust]
41 unsafe_code = "forbid"35 unsafe_code = "forbid"
@@ -44,12 +38,35 @@ unsafe_code = "forbid"
44 common = { path = "crates/common" }38 common = { path = "crates/common" }
45 pixel = { path = "crates/pixel" }39 pixel = { path = "crates/pixel" }
46 spectrum = { path = "crates/spectrum" }40 spectrum = { path = "crates/spectrum" }
41+usage = { path = "crates/usage" }
47 tokio = { version = "1.54.1", features = ["full"] }42 tokio = { version = "1.54.1", features = ["full"] }
48 bitcode = "0.6.9"43 bitcode = "0.6.9"
49-quinn = { version = "0.11.12", default-features = false, features = [44+quinn = { version = "0.11.12", default-features = false, features = ["runtime-tokio"] }
50- "runtime-tokio",
51-] }
52 rustls = "0.23.45"45 rustls = "0.23.45"
46+bytes = "1.12.2"
47+tracing = "0.1.44"
48+tracing-subscriber = "0.3.23"
49+thiserror = "2.0.21"
50+reed-solomon-simd = "3.1.0"
51+sha2 = "0.11.2"
52+serde = { version = "1.0.229", features = ["derive"] }
53+serde_json = "1.0.154"
54+image = { version = "0.25.10", default-features = false, features = ["jpeg", "png", "webp", "gif"] }
55+ureq = "3.5.2"
56+resvg = "0.50.0"
57+sysinfo = { version = "0.40.4", default-features = false }
58+winreg = "0.56.0"
59+ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
60+ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
61+ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
62+ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
63+ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
64+ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
65+ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
66+ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
67+ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
68+ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
69+ec-av1 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
53 70
54 [patch.crates-io]71 [patch.crates-io]
55 gpui-pre-windows = { path = "vendor/gpui-pre-windows" }72 gpui-pre-windows = { path = "vendor/gpui-pre-windows" }
ci/build.shmodified+5 -2
@@ -43,12 +43,12 @@ echo "::endgroup::"
43 echo "::group::Build"43 echo "::group::Build"
44 if [ "$os" = windows ]; then44 if [ "$os" = windows ]; then
45 sha256sum -c --quiet ci/shaders.sha25645 sha256sum -c --quiet ci/shaders.sha256
46- export XWIN_ACCEPT_LICENSE=1 XWIN_CACHE_DIR="$CARGO_HOME/xwin" GPUI_SHADERS_BYTES="$PWD/ci/shaders_bytes.rs"46+ export XWIN_ACCEPT_LICENSE=1 XWIN_CACHE_DIR="$CARGO_HOME/xwin" GPUI_SHADERS_BYTES="$PWD/ci/shaders_bytes.rs" YUMUSH_TARGET="$target"
47 export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-C target-cpu=$cpu"47 export CARGO_TARGET_X86_64_PC_WINDOWS_MSVC_RUSTFLAGS="-C target-cpu=$cpu"
48 cargo xwin build --release -p client --target "$windows" --target-dir "target/$level"48 cargo xwin build --release -p client --target "$windows" --target-dir "target/$level"
49 built="target/$level/$windows/release/client.exe"49 built="target/$level/$windows/release/client.exe"
50 else50 else
51- export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C target-cpu=$cpu"51+ export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS="-C target-cpu=$cpu" YUMUSH_TARGET="$target"
52 cargo build --release -p "$package" --target-dir "target/$level"52 cargo build --release -p "$package" --target-dir "target/$level"
53 built="target/$level/release/$package"53 built="target/$level/release/$package"
54 fi54 fi
@@ -57,4 +57,7 @@ echo "::endgroup::"
57 echo "::group::Package"57 echo "::group::Package"
58 cp "$built" "$target"58 cp "$built" "$target"
59 sha256sum "$target"59 sha256sum "$target"
60+if [ "$os" = windows ]; then
61+ bash harness/imports.sh "$built"
62+fi
60 echo "::endgroup::"63 echo "::endgroup::"
configs/client_config.tomldeleted+0 -2
@@ -1,2 +0,0 @@
1-[client_config]
2-server_address = "127.0.0.1:2026"
crates/client/Cargo.tomlmodified+25 -26
@@ -4,36 +4,36 @@ version = "0.1.0"
4 edition = "2024"4 edition = "2024"
5 5
6 [dependencies]6 [dependencies]
7-usage = { path = "../usage" }7+usage.workspace = true
8 common.workspace = true8 common.workspace = true
9+bitcode.workspace = true
9 pixel.workspace = true10 pixel.workspace = true
10 spectrum.workspace = true11 spectrum.workspace = true
11-reed-solomon-simd = "3.1.0"12+reed-solomon-simd.workspace = true
12 tokio.workspace = true13 tokio.workspace = true
13 quinn = { workspace = true, features = ["rustls-ring"] }14 quinn = { workspace = true, features = ["rustls-ring"] }
14-15+ec-opus.workspace = true
16+ec-core.workspace = true
17+ec-probe.workspace = true
18+ec-ogg.workspace = true
19+ec-h264.workspace = true
20+ec-vp8.workspace = true
21+ec-flac.workspace = true
22+ec-h265.workspace = true
23+ec-hw.workspace = true
24+ec-vp9.workspace = true
25+ec-av1.workspace = true
15 gpui-kit = { version = "0.11.0", features = ["syntect"] }26 gpui-kit = { version = "0.11.0", features = ["syntect"] }
16-ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }27+ureq.workspace = true
17-ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }28+serde.workspace = true
18-ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }29+serde_json.workspace = true
19-ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }30+bytes.workspace = true
20-ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }31+tracing.workspace = true
21-ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }32+tracing-subscriber.workspace = true
22-ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
23-ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
24-ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
25-ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
26-ec-av1 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "9b677004" }
27-ureq = "3.5.2"
28-serde = { version = "1.0.229", features = ["derive"] }
29-serde_json = "1.0.154"
30-bytes = "1.12.2"
31-tracing = "0.1.44"
32-tracing-subscriber = "0.3.23"
33 jiff = "1.0.2"33 jiff = "1.0.2"
34 dirs = "7.0.0"34 dirs = "7.0.0"
35 sys-locale = "0.3.2"35 sys-locale = "0.3.2"
36-image = { version = "0.25.10", default-features = false, features = ["jpeg", "png", "webp", "gif"] }36+image.workspace = true
37 rtrb = "0.4.1"37 rtrb = "0.4.1"
38 gethostname = "1.1.0"38 gethostname = "1.1.0"
39 self-replace = "1.5.1"39 self-replace = "1.5.1"
@@ -41,8 +41,7 @@ ruzstd = "0.9.1"
41 rustls-platform-verifier = "0.7.1"41 rustls-platform-verifier = "0.7.1"
42 flate2 = "1.1.11"42 flate2 = "1.1.11"
43 emojis = "0.9.1"43 emojis = "0.9.1"
44-resvg = "0.50.0"44+resvg.workspace = true
45-thiserror = "2.0.21"
46 45
47 [target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]46 [target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]
48 nokhwa = { version = "0.10.11", default-features = false, features = ["input-native"] }47 nokhwa = { version = "0.10.11", default-features = false, features = ["input-native"] }
@@ -60,8 +59,8 @@ wasapi = "0.27.0"
60 windows-capture = "2.0.1"59 windows-capture = "2.0.1"
61 xcap = { version = "0.9.11", default-features = false }60 xcap = { version = "0.9.11", default-features = false }
62 tray-icon = { version = "0.27.0", default-features = false }61 tray-icon = { version = "0.27.0", default-features = false }
63-winreg = "0.56.0"62+winreg.workspace = true
64-sysinfo = { version = "0.40.4", default-features = false, features = ["system"] }63+sysinfo = { workspace = true, features = ["system"] }
65 64
66 [target.'cfg(target_os = "macos")'.dependencies]65 [target.'cfg(target_os = "macos")'.dependencies]
67 coreaudio-rs = "0.14.2"66 coreaudio-rs = "0.14.2"
@@ -70,7 +69,7 @@ coreaudio-rs = "0.14.2"
70 embed-resource = "3.0.12"69 embed-resource = "3.0.12"
71 icns = "0.5.0"70 icns = "0.5.0"
72 ico = "0.6.0"71 ico = "0.6.0"
73-resvg = "0.50.0"72+resvg.workspace = true
74 toml = "1.2.3"73 toml = "1.2.3"
75 74
76 [lints]75 [lints]
crates/client/build.rsmodified+27 -45
@@ -20,41 +20,28 @@ const COLORS: [&str; 10] = [
20 "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad",20 "ground", "raise", "hov", "press", "thread", "off", "faint", "dim", "paper", "bad",
21 ];21 ];
22 const SCALES: [&str; 6] = ["space", "radius", "stroke", "text", "size", "leading"];22 const SCALES: [&str; 6] = ["space", "radius", "stroke", "text", "size", "leading"];
23-const V1: &[&str] = &["fxsr", "sse", "sse2"];
24-const V1_WINDOWS: &[&str] = &["cmpxchg16b", "fxsr", "sse", "sse2", "sse3"];
25-const V3: &[&str] = &[
26- "avx",
27- "avx2",
28- "bmi1",
29- "bmi2",
30- "cmpxchg16b",
31- "f16c",
32- "fma",
33- "fxsr",
34- "lzcnt",
35- "movbe",
36- "popcnt",
37- "sse",
38- "sse2",
39- "sse3",
40- "sse4.1",
41- "sse4.2",
42- "ssse3",
43- "xsave",
44-];
45 const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"];23 const MEDIA_FOUNDATION: [&str; 3] = ["mf.dll", "mfplat.dll", "mfreadwrite.dll"];
46 24
47 fn main() {25 fn main() {
48 println!("cargo::rerun-if-changed={SOURCE}");26 println!("cargo::rerun-if-changed={SOURCE}");
49 icons();27 icons();
50 words();28 words();
29+ tokens();
51 target();30 target();
31+ commit();
32+ link_args();
33+}
34+
35+fn link_args() {
52 if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {36 if env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc") {
53 for dll in MEDIA_FOUNDATION {37 for dll in MEDIA_FOUNDATION {
54 println!("cargo::rustc-link-arg-bins=/DELAYLOAD:{dll}");38 println!("cargo::rustc-link-arg-bins=/DELAYLOAD:{dll}");
55 }39 }
56 println!("cargo::rustc-link-arg-bins=delayimp.lib");40 println!("cargo::rustc-link-arg-bins=delayimp.lib");
57 }41 }
42+}
43+
44+fn tokens() {
58 let tokens: Table = fs::read_to_string(SOURCE)45 let tokens: Table = fs::read_to_string(SOURCE)
59 .expect("read tokens")46 .expect("read tokens")
60 .parse()47 .parse()
@@ -72,21 +59,22 @@ fn main() {
72 let themes = tokens["theme"].as_table().expect("theme table");59 let themes = tokens["theme"].as_table().expect("theme table");
73 writeln!(60 writeln!(
74 out,61 out,
75- "#[derive(Debug, Clone, Copy, PartialEq, Eq)]\npub enum Theme {{ {} }}",62+ "common::string_enum! {{ #[derive(Debug, Clone, Copy, PartialEq, Eq)] Theme {{ {} }} }}",
76 themes63 themes
77 .keys()64 .keys()
78- .map(|name| camel(name))65+ .map(|name| format!("{} => {name:?}", camel(name)))
79 .collect::<Vec<_>>()66 .collect::<Vec<_>>()
80 .join(", ")67 .join(", ")
81 )68 )
82 .unwrap();69 .unwrap();
83 writeln!(70 writeln!(
84 out,71 out,
85- "impl Theme {{\n pub const ALL: [Theme; {}] = [{}];\n pub const fn as_str(self) -> &'static str {{ match self {{ {} }} }}\n pub fn parse(text: &str) -> Option<Self> {{ Self::ALL.into_iter().find(|theme| theme.as_str() == text) }}\n pub const fn colors(self) -> &'static Colors {{ match self {{ {} }} }}\n}}",72+ "impl Theme {{ pub const fn colors(self) -> &'static Colors {{ match self {{ {} }} }} }}",
86- themes.len(),73+ themes
87- themes.keys().map(|name| format!("Theme::{}", camel(name))).collect::<Vec<_>>().join(", "),74+ .keys()
88- themes.keys().map(|name| format!("Theme::{} => \"{name}\"", camel(name))).collect::<Vec<_>>().join(", "),75+ .map(|name| format!("Theme::{} => &{}", camel(name), name.to_uppercase()))
89- themes.keys().map(|name| format!("Theme::{} => &{}", camel(name), name.to_uppercase())).collect::<Vec<_>>().join(", "),76+ .collect::<Vec<_>>()
77+ .join(", ")
90 )78 )
91 .unwrap();79 .unwrap();
92 80
@@ -371,23 +359,17 @@ fn holes(text: &str) -> Vec<String> {
371 }359 }
372 360
373 fn target() {361 fn target() {
374- let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();362+ println!("cargo::rerun-if-env-changed=YUMUSH_TARGET");
375- let os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();363+ let target = env::var("YUMUSH_TARGET").unwrap_or_else(|_| {
376- let features = env::var("CARGO_CFG_TARGET_FEATURE").unwrap_or_default();364+ let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
377- let mut features: Vec<&str> = features365+ let os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
378- .split(',')366+ if arch == "x86_64" {
379- .filter(|feature| !feature.is_empty() && *feature != "crt-static")367+ "custom".to_string()
380- .collect();368+ } else {
381- features.sort_unstable();369+ format!("{arch}-{os}")
382- let target = match (arch.as_str(), features.as_slice()) {370+ }
383- ("x86_64", V1) if os != "windows" => format!("x86_64_v1-{os}"),371+ });
384- ("x86_64", V1_WINDOWS) if os == "windows" => format!("x86_64_v1-{os}"),
385- ("x86_64", V3) => format!("x86_64_v3-{os}"),
386- ("x86_64", _) => "custom".to_string(),
387- _ => format!("{arch}-{os}"),
388- };
389 println!("cargo::rustc-env=YUMUSH_TARGET={target}");372 println!("cargo::rustc-env=YUMUSH_TARGET={target}");
390- commit();
391 }373 }
392 374
393 fn commit() {375 fn commit() {
crates/client/src/accounts.rsmodified+12 -14
@@ -29,6 +29,12 @@ impl Accounts {
29 self.list.iter().find(|account| account.user_id == user_id)29 self.list.iter().find(|account| account.user_id == user_id)
30 }30 }
31 31
32+ fn get_mut(&mut self, user_id: Id) -> Option<&mut Account> {
33+ self.list
34+ .iter_mut()
35+ .find(|account| account.user_id == user_id)
36+ }
37+
32 pub fn recent(&self) -> Vec<&Account> {38 pub fn recent(&self) -> Vec<&Account> {
33 let mut list: Vec<&Account> = self.list.iter().collect();39 let mut list: Vec<&Account> = self.list.iter().collect();
34 list.sort_by_key(|account| Reverse(account.used_ms));40 list.sort_by_key(|account| Reverse(account.used_ms));
@@ -49,11 +55,7 @@ impl Accounts {
49 }55 }
50 56
51 pub fn rename(&mut self, user: &User) {57 pub fn rename(&mut self, user: &User) {
52- if let Some(account) = self58+ if let Some(account) = self.get_mut(user.id) {
53- .list
54- .iter_mut()
55- .find(|account| account.user_id == user.id)
56- {
57 account.username = user.username.clone();59 account.username = user.username.clone();
58 save(self);60 save(self);
59 }61 }
@@ -74,11 +76,7 @@ impl Accounts {
74 Some(bytes) => write_config(&name, bytes),76 Some(bytes) => write_config(&name, bytes),
75 None => remove_config(&name),77 None => remove_config(&name),
76 }78 }
77- if let Some(account) = self79+ if let Some(account) = self.get_mut(user_id) {
78- .list
79- .iter_mut()
80- .find(|account| account.user_id == user_id)
81- {
82 account.picture =80 account.picture =
83 bytes.map(|bytes| Arc::new(Image::from_bytes(ImageFormat::Jpeg, bytes)));81 bytes.map(|bytes| Arc::new(Image::from_bytes(ImageFormat::Jpeg, bytes)));
84 }82 }
@@ -126,21 +124,21 @@ pub fn load(server: &str) -> Accounts {
126 server: server.to_string(),124 server: server.to_string(),
127 ..Accounts::default()125 ..Accounts::default()
128 };126 };
129- let Some(content) = read_config(&file(server)).or_else(|| read_config("accounts")) else {127+ let Some(content) = read_config(&file(server)) else {
130 return accounts;128 return accounts;
131 };129 };
132 130
133 for line in content.lines() {131 for line in content.lines() {
134 match line.split('\t').collect::<Vec<_>>().as_slice() {132 match line.split('\t').collect::<Vec<_>>().as_slice() {
135 ["active", user_id] => accounts.active = user_id.parse().ok(),133 ["active", user_id] => accounts.active = user_id.parse().ok(),
136- [user_id, username, token, rest @ ..] => {134+ [user_id, username, token, used] => {
137- if let Ok(user_id) = user_id.parse() {135+ if let (Ok(user_id), Ok(used_ms)) = (user_id.parse(), used.parse()) {
138 accounts.list.push(Account {136 accounts.list.push(Account {
139 user_id,137 user_id,
140 username: username.to_string(),138 username: username.to_string(),
141 token: token.to_string(),139 token: token.to_string(),
142 picture: picture(server, user_id),140 picture: picture(server, user_id),
143- used_ms: rest.first().and_then(|used| used.parse().ok()).unwrap_or(0),141+ used_ms,
144 });142 });
145 }143 }
146 }144 }
crates/client/src/ci.rsmodified+22 -12
@@ -121,16 +121,18 @@ impl Repo {
121 }121 }
122 122
123 fn poll(repo: &Repo, send: &UnboundedSender<Event>, stop: &AtomicBool) {123 fn poll(repo: &Repo, send: &UnboundedSender<Event>, stop: &AtomicBool) {
124- let mut followed = None;124+ let mut last = None;
125 while !stop.load(Ordering::Relaxed) && !send.is_closed() {125 while !stop.load(Ordering::Relaxed) && !send.is_closed() {
126 if let Some(run) = latest(repo) {126 if let Some(run) = latest(repo) {
127- let fresh = followed != Some(run.number);127+ let state = State::of(&run.state);
128- let live = !State::of(&run.state).finished();128+ let number = run.number;
129- if fresh || live {129+ if last != Some((number, state)) || !state.finished() {
130- followed = Some(run.number);130+ last = Some((number, state));
131- let _ = send.send(Event::Run(run.clone()));131+ let _ = send.send(Event::Run(run));
132- if live {132+ if !state.finished()
133- follow(repo, run.number, send, stop);133+ && let Some(state) = follow(repo, number, send, stop)
134+ {
135+ last = Some((number, state));
134 }136 }
135 }137 }
136 }138 }
@@ -160,11 +162,17 @@ fn latest(repo: &Repo) -> Option<Run> {
160 .next()162 .next()
161 }163 }
162 164
163-fn follow(repo: &Repo, number: u64, send: &UnboundedSender<Event>, stop: &AtomicBool) {165+fn follow(
166+ repo: &Repo,
167+ number: u64,
168+ send: &UnboundedSender<Event>,
169+ stop: &AtomicBool,
170+) -> Option<State> {
164 let Ok(response) = ureq::get(format!("{}/ci/runs/{number}/events", repo.api)).call() else {171 let Ok(response) = ureq::get(format!("{}/ci/runs/{number}/events", repo.api)).call() else {
165- return;172+ return None;
166 };173 };
167 let mut streaming = HashSet::new();174 let mut streaming = HashSet::new();
175+ let mut last = None;
168 let finished = Arc::new(std::sync::Mutex::new(HashSet::new()));176 let finished = Arc::new(std::sync::Mutex::new(HashSet::new()));
169 events(response.into_body().into_reader(), |event, data| {177 events(response.into_body().into_reader(), |event, data| {
170 if event != "run" {178 if event != "run" {
@@ -183,10 +191,12 @@ fn follow(repo: &Repo, number: u64, send: &UnboundedSender<Event>, stop: &Atomic
183 std::thread::spawn(move || log(&url, &job, &send, &finished));191 std::thread::spawn(move || log(&url, &job, &send, &finished));
184 }192 }
185 }193 }
186- let done = State::of(&run.state).finished();194+ let state = State::of(&run.state);
195+ last = Some(state);
187 let _ = send.send(Event::Run(run));196 let _ = send.send(Event::Run(run));
188- !done && !stop.load(Ordering::Relaxed)197+ !state.finished() && !stop.load(Ordering::Relaxed)
189 });198 });
199+ last
190 }200 }
191 201
192 fn log(202 fn log(
crates/client/src/cli.rsmodified+27 -42
@@ -3,7 +3,7 @@ use std::{collections::HashMap, io::Read, process::exit, time::Duration};
3 use clap::{Parser, Subcommand};3 use clap::{Parser, Subcommand};
4 use common::{4 use common::{
5 call::{5 call::{
6- CreateMessage, CreateTag, GetForge, ImportRelease, ListCommunities, ListMembers,6+ Call, CreateMessage, CreateTag, GetForge, ImportRelease, ListCommunities, ListMembers,
7 ListMessages, OpenNotes, PublishRelease,7 ListMessages, OpenNotes, PublishRelease,
8 },8 },
9 event::Event,9 event::Event,
@@ -99,13 +99,11 @@ async fn execute(command: Command) -> Result<(), String> {
99 let community = session.chat(&chat).await?;99 let community = session.chat(&chat).await?;
100 let names = session.names(community.id).await?;100 let names = session.names(community.id).await?;
101 let messages = session101 let messages = session
102- .network
103 .call(ListMessages {102 .call(ListMessages {
104 community_id: community.id,103 community_id: community.id,
105 before: None,104 before: None,
106 })105 })
107- .await106+ .await?;
108- .map_err(text)?;
109 let skip = messages.len().saturating_sub(count);107 let skip = messages.len().saturating_sub(count);
110 for message in &messages[skip..] {108 for message in &messages[skip..] {
111 print_message(message, &names, None);109 print_message(message, &names, None);
@@ -125,26 +123,20 @@ async fn execute(command: Command) -> Result<(), String> {
125 let session = open().await?;123 let session = open().await?;
126 let community = session.chat(&chat).await?;124 let community = session.chat(&chat).await?;
127 session125 session
128- .network
129 .call(CreateMessage {126 .call(CreateMessage {
130 community_id: community.id,127 community_id: community.id,
131 body,128 body,
132 attachments: Vec::new(),129 attachments: Vec::new(),
133 reply_to: None,130 reply_to: None,
134 })131 })
135- .await132+ .await?;
136- .map_err(text)?;
137 Ok(())133 Ok(())
138 }134 }
139 Command::Tail { chat } => tail(open().await?, chat).await,135 Command::Tail { chat } => tail(open().await?, chat).await,
140 Command::Ci { tag } => follow(&open().await?, tag.as_deref()).await,136 Command::Ci { tag } => follow(&open().await?, tag.as_deref()).await,
141 Command::Build { tag } => {137 Command::Build { tag } => {
142 let session = open().await?;138 let session = open().await?;
143- session139+ session.call(CreateTag { tag: tag.clone() }).await?;
144- .network
145- .call(CreateTag { tag: tag.clone() })
146- .await
147- .map_err(text)?;
148 println!("tag {tag} created");140 println!("tag {tag} created");
149 follow(&session, Some(&tag)).await141 follow(&session, Some(&tag)).await
150 }142 }
@@ -160,17 +152,16 @@ fn text(fail: Fail) -> String {
160 fail.to_string()152 fail.to_string()
161 }153 }
162 154
163-fn start() -> (NetworkHandle, Receiver<NetworkEvent>, accounts::Accounts) {155+fn start() -> (Session, accounts::Accounts) {
164 let server = Server::load();156 let server = Server::load();
165 let accounts = accounts::load(&server.address);157 let accounts = accounts::load(&server.address);
166 let (network, events) = net::start(server);158 let (network, events) = net::start(server);
167- (network, events, accounts)159+ (Session { network, events }, accounts)
168 }160 }
169 161
170 async fn login(username: &str) -> Result<(), String> {162 async fn login(username: &str) -> Result<(), String> {
171 let password = rpassword::prompt_password("password: ").map_err(|error| error.to_string())?;163 let password = rpassword::prompt_password("password: ").map_err(|error| error.to_string())?;
172- let (network, events, mut accounts) = start();164+ let (session, mut accounts) = start();
173- let session = Session { network, events };
174 let (user, token) = session165 let (user, token) = session
175 .connect(session.network.login(username, &password))166 .connect(session.network.login(username, &password))
176 .await?;167 .await?;
@@ -190,13 +181,12 @@ async fn logout() -> Result<(), String> {
190 }181 }
191 182
192 async fn open() -> Result<Session, String> {183 async fn open() -> Result<Session, String> {
193- let (network, events, accounts) = start();184+ let (session, accounts) = start();
194 let token = accounts185 let token = accounts
195 .active186 .active
196 .and_then(|user_id| accounts.get(user_id))187 .and_then(|user_id| accounts.get(user_id))
197 .map(|account| account.token.clone())188 .map(|account| account.token.clone())
198 .ok_or("not signed in: yumush login <username>")?;189 .ok_or("not signed in: yumush login <username>")?;
199- let session = Session { network, events };
200 session.connect(session.network.resume(&token)).await?;190 session.connect(session.network.resume(&token)).await?;
201 Ok(session)191 Ok(session)
202 }192 }
@@ -212,31 +202,29 @@ impl Session {
212 .map_err(text)202 .map_err(text)
213 }203 }
214 204
205+ async fn call<C: Call>(&self, call: C) -> Result<C::Reply, String> {
206+ self.network.call(call).await.map_err(text)
207+ }
208+
215 async fn communities(&self) -> Result<Vec<Community>, String> {209 async fn communities(&self) -> Result<Vec<Community>, String> {
216- let mut communities = self.network.call(ListCommunities).await.map_err(text)?;210+ let mut communities = self.call(ListCommunities).await?;
217 if !communities211 if !communities
218 .iter()212 .iter()
219 .any(|community| matches!(community.kind, CommunityKind::Notes))213 .any(|community| matches!(community.kind, CommunityKind::Notes))
220 {214 {
221- communities.push(self.network.call(OpenNotes).await.map_err(text)?);215+ communities.push(self.call(OpenNotes).await?);
222 }216 }
223 Ok(communities)217 Ok(communities)
224 }218 }
225 219
226 async fn chat(&self, chat: &str) -> Result<Community, String> {220 async fn chat(&self, chat: &str) -> Result<Community, String> {
227- self.communities()221+ find_chat(&self.communities().await?, chat).cloned()
228- .await?
229- .into_iter()
230- .find(|community| title(community).eq_ignore_ascii_case(chat))
231- .ok_or_else(|| format!("no chat named {chat}; see yumush chats"))
232 }222 }
233 223
234 async fn names(&self, community_id: Id) -> Result<HashMap<Id, String>, String> {224 async fn names(&self, community_id: Id) -> Result<HashMap<Id, String>, String> {
235 Ok(self225 Ok(self
236- .network
237 .call(ListMembers { community_id })226 .call(ListMembers { community_id })
238- .await227+ .await?
239- .map_err(text)?
240 .into_iter()228 .into_iter()
241 .map(|member| (member.user.id, member.user.username))229 .map(|member| (member.user.id, member.user.username))
242 .collect())230 .collect())
@@ -254,6 +242,13 @@ impl Session {
254 }242 }
255 }243 }
256 244
245+fn find_chat<'a>(communities: &'a [Community], chat: &str) -> Result<&'a Community, String> {
246+ communities
247+ .iter()
248+ .find(|community| title(community).eq_ignore_ascii_case(chat))
249+ .ok_or_else(|| format!("no chat named {chat}; see yumush chats"))
250+}
251+
257 fn title(community: &Community) -> String {252 fn title(community: &Community) -> String {
258 match &community.kind {253 match &community.kind {
259 CommunityKind::Group => community.name.clone(),254 CommunityKind::Group => community.name.clone(),
@@ -290,7 +285,7 @@ fn print_message(message: &Message, names: &HashMap<Id, String>, chat: Option<&s
290 async fn tail(mut session: Session, chat: Option<String>) -> Result<(), String> {285 async fn tail(mut session: Session, chat: Option<String>) -> Result<(), String> {
291 let communities = session.communities().await?;286 let communities = session.communities().await?;
292 let only = match &chat {287 let only = match &chat {
293- Some(chat) => Some(session.chat(chat).await?.id),288+ Some(chat) => Some(find_chat(&communities, chat)?.id),
294 None => None,289 None => None,
295 };290 };
296 let titles: HashMap<Id, String> = communities291 let titles: HashMap<Id, String> = communities
@@ -319,10 +314,8 @@ async fn tail(mut session: Session, chat: Option<String>) -> Result<(), String>
319 314
320 async fn follow(session: &Session, tag: Option<&str>) -> Result<(), String> {315 async fn follow(session: &Session, tag: Option<&str>) -> Result<(), String> {
321 let repo = session316 let repo = session
322- .network
323 .call(GetForge)317 .call(GetForge)
324- .await318+ .await?
325- .map_err(text)?
326 .ok_or("the server has no forge set")?;319 .ok_or("the server has no forge set")?;
327 let (_watch, mut events) = ci::watch(repo);320 let (_watch, mut events) = ci::watch(repo);
328 let mut states: HashMap<String, ci::State> = HashMap::new();321 let mut states: HashMap<String, ci::State> = HashMap::new();
@@ -373,11 +366,7 @@ async fn import(
373 publish: Option<Side>,366 publish: Option<Side>,
374 required: bool,367 required: bool,
375 ) -> Result<(), String> {368 ) -> Result<(), String> {
376- session369+ session.call(ImportRelease { tag: tag.clone() }).await?;
377- .network
378- .call(ImportRelease { tag: tag.clone() })
379- .await
380- .map_err(text)?;
381 println!("importing {tag}");370 println!("importing {tag}");
382 let staged = loop {371 let staged = loop {
383 if let Event::Imported { tag: done, result } = session.event().await?372 if let Event::Imported { tag: done, result } = session.event().await?
@@ -401,11 +390,7 @@ async fn import(
401 .filter(|file| side.takes(&file.target))390 .filter(|file| side.takes(&file.target))
402 .map(|file| file.file)391 .map(|file| file.file)
403 .collect();392 .collect();
404- let release = session393+ let release = session.call(PublishRelease { files, required }).await?;
405- .network
406- .call(PublishRelease { files, required })
407- .await
408- .map_err(text)?;
409 println!("published release #{}", release.seq);394 println!("published release #{}", release.seq);
410 Ok(())395 Ok(())
411 }396 }
crates/client/src/embed.rsmodified+75 -17
@@ -1,10 +1,12 @@
1 use std::io::Read;1 use std::io::Read;
2+use std::net::{IpAddr, ToSocketAddrs};
2 use std::time::Duration;3 use std::time::Duration;
3 4
4-use ureq::http::Uri;5+use ureq::http::{Uri, header::LOCATION};
5 use ureq::{Agent, Body, ResponseExt};6 use ureq::{Agent, Body, ResponseExt};
6 7
7 const MAX_LINKS: usize = 3;8 const MAX_LINKS: usize = 3;
9+const MAX_REDIRECTS: usize = 5;
8 const MAX_IMAGE: u64 = 5 * 1024 * 1024;10 const MAX_IMAGE: u64 = 5 * 1024 * 1024;
9 const MAX_HTML: u64 = 512 * 1024;11 const MAX_HTML: u64 = 512 * 1024;
10 const MAX_TITLE: usize = 256;12 const MAX_TITLE: usize = 256;
@@ -56,10 +58,10 @@ pub fn urls(text: &str) -> Vec<String> {
56 }58 }
57 59
58 fn find_scheme(s: &str) -> Option<usize> {60 fn find_scheme(s: &str) -> Option<usize> {
59- match (s.find("http://"), s.find("https://")) {61+ s.find("http://")
60- (Some(a), Some(b)) => Some(a.min(b)),62+ .into_iter()
61- (a, b) => a.or(b),63+ .chain(s.find("https://"))
62- }64+ .min()
63 }65 }
64 66
65 fn trim_link(s: &str) -> &str {67 fn trim_link(s: &str) -> &str {
@@ -79,18 +81,15 @@ fn trim_link(s: &str) -> &str {
79 }81 }
80 82
81 pub fn fetch(url: &str) -> Option<Embed> {83 pub fn fetch(url: &str) -> Option<Embed> {
82- if !is_web(url) {
83- return None;
84- }
85 let agent = Agent::new_with_config(84 let agent = Agent::new_with_config(
86 Agent::config_builder()85 Agent::config_builder()
87 .timeout_global(Some(Duration::from_secs(5)))86 .timeout_global(Some(Duration::from_secs(5)))
88- .max_redirects(5)87+ .max_redirects(0)
89 .user_agent("yumush")88 .user_agent("yumush")
90 .http_status_as_error(true)89 .http_status_as_error(true)
91 .build(),90 .build(),
92 );91 );
93- let mut resp = agent.get(url).call().ok()?;92+ let mut resp = get(&agent, url)?;
94 let final_url = resp.get_uri().to_string();93 let final_url = resp.get_uri().to_string();
95 let mime = mime_of(&resp)?;94 let mime = mime_of(&resp)?;
96 95
@@ -139,9 +138,71 @@ pub fn fetch(url: &str) -> Option<Embed> {
139 })138 })
140 }139 }
141 140
142-fn is_web(url: &str) -> bool {141+fn get(agent: &Agent, url: &str) -> Option<ureq::http::Response<Body>> {
143- url.parse::<Uri>()142+ let mut url = url.to_owned();
144- .is_ok_and(|u| matches!(u.scheme_str(), Some("http" | "https")))143+ for _ in 0..=MAX_REDIRECTS {
144+ if !public(&url) {
145+ return None;
146+ }
147+ let resp = agent.get(&url).call().ok()?;
148+ if !resp.status().is_redirection() {
149+ return Some(resp);
150+ }
151+ let location = resp.headers().get(LOCATION)?.to_str().ok()?;
152+ url = resolve(&url, location)?;
153+ }
154+ None
155+}
156+
157+fn public(url: &str) -> bool {
158+ let Ok(uri) = url.parse::<Uri>() else {
159+ return false;
160+ };
161+ let default_port = match uri.scheme_str() {
162+ Some("http") => 80,
163+ Some("https") => 443,
164+ _ => return false,
165+ };
166+ let Some(host) = uri.host() else {
167+ return false;
168+ };
169+ let host = host.trim_start_matches('[').trim_end_matches(']');
170+ let Ok(addrs) = (host, uri.port_u16().unwrap_or(default_port)).to_socket_addrs() else {
171+ return false;
172+ };
173+ let addrs: Vec<_> = addrs.collect();
174+ !addrs.is_empty() && addrs.iter().all(|addr| routable(addr.ip()))
175+}
176+
177+fn routable(ip: IpAddr) -> bool {
178+ match ip {
179+ IpAddr::V4(ip) => {
180+ let [a, b, ..] = ip.octets();
181+ let shared = a == 100 && (b & 0xc0) == 64;
182+ !(a == 0
183+ || shared
184+ || ip.is_private()
185+ || ip.is_loopback()
186+ || ip.is_link_local()
187+ || ip.is_broadcast()
188+ || ip.is_unspecified()
189+ || ip.is_multicast()
190+ || ip.is_documentation())
191+ }
192+ IpAddr::V6(ip) => {
193+ if let Some(mapped) = ip.to_ipv4_mapped() {
194+ return routable(IpAddr::V4(mapped));
195+ }
196+ let first = ip.segments()[0];
197+ let unique_local = (first & 0xfe00) == 0xfc00;
198+ let link_local = (first & 0xffc0) == 0xfe80;
199+ !(ip.is_loopback()
200+ || ip.is_unspecified()
201+ || ip.is_multicast()
202+ || unique_local
203+ || link_local)
204+ }
205+ }
145 }206 }
146 207
147 fn mime_of(resp: &ureq::http::Response<Body>) -> Option<String> {208 fn mime_of(resp: &ureq::http::Response<Body>) -> Option<String> {
@@ -165,10 +226,7 @@ fn read_image(resp: &mut ureq::http::Response<Body>) -> Option<Vec<u8>> {
165 }226 }
166 227
167 fn fetch_image(agent: &Agent, url: &str) -> Option<Vec<u8>> {228 fn fetch_image(agent: &Agent, url: &str) -> Option<Vec<u8>> {
168- if !is_web(url) {229+ let mut resp = get(agent, url)?;
169- return None;
170- }
171- let mut resp = agent.get(url).call().ok()?;
172 if !is_image(&mime_of(&resp)?) {230 if !is_image(&mime_of(&resp)?) {
173 return None;231 return None;
174 }232 }
crates/client/src/emoji.rsmodified+1 -1
@@ -63,7 +63,7 @@ pub fn key(emoji: &str) -> String {
63 .join("-")63 .join("-")
64 }64 }
65 65
66-pub fn known(emoji: &str) -> bool {66+fn known(emoji: &str) -> bool {
67 PACKED.index.contains_key(&key(emoji))67 PACKED.index.contains_key(&key(emoji))
68 }68 }
69 69
crates/client/src/gui.rsmodified+208 -248
@@ -1,16 +1,16 @@
1 use crate::gui::glyph::Fill as _;1 use crate::gui::glyph::Fill as _;
2-use crate::lang::{Label as _, w};2+use crate::lang::w;
3 use common::model::{Hue, Id};3 use common::model::{Hue, Id};
4 use std::{collections::HashMap, fmt::Display, rc::Rc, sync::Arc, time::Instant};4 use std::{collections::HashMap, fmt::Display, rc::Rc, sync::Arc, time::Instant};
5 5
6 use common::{6 use common::{
7 call::{GetAvatar, GetSettings, MarkRead},7 call::{GetAvatar, GetSettings, MarkRead},
8 constant::{MAXIMUM_AVATAR_BYTES, MAXIMUM_MESSAGE_LENGTH},8 constant::{MAXIMUM_AVATAR_BYTES, MAXIMUM_MESSAGE_LENGTH},
9- error::Error,9+ error::{Error, ReleaseProblem},
10 event::Event,10 event::Event,
11 model::{11 model::{
12- BackupInfo, CallLog, Community, CommunityKind, Message, Presence, Rank, Sanction,12+ CallLog, Community, CommunityKind, Message, Presence, Rank, Sanction, ServerSettings,
13- ServerSettings, Unread, User, mentions,13+ Staged, Unread, User, mentions,
14 },14 },
15 };15 };
16 use gpui_kit::{16 use gpui_kit::{
@@ -18,10 +18,9 @@ use gpui_kit::{
18 Entity, FontWeight, Hsla, Image, ImageFormat, InteractiveElement, IntoElement, KeyBinding,18 Entity, FontWeight, Hsla, Image, ImageFormat, InteractiveElement, IntoElement, KeyBinding,
19 KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, ParentElement, Pixels, Rems, Render,19 KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, ParentElement, Pixels, Rems, Render,
20 RenderOnce, Stateful, StatefulInteractiveElement, Styled, WeakEntity, Window, actions,20 RenderOnce, Stateful, StatefulInteractiveElement, Styled, WeakEntity, Window, actions,
21- assets::IconName,
22 base::Selectable,21 base::Selectable,
23 component::{22 component::{
24- Icon, Sizable, Theme, ThemeRegistry, WindowExt,23+ Sizable, Theme, ThemeRegistry, WindowExt,
25 input::{Input, InputEvent, InputState},24 input::{Input, InputEvent, InputState},
26 notification::Notification,25 notification::Notification,
27 spinner::Spinner,26 spinner::Spinner,
@@ -37,7 +36,8 @@ use crate::{
37 accounts::{self, Accounts},36 accounts::{self, Accounts},
38 marks::{self, Mark},37 marks::{self, Mark},
39 net::{Fail, LinkError, NetworkEvent, NetworkHandle},38 net::{Fail, LinkError, NetworkEvent, NetworkHandle},
40- settings::{Scale, Settings},39+ settings::Settings,
40+ voice::{self, Sound},
41 };41 };
42 42
43 mod account_list;43 mod account_list;
@@ -54,6 +54,7 @@ mod forward;
54 pub mod gallery;54 pub mod gallery;
55 pub mod glyph;55 pub mod glyph;
56 mod jump;56 mod jump;
57+mod keys;
57 mod media_view;58 mod media_view;
58 mod message_actions;59 mod message_actions;
59 mod parts;60 mod parts;
@@ -86,56 +87,6 @@ pub fn text(size: f32) -> Rems {
86 rems(size / style::text::UI)87 rems(size / style::text::UI)
87 }88 }
88 89
89-#[derive(Clone, Copy)]
90-pub struct Palette {
91- pub window: Hsla,
92- pub panel: Hsla,
93- pub field: Hsla,
94- pub border: Hsla,
95- pub text: Hsla,
96- pub body: Hsla,
97- pub muted: Hsla,
98- pub hover: Hsla,
99- pub accent: Hsla,
100- pub on_accent: Hsla,
101- pub ok: Hsla,
102- pub danger: Hsla,
103- pub alert: Hsla,
104- pub screen: Hsla,
105- pub camera: Hsla,
106- pub dark: bool,
107- pub tokens: Tokens,
108-}
109-
110-impl Palette {
111- pub fn tinted(self, id: Id) -> Hsla {
112- self.tokens.person(id)
113- }
114-}
115-
116-pub fn palette(cx: &App) -> Palette {
117- let tokens = Tokens::of(cx);
118- Palette {
119- window: tokens.ground(),
120- panel: tokens.ground(),
121- field: tokens.raise(),
122- border: tokens.thread(),
123- text: tokens.paper(),
124- body: tokens.paper(),
125- muted: tokens.dim(),
126- hover: tokens.hov(),
127- accent: tokens.paper(),
128- on_accent: tokens.ground(),
129- ok: tokens.hue(Hue::Mint),
130- danger: tokens.bad(),
131- alert: tokens.bad(),
132- screen: tokens.hue(Hue::Sky),
133- camera: tokens.hue(Hue::Amber),
134- dark: tokens.dark(),
135- tokens,
136- }
137-}
138-
139 const FONT: &str = "Onest";90 const FONT: &str = "Onest";
140 const MONO_FONT: &str = "Adwaita Mono";91 const MONO_FONT: &str = "Adwaita Mono";
141 92
@@ -168,35 +119,35 @@ pub fn init(cx: &mut App) {
168 }119 }
169 120
170 pub fn sync_theme(cx: &mut App) {121 pub fn sync_theme(cx: &mut App) {
171- let palette = palette(cx);122+ let t = Tokens::of(cx);
172- let font_size = cx.global::<Scale>().0.pixels();123+ let font_size = Tokens::of(cx).size.pixels();
173 let theme = Theme::global_mut(cx);124 let theme = Theme::global_mut(cx);
174 theme.font_family = FONT.into();125 theme.font_family = FONT.into();
175 theme.mono_font_family = MONO_FONT.into();126 theme.mono_font_family = MONO_FONT.into();
176 let colors = &mut theme.colors;127 let colors = &mut theme.colors;
177 128
178- colors.background = palette.panel;129+ colors.background = t.ground();
179- colors.foreground = palette.text;130+ colors.foreground = t.paper();
180- colors.popover = palette.panel;131+ colors.popover = t.ground();
181- colors.popover_foreground = palette.text;132+ colors.popover_foreground = t.paper();
182- colors.border = palette.border;133+ colors.border = t.thread();
183- colors.input = palette.border;134+ colors.input = t.thread();
184- colors.muted = palette.field;135+ colors.muted = t.raise();
185- colors.muted_foreground = palette.muted;136+ colors.muted_foreground = t.dim();
186- colors.accent = palette.hover;137+ colors.accent = t.hov();
187- colors.accent_foreground = palette.text;138+ colors.accent_foreground = t.paper();
188- colors.list_hover = palette.hover;139+ colors.list_hover = t.hov();
189- colors.secondary = palette.field;140+ colors.secondary = t.raise();
190- colors.secondary_foreground = palette.text;141+ colors.secondary_foreground = t.paper();
191- colors.primary = palette.accent;142+ colors.primary = t.paper();
192- colors.primary_hover = palette.accent;143+ colors.primary_hover = t.paper();
193- colors.primary_active = palette.accent;144+ colors.primary_active = t.paper();
194- colors.primary_foreground = palette.on_accent;145+ colors.primary_foreground = t.ground();
195- colors.ring = palette.accent;146+ colors.ring = t.paper();
196- colors.caret = palette.accent;147+ colors.caret = t.paper();
197- colors.danger = palette.danger;148+ colors.danger = t.bad();
198- colors.slider_bar = palette.text;149+ colors.slider_bar = t.paper();
199- colors.slider_thumb = palette.text;150+ colors.slider_thumb = t.paper();
200 theme.tokens = (&theme.colors).into();151 theme.tokens = (&theme.colors).into();
201 theme.radius = px(radius::SM);152 theme.radius = px(radius::SM);
202 theme.radius_lg = px(radius::LG);153 theme.radius_lg = px(radius::LG);
@@ -204,10 +155,7 @@ pub fn sync_theme(cx: &mut App) {
204 theme.focus_ring = false;155 theme.focus_ring = false;
205 }156 }
206 157
207-const FIND_KEY: &str = "ctrl-k";158+pub fn badge(t: Tokens, id: Id, name: &str, size: Pixels, font: Rems) -> Div {
208-pub const JUMP_HINT: &str = "Ctrl K";
209-
210-pub fn badge(palette: Palette, id: Id, name: &str, size: Pixels, font: Rems) -> Div {
211 let initial = name159 let initial = name
212 .chars()160 .chars()
213 .next()161 .next()
@@ -221,22 +169,22 @@ pub fn badge(palette: Palette, id: Id, name: &str, size: Pixels, font: Rems) ->
221 .flex()169 .flex()
222 .items_center()170 .items_center()
223 .justify_center()171 .justify_center()
224- .bg(palette.tinted(id))172+ .bg(t.person(id))
225- .text_color(palette.on_accent)173+ .text_color(t.ground())
226 .text_size(font)174 .text_size(font)
227 .font_weight(FontWeight::SEMIBOLD)175 .font_weight(FontWeight::SEMIBOLD)
228 .child(initial)176 .child(initial)
229 }177 }
230 178
231 pub fn avatar(179 pub fn avatar(
232- palette: Palette,180+ t: Tokens,
233 user: &User,181 user: &User,
234 size: Pixels,182 size: Pixels,
235 font: Rems,183 font: Rems,
236 avatars: &HashMap<Id, Arc<Image>>,184 avatars: &HashMap<Id, Arc<Image>>,
237 ) -> Div {185 ) -> Div {
238 let Some(image) = user.avatar_id.as_ref().and_then(|id| avatars.get(id)) else {186 let Some(image) = user.avatar_id.as_ref().and_then(|id| avatars.get(id)) else {
239- return badge(palette, user.id, &user.username, size, font).rounded_full();187+ return badge(t, user.id, &user.username, size, font).rounded_full();
240 };188 };
241 189
242 div()190 div()
@@ -331,7 +279,7 @@ pub fn community_name(community: &Community) -> &str {
331 }279 }
332 280
333 pub fn community_icon(281 pub fn community_icon(
334- palette: Palette,282+ t: Tokens,
335 community: &Community,283 community: &Community,
336 size: Pixels,284 size: Pixels,
337 font: Rems,285 font: Rems,
@@ -345,34 +293,22 @@ pub fn community_icon(
345 .rounded(px(radius::SM))293 .rounded(px(radius::SM))
346 .overflow_hidden()294 .overflow_hidden()
347 .child(img(image.clone()).size_full().rounded(px(radius::SM))),295 .child(img(image.clone()).size_full().rounded(px(radius::SM))),
348- None => {296+ None => badge(t, community.id, &community.name, size, font).rounded(px(radius::SM)),
349- badge(palette, community.id, &community.name, size, font).rounded(px(radius::SM))
350- }
351 },297 },
352- CommunityKind::Direct { peer } => avatar(palette, peer, size, font, avatars),298+ CommunityKind::Direct { peer } => avatar(t, peer, size, font, avatars),
353 CommunityKind::Notes => {299 CommunityKind::Notes => {
354- badge(palette, community.id, w().gui.notes, size, font).rounded(px(radius::SM))300+ badge(t, community.id, w().gui.notes, size, font).rounded(px(radius::SM))
355 }301 }
356 }302 }
357 }303 }
358 304
359 pub const KB: f64 = 1024.0;305 pub const KB: f64 = 1024.0;
360 pub const MB: f64 = KB * 1024.0;306 pub const MB: f64 = KB * 1024.0;
361-const GB: f64 = MB * 1024.0;
362 307
363 pub const CLOCK: &str = "%H:%M";308 pub const CLOCK: &str = "%H:%M";
364 pub const CLOCK_SECONDS: &str = "%H:%M:%S";309 pub const CLOCK_SECONDS: &str = "%H:%M:%S";
365 310
366-pub fn storage(bytes: u64) -> String {311+pub use common::error::size_text as storage;
367- let bytes = bytes as f64;
368- if bytes >= GB {
369- format!("{:.1} GB", bytes / GB)
370- } else if bytes >= MB {
371- format!("{:.1} MB", bytes / MB)
372- } else {
373- format!("{:.1} KB", bytes / KB)
374- }
375-}
376 312
377 pub fn millis_time(millis: u64, format: &str) -> String {313 pub fn millis_time(millis: u64, format: &str) -> String {
378 let Ok(timestamp) = Timestamp::from_millisecond(millis as i64) else {314 let Ok(timestamp) = Timestamp::from_millisecond(millis as i64) else {
@@ -395,13 +331,8 @@ pub fn month_named(format: &str, month: i8) -> String {
395 format.replace("%b", name)331 format.replace("%b", name)
396 }332 }
397 333
398-pub use parts::motion;334+pub fn hoverable(id: impl Into<ElementId>, element: Div, t: Tokens) -> Stateful<Div> {
399-335+ let hover = t.hov();
400-pub fn hoverable(id: impl Into<ElementId>, element: Div, palette: Palette) -> Stateful<Div> {
401- hoverable_with(id, element, palette.hover)
402-}
403-
404-pub fn hoverable_with(id: impl Into<ElementId>, element: Div, hover: Hsla) -> Stateful<Div> {
405 element336 element
406 .id(id)337 .id(id)
407 .cursor_pointer()338 .cursor_pointer()
@@ -410,10 +341,10 @@ pub fn hoverable_with(id: impl Into<ElementId>, element: Div, hover: Hsla) -> St
410 341
411 pub fn clickable(342 pub fn clickable(
412 id: impl Into<ElementId>,343 id: impl Into<ElementId>,
413- palette: Palette,344+ t: Tokens,
414 on_click: impl Fn(&mut Window, &mut App) + 'static,345 on_click: impl Fn(&mut Window, &mut App) + 'static,
415 ) -> Stateful<Div> {346 ) -> Stateful<Div> {
416- hoverable(id, div(), palette).on_click(move |_, window, cx| on_click(window, cx))347+ hoverable(id, div(), t).on_click(move |_, window, cx| on_click(window, cx))
417 }348 }
418 349
419 pub fn entity_action<T: 'static>(350 pub fn entity_action<T: 'static>(
@@ -429,15 +360,15 @@ pub struct Tip(&'static str);
429 360
430 impl Render for Tip {361 impl Render for Tip {
431 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {362 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
432- let palette = palette(cx);363+ let t = Tokens::of(cx);
433 div()364 div()
434 .px(px(space::SM))365 .px(px(space::SM))
435 .py(px(space::XS))366 .py(px(space::XS))
436 .rounded(px(radius::SM))367 .rounded(px(radius::SM))
437 .border_1()368 .border_1()
438- .border_color(palette.border)369+ .border_color(t.thread())
439- .bg(palette.field)370+ .bg(t.raise())
440- .text_color(palette.text)371+ .text_color(t.paper())
441 .font_family(FONT)372 .font_family(FONT)
442 .text_size(text(style::text::LABEL))373 .text_size(text(style::text::LABEL))
443 .child(self.0)374 .child(self.0)
@@ -479,26 +410,11 @@ impl RenderOnce for Trigger {
479 }410 }
480 }411 }
481 412
482-pub fn rank_tag(rank: Option<Rank>, palette: Palette) -> Option<Div> {413+pub fn presence_color(presence: Presence, t: Tokens) -> Hsla {
483- let tag = div()
484- .flex_shrink_0()
485- .text_size(text(style::text::CAPTION))
486- .text_color(palette.muted);
487- match rank? {
488- Rank::Member => None,
489- Rank::Builder => Some(
490- tag.text_color(palette.accent)
491- .child(Icon::new(IconName::Shield).size(px(size::ICON_SM))),
492- ),
493- rank => Some(tag.child(rank.label())),
494- }
495-}
496-
497-pub fn presence_color(presence: Presence, palette: Palette) -> Hsla {
498 match presence {414 match presence {
499- Presence::Online => palette.ok,415+ Presence::Online => t.hue(Hue::Mint),
500- Presence::Busy => palette.danger,416+ Presence::Busy => t.bad(),
501- Presence::Offline => palette.muted,417+ Presence::Offline => t.dim(),
502 }418 }
503 }419 }
504 420
@@ -506,7 +422,7 @@ pub fn presence_avatar(
506 avatar: impl IntoElement,422 avatar: impl IntoElement,
507 presence: Presence,423 presence: Presence,
508 size: Pixels,424 size: Pixels,
509- palette: Palette,425+ t: Tokens,
510 ) -> Div {426 ) -> Div {
511 let dot = if size > px(size::CHIP) {427 let dot = if size > px(size::CHIP) {
512 px(space::SM + space::XXS)428 px(space::SM + space::XXS)
@@ -522,14 +438,14 @@ pub fn presence_avatar(
522 .size(dot)438 .size(dot)
523 .rounded_full()439 .rounded_full()
524 .border_2()440 .border_2()
525- .border_color(palette.window)441+ .border_color(t.ground())
526- .bg(presence_color(presence, palette)),442+ .bg(presence_color(presence, t)),
527 )443 )
528 }444 }
529 445
530 pub fn bind_keys(cx: &mut App) {446 pub fn bind_keys(cx: &mut App) {
531 cx.bind_keys([447 cx.bind_keys([
532- KeyBinding::new(FIND_KEY, FocusFind, None),448+ KeyBinding::new(keys::bind!("k"), FocusFind, None),
533 KeyBinding::new("escape", CloseSettings, None),449 KeyBinding::new("escape", CloseSettings, None),
534 ]);450 ]);
535 composer::bind_keys(cx);451 composer::bind_keys(cx);
@@ -571,14 +487,14 @@ impl Connection {
571 }487 }
572 }488 }
573 489
574-fn connection_notice(connection: &Connection, palette: Palette) -> Option<Div> {490+fn connection_notice(connection: &Connection, t: Tokens) -> Option<Div> {
575 let (label, color, busy) = match connection {491 let (label, color, busy) = match connection {
576- Connection::Connecting => (w().gui.connecting.to_string(), palette.muted, true),492+ Connection::Connecting => (w().gui.connecting.to_string(), t.dim(), true),
577 Connection::Connected => return None,493 Connection::Connected => return None,
578 Connection::Lost { error, attempts } => {494 Connection::Lost { error, attempts } => {
579- (w().gui.reconnecting(attempts, error), palette.alert, true)495+ (w().gui.reconnecting(attempts, error), t.bad(), true)
580 }496 }
581- Connection::Failed(error) => (error.clone(), palette.alert, false),497+ Connection::Failed(error) => (error.clone(), t.bad(), false),
582 };498 };
583 Some(499 Some(
584 div()500 div()
@@ -594,6 +510,14 @@ fn connection_notice(connection: &Connection, palette: Palette) -> Option<Div> {
594 )510 )
595 }511 }
596 512
513+#[derive(Default)]
514+struct Missed {
515+ resume: bool,
516+ stale: bool,
517+ notices: Vec<Notification>,
518+ imports: Vec<(String, Result<Vec<Staged>, ReleaseProblem>)>,
519+}
520+
597 pub struct Yumush {521 pub struct Yumush {
598 user: Option<User>,522 user: Option<User>,
599 current_route: Route,523 current_route: Route,
@@ -609,9 +533,7 @@ pub struct Yumush {
609 voice: VoiceControls,533 voice: VoiceControls,
610 focus: gpui_kit::FocusHandle,534 focus: gpui_kit::FocusHandle,
611 window: Option<AnyWindowHandle>,535 window: Option<AnyWindowHandle>,
612- deferred: Vec<NetworkEvent>,536+ missed: Missed,
613- backups: Vec<BackupInfo>,
614- pending_backup_delete: Option<String>,
615 update: crate::update::Phase,537 update: crate::update::Phase,
616 desk: builder::releases::Desk,538 desk: builder::releases::Desk,
617 release_tag: Entity<InputState>,539 release_tag: Entity<InputState>,
@@ -689,7 +611,7 @@ impl Yumush {
689 .detach();611 .detach();
690 612
691 sidebar::wander(cx);613 sidebar::wander(cx);
692- let voice = VoiceControls::new(&settings.voice, window, cx);614+ let voice = VoiceControls::new(&settings.voice, cx);
693 615
694 let server = network.server();616 let server = network.server();
695 let account_filter = new_input(w().auth.find_account, window, cx);617 let account_filter = new_input(w().auth.find_account, window, cx);
@@ -716,9 +638,7 @@ impl Yumush {
716 account_filter,638 account_filter,
717 voice,639 voice,
718 window: None,640 window: None,
719- deferred: Vec::new(),641+ missed: Missed::default(),
720- backups: Vec::new(),
721- pending_backup_delete: None,
722 update: crate::update::Phase::Idle,642 update: crate::update::Phase::Idle,
723 desk: builder::releases::Desk::default(),643 desk: builder::releases::Desk::default(),
724 release_tag,644 release_tag,
@@ -741,7 +661,7 @@ impl Yumush {
741 pumped: Instant::now(),661 pumped: Instant::now(),
742 send_order: Default::default(),662 send_order: Default::default(),
743 };663 };
744- yumush.chat.camera_task = Some(camera_view::ticker(cx));664+ yumush.chat.session.camera_task = Some(camera_view::ticker(cx));
745 yumush665 yumush
746 }666 }
747 667
@@ -766,8 +686,41 @@ impl Yumush {
766 })686 })
767 .detach();687 .detach();
768 688
769- for event in std::mem::take(&mut self.deferred) {689+ self.fullscreen = false;
770- self.handle_network_event(event, Some(window), cx);690+ if let Some(viewer) = self.chat.session.viewer.as_mut() {
691+ viewer.fullscreen = false;
692+ }
693+
694+ let missed = std::mem::take(&mut self.missed);
695+ if missed.resume {
696+ self.resume(window, cx);
697+ }
698+ for notice in missed.notices {
699+ window.push_notification(notice, cx);
700+ }
701+ for (tag, result) in missed.imports {
702+ self.release_imported(&tag, result, window, cx);
703+ }
704+ if missed.stale {
705+ self.releases_changed(window, cx);
706+ self.report_created(window, cx);
707+ self.voice_changed(window, cx);
708+ }
709+ self.focus_page(window, cx);
710+ }
711+
712+ fn notify(&mut self, window: Option<&mut Window>, notice: Notification, cx: &mut App) {
713+ match window {
714+ Some(window) => window.push_notification(notice, cx),
715+ None => self.missed.notices.push(notice),
716+ }
717+ }
718+
719+ fn resume(&mut self, window: &mut Window, cx: &mut Context<Self>) {
720+ if self.user.is_some() {
721+ self.reload(window, cx);
722+ } else if let Some(active) = self.accounts.active {
723+ self.switch_account(active, window, cx);
771 }724 }
772 }725 }
773 726
@@ -789,8 +742,8 @@ impl Yumush {
789 ) {742 ) {
790 self.accounts.sign_in(&user, token);743 self.accounts.sign_in(&user, token);
791 self.request_user_avatar(&user, cx);744 self.request_user_avatar(&user, cx);
792- self.chat.muted = marks::load(Mark::Mute, user.id);745+ self.chat.session.muted = marks::load(Mark::Mute, user.id);
793- self.chat.pinned = marks::load(Mark::Pin, user.id);746+ self.chat.session.pinned = marks::load(Mark::Pin, user.id);
794 style::remember(&[&user]);747 style::remember(&[&user]);
795 style::remember_me(user.id);748 style::remember_me(user.id);
796 self.user = Some(user);749 self.user = Some(user);
@@ -860,8 +813,8 @@ impl Yumush {
860 return;813 return;
861 };814 };
862 let ids = match mark {815 let ids = match mark {
863- Mark::Mute => &mut self.chat.muted,816+ Mark::Mute => &mut self.chat.session.muted,
864- Mark::Pin => &mut self.chat.pinned,817+ Mark::Pin => &mut self.chat.session.pinned,
865 };818 };
866 if !ids.remove(&community_id) {819 if !ids.remove(&community_id) {
867 ids.insert(community_id);820 ids.insert(community_id);
@@ -871,7 +824,7 @@ impl Yumush {
871 }824 }
872 825
873 pub(super) fn armed(&self, armed: chat::Armed) -> bool {826 pub(super) fn armed(&self, armed: chat::Armed) -> bool {
874- self.chat.armed == Some(armed)827+ self.chat.session.armed.as_ref() == Some(&armed)
875 }828 }
876 829
877 pub(super) fn armed_label(&self, armed: chat::Armed, label: &'static str) -> &'static str {830 pub(super) fn armed_label(&self, armed: chat::Armed, label: &'static str) -> &'static str {
@@ -883,17 +836,17 @@ impl Yumush {
883 }836 }
884 837
885 pub(super) fn arm(&mut self, armed: chat::Armed, cx: &mut Context<Self>) -> bool {838 pub(super) fn arm(&mut self, armed: chat::Armed, cx: &mut Context<Self>) -> bool {
886- if self.armed(armed) {839+ if self.armed(armed.clone()) {
887- self.chat.armed = None;840+ self.chat.session.armed = None;
888 return true;841 return true;
889 }842 }
890- self.chat.armed = Some(armed);843+ self.chat.session.armed = Some(armed);
891 cx.notify();844 cx.notify();
892 false845 false
893 }846 }
894 847
895 pub(super) fn disarm(&mut self, cx: &mut Context<Self>) {848 pub(super) fn disarm(&mut self, cx: &mut Context<Self>) {
896- if self.chat.armed.take().is_some() {849+ if self.chat.session.armed.take().is_some() {
897 cx.notify();850 cx.notify();
898 }851 }
899 }852 }
@@ -917,20 +870,23 @@ impl Yumush {
917 fn change_page(&mut self, route: Route, window: &mut Window, cx: &mut Context<Self>) {870 fn change_page(&mut self, route: Route, window: &mut Window, cx: &mut Context<Self>) {
918 self.current_route = route;871 self.current_route = route;
919 cx.notify();872 cx.notify();
873+ self.focus_page(window, cx);
874+ }
920 875
921- match route {876+ fn focus_page(&self, window: &mut Window, cx: &mut Context<Self>) {
877+ match self.current_route {
922 Route::Login | Route::Register => self.auth.focus(window, cx),878 Route::Login | Route::Register => self.auth.focus(window, cx),
923 Route::Chat => self.chat.focus(window, cx),879 Route::Chat => self.chat.focus(window, cx),
924 }880 }
925 }881 }
926 882
927 fn show_view(&mut self, view: View, window: &mut Window, cx: &mut Context<Self>) {883 fn show_view(&mut self, view: View, window: &mut Window, cx: &mut Context<Self>) {
928- self.chat.section = None;884+ self.chat.session.section = None;
929- if self.chat.view == View::Settings && view != View::Settings {885+ if self.chat.session.view == View::Settings && view != View::Settings {
930 self.leave_settings();886 self.leave_settings();
931 }887 }
932 if view == View::Settings {888 if view == View::Settings {
933- self.enter_settings(window, cx);889+ self.enter_settings(cx);
934 let (username, status) = self890 let (username, status) = self
935 .user891 .user
936 .as_ref()892 .as_ref()
@@ -958,8 +914,8 @@ impl Yumush {
958 self.load_bans(window, cx);914 self.load_bans(window, cx);
959 }915 }
960 916
961- self.chat.view = view;917+ self.chat.session.view = view;
962- self.chat.armed = None;918+ self.chat.session.armed = None;
963 if view == View::Chat {919 if view == View::Chat {
964 self.chat.focus(window, cx);920 self.chat.focus(window, cx);
965 }921 }
@@ -975,11 +931,11 @@ impl Yumush {
975 community: &Community,931 community: &Community,
976 size: Pixels,932 size: Pixels,
977 font: Rems,933 font: Rems,
978- palette: Palette,934+ t: Tokens,
979 ) -> Div {935 ) -> Div {
980- let icon = community_icon(palette, community, size, font, &self.chat.avatars);936+ let icon = community_icon(t, community, size, font, &self.chat.session.avatars);
981 match community.kind.peer() {937 match community.kind.peer() {
982- Some(peer) => presence_avatar(icon, self.presence_of(peer.id), size, palette),938+ Some(peer) => presence_avatar(icon, self.presence_of(peer.id), size, t),
983 None => icon,939 None => icon,
984 }940 }
985 }941 }
@@ -989,6 +945,7 @@ impl Yumush {
989 return Presence::Offline;945 return Presence::Offline;
990 }946 }
991 self.chat947 self.chat
948+ .session
992 .presences949 .presences
993 .get(&user_id)950 .get(&user_id)
994 .copied()951 .copied()
@@ -1000,19 +957,19 @@ impl Yumush {
1000 }957 }
1001 958
1002 pub fn request_avatar(&mut self, avatar_id: Id, cx: &mut Context<Self>) {959 pub fn request_avatar(&mut self, avatar_id: Id, cx: &mut Context<Self>) {
1003- if self.chat.avatars.contains_key(&avatar_id)960+ if self.chat.session.avatars.contains_key(&avatar_id)
1004- || self.chat.avatar_requests.contains(&avatar_id)961+ || self.chat.session.avatar_requests.contains(&avatar_id)
1005 {962 {
1006 return;963 return;
1007 }964 }
1008- self.chat.avatar_requests.insert(avatar_id);965+ self.chat.session.avatar_requests.insert(avatar_id);
1009 966
1010 let network = self.network.clone();967 let network = self.network.clone();
1011 968
1012 cx.spawn(async move |this, cx| {969 cx.spawn(async move |this, cx| {
1013 let result = network.call(GetAvatar { avatar_id }).await;970 let result = network.call(GetAvatar { avatar_id }).await;
1014 let _ = this.update(cx, |yumush, cx| {971 let _ = this.update(cx, |yumush, cx| {
1015- yumush.chat.avatar_requests.remove(&avatar_id);972+ yumush.chat.session.avatar_requests.remove(&avatar_id);
1016 if let Ok(bytes) = result {973 if let Ok(bytes) = result {
1017 style::picture(avatar_id, &bytes);974 style::picture(avatar_id, &bytes);
1018 if let Some(me) = yumush975 if let Some(me) = yumush
@@ -1022,7 +979,7 @@ impl Yumush {
1022 {979 {
1023 yumush.accounts.set_picture(me.id, Some(bytes.clone()));980 yumush.accounts.set_picture(me.id, Some(bytes.clone()));
1024 }981 }
1025- yumush.chat.avatars.insert(982+ yumush.chat.session.avatars.insert(
1026 avatar_id,983 avatar_id,
1027 Arc::new(Image::from_bytes(ImageFormat::Jpeg, bytes)),984 Arc::new(Image::from_bytes(ImageFormat::Jpeg, bytes)),
1028 );985 );
@@ -1054,8 +1011,8 @@ impl Yumush {
1054 if self.is_me(user.id) {1011 if self.is_me(user.id) {
1055 self.user = Some(user.clone());1012 self.user = Some(user.clone());
1056 self.accounts.rename(user);1013 self.accounts.rename(user);
1057- if !self.is_builder() && self.chat.view == View::Builder {1014+ if !self.is_builder() && self.chat.session.view == View::Builder {
1058- self.chat.view = View::Chat;1015+ self.chat.session.view = View::Chat;
1059 }1016 }
1060 }1017 }
1061 self.request_user_avatar(user, cx);1018 self.request_user_avatar(user, cx);
@@ -1073,7 +1030,7 @@ impl Yumush {
1073 self.close_viewer(cx)1030 self.close_viewer(cx)
1074 }1031 }
1075 Event::StatsWanted(true) => self.start_stats_push(cx),1032 Event::StatsWanted(true) => self.start_stats_push(cx),
1076- Event::StatsWanted(false) => self.chat.stats_task = None,1033+ Event::StatsWanted(false) => self.chat.session.stats_task = None,
1077 Event::Typing { .. } => {1034 Event::Typing { .. } => {
1078 cx.spawn(async move |this, cx| {1035 cx.spawn(async move |this, cx| {
1079 cx.background_executor().timer(chat::TYPING_TTL).await;1036 cx.background_executor().timer(chat::TYPING_TTL).await;
@@ -1107,14 +1064,15 @@ impl Yumush {
1107 }1064 }
1108 1065
1109 fn read_selected(&mut self, cx: &mut Context<Self>) {1066 fn read_selected(&mut self, cx: &mut Context<Self>) {
1110- let Some(community_id) = self.chat.selected_community_id else {1067+ let Some(community_id) = self.chat.session.selected_community_id else {
1111 return;1068 return;
1112 };1069 };
1113- let Some(message_id) = self.chat.messages.last().map(|message| message.id) else {1070+ let Some(message_id) = self.chat.session.messages.last().map(|message| message.id) else {
1114 return;1071 return;
1115 };1072 };
1116 if self1073 if self
1117 .chat1074 .chat
1075+ .session
1118 .unread1076 .unread
1119 .get(&community_id)1077 .get(&community_id)
1120 .is_some_and(|unread| unread.messages > 0)1078 .is_some_and(|unread| unread.messages > 0)
@@ -1136,6 +1094,7 @@ impl Yumush {
1136 }1094 }
1137 let unread = self1095 let unread = self
1138 .chat1096 .chat
1097+ .session
1139 .unread1098 .unread
1140 .entry(message.community_id)1099 .entry(message.community_id)
1141 .or_insert_with(|| Unread {1100 .or_insert_with(|| Unread {
@@ -1156,7 +1115,7 @@ impl Yumush {
1156 1115
1157 message.user_id != me.id1116 message.user_id != me.id
1158 && message.call.is_none()1117 && message.call.is_none()
1159- && !self.chat.muted.contains(&message.community_id)1118+ && !self.chat.session.muted.contains(&message.community_id)
1160 && self.presence_of(me.id) == Presence::Online1119 && self.presence_of(me.id) == Presence::Online
1161 && !viewing1120 && !viewing
1162 }1121 }
@@ -1188,13 +1147,17 @@ impl Yumush {
1188 self.user.as_ref().is_some_and(|me| me.id == user_id)1147 self.user.as_ref().is_some_and(|me| me.id == user_id)
1189 }1148 }
1190 1149
1191- fn end_session(&mut self, window: &mut Window, cx: &mut Context<Self>) {1150+ fn clear_session(&mut self, cx: &mut Context<Self>) {
1192 self.end_voice(cx);1151 self.end_voice(cx);
1193 self.leave_settings();1152 self.leave_settings();
1194 self.stop_playing(cx);1153 self.stop_playing(cx);
1195 self.user = None;1154 self.user = None;
1196 self.desk = builder::releases::Desk::default();1155 self.desk = builder::releases::Desk::default();
1197 self.chat.reset();1156 self.chat.reset();
1157+ }
1158+
1159+ fn end_session(&mut self, window: &mut Window, cx: &mut Context<Self>) {
1160+ self.clear_session(cx);
1198 self.change_page(Route::Login, window, cx);1161 self.change_page(Route::Login, window, cx);
1199 }1162 }
1200 1163
@@ -1229,10 +1192,10 @@ impl Yumush {
1229 cx.notify();1192 cx.notify();
1230 }1193 }
1231 1194
1232- fn load_server_settings(&self, window: &mut Window, cx: &mut Context<Self>) {1195+ fn load_server_settings(&self, cx: &mut Context<Self>) {
1233 let network = self.network.clone();1196 let network = self.network.clone();
1234 1197
1235- cx.spawn_in(window, async move |this, cx| {1198+ cx.spawn(async move |this, cx| {
1236 let Ok(settings) = network.call(GetSettings).await else {1199 let Ok(settings) = network.call(GetSettings).await else {
1237 return;1200 return;
1238 };1201 };
@@ -1257,19 +1220,14 @@ impl Yumush {
1257 self.before_pushed(pushed, active, cx);1220 self.before_pushed(pushed, active, cx);
1258 }1221 }
1259 1222
1260- let Some(window) = window else {
1261- self.handle_hidden(event, cx);
1262- return;
1263- };
1264-
1265 match event {1223 match event {
1266 NetworkEvent::Connected => {1224 NetworkEvent::Connected => {
1267 self.connection = Connection::Connected;1225 self.connection = Connection::Connected;
1268- self.load_server_settings(window, cx);1226+ self.desk.connected();
1269- if self.user.is_some() {1227+ self.load_server_settings(cx);
1270- self.reload(window, cx);1228+ match window {
1271- } else if let Some(active) = self.accounts.active {1229+ Some(window) => self.resume(window, cx),
1272- self.switch_account(active, window, cx);1230+ None => self.missed.resume = true,
1273 }1231 }
1274 }1232 }
1275 NetworkEvent::Disconnected(error) => self.connection.lost(&error),1233 NetworkEvent::Disconnected(error) => self.connection.lost(&error),
@@ -1279,7 +1237,11 @@ impl Yumush {
1279 if let Some(user) = &self.user {1237 if let Some(user) = &self.user {
1280 self.accounts.forget(user.id);1238 self.accounts.forget(user.id);
1281 }1239 }
1282- self.end_session(window, cx);1240+ self.clear_session(cx);
1241+ match window {
1242+ Some(window) => self.change_page(Route::Login, window, cx),
1243+ None => self.current_route = Route::Login,
1244+ }
1283 }1245 }
1284 NetworkEvent::Pushed(event) => match *event {1246 NetworkEvent::Pushed(event) => match *event {
1285 Event::MemberLeft {1247 Event::MemberLeft {
@@ -1307,15 +1269,24 @@ impl Yumush {
1307 }1269 }
1308 (Sanction::Kick, None) => w().gui.kicked(community_name),1270 (Sanction::Kick, None) => w().gui.kicked(community_name),
1309 };1271 };
1310- window.push_notification(Notification::warning(text), cx);1272+ self.notify(window, Notification::warning(text), cx);
1311 }1273 }
1312 Event::CommunityDeleted { community_id } => {1274 Event::CommunityDeleted { community_id } => {
1313 self.leave_voice_in(community_id, cx);1275 self.leave_voice_in(community_id, cx);
1314 self.apply_pushed(Event::CommunityDeleted { community_id }, cx);1276 self.apply_pushed(Event::CommunityDeleted { community_id }, cx);
1315 }1277 }
1316- Event::ReportCreated => self.report_created(window, cx),1278+ Event::ReportCreated => match window {
1317- Event::Release => self.releases_changed(window, cx),1279+ Some(window) => self.report_created(window, cx),
1318- Event::Imported { result, .. } => self.release_imported(result, window, cx),1280+ None => self.missed.stale = true,
1281+ },
1282+ Event::Release => match window {
1283+ Some(window) => self.releases_changed(window, cx),
1284+ None => self.missed.stale = true,
1285+ },
1286+ Event::Imported { tag, result } => match window {
1287+ Some(window) => self.release_imported(&tag, result, window, cx),
1288+ None => self.missed.imports.push((tag, result)),
1289+ },
1319 Event::SettingsUpdated(settings) => self.server = Some(settings),1290 Event::SettingsUpdated(settings) => self.server = Some(settings),
1320 event => {1291 event => {
1321 let voice = matches!(1292 let voice = matches!(
@@ -1326,7 +1297,10 @@ impl Yumush {
1326 );1297 );
1327 self.apply_pushed(event, cx);1298 self.apply_pushed(event, cx);
1328 if voice {1299 if voice {
1329- self.voice_changed(window, cx);1300+ match window {
1301+ Some(window) => self.voice_changed(window, cx),
1302+ None => self.missed.stale = true,
1303+ }
1330 }1304 }
1331 }1305 }
1332 },1306 },
@@ -1340,11 +1314,12 @@ impl Yumush {
1340 match event {1314 match event {
1341 Event::MessageCreated(message) => {1315 Event::MessageCreated(message) => {
1342 if self.should_notify(message, active) {1316 if self.should_notify(message, active) {
1343- self.network.play_notification(&self.settings.voice);1317+ voice::play_sound(Sound::Notification, &self.settings.voice);
1344 }1318 }
1345 self.count_message(message, active, cx);1319 self.count_message(message, active, cx);
1346 if !self1320 if !self
1347 .chat1321 .chat
1322+ .session
1348 .communities1323 .communities
1349 .iter()1324 .iter()
1350 .any(|community| community.id == message.community_id)1325 .any(|community| community.id == message.community_id)
@@ -1361,7 +1336,7 @@ impl Yumush {
1361 community_id,1336 community_id,
1362 user_id,1337 user_id,
1363 } if self.starts_call(*community_id, *user_id) => {1338 } if self.starts_call(*community_id, *user_id) => {
1364- self.chat.ringing.insert(*community_id);1339+ self.chat.session.ringing.insert(*community_id);
1365 }1340 }
1366 Event::VoiceLeft {1341 Event::VoiceLeft {
1367 community_id,1342 community_id,
@@ -1372,30 +1347,6 @@ impl Yumush {
1372 _ => {}1347 _ => {}
1373 }1348 }
1374 }1349 }
1375-
1376- fn handle_hidden(&mut self, event: NetworkEvent, cx: &mut Context<Self>) {
1377- match event {
1378- NetworkEvent::Connected => {
1379- self.connection = Connection::Connected;
1380- self.deferred.push(NetworkEvent::Connected);
1381- }
1382- NetworkEvent::Disconnected(error) => self.connection.lost(&error),
1383- NetworkEvent::VoiceRejoined => self.refresh_voice(cx),
1384- NetworkEvent::VoiceEnded => self.chat.set_voice_off(),
1385- NetworkEvent::SessionLost => self.deferred.push(NetworkEvent::SessionLost),
1386- NetworkEvent::Pushed(event) => match *event {
1387- Event::MemberLeft { .. }
1388- | Event::Removed { .. }
1389- | Event::CommunityDeleted { .. }
1390- | Event::ReportCreated => self.deferred.push(NetworkEvent::Pushed(event)),
1391- Event::SettingsUpdated(settings) => self.server = Some(settings),
1392- event => self.apply_pushed(event, cx),
1393- },
1394- }
1395-
1396- self.update_ringing(cx);
1397- cx.notify();
1398- }
1399 }1350 }
1400 1351
1401 pub fn input_dialog(1352 pub fn input_dialog(
@@ -1421,7 +1372,7 @@ pub fn input_dialog(
1421 let entity = cx.entity();1372 let entity = cx.entity();
1422 let dialog_input = input.clone();1373 let dialog_input = input.clone();
1423 window.open_dialog(cx, move |dialog, _, cx| {1374 window.open_dialog(cx, move |dialog, _, cx| {
1424- let palette = palette(cx);1375+ let t = Tokens::of(cx);
1425 let entity = entity.clone();1376 let entity = entity.clone();
1426 let on_submit = on_submit.clone();1377 let on_submit = on_submit.clone();
1427 let button_input = dialog_input.clone();1378 let button_input = dialog_input.clone();
@@ -1436,7 +1387,7 @@ pub fn input_dialog(
1436 .items_center()1387 .items_center()
1437 .gap(px(space::MD))1388 .gap(px(space::MD))
1438 .child(1389 .child(
1439- widget::frame(palette, Input::new(&dialog_input).token(glyph::token))1390+ widget::frame(t, Input::new(&dialog_input).token(glyph::token))
1440 .flex_1()1391 .flex_1()
1441 .min_w_0(),1392 .min_w_0(),
1442 )1393 )
@@ -1444,7 +1395,7 @@ pub fn input_dialog(
1444 "input_dialog_submit",1395 "input_dialog_submit",
1445 action,1396 action,
1446 parts::Press::Primary,1397 parts::Press::Primary,
1447- palette.tokens,1398+ t,
1448 move |window, cx| {1399 move |window, cx| {
1449 let text = button_input.read(cx).text().to_string();1400 let text = button_input.read(cx).text().to_string();
1450 entity.update(cx, |this, cx| on_submit(this, text, window, cx));1401 entity.update(cx, |this, cx| on_submit(this, text, window, cx));
@@ -1492,6 +1443,7 @@ impl Render for Yumush {
1492 crate::usage::tick(crate::usage::Group::Gui);1443 crate::usage::tick(crate::usage::Group::Gui);
1493 let fullscreen = self1444 let fullscreen = self
1494 .chat1445 .chat
1446+ .session
1495 .viewer1447 .viewer
1496 .as_ref()1448 .as_ref()
1497 .is_some_and(|viewer| viewer.fullscreen);1449 .is_some_and(|viewer| viewer.fullscreen);
@@ -1504,16 +1456,16 @@ impl Render for Yumush {
1504 }1456 }
1505 self.hide_idle_cursor(window, cx);1457 self.hide_idle_cursor(window, cx);
1506 self.schedule_pump(window, cx);1458 self.schedule_pump(window, cx);
1507- let palette = palette(cx);1459+ let t = Tokens::of(cx);
1508 let route = self.current_route;1460 let route = self.current_route;
1509 let required = self.update.required();1461 let required = self.update.required();
1510 let page = match route {1462 let page = match route {
1511- _ if required => self.update_required(palette).into_any_element(),1463+ _ if required => self.update_required(t).into_any_element(),
1512 Route::Login | Route::Register => self.auth_page(route, cx).into_any_element(),1464 Route::Login | Route::Register => self.auth_page(route, cx).into_any_element(),
1513 Route::Chat => self.chat_page(cx).into_any_element(),1465 Route::Chat => self.chat_page(cx).into_any_element(),
1514 };1466 };
1515 let banner = (route == Route::Chat && !required)1467 let banner = (route == Route::Chat && !required)
1516- .then(|| connection_notice(&self.connection, palette))1468+ .then(|| connection_notice(&self.connection, t))
1517 .flatten();1469 .flatten();
1518 1470
1519 div()1471 div()
@@ -1521,8 +1473,8 @@ impl Render for Yumush {
1521 .flex()1473 .flex()
1522 .flex_col()1474 .flex_col()
1523 .size_full()1475 .size_full()
1524- .bg(palette.window)1476+ .bg(t.ground())
1525- .text_color(palette.text)1477+ .text_color(t.paper())
1526 .text_size(text(style::text::UI))1478 .text_size(text(style::text::UI))
1527 .track_focus(&self.focus)1479 .track_focus(&self.focus)
1528 .on_action(cx.listener(|this, _: &FocusFind, window, cx| this.open_jump(window, cx)))1480 .on_action(cx.listener(|this, _: &FocusFind, window, cx| this.open_jump(window, cx)))
@@ -1530,38 +1482,46 @@ impl Render for Yumush {
1530 if this.zoom.is_some() {1482 if this.zoom.is_some() {
1531 this.zoom = None;1483 this.zoom = None;
1532 cx.notify();1484 cx.notify();
1533- } else if this.chat.friends_open {1485+ } else if this.chat.session.friends_open {
1534 this.close_friends(window, cx);1486 this.close_friends(window, cx);
1535 } else if this.chat.goto.open {1487 } else if this.chat.goto.open {
1536 this.close_jump(window, cx);1488 this.close_jump(window, cx);
1537- } else if this.fullscreen {1489+ } else if this
1490+ .chat
1491+ .session
1492+ .viewer
1493+ .as_ref()
1494+ .is_some_and(|v| v.fullscreen)
1495+ {
1538 this.toggle_fullscreen(cx);1496 this.toggle_fullscreen(cx);
1539- } else if this.chat.view != View::Chat {1497+ } else if this.chat.session.view != View::Chat {
1540 this.show_view(View::Chat, window, cx);1498 this.show_view(View::Chat, window, cx);
1541 } else {1499 } else {
1542 this.cancel_composer(window, cx);1500 this.cancel_composer(window, cx);
1543 }1501 }
1544 }))1502 }))
1545- .on_key_down(cx.listener(|this, event: &KeyDownEvent, _, cx| {1503+ .on_key_down(cx.listener(|this, event: &KeyDownEvent, window, cx| {
1546- this.voice_key_down(event, cx);1504+ this.voice_key_down(event, window, cx);
1547 }))1505 }))
1548 .on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| {1506 .on_key_up(cx.listener(|this, event: &KeyUpEvent, _, cx| {
1549 this.voice_key_up(event, cx);1507 this.voice_key_up(event, cx);
1550 }))1508 }))
1551- .on_modifiers_changed(cx.listener(|this, event: &ModifiersChangedEvent, _, cx| {1509+ .on_modifiers_changed(
1552- this.voice_modifiers(event, cx);1510+ cx.listener(|this, event: &ModifiersChangedEvent, window, cx| {
1553- }))1511+ this.voice_modifiers(event, window, cx);
1512+ }),
1513+ )
1554 .children(banner)1514 .children(banner)
1555 .child(div().flex_1().min_h_0().child(page))1515 .child(div().flex_1().min_h_0().child(page))
1556 .children(1516 .children(
1557 (route == Route::Chat && !required)1517 (route == Route::Chat && !required)
1558- .then(|| self.jump_box(palette, cx))1518+ .then(|| self.jump_box(t, cx))
1559 .flatten(),1519 .flatten(),
1560 )1520 )
1561 .children(1521 .children(
1562 self.zoom1522 self.zoom
1563 .as_ref()1523 .as_ref()
1564- .map(|zoom| zoom_view(zoom, &cx.entity(), palette.tokens)),1524+ .map(|zoom| zoom_view(zoom, &cx.entity(), t)),
1565 )1525 )
1566 }1526 }
1567 }1527 }
crates/client/src/gui/account_list.rsmodified+17 -16
@@ -5,45 +5,46 @@ use gpui_kit::{
5 };5 };
6 6
7 use super::{7 use super::{
8- Palette, Tooltip as _, Yumush, badge, clickable, hoverable, parts,8+ Tooltip as _, Yumush, badge, clickable, hoverable, parts,
9 sidebar::input_box,9 sidebar::input_box,
10- style::{radius, size, space, text},10+ style::{Tokens, radius, size, space, text},
11 text,11 text,
12 };12 };
13 use crate::accounts::Account;13 use crate::accounts::Account;
14 use crate::lang::w;14 use crate::lang::w;
15 15
16-const SHOWN: f32 = 3.;16+const SHOWN: usize = 3;
17 17
18 pub(super) fn account_list(18 pub(super) fn account_list(
19 yumush: &Yumush,19 yumush: &Yumush,
20 entity: &Entity<Yumush>,20 entity: &Entity<Yumush>,
21- skip_active: bool,
22 popover: Option<Entity<PopoverState>>,21 popover: Option<Entity<PopoverState>>,
23- palette: Palette,22+ t: Tokens,
24 cx: &App,23 cx: &App,
25 ) -> Div {24 ) -> Div {
26 let mut accounts = yumush.accounts.recent();25 let mut accounts = yumush.accounts.recent();
27- if skip_active {26+ if popover.is_some() {
28 accounts.retain(|account| Some(account.user_id) != yumush.accounts.active);27 accounts.retain(|account| Some(account.user_id) != yumush.accounts.active);
29 }28 }
30- let filtered = accounts.len() > SHOWN as usize;29+ let searchable = accounts.len() > SHOWN;
31 let query = super::widget::search_text(&yumush.account_filter, cx);30 let query = super::widget::search_text(&yumush.account_filter, cx);
32 let rows: Vec<AnyElement> = accounts31 let rows: Vec<AnyElement> = accounts
33 .into_iter()32 .into_iter()
34- .filter(|account| !filtered || account.username.to_lowercase().contains(query.as_str()))33+ .filter(|account| !searchable || account.username.to_lowercase().contains(query.as_str()))
35- .map(|account| row(account, entity, popover.clone(), palette))34+ .map(|account| row(account, entity, popover.clone(), t))
36 .collect();35 .collect();
37 36
38 div()37 div()
39 .flex()38 .flex()
40 .flex_col()39 .flex_col()
41 .gap(px(space::XXS))40 .gap(px(space::XXS))
42- .children(filtered.then(|| input_box(&yumush.account_filter, palette).px(px(space::SM))))41+ .children(searchable.then(|| input_box(&yumush.account_filter, t).px(px(space::SM))))
43 .child(42 .child(
44 div()43 div()
45 .id("account_rows")44 .id("account_rows")
46- .max_h(px(SHOWN * size::CONTROL + (SHOWN - 1.) * space::XXS))45+ .max_h(px(
46+ SHOWN as f32 * size::CONTROL + (SHOWN - 1) as f32 * space::XXS
47+ ))
47 .overflow_y_scroll()48 .overflow_y_scroll()
48 .flex()49 .flex()
49 .flex_col()50 .flex_col()
@@ -56,7 +57,7 @@ fn row(
56 account: &Account,57 account: &Account,
57 entity: &Entity<Yumush>,58 entity: &Entity<Yumush>,
58 popover: Option<Entity<PopoverState>>,59 popover: Option<Entity<PopoverState>>,
59- palette: Palette,60+ t: Tokens,
60 ) -> AnyElement {61 ) -> AnyElement {
61 let user_id = account.user_id;62 let user_id = account.user_id;
62 let switch_entity = entity.clone();63 let switch_entity = entity.clone();
@@ -80,7 +81,7 @@ fn row(
80 .overflow_hidden()81 .overflow_hidden()
81 .child(gpui_kit::img(picture.clone()).size_full()),82 .child(gpui_kit::img(picture.clone()).size_full()),
82 None => badge(83 None => badge(
83- palette,84+ t,
84 user_id,85 user_id,
85 &account.username,86 &account.username,
86 px(size::CHIP),87 px(size::CHIP),
@@ -90,7 +91,7 @@ fn row(
90 })91 })
91 .child(div().flex_1().truncate().child(account.username.clone()))92 .child(div().flex_1().truncate().child(account.username.clone()))
92 .child(93 .child(
93- clickable(format!("forget_{user_id}"), palette, move |_, cx| {94+ clickable(format!("forget_{user_id}"), t, move |_, cx| {
94 cx.stop_propagation();95 cx.stop_propagation();
95 forget_entity.update(cx, |yumush, cx| yumush.forget_account(user_id, cx));96 forget_entity.update(cx, |yumush, cx| yumush.forget_account(user_id, cx));
96 })97 })
@@ -100,10 +101,10 @@ fn row(
100 .items_center()101 .items_center()
101 .justify_center()102 .justify_center()
102 .rounded(px(radius::SM))103 .rounded(px(radius::SM))
103- .text_color(palette.muted)104+ .text_color(t.dim())
104 .child(parts::small_icon(IconName::X)),105 .child(parts::small_icon(IconName::X)),
105 ),106 ),
106- palette,107+ t,
107 )108 )
108 .on_click(move |_, window, cx| {109 .on_click(move |_, window, cx| {
109 if let Some(popover) = &popover {110 if let Some(popover) = &popover {
crates/client/src/gui/auth.rsmodified+45 -52
@@ -8,12 +8,11 @@ use gpui_kit::{
8 };8 };
9 9
10 use super::{10 use super::{
11- Palette, Route, Yumush,11+ Route, Yumush,
12 account_list::account_list,12 account_list::account_list,
13- clickable, connection_notice, new_input, notify_error, palette, parts,13+ clickable, connection_notice, new_input, notify_error, parts,
14 settings_page::{segment, segment_track},14 settings_page::{segment, segment_track},
15- style::{radius, size, space, text},15+ style::{Tokens, radius, size, space, text},
16- text,
17 widget::{field, frame},16 widget::{field, frame},
18 };17 };
19 use crate::lang::w;18 use crate::lang::w;
@@ -94,14 +93,13 @@ fn submit(this: &mut Yumush, window: &mut Window, cx: &mut Context<Yumush>) {
94 let network = this.network.clone();93 let network = this.network.clone();
95 94
96 cx.spawn_in(window, async move |this, cx| {95 cx.spawn_in(window, async move |this, cx| {
97- let result = match route {96+ let result = if route == Route::Register {
98- Route::Register => {97+ let invite = (!invite.is_empty()).then_some(invite);
99- let invite = (!invite.is_empty()).then_some(invite);98+ network
100- network99+ .register(&username, &password, invite.as_deref())
101- .register(&username, &password, invite.as_deref())100+ .await
102- .await101+ } else {
103- }102+ network.login(&username, &password).await
104- Route::Login | Route::Chat => network.login(&username, &password).await,
105 };103 };
106 104
107 match result {105 match result {
@@ -124,10 +122,10 @@ fn server_toggle(
124 entity: &Entity<Yumush>,122 entity: &Entity<Yumush>,
125 address: &str,123 address: &str,
126 open: bool,124 open: bool,
127- palette: Palette,125+ t: Tokens,
128 ) -> impl IntoElement {126 ) -> impl IntoElement {
129 let entity = entity.clone();127 let entity = entity.clone();
130- clickable("server_toggle", palette, move |_, cx| {128+ clickable("server_toggle", t, move |_, cx| {
131 entity.update(cx, |yumush, cx| {129 entity.update(cx, |yumush, cx| {
132 yumush.auth.server_open = !yumush.auth.server_open;130 yumush.auth.server_open = !yumush.auth.server_open;
133 cx.notify();131 cx.notify();
@@ -140,8 +138,8 @@ fn server_toggle(
140 .flex()138 .flex()
141 .items_center()139 .items_center()
142 .gap(px(space::XS))140 .gap(px(space::XS))
143- .text_size(text(text::CAPTION))141+ .text_size(t.text(text::CAPTION))
144- .text_color(palette.muted)142+ .text_color(t.dim())
145 .child(host(address).to_string())143 .child(host(address).to_string())
146 .child(144 .child(
147 super::parts::small_icon(IconName::ChevronRight).with_animation(145 super::parts::small_icon(IconName::ChevronRight).with_animation(
@@ -164,16 +162,17 @@ fn host(address: &str) -> &str {
164 }162 }
165 }163 }
166 164
167-fn password_field(palette: Palette, input: &Entity<InputState>) -> Div {165+fn password_field(t: Tokens, input: &Entity<InputState>) -> Div {
168- frame(palette, Input::new(input).mask_toggle())166+ frame(t, Input::new(input).mask_toggle())
169 }167 }
170 168
171 impl Yumush {169 impl Yumush {
172 pub(super) fn auth_page(&self, route: Route, cx: &mut Context<Self>) -> impl IntoElement {170 pub(super) fn auth_page(&self, route: Route, cx: &mut Context<Self>) -> impl IntoElement {
173- let palette = palette(cx);171+ let t = Tokens::of(cx);
174- let action_label = match route {172+ let action_label = if route == Route::Register {
175- Route::Register => w().auth.register,173+ w().auth.register
176- Route::Login | Route::Chat => w().auth.log_in,174+ } else {
175+ w().auth.log_in
177 };176 };
178 177
179 let entity = cx.entity();178 let entity = cx.entity();
@@ -182,7 +181,7 @@ impl Yumush {
182 "auth_button",181 "auth_button",
183 action_label,182 action_label,
184 parts::Press::Primary,183 parts::Press::Primary,
185- palette.tokens,184+ t,
186 move |window, cx| {185 move |window, cx| {
187 submit_entity.update(cx, |this, cx| submit(this, window, cx));186 submit_entity.update(cx, |this, cx| submit(this, window, cx));
188 },187 },
@@ -194,17 +193,11 @@ impl Yumush {
194 let maintenance = server.is_some_and(|settings| settings.maintenance);193 let maintenance = server.is_some_and(|settings| settings.maintenance);
195 let title = server.map_or_else(|| "yumush".to_string(), |settings| settings.name.clone());194 let title = server.map_or_else(|| "yumush".to_string(), |settings| settings.name.clone());
196 195
197- let tabs = segment_track(palette)196+ let tabs = segment_track(t)
198- .child(tab(palette, &entity, Route::Login, w().auth.log_in, route))197+ .child(tab(t, &entity, Route::Login, w().auth.log_in, route))
199- .child(tab(198+ .child(tab(t, &entity, Route::Register, w().auth.register, route));
200- palette,
201- &entity,
202- Route::Register,
203- w().auth.register,
204- route,
205- ));
206 let invite = (route == Route::Register && !registration_open)199 let invite = (route == Route::Register && !registration_open)
207- .then(|| field(palette, &self.auth.invite_input));200+ .then(|| field(t, &self.auth.invite_input));
208 201
209 div()202 div()
210 .flex()203 .flex()
@@ -221,28 +214,28 @@ impl Yumush {
221 .gap(px(space::MD))214 .gap(px(space::MD))
222 .child(215 .child(
223 div()216 div()
224- .text_size(text(text::BODY))217+ .text_size(t.text(text::BODY))
225 .font_weight(FontWeight::SEMIBOLD)218 .font_weight(FontWeight::SEMIBOLD)
226 .child(title),219 .child(title),
227 )220 )
228 .children(maintenance.then(|| {221 .children(maintenance.then(|| {
229 div()222 div()
230- .text_size(text(text::CAPTION))223+ .text_size(t.text(text::CAPTION))
231- .text_color(palette.muted)224+ .text_color(t.dim())
232 .child(w().auth.maintenance)225 .child(w().auth.maintenance)
233 }))226 }))
234- .children(self.saved_accounts(&entity, palette, cx))227+ .children(self.saved_accounts(&entity, t, cx))
235 .child(tabs)228 .child(tabs)
236- .child(field(palette, &self.auth.username_input))229+ .child(field(t, &self.auth.username_input))
237- .child(password_field(palette, &self.auth.password_input))230+ .child(password_field(t, &self.auth.password_input))
238 .children(invite)231 .children(invite)
239 .child(action_button)232 .child(action_button)
240- .children(connection_notice(&self.connection, palette))233+ .children(connection_notice(&self.connection, t))
241 .child(server_toggle(234 .child(server_toggle(
242 &entity,235 &entity,
243 &self.network.server().address,236 &self.network.server().address,
244 self.auth.server_open,237 self.auth.server_open,
245- palette,238+ t,
246 ))239 ))
247 .child(240 .child(
248 div()241 div()
@@ -251,19 +244,19 @@ impl Yumush {
251 .flex()244 .flex()
252 .flex_col()245 .flex_col()
253 .gap(px(space::SM))246 .gap(px(space::SM))
254- .child(field(palette, &self.auth.server_input))247+ .child(field(t, &self.auth.server_input))
255 .child(248 .child(
256 div()249 div()
257 .flex()250 .flex()
258 .items_center()251 .items_center()
259 .justify_between()252 .justify_between()
260- .text_size(text(text::CAPTION))253+ .text_size(t.text(text::CAPTION))
261- .text_color(palette.muted)254+ .text_color(t.dim())
262 .child(w().auth.accept_any_cert)255 .child(w().auth.accept_any_cert)
263 .child(super::parts::toggle(256 .child(super::parts::toggle(
264 "any_cert_switch",257 "any_cert_switch",
265 self.auth.any_cert,258 self.auth.any_cert,
266- palette.tokens,259+ t,
267 {260 {
268 let entity = entity.clone();261 let entity = entity.clone();
269 move |_, cx| {262 move |_, cx| {
@@ -287,21 +280,21 @@ impl Yumush {
287 )280 )
288 }281 }
289 282
290- fn saved_accounts(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> Option<Div> {283+ fn saved_accounts(&self, entity: &Entity<Self>, t: Tokens, cx: &App) -> Option<Div> {
291 (!self.accounts.list.is_empty()).then(|| {284 (!self.accounts.list.is_empty()).then(|| {
292 div()285 div()
293 .flex()286 .flex()
294 .flex_col()287 .flex_col()
295 .gap(px(space::XS))288 .gap(px(space::XS))
296 .pb(px(space::LG))289 .pb(px(space::LG))
297- .child(super::parts::caption_head(w().auth.saved, palette.tokens))290+ .child(super::parts::caption_head(w().auth.saved, t))
298- .child(account_list(self, entity, false, None, palette, cx))291+ .child(account_list(self, entity, None, t, cx))
299 })292 })
300 }293 }
301 }294 }
302 295
303 fn tab(296 fn tab(
304- palette: Palette,297+ t: Tokens,
305 entity: &Entity<Yumush>,298 entity: &Entity<Yumush>,
306 target: Route,299 target: Route,
307 label: &'static str,300 label: &'static str,
@@ -309,13 +302,13 @@ fn tab(
309 ) -> impl IntoElement {302 ) -> impl IntoElement {
310 let entity = entity.clone();303 let entity = entity.clone();
311 segment(304 segment(
312- clickable(label, palette, move |window, cx| {305+ clickable(label, t, move |window, cx| {
313 entity.update(cx, |this, cx| this.change_page(target, window, cx));306 entity.update(cx, |this, cx| this.change_page(target, window, cx));
314 }),307 }),
315 route == target,308 route == target,
316- palette,309+ t,
317 )310 )
318 .flex_1()311 .flex_1()
319- .text_size(text(text::CAPTION))312+ .text_size(t.text(text::CAPTION))
320 .child(label)313 .child(label)
321 }314 }
crates/client/src/gui/builder.rsmodified+63 -65
@@ -29,16 +29,22 @@ use gpui_kit::{
29 29
30 use self::ui::icon_button;30 use self::ui::icon_button;
31 use super::{31 use super::{
32- Palette, Yumush,32+ Yumush,
33 chat::View,33 chat::View,
34 entity_action, notify_error,34 entity_action, notify_error,
35 parts::{self, Press},35 parts::{self, Press},
36 settings_page::{frame, heading},36 settings_page::{frame, heading},
37- style::{size, space, text},37+ style::{Tokens, size, space, text},
38- text,
39 widget::search_text,38 widget::search_text,
40 };39 };
41 use crate::net::NetworkHandle;40 use crate::net::NetworkHandle;
41+use common::share::Kind;
42+
43+pub(super) struct Transfer {
44+ pub(super) community_id: Id,
45+ pub(super) members: Vec<Member>,
46+ pub(super) pending: Option<Id>,
47+}
42 48
43 pub(super) fn save_directory() -> PathBuf {49 pub(super) fn save_directory() -> PathBuf {
44 dirs::download_dir().unwrap_or_else(std::env::temp_dir)50 dirs::download_dir().unwrap_or_else(std::env::temp_dir)
@@ -108,56 +114,46 @@ impl BuilderTab {
108 }114 }
109 }115 }
110 116
111-pub(super) struct Transfer {
112- pub(super) community_id: Id,
113- pub(super) members: Vec<Member>,
114- pub(super) pending: Option<Id>,
115-}
116-
117 impl Yumush {117 impl Yumush {
118 pub(super) fn builder_page(118 pub(super) fn builder_page(
119 &self,119 &self,
120 entity: &Entity<Self>,120 entity: &Entity<Self>,
121- palette: Palette,121+ t: Tokens,
122 cx: &App,122 cx: &App,
123 ) -> impl IntoElement {123 ) -> impl IntoElement {
124- let tab = self.chat.builder_tab;124+ let tab = self.chat.admin.builder_tab;
125 let title = tab.label();125 let title = tab.label();
126 let body = match tab {126 let body = match tab {
127 BuilderTab::Overview => self127 BuilderTab::Overview => self
128- .overview_rows(palette)128+ .overview_rows(t)
129 .into_iter()129 .into_iter()
130 .map(IntoElement::into_any_element)130 .map(IntoElement::into_any_element)
131 .collect(),131 .collect(),
132- BuilderTab::Users => self.users_body(entity, palette, cx),132+ BuilderTab::Users => self.users_body(entity, t, cx),
133- BuilderTab::Communities => self.communities_body(entity, palette, cx),133+ BuilderTab::Communities => self.communities_body(entity, t, cx),
134- BuilderTab::Messages => self.messages_body(entity, palette),134+ BuilderTab::Messages => self.messages_body(entity, t),
135- BuilderTab::Voice => self.voice_body(entity, palette),135+ BuilderTab::Voice => self.voice_body(entity, t),
136- BuilderTab::Storage => self.storage_body(entity, palette),136+ BuilderTab::Storage => self.storage_body(entity, t),
137- BuilderTab::Access => self.access_body(entity, palette),137+ BuilderTab::Access => self.access_body(entity, t),
138- BuilderTab::Reports => self.reports_body(entity, palette),138+ BuilderTab::Reports => self.reports_body(entity, t),
139- BuilderTab::Server => self.server_body(entity, palette),139+ BuilderTab::Server => self.server_body(entity, t),
140- BuilderTab::Releases => self.releases_body(entity, palette),140+ BuilderTab::Releases => self.releases_body(entity, t),
141- BuilderTab::Log => self.log_body(entity, palette),141+ BuilderTab::Log => self.log_body(entity, t),
142 };142 };
143- let mut sections = vec![143+ let mut sections =
144- heading(title, self.tab_actions(tab, entity, palette, cx), palette).into_any_element(),144+ vec![heading(title, self.tab_actions(tab, entity, t, cx), t).into_any_element()];
145- ];
146 sections.extend(body);145 sections.extend(body);
147 146
148 frame(147 frame(
149 "builder_scroll",148 "builder_scroll",
150 entity,149 entity,
151- palette,150+ t,
152 Role::Builder.label(),151 Role::Builder.label(),
153 BuilderTab::ALL152 BuilderTab::ALL
154- .map(|tab| {153+ .map(|tab| self.builder_nav_item(tab, entity, t).into_any_element())
155- self.builder_nav_item(tab, entity, palette)
156- .into_any_element()
157- })
158 .into_iter()154 .into_iter()
159 .collect(),155 .collect(),
160- vec![self.ghost_toggle(entity, palette).into_any_element()],156+ vec![self.ghost_toggle(entity, t).into_any_element()],
161 sections,157 sections,
162 )158 )
163 }159 }
@@ -166,7 +162,7 @@ impl Yumush {
166 &self,162 &self,
167 tab: BuilderTab,163 tab: BuilderTab,
168 entity: &Entity<Self>,164 entity: &Entity<Self>,
169- palette: Palette,165+ t: Tokens,
170 cx: &App,166 cx: &App,
171 ) -> Vec<AnyElement> {167 ) -> Vec<AnyElement> {
172 match tab {168 match tab {
@@ -175,7 +171,7 @@ impl Yumush {
175 "refresh_voice_button".to_string(),171 "refresh_voice_button".to_string(),
176 w().builder.refresh,172 w().builder.refresh,
177 Press::Plain,173 Press::Plain,
178- palette.tokens,174+ t,
179 entity_action(entity, |yumush, window, cx| {175 entity_action(entity, |yumush, window, cx| {
180 yumush.load_voice_rooms(window, cx)176 yumush.load_voice_rooms(window, cx)
181 }),177 }),
@@ -183,11 +179,11 @@ impl Yumush {
183 .into_any_element(),179 .into_any_element(),
184 ],180 ],
185 BuilderTab::Server if self.server_form(cx) != self.server => vec![181 BuilderTab::Server if self.server_form(cx) != self.server => vec![
186- crate::gui::parts::button(182+ parts::button(
187 "save_server",183 "save_server",
188 w().builder.save,184 w().builder.save,
189- crate::gui::parts::Press::Plain,185+ Press::Plain,
190- palette.tokens,186+ t,
191 entity_action(entity, |yumush, window, cx| {187 entity_action(entity, |yumush, window, cx| {
192 yumush.save_server_settings(window, cx)188 yumush.save_server_settings(window, cx)
193 }),189 }),
@@ -199,7 +195,7 @@ impl Yumush {
199 "add_release_files".to_string(),195 "add_release_files".to_string(),
200 w().builder_release.add_files,196 w().builder_release.add_files,
201 Press::Plain,197 Press::Plain,
202- palette.tokens,198+ t,
203 entity_action(entity, |yumush, window, cx| {199 entity_action(entity, |yumush, window, cx| {
204 yumush.pick_release_files(window, cx)200 yumush.pick_release_files(window, cx)
205 }),201 }),
@@ -211,8 +207,8 @@ impl Yumush {
211 "export_builder_log".to_string(),207 "export_builder_log".to_string(),
212 IconName::Download,208 IconName::Download,
213 w().builder.export,209 w().builder.export,
214- palette.muted,210+ t.dim(),
215- palette,211+ t,
216 entity_action(entity, |yumush, window, cx| {212 entity_action(entity, |yumush, window, cx| {
217 yumush.export_builder_log(window, cx)213 yumush.export_builder_log(window, cx)
218 }),214 }),
@@ -227,17 +223,17 @@ impl Yumush {
227 &self,223 &self,
228 tab: BuilderTab,224 tab: BuilderTab,
229 entity: &Entity<Self>,225 entity: &Entity<Self>,
230- palette: Palette,226+ t: Tokens,
231 ) -> impl IntoElement {227 ) -> impl IntoElement {
232 let open = (tab == BuilderTab::Reports)228 let open = (tab == BuilderTab::Reports)
233- .then_some(self.chat.open_reports)229+ .then_some(self.chat.admin.open_reports)
234 .filter(|count| *count > 0);230 .filter(|count| *count > 0);
235 231
236- super::parts::index_item(232+ parts::index_item(
237 format!("builder_tab_{}", tab.id()),233 format!("builder_tab_{}", tab.id()),
238 tab.label(),234 tab.label(),
239- self.chat.builder_tab == tab,235+ self.chat.admin.builder_tab == tab,
240- palette.tokens,236+ t,
241 entity_action(entity, move |yumush, window, cx| {237 entity_action(entity, move |yumush, window, cx| {
242 yumush.select_builder_tab(tab, window, cx)238 yumush.select_builder_tab(tab, window, cx)
243 }),239 }),
@@ -245,14 +241,14 @@ impl Yumush {
245 .children(open.map(|count| {241 .children(open.map(|count| {
246 div()242 div()
247 .ml(px(space::SM))243 .ml(px(space::SM))
248- .text_size(text(text::CAPTION))244+ .text_size(t.text(text::CAPTION))
249- .text_color(palette.danger)245+ .text_color(t.bad())
250 .child(count.to_string())246 .child(count.to_string())
251 }))247 }))
252 }248 }
253 249
254- fn ghost_toggle(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {250+ fn ghost_toggle(&self, entity: &Entity<Self>, t: Tokens) -> impl IntoElement {
255- let enabled = self.chat.ghost;251+ let enabled = self.chat.session.ghost;
256 let toggle = entity_action(entity, move |yumush, window, cx| {252 let toggle = entity_action(entity, move |yumush, window, cx| {
257 yumush.set_ghost(!enabled, window, cx)253 yumush.set_ghost(!enabled, window, cx)
258 });254 });
@@ -262,15 +258,10 @@ impl Yumush {
262 .flex()258 .flex()
263 .items_center()259 .items_center()
264 .justify_between()260 .justify_between()
265- .text_size(text(text::LABEL))261+ .text_size(t.text(text::LABEL))
266- .text_color(palette.muted)262+ .text_color(t.dim())
267 .child(w().builder.ghost)263 .child(w().builder.ghost)
268- .child(super::parts::toggle(264+ .child(parts::toggle("ghost_switch", enabled, t, toggle))
269- "ghost_switch",
270- enabled,
271- palette.tokens,
272- toggle,
273- ))
274 }265 }
275 266
276 pub(super) fn is_builder(&self) -> bool {267 pub(super) fn is_builder(&self) -> bool {
@@ -281,7 +272,7 @@ impl Yumush {
281 272
282 pub(super) fn load_builder(&mut self, window: &mut Window, cx: &mut Context<Self>) {273 pub(super) fn load_builder(&mut self, window: &mut Window, cx: &mut Context<Self>) {
283 self.load_open_reports(window, cx);274 self.load_open_reports(window, cx);
284- match self.chat.builder_tab {275+ match self.chat.admin.builder_tab {
285 BuilderTab::Overview => self.load_overview(window, cx),276 BuilderTab::Overview => self.load_overview(window, cx),
286 BuilderTab::Users => self.load_users(window, cx),277 BuilderTab::Users => self.load_users(window, cx),
287 BuilderTab::Communities => self.load_builder_communities(window, cx),278 BuilderTab::Communities => self.load_builder_communities(window, cx),
@@ -309,9 +300,13 @@ impl Yumush {
309 }300 }
310 }301 }
311 302
303+ pub(super) fn on_builder_tab(&self, tab: BuilderTab) -> bool {
304+ self.chat.session.view == View::Builder && self.chat.admin.builder_tab == tab
305+ }
306+
312 pub(super) fn report_created(&self, window: &mut Window, cx: &mut Context<Self>) {307 pub(super) fn report_created(&self, window: &mut Window, cx: &mut Context<Self>) {
313 self.load_open_reports(window, cx);308 self.load_open_reports(window, cx);
314- if self.chat.view == View::Builder && self.chat.builder_tab == BuilderTab::Reports {309+ if self.on_builder_tab(BuilderTab::Reports) {
315 self.load_reports(window, cx);310 self.load_reports(window, cx);
316 }311 }
317 }312 }
@@ -322,7 +317,7 @@ impl Yumush {
322 window: &mut Window,317 window: &mut Window,
323 cx: &mut Context<Self>,318 cx: &mut Context<Self>,
324 ) {319 ) {
325- self.chat.builder_tab = tab;320+ self.chat.admin.builder_tab = tab;
326 if tab == BuilderTab::Server {321 if tab == BuilderTab::Server {
327 self.fill_server_form(window, cx);322 self.fill_server_form(window, cx);
328 }323 }
@@ -374,7 +369,7 @@ impl Yumush {
374 .as_ref()369 .as_ref()
375 .and_then(|me| accounts.iter().find(|account| account.user.id == me.id))370 .and_then(|me| accounts.iter().find(|account| account.user.id == me.id))
376 .is_some_and(|account| account.ghost);371 .is_some_and(|account| account.ghost);
377- yumush.chat.builder_users = accounts;372+ yumush.chat.admin.builder_users = accounts;
378 yumush.set_ghost_state(ghost);373 yumush.set_ghost_state(ghost);
379 cx.notify();374 cx.notify();
380 },375 },
@@ -382,19 +377,20 @@ impl Yumush {
382 }377 }
383 378
384 pub(super) fn releases_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {379 pub(super) fn releases_changed(&mut self, window: &mut Window, cx: &mut Context<Self>) {
385- if self.chat.view == View::Builder && self.chat.builder_tab == BuilderTab::Releases {380+ if self.on_builder_tab(BuilderTab::Releases) {
386 self.load_releases(window, cx);381 self.load_releases(window, cx);
387 }382 }
388 }383 }
389 384
390 pub(super) fn voice_changed(&self, window: &mut Window, cx: &mut Context<Self>) {385 pub(super) fn voice_changed(&self, window: &mut Window, cx: &mut Context<Self>) {
391- if self.chat.view == View::Builder && self.chat.builder_tab == BuilderTab::Voice {386+ if self.on_builder_tab(BuilderTab::Voice) {
392 self.load_voice_rooms(window, cx);387 self.load_voice_rooms(window, cx);
393 }388 }
394 }389 }
395 390
396 fn resolve_user(&self, username: &str) -> Option<Id> {391 fn resolve_user(&self, username: &str) -> Option<Id> {
397 self.chat392 self.chat
393+ .admin
398 .builder_users394 .builder_users
399 .iter()395 .iter()
400 .find(|account| account.user.username.to_lowercase() == username)396 .find(|account| account.user.username.to_lowercase() == username)
@@ -403,6 +399,7 @@ impl Yumush {
403 399
404 fn resolve_community(&self, name: &str) -> Option<Id> {400 fn resolve_community(&self, name: &str) -> Option<Id> {
405 self.chat401 self.chat
402+ .admin
406 .builder_communities403 .builder_communities
407 .iter()404 .iter()
408 .find(|summary| {405 .find(|summary| {
@@ -432,12 +429,13 @@ impl Yumush {
432 }429 }
433 430
434 fn set_ghost_state(&mut self, ghost: bool) {431 fn set_ghost_state(&mut self, ghost: bool) {
435- self.chat.ghost = ghost;432+ self.chat.session.ghost = ghost;
436 let Some(me) = self.user.as_ref() else {433 let Some(me) = self.user.as_ref() else {
437 return;434 return;
438 };435 };
439 if let Some(account) = self436 if let Some(account) = self
440 .chat437 .chat
438+ .admin
441 .builder_users439 .builder_users
442 .iter_mut()440 .iter_mut()
443 .find(|account| account.user.id == me.id)441 .find(|account| account.user.id == me.id)
@@ -451,8 +449,8 @@ impl Yumush {
451 449
452 cx.spawn_in(window, async move |this, cx| {450 cx.spawn_in(window, async move |this, cx| {
453 if enabled {451 if enabled {
454- let _ = network.stop_share().await;452+ let _ = network.stop(Kind::Screen).await;
455- let _ = network.stop_camera().await;453+ let _ = network.stop(Kind::Camera).await;
456 }454 }
457 match network.call(SetGhost { enabled }).await {455 match network.call(SetGhost { enabled }).await {
458 Ok(()) => {456 Ok(()) => {
crates/client/src/gui/builder/access.rsmodified+50 -66
@@ -9,28 +9,15 @@ use gpui_kit::{
9 };9 };
10 10
11 use super::ui::{11 use super::ui::{
12- card, card_header, confirmed, delete_icon_button, fixed, icon_button, list_row, pill, toolbar,12+ card, card_header, delete_icon_button, fixed, icon_button, list_card, list_row, number, pill,
13+ rows_body, toolbar,
13 };14 };
14-use crate::gui::style::{size, space, text};15+use crate::gui::chat::Armed;
15-use crate::gui::{Palette, Yumush, entity_action, millis_time, notify_error, text, widget::field};16+use crate::gui::style::{Tokens, size, space, text};
17+use crate::gui::{Yumush, entity_action, millis_time, notify_error, text, widget::field};
16 use crate::lang::w;18 use crate::lang::w;
17 19
18-fn list_card(header: Div, rows: Vec<Div>, none: &str, palette: Palette) -> Div {20+fn invite_row(invite: &InviteCode, pending: bool, entity: &Entity<Yumush>, t: Tokens) -> Div {
19- let body = if rows.is_empty() {
20- crate::gui::parts::empty(none, palette.tokens)
21- } else {
22- div().flex().flex_col().children(rows)
23- };
24-
25- card(palette).child(header).child(body)
26-}
27-
28-fn invite_row(
29- invite: &InviteCode,
30- pending: bool,
31- entity: &Entity<Yumush>,
32- palette: Palette,
33-) -> Div {
34 let copy_code = invite.code.clone();21 let copy_code = invite.code.clone();
35 let delete_code = invite.code.clone();22 let delete_code = invite.code.clone();
36 let expiry = invite.expires_at.map_or_else(23 let expiry = invite.expires_at.map_or_else(
@@ -62,7 +49,7 @@ fn invite_row(
62 .child(49 .child(
63 div()50 div()
64 .text_size(text(text::CAPTION))51 .text_size(text(text::CAPTION))
65- .text_color(palette.muted)52+ .text_color(t.dim())
66 .truncate()53 .truncate()
67 .child(format!("{left} · {expiry}")),54 .child(format!("{left} · {expiry}")),
68 ),55 ),
@@ -71,23 +58,21 @@ fn invite_row(
71 format!("copy_invite_{}", invite.code),58 format!("copy_invite_{}", invite.code),
72 IconName::Copy,59 IconName::Copy,
73 w().builder_access.copy,60 w().builder_access.copy,
74- palette.muted,61+ t.dim(),
75- palette,62+ t,
76- entity_action(entity, move |yumush, _, cx| {63+ move |_, cx| cx.write_to_clipboard(ClipboardItem::new_string(copy_code.clone())),
77- yumush.copy_invite(&copy_code, cx)
78- }),
79 ))64 ))
80 .child(delete_icon_button(65 .child(delete_icon_button(
81 format!("delete_invite_{}", invite.code),66 format!("delete_invite_{}", invite.code),
82 pending,67 pending,
83- palette,68+ t,
84 entity_action(entity, move |yumush, window, cx| {69 entity_action(entity, move |yumush, window, cx| {
85 yumush.delete_invite(&delete_code, window, cx)70 yumush.delete_invite(&delete_code, window, cx)
86 }),71 }),
87 ))72 ))
88 }73 }
89 74
90-fn ban_row(ban: &ServerBan, entity: &Entity<Yumush>, palette: Palette) -> Div {75+fn ban_row(ban: &ServerBan, entity: &Entity<Yumush>, t: Tokens) -> Div {
91 let remove_id = ban.id;76 let remove_id = ban.id;
92 let kind = match ban.kind {77 let kind = match ban.kind {
93 ServerBanKind::Ip => "IP",78 ServerBanKind::Ip => "IP",
@@ -96,7 +81,7 @@ fn ban_row(ban: &ServerBan, entity: &Entity<Yumush>, palette: Palette) -> Div {
96 81
97 list_row()82 list_row()
98 .px(px(space::LG))83 .px(px(space::LG))
99- .child(pill(kind, palette.text, palette))84+ .child(pill(kind, t.paper()))
100 .child(85 .child(
101 div()86 div()
102 .flex_1()87 .flex_1()
@@ -112,7 +97,7 @@ fn ban_row(ban: &ServerBan, entity: &Entity<Yumush>, palette: Palette) -> Div {
112 .children(ban.reason.as_ref().map(|reason| {97 .children(ban.reason.as_ref().map(|reason| {
113 div()98 div()
114 .text_size(text(text::CAPTION))99 .text_size(text(text::CAPTION))
115- .text_color(palette.muted)100+ .text_color(t.dim())
116 .min_w_0()101 .min_w_0()
117 .child(super::super::glyph::line(102 .child(super::super::glyph::line(
118 reason.clone().into(),103 reason.clone().into(),
@@ -124,8 +109,8 @@ fn ban_row(ban: &ServerBan, entity: &Entity<Yumush>, palette: Palette) -> Div {
124 format!("remove_ban_{}", ban.id),109 format!("remove_ban_{}", ban.id),
125 IconName::X,110 IconName::X,
126 w().builder_access.remove,111 w().builder_access.remove,
127- palette.muted,112+ t.dim(),
128- palette,113+ t,
129 entity_action(entity, move |yumush, window, cx| {114 entity_action(entity, move |yumush, window, cx| {
130 yumush.remove_ban(remove_id, window, cx)115 yumush.remove_ban(remove_id, window, cx)
131 }),116 }),
@@ -144,7 +129,7 @@ impl Yumush {
144 cx,129 cx,
145 |network| async move { network.call(ListInviteCodes).await },130 |network| async move { network.call(ListInviteCodes).await },
146 |yumush, codes, cx| {131 |yumush, codes, cx| {
147- yumush.chat.builder_invites = codes;132+ yumush.chat.admin.builder_invites = codes;
148 cx.notify();133 cx.notify();
149 },134 },
150 );135 );
@@ -156,24 +141,25 @@ impl Yumush {
156 cx,141 cx,
157 |network| async move { network.call(ListServerBans).await },142 |network| async move { network.call(ListServerBans).await },
158 |yumush, bans, cx| {143 |yumush, bans, cx| {
159- yumush.chat.builder_bans = bans;144+ yumush.chat.admin.builder_bans = bans;
160 cx.notify();145 cx.notify();
161 },146 },
162 );147 );
163 }148 }
164 149
165 pub(super) fn create_invite(&mut self, window: &mut Window, cx: &mut Context<Self>) {150 pub(super) fn create_invite(&mut self, window: &mut Window, cx: &mut Context<Self>) {
166- let uses = self.chat.invite_uses.read(cx).text().to_string();151+ let uses = self.chat.admin.invite_uses.read(cx).text().to_string();
167- let Ok(uses) = uses.trim().parse::<u32>() else {152+ let Some(uses) = number(&uses) else {
168 return;153 return;
169 };154 };
170- let hours = self.chat.invite_hours.read(cx).text().to_string();155+ let hours = self.chat.admin.invite_hours.read(cx).text().to_string();
171- let hours = match hours.trim() {156+ let hours = if hours.trim().is_empty() {
172- "" => None,157+ None
173- text => match text.parse::<u32>() {158+ } else {
174- Ok(hours) => Some(hours),159+ let Some(hours) = number(&hours) else {
175- Err(_) => return,160+ return;
176- },161+ };
162+ Some(hours)
177 };163 };
178 let network = self.network.clone();164 let network = self.network.clone();
179 165
@@ -195,8 +181,7 @@ impl Yumush {
195 window: &mut Window,181 window: &mut Window,
196 cx: &mut Context<Self>,182 cx: &mut Context<Self>,
197 ) {183 ) {
198- if !confirmed(&mut self.chat.pending_invite_delete, code.to_string()) {184+ if !self.arm(Armed::DeleteInvite(code.to_string()), cx) {
199- cx.notify();
200 return;185 return;
201 }186 }
202 let network = self.network.clone();187 let network = self.network.clone();
@@ -214,10 +199,6 @@ impl Yumush {
214 .detach();199 .detach();
215 }200 }
216 201
217- pub(super) fn copy_invite(&self, code: &str, cx: &mut Context<Self>) {
218- cx.write_to_clipboard(ClipboardItem::new_string(code.to_string()));
219- }
220-
221 pub(super) fn remove_ban(&mut self, id: Id, window: &mut Window, cx: &mut Context<Self>) {202 pub(super) fn remove_ban(&mut self, id: Id, window: &mut Window, cx: &mut Context<Self>) {
222 let network = self.network.clone();203 let network = self.network.clone();
223 204
@@ -233,15 +214,15 @@ impl Yumush {
233 .detach();214 .detach();
234 }215 }
235 216
236- pub(super) fn access_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {217+ pub(super) fn access_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
237 let controls = toolbar(vec![218 let controls = toolbar(vec![
238- fixed(80., field(palette, &self.chat.invite_uses)),219+ fixed(80., field(t, &self.chat.admin.invite_uses)),
239- fixed(size::THUMB, field(palette, &self.chat.invite_hours)),220+ fixed(size::THUMB, field(t, &self.chat.admin.invite_hours)),
240 crate::gui::parts::button(221 crate::gui::parts::button(
241 "create_invite",222 "create_invite",
242 w().builder_access.create,223 w().builder_access.create,
243 crate::gui::parts::Press::Plain,224 crate::gui::parts::Press::Plain,
244- palette.tokens,225+ t,
245 entity_action(entity, |yumush, window, cx| {226 entity_action(entity, |yumush, window, cx| {
246 yumush.create_invite(window, cx)227 yumush.create_invite(window, cx)
247 }),228 }),
@@ -249,27 +230,30 @@ impl Yumush {
249 .into_any_element(),230 .into_any_element(),
250 ])231 ])
251 .into_any_element();232 .into_any_element();
252- let invite_header = card_header(w().builder_access.invite_codes, vec![controls], palette);233+ let invite_header = card_header(w().builder_access.invite_codes, vec![controls], t);
253- let invites = self.chat.builder_invites.iter().map(|invite| {234+ let invites = self.chat.admin.builder_invites.iter().map(|invite| {
254- let pending = self.chat.pending_invite_delete.as_deref() == Some(invite.code.as_str());235+ let pending = self.armed(Armed::DeleteInvite(invite.code.clone()));
255- invite_row(invite, pending, entity, palette)236+ invite_row(invite, pending, entity, t)
256 });237 });
257 let bans = self238 let bans = self
258 .chat239 .chat
240+ .admin
259 .builder_bans241 .builder_bans
260 .iter()242 .iter()
261- .map(|ban| ban_row(ban, entity, palette));243+ .map(|ban| ban_row(ban, entity, t))
262- let ban_header = card_header(w().builder_access.bans, Vec::new(), palette);244+ .collect();
263 245
264 vec![246 vec![
265- list_card(247+ card()
266- invite_header,248+ .child(invite_header)
267- invites.collect(),249+ .child(rows_body(
268- w().builder_access.no_invite_codes,250+ invites.collect(),
269- palette,251+ w().builder_access.no_invite_codes,
270- )252+ t,
271- .into_any_element(),253+ ))
272- list_card(ban_header, bans.collect(), w().common.no_bans, palette).into_any_element(),254+ .into_any_element(),
255+ list_card(Some(w().builder_access.bans), bans, w().common.no_bans, t)
256+ .into_any_element(),
273 ]257 ]
274 }258 }
275 }259 }
crates/client/src/gui/builder/backups.rsmodified+24 -33
@@ -9,25 +9,24 @@ use gpui_kit::{
9 9
10 use super::{10 use super::{
11 save_directory,11 save_directory,
12- ui::{card, card_header, confirmed, delete_icon_button, icon_button, list_row},12+ ui::{card, card_header, confirmed, delete_icon_button, icon_button, list_row, rows_body},
13 };13 };
14 use crate::gui::{14 use crate::gui::{
15- Palette, Yumush, entity_action, millis_time, notify_error, storage,15+ Yumush, entity_action, millis_time, notify_error, storage,
16- style::{size, text},16+ style::{Tokens, size, text},
17- text,
18 };17 };
19 use crate::lang::w;18 use crate::lang::w;
20 19
21 const STORAGE_WIDTH: f32 = 72.;20 const STORAGE_WIDTH: f32 = 72.;
22 21
23-fn backup_row(info: &BackupInfo, pending: bool, entity: &Entity<Yumush>, palette: Palette) -> Div {22+fn backup_row(info: &BackupInfo, pending: bool, entity: &Entity<Yumush>, t: Tokens) -> Div {
24 let export_name = info.name.clone();23 let export_name = info.name.clone();
25 let export = icon_button(24 let export = icon_button(
26 format!("export_backup_{}", info.name),25 format!("export_backup_{}", info.name),
27 IconName::Download,26 IconName::Download,
28 w().builder_backups.export,27 w().builder_backups.export,
29- palette.muted,28+ t.dim(),
30- palette,29+ t,
31 entity_action(entity, move |yumush, window, cx| {30 entity_action(entity, move |yumush, window, cx| {
32 yumush.export_backup(&export_name, window, cx)31 yumush.export_backup(&export_name, window, cx)
33 }),32 }),
@@ -37,7 +36,7 @@ fn backup_row(info: &BackupInfo, pending: bool, entity: &Entity<Yumush>, palette
37 let delete = delete_icon_button(36 let delete = delete_icon_button(
38 format!("delete_backup_{}", info.name),37 format!("delete_backup_{}", info.name),
39 pending,38 pending,
40- palette,39+ t,
41 entity_action(entity, move |yumush, window, cx| {40 entity_action(entity, move |yumush, window, cx| {
42 yumush.delete_backup(&delete_name, window, cx)41 yumush.delete_backup(&delete_name, window, cx)
43 }),42 }),
@@ -48,22 +47,22 @@ fn backup_row(info: &BackupInfo, pending: bool, entity: &Entity<Yumush>, palette
48 Icon::new(IconName::HardDrive)47 Icon::new(IconName::HardDrive)
49 .size(px(size::ICON))48 .size(px(size::ICON))
50 .flex_shrink_0()49 .flex_shrink_0()
51- .text_color(palette.muted),50+ .text_color(t.dim()),
52 )51 )
53 .child(52 .child(
54 div()53 div()
55 .flex_1()54 .flex_1()
56 .min_w_0()55 .min_w_0()
57 .truncate()56 .truncate()
58- .text_size(text(text::LABEL))57+ .text_size(t.text(text::LABEL))
59- .text_color(palette.text)58+ .text_color(t.paper())
60 .child(info.name.clone()),59 .child(info.name.clone()),
61 )60 )
62 .child(61 .child(
63 div()62 div()
64 .flex_shrink_0()63 .flex_shrink_0()
65- .text_size(text(text::CAPTION))64+ .text_size(t.text(text::CAPTION))
66- .text_color(palette.muted)65+ .text_color(t.dim())
67 .child(millis_time(info.created_ms, crate::lang::w().common.date)),66 .child(millis_time(info.created_ms, crate::lang::w().common.date)),
68 )67 )
69 .child(68 .child(
@@ -72,8 +71,8 @@ fn backup_row(info: &BackupInfo, pending: bool, entity: &Entity<Yumush>, palette
72 .flex_shrink_0()71 .flex_shrink_0()
73 .flex()72 .flex()
74 .justify_end()73 .justify_end()
75- .text_size(text(text::CAPTION))74+ .text_size(t.text(text::CAPTION))
76- .text_color(palette.muted)75+ .text_color(t.dim())
77 .child(storage(info.size_bytes)),76 .child(storage(info.size_bytes)),
78 )77 )
79 .child(export)78 .child(export)
@@ -81,38 +80,30 @@ fn backup_row(info: &BackupInfo, pending: bool, entity: &Entity<Yumush>, palette
81 }80 }
82 81
83 impl Yumush {82 impl Yumush {
84- pub(super) fn backups_card(&self, entity: &Entity<Self>, palette: Palette) -> Div {83+ pub(super) fn backups_card(&self, entity: &Entity<Self>, t: Tokens) -> Div {
85 let create = crate::gui::parts::button(84 let create = crate::gui::parts::button(
86 "create_backup",85 "create_backup",
87 w().builder_backups.create,86 w().builder_backups.create,
88 crate::gui::parts::Press::Plain,87 crate::gui::parts::Press::Plain,
89- palette.tokens,88+ t,
90 entity_action(entity, |yumush, window, cx| {89 entity_action(entity, |yumush, window, cx| {
91 yumush.create_backup(window, cx)90 yumush.create_backup(window, cx)
92 }),91 }),
93 )92 )
94 .into_any_element();93 .into_any_element();
95 let rows: Vec<Div> = self94 let rows: Vec<Div> = self
95+ .desk
96 .backups96 .backups
97 .iter()97 .iter()
98 .map(|info| {98 .map(|info| {
99- let pending = self.pending_backup_delete.as_deref() == Some(info.name.as_str());99+ let pending = self.desk.pending_backup.as_deref() == Some(info.name.as_str());
100- backup_row(info, pending, entity, palette)100+ backup_row(info, pending, entity, t)
101 })101 })
102 .collect();102 .collect();
103- let body = if rows.is_empty() {
104- crate::gui::parts::empty(w().builder_backups.no_backups, palette.tokens)
105- } else {
106- div().flex().flex_col().children(rows)
107- };
108 103
109- card(palette)104+ card()
110- .child(card_header(105+ .child(card_header(w().builder_backups.backups, vec![create], t))
111- w().builder_backups.backups,106+ .child(rows_body(rows, w().builder_backups.no_backups, t))
112- vec![create],
113- palette,
114- ))
115- .child(body)
116 }107 }
117 108
118 pub(super) fn load_backups(&self, window: &mut Window, cx: &mut Context<Self>) {109 pub(super) fn load_backups(&self, window: &mut Window, cx: &mut Context<Self>) {
@@ -121,7 +112,7 @@ impl Yumush {
121 cx,112 cx,
122 |network| async move { network.call(ListBackups).await },113 |network| async move { network.call(ListBackups).await },
123 |yumush, backups, cx| {114 |yumush, backups, cx| {
124- yumush.backups = backups;115+ yumush.desk.backups = backups;
125 cx.notify();116 cx.notify();
126 },117 },
127 );118 );
@@ -143,7 +134,7 @@ impl Yumush {
143 }134 }
144 135
145 fn delete_backup(&mut self, name: &str, window: &mut Window, cx: &mut Context<Self>) {136 fn delete_backup(&mut self, name: &str, window: &mut Window, cx: &mut Context<Self>) {
146- if !confirmed(&mut self.pending_backup_delete, name.to_string()) {137+ if !confirmed(&mut self.desk.pending_backup, name.to_string()) {
147 cx.notify();138 cx.notify();
148 return;139 return;
149 }140 }
crates/client/src/gui/builder/ci_view.rsmodified+99 -113
@@ -1,23 +1,25 @@
1 use std::{collections::HashMap, rc::Rc, time::Duration};1 use std::{collections::HashMap, rc::Rc, time::Duration};
2 2
3-use common::call::{CreateTag, GetForge};3+use common::{
4+ call::{CreateTag, GetForge},
5+ model::Hue,
6+};
4 use gpui_kit::{7 use gpui_kit::{
5 Anchor, AnyElement, App, Context, Div, Entity, Focusable, InteractiveElement, IntoElement,8 Anchor, AnyElement, App, Context, Div, Entity, Focusable, InteractiveElement, IntoElement,
6- ListHorizontalSizingBehavior, ParentElement, ScrollStrategy, Styled, Window,9+ ListHorizontalSizingBehavior, ParentElement, ScrollStrategy, Styled, Task, Window,
7 component::popover::{Popover, PopoverState},10 component::popover::{Popover, PopoverState},
8 div, px, uniform_list,11 div, px, uniform_list,
9 };12 };
10 13
11-use super::releases::caption_text;14+use super::ui::{caption_text, card, list_row};
12-use super::ui::{card, list_row};
13 use crate::ci::{self, Event, Job, Run, State};15 use crate::ci::{self, Event, Job, Run, State};
14 use crate::gui::builder::BuilderTab;16 use crate::gui::builder::BuilderTab;
15 use crate::gui::chat::View;17 use crate::gui::chat::View;
16 use crate::gui::{18 use crate::gui::{
17- Palette, Trigger, Yumush, entity_action, hoverable, notify_error,19+ Trigger, Yumush, entity_action, hoverable, notify_error,
18 parts::{self, Fill, Press},20 parts::{self, Fill, Press},
19 profile::yumush_action,21 profile::yumush_action,
20- style::{radius, size, space, text},22+ style::{Tokens, radius, size, space, text},
21 text,23 text,
22 };24 };
23 use crate::lang::w;25 use crate::lang::w;
@@ -26,16 +28,23 @@ const LOG_LINE: f32 = 18.;
26 const LOG_MAX: usize = 50_000;28 const LOG_MAX: usize = 50_000;
27 const TICK: Duration = Duration::from_secs(1);29 const TICK: Duration = Duration::from_secs(1);
28 30
31+#[derive(Default, PartialEq, Eq)]
32+enum Banner {
33+ #[default]
34+ Hidden,
35+ Shown,
36+ Dismissed,
37+}
38+
29 #[derive(Default)]39 #[derive(Default)]
30 pub(crate) struct Live {40 pub(crate) struct Live {
31 repo: Option<String>,41 repo: Option<String>,
32 watch: Option<ci::Watch>,42 watch: Option<ci::Watch>,
43+ ticks: Option<Task<()>>,
33 run: Option<Run>,44 run: Option<Run>,
34 logs: HashMap<String, Vec<String>>,45 logs: HashMap<String, Vec<String>>,
35 log_open: Option<String>,46 log_open: Option<String>,
36- seen_live: bool,47+ banner: Banner,
37- dismissed: bool,
38- tagging: bool,
39 }48 }
40 49
41 impl Live {50 impl Live {
@@ -48,7 +57,7 @@ impl Live {
48 }57 }
49 58
50 fn shown(&self) -> bool {59 fn shown(&self) -> bool {
51- self.run.is_some() && self.seen_live && !self.dismissed60+ self.banner == Banner::Shown
52 }61 }
53 62
54 fn done(&self) -> usize {63 fn done(&self) -> usize {
@@ -65,12 +74,13 @@ impl Live {
65 self.done() as f32 / total.max(1) as f3274 self.done() as f32 / total.max(1) as f32
66 }75 }
67 76
68- fn failed(&self) -> bool {77+ fn tally(&self) -> String {
69- self.state() == Some(State::Failed)78+ let total = self.run.as_ref().map_or(0, |run| run.jobs.len());
79+ format!("{} / {total}", self.done())
70 }80 }
71 81
72- pub(super) fn tagging(&self) -> bool {82+ fn failed(&self) -> bool {
73- self.tagging83+ self.state() == Some(State::Failed)
74 }84 }
75 }85 }
76 86
@@ -99,14 +109,14 @@ fn run_label(state: State) -> &'static str {
99 }109 }
100 }110 }
101 111
102-fn job_status(state: State, palette: Palette) -> Div {112+fn job_status(state: State, t: Tokens) -> Div {
103 let w = &w().builder_release;113 let w = &w().builder_release;
104 match state {114 match state {
105- State::Waiting => caption_text(w.waiting, palette.muted),115+ State::Waiting => caption_text(w.waiting, t.dim()),
106- State::Running => caption_text(w.running, palette.text),116+ State::Running => caption_text(w.running, t.paper()),
107- State::Success => caption_text(w.done, palette.ok),117+ State::Success => caption_text(w.done, t.hue(Hue::Mint)),
108- State::Skipped => caption_text(w.skipped, palette.muted),118+ State::Skipped => caption_text(w.skipped, t.dim()),
109- State::Failed => caption_text(w.failed, palette.danger),119+ State::Failed => caption_text(w.failed, t.bad()),
110 }120 }
111 }121 }
112 122
@@ -115,7 +125,7 @@ fn job_row(
115 log: Option<&Vec<String>>,125 log: Option<&Vec<String>>,
116 seconds: bool,126 seconds: bool,
117 entity: &Entity<Yumush>,127 entity: &Entity<Yumush>,
118- palette: Palette,128+ t: Tokens,
119 ) -> Div {129 ) -> Div {
120 let state = State::of(&job.state);130 let state = State::of(&job.state);
121 let step = job.steps.last().map(|step| step.name.as_str());131 let step = job.steps.last().map(|step| step.name.as_str());
@@ -134,10 +144,10 @@ fn job_row(
134 .child(144 .child(
135 div()145 div()
136 .text_size(text(text::LABEL))146 .text_size(text(text::LABEL))
137- .text_color(palette.text)147+ .text_color(t.paper())
138 .child(job.label().to_string()),148 .child(job.label().to_string()),
139 )149 )
140- .children(detail.map(|detail| caption_text(detail, palette.muted).truncate()));150+ .children(detail.map(|detail| caption_text(detail, t.dim()).truncate()));
141 let id = job.id.clone();151 let id = job.id.clone();
142 let entity = entity.clone();152 let entity = entity.clone();
143 list_row()153 list_row()
@@ -150,19 +160,19 @@ fn job_row(
150 .content(move |_, window, cx| log_sheet(&id, &entity, window, cx)),160 .content(move |_, window, cx| log_sheet(&id, &entity, window, cx)),
151 ),161 ),
152 )162 )
153- .child(job_status(state, palette))163+ .child(job_status(state, t))
154 .children(164 .children(
155 span(165 span(
156 job.started_at.as_deref(),166 job.started_at.as_deref(),
157 job.finished_at.as_deref(),167 job.finished_at.as_deref(),
158 seconds,168 seconds,
159 )169 )
160- .map(|time| caption_text(time, palette.muted)),170+ .map(|time| caption_text(time, t.dim())),
161 )171 )
162 }172 }
163 173
164 fn log_sheet(job: &str, entity: &Entity<Yumush>, window: &mut Window, cx: &mut App) -> Div {174 fn log_sheet(job: &str, entity: &Entity<Yumush>, window: &mut Window, cx: &mut App) -> Div {
165- let palette = crate::gui::palette(cx);175+ let t = Tokens::of(cx);
166 let input = entity.read(cx).log_search.clone();176 let input = entity.read(cx).log_search.clone();
167 if !input.read(cx).focus_handle(cx).contains_focused(window, cx) {177 if !input.read(cx).focus_handle(cx).contains_focused(window, cx) {
168 input.update(cx, |state, cx| state.focus(window, cx));178 input.update(cx, |state, cx| state.focus(window, cx));
@@ -191,16 +201,16 @@ fn log_sheet(job: &str, entity: &Entity<Yumush>, window: &mut Window, cx: &mut A
191 }201 }
192 let job = job.to_string();202 let job = job.to_string();
193 let entity = entity.clone();203 let entity = entity.clone();
194- crate::gui::widget::panel(palette)204+ parts::surface(t)
195 .w(px(size::PAGE - space::XL))205 .w(px(size::PAGE - space::XL))
196 .p(px(space::XS))206 .p(px(space::XS))
197 .flex()207 .flex()
198 .flex_col()208 .flex_col()
199 .gap(px(space::XS))209 .gap(px(space::XS))
200- .child(crate::gui::sidebar::input_box(&input, palette))210+ .child(crate::gui::sidebar::input_box(&input, t))
201 .child(211 .child(
202 uniform_list(format!("ci_log_lines_{job}"), count, move |range, _, cx| {212 uniform_list(format!("ci_log_lines_{job}"), count, move |range, _, cx| {
203- let palette = crate::gui::palette(cx);213+ let t = Tokens::of(cx);
204 let Some(log) = entity.read(cx).desk.live.logs.get(&job) else {214 let Some(log) = entity.read(cx).desk.live.logs.get(&job) else {
205 return Vec::new();215 return Vec::new();
206 };216 };
@@ -213,7 +223,7 @@ fn log_sheet(job: &str, entity: &Entity<Yumush>, window: &mut Window, cx: &mut A
213 .px(px(space::XS))223 .px(px(space::XS))
214 .whitespace_nowrap()224 .whitespace_nowrap()
215 .text_size(text(text::CAPTION))225 .text_size(text(text::CAPTION))
216- .text_color(palette.muted)226+ .text_color(t.dim())
217 .child(line.clone())227 .child(line.clone())
218 })228 })
219 .collect()229 .collect()
@@ -235,9 +245,27 @@ impl Yumush {
235 return;245 return;
236 };246 };
237 let (watch, mut events) = ci::watch(repo.clone());247 let (watch, mut events) = ci::watch(repo.clone());
248+ let ticks = cx.spawn({
249+ let this = this.clone();
250+ async move |cx| {
251+ loop {
252+ cx.background_executor().timer(TICK).await;
253+ let ticked = this.update_in(cx, |yumush, window, cx| {
254+ if yumush.desk.live.live() {
255+ window.refresh();
256+ cx.notify();
257+ }
258+ });
259+ if ticked.is_err() {
260+ break;
261+ }
262+ }
263+ }
264+ });
238 let started = this.update(cx, |yumush, _| {265 let started = this.update(cx, |yumush, _| {
239 yumush.desk.live.repo = Some(repo);266 yumush.desk.live.repo = Some(repo);
240 yumush.desk.live.watch = Some(watch);267 yumush.desk.live.watch = Some(watch);
268+ yumush.desk.live.ticks = Some(ticks);
241 });269 });
242 if started.is_err() {270 if started.is_err() {
243 return;271 return;
@@ -255,24 +283,6 @@ impl Yumush {
255 .detach();283 .detach();
256 })284 })
257 .detach();285 .detach();
258- cx.spawn_in(window, async move |this, cx| {
259- loop {
260- cx.background_executor().timer(TICK).await;
261- let Ok(watching) = this.update_in(cx, |yumush, window, cx| {
262- if yumush.desk.live.live() {
263- window.refresh();
264- cx.notify();
265- }
266- yumush.desk.live.watch.is_some()
267- }) else {
268- break;
269- };
270- if !watching {
271- break;
272- }
273- }
274- })
275- .detach();
276 }286 }
277 287
278 fn ci_event(&mut self, event: Event, cx: &mut Context<Self>) {288 fn ci_event(&mut self, event: Event, cx: &mut Context<Self>) {
@@ -281,11 +291,10 @@ impl Yumush {
281 Event::Run(run) => {291 Event::Run(run) => {
282 if live.run.as_ref().map(|old| old.number) != Some(run.number) {292 if live.run.as_ref().map(|old| old.number) != Some(run.number) {
283 live.logs.clear();293 live.logs.clear();
284- live.dismissed = false;294+ live.banner = Banner::Hidden;
285- live.seen_live = false;
286 }295 }
287- if !State::of(&run.state).finished() {296+ if live.banner == Banner::Hidden && !State::of(&run.state).finished() {
288- live.seen_live = true;297+ live.banner = Banner::Shown;
289 }298 }
290 live.run = Some(run);299 live.run = Some(run);
291 }300 }
@@ -341,16 +350,16 @@ impl Yumush {
341 350
342 pub(super) fn create_tag(&mut self, window: &mut Window, cx: &mut Context<Self>) {351 pub(super) fn create_tag(&mut self, window: &mut Window, cx: &mut Context<Self>) {
343 let tag = self.release_tag_text(cx);352 let tag = self.release_tag_text(cx);
344- if tag.is_empty() || self.desk.live.tagging {353+ if tag.is_empty() || self.desk.tagging {
345 return;354 return;
346 }355 }
347- self.desk.live.tagging = true;356+ self.desk.tagging = true;
348 cx.notify();357 cx.notify();
349 let network = self.network.clone();358 let network = self.network.clone();
350 cx.spawn_in(window, async move |this, cx| {359 cx.spawn_in(window, async move |this, cx| {
351 let result = network.call(CreateTag { tag }).await;360 let result = network.call(CreateTag { tag }).await;
352 let _ = this.update(cx, |yumush, cx| {361 let _ = this.update(cx, |yumush, cx| {
353- yumush.desk.live.tagging = false;362+ yumush.desk.tagging = false;
354 cx.notify();363 cx.notify();
355 });364 });
356 if let Err(error) = result {365 if let Err(error) = result {
@@ -360,7 +369,7 @@ impl Yumush {
360 .detach();369 .detach();
361 }370 }
362 371
363- fn run_head(&self, palette: Palette) -> Option<Div> {372+ fn run_head(&self, t: Tokens) -> Option<Div> {
364 let live = &self.desk.live;373 let live = &self.desk.live;
365 let run = live.run.as_ref()?;374 let run = live.run.as_ref()?;
366 let state = State::of(&run.state);375 let state = State::of(&run.state);
@@ -374,7 +383,7 @@ impl Yumush {
374 let aside = if state.finished() {383 let aside = if state.finished() {
375 time384 time
376 } else {385 } else {
377- format!("{} / {} · {time}", live.done(), run.jobs.len())386+ format!("{} · {time}", live.tally())
378 };387 };
379 Some(388 Some(
380 div()389 div()
@@ -384,42 +393,32 @@ impl Yumush {
384 .text_size(text(text::LABEL))393 .text_size(text(text::LABEL))
385 .child(394 .child(
386 div()395 div()
387- .text_color(if live.failed() {396+ .text_color(if live.failed() { t.bad() } else { t.paper() })
388- palette.danger
389- } else {
390- palette.text
391- })
392 .child(format!("#{} · {name} · {}", run.number, run_label(state))),397 .child(format!("#{} · {name} · {}", run.number, run_label(state))),
393 )398 )
394- .child(div().text_color(palette.muted).child(aside)),399+ .child(div().text_color(t.dim()).child(aside)),
395 )400 )
396 }401 }
397 402
398- fn ci_rows(403+ fn ci_rows(&self, entity: &Entity<Self>, compact: bool, t: Tokens) -> Vec<Div> {
399- &self,
400- entity: &Entity<Self>,
401- fit: impl Fn(Div) -> Div,
402- palette: Palette,
403- ) -> Vec<Div> {
404 let live = &self.desk.live;404 let live = &self.desk.live;
405 let seconds = self.settings.clock_seconds;405 let seconds = self.settings.clock_seconds;
406 live.run.as_ref().map_or_else(Vec::new, |run| {406 live.run.as_ref().map_or_else(Vec::new, |run| {
407 run.jobs407 run.jobs
408 .iter()408 .iter()
409 .map(|job| {409 .map(|job| {
410- fit(job_row(410+ let row = job_row(job, live.logs.get(&job.id), seconds, entity, t);
411- job,411+ if compact {
412- live.logs.get(&job.id),412+ row.min_h(px(size::CONTROL)).py(px(space::XXS))
413- seconds,413+ } else {
414- entity,414+ row
415- palette,415+ }
416- ))
417 })416 })
418 .collect()417 .collect()
419 })418 })
420 }419 }
421 420
422- fn import_run_button(&self, entity: &Entity<Self>, palette: Palette) -> Option<AnyElement> {421+ fn import_run_button(&self, entity: &Entity<Self>, t: Tokens) -> Option<AnyElement> {
423 let run = self.desk.live.run.as_ref()?;422 let run = self.desk.live.run.as_ref()?;
424 let tag = run.tag()?.to_string();423 let tag = run.tag()?.to_string();
425 (State::of(&run.state) == State::Success).then(|| {424 (State::of(&run.state) == State::Success).then(|| {
@@ -427,7 +426,7 @@ impl Yumush {
427 "ci_import",426 "ci_import",
428 w().builder_release.import,427 w().builder_release.import,
429 Press::Primary,428 Press::Primary,
430- palette.tokens,429+ t,
431 entity_action(entity, move |yumush, window, cx| {430 entity_action(entity, move |yumush, window, cx| {
432 yumush.import_tag(tag.clone(), window, cx)431 yumush.import_tag(tag.clone(), window, cx)
433 }),432 }),
@@ -436,19 +435,19 @@ impl Yumush {
436 })435 })
437 }436 }
438 437
439- pub(super) fn ci_card(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {438+ pub(super) fn ci_card(&self, entity: &Entity<Self>, t: Tokens) -> Option<Div> {
440- let head = self.run_head(palette)?;439+ let head = self.run_head(t)?;
441 Some(440 Some(
442- card(palette)441+ card()
443 .child(head)442 .child(head)
444 .child(parts::track(443 .child(parts::track(
445 Fill::Part(self.desk.live.share()),444 Fill::Part(self.desk.live.share()),
446 self.desk.live.failed(),445 self.desk.live.failed(),
447- palette.tokens,446+ t,
448 ))447 ))
449- .children(self.ci_rows(entity, |row| row, palette))448+ .children(self.ci_rows(entity, false, t))
450 .children(449 .children(
451- self.import_run_button(entity, palette)450+ self.import_run_button(entity, t)
452 .map(|button| list_row().justify_end().child(button)),451 .map(|button| list_row().justify_end().child(button)),
453 ),452 ),
454 )453 )
@@ -457,7 +456,7 @@ impl Yumush {
457 pub(in crate::gui) fn build_control(456 pub(in crate::gui) fn build_control(
458 &self,457 &self,
459 entity: &Entity<Self>,458 entity: &Entity<Self>,
460- palette: Palette,459+ t: Tokens,
461 ) -> Option<AnyElement> {460 ) -> Option<AnyElement> {
462 let live = &self.desk.live;461 let live = &self.desk.live;
463 if !live.shown() {462 if !live.shown() {
@@ -473,7 +472,7 @@ impl Yumush {
473 )472 )
474 .unwrap_or_default()473 .unwrap_or_default()
475 } else {474 } else {
476- format!("{} / {}", live.done(), run.jobs.len())475+ live.tally()
477 };476 };
478 let failed = live.failed();477 let failed = live.failed();
479 let trigger = hoverable(478 let trigger = hoverable(
@@ -492,17 +491,13 @@ impl Yumush {
492 .text_size(text(text::LABEL))491 .text_size(text(text::LABEL))
493 .child(492 .child(
494 div()493 div()
495- .text_color(if failed { palette.danger } else { palette.text })494+ .text_color(if failed { t.bad() } else { t.paper() })
496 .child(run_label(state)),495 .child(run_label(state)),
497 )496 )
498- .child(div().text_color(palette.muted).child(aside)),497+ .child(div().text_color(t.dim()).child(aside)),
499 )498 )
500- .child(parts::track(499+ .child(parts::track(Fill::Part(live.share()), failed, t)),
501- Fill::Part(live.share()),500+ t,
502- failed,
503- palette.tokens,
504- )),
505- palette,
506 );501 );
507 let entity = entity.clone();502 let entity = entity.clone();
508 Some(503 Some(
@@ -512,25 +507,20 @@ impl Yumush {
512 .trigger(Trigger::new(trigger))507 .trigger(Trigger::new(trigger))
513 .content(move |_, _, cx| {508 .content(move |_, _, cx| {
514 let popover = cx.entity();509 let popover = cx.entity();
515- let palette = crate::gui::palette(cx);510+ let t = Tokens::of(cx);
516- entity.read(cx).build_sheet(&entity, &popover, palette)511+ entity.read(cx).build_sheet(&entity, &popover, t)
517 })512 })
518 .into_any_element(),513 .into_any_element(),
519 )514 )
520 }515 }
521 516
522- fn build_sheet(517+ fn build_sheet(&self, entity: &Entity<Self>, popover: &Entity<PopoverState>, t: Tokens) -> Div {
523- &self,
524- entity: &Entity<Self>,
525- popover: &Entity<PopoverState>,
526- palette: Palette,
527- ) -> Div {
528 let w = &w().builder_release;518 let w = &w().builder_release;
529 let open = parts::button(519 let open = parts::button(
530 "build_open_releases",520 "build_open_releases",
531 w.open_releases,521 w.open_releases,
532 Press::Plain,522 Press::Plain,
533- palette.tokens,523+ t,
534 yumush_action(entity, popover, |yumush, window, cx| {524 yumush_action(entity, popover, |yumush, window, cx| {
535 yumush.show_view(View::Builder, window, cx);525 yumush.show_view(View::Builder, window, cx);
536 yumush.select_builder_tab(BuilderTab::Releases, window, cx);526 yumush.select_builder_tab(BuilderTab::Releases, window, cx);
@@ -541,29 +531,25 @@ impl Yumush {
541 "build_sheet_dismiss",531 "build_sheet_dismiss",
542 w.dismiss,532 w.dismiss,
543 Press::Plain,533 Press::Plain,
544- palette.tokens,534+ t,
545 yumush_action(entity, popover, |yumush, _, cx| {535 yumush_action(entity, popover, |yumush, _, cx| {
546- yumush.desk.live.dismissed = true;536+ yumush.desk.live.banner = Banner::Dismissed;
547 cx.notify();537 cx.notify();
548 }),538 }),
549 )539 )
550 });540 });
551- parts::popover(palette.tokens)541+ parts::popover(t)
552 .w(px(size::SHEET))542 .w(px(size::SHEET))
553 .p(px(space::MD))543 .p(px(space::MD))
554- .children(self.run_head(palette))544+ .children(self.run_head(t))
555- .children(self.ci_rows(545+ .children(self.ci_rows(entity, true, t))
556- entity,
557- |row| row.min_h(px(size::CONTROL)).py(px(space::XXS)),
558- palette,
559- ))
560 .child(546 .child(
561 div()547 div()
562 .pt(px(space::SM))548 .pt(px(space::SM))
563 .flex()549 .flex()
564 .justify_between()550 .justify_between()
565 .child(open)551 .child(open)
566- .children(self.import_run_button(entity, palette))552+ .children(self.import_run_button(entity, t))
567 .children(dismiss),553 .children(dismiss),
568 )554 )
569 }555 }
crates/client/src/gui/builder/communities.rsmodified+67 -119
@@ -1,60 +1,33 @@
1 use common::model::Id;1 use common::model::Id;
2 use common::{2 use common::{
3- call::{3+ call::{DeleteCommunity, GetCommunity, ListAllCommunities, ListMembers, TransferOwnership},
4- DeleteCommunity, GetCommunity, ListAllCommunities, ListMembers, SetCommunityVoice,
5- TransferOwnership,
6- },
7 model::{Community, CommunitySummary, Member, Rank},4 model::{Community, CommunitySummary, Member, Rank},
8 };5 };
9 use gpui_kit::{6 use gpui_kit::{
10 AnyElement, App, Context, Div, Entity, FontWeight, IntoElement, ParentElement, Styled, Window,7 AnyElement, App, Context, Div, Entity, FontWeight, IntoElement, ParentElement, Styled, Window,
11- assets::IconName, div, prelude::FluentBuilder as _, px,8+ assets::IconName, div, px,
12 };9 };
13 10
14-use super::{11+use super::Transfer;
15- Transfer,12+use super::ui::{card, delete_icon_button, icon_button, list_row, pill, rows_body};
16- ui::{card, confirmed, icon_button, list_row, pill, rows_body},
17-};
18 use crate::gui::{13 use crate::gui::{
19- Palette, Yumush, avatar, community_icon, entity_action, notify_error,14+ Yumush, avatar,
15+ chat::Armed,
16+ community_icon, entity_action, notify_error,
20 parts::{self, Press},17 parts::{self, Press},
21 profile::user_link,18 profile::user_link,
22- style::{radius, size, space, text},19+ style::{Tokens, radius, size, space, text},
23 text,20 text,
24 widget::search_text,21 widget::search_text,
25 };22 };
26 use crate::lang::w;23 use crate::lang::w;
27 24
28 impl Yumush {25 impl Yumush {
29- pub(super) fn set_builder_community_voice(26+ pub(in crate::gui) fn load_builder_communities(
30- &mut self,27+ &self,
31- community_id: Id,
32- enabled: bool,
33 window: &mut Window,28 window: &mut Window,
34 cx: &mut Context<Self>,29 cx: &mut Context<Self>,
35 ) {30 ) {
36- let network = self.network.clone();
37-
38- cx.spawn_in(window, async move |this, cx| {
39- match network
40- .call(SetCommunityVoice {
41- community_id,
42- enabled,
43- })
44- .await
45- {
46- Ok(_) => {
47- let _ = this.update_in(cx, |yumush, window, cx| {
48- yumush.load_builder_communities(window, cx)
49- });
50- }
51- Err(error) => notify_error(&this, cx, error),
52- }
53- })
54- .detach();
55- }
56-
57- pub(super) fn load_builder_communities(&self, window: &mut Window, cx: &mut Context<Self>) {
58 self.fetch_builder(31 self.fetch_builder(
59 window,32 window,
60 cx,33 cx,
@@ -68,7 +41,7 @@ impl Yumush {
68 yumush.request_user_avatar(owner, cx);41 yumush.request_user_avatar(owner, cx);
69 }42 }
70 }43 }
71- yumush.chat.builder_communities = summaries;44+ yumush.chat.admin.builder_communities = summaries;
72 cx.notify();45 cx.notify();
73 },46 },
74 );47 );
@@ -80,8 +53,7 @@ impl Yumush {
80 window: &mut Window,53 window: &mut Window,
81 cx: &mut Context<Self>,54 cx: &mut Context<Self>,
82 ) {55 ) {
83- if !confirmed(&mut self.chat.pending_community_delete, community_id) {56+ if !self.arm(Armed::BuilderDeleteCommunity(community_id), cx) {
84- cx.notify();
85 return;57 return;
86 }58 }
87 let network = self.network.clone();59 let network = self.network.clone();
@@ -90,7 +62,7 @@ impl Yumush {
90 match network.call(DeleteCommunity { community_id }).await {62 match network.call(DeleteCommunity { community_id }).await {
91 Ok(()) => {63 Ok(()) => {
92 let _ = this.update_in(cx, |yumush, window, cx| {64 let _ = this.update_in(cx, |yumush, window, cx| {
93- yumush.chat.remove_community(community_id);65+ yumush.forget_community(community_id, cx);
94 yumush.load_builder_communities(window, cx);66 yumush.load_builder_communities(window, cx);
95 });67 });
96 }68 }
@@ -108,15 +80,16 @@ impl Yumush {
108 ) {80 ) {
109 if self81 if self
110 .chat82 .chat
83+ .admin
111 .transfer84 .transfer
112 .as_ref()85 .as_ref()
113 .is_some_and(|transfer| transfer.community_id == community_id)86 .is_some_and(|transfer| transfer.community_id == community_id)
114 {87 {
115- self.chat.transfer = None;88+ self.chat.admin.transfer = None;
116 cx.notify();89 cx.notify();
117 return;90 return;
118 }91 }
119- self.chat.transfer = Some(Transfer {92+ self.chat.admin.transfer = Some(Transfer {
120 community_id,93 community_id,
121 members: Vec::new(),94 members: Vec::new(),
122 pending: None,95 pending: None,
@@ -146,7 +119,7 @@ impl Yumush {
146 for member in &members {119 for member in &members {
147 yumush.request_user_avatar(&member.user, cx);120 yumush.request_user_avatar(&member.user, cx);
148 }121 }
149- let Some(transfer) = yumush.chat.transfer.as_mut() else {122+ let Some(transfer) = yumush.chat.admin.transfer.as_mut() else {
150 return;123 return;
151 };124 };
152 if transfer.community_id == community_id {125 if transfer.community_id == community_id {
@@ -159,8 +132,8 @@ impl Yumush {
159 .detach();132 .detach();
160 }133 }
161 134
162- pub(super) fn transfer_rows(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {135+ pub(super) fn transfer_rows(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
163- let Some(transfer) = &self.chat.transfer else {136+ let Some(transfer) = &self.chat.admin.transfer else {
164 return Vec::new();137 return Vec::new();
165 };138 };
166 139
@@ -170,17 +143,18 @@ impl Yumush {
170 .filter(|member| member.rank != Rank::Owner)143 .filter(|member| member.rank != Rank::Owner)
171 .map(|member| {144 .map(|member| {
172 let pending = transfer.pending == Some(member.user.id);145 let pending = transfer.pending == Some(member.user.id);
173- self.transfer_row(member, pending, entity, palette)146+ self.transfer_row(member, pending, entity, t)
174 .into_any_element()147 .into_any_element()
175 })148 })
176 .collect()149 .collect()
177 }150 }
178 151
179 pub(super) fn transfer_to(&mut self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {152 pub(super) fn transfer_to(&mut self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {
180- let Some(transfer) = self.chat.transfer.as_mut() else {153+ let Some(transfer) = self.chat.admin.transfer.as_mut() else {
181 return;154 return;
182 };155 };
183- if !confirmed(&mut transfer.pending, user_id) {156+ if transfer.pending.take() != Some(user_id) {
157+ transfer.pending = Some(user_id);
184 window.refresh();158 window.refresh();
185 cx.notify();159 cx.notify();
186 return;160 return;
@@ -198,7 +172,7 @@ impl Yumush {
198 {172 {
199 Ok(()) => {173 Ok(()) => {
200 let _ = this.update_in(cx, |yumush, window, cx| {174 let _ = this.update_in(cx, |yumush, window, cx| {
201- yumush.chat.transfer = None;175+ yumush.chat.admin.transfer = None;
202 yumush.load_builder_communities(window, cx);176 yumush.load_builder_communities(window, cx);
203 });177 });
204 }178 }
@@ -248,11 +222,7 @@ impl Yumush {
248 cx: &mut Context<Self>,222 cx: &mut Context<Self>,
249 ) {223 ) {
250 let community_id = community.id;224 let community_id = community.id;
251- if self.chat.joined(community_id) {225+ self.open_builder_community(community, window, cx);
252- self.select_community(community_id, window, cx);
253- } else {
254- self.open_builder_community(community, window, cx);
255- }
256 if voice && !self.chat.in_voice(community_id) {226 if voice && !self.chat.in_voice(community_id) {
257 self.toggle_voice(community_id, window, cx);227 self.toggle_voice(community_id, window, cx);
258 }228 }
@@ -266,7 +236,7 @@ impl Yumush {
266 ) {236 ) {
267 let community_id = community.id;237 let community_id = community.id;
268 if !self.chat.joined(community_id) {238 if !self.chat.joined(community_id) {
269- self.chat.opened = Some(community);239+ self.chat.session.opened = Some(community);
270 }240 }
271 self.select_community(community_id, window, cx);241 self.select_community(community_id, window, cx);
272 }242 }
@@ -274,12 +244,13 @@ impl Yumush {
274 pub(super) fn communities_body(244 pub(super) fn communities_body(
275 &self,245 &self,
276 entity: &Entity<Self>,246 entity: &Entity<Self>,
277- palette: Palette,247+ t: Tokens,
278 cx: &App,248 cx: &App,
279 ) -> Vec<AnyElement> {249 ) -> Vec<AnyElement> {
280- let query = search_text(&self.chat.builder_search, cx);250+ let query = search_text(&self.chat.admin.builder_search, cx);
281 let rows: Vec<Div> = self251 let rows: Vec<Div> = self
282 .chat252 .chat
253+ .admin
283 .builder_communities254 .builder_communities
284 .iter()255 .iter()
285 .filter(|summary| {256 .filter(|summary| {
@@ -289,22 +260,22 @@ impl Yumush {
289 .to_lowercase()260 .to_lowercase()
290 .contains(query.as_str())261 .contains(query.as_str())
291 })262 })
292- .map(|summary| self.community_row(summary, entity, palette))263+ .map(|summary| self.community_row(summary, entity, t))
293 .collect();264 .collect();
294 265
295 vec![266 vec![
296- card(palette)267+ card()
297 .child(268 .child(
298 div().pb(px(space::SM)).flex().items_center().child(269 div().pb(px(space::SM)).flex().items_center().child(
299 div()270 div()
300 .w(px(size::SIDEBAR))271 .w(px(size::SIDEBAR))
301 .child(crate::gui::sidebar::input_box(272 .child(crate::gui::sidebar::input_box(
302- &self.chat.builder_search,273+ &self.chat.admin.builder_search,
303- palette,274+ t,
304 )),275 )),
305 ),276 ),
306 )277 )
307- .child(rows_body(rows, w().builder_communities.empty, palette))278+ .child(rows_body(rows, w().builder_communities.empty, t))
308 .into_any_element(),279 .into_any_element(),
309 ]280 ]
310 }281 }
@@ -314,7 +285,7 @@ impl Yumush {
314 member: &Member,285 member: &Member,
315 pending: bool,286 pending: bool,
316 entity: &Entity<Self>,287 entity: &Entity<Self>,
317- palette: Palette,288+ t: Tokens,
318 ) -> Div {289 ) -> Div {
319 let user_id = member.user.id;290 let user_id = member.user.id;
320 291
@@ -334,11 +305,11 @@ impl Yumush {
334 .items_center()305 .items_center()
335 .gap(px(space::SM))306 .gap(px(space::SM))
336 .child(avatar(307 .child(avatar(
337- palette,308+ t,
338 &member.user,309 &member.user,
339 px(size::AVATAR),310 px(size::AVATAR),
340 text(text::CAPTION),311 text(text::CAPTION),
341- &self.chat.avatars,312+ &self.chat.session.avatars,
342 ))313 ))
343 .child(314 .child(
344 div()315 div()
@@ -356,7 +327,7 @@ impl Yumush {
356 w().builder_communities.transfer327 w().builder_communities.transfer
357 },328 },
358 Press::Plain,329 Press::Plain,
359- palette.tokens,330+ t,
360 entity_action(entity, move |yumush, window, cx| {331 entity_action(entity, move |yumush, window, cx| {
361 yumush.transfer_to(user_id, window, cx)332 yumush.transfer_to(user_id, window, cx)
362 }),333 }),
@@ -367,19 +338,16 @@ impl Yumush {
367 &self,338 &self,
368 summary: &CommunitySummary,339 summary: &CommunitySummary,
369 entity: &Entity<Self>,340 entity: &Entity<Self>,
370- palette: Palette,341+ t: Tokens,
371 ) -> Div {342 ) -> Div {
372 let community = &summary.community;343 let community = &summary.community;
373- let opened = community.clone();
374 let id = community.id;344 let id = community.id;
375- let log_id = id;345+ let opened = community.clone();
376- let transfer_id = id;
377- let delete_id = id;
378- let voice_id = id;
379 let voice_enabled = community.voice_enabled;346 let voice_enabled = community.voice_enabled;
380- let pending_delete = self.chat.pending_community_delete == Some(id);347+ let pending_delete = self.armed(Armed::BuilderDeleteCommunity(id));
381 let expanded = self348 let expanded = self
382 .chat349 .chat
350+ .admin
383 .transfer351 .transfer
384 .as_ref()352 .as_ref()
385 .is_some_and(|transfer| transfer.community_id == id);353 .is_some_and(|transfer| transfer.community_id == id);
@@ -394,11 +362,11 @@ impl Yumush {
394 let row = list_row()362 let row = list_row()
395 .px(px(space::LG))363 .px(px(space::LG))
396 .child(community_icon(364 .child(community_icon(
397- palette,365+ t,
398 community,366 community,
399 px(size::AVATAR),367 px(size::AVATAR),
400 text(text::CAPTION),368 text(text::CAPTION),
401- &self.chat.avatars,369+ &self.chat.session.avatars,
402 ))370 ))
403 .child(371 .child(
404 div()372 div()
@@ -410,28 +378,25 @@ impl Yumush {
410 div()378 div()
411 .text_size(text(text::LABEL))379 .text_size(text(text::LABEL))
412 .font_weight(FontWeight::MEDIUM)380 .font_weight(FontWeight::MEDIUM)
413- .text_color(palette.text)381+ .text_color(t.paper())
414 .truncate()382 .truncate()
415 .child(community.name.clone()),383 .child(community.name.clone()),
416 )384 )
417 .child(385 .child(
418 div()386 div()
419 .text_size(text(text::CAPTION))387 .text_size(text(text::CAPTION))
420- .text_color(palette.muted)388+ .text_color(t.dim())
421 .truncate()389 .truncate()
422 .child(meta),390 .child(meta),
423 ),391 ),
424 )392 )
425- .children(393+ .children((!voice_enabled).then(|| pill(w().builder_communities.voice_off, t.dim())))
426- (!voice_enabled)
427- .then(|| pill(w().builder_communities.voice_off, palette.muted, palette)),
428- )
429 .child(icon_button(394 .child(icon_button(
430 format!("open_community_{id}"),395 format!("open_community_{id}"),
431 IconName::ArrowUpRight,396 IconName::ArrowUpRight,
432 w().builder_communities.open,397 w().builder_communities.open,
433- palette.muted,398+ t.dim(),
434- palette,399+ t,
435 entity_action(entity, move |yumush, window, cx| {400 entity_action(entity, move |yumush, window, cx| {
436 yumush.open_builder_community(opened.clone(), window, cx)401 yumush.open_builder_community(opened.clone(), window, cx)
437 }),402 }),
@@ -440,10 +405,10 @@ impl Yumush {
440 format!("log_community_{id}"),405 format!("log_community_{id}"),
441 IconName::ScrollText,406 IconName::ScrollText,
442 w().builder_communities.log,407 w().builder_communities.log,
443- palette.muted,408+ t.dim(),
444- palette,409+ t,
445 entity_action(entity, move |yumush, window, cx| {410 entity_action(entity, move |yumush, window, cx| {
446- yumush.show_logs(log_id, window, cx)411+ yumush.show_logs(id, window, cx)
447 }),412 }),
448 ))413 ))
449 .child(icon_button(414 .child(icon_button(
@@ -458,47 +423,30 @@ impl Yumush {
458 } else {423 } else {
459 w().builder_communities.voice_off424 w().builder_communities.voice_off
460 },425 },
461- palette.muted,426+ t.dim(),
462- palette,427+ t,
463 entity_action(entity, move |yumush, window, cx| {428 entity_action(entity, move |yumush, window, cx| {
464- yumush.set_builder_community_voice(voice_id, !voice_enabled, window, cx)429+ yumush.set_community_voice(id, !voice_enabled, window, cx)
465 }),430 }),
466 ))431 ))
467 .child(icon_button(432 .child(icon_button(
468 format!("transfer_community_{id}"),433 format!("transfer_community_{id}"),
469 IconName::ArrowRightLeft,434 IconName::ArrowRightLeft,
470 w().builder_communities.transfer,435 w().builder_communities.transfer,
471- if expanded {436+ if expanded { t.paper() } else { t.dim() },
472- palette.text437+ t,
473- } else {
474- palette.muted
475- },
476- palette,
477 entity_action(entity, move |yumush, window, cx| {438 entity_action(entity, move |yumush, window, cx| {
478- yumush.open_transfer(transfer_id, window, cx)439+ yumush.open_transfer(id, window, cx)
479 }),440 }),
480 ))441 ))
481- .child(442+ .child(delete_icon_button(
482- icon_button(443+ format!("delete_community_{id}"),
483- format!("delete_community_{id}_{pending_delete}"),444+ pending_delete,
484- IconName::Trash,445+ t,
485- if pending_delete {446+ entity_action(entity, move |yumush, window, cx| {
486- w().builder_communities.confirm_delete447+ yumush.delete_builder_community(id, window, cx)
487- } else {448+ }),
488- w().builder_communities.delete449+ ));
489- },
490- if pending_delete {
491- palette.on_accent
492- } else {
493- palette.danger
494- },
495- palette,
496- entity_action(entity, move |yumush, window, cx| {
497- yumush.delete_builder_community(delete_id, window, cx)
498- }),
499- )
500- .when(pending_delete, |this| this.bg(palette.danger)),
501- );
502 450
503 div()451 div()
504 .flex()452 .flex()
@@ -510,7 +458,7 @@ impl Yumush {
510 .flex()458 .flex()
511 .flex_col()459 .flex_col()
512 .rounded(px(radius::MD))460 .rounded(px(radius::MD))
513- .children(self.transfer_rows(entity, palette)),461+ .children(self.transfer_rows(entity, t)),
514 )462 )
515 }))463 }))
516 }464 }
crates/client/src/gui/builder/log.rsmodified+40 -41
@@ -13,13 +13,16 @@ use jiff::Timestamp;
13 13
14 use super::{14 use super::{
15 save_directory,15 save_directory,
16- ui::{card, end_of_day_ms, fixed, list_row, pill, start_of_day_ms, toolbar},16+ ui::{
17+ caption_text, card, end_of_day_ms, fixed, list_row, pill, rows_body, start_of_day_ms,
18+ toolbar,
19+ },
17 };20 };
18 use crate::gui::{21 use crate::gui::{
19- Palette, Yumush,22+ Yumush,
20 community_settings::user_name,23 community_settings::user_name,
21 entity_action, millis_time, notify_error,24 entity_action, millis_time, notify_error,
22- style::{size, space, text},25+ style::{Tokens, size, space, text},
23 text,26 text,
24 widget::{field, search_text},27 widget::{field, search_text},
25 };28 };
@@ -113,7 +116,12 @@ fn action_detail(action: &AdminAction) -> Option<String> {
113 }116 }
114 117
115 fn csv_field(text: &str) -> String {118 fn csv_field(text: &str) -> String {
116- format!("\"{}\"", text.replace('"', "\"\""))119+ let guarded = if text.starts_with(['=', '+', '-', '@', '\t', '\r']) {
120+ format!("'{text}")
121+ } else {
122+ text.to_string()
123+ };
124+ format!("\"{}\"", guarded.replace('"', "\"\""))
117 }125 }
118 126
119 fn builder_log_csv(entries: &[AdminLogEntry]) -> String {127 fn builder_log_csv(entries: &[AdminLogEntry]) -> String {
@@ -188,9 +196,9 @@ fn action_icon(action: &AdminAction) -> IconName {
188 }196 }
189 }197 }
190 198
191-fn builder_log_row(entry: &AdminLogEntry, palette: Palette) -> Div {199+fn builder_log_row(entry: &AdminLogEntry, t: Tokens) -> Div {
192 list_row()200 list_row()
193- .child(crate::gui::parts::small_icon(action_icon(&entry.action)).text_color(palette.muted))201+ .child(crate::gui::parts::small_icon(action_icon(&entry.action)).text_color(t.dim()))
194 .child(202 .child(
195 div()203 div()
196 .flex_1()204 .flex_1()
@@ -202,46 +210,41 @@ fn builder_log_row(entry: &AdminLogEntry, palette: Palette) -> Div {
202 div()210 div()
203 .truncate()211 .truncate()
204 .text_size(text(text::LABEL))212 .text_size(text(text::LABEL))
205- .text_color(palette.text)213+ .text_color(t.paper())
206 .child(builder_log_text(entry)),214 .child(builder_log_text(entry)),
207 )215 )
208- .child(216+ .child(caption_text(
209- div()217+ millis_time(entry.created_at, crate::lang::w().common.stamp),
210- .text_size(text(text::CAPTION))218+ t.dim(),
211- .text_color(palette.muted)219+ )),
212- .child(millis_time(entry.created_at, crate::lang::w().common.stamp)),
213- ),
214 )220 )
215 .children(221 .children(
216 entry222 entry
217 .community223 .community
218 .as_deref()224 .as_deref()
219- .map(|community| pill(community, palette.accent, palette)),225+ .map(|community| pill(community, t.paper())),
220 )226 )
221 }227 }
222 228
223 impl Yumush {229 impl Yumush {
224 pub(super) fn load_builder_logs(&self, window: &mut Window, cx: &mut Context<Self>) {230 pub(super) fn load_builder_logs(&self, window: &mut Window, cx: &mut Context<Self>) {
225- if !self.is_builder() {
226- return;
227- }
228 let (Some(actor_id), Some(target_id)) = (231 let (Some(actor_id), Some(target_id)) = (
229- self.filter_user(&self.chat.builder_log_actor, cx),232+ self.filter_user(&self.chat.admin.builder_log_actor, cx),
230- self.filter_user(&self.chat.builder_log_target, cx),233+ self.filter_user(&self.chat.admin.builder_log_target, cx),
231 ) else {234 ) else {
232 window.push_notification(Notification::error(w().builder_log.unknown_user), cx);235 window.push_notification(Notification::error(w().builder_log.unknown_user), cx);
233 return;236 return;
234 };237 };
235 let action = self238 let action = self
236 .chat239 .chat
240+ .admin
237 .builder_log_action241 .builder_log_action
238 .read(cx)242 .read(cx)
239 .selected_value()243 .selected_value()
240 .copied()244 .copied()
241- .filter(|name| *name != "All")
242 .and_then(AdminActionKind::parse);245 .and_then(AdminActionKind::parse);
243- let after_ms = start_of_day_ms(&search_text(&self.chat.builder_log_from, cx));246+ let after_ms = start_of_day_ms(&search_text(&self.chat.admin.builder_log_from, cx));
244- let before_ms = end_of_day_ms(&search_text(&self.chat.builder_log_to, cx));247+ let before_ms = end_of_day_ms(&search_text(&self.chat.admin.builder_log_to, cx));
245 self.fetch_builder(248 self.fetch_builder(
246 window,249 window,
247 cx,250 cx,
@@ -257,7 +260,7 @@ impl Yumush {
257 .await260 .await
258 },261 },
259 |yumush, entries, cx| {262 |yumush, entries, cx| {
260- yumush.chat.builder_logs = entries;263+ yumush.chat.admin.builder_logs = entries;
261 cx.notify();264 cx.notify();
262 },265 },
263 );266 );
@@ -269,7 +272,7 @@ impl Yumush {
269 millis_time(now_ms(), "%Y%m%d-%H%M%S")272 millis_time(now_ms(), "%Y%m%d-%H%M%S")
270 );273 );
271 let target = cx.prompt_for_new_path(&save_directory(), Some(&name));274 let target = cx.prompt_for_new_path(&save_directory(), Some(&name));
272- let csv = builder_log_csv(&self.chat.builder_logs);275+ let csv = builder_log_csv(&self.chat.admin.builder_logs);
273 276
274 cx.spawn_in(window, async move |this, cx| {277 cx.spawn_in(window, async move |this, cx| {
275 let target = match target.await {278 let target = match target.await {
@@ -287,24 +290,25 @@ impl Yumush {
287 .detach();290 .detach();
288 }291 }
289 292
290- pub(super) fn log_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {293+ pub(super) fn log_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
291 let filters = toolbar(vec![294 let filters = toolbar(vec![
292- fixed(size::THUMB, field(palette, &self.chat.builder_log_actor)),295+ fixed(size::THUMB, field(t, &self.chat.admin.builder_log_actor)),
293- fixed(size::THUMB, field(palette, &self.chat.builder_log_target)),296+ fixed(size::THUMB, field(t, &self.chat.admin.builder_log_target)),
294 fixed(297 fixed(
295 size::THUMB,298 size::THUMB,
296 crate::gui::widget::underline(299 crate::gui::widget::underline(
297- palette,300+ t,
298- Select::new(&self.chat.builder_log_action).appearance(false),301+ size::CONTROL,
302+ Select::new(&self.chat.admin.builder_log_action).appearance(false),
299 ),303 ),
300 ),304 ),
301- fixed(size::THUMB, field(palette, &self.chat.builder_log_from)),305+ fixed(size::THUMB, field(t, &self.chat.admin.builder_log_from)),
302- fixed(size::THUMB, field(palette, &self.chat.builder_log_to)),306+ fixed(size::THUMB, field(t, &self.chat.admin.builder_log_to)),
303 crate::gui::parts::button(307 crate::gui::parts::button(
304 "apply_builder_log",308 "apply_builder_log",
305 w().builder_log.apply,309 w().builder_log.apply,
306 crate::gui::parts::Press::Plain,310 crate::gui::parts::Press::Plain,
307- palette.tokens,311+ t,
308 entity_action(entity, |yumush, window, cx| {312 entity_action(entity, |yumush, window, cx| {
309 yumush.load_builder_logs(window, cx)313 yumush.load_builder_logs(window, cx)
310 }),314 }),
@@ -313,20 +317,15 @@ impl Yumush {
313 ]);317 ]);
314 let rows: Vec<Div> = self318 let rows: Vec<Div> = self
315 .chat319 .chat
320+ .admin
316 .builder_logs321 .builder_logs
317 .iter()322 .iter()
318- .map(|entry| builder_log_row(entry, palette))323+ .map(|entry| builder_log_row(entry, t))
319 .collect();324 .collect();
320- let body = if rows.is_empty() {
321- crate::gui::parts::empty(w().builder_log.no_entries, palette.tokens)
322- } else {
323- div().flex().flex_col().children(rows)
324- };
325-
326 vec![325 vec![
327- card(palette)326+ card()
328 .child(div().pb(px(space::SM)).child(filters))327 .child(div().pb(px(space::SM)).child(filters))
329- .child(body)328+ .child(rows_body(rows, w().builder_log.no_entries, t))
330 .into_any_element(),329 .into_any_element(),
331 ]330 ]
332 }331 }
crates/client/src/gui/builder/messages.rsmodified+45 -49
@@ -13,12 +13,13 @@ use gpui_kit::{
13 px,13 px,
14 };14 };
15 15
16-use super::ui::{card, confirmed, delete_icon_button, end_of_day_ms, icon_button, start_of_day_ms};16+use super::ui::{card, delete_icon_button, end_of_day_ms, icon_button, start_of_day_ms};
17-use crate::gui::style::{size, space, stroke, text};17+use crate::gui::chat::Armed;
18+use crate::gui::style::{Tokens, size, space, stroke, text};
18 use crate::gui::{19 use crate::gui::{
19- Palette, Yumush,20+ Yumush,
20 community_settings::user_name,21 community_settings::user_name,
21- entity_action, millis_time, notify_error,22+ entity_action, glyph, millis_time, notify_error,
22 profile::user_link,23 profile::user_link,
23 text,24 text,
24 widget::{field, search_text},25 widget::{field, search_text},
@@ -30,7 +31,7 @@ fn message_hit_row(
30 pending: bool,31 pending: bool,
31 purge_pending: bool,32 purge_pending: bool,
32 entity: &Entity<Yumush>,33 entity: &Entity<Yumush>,
33- palette: Palette,34+ t: Tokens,
34 ) -> Div {35 ) -> Div {
35 let message_id = hit.message.id;36 let message_id = hit.message.id;
36 let community_id = hit.message.community_id;37 let community_id = hit.message.community_id;
@@ -38,15 +39,13 @@ fn message_hit_row(
38 let hue = hit39 let hue = hit
39 .author40 .author
40 .as_ref()41 .as_ref()
41- .map_or(palette.tokens.faint(), |author| {42+ .map_or(t.faint(), |author| t.person(author.id));
42- palette.tokens.person(author.id)
43- });
44 let open = icon_button(43 let open = icon_button(
45 format!("open_message_{}", hit.message.id),44 format!("open_message_{}", hit.message.id),
46 IconName::MessageSquare,45 IconName::MessageSquare,
47 w().builder_messages.open_chat,46 w().builder_messages.open_chat,
48- palette.muted,47+ t.dim(),
49- palette,48+ t,
50 entity_action(entity, move |yumush, window, cx| {49 entity_action(entity, move |yumush, window, cx| {
51 yumush.jump_to(community_id, false, window, cx)50 yumush.jump_to(community_id, false, window, cx)
52 }),51 }),
@@ -54,7 +53,7 @@ fn message_hit_row(
54 let delete = delete_icon_button(53 let delete = delete_icon_button(
55 format!("delete_message_{}", hit.message.id),54 format!("delete_message_{}", hit.message.id),
56 pending,55 pending,
57- palette,56+ t,
58 entity_action(entity, move |yumush, window, cx| {57 entity_action(entity, move |yumush, window, cx| {
59 yumush.delete_builder_message(message_id, window, cx)58 yumush.delete_builder_message(message_id, window, cx)
60 }),59 }),
@@ -69,14 +68,14 @@ fn message_hit_row(
69 } else {68 } else {
70 w().builder_messages.purge_user69 w().builder_messages.purge_user
71 },70 },
72- palette.danger,71+ t.bad(),
73- palette,72+ t,
74 entity_action(entity, move |yumush, window, cx| {73 entity_action(entity, move |yumush, window, cx| {
75 yumush.purge_builder_user(user_id, window, cx)74 yumush.purge_builder_user(user_id, window, cx)
76 }),75 }),
77 )76 )
78 .when(purge_pending, |this| {77 .when(purge_pending, |this| {
79- this.bg(palette.danger).text_color(palette.on_accent)78+ this.bg(t.bad()).text_color(t.ground())
80 })79 })
81 });80 });
82 81
@@ -98,7 +97,7 @@ fn message_hit_row(
98 .py(px(space::SM))97 .py(px(space::SM))
99 .pl(px(space::XL + space::LG))98 .pl(px(space::XL + space::LG))
100 .pr(px(space::LG))99 .pr(px(space::LG))
101- .hover(|style| style.bg(palette.hover))100+ .hover(|style| style.bg(t.hov()))
102 .child(dot)101 .child(dot)
103 .child(102 .child(
104 div()103 div()
@@ -128,7 +127,7 @@ fn message_hit_row(
128 div()127 div()
129 .flex_shrink_0()128 .flex_shrink_0()
130 .text_size(text(text::CAPTION))129 .text_size(text(text::CAPTION))
131- .text_color(palette.muted)130+ .text_color(t.dim())
132 .child(millis_time(131 .child(millis_time(
133 hit.message.created_at,132 hit.message.created_at,
134 crate::lang::w().common.year_stamp,133 crate::lang::w().common.year_stamp,
@@ -139,21 +138,21 @@ fn message_hit_row(
139 .min_w_0()138 .min_w_0()
140 .truncate()139 .truncate()
141 .text_size(text(text::CAPTION))140 .text_size(text(text::CAPTION))
142- .text_color(palette.tokens.faint())141+ .text_color(t.faint())
143 .child(hit.community.clone()),142 .child(hit.community.clone()),
144 ),143 ),
145 )144 )
146 .child(match hit.message.call {145 .child(match hit.message.call {
147 Some(call) => {146 Some(call) => {
148- crate::gui::chat::call_line(call, user_name(&hit.author), false, palette)147+ crate::gui::chat::call_line(call, user_name(&hit.author), false, t)
149 }148 }
150 None => div()149 None => div()
151 .text_size(text(text::BODY))150 .text_size(text(text::BODY))
152- .text_color(palette.body)151+ .text_color(t.paper())
153 .line_clamp(2)152 .line_clamp(2)
154- .child(super::super::glyph::wrapped(153+ .child(glyph::wrapped(
155 hit.message.body.clone().into(),154 hit.message.body.clone().into(),
156- super::super::text(super::super::style::text::BODY),155+ text(text::BODY),
157 )),156 )),
158 }),157 }),
159 )158 )
@@ -173,7 +172,7 @@ fn message_hit_row(
173 }172 }
174 173
175 impl Yumush {174 impl Yumush {
176- pub(super) fn messages_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {175+ pub(super) fn messages_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
177 let filters = div()176 let filters = div()
178 .px(px(space::LG))177 .px(px(space::LG))
179 .py(px(space::MD))178 .py(px(space::MD))
@@ -185,7 +184,7 @@ impl Yumush {
185 div()184 div()
186 .flex_1()185 .flex_1()
187 .min_w_0()186 .min_w_0()
188- .child(field(palette, &self.chat.builder_message_text)),187+ .child(field(t, &self.chat.admin.builder_message_text)),
189 ),188 ),
190 )189 )
191 .child(190 .child(
@@ -196,23 +195,18 @@ impl Yumush {
196 .gap(px(space::SM))195 .gap(px(space::SM))
197 .children(196 .children(
198 [197 [
199- &self.chat.builder_message_user,198+ &self.chat.admin.builder_message_user,
200- &self.chat.builder_message_community,199+ &self.chat.admin.builder_message_community,
201- &self.chat.builder_message_from,200+ &self.chat.admin.builder_message_from,
202- &self.chat.builder_message_to,201+ &self.chat.admin.builder_message_to,
203 ]202 ]
204- .map(|input| {203+ .map(|input| div().flex_1().min_w(px(size::THUMB)).child(field(t, input))),
205- div()
206- .flex_1()
207- .min_w(px(size::THUMB))
208- .child(field(palette, input))
209- }),
210 )204 )
211 .child(crate::gui::parts::button(205 .child(crate::gui::parts::button(
212 "search_messages",206 "search_messages",
213 w().builder_messages.search,207 w().builder_messages.search,
214 crate::gui::parts::Press::Plain,208 crate::gui::parts::Press::Plain,
215- palette.tokens,209+ t,
216 entity_action(entity, |yumush, window, cx| {210 entity_action(entity, |yumush, window, cx| {
217 yumush.search_messages(window, cx)211 yumush.search_messages(window, cx)
218 }),212 }),
@@ -220,19 +214,20 @@ impl Yumush {
220 );214 );
221 let rows: Vec<Div> = self215 let rows: Vec<Div> = self
222 .chat216 .chat
217+ .admin
223 .builder_messages218 .builder_messages
224 .iter()219 .iter()
225 .map(|hit| {220 .map(|hit| {
226- let pending = self.chat.pending_message_delete == Some(hit.message.id);221+ let pending = self.armed(Armed::DeleteMessage(hit.message.id));
227 let purge_pending = hit222 let purge_pending = hit
228 .author223 .author
229 .as_ref()224 .as_ref()
230- .is_some_and(|author| self.chat.pending_builder_purge == Some(author.id));225+ .is_some_and(|author| self.armed(Armed::PurgeUser(author.id)));
231- message_hit_row(hit, pending, purge_pending, entity, palette)226+ message_hit_row(hit, pending, purge_pending, entity, t)
232 })227 })
233 .collect();228 .collect();
234 let list = if rows.is_empty() {229 let list = if rows.is_empty() {
235- crate::gui::parts::empty(w().builder_messages.no_messages, palette.tokens)230+ crate::gui::parts::empty(w().builder_messages.no_messages, t)
236 } else {231 } else {
237 div()232 div()
238 .relative()233 .relative()
@@ -245,24 +240,25 @@ impl Yumush {
245 .top_0()240 .top_0()
246 .bottom_0()241 .bottom_0()
247 .w(px(stroke::LINE))242 .w(px(stroke::LINE))
248- .bg(palette.tokens.thread()),243+ .bg(t.thread()),
249 )244 )
250 .children(rows)245 .children(rows)
251 };246 };
252 247
253 vec![248 vec![
254- card(palette).child(filters).into_any_element(),249+ card().child(filters).into_any_element(),
255- card(palette).child(list).into_any_element(),250+ card().child(list).into_any_element(),
256 ]251 ]
257 }252 }
258 253
259 pub(super) fn search_messages(&mut self, window: &mut Window, cx: &mut Context<Self>) {254 pub(super) fn search_messages(&mut self, window: &mut Window, cx: &mut Context<Self>) {
260- let text = search_text(&self.chat.builder_message_text, cx);255+ let text = search_text(&self.chat.admin.builder_message_text, cx);
261- let Some(user_id) = self.filter_user(&self.chat.builder_message_user, cx) else {256+ let Some(user_id) = self.filter_user(&self.chat.admin.builder_message_user, cx) else {
262 window.push_notification(Notification::error(w().builder_messages.unknown_user), cx);257 window.push_notification(Notification::error(w().builder_messages.unknown_user), cx);
263 return;258 return;
264 };259 };
265- let Some(community_id) = self.filter_community(&self.chat.builder_message_community, cx)260+ let Some(community_id) =
261+ self.filter_community(&self.chat.admin.builder_message_community, cx)
266 else {262 else {
267 window.push_notification(263 window.push_notification(
268 Notification::error(w().builder_messages.unknown_community),264 Notification::error(w().builder_messages.unknown_community),
@@ -270,8 +266,8 @@ impl Yumush {
270 );266 );
271 return;267 return;
272 };268 };
273- let after_ms = start_of_day_ms(&search_text(&self.chat.builder_message_from, cx));269+ let after_ms = start_of_day_ms(&search_text(&self.chat.admin.builder_message_from, cx));
274- let before_ms = end_of_day_ms(&search_text(&self.chat.builder_message_to, cx));270+ let before_ms = end_of_day_ms(&search_text(&self.chat.admin.builder_message_to, cx));
275 let text = (!text.is_empty()).then_some(text);271 let text = (!text.is_empty()).then_some(text);
276 let network = self.network.clone();272 let network = self.network.clone();
277 273
@@ -294,7 +290,7 @@ impl Yumush {
294 };290 };
295 291
296 let _ = this.update(cx, |yumush, cx| {292 let _ = this.update(cx, |yumush, cx| {
297- yumush.chat.builder_messages = hits;293+ yumush.chat.admin.builder_messages = hits;
298 cx.notify();294 cx.notify();
299 });295 });
300 })296 })
@@ -307,8 +303,7 @@ impl Yumush {
307 window: &mut Window,303 window: &mut Window,
308 cx: &mut Context<Self>,304 cx: &mut Context<Self>,
309 ) {305 ) {
310- if !confirmed(&mut self.chat.pending_message_delete, message_id) {306+ if !self.arm(Armed::DeleteMessage(message_id), cx) {
311- cx.notify();
312 return;307 return;
313 }308 }
314 let network = self.network.clone();309 let network = self.network.clone();
@@ -319,6 +314,7 @@ impl Yumush {
319 let _ = this.update(cx, |yumush, cx| {314 let _ = this.update(cx, |yumush, cx| {
320 yumush315 yumush
321 .chat316 .chat
317+ .admin
322 .builder_messages318 .builder_messages
323 .retain(|hit| hit.message.id != message_id);319 .retain(|hit| hit.message.id != message_id);
324 cx.notify();320 cx.notify();
crates/client/src/gui/builder/overview.rsmodified+38 -61
@@ -8,14 +8,14 @@ use gpui_kit::{Context, Div, IntoElement, ParentElement, Styled, Window, div, px
8 use jiff::Timestamp;8 use jiff::Timestamp;
9 use std::time::Duration;9 use std::time::Duration;
10 10
11-use super::ui::{card, card_header, stat_tile};11+use super::ui::{caption_text, card, card_header, stat_tile};
12 use crate::gui::{12 use crate::gui::{
13- Palette, Yumush,13+ Yumush,
14 builder::BuilderTab,14 builder::BuilderTab,
15 chat::View,15 chat::View,
16 storage,16 storage,
17- style::{radius, size, space, text},17+ style::{Tokens, radius, size, space},
18- text, voice_stats,18+ voice_stats,
19 };19 };
20 use crate::lang::w;20 use crate::lang::w;
21 21
@@ -35,15 +35,12 @@ fn day_label(day: u64) -> String {
35 .unwrap_or_default()35 .unwrap_or_default()
36 }36 }
37 37
38-fn tile_row(tiles: &[(&str, String)], palette: Palette) -> Div {38+fn tile_row(tiles: &[(&str, String)], t: Tokens) -> Div {
39- div()39+ div().flex().gap(px(space::MD)).children(
40- .flex()40+ tiles
41- .gap(px(space::MD))41+ .iter()
42- .children(tiles.iter().map(|(label, value)| {42+ .map(|(label, value)| stat_tile(label, value, t).flex_1().min_w(px(size::SIDEBAR))),
43- stat_tile(label, value, palette)43+ )
44- .flex_1()
45- .min_w(px(size::SIDEBAR))
46- }))
47 }44 }
48 45
49 fn bar_chart(46 fn bar_chart(
@@ -51,7 +48,7 @@ fn bar_chart(
51 stats: &[DayStat],48 stats: &[DayStat],
52 value: fn(&DayStat) -> u64,49 value: fn(&DayStat) -> u64,
53 summary: u64,50 summary: u64,
54- palette: Palette,51+ t: Tokens,
55 ) -> Div {52 ) -> Div {
56 let values: Vec<u64> = stats.iter().map(value).collect();53 let values: Vec<u64> = stats.iter().map(value).collect();
57 let maximum = values.iter().copied().max().unwrap_or_default();54 let maximum = values.iter().copied().max().unwrap_or_default();
@@ -64,19 +61,13 @@ fn bar_chart(
64 .map(|stat| day_label(stat.day))61 .map(|stat| day_label(stat.day))
65 .unwrap_or_default();62 .unwrap_or_default();
66 63
67- card(palette)64+ card()
68 .flex_1()65 .flex_1()
69 .min_w_0()66 .min_w_0()
70 .child(card_header(67 .child(card_header(
71 title,68 title,
72- vec![69+ vec![caption_text(summary.to_string(), t.dim()).into_any_element()],
73- div()70+ t,
74- .text_size(text(text::CAPTION))
75- .text_color(palette.muted)
76- .child(summary.to_string())
77- .into_any_element(),
78- ],
79- palette,
80 ))71 ))
81 .child(72 .child(
82 div()73 div()
@@ -85,12 +76,7 @@ fn bar_chart(
85 .flex()76 .flex()
86 .flex_col()77 .flex_col()
87 .gap(px(space::XS))78 .gap(px(space::XS))
88- .child(79+ .child(caption_text(maximum.to_string(), t.dim()))
89- div()
90- .text_size(text(text::CAPTION))
91- .text_color(palette.muted)
92- .child(maximum.to_string()),
93- )
94 .child(80 .child(
95 div()81 div()
96 .h(px(CHART_HEIGHT))82 .h(px(CHART_HEIGHT))
@@ -99,11 +85,11 @@ fn bar_chart(
99 .gap(px(space::XXS))85 .gap(px(space::XXS))
100 .children(values.iter().map(|&value| {86 .children(values.iter().map(|&value| {
101 let (height, color) = if value == 0 {87 let (height, color) = if value == 0 {
102- (space::XXS, palette.hover)88+ (space::XXS, t.hov())
103 } else {89 } else {
104 (90 (
105 (CHART_HEIGHT * value as f32 / maximum as f32).max(space::XXS),91 (CHART_HEIGHT * value as f32 / maximum as f32).max(space::XXS),
106- palette.accent,92+ t.paper(),
107 )93 )
108 };94 };
109 95
@@ -118,38 +104,36 @@ fn bar_chart(
118 div()104 div()
119 .pt(px(space::XS))105 .pt(px(space::XS))
120 .border_t_1()106 .border_t_1()
121- .border_color(palette.border)107+ .border_color(t.thread())
122 .flex()108 .flex()
123 .justify_between()109 .justify_between()
124- .text_size(text(text::CAPTION))110+ .child(caption_text(first, t.dim()))
125- .text_color(palette.muted)111+ .child(caption_text(last, t.dim())),
126- .child(first)
127- .child(last),
128 ),112 ),
129 )113 )
130 }114 }
131 115
132 impl Yumush {116 impl Yumush {
133 fn watch_server_stats(&mut self, cx: &mut Context<Self>) {117 fn watch_server_stats(&mut self, cx: &mut Context<Self>) {
134- if self.chat.server_stats_task.is_some() {118+ if self.chat.admin.server_stats_task.is_some() {
135 return;119 return;
136 }120 }
137 let network = self.network.clone();121 let network = self.network.clone();
138- self.chat.server_stats_task = Some(cx.spawn(async move |this, cx| {122+ self.chat.admin.server_stats_task = Some(cx.spawn(async move |this, cx| {
139 loop {123 loop {
140 let open = this124 let open = this
141 .update(cx, |yumush, _| {125 .update(cx, |yumush, _| {
142- yumush.chat.view == View::Builder126+ yumush.chat.session.view == View::Builder
143- && yumush.chat.builder_tab == BuilderTab::Overview127+ && yumush.chat.admin.builder_tab == BuilderTab::Overview
144 })128 })
145 .unwrap_or(false);129 .unwrap_or(false);
146 if !open {130 if !open {
147- let _ = this.update(cx, |yumush, _| yumush.chat.server_stats_task = None);131+ let _ = this.update(cx, |yumush, _| yumush.chat.admin.server_stats_task = None);
148 break;132 break;
149 }133 }
150 if let Ok(stats) = network.call(GetServerStats).await {134 if let Ok(stats) = network.call(GetServerStats).await {
151 let _ = this.update(cx, |yumush, cx| {135 let _ = this.update(cx, |yumush, cx| {
152- yumush.chat.server_stats = Some(stats);136+ yumush.chat.admin.server_stats = Some(stats);
153 cx.notify();137 cx.notify();
154 });138 });
155 }139 }
@@ -170,18 +154,18 @@ impl Yumush {
170 ))154 ))
171 },155 },
172 |yumush, (overview, stats), cx| {156 |yumush, (overview, stats), cx| {
173- yumush.chat.builder_overview = Some(overview);157+ yumush.chat.admin.builder_overview = Some(overview);
174- yumush.chat.builder_stats = stats;158+ yumush.chat.admin.builder_stats = stats;
175 cx.notify();159 cx.notify();
176 },160 },
177 );161 );
178 }162 }
179 163
180- pub(super) fn overview_rows(&self, palette: Palette) -> Vec<Div> {164+ pub(super) fn overview_rows(&self, t: Tokens) -> Vec<Div> {
181- let Some(overview) = &self.chat.builder_overview else {165+ let Some(overview) = &self.chat.admin.builder_overview else {
182 return Vec::new();166 return Vec::new();
183 };167 };
184- let stats = &self.chat.builder_stats;168+ let stats = &self.chat.admin.builder_stats;
185 let active = stats.last().map_or(0, |stat| stat.active_users);169 let active = stats.last().map_or(0, |stat| stat.active_users);
186 let messages = stats.iter().map(|stat| stat.messages).sum::<u64>();170 let messages = stats.iter().map(|stat| stat.messages).sum::<u64>();
187 171
@@ -200,10 +184,7 @@ impl Yumush {
200 ),184 ),
201 ];185 ];
202 186
203- let mut rows: Vec<Div> = tiles187+ let mut rows: Vec<Div> = tiles.chunks(3).map(|chunk| tile_row(chunk, t)).collect();
204- .chunks(3)
205- .map(|chunk| tile_row(chunk, palette))
206- .collect();
207 rows.push(188 rows.push(
208 div()189 div()
209 .flex()190 .flex()
@@ -213,29 +194,25 @@ impl Yumush {
213 stats,194 stats,
214 |stat| stat.active_users,195 |stat| stat.active_users,
215 active,196 active,
216- palette,197+ t,
217 ))198 ))
218 .child(bar_chart(199 .child(bar_chart(
219 w().common.messages,200 w().common.messages,
220 stats,201 stats,
221 |stat| stat.messages,202 |stat| stat.messages,
222 messages,203 messages,
223- palette,204+ t,
224 )),205 )),
225 );206 );
226- if let Some(stats) = &self.chat.server_stats {207+ if let Some(stats) = &self.chat.admin.server_stats {
227 rows.push(208 rows.push(
228- card(palette)209+ card()
229- .child(card_header(210+ .child(card_header(w().builder_overview.server, Vec::new(), t))
230- w().builder_overview.server,
231- Vec::new(),
232- palette,
233- ))
234 .child(div().pt(px(space::SM)).child(voice_stats::stats_panel(211 .child(div().pt(px(space::SM)).child(voice_stats::stats_panel(
235 stats,212 stats,
236 &|id| self.chat.name_of(id),213 &|id| self.chat.name_of(id),
237 voice_stats::Detail::Full,214 voice_stats::Detail::Full,
238- palette,215+ t,
239 ))),216 ))),
240 );217 );
241 }218 }
crates/client/src/gui/builder/releases.rsmodified+72 -87
@@ -1,23 +1,26 @@
1 use common::{1 use common::{
2 call::{ImportRelease, ListReleases, PublishRelease, SetReleaseRequired},2 call::{ImportRelease, ListReleases, PublishRelease, SetReleaseRequired},
3 error::ReleaseProblem,3 error::ReleaseProblem,
4- model::{ReleaseInfo, Staged},4+ model::{BackupInfo, ReleaseInfo, Staged},
5 update::{Sha, Side},5 update::{Sha, Side},
6 };6 };
7 use gpui_kit::{7 use gpui_kit::{
8- AnyElement, Context, Div, Entity, Hsla, IntoElement, ParentElement, PathPromptOptions, Styled,8+ AnyElement, Context, Div, Entity, IntoElement, ParentElement, PathPromptOptions, Styled,
9 Window,9 Window,
10 component::{WindowExt as _, notification::Notification},10 component::{WindowExt as _, notification::Notification},
11 div, px, uniform_list,11 div, px, uniform_list,
12 };12 };
13 use std::path::PathBuf;13 use std::path::PathBuf;
14 14
15-use super::ui::{card, card_header, confirmed, delete_icon_button, list_row, rows_body};15+use super::{
16+ reports::Punish,
17+ ui::{caption_text, card, card_header, delete_icon_button, list_row, rows_body},
18+};
16 use crate::gui::{19 use crate::gui::{
17- Palette, Yumush, entity_action, millis_time, notify_error,20+ Yumush, entity_action, millis_time, notify_error,
18 parts::{self, Fill, Press},21 parts::{self, Fill, Press},
19 storage,22 storage,
20- style::{size, space, text},23+ style::{Tokens, size, space, text},
21 text,24 text,
22 widget::field,25 widget::field,
23 };26 };
@@ -31,9 +34,13 @@ pub(crate) struct Desk {
31 next: u64,34 next: u64,
32 required: bool,35 required: bool,
33 publishing: bool,36 publishing: bool,
37+ pub(super) tagging: bool,
34 releases: Vec<ReleaseInfo>,38 releases: Vec<ReleaseInfo>,
35- pending_required: Option<u64>,39+ pub(super) pending_required: Option<u64>,
36- importing: Option<String>,40+ pub(super) importing: Option<String>,
41+ pub(super) backups: Vec<BackupInfo>,
42+ pub(super) pending_backup: Option<String>,
43+ pub(super) punish: Option<Punish>,
37 pub(super) live: super::ci_view::Live,44 pub(super) live: super::ci_view::Live,
38 }45 }
39 46
@@ -88,30 +95,17 @@ impl Desk {
88 fn draft(&mut self, id: u64) -> Option<&mut Draft> {95 fn draft(&mut self, id: u64) -> Option<&mut Draft> {
89 self.drafts.iter_mut().find(|draft| draft.id == id)96 self.drafts.iter_mut().find(|draft| draft.id == id)
90 }97 }
91-}
92-
93-pub(super) fn caption_text(value: impl Into<String>, color: Hsla) -> Div {
94- div()
95- .text_size(text(text::CAPTION))
96- .text_color(color)
97- .child(value.into())
98-}
99 98
100-pub(super) fn meter(share: f32, label: String, palette: Palette) -> Div {99+ pub(in crate::gui) fn connected(&mut self) {
101- div()100+ self.importing = None;
102- .w(px(METER))101+ }
103- .flex()
104- .items_center()
105- .gap(px(space::SM))
106- .child(parts::track(Fill::Part(share), false, palette.tokens))
107- .child(caption_text(label, palette.muted))
108 }102 }
109 103
110-fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, palette: Palette) -> Div {104+fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, t: Tokens) -> Div {
111 let id = draft.id;105 let id = draft.id;
112 let status = match &draft.stage {106 let status = match &draft.stage {
113 Stage::Uploading(sent) if *sent >= draft.size => {107 Stage::Uploading(sent) if *sent >= draft.size => {
114- caption_text(w().builder_release.compressing, palette.muted)108+ caption_text(w().builder_release.compressing, t.dim())
115 }109 }
116 Stage::Uploading(sent) => {110 Stage::Uploading(sent) => {
117 let share = *sent as f32 / draft.size.max(1) as f32;111 let share = *sent as f32 / draft.size.max(1) as f32;
@@ -119,10 +113,10 @@ fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, palette: P
119 .flex()113 .flex()
120 .items_center()114 .items_center()
121 .gap(px(space::SM))115 .gap(px(space::SM))
122- .child(parts::track(Fill::Part(share), false, palette.tokens))116+ .child(parts::track(Fill::Part(share), false, t))
123- .child(caption_text(format!("{:.0}%", share * 100.), palette.muted))117+ .child(caption_text(format!("{:.0}%", share * 100.), t.dim()))
124 }118 }
125- Stage::Ready(_) if duplicate => caption_text(w().builder_release.duplicate, palette.danger),119+ Stage::Ready(_) if duplicate => caption_text(w().builder_release.duplicate, t.bad()),
126 Stage::Ready(staged) => caption_text(120 Stage::Ready(staged) => caption_text(
127 format!(121 format!(
128 "{} · {} → {}",122 "{} · {} → {}",
@@ -130,9 +124,9 @@ fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, palette: P
130 storage(staged.size),124 storage(staged.size),
131 storage(staged.packed)125 storage(staged.packed)
132 ),126 ),
133- palette.muted,127+ t.dim(),
134 ),128 ),
135- Stage::Failed(error) => caption_text(error.clone(), palette.danger),129+ Stage::Failed(error) => caption_text(error.clone(), t.bad()),
136 };130 };
137 131
138 list_row()132 list_row()
@@ -146,7 +140,7 @@ fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, palette: P
146 div()140 div()
147 .truncate()141 .truncate()
148 .text_size(text(text::LABEL))142 .text_size(text(text::LABEL))
149- .text_color(palette.text)143+ .text_color(t.paper())
150 .child(draft.name.clone()),144 .child(draft.name.clone()),
151 )145 )
152 .child(status),146 .child(status),
@@ -154,17 +148,12 @@ fn draft_row(draft: &Draft, duplicate: bool, entity: &Entity<Yumush>, palette: P
154 .child(delete_icon_button(148 .child(delete_icon_button(
155 format!("remove_draft_{id}"),149 format!("remove_draft_{id}"),
156 false,150 false,
157- palette,151+ t,
158 entity_action(entity, move |yumush, _, cx| yumush.remove_draft(id, cx)),152 entity_action(entity, move |yumush, _, cx| yumush.remove_draft(id, cx)),
159 ))153 ))
160 }154 }
161 155
162-fn release_row(156+fn release_row(release: &ReleaseInfo, pending: bool, entity: &Entity<Yumush>, t: Tokens) -> Div {
163- release: &ReleaseInfo,
164- pending: bool,
165- entity: &Entity<Yumush>,
166- palette: Palette,
167-) -> Div {
168 let seq = release.seq;157 let seq = release.seq;
169 let required = release.required;158 let required = release.required;
170 let targets = release159 let targets = release
@@ -178,7 +167,7 @@ fn release_row(
178 format!("confirm_release_{seq}"),167 format!("confirm_release_{seq}"),
179 w().builder_release.confirm,168 w().builder_release.confirm,
180 Press::Danger,169 Press::Danger,
181- palette.tokens,170+ t,
182 entity_action(entity, move |yumush, window, cx| {171 entity_action(entity, move |yumush, window, cx| {
183 yumush.set_release_required(seq, true, window, cx)172 yumush.set_release_required(seq, true, window, cx)
184 }),173 }),
@@ -189,7 +178,7 @@ fn release_row(
189 format!("release_required_{seq}"),178 format!("release_required_{seq}"),
190 w().builder_release.required,179 w().builder_release.required,
191 required,180 required,
192- palette.tokens,181+ t,
193 entity_action(entity, move |yumush, window, cx| {182 entity_action(entity, move |yumush, window, cx| {
194 yumush.toggle_release_required(seq, !required, window, cx)183 yumush.toggle_release_required(seq, !required, window, cx)
195 }),184 }),
@@ -203,43 +192,35 @@ fn release_row(
203 div()192 div()
204 .w(px(size::CONTROL * 1.5))193 .w(px(size::CONTROL * 1.5))
205 .text_size(text(text::LABEL))194 .text_size(text(text::LABEL))
206- .text_color(palette.text)195+ .text_color(t.paper())
207 .child(format!("#{seq}")),196 .child(format!("#{seq}")),
208 )197 )
209 .child(caption_text(198 .child(caption_text(
210 millis_time(release.created_ms, w().common.date),199 millis_time(release.created_ms, w().common.date),
211- palette.muted,200+ t.dim(),
212 ))201 ))
213- .child(202+ .child(caption_text(targets, t.dim()).flex_1().min_w_0().truncate())
214- caption_text(targets, palette.muted)
215- .flex_1()
216- .min_w_0()
217- .truncate(),
218- )
219 .child(control)203 .child(control)
220 }204 }
221 205
222 impl Yumush {206 impl Yumush {
223- pub(super) fn releases_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {207+ pub(super) fn releases_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
224- let mut body = vec![self.import_card(entity, palette).into_any_element()];208+ let mut body = vec![self.import_card(entity, t).into_any_element()];
225- body.extend(209+ body.extend(self.ci_card(entity, t).map(IntoElement::into_any_element));
226- self.ci_card(entity, palette)
227- .map(IntoElement::into_any_element),
228- );
229 if !self.desk.drafts.is_empty() {210 if !self.desk.drafts.is_empty() {
230- body.push(self.draft_card(entity, palette).into_any_element());211+ body.push(self.draft_card(entity, t).into_any_element());
231 }212 }
232- body.push(self.releases_card(entity, palette).into_any_element());213+ body.push(self.releases_card(entity, t).into_any_element());
233 body214 body
234 }215 }
235 216
236- fn import_card(&self, entity: &Entity<Self>, palette: Palette) -> Div {217+ fn import_card(&self, entity: &Entity<Self>, t: Tokens) -> Div {
237 let w = &w().builder_release;218 let w = &w().builder_release;
238 let import = parts::button(219 let import = parts::button(
239 "import_release",220 "import_release",
240 w.import,221 w.import,
241 Press::Plain,222 Press::Plain,
242- palette.tokens,223+ t,
243 entity_action(entity, |yumush, window, cx| {224 entity_action(entity, |yumush, window, cx| {
244 let tag = yumush.release_tag_text(cx);225 let tag = yumush.release_tag_text(cx);
245 yumush.import_tag(tag, window, cx)226 yumush.import_tag(tag, window, cx)
@@ -249,38 +230,38 @@ impl Yumush {
249 "build_release",230 "build_release",
250 w.build,231 w.build,
251 Press::Primary,232 Press::Primary,
252- palette.tokens,233+ t,
253 entity_action(entity, |yumush, window, cx| yumush.create_tag(window, cx)),234 entity_action(entity, |yumush, window, cx| yumush.create_tag(window, cx)),
254 );235 );
255 let status = self236 let status = self
256 .desk237 .desk
257 .importing238 .importing
258 .as_ref()239 .as_ref()
259- .map(|tag| caption_text(format!("{} {tag}", w.importing), palette.muted));240+ .map(|tag| caption_text(format!("{} {tag}", w.importing), t.dim()));
260- card(palette).child(241+ card().child(
261 list_row()242 list_row()
262- .child(field(palette, &self.release_tag).w(px(METER)))243+ .child(field(t, &self.release_tag).w(px(METER)))
263 .children(status)244 .children(status)
264 .child(div().flex_1())245 .child(div().flex_1())
265 .child(if self.desk.importing.is_none() {246 .child(if self.desk.importing.is_none() {
266 import247 import
267 } else {248 } else {
268- import.opacity(0.4)249+ import.opacity(parts::DISABLED)
269 })250 })
270- .child(if self.desk.live.tagging() {251+ .child(if self.desk.tagging {
271- build.opacity(0.4)252+ build.opacity(parts::DISABLED)
272 } else {253 } else {
273 build254 build
274 }),255 }),
275 )256 )
276 }257 }
277 258
278- fn required_toggle(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {259+ fn required_toggle(&self, entity: &Entity<Self>, t: Tokens) -> impl IntoElement {
279 parts::labeled_toggle(260 parts::labeled_toggle(
280 "release_required",261 "release_required",
281 w().builder_release.required,262 w().builder_release.required,
282 self.desk.required,263 self.desk.required,
283- palette.tokens,264+ t,
284 entity_action(entity, |yumush, window, cx| {265 entity_action(entity, |yumush, window, cx| {
285 yumush.desk.required = !yumush.desk.required;266 yumush.desk.required = !yumush.desk.required;
286 window.refresh();267 window.refresh();
@@ -289,13 +270,13 @@ impl Yumush {
289 )270 )
290 }271 }
291 272
292- fn draft_card(&self, entity: &Entity<Self>, palette: Palette) -> Div {273+ fn draft_card(&self, entity: &Entity<Self>, t: Tokens) -> Div {
293 let w = &w().builder_release;274 let w = &w().builder_release;
294 let drafts = &self.desk.drafts;275 let drafts = &self.desk.drafts;
295 let rows: Vec<Div> = drafts276 let rows: Vec<Div> = drafts
296 .iter()277 .iter()
297 .enumerate()278 .enumerate()
298- .map(|(index, draft)| draft_row(draft, is_duplicate(drafts, index), entity, palette))279+ .map(|(index, draft)| draft_row(draft, is_duplicate(drafts, index), entity, t))
299 .collect();280 .collect();
300 let publish = [281 let publish = [
301 ("publish_server", w.server, Side::Server),282 ("publish_server", w.server, Side::Server),
@@ -307,7 +288,7 @@ impl Yumush {
307 id,288 id,
308 label,289 label,
309 Press::Primary,290 Press::Primary,
310- palette.tokens,291+ t,
311 entity_action(entity, move |yumush, window, cx| {292 entity_action(entity, move |yumush, window, cx| {
312 yumush.publish_release(side, window, cx)293 yumush.publish_release(side, window, cx)
313 }),294 }),
@@ -315,44 +296,44 @@ impl Yumush {
315 if self.desk.picked(side).is_some() {296 if self.desk.picked(side).is_some() {
316 button297 button
317 } else {298 } else {
318- button.opacity(0.4)299+ button.opacity(parts::DISABLED)
319 }300 }
320 });301 });
321 let discard = parts::button(302 let discard = parts::button(
322 "discard_release",303 "discard_release",
323 w.discard,304 w.discard,
324 Press::Plain,305 Press::Plain,
325- palette.tokens,306+ t,
326 entity_action(entity, |yumush, _, cx| {307 entity_action(entity, |yumush, _, cx| {
327 yumush.desk.drafts.clear();308 yumush.desk.drafts.clear();
328 yumush.desk.required = false;309 yumush.desk.required = false;
329 cx.notify();310 cx.notify();
330 }),311 }),
331 );312 );
332- card(palette)313+ card()
333 .child(card_header(314 .child(card_header(
334 &format!("#{} · {}", self.desk.next_seq(), w.ready),315 &format!("#{} · {}", self.desk.next_seq(), w.ready),
335 Vec::new(),316 Vec::new(),
336- palette,317+ t,
337 ))318 ))
338 .child(div().flex().flex_col().children(rows))319 .child(div().flex().flex_col().children(rows))
339 .child(320 .child(
340 list_row()321 list_row()
341- .child(self.required_toggle(entity, palette))322+ .child(self.required_toggle(entity, t))
342 .child(div().flex_1())323 .child(div().flex_1())
343 .child(discard)324 .child(discard)
344 .children(publish),325 .children(publish),
345 )326 )
346 }327 }
347 328
348- fn releases_card(&self, entity: &Entity<Self>, palette: Palette) -> Div {329+ fn releases_card(&self, entity: &Entity<Self>, t: Tokens) -> Div {
349 let count = self.desk.releases.len();330 let count = self.desk.releases.len();
350- let header = card_header(w().builder_release.published, Vec::new(), palette);331+ let header = card_header(w().builder_release.published, Vec::new(), t);
351 if count == 0 {332 if count == 0 {
352- return card(palette).child(header).child(rows_body(333+ return card().child(header).child(rows_body(
353 Vec::new(),334 Vec::new(),
354 w().builder_release.no_releases,335 w().builder_release.no_releases,
355- palette,336+ t,
356 ));337 ));
357 }338 }
358 let list = {339 let list = {
@@ -360,17 +341,15 @@ impl Yumush {
360 uniform_list("published_releases", count, move |range, _, cx| {341 uniform_list("published_releases", count, move |range, _, cx| {
361 let yumush = entity.read(cx);342 let yumush = entity.read(cx);
362 let pending = yumush.desk.pending_required;343 let pending = yumush.desk.pending_required;
363- let palette = crate::gui::palette(cx);344+ let t = Tokens::of(cx);
364 yumush.desk.releases[range]345 yumush.desk.releases[range]
365 .iter()346 .iter()
366- .map(|release| {347+ .map(|release| release_row(release, pending == Some(release.seq), &entity, t))
367- release_row(release, pending == Some(release.seq), &entity, palette)
368- })
369 .collect()348 .collect()
370 })349 })
371 .h(px((count as f32 * size::ROW).min(size::PAGE)))350 .h(px((count as f32 * size::ROW).min(size::PAGE)))
372 };351 };
373- card(palette).child(header).child(list)352+ card().child(header).child(list)
374 }353 }
375 354
376 pub(super) fn load_releases(&mut self, window: &mut Window, cx: &mut Context<Self>) {355 pub(super) fn load_releases(&mut self, window: &mut Window, cx: &mut Context<Self>) {
@@ -492,10 +471,14 @@ impl Yumush {
492 471
493 pub(in crate::gui) fn release_imported(472 pub(in crate::gui) fn release_imported(
494 &mut self,473 &mut self,
474+ tag: &str,
495 result: Result<Vec<Staged>, ReleaseProblem>,475 result: Result<Vec<Staged>, ReleaseProblem>,
496 window: &mut Window,476 window: &mut Window,
497 cx: &mut Context<Self>,477 cx: &mut Context<Self>,
498 ) {478 ) {
479+ if self.desk.importing.as_deref() != Some(tag) {
480+ return;
481+ }
499 self.desk.importing = None;482 self.desk.importing = None;
500 match result {483 match result {
501 Ok(staged) if staged.is_empty() => {484 Ok(staged) if staged.is_empty() => {
@@ -541,6 +524,7 @@ impl Yumush {
541 yumush.desk.required = false;524 yumush.desk.required = false;
542 yumush.desk.publishing = false;525 yumush.desk.publishing = false;
543 yumush.load_releases(window, cx);526 yumush.load_releases(window, cx);
527+ cx.notify();
544 });528 });
545 }529 }
546 Err(error) => {530 Err(error) => {
@@ -562,11 +546,12 @@ impl Yumush {
562 window: &mut Window,546 window: &mut Window,
563 cx: &mut Context<Self>,547 cx: &mut Context<Self>,
564 ) {548 ) {
565- if required && !confirmed(&mut self.desk.pending_required, seq) {549+ if required {
550+ self.desk.pending_required = Some(seq);
566 cx.notify();551 cx.notify();
567- return;552+ } else {
553+ self.set_release_required(seq, false, window, cx);
568 }554 }
569- self.set_release_required(seq, required, window, cx);
570 }555 }
571 556
572 fn set_release_required(557 fn set_release_required(
crates/client/src/gui/builder/reports.rsmodified+125 -126
@@ -4,23 +4,23 @@ use std::future::Future;
4 4
5 use common::{5 use common::{
6 call::{BanUser, DeleteMessage, HandleReport, ListReports, TimeoutUser},6 call::{BanUser, DeleteMessage, HandleReport, ListReports, TimeoutUser},
7- model::{BanScope, Report, ReportStatus},7+ model::{BanScope, Hue, Report, ReportStatus},
8 };8 };
9 use gpui_kit::{9 use gpui_kit::{
10 AnyElement, Context, Div, Entity, FontWeight, Hsla, IntoElement, ParentElement, Styled, Window,10 AnyElement, Context, Div, Entity, FontWeight, Hsla, IntoElement, ParentElement, Styled, Window,
11 div, px,11 div, px,
12 };12 };
13 13
14-use super::ui::{list_card, pill};14+use super::ui::{caption_text, confirmed, list_card, pill};
15 use crate::{15 use crate::{
16 gui::{16 gui::{
17- Palette, Yumush, avatar, badge, clickable,17+ Yumush, avatar, badge, clickable,
18 community_settings::user_name,18 community_settings::user_name,
19- entity_action, millis_time, notify_error,19+ entity_action, glyph, millis_time, notify_error,
20 parts::{self, Press},20 parts::{self, Press},
21 profile::user_link,21 profile::user_link,
22 settings_page::{segment, segment_track},22 settings_page::{segment, segment_track},
23- style::{radius, size, space, text},23+ style::{Tokens, radius, size, space, text},
24 text as text_fn,24 text as text_fn,
25 },25 },
26 net::{Fail, NetworkHandle},26 net::{Fail, NetworkHandle},
@@ -33,11 +33,17 @@ const REPORT_FILTERS: [Option<ReportStatus>; 4] = [
33 None,33 None,
34 ];34 ];
35 35
36-fn status_color(status: ReportStatus, palette: Palette) -> Hsla {36+#[derive(Clone, Copy, PartialEq, Eq)]
37+pub(super) enum Punish {
38+ Timeout(Id),
39+ Ban(Id),
40+}
41+
42+fn status_color(status: ReportStatus, t: Tokens) -> Hsla {
37 match status {43 match status {
38- ReportStatus::Open => palette.accent,44+ ReportStatus::Open => t.paper(),
39- ReportStatus::Resolved => palette.ok,45+ ReportStatus::Resolved => t.hue(Hue::Mint),
40- ReportStatus::Dismissed => palette.muted,46+ ReportStatus::Dismissed => t.dim(),
41 }47 }
42 }48 }
43 49
@@ -55,42 +61,42 @@ impl Yumush {
55 .map(|reports| reports.len())61 .map(|reports| reports.len())
56 },62 },
57 |yumush, count, cx| {63 |yumush, count, cx| {
58- yumush.chat.open_reports = count;64+ yumush.chat.admin.open_reports = count;
59 cx.notify();65 cx.notify();
60 },66 },
61 );67 );
62 }68 }
63 69
64 pub(super) fn load_reports(&self, window: &mut Window, cx: &mut Context<Self>) {70 pub(super) fn load_reports(&self, window: &mut Window, cx: &mut Context<Self>) {
65- let status = self.chat.report_filter;71+ let status = self.chat.admin.report_filter;
66 self.fetch_builder(72 self.fetch_builder(
67 window,73 window,
68 cx,74 cx,
69 move |network| async move { network.call(ListReports { status }).await },75 move |network| async move { network.call(ListReports { status }).await },
70 |yumush, reports, cx| {76 |yumush, reports, cx| {
71- yumush.chat.builder_reports = reports;77+ yumush.chat.admin.builder_reports = reports;
72 cx.notify();78 cx.notify();
73 },79 },
74 );80 );
75 }81 }
76 82
77- pub(super) fn refresh_reports(&self, window: &mut Window, cx: &mut Context<Self>) {83+ fn refresh_reports(&self, window: &mut Window, cx: &mut Context<Self>) {
78 self.load_reports(window, cx);84 self.load_reports(window, cx);
79 self.load_open_reports(window, cx);85 self.load_open_reports(window, cx);
80 }86 }
81 87
82- pub(super) fn select_report_filter(88+ fn select_report_filter(
83 &mut self,89 &mut self,
84 status: Option<ReportStatus>,90 status: Option<ReportStatus>,
85 window: &mut Window,91 window: &mut Window,
86 cx: &mut Context<Self>,92 cx: &mut Context<Self>,
87 ) {93 ) {
88- self.chat.report_filter = status;94+ self.chat.admin.report_filter = status;
89 self.load_reports(window, cx);95 self.load_reports(window, cx);
90 cx.notify();96 cx.notify();
91 }97 }
92 98
93- pub(super) fn report_action<Fut>(99+ fn report_action<Fut>(
94 &mut self,100 &mut self,
95 window: &mut Window,101 window: &mut Window,
96 cx: &mut Context<Self>,102 cx: &mut Context<Self>,
@@ -109,7 +115,7 @@ impl Yumush {
109 .detach();115 .detach();
110 }116 }
111 117
112- pub(super) fn handle_report(118+ fn handle_report(
113 &mut self,119 &mut self,
114 report_id: Id,120 report_id: Id,
115 status: ReportStatus,121 status: ReportStatus,
@@ -121,7 +127,7 @@ impl Yumush {
121 });127 });
122 }128 }
123 129
124- pub(super) fn delete_report_message(130+ fn delete_report_message(
125 &mut self,131 &mut self,
126 message_id: Id,132 message_id: Id,
127 window: &mut Window,133 window: &mut Window,
@@ -132,93 +138,89 @@ impl Yumush {
132 });138 });
133 }139 }
134 140
135- pub(super) fn timeout_report_target(141+ fn punish_report(
136 &mut self,142 &mut self,
137- user_id: Id,143+ punish: Punish,
138- window: &mut Window,
139- cx: &mut Context<Self>,
140- ) {
141- self.report_action(window, cx, move |network| async move {
142- network
143- .call(TimeoutUser {
144- user_id,
145- minutes: 60,
146- })
147- .await
148- });
149- }
150-
151- pub(super) fn ban_report_target(
152- &mut self,
153- user_id: Id,
154 reason: &str,144 reason: &str,
155 window: &mut Window,145 window: &mut Window,
156 cx: &mut Context<Self>,146 cx: &mut Context<Self>,
157 ) {147 ) {
158- let reason = reason.to_string();148+ if !confirmed(&mut self.desk.punish, punish) {
159- self.report_action(window, cx, move |network| async move {149+ cx.notify();
160- network150+ return;
161- .call(BanUser {151+ }
162- user_id,152+ match punish {
163- reason: Some(reason),153+ Punish::Timeout(user_id) => self.report_action(window, cx, move |network| async move {
164- scope: BanScope::Account,154+ network
165- })155+ .call(TimeoutUser {
166- .await156+ user_id,
167- });157+ minutes: 60,
158+ })
159+ .await
160+ }),
161+ Punish::Ban(user_id) => {
162+ let reason = reason.to_string();
163+ self.report_action(window, cx, move |network| async move {
164+ network
165+ .call(BanUser {
166+ user_id,
167+ reason: Some(reason),
168+ scope: BanScope::Account,
169+ })
170+ .await
171+ });
172+ }
173+ }
168 }174 }
169 175
170- pub(super) fn report_filters(&self, entity: &Entity<Self>, palette: Palette) -> Div {176+ fn report_filters(&self, entity: &Entity<Self>, t: Tokens) -> Div {
171- div().flex().child(177+ div()
172- segment_track(palette).children(REPORT_FILTERS.map(|status| {178+ .flex()
179+ .child(segment_track(t).children(REPORT_FILTERS.map(|status| {
173 let label = status.map_or(w().builder_reports.all, ReportStatus::label);180 let label = status.map_or(w().builder_reports.all, ReportStatus::label);
174 segment(181 segment(
175 clickable(182 clickable(
176 label,183 label,
177- palette,184+ t,
178 entity_action(entity, move |yumush, window, cx| {185 entity_action(entity, move |yumush, window, cx| {
179 yumush.select_report_filter(status, window, cx)186 yumush.select_report_filter(status, window, cx)
180 }),187 }),
181 ),188 ),
182- self.chat.report_filter == status,189+ self.chat.admin.report_filter == status,
183- palette,190+ t,
184 )191 )
185 .px(px(space::MD))192 .px(px(space::MD))
186 .child(label)193 .child(label)
187- })),194+ })))
188- )
189 }195 }
190 196
191- pub(super) fn reports_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {197+ pub(super) fn reports_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
192 let rows: Vec<Div> = self198 let rows: Vec<Div> = self
193 .chat199 .chat
200+ .admin
194 .builder_reports201 .builder_reports
195 .iter()202 .iter()
196- .map(|report| self.report_row(report, entity, palette))203+ .map(|report| self.report_row(report, entity, t))
197 .collect();204 .collect();
198 205
199 vec![206 vec![
200- self.report_filters(entity, palette).into_any_element(),207+ self.report_filters(entity, t).into_any_element(),
201- list_card(None, rows, w().builder_reports.no_reports, palette).into_any_element(),208+ list_card(None, rows, w().builder_reports.no_reports, t).into_any_element(),
202 ]209 ]
203 }210 }
204 211
205- pub(super) fn report_row(212+ fn report_row(&self, report: &Report, entity: &Entity<Self>, t: Tokens) -> Div {
206- &self,
207- report: &Report,
208- entity: &Entity<Self>,
209- palette: Palette,
210- ) -> Div {
211 let target_avatar = match &report.target {213 let target_avatar = match &report.target {
212 Some(user) => avatar(214 Some(user) => avatar(
213- palette,215+ t,
214 user,216 user,
215 px(size::AVATAR),217 px(size::AVATAR),
216 text_fn(text::CAPTION),218 text_fn(text::CAPTION),
217- &self.chat.avatars,219+ &self.chat.session.avatars,
218 )220 )
219 .into_any_element(),221 .into_any_element(),
220 None => badge(222 None => badge(
221- palette,223+ t,
222 report.id,224 report.id,
223 w().builder_reports.someone,225 w().builder_reports.someone,
224 px(size::AVATAR),226 px(size::AVATAR),
@@ -248,42 +250,36 @@ impl Yumush {
248 .child(user_name(&report.target).to_string()),250 .child(user_name(&report.target).to_string()),
249 ),251 ),
250 ))252 ))
251- .child(pill(253+ .child(pill(report.status.label(), status_color(report.status, t)))
252- report.status.label(),
253- status_color(report.status, palette),
254- palette,
255- ))
256 .child(user_link(254 .child(user_link(
257 format!("report_reporter_{}", report.id),255 format!("report_reporter_{}", report.id),
258 report.reporter.as_ref(),256 report.reporter.as_ref(),
259 entity,257 entity,
260 div()258 div()
261 .text_size(text_fn(text::CAPTION))259 .text_size(text_fn(text::CAPTION))
262- .text_color(palette.muted)260+ .text_color(t.dim())
263 .truncate()261 .truncate()
264 .child(w().builder_reports.reported_by(user_name(&report.reporter))),262 .child(w().builder_reports.reported_by(user_name(&report.reporter))),
265 ));263 ));
266- let meta = div()264+ let meta = caption_text(
267- .flex_shrink_0()265+ format!(
268- .text_size(text_fn(text::CAPTION))
269- .text_color(palette.muted)
270- .child(format!(
271 "{} · {}",266 "{} · {}",
272 report267 report
273 .community268 .community
274 .as_deref()269 .as_deref()
275 .unwrap_or(w().builder_reports.deleted_community),270 .unwrap_or(w().builder_reports.deleted_community),
276 millis_time(report.created_at, crate::lang::w().common.stamp)271 millis_time(report.created_at, crate::lang::w().common.stamp)
277- ));272+ ),
278- let actions = self.report_actions(report, entity, palette);273+ t.dim(),
274+ )
275+ .flex_shrink_0();
276+ let actions = self.report_actions(report, entity, t);
279 let handled = (report.status != ReportStatus::Open).then(|| {277 let handled = (report.status != ReportStatus::Open).then(|| {
280- div()278+ caption_text(
281- .text_size(text_fn(text::CAPTION))279+ w().builder_reports
282- .text_color(palette.muted)280+ .handled_by(user_name(&report.handled_by)),
283- .child(281+ t.dim(),
284- w().builder_reports282+ )
285- .handled_by(user_name(&report.handled_by)),
286- )
287 });283 });
288 284
289 div()285 div()
@@ -303,10 +299,10 @@ impl Yumush {
303 .child(299 .child(
304 div()300 div()
305 .text_size(text_fn(text::LABEL))301 .text_size(text_fn(text::LABEL))
306- .text_color(palette.body)302+ .text_color(t.paper())
307- .child(super::super::glyph::wrapped(303+ .child(glyph::wrapped(
308 report.reason.clone().into(),304 report.reason.clone().into(),
309- super::super::text(super::super::style::text::LABEL),305+ text_fn(text::LABEL),
310 )),306 )),
311 )307 )
312 .children(report.body.as_ref().map(|body| {308 .children(report.body.as_ref().map(|body| {
@@ -314,14 +310,11 @@ impl Yumush {
314 .px(px(space::SM))310 .px(px(space::SM))
315 .py(px(space::SM))311 .py(px(space::SM))
316 .rounded(px(radius::MD))312 .rounded(px(radius::MD))
317- .bg(palette.window)313+ .bg(t.ground())
318 .text_size(text_fn(text::CAPTION))314 .text_size(text_fn(text::CAPTION))
319- .text_color(palette.muted)315+ .text_color(t.dim())
320 .line_clamp(2)316 .line_clamp(2)
321- .child(super::super::glyph::wrapped(317+ .child(glyph::wrapped(body.clone().into(), text_fn(text::CAPTION)))
322- body.clone().into(),
323- super::super::text(super::super::style::text::CAPTION),
324- ))
325 }))318 }))
326 .children(handled)319 .children(handled)
327 .children((!actions.is_empty()).then(|| {320 .children((!actions.is_empty()).then(|| {
@@ -334,35 +327,30 @@ impl Yumush {
334 }))327 }))
335 }328 }
336 329
337- pub(super) fn report_actions(330+ fn report_actions(&self, report: &Report, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
338- &self,
339- report: &Report,
340- entity: &Entity<Self>,
341- palette: Palette,
342- ) -> Vec<AnyElement> {
343 if report.status != ReportStatus::Open {331 if report.status != ReportStatus::Open {
344 return Vec::new();332 return Vec::new();
345 }333 }
346- let resolve_id = report.id;334+ let report_id = report.id;
347- let dismiss_id = report.id;335+ let words = &w().builder_reports;
348 let mut buttons = vec![336 let mut buttons = vec![
349 parts::button(337 parts::button(
350- format!("resolve_report_{}", report.id),338+ format!("resolve_report_{report_id}"),
351- w().builder_reports.resolve,339+ words.resolve,
352 Press::Plain,340 Press::Plain,
353- palette.tokens,341+ t,
354 entity_action(entity, move |yumush, window, cx| {342 entity_action(entity, move |yumush, window, cx| {
355- yumush.handle_report(resolve_id, ReportStatus::Resolved, window, cx)343+ yumush.handle_report(report_id, ReportStatus::Resolved, window, cx)
356 }),344 }),
357 )345 )
358 .into_any_element(),346 .into_any_element(),
359 parts::button(347 parts::button(
360- format!("dismiss_report_{}", report.id),348+ format!("dismiss_report_{report_id}"),
361- w().builder_reports.dismiss,349+ words.dismiss,
362 Press::Plain,350 Press::Plain,
363- palette.tokens,351+ t,
364 entity_action(entity, move |yumush, window, cx| {352 entity_action(entity, move |yumush, window, cx| {
365- yumush.handle_report(dismiss_id, ReportStatus::Dismissed, window, cx)353+ yumush.handle_report(report_id, ReportStatus::Dismissed, window, cx)
366 }),354 }),
367 )355 )
368 .into_any_element(),356 .into_any_element(),
@@ -370,10 +358,10 @@ impl Yumush {
370 if let (Some(message_id), Some(_)) = (report.message_id, report.community_id) {358 if let (Some(message_id), Some(_)) = (report.message_id, report.community_id) {
371 buttons.push(359 buttons.push(
372 parts::button(360 parts::button(
373- format!("delete_report_message_{}", report.id),361+ format!("delete_report_message_{report_id}"),
374- w().builder_reports.delete_message,362+ words.delete_message,
375 Press::Plain,363 Press::Plain,
376- palette.tokens,364+ t,
377 entity_action(entity, move |yumush, window, cx| {365 entity_action(entity, move |yumush, window, cx| {
378 yumush.delete_report_message(message_id, window, cx)366 yumush.delete_report_message(message_id, window, cx)
379 }),367 }),
@@ -382,29 +370,40 @@ impl Yumush {
382 );370 );
383 }371 }
384 if let Some(target) = &report.target {372 if let Some(target) = &report.target {
385- let timeout_id = target.id;373+ let user_id = target.id;
386- let ban_id = target.id;374+ let reason = report.reason.clone();
387- let ban_reason = report.reason.clone();375+ let armed = self.desk.punish;
376+ let timeout = Punish::Timeout(user_id);
377+ let ban = Punish::Ban(user_id);
378+ let timeout_reason = reason.clone();
388 buttons.push(379 buttons.push(
389 parts::button(380 parts::button(
390- format!("timeout_report_{}", report.id),381+ format!("timeout_report_{report_id}_{}", armed == Some(timeout)),
391- w().builder_reports.timeout,382+ if armed == Some(timeout) {
383+ w().builder_ui.confirm
384+ } else {
385+ words.timeout
386+ },
392 Press::Plain,387 Press::Plain,
393- palette.tokens,388+ t,
394 entity_action(entity, move |yumush, window, cx| {389 entity_action(entity, move |yumush, window, cx| {
395- yumush.timeout_report_target(timeout_id, window, cx)390+ yumush.punish_report(timeout, &timeout_reason, window, cx)
396 }),391 }),
397 )392 )
398 .into_any_element(),393 .into_any_element(),
399 );394 );
400 buttons.push(395 buttons.push(
401 parts::button(396 parts::button(
402- format!("ban_report_{}", report.id),397+ format!("ban_report_{report_id}_{}", armed == Some(ban)),
403- w().builder_reports.ban,398+ if armed == Some(ban) {
399+ w().builder_ui.confirm
400+ } else {
401+ words.ban
402+ },
404 Press::Danger,403 Press::Danger,
405- palette.tokens,404+ t,
406 entity_action(entity, move |yumush, window, cx| {405 entity_action(entity, move |yumush, window, cx| {
407- yumush.ban_report_target(ban_id, &ban_reason, window, cx)406+ yumush.punish_report(ban, &reason, window, cx)
408 }),407 }),
409 )408 )
410 .into_any_element(),409 .into_any_element(),
crates/client/src/gui/builder/server.rsmodified+129 -128
@@ -1,4 +1,5 @@
1 use crate::gui::glyph::Fill as _;1 use crate::gui::glyph::Fill as _;
2+use crate::gui::style::Tokens;
2 use common::{3 use common::{
3 call::{RestartServer, UpdateServerSettings},4 call::{RestartServer, UpdateServerSettings},
4 model::ServerSettings,5 model::ServerSettings,
@@ -8,9 +9,12 @@ use gpui_kit::{
8 component::{WindowExt, input::InputState, notification::Notification},9 component::{WindowExt, input::InputState, notification::Notification},
9 };10 };
10 11
11-use super::ui::{field_row, list_card, number, to_bytes, to_units};12+use super::{
13+ BuilderTab,
14+ ui::{field_row, list_card, number, to_bytes, to_units},
15+};
12 use crate::gui::{16 use crate::gui::{
13- KB, MB, Palette, Yumush,17+ KB, MB, Yumush,
14 chat::Armed,18 chat::Armed,
15 notify_error,19 notify_error,
16 settings_page::{delete_control, segmented},20 settings_page::{delete_control, segmented},
@@ -39,95 +43,93 @@ impl Yumush {
39 let Some(settings) = self.server.clone() else {43 let Some(settings) = self.server.clone() else {
40 return;44 return;
41 };45 };
42- self.chat.server_registration_open = settings.registration_open;46+ self.chat.admin.server_registration_open = settings.registration_open;
43- self.chat.server_maintenance = settings.maintenance;47+ self.chat.admin.server_maintenance = settings.maintenance;
44 let chat = &self.chat;48 let chat = &self.chat;
45- set_input(&chat.server_name, &settings.name, window, cx);49+ let fields = [
46- set_input(50+ (&chat.admin.server_name, settings.name.clone()),
47- &chat.server_limit,51+ (
48- &to_units(settings.max_attachment_bytes, MB as u64),52+ &chat.admin.server_limit,
49- window,53+ to_units(settings.max_attachment_bytes, MB as u64),
50- cx,54+ ),
51- );55+ (
52- set_input(56+ &chat.admin.server_user_quota,
53- &chat.server_user_quota,57+ to_units(settings.user_quota_bytes, MB as u64),
54- &to_units(settings.user_quota_bytes, MB as u64),58+ ),
55- window,59+ (
56- cx,60+ &chat.admin.server_community_quota,
57- );61+ to_units(settings.community_quota_bytes, MB as u64),
58- set_input(62+ ),
59- &chat.server_community_quota,63+ (
60- &to_units(settings.community_quota_bytes, MB as u64),64+ &chat.admin.server_message_retention,
61- window,65+ settings.message_retention_days.to_string(),
62- cx,66+ ),
63- );67+ (
64- set_input(68+ &chat.admin.server_attachment_retention,
65- &chat.server_message_retention,69+ settings.attachment_retention_days.to_string(),
66- &settings.message_retention_days.to_string(),70+ ),
67- window,71+ (
68- cx,72+ &chat.admin.server_announcement,
69- );73+ settings.announcement.clone(),
70- set_input(74+ ),
71- &chat.server_attachment_retention,75+ (
72- &settings.attachment_retention_days.to_string(),76+ &chat.admin.server_max_communities,
73- window,77+ settings.max_communities_per_user.to_string(),
74- cx,78+ ),
75- );79+ (
76- set_input(80+ &chat.admin.server_max_message_length,
77- &chat.server_announcement,81+ settings.max_message_length.to_string(),
78- &settings.announcement,82+ ),
79- window,83+ (
80- cx,84+ &chat.admin.server_max_avatar,
81- );85+ to_units(settings.max_avatar_bytes, KB as u64),
82- set_input(86+ ),
83- &chat.server_max_communities,87+ (
84- &settings.max_communities_per_user.to_string(),88+ &chat.admin.server_messages_per_minute,
85- window,89+ settings.messages_per_minute.to_string(),
86- cx,90+ ),
87- );91+ (
88- set_input(92+ &chat.admin.server_logins_per_minute,
89- &chat.server_max_message_length,93+ settings.logins_per_minute.to_string(),
90- &settings.max_message_length.to_string(),94+ ),
91- window,95+ ];
92- cx,96+ for (input, text) in fields {
93- );97+ set_input(input, &text, window, cx);
94- set_input(98+ }
95- &chat.server_max_avatar,99+ }
96- &to_units(settings.max_avatar_bytes, KB as u64),100+
97- window,101+ pub(in crate::gui) fn set_server(
98- cx,102+ &mut self,
99- );103+ settings: ServerSettings,
100- set_input(104+ window: Option<&mut Window>,
101- &chat.server_messages_per_minute,105+ cx: &mut Context<Self>,
102- &settings.messages_per_minute.to_string(),106+ ) {
103- window,107+ self.server = Some(settings);
104- cx,108+ if let Some(window) = window
105- );109+ && self.chat.admin.builder_tab == BuilderTab::Server
106- set_input(110+ {
107- &chat.server_logins_per_minute,111+ self.fill_server_form(window, cx);
108- &settings.logins_per_minute.to_string(),112+ }
109- window,113+ cx.notify();
110- cx,
111- );
112 }114 }
113 115
114 pub(super) fn server_form(&self, cx: &App) -> Option<ServerSettings> {116 pub(super) fn server_form(&self, cx: &App) -> Option<ServerSettings> {
115 let chat = &self.chat;117 let chat = &self.chat;
116 Some(ServerSettings {118 Some(ServerSettings {
117- name: input_text(&chat.server_name, cx),119+ name: input_text(&chat.admin.server_name, cx),
118- registration_open: chat.server_registration_open,120+ registration_open: chat.admin.server_registration_open,
119- max_attachment_bytes: input_bytes(&chat.server_limit, MB as u64, cx)?,121+ max_attachment_bytes: input_bytes(&chat.admin.server_limit, MB as u64, cx)?,
120- maintenance: chat.server_maintenance,122+ maintenance: chat.admin.server_maintenance,
121- user_quota_bytes: input_bytes(&chat.server_user_quota, MB as u64, cx)?,123+ user_quota_bytes: input_bytes(&chat.admin.server_user_quota, MB as u64, cx)?,
122- community_quota_bytes: input_bytes(&chat.server_community_quota, MB as u64, cx)?,124+ community_quota_bytes: input_bytes(&chat.admin.server_community_quota, MB as u64, cx)?,
123- message_retention_days: input_number(&chat.server_message_retention, cx)?,125+ message_retention_days: input_number(&chat.admin.server_message_retention, cx)?,
124- attachment_retention_days: input_number(&chat.server_attachment_retention, cx)?,126+ attachment_retention_days: input_number(&chat.admin.server_attachment_retention, cx)?,
125- announcement: input_text(&chat.server_announcement, cx),127+ announcement: input_text(&chat.admin.server_announcement, cx),
126- max_communities_per_user: input_number(&chat.server_max_communities, cx)?,128+ max_communities_per_user: input_number(&chat.admin.server_max_communities, cx)?,
127- max_message_length: input_number(&chat.server_max_message_length, cx)?,129+ max_message_length: input_number(&chat.admin.server_max_message_length, cx)?,
128- max_avatar_bytes: input_bytes(&chat.server_max_avatar, KB as u64, cx)?,130+ max_avatar_bytes: input_bytes(&chat.admin.server_max_avatar, KB as u64, cx)?,
129- messages_per_minute: input_number(&chat.server_messages_per_minute, cx)?,131+ messages_per_minute: input_number(&chat.admin.server_messages_per_minute, cx)?,
130- logins_per_minute: input_number(&chat.server_logins_per_minute, cx)?,132+ logins_per_minute: input_number(&chat.admin.server_logins_per_minute, cx)?,
131 })133 })
132 }134 }
133 135
@@ -141,9 +143,8 @@ impl Yumush {
141 cx.spawn_in(window, async move |this, cx| {143 cx.spawn_in(window, async move |this, cx| {
142 match network.call(UpdateServerSettings { settings }).await {144 match network.call(UpdateServerSettings { settings }).await {
143 Ok(settings) => {145 Ok(settings) => {
144- let _ = this.update(cx, |yumush, cx| {146+ let _ = this.update_in(cx, |yumush, window, cx| {
145- yumush.server = Some(settings);147+ yumush.set_server(settings, Some(window), cx)
146- cx.notify();
147 });148 });
148 }149 }
149 Err(error) => notify_error(&this, cx, error),150 Err(error) => notify_error(&this, cx, error),
@@ -166,13 +167,13 @@ impl Yumush {
166 cx.notify();167 cx.notify();
167 }168 }
168 169
169- pub(super) fn server_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {170+ pub(super) fn server_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
170 let general = vec![171 let general = vec![
171 field_row(172 field_row(
172 w().builder_server.name,173 w().builder_server.name,
173 None,174 None,
174- field(palette, &self.chat.server_name),175+ field(t, &self.chat.admin.server_name),
175- palette,176+ t,
176 ),177 ),
177 field_row(178 field_row(
178 w().builder_server.registration,179 w().builder_server.registration,
@@ -182,12 +183,12 @@ impl Yumush {
182 (true, w().builder_server.open),183 (true, w().builder_server.open),
183 (false, w().builder_server.closed),184 (false, w().builder_server.closed),
184 ],185 ],
185- self.chat.server_registration_open,186+ self.chat.admin.server_registration_open,
186 entity,187 entity,
187- palette,188+ t,
188- |yumush, open, _| yumush.chat.server_registration_open = open,189+ |yumush, open, _| yumush.chat.admin.server_registration_open = open,
189 ),190 ),
190- palette,191+ t,
191 ),192 ),
192 field_row(193 field_row(
193 w().builder_server.maintenance,194 w().builder_server.maintenance,
@@ -197,92 +198,92 @@ impl Yumush {
197 (false, w().builder_server.off),198 (false, w().builder_server.off),
198 (true, w().builder_server.on),199 (true, w().builder_server.on),
199 ],200 ],
200- self.chat.server_maintenance,201+ self.chat.admin.server_maintenance,
201 entity,202 entity,
202- palette,203+ t,
203- |yumush, on, _| yumush.chat.server_maintenance = on,204+ |yumush, on, _| yumush.chat.admin.server_maintenance = on,
204 ),205 ),
205- palette,206+ t,
206 ),207 ),
207 field_row(208 field_row(
208 w().builder_server.announcement,209 w().builder_server.announcement,
209 None,210 None,
210- field(palette, &self.chat.server_announcement),211+ field(t, &self.chat.admin.server_announcement),
211- palette,212+ t,
212 ),213 ),
213 ];214 ];
214 let limits = vec![215 let limits = vec![
215 field_row(216 field_row(
216 w().builder_server.max_attachment,217 w().builder_server.max_attachment,
217 None,218 None,
218- field(palette, &self.chat.server_limit),219+ field(t, &self.chat.admin.server_limit),
219- palette,220+ t,
220 ),221 ),
221 field_row(222 field_row(
222 w().builder_server.max_avatar,223 w().builder_server.max_avatar,
223 None,224 None,
224- field(palette, &self.chat.server_max_avatar),225+ field(t, &self.chat.admin.server_max_avatar),
225- palette,226+ t,
226 ),227 ),
227 field_row(228 field_row(
228 w().builder_server.max_message_length,229 w().builder_server.max_message_length,
229 None,230 None,
230- field(palette, &self.chat.server_max_message_length),231+ field(t, &self.chat.admin.server_max_message_length),
231- palette,232+ t,
232 ),233 ),
233 field_row(234 field_row(
234 w().builder_server.communities_per_user,235 w().builder_server.communities_per_user,
235 Some(w().builder_server.zero_unlimited),236 Some(w().builder_server.zero_unlimited),
236- field(palette, &self.chat.server_max_communities),237+ field(t, &self.chat.admin.server_max_communities),
237- palette,238+ t,
238 ),239 ),
239 ];240 ];
240 let storage = vec![241 let storage = vec![
241 field_row(242 field_row(
242 w().builder_server.user_quota,243 w().builder_server.user_quota,
243 Some(w().builder_server.zero_unlimited),244 Some(w().builder_server.zero_unlimited),
244- field(palette, &self.chat.server_user_quota),245+ field(t, &self.chat.admin.server_user_quota),
245- palette,246+ t,
246 ),247 ),
247 field_row(248 field_row(
248 w().builder_server.community_quota,249 w().builder_server.community_quota,
249 Some(w().builder_server.zero_unlimited),250 Some(w().builder_server.zero_unlimited),
250- field(palette, &self.chat.server_community_quota),251+ field(t, &self.chat.admin.server_community_quota),
251- palette,252+ t,
252 ),253 ),
253 field_row(254 field_row(
254 w().builder_server.message_retention,255 w().builder_server.message_retention,
255 Some(w().builder_server.zero_off),256 Some(w().builder_server.zero_off),
256- field(palette, &self.chat.server_message_retention),257+ field(t, &self.chat.admin.server_message_retention),
257- palette,258+ t,
258 ),259 ),
259 field_row(260 field_row(
260 w().builder_server.attachment_retention,261 w().builder_server.attachment_retention,
261 Some(w().builder_server.zero_off),262 Some(w().builder_server.zero_off),
262- field(palette, &self.chat.server_attachment_retention),263+ field(t, &self.chat.admin.server_attachment_retention),
263- palette,264+ t,
264 ),265 ),
265 ];266 ];
266 let rate = vec![267 let rate = vec![
267 field_row(268 field_row(
268 w().builder_server.messages_per_minute,269 w().builder_server.messages_per_minute,
269 Some(w().builder_server.zero_off),270 Some(w().builder_server.zero_off),
270- field(palette, &self.chat.server_messages_per_minute),271+ field(t, &self.chat.admin.server_messages_per_minute),
271- palette,272+ t,
272 ),273 ),
273 field_row(274 field_row(
274 w().builder_server.logins_per_minute,275 w().builder_server.logins_per_minute,
275 Some(w().builder_server.zero_off),276 Some(w().builder_server.zero_off),
276- field(palette, &self.chat.server_logins_per_minute),277+ field(t, &self.chat.admin.server_logins_per_minute),
277- palette,278+ t,
278 ),279 ),
279 ];280 ];
280 281
281 vec![282 vec![
282- list_card(Some(w().builder_server.general), general, "", palette).into_any_element(),283+ list_card(Some(w().builder_server.general), general, "", t).into_any_element(),
283- list_card(Some(w().builder_server.limits), limits, "", palette).into_any_element(),284+ list_card(Some(w().builder_server.limits), limits, "", t).into_any_element(),
284- list_card(Some(w().builder_server.storage), storage, "", palette).into_any_element(),285+ list_card(Some(w().builder_server.storage), storage, "", t).into_any_element(),
285- list_card(Some(w().builder_server.rate_limits), rate, "", palette).into_any_element(),286+ list_card(Some(w().builder_server.rate_limits), rate, "", t).into_any_element(),
286 list_card(287 list_card(
287 Some(w().builder_server.process),288 Some(w().builder_server.process),
288 vec![field_row(289 vec![field_row(
@@ -293,13 +294,13 @@ impl Yumush {
293 w().update.restart,294 w().update.restart,
294 self.armed(Armed::RestartServer),295 self.armed(Armed::RestartServer),
295 entity,296 entity,
296- palette,297+ t,
297 Yumush::restart_server,298 Yumush::restart_server,
298 ),299 ),
299- palette,300+ t,
300 )],301 )],
301 "",302 "",
302- palette,303+ t,
303 )304 )
304 .into_any_element(),305 .into_any_element(),
305 ]306 ]
crates/client/src/gui/builder/storage.rsmodified+68 -114
@@ -10,28 +10,19 @@ use gpui_kit::{
10 div, px, relative,10 div, px, relative,
11 };11 };
12 12
13-use super::ui::{13+use super::ui::{card, card_header, delete_icon_button, fixed, list_card, list_row, toolbar};
14- card, card_header, confirmed, delete_icon_button, fixed, list_card, list_row, toolbar,14+use crate::gui::chat::Armed;
15-};
16 use crate::gui::{15 use crate::gui::{
17- Palette, Yumush,16+ Yumush,
18 community_settings::user_name,17 community_settings::user_name,
19 entity_action, millis_time, notify_error, storage,18 entity_action, millis_time, notify_error, storage,
20- style::{radius, size, space, text},19+ style::{Tokens, radius, size, space, text},
21 text,20 text,
22 widget::field,21 widget::field,
23 };22 };
24 use crate::lang::w;23 use crate::lang::w;
25 24
26-fn share(bytes: u64, max: u64) -> f32 {25+fn usage_row(name: &str, bytes: u64, count: u64, fraction: f32, t: Tokens) -> Div {
27- if max == 0 {
28- 0.
29- } else {
30- bytes as f32 / max as f32
31- }
32-}
33-
34-fn usage_row(name: &str, bytes: u64, count: u64, fraction: f32, palette: Palette) -> Div {
35 div()26 div()
36 .px(px(space::LG))27 .px(px(space::LG))
37 .py(px(space::SM))28 .py(px(space::SM))
@@ -49,7 +40,7 @@ fn usage_row(name: &str, bytes: u64, count: u64, fraction: f32, palette: Palette
49 .min_w_0()40 .min_w_0()
50 .truncate()41 .truncate()
51 .text_size(text(text::LABEL))42 .text_size(text(text::LABEL))
52- .text_color(palette.text)43+ .text_color(t.paper())
53 .child(name.to_string()),44 .child(name.to_string()),
54 )45 )
55 .child(46 .child(
@@ -57,7 +48,7 @@ fn usage_row(name: &str, bytes: u64, count: u64, fraction: f32, palette: Palette
57 .flex_shrink_0()48 .flex_shrink_0()
58 .text_size(text(text::LABEL))49 .text_size(text(text::LABEL))
59 .font_weight(FontWeight::MEDIUM)50 .font_weight(FontWeight::MEDIUM)
60- .text_color(palette.text)51+ .text_color(t.paper())
61 .child(storage(bytes)),52 .child(storage(bytes)),
62 )53 )
63 .child(54 .child(
@@ -67,7 +58,7 @@ fn usage_row(name: &str, bytes: u64, count: u64, fraction: f32, palette: Palette
67 .flex()58 .flex()
68 .justify_end()59 .justify_end()
69 .text_size(text(text::CAPTION))60 .text_size(text(text::CAPTION))
70- .text_color(palette.muted)61+ .text_color(t.dim())
71 .child(count.to_string()),62 .child(count.to_string()),
72 ),63 ),
73 )64 )
@@ -75,28 +66,37 @@ fn usage_row(name: &str, bytes: u64, count: u64, fraction: f32, palette: Palette
75 div()66 div()
76 .h(px(space::XXS))67 .h(px(space::XXS))
77 .rounded(px(radius::SM))68 .rounded(px(radius::SM))
78- .bg(palette.hover)69+ .bg(t.hov())
79 .child(70 .child(
80 div()71 div()
81 .h_full()72 .h_full()
82 .w(relative(fraction))73 .w(relative(fraction))
83 .rounded(px(radius::SM))74 .rounded(px(radius::SM))
84- .bg(palette.accent),75+ .bg(t.paper()),
85 ),76 ),
86 )77 )
87 }78 }
88 79
89-fn attachment_row(80+fn usage_card(title: &'static str, rows: Vec<(&str, u64, u64)>, t: Tokens) -> Div {
90- info: &AttachmentInfo,81+ let max = rows.iter().map(|&(_, bytes, _)| bytes).max().unwrap_or(0);
91- pending: bool,82+ let rows = rows
92- entity: &Entity<Yumush>,83+ .into_iter()
93- palette: Palette,84+ .map(|(name, bytes, count)| {
94-) -> Div {85+ usage_row(name, bytes, count, bytes as f32 / max.max(1) as f32, t)
86+ })
87+ .collect();
88+ div()
89+ .flex_1()
90+ .min_w_0()
91+ .child(list_card(Some(title), rows, w().builder_storage.no_data, t).h_full())
92+}
93+
94+fn attachment_row(info: &AttachmentInfo, pending: bool, entity: &Entity<Yumush>, t: Tokens) -> Div {
95 let attachment_id = info.attachment.id;95 let attachment_id = info.attachment.id;
96 let delete = delete_icon_button(96 let delete = delete_icon_button(
97 format!("delete_attachment_{}", info.attachment.id),97 format!("delete_attachment_{}", info.attachment.id),
98 pending,98 pending,
99- palette,99+ t,
100 entity_action(entity, move |yumush, window, cx| {100 entity_action(entity, move |yumush, window, cx| {
101 yumush.delete_builder_attachment(attachment_id, window, cx)101 yumush.delete_builder_attachment(attachment_id, window, cx)
102 }),102 }),
@@ -107,7 +107,7 @@ fn attachment_row(
107 Icon::new(IconName::File)107 Icon::new(IconName::File)
108 .size(px(size::ICON))108 .size(px(size::ICON))
109 .flex_shrink_0()109 .flex_shrink_0()
110- .text_color(palette.muted),110+ .text_color(t.dim()),
111 )111 )
112 .child(112 .child(
113 div()113 div()
@@ -120,7 +120,7 @@ fn attachment_row(
120 div()120 div()
121 .min_w_0()121 .min_w_0()
122 .text_size(text(text::LABEL))122 .text_size(text(text::LABEL))
123- .text_color(palette.text)123+ .text_color(t.paper())
124 .child(super::super::glyph::line(124 .child(super::super::glyph::line(
125 info.attachment.name.clone().into(),125 info.attachment.name.clone().into(),
126 super::super::text(super::super::style::text::LABEL),126 super::super::text(super::super::style::text::LABEL),
@@ -130,7 +130,7 @@ fn attachment_row(
130 div()130 div()
131 .truncate()131 .truncate()
132 .text_size(text(text::CAPTION))132 .text_size(text(text::CAPTION))
133- .text_color(palette.muted)133+ .text_color(t.dim())
134 .child(format!(134 .child(format!(
135 "{} · {} · {}",135 "{} · {} · {}",
136 user_name(&info.uploader),136 user_name(&info.uploader),
@@ -143,96 +143,52 @@ fn attachment_row(
143 div()143 div()
144 .flex_shrink_0()144 .flex_shrink_0()
145 .text_size(text(text::CAPTION))145 .text_size(text(text::CAPTION))
146- .text_color(palette.muted)146+ .text_color(t.dim())
147 .child(storage(info.attachment.size)),147 .child(storage(info.attachment.size)),
148 )148 )
149 .child(delete)149 .child(delete)
150 }150 }
151 151
152 impl Yumush {152 impl Yumush {
153- pub(super) fn storage_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {153+ pub(super) fn storage_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
154- let user_max = self
155- .chat
156- .builder_usage_users
157- .iter()
158- .map(|usage| usage.bytes)
159- .max()
160- .unwrap_or(0);
161- let community_max = self
162- .chat
163- .builder_usage_communities
164- .iter()
165- .map(|usage| usage.bytes)
166- .max()
167- .unwrap_or(0);
168- let users: Vec<Div> = self
169- .chat
170- .builder_usage_users
171- .iter()
172- .map(|usage| {
173- usage_row(
174- &usage.user.username,
175- usage.bytes,
176- usage.count,
177- share(usage.bytes, user_max),
178- palette,
179- )
180- })
181- .collect();
182- let communities: Vec<Div> = self
183- .chat
184- .builder_usage_communities
185- .iter()
186- .map(|usage| {
187- usage_row(
188- &usage.community,
189- usage.bytes,
190- usage.count,
191- share(usage.bytes, community_max),
192- palette,
193- )
194- })
195- .collect();
196 let usage = div()154 let usage = div()
197 .flex()155 .flex()
198 .gap(px(space::XL))156 .gap(px(space::XL))
199- .child(157+ .child(usage_card(
200- div().flex_1().min_w_0().child(158+ w().builder_storage.users,
201- list_card(159+ self.chat
202- Some(w().builder_storage.users),160+ .admin
203- users,161+ .builder_usage_users
204- w().builder_storage.no_data,162+ .iter()
205- palette,163+ .map(|usage| (usage.user.username.as_str(), usage.bytes, usage.count))
206- )164+ .collect(),
207- .h_full(),165+ t,
208- ),166+ ))
209- )167+ .child(usage_card(
210- .child(168+ w().builder_storage.communities,
211- div().flex_1().min_w_0().child(169+ self.chat
212- list_card(170+ .admin
213- Some(w().builder_storage.communities),171+ .builder_usage_communities
214- communities,172+ .iter()
215- w().builder_storage.no_data,173+ .map(|usage| (usage.community.as_str(), usage.bytes, usage.count))
216- palette,174+ .collect(),
217- )175+ t,
218- .h_full(),176+ ));
219- ),
220- );
221 177
222 let controls = toolbar(vec![178 let controls = toolbar(vec![
223 fixed(179 fixed(
224 size::THUMB,180 size::THUMB,
225- field(palette, &self.chat.builder_attachment_user),181+ field(t, &self.chat.admin.builder_attachment_user),
226 ),182 ),
227 fixed(183 fixed(
228 size::THUMB,184 size::THUMB,
229- field(palette, &self.chat.builder_attachment_community),185+ field(t, &self.chat.admin.builder_attachment_community),
230 ),186 ),
231 crate::gui::parts::button(187 crate::gui::parts::button(
232 "search_attachments",188 "search_attachments",
233 w().builder_storage.search,189 w().builder_storage.search,
234 crate::gui::parts::Press::Plain,190 crate::gui::parts::Press::Plain,
235- palette.tokens,191+ t,
236 entity_action(entity, |yumush, window, cx| {192 entity_action(entity, |yumush, window, cx| {
237 yumush.search_attachments(window, cx)193 yumush.search_attachments(window, cx)
238 }),194 }),
@@ -242,37 +198,35 @@ impl Yumush {
242 .into_any_element();198 .into_any_element();
243 let rows: Vec<Div> = self199 let rows: Vec<Div> = self
244 .chat200 .chat
201+ .admin
245 .builder_attachments202 .builder_attachments
246 .iter()203 .iter()
247 .map(|info| {204 .map(|info| {
248- let pending = self.chat.pending_attachment_delete == Some(info.attachment.id);205+ let pending = self.armed(Armed::DeleteAttachment(info.attachment.id));
249- attachment_row(info, pending, entity, palette)206+ attachment_row(info, pending, entity, t)
250 })207 })
251 .collect();208 .collect();
252 let body = if rows.is_empty() {209 let body = if rows.is_empty() {
253- crate::gui::parts::empty(w().builder_storage.no_attachments, palette.tokens)210+ crate::gui::parts::empty(w().builder_storage.no_attachments, t)
254 } else {211 } else {
255 div().flex().flex_col().children(rows)212 div().flex().flex_col().children(rows)
256 };213 };
257- let attachments = card(palette)214+ let attachments = card()
258 .child(card_header(215 .child(card_header(
259 w().builder_storage.attachments,216 w().builder_storage.attachments,
260 vec![controls],217 vec![controls],
261- palette,218+ t,
262 ))219 ))
263 .child(body);220 .child(body);
264 221
265 vec![222 vec![
266 usage.into_any_element(),223 usage.into_any_element(),
267 attachments.into_any_element(),224 attachments.into_any_element(),
268- self.backups_card(entity, palette).into_any_element(),225+ self.backups_card(entity, t).into_any_element(),
269 ]226 ]
270 }227 }
271 228
272 pub(super) fn load_storage(&self, window: &mut Window, cx: &mut Context<Self>) {229 pub(super) fn load_storage(&self, window: &mut Window, cx: &mut Context<Self>) {
273- if !self.is_builder() {
274- return;
275- }
276 self.search_attachments(window, cx);230 self.search_attachments(window, cx);
277 self.load_backups(window, cx);231 self.load_backups(window, cx);
278 self.fetch_builder(232 self.fetch_builder(
@@ -280,19 +234,20 @@ impl Yumush {
280 cx,234 cx,
281 |network| async move { network.storage_usage().await },235 |network| async move { network.storage_usage().await },
282 |yumush, (users, communities), cx| {236 |yumush, (users, communities), cx| {
283- yumush.chat.builder_usage_users = users;237+ yumush.chat.admin.builder_usage_users = users;
284- yumush.chat.builder_usage_communities = communities;238+ yumush.chat.admin.builder_usage_communities = communities;
285 cx.notify();239 cx.notify();
286 },240 },
287 );241 );
288 }242 }
289 243
290 pub(super) fn search_attachments(&self, window: &mut Window, cx: &mut Context<Self>) {244 pub(super) fn search_attachments(&self, window: &mut Window, cx: &mut Context<Self>) {
291- let Some(user_id) = self.filter_user(&self.chat.builder_attachment_user, cx) else {245+ let Some(user_id) = self.filter_user(&self.chat.admin.builder_attachment_user, cx) else {
292 window.push_notification(Notification::error(w().builder_storage.unknown_user), cx);246 window.push_notification(Notification::error(w().builder_storage.unknown_user), cx);
293 return;247 return;
294 };248 };
295- let Some(community_id) = self.filter_community(&self.chat.builder_attachment_community, cx)249+ let Some(community_id) =
250+ self.filter_community(&self.chat.admin.builder_attachment_community, cx)
296 else {251 else {
297 window.push_notification(252 window.push_notification(
298 Notification::error(w().builder_storage.unknown_community),253 Notification::error(w().builder_storage.unknown_community),
@@ -318,7 +273,7 @@ impl Yumush {
318 };273 };
319 274
320 let _ = this.update(cx, |yumush, cx| {275 let _ = this.update(cx, |yumush, cx| {
321- yumush.chat.builder_attachments = attachments;276+ yumush.chat.admin.builder_attachments = attachments;
322 cx.notify();277 cx.notify();
323 });278 });
324 })279 })
@@ -331,8 +286,7 @@ impl Yumush {
331 window: &mut Window,286 window: &mut Window,
332 cx: &mut Context<Self>,287 cx: &mut Context<Self>,
333 ) {288 ) {
334- if !confirmed(&mut self.chat.pending_attachment_delete, attachment_id) {289+ if !self.arm(Armed::DeleteAttachment(attachment_id), cx) {
335- cx.notify();
336 return;290 return;
337 }291 }
338 let network = self.network.clone();292 let network = self.network.clone();
crates/client/src/gui/builder/ui.rsmodified+53 -72
@@ -1,9 +1,6 @@
1-use crate::gui::style::{size, space, text};1+use crate::gui::parts::{self, Fill, Scale, Tone};
2-use crate::gui::{2+use crate::gui::style::{Tokens, size, space, text};
3- Palette, Tooltip as _,3+use crate::gui::{Tooltip as _, text};
4- parts::{self, Scale, Tone},
5- text,
6-};
7 use crate::lang::w;4 use crate::lang::w;
8 use gpui_kit::{5 use gpui_kit::{
9 AnyElement, App, Div, FontWeight, Hsla, IntoElement, ParentElement, Stateful, Styled, Window,6 AnyElement, App, Div, FontWeight, Hsla, IntoElement, ParentElement, Stateful, Styled, Window,
@@ -12,6 +9,7 @@ use gpui_kit::{
12 use jiff::{civil::Date, tz::TimeZone};9 use jiff::{civil::Date, tz::TimeZone};
13 10
14 const LABEL_WIDTH: f32 = 88.;11 const LABEL_WIDTH: f32 = 88.;
12+const METER: f32 = 140.;
15 13
16 pub(super) fn to_bytes(text: &str, unit: u64) -> Option<u64> {14 pub(super) fn to_bytes(text: &str, unit: u64) -> Option<u64> {
17 text.trim().parse::<u64>().ok()?.checked_mul(unit)15 text.trim().parse::<u64>().ok()?.checked_mul(unit)
@@ -43,30 +41,38 @@ pub(super) fn number(text: &str) -> Option<u32> {
43 text.trim().parse().ok()41 text.trim().parse().ok()
44 }42 }
45 43
44+pub(super) fn caption_text(value: impl Into<String>, color: Hsla) -> Div {
45+ div()
46+ .text_size(text(text::CAPTION))
47+ .text_color(color)
48+ .child(value.into())
49+}
50+
51+pub(super) fn meter(share: f32, label: String, t: Tokens) -> Div {
52+ div()
53+ .w(px(METER))
54+ .flex()
55+ .items_center()
56+ .gap(px(space::SM))
57+ .child(parts::track(Fill::Part(share), false, t))
58+ .child(caption_text(label, t.dim()))
59+}
60+
46 pub(super) fn icon_button(61 pub(super) fn icon_button(
47 id: String,62 id: String,
48 icon: IconName,63 icon: IconName,
49 tip: &'static str,64 tip: &'static str,
50 color: Hsla,65 color: Hsla,
51- palette: Palette,66+ t: Tokens,
52 action: impl Fn(&mut Window, &mut App) + 'static,67 action: impl Fn(&mut Window, &mut App) + 'static,
53 ) -> Stateful<Div> {68 ) -> Stateful<Div> {
54- parts::icon_button(69+ parts::icon_button(id, icon, tip, Tone::Idle, Scale::Small, t, action).text_color(color)
55- id,
56- icon,
57- tip,
58- Tone::Idle,
59- Scale::Small,
60- palette.tokens,
61- action,
62- )
63- .text_color(color)
64 }70 }
65 71
66 pub(super) fn delete_icon_button(72 pub(super) fn delete_icon_button(
67 id: String,73 id: String,
68 pending: bool,74 pending: bool,
69- palette: Palette,75+ t: Tokens,
70 action: impl Fn(&mut Window, &mut App) + 'static,76 action: impl Fn(&mut Window, &mut App) + 'static,
71 ) -> Stateful<Div> {77 ) -> Stateful<Div> {
72 icon_button(78 icon_button(
@@ -77,13 +83,11 @@ pub(super) fn delete_icon_button(
77 } else {83 } else {
78 w().builder_ui.delete84 w().builder_ui.delete
79 },85 },
80- palette.danger,86+ t.bad(),
81- palette,87+ t,
82 action,88 action,
83 )89 )
84- .when(pending, |this| {90+ .when(pending, |this| this.bg(t.bad()).text_color(t.ground()))
85- this.bg(palette.danger).text_color(palette.on_accent)
86- })
87 }91 }
88 92
89 pub(super) fn action_button(93 pub(super) fn action_button(
@@ -92,17 +96,17 @@ pub(super) fn action_button(
92 label: &'static str,96 label: &'static str,
93 tip: &'static str,97 tip: &'static str,
94 color: Hsla,98 color: Hsla,
95- palette: Palette,99+ t: Tokens,
96 action: impl Fn(&mut Window, &mut App) + 'static,100 action: impl Fn(&mut Window, &mut App) + 'static,
97 ) -> Stateful<Div> {101 ) -> Stateful<Div> {
98- parts::press(id, palette.tokens, action)102+ parts::press(id, t, action)
99 .tip(tip)103 .tip(tip)
100 .px_0()104 .px_0()
101 .min_w(px(size::THUMB))105 .min_w(px(size::THUMB))
102 .text_size(text(text::CAPTION))106 .text_size(text(text::CAPTION))
103 .font_weight(FontWeight::MEDIUM)107 .font_weight(FontWeight::MEDIUM)
104 .text_color(color)108 .text_color(color)
105- .child(crate::gui::parts::small_icon(icon))109+ .child(parts::small_icon(icon))
106 .child(label)110 .child(label)
107 }111 }
108 112
@@ -112,7 +116,7 @@ pub(super) fn confirm_button(
112 label: &'static str,116 label: &'static str,
113 tip: &'static str,117 tip: &'static str,
114 pending: bool,118 pending: bool,
115- palette: Palette,119+ t: Tokens,
116 action: impl Fn(&mut Window, &mut App) + 'static,120 action: impl Fn(&mut Window, &mut App) + 'static,
117 ) -> Stateful<Div> {121 ) -> Stateful<Div> {
118 action_button(122 action_button(
@@ -128,8 +132,8 @@ pub(super) fn confirm_button(
128 } else {132 } else {
129 tip133 tip
130 },134 },
131- palette.danger,135+ t.bad(),
132- palette,136+ t,
133 action,137 action,
134 )138 )
135 .when(pending, |this| this.font_weight(FontWeight::SEMIBOLD))139 .when(pending, |this| this.font_weight(FontWeight::SEMIBOLD))
@@ -137,7 +141,7 @@ pub(super) fn confirm_button(
137 141
138 pub(super) fn action_group(142 pub(super) fn action_group(
139 title: &'static str,143 title: &'static str,
140- palette: Palette,144+ t: Tokens,
141 children: Vec<AnyElement>,145 children: Vec<AnyElement>,
142 ) -> Option<Div> {146 ) -> Option<Div> {
143 if children.is_empty() {147 if children.is_empty() {
@@ -158,7 +162,7 @@ pub(super) fn action_group(
158 .items_center()162 .items_center()
159 .text_size(text(text::CAPTION))163 .text_size(text(text::CAPTION))
160 .font_weight(FontWeight::MEDIUM)164 .font_weight(FontWeight::MEDIUM)
161- .text_color(palette.muted)165+ .text_color(t.dim())
162 .child(title),166 .child(title),
163 )167 )
164 .child(168 .child(
@@ -198,41 +202,32 @@ pub(super) fn end_of_day_ms(text: &str) -> Option<u64> {
198 epoch_ms(date.tomorrow().ok()?)?.checked_sub(1)202 epoch_ms(date.tomorrow().ok()?)?.checked_sub(1)
199 }203 }
200 204
201-pub(super) fn rows_body(rows: Vec<Div>, none: &str, palette: Palette) -> Div {205+pub(super) fn rows_body(rows: Vec<Div>, none: &str, t: Tokens) -> Div {
202 if rows.is_empty() {206 if rows.is_empty() {
203- return crate::gui::parts::empty(none, palette.tokens);207+ return parts::empty(none, t);
204 }208 }
205 div().flex().flex_col().children(rows)209 div().flex().flex_col().children(rows)
206 }210 }
207 211
208-pub(super) fn card(_palette: Palette) -> Div {212+pub(super) fn card() -> Div {
209 div().flex().flex_col()213 div().flex().flex_col()
210 }214 }
211 215
212-pub(super) fn card_header(title: &str, actions: Vec<AnyElement>, palette: Palette) -> Div {216+pub(super) fn card_header(title: &str, actions: Vec<AnyElement>, t: Tokens) -> Div {
213 div()217 div()
214 .pb(px(space::XS))218 .pb(px(space::XS))
215 .flex()219 .flex()
216 .items_center()220 .items_center()
217 .justify_between()221 .justify_between()
218 .gap(px(space::SM))222 .gap(px(space::SM))
219- .child(crate::gui::parts::section(223+ .child(parts::section(title.to_string(), t))
220- title.to_string(),
221- palette.tokens,
222- ))
223 .children(actions)224 .children(actions)
224 }225 }
225 226
226-pub(super) fn list_card(title: Option<&str>, rows: Vec<Div>, none: &str, palette: Palette) -> Div {227+pub(super) fn list_card(title: Option<&str>, rows: Vec<Div>, none: &str, t: Tokens) -> Div {
227- let body = if rows.is_empty() {228+ card()
228- crate::gui::parts::empty(none, palette.tokens)229+ .children(title.map(|title| card_header(title, Vec::new(), t)))
229- } else {230+ .child(rows_body(rows, none, t))
230- div().flex().flex_col().children(rows)
231- };
232-
233- card(palette)
234- .children(title.map(|title| card_header(title, Vec::new(), palette)))
235- .child(body)
236 }231 }
237 232
238 pub(super) fn list_row() -> Div {233 pub(super) fn list_row() -> Div {
@@ -253,28 +248,23 @@ pub(super) fn toolbar(items: Vec<AnyElement>) -> Div {
253 .children(items)248 .children(items)
254 }249 }
255 250
256-pub(super) fn stat_tile(label: &str, value: &str, palette: Palette) -> Div {251+pub(super) fn stat_tile(label: &str, value: &str, t: Tokens) -> Div {
257- card(palette)252+ card()
258 .gap(px(space::XXS))253 .gap(px(space::XXS))
259 .child(254 .child(
260 div()255 div()
261 .text_size(text(text::DISPLAY))256 .text_size(text(text::DISPLAY))
262- .text_color(palette.text)257+ .text_color(t.paper())
263 .child(value.to_string()),258 .child(value.to_string()),
264 )259 )
265- .child(260+ .child(caption_text(label.to_string(), t.dim()))
266- div()
267- .text_size(text(text::CAPTION))
268- .text_color(palette.muted)
269- .child(label.to_string()),
270- )
271 }261 }
272 262
273 pub(super) fn field_row(263 pub(super) fn field_row(
274 label: &str,264 label: &str,
275 hint: Option<&str>,265 hint: Option<&str>,
276 control: impl IntoElement,266 control: impl IntoElement,
277- palette: Palette,267+ t: Tokens,
278 ) -> Div {268 ) -> Div {
279 list_row()269 list_row()
280 .justify_between()270 .justify_between()
@@ -287,23 +277,14 @@ pub(super) fn field_row(
287 .child(277 .child(
288 div()278 div()
289 .text_size(text(text::LABEL))279 .text_size(text(text::LABEL))
290- .text_color(palette.text)280+ .text_color(t.paper())
291 .child(label.to_string()),281 .child(label.to_string()),
292 )282 )
293- .children(hint.map(|hint| {283+ .children(hint.map(|hint| caption_text(hint.to_string(), t.dim()))),
294- div()
295- .text_size(text(text::CAPTION))
296- .text_color(palette.muted)
297- .child(hint.to_string())
298- })),
299 )284 )
300 .child(div().w(px(size::SIDEBAR)).flex_shrink_0().child(control))285 .child(div().w(px(size::SIDEBAR)).flex_shrink_0().child(control))
301 }286 }
302 287
303-pub(super) fn pill(label: &str, color: Hsla, palette: Palette) -> Div {288+pub(super) fn pill(label: &str, color: Hsla) -> Div {
304- let _ = palette;289+ caption_text(label.to_string(), color)
305- div()
306- .text_size(text(text::CAPTION))
307- .text_color(color)
308- .child(label.to_string())
309 }290 }
crates/client/src/gui/builder/users.rsmodified+618 -645
@@ -7,7 +7,9 @@ use common::{
7 ListUpdateClients, PurgeUser, RenameUser, ResetPassword, RevokeSession, RevokeSessions,7 ListUpdateClients, PurgeUser, RenameUser, ResetPassword, RevokeSession, RevokeSessions,
8 SuspendUser, TimeoutUser,8 SuspendUser, TimeoutUser,
9 },9 },
10- model::{Account, BanScope, Role, SessionInfo, UpdateClient, UpdateState, User},10+ model::{
11+ Account, BanScope, Hue, Role, SessionInfo, Suspension, UpdateClient, UpdateState, User,
12+ },
11 permission,13 permission,
12 stats::Stats,14 stats::Stats,
13 time::{DAY_MILLIS, HOUR_MILLIS, MINUTE_MILLIS, now_ms},15 time::{DAY_MILLIS, HOUR_MILLIS, MINUTE_MILLIS, now_ms},
@@ -23,17 +25,17 @@ use gpui_kit::{
23 };25 };
24 26
25 use super::BuilderTab;27 use super::BuilderTab;
26-use super::releases::{caption_text, meter};28+use super::ui::{
27-use super::ui::{action_button, action_group, card, confirm_button, confirmed, pill};29+ action_button, action_group, caption_text, card, confirm_button, meter, number, pill, rows_body,
30+};
31+use crate::gui::chat::{Armed, admin::UserEdit};
28 use crate::lang::w;32 use crate::lang::w;
29 use crate::{33 use crate::{
30 gui::{34 gui::{
31- Palette, Tooltip as _, Yumush, avatar,35+ Tooltip as _, Yumush, avatar, clickable, entity_action, millis_time, notify_error,
32- chat::View,
33- clickable, entity_action, millis_time, notify_error,
34 parts::{self, Press},36 parts::{self, Press},
35 profile::user_link,37 profile::user_link,
36- style::{radius, size, space, text},38+ style::{Tokens, radius, size, space, text},
37 text,39 text,
38 widget::{field, search_text},40 widget::{field, search_text},
39 },41 },
@@ -61,15 +63,31 @@ fn seen_text(last_seen: Option<u64>) -> String {
61 }63 }
62 }64 }
63 65
64-fn status(label: &str, color: gpui_kit::Hsla, palette: Palette) -> Div {66+fn status(label: &str, color: gpui_kit::Hsla) -> Div {
65- div().flex_shrink_0().child(pill(label, color, palette))67+ div().flex_shrink_0().child(pill(label, color))
68+}
69+
70+fn form_row(
71+ input: &Entity<gpui_kit::component::input::InputState>,
72+ t: Tokens,
73+ actions: impl IntoIterator<Item = AnyElement>,
74+) -> Div {
75+ div()
76+ .h(px(size::ROW))
77+ .px(px(space::MD))
78+ .flex()
79+ .items_center()
80+ .gap(px(space::SM))
81+ .child(div().flex_1().min_w_0().child(field(t, input)))
82+ .children(actions)
66 }83 }
67 84
68 impl Yumush {85 impl Yumush {
69 pub(super) fn submit_new_user(&mut self, window: &mut Window, cx: &mut Context<Self>) {86 pub(super) fn submit_new_user(&mut self, window: &mut Window, cx: &mut Context<Self>) {
70- let username = self.chat.new_username.read(cx).text().to_string();87+ let username = self.chat.admin.new_username.read(cx).text().to_string();
71- let password = self.chat.new_password.read(cx).text().to_string();88+ let password = self.chat.admin.new_password.read(cx).text().to_string();
72 self.chat89 self.chat
90+ .admin
73 .new_password91 .new_password
74 .update(cx, |input, cx| input.set_value("", window, cx));92 .update(cx, |input, cx| input.set_value("", window, cx));
75 let network = self.network.clone();93 let network = self.network.clone();
@@ -80,6 +98,7 @@ impl Yumush {
80 let _ = this.update_in(cx, |yumush, window, cx| {98 let _ = this.update_in(cx, |yumush, window, cx| {
81 yumush99 yumush
82 .chat100 .chat
101+ .admin
83 .new_username102 .new_username
84 .update(cx, |input, cx| input.set_value("", window, cx));103 .update(cx, |input, cx| input.set_value("", window, cx));
85 yumush.load_users(window, cx);104 yumush.load_users(window, cx);
@@ -97,8 +116,7 @@ impl Yumush {
97 window: &mut Window,116 window: &mut Window,
98 cx: &mut Context<Self>,117 cx: &mut Context<Self>,
99 ) {118 ) {
100- if !confirmed(&mut self.chat.pending_builder_delete, user_id) {119+ if !self.arm(Armed::BuilderDeleteUser(user_id), cx) {
101- cx.notify();
102 return;120 return;
103 }121 }
104 let network = self.network.clone();122 let network = self.network.clone();
@@ -109,8 +127,12 @@ impl Yumush {
109 let _ = this.update(cx, |yumush, cx| {127 let _ = this.update(cx, |yumush, cx| {
110 yumush128 yumush
111 .chat129 .chat
130+ .admin
112 .builder_users131 .builder_users
113 .retain(|account| account.user.id != user_id);132 .retain(|account| account.user.id != user_id);
133+ if yumush.sessions_open(user_id) {
134+ yumush.close_builder_sessions();
135+ }
114 cx.notify();136 cx.notify();
115 });137 });
116 }138 }
@@ -125,6 +147,7 @@ impl Yumush {
125 window: &mut Window,147 window: &mut Window,
126 cx: &mut Context<Self>,148 cx: &mut Context<Self>,
127 action: impl FnOnce(NetworkHandle) -> Fut + 'static,149 action: impl FnOnce(NetworkHandle) -> Fut + 'static,
150+ done: impl FnOnce(&mut Self, &mut Window, &mut Context<Self>) + 'static,
128 ) where151 ) where
129 Fut: Future<Output = Result<(), Fail>> + 'static,152 Fut: Future<Output = Result<(), Fail>> + 'static,
130 {153 {
@@ -132,7 +155,10 @@ impl Yumush {
132 155
133 cx.spawn_in(window, async move |this, cx| match action(network).await {156 cx.spawn_in(window, async move |this, cx| match action(network).await {
134 Ok(()) => {157 Ok(()) => {
135- let _ = this.update_in(cx, |yumush, window, cx| yumush.load_users(window, cx));158+ let _ = this.update_in(cx, |yumush, window, cx| {
159+ done(yumush, window, cx);
160+ yumush.load_users(window, cx);
161+ });
136 }162 }
137 Err(error) => notify_error(&this, cx, error),163 Err(error) => notify_error(&this, cx, error),
138 })164 })
@@ -146,9 +172,12 @@ impl Yumush {
146 window: &mut Window,172 window: &mut Window,
147 cx: &mut Context<Self>,173 cx: &mut Context<Self>,
148 ) {174 ) {
149- self.builder_user_action(window, cx, move |network| async move {175+ self.builder_user_action(
150- network.call(SuspendUser { user_id, suspended }).await176+ window,
151- });177+ cx,
178+ move |network| async move { network.call(SuspendUser { user_id, suspended }).await },
179+ |_, _, _| {},
180+ );
152 }181 }
153 182
154 pub(super) fn revoke_builder_sessions(183 pub(super) fn revoke_builder_sessions(
@@ -157,9 +186,12 @@ impl Yumush {
157 window: &mut Window,186 window: &mut Window,
158 cx: &mut Context<Self>,187 cx: &mut Context<Self>,
159 ) {188 ) {
160- self.builder_user_action(window, cx, move |network| async move {189+ self.builder_user_action(
161- network.call(RevokeSessions { user_id }).await190+ window,
162- });191+ cx,
192+ move |network| async move { network.call(RevokeSessions { user_id }).await },
193+ |_, _, _| {},
194+ );
163 }195 }
164 196
165 pub(super) fn clear_builder_profile(197 pub(super) fn clear_builder_profile(
@@ -168,22 +200,26 @@ impl Yumush {
168 window: &mut Window,200 window: &mut Window,
169 cx: &mut Context<Self>,201 cx: &mut Context<Self>,
170 ) {202 ) {
171- self.builder_user_action(window, cx, move |network| async move {203+ self.builder_user_action(
172- network.call(ClearProfile { user_id }).await.map(|_| ())204+ window,
173- });205+ cx,
206+ move |network| async move { network.call(ClearProfile { user_id }).await.map(|_| ()) },
207+ |_, _, _| {},
208+ );
174 }209 }
175 210
176 pub(super) fn toggle_builder_stats(&mut self, user_id: Id, cx: &mut Context<Self>) {211 pub(super) fn toggle_builder_stats(&mut self, user_id: Id, cx: &mut Context<Self>) {
177- let target = match self.chat.followed {212+ let target = match self.chat.session.followed {
178 Some((id, _)) if id == user_id => None,213 Some((id, _)) if id == user_id => None,
179 _ => Some(user_id),214 _ => Some(user_id),
180 };215 };
181- self.chat.followed = target.map(|id| (id, Stats::default()));216+ self.chat.session.followed = target.map(|id| (id, Stats::default()));
182 let network = self.network.clone();217 let network = self.network.clone();
183 cx.spawn(async move |this, cx| {218 cx.spawn(async move |this, cx| {
184 let latest = network.call(FollowStats { user_id: target }).await;219 let latest = network.call(FollowStats { user_id: target }).await;
185 let _ = this.update(cx, |yumush, cx| {220 let _ = this.update(cx, |yumush, cx| {
186- if let (Ok(Some(stats)), Some(followed)) = (latest, yumush.chat.followed.as_mut())221+ if let (Ok(Some(stats)), Some(followed)) =
222+ (latest, yumush.chat.session.followed.as_mut())
187 && Some(followed.0) == target223 && Some(followed.0) == target
188 {224 {
189 followed.1 = stats;225 followed.1 = stats;
@@ -195,26 +231,38 @@ impl Yumush {
195 cx.notify();231 cx.notify();
196 }232 }
197 233
198- pub(super) fn toggle_builder_password(&mut self, user_id: Id, cx: &mut Context<Self>) {234+ pub(super) fn toggle_user_edit(&mut self, user_id: Id, edit: UserEdit, cx: &mut Context<Self>) {
199- if self.chat.pending_builder_password == Some(user_id) {235+ let target = Some((user_id, edit));
200- self.chat.pending_builder_password = None;236+ self.chat.admin.editing = if self.chat.admin.editing == target {
237+ None
201 } else {238 } else {
202- self.chat.pending_builder_password = Some(user_id);239+ target
203- }240+ };
204 cx.notify();241 cx.notify();
205 }242 }
206 243
244+ fn edit_open(&self, user_id: Id, edit: UserEdit) -> bool {
245+ self.chat.admin.editing == Some((user_id, edit))
246+ }
247+
207 pub(super) fn reset_builder_password(&mut self, window: &mut Window, cx: &mut Context<Self>) {248 pub(super) fn reset_builder_password(&mut self, window: &mut Window, cx: &mut Context<Self>) {
208- let Some(user_id) = self.chat.pending_builder_password.take() else {249+ let Some((user_id, UserEdit::Password)) = self.chat.admin.editing else {
209 return;250 return;
210 };251 };
211- let password = self.chat.builder_password.read(cx).text().to_string();252+ let password = self.chat.admin.builder_password.read(cx).text().to_string();
212- self.chat253+ self.builder_user_action(
213- .builder_password254+ window,
214- .update(cx, |input, cx| input.set_value("", window, cx));255+ cx,
215- self.builder_user_action(window, cx, move |network| async move {256+ move |network| async move { network.call(ResetPassword { user_id, password }).await },
216- network.call(ResetPassword { user_id, password }).await257+ |yumush, window, cx| {
217- });258+ yumush.chat.admin.editing = None;
259+ yumush
260+ .chat
261+ .admin
262+ .builder_password
263+ .update(cx, |input, cx| input.set_value("", window, cx));
264+ },
265+ );
218 }266 }
219 267
220 pub(super) fn load_sessions(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {268 pub(super) fn load_sessions(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {
@@ -228,8 +276,8 @@ impl Yumush {
228 match network.call(ListSessions { user_id }).await {276 match network.call(ListSessions { user_id }).await {
229 Ok(sessions) => {277 Ok(sessions) => {
230 let _ = this.update(cx, |yumush, cx| {278 let _ = this.update(cx, |yumush, cx| {
231- yumush.chat.builder_sessions = Some((user_id, sessions));279+ yumush.chat.admin.builder_sessions = Some((user_id, sessions));
232- yumush.chat.builder_friends = friends;280+ yumush.chat.admin.builder_friends = friends;
233 cx.notify();281 cx.notify();
234 });282 });
235 }283 }
@@ -239,45 +287,51 @@ impl Yumush {
239 .detach();287 .detach();
240 }288 }
241 289
290+ fn sessions_open(&self, user_id: Id) -> bool {
291+ self.chat
292+ .admin
293+ .builder_sessions
294+ .as_ref()
295+ .is_some_and(|(open, _)| *open == user_id)
296+ }
297+
298+ fn close_builder_sessions(&mut self) {
299+ self.chat.admin.builder_sessions = None;
300+ self.chat.admin.builder_clients.clear();
301+ self.chat.admin.builder_clients_task = None;
302+ }
303+
242 pub(super) fn toggle_builder_sessions(304 pub(super) fn toggle_builder_sessions(
243 &mut self,305 &mut self,
244 user_id: Id,306 user_id: Id,
245 window: &mut Window,307 window: &mut Window,
246 cx: &mut Context<Self>,308 cx: &mut Context<Self>,
247 ) {309 ) {
248- if let Some((followed, _)) = self.chat.followed {310+ if let Some((followed, _)) = self.chat.session.followed {
249 self.toggle_builder_stats(followed, cx);311 self.toggle_builder_stats(followed, cx);
250 }312 }
251- if self313+ if self.sessions_open(user_id) {
252- .chat314+ self.close_builder_sessions();
253- .builder_sessions
254- .as_ref()
255- .is_some_and(|(open, _)| *open == user_id)
256- {
257- self.chat.builder_sessions = None;
258- self.chat.builder_clients.clear();
259- self.chat.builder_clients_task = None;
260 cx.notify();315 cx.notify();
261 return;316 return;
262 }317 }
263 self.load_sessions(user_id, window, cx);318 self.load_sessions(user_id, window, cx);
264- self.chat.builder_clients.clear();319+ self.chat.admin.builder_clients.clear();
265 self.watch_builder_clients(user_id, cx);320 self.watch_builder_clients(user_id, cx);
266 }321 }
267 322
268 fn watch_builder_clients(&mut self, user_id: Id, cx: &mut Context<Self>) {323 fn watch_builder_clients(&mut self, user_id: Id, cx: &mut Context<Self>) {
269 let network = self.network.clone();324 let network = self.network.clone();
270- self.chat.builder_clients_task = Some(cx.spawn(async move |this, cx| {325+ self.chat.admin.builder_clients_task = Some(cx.spawn(async move |this, cx| {
271 loop {326 loop {
272- let Ok(visible) = this.update(cx, |yumush, _| {327+ let Ok(visible) =
273- yumush.chat.view == View::Builder328+ this.update(cx, |yumush, _| yumush.on_builder_tab(BuilderTab::Users))
274- && yumush.chat.builder_tab == BuilderTab::Users329+ else {
275- }) else {
276 break;330 break;
277 };331 };
278 if visible && let Ok(clients) = network.call(ListUpdateClients { user_id }).await {332 if visible && let Ok(clients) = network.call(ListUpdateClients { user_id }).await {
279 let _ = this.update(cx, |yumush, cx| {333 let _ = this.update(cx, |yumush, cx| {
280- yumush.chat.builder_clients = clients;334+ yumush.chat.admin.builder_clients = clients;
281 cx.notify();335 cx.notify();
282 });336 });
283 }337 }
@@ -314,68 +368,56 @@ impl Yumush {
314 .detach();368 .detach();
315 }369 }
316 370
317- pub(super) fn toggle_builder_rename(&mut self, user_id: Id, cx: &mut Context<Self>) {
318- if self.chat.pending_builder_rename == Some(user_id) {
319- self.chat.pending_builder_rename = None;
320- } else {
321- self.chat.pending_builder_rename = Some(user_id);
322- }
323- cx.notify();
324- }
325-
326 pub(super) fn rename_builder_user(&mut self, window: &mut Window, cx: &mut Context<Self>) {371 pub(super) fn rename_builder_user(&mut self, window: &mut Window, cx: &mut Context<Self>) {
327- let Some(user_id) = self.chat.pending_builder_rename.take() else {372+ let Some((user_id, UserEdit::Rename)) = self.chat.admin.editing else {
328 return;373 return;
329 };374 };
330- let username = self.chat.builder_rename.read(cx).text().to_string();375+ let username = self.chat.admin.builder_rename.read(cx).text().to_string();
331- self.chat376+ self.builder_user_action(
332- .builder_rename377+ window,
333- .update(cx, |input, cx| input.set_value("", window, cx));378+ cx,
334- self.builder_user_action(window, cx, move |network| async move {379+ move |network| async move {
335- network380+ network
336- .call(RenameUser { user_id, username })381+ .call(RenameUser { user_id, username })
337- .await382+ .await
338- .map(|_| ())383+ .map(|_| ())
339- });384+ },
340- }385+ |yumush, window, cx| {
341-386+ yumush.chat.admin.editing = None;
342- pub(super) fn toggle_builder_timeout(&mut self, user_id: Id, cx: &mut Context<Self>) {387+ yumush
343- if self.chat.pending_builder_timeout == Some(user_id) {388+ .chat
344- self.chat.pending_builder_timeout = None;389+ .admin
345- } else {390+ .builder_rename
346- self.chat.pending_builder_timeout = Some(user_id);391+ .update(cx, |input, cx| input.set_value("", window, cx));
347- }392+ },
348- cx.notify();393+ );
349 }394 }
350 395
351 pub(super) fn confirm_builder_timeout(&mut self, window: &mut Window, cx: &mut Context<Self>) {396 pub(super) fn confirm_builder_timeout(&mut self, window: &mut Window, cx: &mut Context<Self>) {
352- let Some(user_id) = self.chat.pending_builder_timeout else {397+ let Some((user_id, UserEdit::Timeout)) = self.chat.admin.editing else {
353 return;398 return;
354 };399 };
355- let minutes = self.chat.builder_timeout.read(cx).text().to_string();400+ let minutes = self.chat.admin.builder_timeout.read(cx).text().to_string();
356- let Ok(minutes) = minutes.trim().parse::<u32>() else {401+ let Some(minutes) = number(&minutes) else {
357 return;402 return;
358 };403 };
359- self.chat.pending_builder_timeout = None;404+ self.builder_user_action(
360- self.chat405+ window,
361- .builder_timeout406+ cx,
362- .update(cx, |input, cx| input.set_value("", window, cx));407+ move |network| async move { network.call(TimeoutUser { user_id, minutes }).await },
363- self.builder_user_action(window, cx, move |network| async move {408+ |yumush, window, cx| {
364- network.call(TimeoutUser { user_id, minutes }).await409+ yumush.chat.admin.editing = None;
365- });410+ yumush
366- }411+ .chat
367-412+ .admin
368- pub(super) fn toggle_builder_ban(&mut self, user_id: Id, cx: &mut Context<Self>) {413+ .builder_timeout
369- if self.chat.pending_builder_ban == Some(user_id) {414+ .update(cx, |input, cx| input.set_value("", window, cx));
370- self.chat.pending_builder_ban = None;415+ },
371- } else {416+ );
372- self.chat.pending_builder_ban = Some(user_id);
373- }
374- cx.notify();
375 }417 }
376 418
377 pub(super) fn toggle_builder_ban_ip(&mut self, cx: &mut Context<Self>) {419 pub(super) fn toggle_builder_ban_ip(&mut self, cx: &mut Context<Self>) {
378- self.chat.builder_ban_scope = match self.chat.builder_ban_scope {420+ self.chat.admin.builder_ban_scope = match self.chat.admin.builder_ban_scope {
379 BanScope::Account => BanScope::AccountAndIp,421 BanScope::Account => BanScope::AccountAndIp,
380 BanScope::AccountAndIp => BanScope::Account,422 BanScope::AccountAndIp => BanScope::Account,
381 };423 };
@@ -383,25 +425,40 @@ impl Yumush {
383 }425 }
384 426
385 pub(super) fn confirm_builder_ban(&mut self, window: &mut Window, cx: &mut Context<Self>) {427 pub(super) fn confirm_builder_ban(&mut self, window: &mut Window, cx: &mut Context<Self>) {
386- let Some(user_id) = self.chat.pending_builder_ban.take() else {428+ let Some((user_id, UserEdit::Ban)) = self.chat.admin.editing else {
387 return;429 return;
388 };430 };
389- let reason = self.chat.builder_ban_reason.read(cx).text().to_string();431+ let reason = self
432+ .chat
433+ .admin
434+ .builder_ban_reason
435+ .read(cx)
436+ .text()
437+ .to_string();
390 let reason = reason.trim().to_string();438 let reason = reason.trim().to_string();
391 let reason = (!reason.is_empty()).then_some(reason);439 let reason = (!reason.is_empty()).then_some(reason);
392- let scope = self.chat.builder_ban_scope;440+ let scope = self.chat.admin.builder_ban_scope;
393- self.chat441+ self.builder_user_action(
394- .builder_ban_reason442+ window,
395- .update(cx, |input, cx| input.set_value("", window, cx));443+ cx,
396- self.builder_user_action(window, cx, move |network| async move {444+ move |network| async move {
397- network445+ network
398- .call(BanUser {446+ .call(BanUser {
399- user_id,447+ user_id,
400- reason,448+ reason,
401- scope,449+ scope,
402- })450+ })
403- .await451+ .await
404- });452+ },
453+ |yumush, window, cx| {
454+ yumush.chat.admin.editing = None;
455+ yumush
456+ .chat
457+ .admin
458+ .builder_ban_reason
459+ .update(cx, |input, cx| input.set_value("", window, cx));
460+ },
461+ );
405 }462 }
406 463
407 pub(super) fn purge_builder_user(464 pub(super) fn purge_builder_user(
@@ -410,8 +467,7 @@ impl Yumush {
410 window: &mut Window,467 window: &mut Window,
411 cx: &mut Context<Self>,468 cx: &mut Context<Self>,
412 ) {469 ) {
413- if !confirmed(&mut self.chat.pending_builder_purge, user_id) {470+ if !self.arm(Armed::PurgeUser(user_id), cx) {
414- cx.notify();
415 return;471 return;
416 }472 }
417 let network = self.network.clone();473 let network = self.network.clone();
@@ -422,6 +478,7 @@ impl Yumush {
422 let _ = this.update_in(cx, |yumush, window, cx| {478 let _ = this.update_in(cx, |yumush, window, cx| {
423 yumush479 yumush
424 .chat480 .chat
481+ .admin
425 .builder_messages482 .builder_messages
426 .retain(|hit| hit.message.user_id != user_id);483 .retain(|hit| hit.message.user_id != user_id);
427 yumush.load_users(window, cx);484 yumush.load_users(window, cx);
@@ -433,16 +490,12 @@ impl Yumush {
433 .detach();490 .detach();
434 }491 }
435 492
436- pub(super) fn users_body(493+ pub(super) fn users_body(&self, entity: &Entity<Self>, t: Tokens, cx: &App) -> Vec<AnyElement> {
437- &self,494+ let query = search_text(&self.chat.admin.builder_search, cx);
438- entity: &Entity<Self>,
439- palette: Palette,
440- cx: &App,
441- ) -> Vec<AnyElement> {
442- let query = search_text(&self.chat.builder_search, cx);
443 let rows: Vec<Div> = match self.user.as_ref() {495 let rows: Vec<Div> = match self.user.as_ref() {
444 Some(me) => self496 Some(me) => self
445 .chat497 .chat
498+ .admin
446 .builder_users499 .builder_users
447 .iter()500 .iter()
448 .filter(|account| {501 .filter(|account| {
@@ -452,204 +505,170 @@ impl Yumush {
452 .to_lowercase()505 .to_lowercase()
453 .contains(query.as_str())506 .contains(query.as_str())
454 })507 })
455- .map(|account| self.builder_row(account, me, entity, palette, cx))508+ .map(|account| self.builder_row(account, me, entity, t, cx))
456 .collect(),509 .collect(),
457 None => Vec::new(),510 None => Vec::new(),
458 };511 };
459 512
513+ let grow = |control: AnyElement| div().flex_1().min_w(px(size::THUMB)).child(control);
460 let toolbar = div()514 let toolbar = div()
461 .pb(px(space::SM))515 .pb(px(space::SM))
462 .flex()516 .flex()
463 .flex_wrap()517 .flex_wrap()
464 .items_center()518 .items_center()
465 .gap(px(space::SM))519 .gap(px(space::SM))
466- .child(520+ .child(grow(
467- div()521+ crate::gui::sidebar::input_box(&self.chat.admin.builder_search, t)
468- .flex_1()522+ .into_any_element(),
469- .min_w(px(size::THUMB))523+ ))
470- .child(crate::gui::sidebar::input_box(524+ .child(grow(
471- &self.chat.builder_search,525+ field(t, &self.chat.admin.new_username).into_any_element(),
472- palette,526+ ))
473- )),527+ .child(grow(
474- )528+ field(t, &self.chat.admin.new_password).into_any_element(),
475- .child(529+ ))
476- div()530+ .child(parts::button(
477- .flex_1()
478- .min_w(px(size::THUMB))
479- .child(field(palette, &self.chat.new_username)),
480- )
481- .child(
482- div()
483- .flex_1()
484- .min_w(px(size::THUMB))
485- .child(field(palette, &self.chat.new_password)),
486- )
487- .child(crate::gui::parts::button(
488 "create_user",531 "create_user",
489 w().builder_users.create,532 w().builder_users.create,
490- crate::gui::parts::Press::Plain,533+ Press::Plain,
491- palette.tokens,534+ t,
492 entity_action(entity, |yumush, window, cx| {535 entity_action(entity, |yumush, window, cx| {
493 yumush.submit_new_user(window, cx)536 yumush.submit_new_user(window, cx)
494 }),537 }),
495 ));538 ));
496 539
497- let body = if rows.is_empty() {540+ vec![
498- crate::gui::parts::empty(w().common.no_users, palette.tokens)541+ card()
499- } else {542+ .child(toolbar)
500- div().flex().flex_col().children(rows)543+ .child(rows_body(rows, w().common.no_users, t))
501- };544+ .into_any_element(),
502-545+ ]
503- vec![card(palette).child(toolbar).child(body).into_any_element()]
504 }546 }
505 547
506- pub(super) fn builder_timeout_row(548+ pub(super) fn builder_timeout_row(&self, user_id: Id, entity: &Entity<Self>, t: Tokens) -> Div {
507- &self,549+ form_row(
508- user_id: Id,550+ &self.chat.admin.builder_timeout,
509- entity: &Entity<Self>,551+ t,
510- palette: Palette,552+ [parts::button(
511- ) -> Div {
512- div()
513- .h(px(size::ROW))
514- .px(px(space::MD))
515- .flex()
516- .items_center()
517- .gap(px(space::SM))
518- .child(
519- div()
520- .flex_1()
521- .min_w_0()
522- .child(field(palette, &self.chat.builder_timeout)),
523- )
524- .child(parts::button(
525 format!("confirm_timeout_{user_id}"),553 format!("confirm_timeout_{user_id}"),
526 w().builder_users.confirm,554 w().builder_users.confirm,
527 Press::Plain,555 Press::Plain,
528- palette.tokens,556+ t,
529 entity_action(entity, |yumush, window, cx| {557 entity_action(entity, |yumush, window, cx| {
530 yumush.confirm_builder_timeout(window, cx)558 yumush.confirm_builder_timeout(window, cx)
531 }),559 }),
532- ))560+ )
561+ .into_any_element()],
562+ )
533 }563 }
534 564
535- pub(super) fn builder_ban_row(565+ pub(super) fn builder_ban_row(&self, user_id: Id, entity: &Entity<Self>, t: Tokens) -> Div {
536- &self,566+ let ip_label = if self.chat.admin.builder_ban_scope == BanScope::AccountAndIp {
537- user_id: Id,
538- entity: &Entity<Self>,
539- palette: Palette,
540- ) -> Div {
541- let ip_label = if self.chat.builder_ban_scope == BanScope::AccountAndIp {
542 w().builder_users.ip_on567 w().builder_users.ip_on
543 } else {568 } else {
544 w().builder_users.ip_off569 w().builder_users.ip_off
545 };570 };
546 571
547- div()572+ form_row(
548- .h(px(size::ROW))573+ &self.chat.admin.builder_ban_reason,
549- .px(px(space::MD))574+ t,
550- .flex()575+ [
551- .items_center()576+ parts::button(
552- .gap(px(space::SM))577+ format!("ban_ip_{user_id}"),
553- .child(578+ ip_label,
554- div()579+ Press::Plain,
555- .flex_1()580+ t,
556- .min_w_0()581+ entity_action(entity, |yumush, _, cx| yumush.toggle_builder_ban_ip(cx)),
557- .child(field(palette, &self.chat.builder_ban_reason)),582+ )
558- )583+ .into_any_element(),
559- .child(parts::button(584+ parts::button(
560- format!("ban_ip_{user_id}"),585+ format!("confirm_ban_{user_id}"),
561- ip_label,586+ w().builder_users.confirm,
562- Press::Plain,587+ Press::Plain,
563- palette.tokens,588+ t,
564- entity_action(entity, |yumush, _, cx| yumush.toggle_builder_ban_ip(cx)),589+ entity_action(entity, |yumush, window, cx| {
565- ))590+ yumush.confirm_builder_ban(window, cx)
566- .child(parts::button(591+ }),
567- format!("confirm_ban_{user_id}"),592+ )
568- w().builder_users.confirm,593+ .into_any_element(),
569- Press::Plain,594+ ],
570- palette.tokens,595+ )
571- entity_action(entity, |yumush, window, cx| {
572- yumush.confirm_builder_ban(window, cx)
573- }),
574- ))
575 }596 }
576 597
577- fn builder_friend_list(&self, palette: Palette) -> Vec<AnyElement> {598+ fn builder_friend_list(&self, t: Tokens) -> AnyElement {
578- let friends = self.chat.builder_friends.clone();599+ let friends = self.chat.admin.builder_friends.clone();
579- let search = self.chat.builder_friend_search.clone();600+ let search = self.chat.admin.builder_friend_search.clone();
580- let avatars = self.chat.avatars.clone();601+ let avatars = self.chat.session.avatars.clone();
581 let label = w().builder_users.friends_count(friends.len());602 let label = w().builder_users.friends_count(friends.len());
582 603
583- vec![604+ Popover::new("builder_friends")
584- Popover::new("builder_friends")605+ .anchor(Anchor::TopLeft)
585- .anchor(Anchor::TopLeft)606+ .appearance(false)
586- .appearance(false)607+ .trigger(crate::gui::Trigger::new(
587- .trigger(crate::gui::Trigger::new(608+ clickable("builder_friends_trigger", t, |_, _| {})
588- clickable("builder_friends_trigger", palette, |_, _| {})609+ .h(px(size::CONTROL_SM))
589- .h(px(size::CONTROL_SM))610+ .flex()
590- .flex()611+ .items_center()
591- .items_center()612+ .gap(px(space::SM))
592- .gap(px(space::SM))613+ .rounded(px(radius::MD))
593- .rounded(px(radius::MD))614+ .text_size(text(text::CAPTION))
594- .text_size(text(text::CAPTION))615+ .font_weight(FontWeight::MEDIUM)
595- .font_weight(FontWeight::MEDIUM)616+ .text_color(t.paper())
596- .text_color(palette.text)617+ .child(parts::small_icon(IconName::Users))
597- .child(crate::gui::parts::small_icon(IconName::Users))618+ .child(label)
598- .child(label)619+ .child(parts::small_icon(IconName::ChevronDown)),
599- .child(crate::gui::parts::small_icon(IconName::ChevronDown)),620+ ))
600- ))621+ .content(move |_, _, cx| {
601- .content(move |_, _, cx| {622+ let query = search_text(&search, cx);
602- let query = crate::gui::widget::search_text(&search, cx);623+ parts::popover(t)
603- crate::gui::parts::popover(palette.tokens)624+ .w(px(size::POPOVER))
604- .w(px(size::POPOVER))625+ .p(px(space::SM))
605- .p(px(space::SM))626+ .gap(px(space::XS))
606- .gap(px(space::XS))627+ .child(crate::gui::sidebar::input_box(&search, t))
607- .child(crate::gui::sidebar::input_box(&search, palette))628+ .child(
608- .child(629+ div()
609- div()630+ .id("builder_friends_list")
610- .id("builder_friends_list")631+ .max_h(px(FRIENDS_MAX_H))
611- .max_h(px(FRIENDS_MAX_H))632+ .overflow_y_scroll()
612- .overflow_y_scroll()633+ .flex()
613- .flex()634+ .flex_col()
614- .flex_col()635+ .when(friends.is_empty(), |list| {
615- .when(friends.is_empty(), |list| {636+ list.child(
616- list.child(637+ div()
638+ .text_size(text(text::CAPTION))
639+ .text_color(t.dim())
640+ .child(w().builder_users.no_friends),
641+ )
642+ })
643+ .children(
644+ friends
645+ .iter()
646+ .filter(|friend| {
647+ friend.username.to_lowercase().contains(&query)
648+ })
649+ .map(|friend| {
617 div()650 div()
618- .text_size(text(text::CAPTION))651+ .h(px(size::CONTROL_SM))
619- .text_color(palette.muted)652+ .flex()
620- .child(w().builder_users.no_friends),653+ .items_center()
621- )654+ .gap(px(space::SM))
622- })655+ .child(avatar(
623- .children(656+ t,
624- friends657+ friend,
625- .iter()658+ px(size::ICON),
626- .filter(|friend| {659+ text(text::CAPTION),
627- friend.username.to_lowercase().contains(&query)660+ &avatars,
628- })661+ ))
629- .map(|friend| {662+ .child(
630- div()663+ div()
631- .h(px(size::CONTROL_SM))664+ .text_size(text(text::CAPTION))
632- .flex()665+ .child(friend.username.clone()),
633- .items_center()666+ )
634- .gap(px(space::SM))667+ }),
635- .child(crate::gui::avatar(668+ ),
636- palette,669+ )
637- friend,670+ })
638- px(size::ICON),671+ .into_any_element()
639- text(text::CAPTION),
640- &avatars,
641- ))
642- .child(
643- div()
644- .text_size(text(text::CAPTION))
645- .child(friend.username.clone()),
646- )
647- }),
648- ),
649- )
650- })
651- .into_any_element(),
652- ]
653 }672 }
654 673
655 pub(super) fn builder_session_row(674 pub(super) fn builder_session_row(
@@ -657,19 +676,18 @@ impl Yumush {
657 user_id: Id,676 user_id: Id,
658 session: &SessionInfo,677 session: &SessionInfo,
659 entity: &Entity<Self>,678 entity: &Entity<Self>,
660- palette: Palette,679+ t: Tokens,
661 ) -> Div {680 ) -> Div {
662- let revoke_user_id = user_id;
663 let session_id = session.id;681 let session_id = session.id;
664 let revoke_button = action_button(682 let revoke_button = action_button(
665 format!("revoke_session_{}", session.id),683 format!("revoke_session_{}", session.id),
666 IconName::LogOut,684 IconName::LogOut,
667 w().builder_users.revoke,685 w().builder_users.revoke,
668 w().builder_users.end_session,686 w().builder_users.end_session,
669- palette.muted,687+ t.dim(),
670- palette,688+ t,
671 entity_action(entity, move |yumush, window, cx| {689 entity_action(entity, move |yumush, window, cx| {
672- yumush.revoke_builder_session(revoke_user_id, session_id, window, cx)690+ yumush.revoke_builder_session(user_id, session_id, window, cx)
673 }),691 }),
674 );692 );
675 let device = if session.device.is_empty() {693 let device = if session.device.is_empty() {
@@ -684,7 +702,7 @@ impl Yumush {
684 .flex()702 .flex()
685 .items_center()703 .items_center()
686 .gap(px(space::SM))704 .gap(px(space::SM))
687- .child(crate::gui::parts::small_icon(IconName::Monitor).text_color(palette.muted))705+ .child(parts::small_icon(IconName::Monitor).text_color(t.dim()))
688 .child(706 .child(
689 div()707 div()
690 .flex_1()708 .flex_1()
@@ -697,20 +715,20 @@ impl Yumush {
697 div()715 div()
698 .flex_shrink_0()716 .flex_shrink_0()
699 .text_size(text(text::CAPTION))717 .text_size(text(text::CAPTION))
700- .text_color(palette.muted)718+ .text_color(t.dim())
701 .child(seen_text(session.last_seen)),719 .child(seen_text(session.last_seen)),
702 )720 )
703 .child(revoke_button)721 .child(revoke_button)
704 }722 }
705 723
706- fn builder_client_row(&self, client: &UpdateClient, palette: Palette) -> Div {724+ fn builder_client_row(&self, client: &UpdateClient, t: Tokens) -> Div {
707 let release = match (client.release, client.target.as_deref()) {725 let release = match (client.release, client.target.as_deref()) {
708 (Some(seq), Some(target)) => format!("#{seq} · {target}"),726 (Some(seq), Some(target)) => format!("#{seq} · {target}"),
709 _ => w().builder_users.unknown.to_string(),727 _ => w().builder_users.unknown.to_string(),
710 };728 };
711 let state = match client.state {729 let state = match client.state {
712- UpdateState::Unknown => caption_text(w().builder_users.dev, palette.muted),730+ UpdateState::Unknown => caption_text(w().builder_users.dev, t.dim()),
713- UpdateState::Latest => caption_text(w().builder_users.latest, palette.ok),731+ UpdateState::Latest => caption_text(w().builder_users.latest, t.hue(Hue::Mint)),
714 UpdateState::Available { required, .. } => caption_text(732 UpdateState::Available { required, .. } => caption_text(
715 if required {733 if required {
716 format!(734 format!(
@@ -721,28 +739,25 @@ impl Yumush {
721 } else {739 } else {
722 w().builder_users.available.to_string()740 w().builder_users.available.to_string()
723 },741 },
724- palette.muted,742+ t.dim(),
725 ),743 ),
726 UpdateState::Downloading { percent, .. } => {744 UpdateState::Downloading { percent, .. } => {
727- meter(f32::from(percent) / 100., format!("{percent}%"), palette)745+ meter(f32::from(percent) / 100., format!("{percent}%"), t)
728 }746 }
729- UpdateState::Installing { .. } => {747+ UpdateState::Installing { .. } => caption_text(w().builder_users.installing, t.dim()),
730- caption_text(w().builder_users.installing, palette.muted)748+ UpdateState::Ready { .. } => caption_text(w().builder_users.ready, t.hue(Hue::Mint)),
731- }749+ UpdateState::Failed { .. } => caption_text(w().builder_users.failed, t.bad()),
732- UpdateState::Ready { .. } => caption_text(w().builder_users.ready, palette.ok),
733- UpdateState::Failed { .. } => caption_text(w().builder_users.failed, palette.danger),
734 };750 };
735 let dot = div()751 let dot = div()
736 .size(px(space::SM))752 .size(px(space::SM))
737 .flex_shrink_0()753 .flex_shrink_0()
738 .rounded_full()754 .rounded_full()
739 .bg(if client.online {755 .bg(if client.online {
740- palette.ok756+ t.hue(Hue::Mint)
741 } else {757 } else {
742- palette.muted758+ t.dim()
743 });759 });
744- let seen =760+ let seen = (!client.online).then(|| caption_text(seen_text(Some(client.seen_ms)), t.dim()));
745- (!client.online).then(|| caption_text(seen_text(Some(client.seen_ms)), palette.muted));
746 761
747 div()762 div()
748 .w_full()763 .w_full()
@@ -750,7 +765,7 @@ impl Yumush {
750 .flex()765 .flex()
751 .items_center()766 .items_center()
752 .gap(px(space::SM))767 .gap(px(space::SM))
753- .child(crate::gui::parts::small_icon(IconName::Monitor).text_color(palette.muted))768+ .child(parts::small_icon(IconName::Monitor).text_color(t.dim()))
754 .child(769 .child(
755 div()770 div()
756 .flex_1()771 .flex_1()
@@ -759,7 +774,7 @@ impl Yumush {
759 .truncate()774 .truncate()
760 .child(client.device.clone()),775 .child(client.device.clone()),
761 )776 )
762- .child(caption_text(release, palette.muted))777+ .child(caption_text(release, t.dim()))
763 .child(state)778 .child(state)
764 .child(dot)779 .child(dot)
765 .children(seen)780 .children(seen)
@@ -769,74 +784,67 @@ impl Yumush {
769 &self,784 &self,
770 user_id: Id,785 user_id: Id,
771 entity: &Entity<Self>,786 entity: &Entity<Self>,
772- palette: Palette,787+ t: Tokens,
773 cx: &App,788 cx: &App,
774 ) -> Div {789 ) -> Div {
775- let value = self.chat.builder_rename.read(cx).text().to_string();790+ let value = self.chat.admin.builder_rename.read(cx).text().to_string();
776 let current = self791 let current = self
777 .chat792 .chat
793+ .admin
778 .builder_users794 .builder_users
779 .iter()795 .iter()
780 .find(|account| account.user.id == user_id)796 .find(|account| account.user.id == user_id)
781 .map_or("", |account| account.user.username.as_str());797 .map_or("", |account| account.user.username.as_str());
782 let ready = !value.is_empty() && value != current;798 let ready = !value.is_empty() && value != current;
783- div()799+ form_row(
784- .h(px(size::ROW))800+ &self.chat.admin.builder_rename,
785- .px(px(space::MD))801+ t,
786- .flex()802+ ready.then(|| {
787- .items_center()803+ parts::button(
788- .gap(px(space::SM))
789- .child(
790- div()
791- .flex_1()
792- .min_w_0()
793- .child(field(palette, &self.chat.builder_rename)),
794- )
795- .when(ready, |row| {
796- row.child(parts::button(
797 format!("confirm_rename_{user_id}"),804 format!("confirm_rename_{user_id}"),
798 w().builder_users.confirm,805 w().builder_users.confirm,
799 Press::Plain,806 Press::Plain,
800- palette.tokens,807+ t,
801 entity_action(entity, |yumush, window, cx| {808 entity_action(entity, |yumush, window, cx| {
802 yumush.rename_builder_user(window, cx)809 yumush.rename_builder_user(window, cx)
803 }),810 }),
804- ))811+ )
805- })812+ .into_any_element()
813+ }),
814+ )
806 }815 }
807 816
808 pub(super) fn builder_password_row(817 pub(super) fn builder_password_row(
809 &self,818 &self,
810 user_id: Id,819 user_id: Id,
811 entity: &Entity<Self>,820 entity: &Entity<Self>,
812- palette: Palette,821+ t: Tokens,
813 cx: &App,822 cx: &App,
814 ) -> Div {823 ) -> Div {
815- let value = self.chat.builder_password.read(cx).text().to_string();824+ let ready = !self
816- let ready = !value.is_empty();825+ .chat
817- div()826+ .admin
818- .h(px(size::ROW))827+ .builder_password
819- .px(px(space::MD))828+ .read(cx)
820- .flex()829+ .text()
821- .items_center()830+ .to_string()
822- .gap(px(space::SM))831+ .is_empty();
823- .child(832+ form_row(
824- div()833+ &self.chat.admin.builder_password,
825- .flex_1()834+ t,
826- .min_w_0()835+ ready.then(|| {
827- .child(field(palette, &self.chat.builder_password)),836+ parts::button(
828- )
829- .when(ready, |row| {
830- row.child(parts::button(
831 format!("confirm_password_{user_id}"),837 format!("confirm_password_{user_id}"),
832 w().builder_users.confirm,838 w().builder_users.confirm,
833 Press::Plain,839 Press::Plain,
834- palette.tokens,840+ t,
835 entity_action(entity, |yumush, window, cx| {841 entity_action(entity, |yumush, window, cx| {
836 yumush.reset_builder_password(window, cx)842 yumush.reset_builder_password(window, cx)
837 }),843 }),
838- ))844+ )
839- })845+ .into_any_element()
846+ }),
847+ )
840 }848 }
841 849
842 pub(super) fn builder_row(850 pub(super) fn builder_row(
@@ -844,113 +852,29 @@ impl Yumush {
844 account: &Account,852 account: &Account,
845 me: &User,853 me: &User,
846 entity: &Entity<Self>,854 entity: &Entity<Self>,
847- palette: Palette,855+ t: Tokens,
848 cx: &App,856 cx: &App,
849 ) -> Div {857 ) -> Div {
850 let user = &account.user;858 let user = &account.user;
851- let is_self = user.id == me.id;859+ let id = user.id;
852- let manage = permission::can_manage_user(me.role, is_self, user.role);860+ let manage = permission::can_manage_user(me.role, user.id == me.id, user.role);
853- let can_delete = !is_self && permission::can_delete_user(me.role, is_self, user.role);861+ let timed_out = matches!(account.suspension, Suspension::Until(until) if until > now_ms());
854- let has_actions = manage || can_delete;862+ let suspended = matches!(account.suspension, Suspension::Indefinite);
855- let suspended = account.suspended;
856- let timed_out = account
857- .suspended_until
858- .is_some_and(|until| until > now_ms());
859 let expanded_sessions = self863 let expanded_sessions = self
860 .chat864 .chat
865+ .admin
861 .builder_sessions866 .builder_sessions
862 .as_ref()867 .as_ref()
863- .filter(|(open, _)| *open == user.id)868+ .filter(|(open, _)| *open == id)
864 .map(|(_, sessions)| sessions);869 .map(|(_, sessions)| sessions);
865- let expanded = expanded_sessions.is_some();
866- let pending_delete = self.chat.pending_builder_delete == Some(user.id);
867- let pending_purge = self.chat.pending_builder_purge == Some(user.id);
868- let delete_id = user.id;
869- let suspend_id = user.id;
870- let sessions_id = user.id;
871- let password_id = user.id;
872- let profile_id = user.id;
873- let sessions_list_id = user.id;
874- let rename_id = user.id;
875- let timeout_id = user.id;
876- let ban_id = user.id;
877- let purge_id = user.id;
878 let joined = millis_time(user.created_at, crate::lang::w().common.date);870 let joined = millis_time(user.created_at, crate::lang::w().common.date);
879 let seen = seen_text(account.last_seen);871 let seen = seen_text(account.last_seen);
880 872
881- let tone = palette.text;
882- let suspend_button = action_button(
883- format!("suspend_user_{}_{suspended}", user.id),
884- IconName::CirclePause,
885- if suspended {
886- w().builder_users.unsuspend
887- } else {
888- w().builder_users.suspend
889- },
890- if suspended {
891- w().builder_users.allow_sign_in
892- } else {
893- w().builder_users.block_until_lifted
894- },
895- tone,
896- palette,
897- entity_action(entity, move |yumush, window, cx| {
898- yumush.suspend_builder_user(suspend_id, !suspended, window, cx)
899- }),
900- );
901-
902- let sessions_button = action_button(
903- format!("sessions_user_{}", user.id),
904- IconName::LogOut,
905- w().builder_users.sign_out,
906- w().builder_users.end_all_sessions,
907- tone,
908- palette,
909- entity_action(entity, move |yumush, window, cx| {
910- yumush.revoke_builder_sessions(sessions_id, window, cx)
911- }),
912- );
913-
914- let stats_id = user.id;
915- let stats_open = self
916- .chat
917- .followed
918- .as_ref()
919- .filter(|(id, _)| *id == user.id)
920- .map(|(_, stats)| stats);
921- let stats_button = action_button(
922- format!("stats_user_{}", user.id),
923- IconName::Activity,
924- w().builder_users.stats,
925- w().builder_users.stats_tip,
926- if stats_open.is_some() {
927- palette.text
928- } else {
929- tone
930- },
931- palette,
932- entity_action(entity, move |yumush, _, cx| {
933- yumush.toggle_builder_stats(stats_id, cx)
934- }),
935- );
936-
937- let password_button = action_button(
938- format!("password_user_{}", user.id),
939- IconName::KeyRound,
940- w().builder_users.password,
941- w().builder_users.password_tip,
942- tone,
943- palette,
944- entity_action(entity, move |yumush, _, cx| {
945- yumush.toggle_builder_password(password_id, cx)
946- }),
947- );
948-
949 let toggle_button = clickable(873 let toggle_button = clickable(
950- format!("sessions_list_user_{}", user.id),874+ format!("sessions_list_user_{id}"),
951- palette,875+ t,
952 entity_action(entity, move |yumush, window, cx| {876 entity_action(entity, move |yumush, window, cx| {
953- yumush.toggle_builder_sessions(sessions_list_id, window, cx)877+ yumush.toggle_builder_sessions(id, window, cx)
954 }),878 }),
955 )879 )
956 .tip(w().builder_users.manage)880 .tip(w().builder_users.manage)
@@ -960,82 +884,10 @@ impl Yumush {
960 .items_center()884 .items_center()
961 .justify_center()885 .justify_center()
962 .rounded(px(radius::MD))886 .rounded(px(radius::MD))
963- .text_color(palette.muted)887+ .text_color(t.dim())
964- .when(expanded, |this| this.bg(palette.hover))888+ .when(expanded_sessions.is_some(), |this| this.bg(t.hov()))
965 .child(Icon::new(IconName::Ellipsis).size(px(size::ICON)));889 .child(Icon::new(IconName::Ellipsis).size(px(size::ICON)));
966 890
967- let rename_button = action_button(
968- format!("rename_user_{}", user.id),
969- IconName::Pencil,
970- w().builder_users.rename,
971- w().builder_users.rename_tip,
972- tone,
973- palette,
974- entity_action(entity, move |yumush, _, cx| {
975- yumush.toggle_builder_rename(rename_id, cx)
976- }),
977- );
978-
979- let timeout_button = action_button(
980- format!("timeout_user_{}", user.id),
981- IconName::Timer,
982- w().builder_users.timeout,
983- w().builder_users.timeout_tip,
984- tone,
985- palette,
986- entity_action(entity, move |yumush, _, cx| {
987- yumush.toggle_builder_timeout(timeout_id, cx)
988- }),
989- );
990-
991- let ban_button = action_button(
992- format!("ban_user_{}", user.id),
993- IconName::Ban,
994- w().builder_users.ban,
995- w().builder_users.ban_tip,
996- tone,
997- palette,
998- entity_action(entity, move |yumush, _, cx| {
999- yumush.toggle_builder_ban(ban_id, cx)
1000- }),
1001- );
1002-
1003- let profile_button = action_button(
1004- format!("profile_user_{}", user.id),
1005- IconName::Eraser,
1006- w().builder_users.clear_profile,
1007- w().builder_users.clear_profile_tip,
1008- palette.danger,
1009- palette,
1010- entity_action(entity, move |yumush, window, cx| {
1011- yumush.clear_builder_profile(profile_id, window, cx)
1012- }),
1013- );
1014-
1015- let purge_button = confirm_button(
1016- format!("purge_user_{}", user.id),
1017- IconName::MessageSquareX,
1018- w().builder_users.purge,
1019- w().builder_users.purge_tip,
1020- pending_purge,
1021- palette,
1022- entity_action(entity, move |yumush, window, cx| {
1023- yumush.purge_builder_user(purge_id, window, cx)
1024- }),
1025- );
1026-
1027- let delete_button = confirm_button(
1028- format!("delete_user_{}", user.id),
1029- IconName::UserX,
1030- w().builder_users.delete,
1031- w().builder_users.delete_tip,
1032- pending_delete,
1033- palette,
1034- entity_action(entity, move |yumush, window, cx| {
1035- yumush.delete_builder_user(delete_id, window, cx)
1036- }),
1037- );
1038-
1039 let row = div()891 let row = div()
1040 .px(px(space::LG))892 .px(px(space::LG))
1041 .py(px(space::MD))893 .py(px(space::MD))
@@ -1043,15 +895,15 @@ impl Yumush {
1043 .items_center()895 .items_center()
1044 .gap(px(space::MD))896 .gap(px(space::MD))
1045 .child(user_link(897 .child(user_link(
1046- format!("builder_user_avatar_{}", user.id),898+ format!("builder_user_avatar_{id}"),
1047 Some(user),899 Some(user),
1048 entity,900 entity,
1049 avatar(901 avatar(
1050- palette,902+ t,
1051 user,903 user,
1052 px(size::AVATAR),904 px(size::AVATAR),
1053 text(text::CAPTION),905 text(text::CAPTION),
1054- &self.chat.avatars,906+ &self.chat.session.avatars,
1055 ),907 ),
1056 ))908 ))
1057 .child(909 .child(
@@ -1068,43 +920,27 @@ impl Yumush {
1068 .items_center()920 .items_center()
1069 .gap(px(space::SM))921 .gap(px(space::SM))
1070 .child(user_link(922 .child(user_link(
1071- format!("builder_user_name_{}", user.id),923+ format!("builder_user_name_{id}"),
1072 Some(user),924 Some(user),
1073 entity,925 entity,
1074 div()926 div()
1075 .truncate()927 .truncate()
1076 .text_size(text(text::LABEL))928 .text_size(text(text::LABEL))
1077 .font_weight(FontWeight::MEDIUM)929 .font_weight(FontWeight::MEDIUM)
1078- .text_color(palette.text)930+ .text_color(t.paper())
1079 .child(user.username.clone()),931 .child(user.username.clone()),
1080 ))932 ))
1081 .when(user.role == Role::Builder, |this| {933 .when(user.role == Role::Builder, |this| {
1082- this.child(status(934+ this.child(status(w().builder_users.tag_builder, t.paper()))
1083- w().builder_users.tag_builder,
1084- palette.accent,
1085- palette,
1086- ))
1087 })935 })
1088 .when(suspended, |this| {936 .when(suspended, |this| {
1089- this.child(status(937+ this.child(status(w().builder_users.tag_suspended, t.bad()))
1090- w().builder_users.tag_suspended,
1091- palette.danger,
1092- palette,
1093- ))
1094 })938 })
1095 .when(timed_out, |this| {939 .when(timed_out, |this| {
1096- this.child(status(940+ this.child(status(w().builder_users.tag_timed_out, t.bad()))
1097- w().builder_users.tag_timed_out,
1098- palette.danger,
1099- palette,
1100- ))
1101 })941 })
1102 .when(account.ghost, |this| {942 .when(account.ghost, |this| {
1103- this.child(status(943+ this.child(status(w().builder_users.tag_ghost, t.dim()))
1104- w().builder_users.tag_ghost,
1105- palette.muted,
1106- palette,
1107- ))
1108 }),944 }),
1109 )945 )
1110 .child(946 .child(
@@ -1112,111 +948,248 @@ impl Yumush {
1112 .min_w_0()948 .min_w_0()
1113 .truncate()949 .truncate()
1114 .text_size(text(text::CAPTION))950 .text_size(text(text::CAPTION))
1115- .text_color(palette.muted)951+ .text_color(t.dim())
1116 .child(w().builder_users.joined_seen(joined, seen)),952 .child(w().builder_users.joined_seen(joined, seen)),
1117 ),953 ),
1118 )954 )
1119- .children(has_actions.then_some(toggle_button));955+ .children(manage.then_some(toggle_button));
1120 956
1121- let panel = expanded_sessions.map(|sessions| {957+ let panel = expanded_sessions
1122- let open_id = user.id;958+ .map(|sessions| self.builder_panel(account, sessions, manage, entity, t, cx));
1123- let password_open = self.chat.pending_builder_password == Some(open_id);
1124- let rename_open = self.chat.pending_builder_rename == Some(open_id);
1125- let timeout_open = self.chat.pending_builder_timeout == Some(open_id);
1126- let ban_open = self.chat.pending_builder_ban == Some(open_id);
1127 959
1128- let account_actions = [960+ div().flex().flex_col().child(row).children(panel)
1129- manage.then(|| rename_button.into_any_element()),961+ }
1130- manage.then(|| password_button.into_any_element()),962+
1131- Some(stats_button.into_any_element()),963+ fn builder_panel(
1132- ];964+ &self,
1133- let moderation_actions = [965+ account: &Account,
1134- manage.then(|| timeout_button.into_any_element()),966+ sessions: &[SessionInfo],
1135- manage.then(|| suspend_button.into_any_element()),967+ manage: bool,
1136- manage.then(|| ban_button.into_any_element()),968+ entity: &Entity<Self>,
1137- manage.then(|| sessions_button.into_any_element()),969+ t: Tokens,
1138- ];970+ cx: &App,
1139- let danger_actions = [971+ ) -> Div {
1140- manage.then(|| profile_button.into_any_element()),972+ let user = &account.user;
1141- manage.then(|| purge_button.into_any_element()),973+ let id = user.id;
1142- can_delete.then(|| delete_button.into_any_element()),974+ let suspended = matches!(account.suspension, Suspension::Indefinite);
1143- ];975+ let manage_only = |button: AnyElement| manage.then_some(button);
1144- let sessions: Vec<AnyElement> = sessions976+
1145- .iter()977+ let rename = action_button(
1146- .map(|session| {978+ format!("rename_user_{id}"),
1147- self.builder_session_row(user.id, session, entity, palette)979+ IconName::Pencil,
1148- .into_any_element()980+ w().builder_users.rename,
1149- })981+ w().builder_users.rename_tip,
1150- .collect();982+ t.paper(),
1151- let clients: Vec<AnyElement> = if self.chat.builder_clients.is_empty() {983+ t,
1152- vec![caption_text(w().builder_users.no_clients, palette.muted).into_any_element()]984+ entity_action(entity, move |yumush, _, cx| {
985+ yumush.toggle_user_edit(id, UserEdit::Rename, cx)
986+ }),
987+ );
988+ let password = action_button(
989+ format!("password_user_{id}"),
990+ IconName::KeyRound,
991+ w().builder_users.password,
992+ w().builder_users.password_tip,
993+ t.paper(),
994+ t,
995+ entity_action(entity, move |yumush, _, cx| {
996+ yumush.toggle_user_edit(id, UserEdit::Password, cx)
997+ }),
998+ );
999+ let stats = action_button(
1000+ format!("stats_user_{id}"),
1001+ IconName::Activity,
1002+ w().builder_users.stats,
1003+ w().builder_users.stats_tip,
1004+ t.paper(),
1005+ t,
1006+ entity_action(entity, move |yumush, _, cx| {
1007+ yumush.toggle_builder_stats(id, cx)
1008+ }),
1009+ );
1010+ let timeout = action_button(
1011+ format!("timeout_user_{id}"),
1012+ IconName::Timer,
1013+ w().builder_users.timeout,
1014+ w().builder_users.timeout_tip,
1015+ t.paper(),
1016+ t,
1017+ entity_action(entity, move |yumush, _, cx| {
1018+ yumush.toggle_user_edit(id, UserEdit::Timeout, cx)
1019+ }),
1020+ );
1021+ let suspend = action_button(
1022+ format!("suspend_user_{id}_{suspended}"),
1023+ IconName::CirclePause,
1024+ if suspended {
1025+ w().builder_users.unsuspend
1026+ } else {
1027+ w().builder_users.suspend
1028+ },
1029+ if suspended {
1030+ w().builder_users.allow_sign_in
1153 } else {1031 } else {
1154- self.chat1032+ w().builder_users.block_until_lifted
1155- .builder_clients1033+ },
1156- .iter()1034+ t.paper(),
1157- .map(|client| self.builder_client_row(client, palette).into_any_element())1035+ t,
1158- .collect()1036+ entity_action(entity, move |yumush, window, cx| {
1159- };1037+ yumush.suspend_builder_user(id, !suspended, window, cx)
1038+ }),
1039+ );
1040+ let sign_out = action_button(
1041+ format!("sessions_user_{id}"),
1042+ IconName::LogOut,
1043+ w().builder_users.sign_out,
1044+ w().builder_users.end_all_sessions,
1045+ t.paper(),
1046+ t,
1047+ entity_action(entity, move |yumush, window, cx| {
1048+ yumush.revoke_builder_sessions(id, window, cx)
1049+ }),
1050+ );
1051+ let ban = action_button(
1052+ format!("ban_user_{id}"),
1053+ IconName::Ban,
1054+ w().builder_users.ban,
1055+ w().builder_users.ban_tip,
1056+ t.paper(),
1057+ t,
1058+ entity_action(entity, move |yumush, _, cx| {
1059+ yumush.toggle_user_edit(id, UserEdit::Ban, cx)
1060+ }),
1061+ );
1062+ let profile = action_button(
1063+ format!("profile_user_{id}"),
1064+ IconName::Eraser,
1065+ w().builder_users.clear_profile,
1066+ w().builder_users.clear_profile_tip,
1067+ t.bad(),
1068+ t,
1069+ entity_action(entity, move |yumush, window, cx| {
1070+ yumush.clear_builder_profile(id, window, cx)
1071+ }),
1072+ );
1073+ let purge = confirm_button(
1074+ format!("purge_user_{id}"),
1075+ IconName::MessageSquareX,
1076+ w().builder_users.purge,
1077+ w().builder_users.purge_tip,
1078+ self.armed(Armed::PurgeUser(id)),
1079+ t,
1080+ entity_action(entity, move |yumush, window, cx| {
1081+ yumush.purge_builder_user(id, window, cx)
1082+ }),
1083+ );
1084+ let delete = confirm_button(
1085+ format!("delete_user_{id}"),
1086+ IconName::UserX,
1087+ w().builder_users.delete,
1088+ w().builder_users.delete_tip,
1089+ self.armed(Armed::BuilderDeleteUser(id)),
1090+ t,
1091+ entity_action(entity, move |yumush, window, cx| {
1092+ yumush.delete_builder_user(id, window, cx)
1093+ }),
1094+ );
1160 1095
1161- div()1096+ let account_actions = [
1162- .flex()1097+ manage_only(rename.into_any_element()),
1163- .flex_col()1098+ manage_only(password.into_any_element()),
1164- .gap(px(space::SM))1099+ Some(stats.into_any_element()),
1165- .ml(px(space::MD))1100+ ];
1166- .mb(px(space::MD))1101+ let moderation_actions = [
1167- .pl(px(space::XL))1102+ manage_only(timeout.into_any_element()),
1168- .py(px(space::SM))1103+ manage_only(suspend.into_any_element()),
1169- .border_l(px(crate::gui::style::stroke::LINE))1104+ manage_only(ban.into_any_element()),
1170- .border_color(palette.tokens.person(user.id))1105+ manage_only(sign_out.into_any_element()),
1171- .children(action_group(1106+ ];
1172- w().builder_users.group_account,1107+ let danger_actions = [
1173- palette,1108+ manage_only(profile.into_any_element()),
1174- account_actions.into_iter().flatten().collect(),1109+ manage_only(purge.into_any_element()),
1175- ))1110+ manage_only(delete.into_any_element()),
1176- .children(1111+ ];
1177- password_open.then(|| self.builder_password_row(user.id, entity, palette, cx)),1112+ let sessions: Vec<AnyElement> = sessions
1178- )1113+ .iter()
1179- .children(1114+ .map(|session| {
1180- rename_open.then(|| self.builder_rename_row(user.id, entity, palette, cx)),1115+ self.builder_session_row(id, session, entity, t)
1181- )1116+ .into_any_element()
1182- .children(action_group(1117+ })
1183- w().builder_users.group_moderation,1118+ .collect();
1184- palette,1119+ let clients: Vec<AnyElement> = if self.chat.admin.builder_clients.is_empty() {
1185- moderation_actions.into_iter().flatten().collect(),1120+ vec![caption_text(w().builder_users.no_clients, t.dim()).into_any_element()]
1186- ))1121+ } else {
1187- .children(timeout_open.then(|| self.builder_timeout_row(user.id, entity, palette)))1122+ self.chat
1188- .children(ban_open.then(|| self.builder_ban_row(user.id, entity, palette)))1123+ .admin
1189- .children(action_group(1124+ .builder_clients
1190- w().builder_users.group_danger,1125+ .iter()
1191- palette,1126+ .map(|client| self.builder_client_row(client, t).into_any_element())
1192- danger_actions.into_iter().flatten().collect(),1127+ .collect()
1193- ))1128+ };
1194- .children(action_group(1129+ let stats_open = self
1195- w().builder_users.group_sessions,1130+ .chat
1196- palette,1131+ .session
1197- sessions,1132+ .followed
1198- ))1133+ .as_ref()
1199- .children(action_group(1134+ .filter(|(followed, _)| *followed == id)
1200- w().builder_users.group_clients,1135+ .map(|(_, stats)| stats);
1201- palette,
1202- clients,
1203- ))
1204- .children(action_group(
1205- w().builder_users.group_friends,
1206- palette,
1207- self.builder_friend_list(palette),
1208- ))
1209- .children(stats_open.map(|stats| {
1210- super::super::voice_stats::stats_panel(
1211- stats,
1212- &|id| self.chat.name_of(id),
1213- super::super::voice_stats::Detail::Full,
1214- palette,
1215- )
1216- .pt(px(space::MD))
1217- }))
1218- });
1219 1136
1220- div().flex().flex_col().child(row).children(panel)1137+ div()
1138+ .flex()
1139+ .flex_col()
1140+ .gap(px(space::SM))
1141+ .ml(px(space::MD))
1142+ .mb(px(space::MD))
1143+ .pl(px(space::XL))
1144+ .py(px(space::SM))
1145+ .border_l(px(crate::gui::style::stroke::LINE))
1146+ .border_color(t.person(id))
1147+ .children(action_group(
1148+ w().builder_users.group_account,
1149+ t,
1150+ account_actions.into_iter().flatten().collect(),
1151+ ))
1152+ .children(
1153+ self.edit_open(id, UserEdit::Password)
1154+ .then(|| self.builder_password_row(id, entity, t, cx)),
1155+ )
1156+ .children(
1157+ self.edit_open(id, UserEdit::Rename)
1158+ .then(|| self.builder_rename_row(id, entity, t, cx)),
1159+ )
1160+ .children(action_group(
1161+ w().builder_users.group_moderation,
1162+ t,
1163+ moderation_actions.into_iter().flatten().collect(),
1164+ ))
1165+ .children(
1166+ self.edit_open(id, UserEdit::Timeout)
1167+ .then(|| self.builder_timeout_row(id, entity, t)),
1168+ )
1169+ .children(
1170+ self.edit_open(id, UserEdit::Ban)
1171+ .then(|| self.builder_ban_row(id, entity, t)),
1172+ )
1173+ .children(action_group(
1174+ w().builder_users.group_danger,
1175+ t,
1176+ danger_actions.into_iter().flatten().collect(),
1177+ ))
1178+ .children(action_group(w().builder_users.group_sessions, t, sessions))
1179+ .children(action_group(w().builder_users.group_clients, t, clients))
1180+ .children(action_group(
1181+ w().builder_users.group_friends,
1182+ t,
1183+ vec![self.builder_friend_list(t)],
1184+ ))
1185+ .children(stats_open.map(|stats| {
1186+ crate::gui::voice_stats::stats_panel(
1187+ stats,
1188+ &|id| self.chat.name_of(id),
1189+ crate::gui::voice_stats::Detail::Full,
1190+ t,
1191+ )
1192+ .pt(px(space::MD))
1193+ }))
1221 }1194 }
1222 }1195 }
crates/client/src/gui/builder/voice.rsmodified+43 -53
@@ -3,7 +3,7 @@ use std::future::Future;
3 3
4 use common::{4 use common::{
5 call::{KickFromVoice, ListVoiceRooms, ServerMute},5 call::{KickFromVoice, ListVoiceRooms, ServerMute},
6- model::{User, VoiceRoom},6+ model::{Hue, User, VoiceRoom},
7 };7 };
8 use gpui_kit::{8 use gpui_kit::{
9 AnyElement, Context, Div, Entity, IntoElement, ParentElement, Styled, Window, assets::IconName,9 AnyElement, Context, Div, Entity, IntoElement, ParentElement, Styled, Window, assets::IconName,
@@ -13,9 +13,9 @@ use gpui_kit::{
13 use super::ui::{card, card_header, icon_button, list_card, list_row, pill, rows_body};13 use super::ui::{card, card_header, icon_button, list_card, list_row, pill, rows_body};
14 use crate::{14 use crate::{
15 gui::{15 gui::{
16- Palette, Yumush, avatar, entity_action, notify_error,16+ Yumush, avatar, entity_action, notify_error,
17 profile::user_link,17 profile::user_link,
18- style::{self, size, space},18+ style::{self, Tokens, size, space},
19 text,19 text,
20 },20 },
21 lang::w,21 lang::w,
@@ -29,13 +29,13 @@ impl Yumush {
29 cx,29 cx,
30 |network| async move { network.call(ListVoiceRooms).await },30 |network| async move { network.call(ListVoiceRooms).await },
31 |yumush, rooms, cx| {31 |yumush, rooms, cx| {
32- yumush.chat.builder_voice_rooms = rooms;32+ yumush.chat.admin.builder_voice_rooms = rooms;
33 cx.notify();33 cx.notify();
34 },34 },
35 );35 );
36 }36 }
37 37
38- pub(super) fn voice_action<Fut>(38+ fn voice_action<Fut>(
39 &mut self,39 &mut self,
40 window: &mut Window,40 window: &mut Window,
41 cx: &mut Context<Self>,41 cx: &mut Context<Self>,
@@ -55,7 +55,7 @@ impl Yumush {
55 .detach();55 .detach();
56 }56 }
57 57
58- pub(super) fn set_server_mute(58+ fn set_server_mute(
59 &mut self,59 &mut self,
60 user_id: Id,60 user_id: Id,
61 muted: bool,61 muted: bool,
@@ -67,61 +67,53 @@ impl Yumush {
67 });67 });
68 }68 }
69 69
70- pub(super) fn kick_from_voice(70+ fn kick_from_voice(&mut self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {
71- &mut self,
72- user_id: Id,
73- window: &mut Window,
74- cx: &mut Context<Self>,
75- ) {
76 self.voice_action(window, cx, move |network| async move {71 self.voice_action(window, cx, move |network| async move {
77 network.call(KickFromVoice { user_id }).await72 network.call(KickFromVoice { user_id }).await
78 });73 });
79 }74 }
80 75
81- pub(super) fn voice_body(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {76+ pub(super) fn voice_body(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
82 let mut body = Vec::new();77 let mut body = Vec::new();
83 78
84- if self.chat.builder_voice_rooms.is_empty() {79+ if self.chat.admin.builder_voice_rooms.is_empty() {
85 body.push(80 body.push(
86- list_card(None, Vec::new(), w().builder_voice.no_rooms, palette).into_any_element(),81+ list_card(None, Vec::new(), w().builder_voice.no_rooms, t).into_any_element(),
87 );82 );
88 }83 }
89- body.extend(self.chat.builder_voice_rooms.iter().map(|room| {84+ body.extend(
90- self.voice_room_card(room, entity, palette)85+ self.chat
91- .into_any_element()86+ .admin
92- }));87+ .builder_voice_rooms
88+ .iter()
89+ .map(|room| self.voice_room_card(room, entity, t).into_any_element()),
90+ );
93 91
94 body92 body
95 }93 }
96 94
97- pub(super) fn voice_room_card(95+ fn voice_room_card(&self, room: &VoiceRoom, entity: &Entity<Self>, t: Tokens) -> Div {
98- &self,
99- room: &VoiceRoom,
100- entity: &Entity<Self>,
101- palette: Palette,
102- ) -> Div {
103 let id = room.community_id;96 let id = room.community_id;
104 let voice = self97 let voice = self
105 .chat98 .chat
99+ .admin
106 .builder_communities100 .builder_communities
107 .iter()101 .iter()
108 .find(|summary| summary.community.id == id)102 .find(|summary| summary.community.id == id)
109 .map(|summary| summary.community.voice_enabled);103 .map(|summary| summary.community.voice_enabled);
110 104
111 let joined = self.chat.in_voice(id);105 let joined = self.chat.in_voice(id);
112- let join_id = id;106+ let mut actions = vec![pill(&room.users.len().to_string(), t.dim()).into_any_element()];
113- let mut actions =
114- vec![pill(&room.users.len().to_string(), palette.muted, palette).into_any_element()];
115 if !joined {107 if !joined {
116 actions.push(108 actions.push(
117 icon_button(109 icon_button(
118 format!("room_join_{id}"),110 format!("room_join_{id}"),
119 IconName::Headphones,111 IconName::Headphones,
120 w().builder_voice.join,112 w().builder_voice.join,
121- palette.ok,113+ t.hue(Hue::Mint),
122- palette,114+ t,
123 entity_action(entity, move |yumush, window, cx| {115 entity_action(entity, move |yumush, window, cx| {
124- yumush.jump_to(join_id, true, window, cx)116+ yumush.jump_to(id, true, window, cx)
125 }),117 }),
126 )118 )
127 .into_any_element(),119 .into_any_element(),
@@ -141,10 +133,10 @@ impl Yumush {
141 } else {133 } else {
142 w().builder_voice.voice_off134 w().builder_voice.voice_off
143 },135 },
144- palette.muted,136+ t.dim(),
145- palette,137+ t,
146 entity_action(entity, move |yumush, window, cx| {138 entity_action(entity, move |yumush, window, cx| {
147- yumush.set_builder_community_voice(id, !enabled, window, cx)139+ yumush.set_community_voice(id, !enabled, window, cx)
148 }),140 }),
149 )141 )
150 .into_any_element(),142 .into_any_element(),
@@ -160,27 +152,25 @@ impl Yumush {
160 room.muted.contains(&user.id),152 room.muted.contains(&user.id),
161 room.ghosts.contains(&user.id),153 room.ghosts.contains(&user.id),
162 entity,154 entity,
163- palette,155+ t,
164 )156 )
165 })157 })
166 .collect();158 .collect();
167 159
168- card(palette)160+ card()
169- .child(card_header(&room.community, actions, palette))161+ .child(card_header(&room.community, actions, t))
170- .child(rows_body(rows, w().common.no_users, palette))162+ .child(rows_body(rows, w().common.no_users, t))
171 }163 }
172 164
173- pub(super) fn voice_user_row(165+ fn voice_user_row(
174 &self,166 &self,
175 user: &User,167 user: &User,
176 muted: bool,168 muted: bool,
177 ghost: bool,169 ghost: bool,
178 entity: &Entity<Self>,170 entity: &Entity<Self>,
179- palette: Palette,171+ t: Tokens,
180 ) -> Div {172 ) -> Div {
181 let id = user.id;173 let id = user.id;
182- let mute_id = id;
183- let kick_id = id;
184 174
185 list_row()175 list_row()
186 .px(px(space::LG))176 .px(px(space::LG))
@@ -194,24 +184,24 @@ impl Yumush {
194 .items_center()184 .items_center()
195 .gap(px(space::MD))185 .gap(px(space::MD))
196 .child(avatar(186 .child(avatar(
197- palette,187+ t,
198 user,188 user,
199 px(size::AVATAR),189 px(size::AVATAR),
200 text(style::text::CAPTION),190 text(style::text::CAPTION),
201- &self.chat.avatars,191+ &self.chat.session.avatars,
202 ))192 ))
203 .child(193 .child(
204 div()194 div()
205 .min_w_0()195 .min_w_0()
206 .truncate()196 .truncate()
207 .text_size(text(style::text::LABEL))197 .text_size(text(style::text::LABEL))
208- .text_color(palette.text)198+ .text_color(t.paper())
209 .child(user.username.clone()),199 .child(user.username.clone()),
210 ),200 ),
211 )),201 )),
212 )202 )
213- .children(muted.then(|| pill(w().builder_voice.muted, palette.danger, palette)))203+ .children(muted.then(|| pill(w().builder_voice.muted, t.bad())))
214- .children(ghost.then(|| pill(w().builder_voice.ghost, palette.muted, palette)))204+ .children(ghost.then(|| pill(w().builder_voice.ghost, t.dim())))
215 .child(icon_button(205 .child(icon_button(
216 format!("voice_mute_{id}_{muted}"),206 format!("voice_mute_{id}_{muted}"),
217 if muted {207 if muted {
@@ -224,20 +214,20 @@ impl Yumush {
224 } else {214 } else {
225 w().builder_voice.mute215 w().builder_voice.mute
226 },216 },
227- palette.muted,217+ t.dim(),
228- palette,218+ t,
229 entity_action(entity, move |yumush, window, cx| {219 entity_action(entity, move |yumush, window, cx| {
230- yumush.set_server_mute(mute_id, !muted, window, cx)220+ yumush.set_server_mute(id, !muted, window, cx)
231 }),221 }),
232 ))222 ))
233 .child(icon_button(223 .child(icon_button(
234 format!("voice_kick_{id}"),224 format!("voice_kick_{id}"),
235 IconName::UserX,225 IconName::UserX,
236 w().builder_voice.kick,226 w().builder_voice.kick,
237- palette.danger,227+ t.bad(),
238- palette,228+ t,
239 entity_action(entity, move |yumush, window, cx| {229 entity_action(entity, move |yumush, window, cx| {
240- yumush.kick_from_voice(kick_id, window, cx)230+ yumush.kick_from_voice(id, window, cx)
241 }),231 }),
242 ))232 ))
243 }233 }
crates/client/src/gui/call_bar.rsmodified+13 -22
@@ -1,5 +1,5 @@
1 use gpui_kit::prelude::FluentBuilder as _;1 use gpui_kit::prelude::FluentBuilder as _;
2-use std::{collections::VecDeque, rc::Rc};2+use std::collections::VecDeque;
3 3
4 use gpui_kit::{4 use gpui_kit::{
5 AnyElement, App, Div, FontWeight, InteractiveElement, ParentElement, SharedString,5 AnyElement, App, Div, FontWeight, InteractiveElement, ParentElement, SharedString,
@@ -13,7 +13,7 @@ use super::{
13 };13 };
14 use crate::lang::w;14 use crate::lang::w;
15 15
16-pub type Action = Rc<dyn Fn(&mut Window, &mut App)>;16+pub type Action = Box<dyn Fn(&mut Window, &mut App)>;
17 17
18 pub struct CallBar {18 pub struct CallBar {
19 pub place: SharedString,19 pub place: SharedString,
@@ -24,7 +24,6 @@ pub struct CallBar {
24 pub muted: bool,24 pub muted: bool,
25 pub deafened: bool,25 pub deafened: bool,
26 pub camera: bool,26 pub camera: bool,
27- pub screen: bool,
28 pub share: Option<(Option<VecDeque<f32>>, gpui_kit::Hsla)>,27 pub share: Option<(Option<VecDeque<f32>>, gpui_kit::Hsla)>,
29 pub stats: bool,28 pub stats: bool,
30 pub ghost: bool,29 pub ghost: bool,
@@ -44,11 +43,6 @@ pub struct CallActions {
44 pub screen_more: AnyElement,43 pub screen_more: AnyElement,
45 }44 }
46 45
47-fn run(action: &Action) -> impl Fn(&mut Window, &mut App) + 'static {
48- let action = action.clone();
49- move |window, cx| action(window, cx)
50-}
51-
52 pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {46 pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
53 let tone = |on: bool| if on { Tone::On } else { Tone::Idle };47 let tone = |on: bool| if on { Tone::On } else { Tone::Idle };
54 let alarm = |on: bool| if on { Tone::Danger } else { Tone::Idle };48 let alarm = |on: bool| if on { Tone::Danger } else { Tone::Idle };
@@ -68,7 +62,7 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
68 .pings62 .pings
69 .last()63 .last()
70 .map_or_else(|| "–".to_string(), |ping| format!("{ping:.0} ms"));64 .map_or_else(|| "–".to_string(), |ping| format!("{ping:.0} ms"));
71- let stats = run(&actions.stats);65+ let screen = bar.share.is_some();
72 let controls = band(space::XS)66 let controls = band(space::XS)
73 .flex_none()67 .flex_none()
74 .child(icon_button(68 .child(icon_button(
@@ -86,7 +80,7 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
86 alarm(bar.muted),80 alarm(bar.muted),
87 Scale::Normal,81 Scale::Normal,
88 t,82 t,
89- run(&actions.mute),83+ actions.mute,
90 ))84 ))
91 .child(actions.mic_more)85 .child(actions.mic_more)
92 .child(icon_button(86 .child(icon_button(
@@ -104,7 +98,7 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
104 alarm(bar.deafened),98 alarm(bar.deafened),
105 Scale::Normal,99 Scale::Normal,
106 t,100 t,
107- run(&actions.deafen),101+ actions.deafen,
108 ))102 ))
109 .child(actions.speaker_more)103 .child(actions.speaker_more)
110 .when(!bar.ghost, |row| {104 .when(!bar.ghost, |row| {
@@ -119,21 +113,21 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
119 tone(bar.camera),113 tone(bar.camera),
120 Scale::Normal,114 Scale::Normal,
121 t,115 t,
122- run(&actions.camera),116+ actions.camera,
123 ))117 ))
124 .child(actions.camera_more)118 .child(actions.camera_more)
125 .child(icon_button(119 .child(icon_button(
126- format!("bar_screen_{}", bar.screen),120+ format!("bar_screen_{screen}"),
127 IconName::ScreenShare,121 IconName::ScreenShare,
128- if bar.screen {122+ if screen {
129 w().call_bar.stop_sharing123 w().call_bar.stop_sharing
130 } else {124 } else {
131 w().call_bar.share_screen125 w().call_bar.share_screen
132 },126 },
133- tone(bar.screen),127+ tone(screen),
134 Scale::Normal,128 Scale::Normal,
135 t,129 t,
136- run(&actions.screen),130+ actions.screen,
137 ))131 ))
138 .child(actions.screen_more)132 .child(actions.screen_more)
139 })133 })
@@ -144,7 +138,7 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
144 Tone::Danger,138 Tone::Danger,
145 Scale::Normal,139 Scale::Normal,
146 t,140 t,
147- run(&actions.leave),141+ actions.leave,
148 ));142 ));
149 div().flex_none().child(thread(t)).child(143 div().flex_none().child(thread(t)).child(
150 band(space::LG)144 band(space::LG)
@@ -165,10 +159,7 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
165 })159 })
166 .cursor_pointer()160 .cursor_pointer()
167 .tip(w().call_bar.go_to_call)161 .tip(w().call_bar.go_to_call)
168- .on_click({162+ .on_click(move |_, window, cx| (actions.go)(window, cx))
169- let go = run(&actions.go);
170- move |_, window, cx| go(window, cx)
171- })
172 .child(super::parts::small_icon(IconName::Phone).text_color(t.dim()))163 .child(super::parts::small_icon(IconName::Phone).text_color(t.dim()))
173 .child(164 .child(
174 words(bar.place, Text::Ui, Ink::Paper, t)165 words(bar.place, Text::Ui, Ink::Paper, t)
@@ -202,7 +193,7 @@ pub fn view(bar: CallBar, actions: CallActions, t: Tokens) -> Div {
202 })193 })
203 .cursor_pointer()194 .cursor_pointer()
204 .tip(w().call_bar.connection_stats)195 .tip(w().call_bar.connection_stats)
205- .on_click(move |_, window, cx| stats(window, cx))196+ .on_click(move |_, window, cx| (actions.stats)(window, cx))
206 .child(197 .child(
207 div()198 div()
208 .w(px(size::ROW))199 .w(px(size::ROW))
crates/client/src/gui/camera_view.rsmodified+175 -123
@@ -1,25 +1,25 @@
1+use std::collections::VecDeque;
1 use std::time::{Duration, Instant};2 use std::time::{Duration, Instant};
2 3
3 use common::model::Id;4 use common::model::Id;
4-
5 use common::share::{Fps, Kind, Quality, Resolution};5 use common::share::{Fps, Kind, Quality, Resolution};
6 use gpui_kit::{6 use gpui_kit::{
7 AnyElement, AppContext as _, Context, Div, Entity, InteractiveElement, IntoElement,7 AnyElement, AppContext as _, Context, Div, Entity, InteractiveElement, IntoElement,
8 ParentElement, StatefulInteractiveElement, Styled, Task, Window, assets::IconName, div,8 ParentElement, StatefulInteractiveElement, Styled, Task, Window, assets::IconName, div,
9 prelude::FluentBuilder as _, px,9 prelude::FluentBuilder as _, px,
10 };10 };
11+use std::sync::atomic::{AtomicBool, Ordering};
11 12
12 use super::{13 use super::{
13- Palette, Tooltip as _, Yumush,14+ Tooltip as _, Yumush,
14 media_view::into_render_image,15 media_view::into_render_image,
15 notify_error,16 notify_error,
16 parts::{Ink, Text, Voice, caption, scrim, voice_line, words},17 parts::{Ink, Text, Voice, caption, scrim, voice_line, words},
17- style::{radius, size, space},18+ style::{Tokens, radius, size, space},
18 surface::Surface,19 surface::Surface,
19- widget::spawn_warn,
20 };20 };
21 use crate::lang::w;21 use crate::lang::w;
22-use crate::share::session::WatchQuality;22+use crate::share::watch::WatchQuality;
23 23
24 const SLOTS: usize = 6;24 const SLOTS: usize = 6;
25 const IDLE_TICK: Duration = Duration::from_millis(250);25 const IDLE_TICK: Duration = Duration::from_millis(250);
@@ -27,11 +27,12 @@ const FRAME_TICK: Duration = Duration::from_millis(16);
27 const PUMP_STALL: Duration = Duration::from_millis(50);27 const PUMP_STALL: Duration = Duration::from_millis(50);
28 const TILE_W: f32 = size::THUMB * 1.5;28 const TILE_W: f32 = size::THUMB * 1.5;
29 const TILE_H: f32 = TILE_W * 9. / 16.;29 const TILE_H: f32 = TILE_W * 9. / 16.;
30-30+const TILE_QUALITY: WatchQuality = WatchQuality::Fixed(Quality {
31-pub(super) const TILE_QUALITY: WatchQuality = WatchQuality::Fixed(Quality {
32 resolution: Resolution::P360,31 resolution: Resolution::P360,
33 fps: Fps::F15,32 fps: Fps::F15,
34 });33 });
34+const WIDE: f32 = 16. / 9.;
35+const GRID_GAP: f32 = super::style::stroke::LINE;
35 36
36 #[derive(Clone, Copy, PartialEq, Eq)]37 #[derive(Clone, Copy, PartialEq, Eq)]
37 pub(super) enum Stage {38 pub(super) enum Stage {
@@ -40,29 +41,81 @@ pub(super) enum Stage {
40 Hidden,41 Hidden,
41 }42 }
42 43
43-pub(super) fn tile_quality(stage: Stage) -> WatchQuality {44+impl Stage {
44- match stage {45+ pub(super) fn quality(self) -> WatchQuality {
45- Stage::Grid => WatchQuality::Auto,46+ match self {
46- Stage::Strip | Stage::Hidden => TILE_QUALITY,47+ Stage::Grid => WatchQuality::Auto,
48+ Stage::Strip | Stage::Hidden => TILE_QUALITY,
49+ }
50+ }
51+
52+ fn cover(self) -> bool {
53+ self != Stage::Grid
47 }54 }
48 }55 }
49 56
50 pub(super) struct Tile {57 pub(super) struct Tile {
51 pub(super) shown: bool,58 pub(super) shown: bool,
59+ pub(super) live: bool,
52 pub(super) surface: Entity<Surface>,60 pub(super) surface: Entity<Surface>,
53 }61 }
54 62
55-fn tile_cover(stage: Stage) -> bool {
56- stage != Stage::Grid
57-}
58-
59 impl Yumush {63 impl Yumush {
60 fn tile_sources(&self) -> Vec<(Id, Kind)> {64 fn tile_sources(&self) -> Vec<(Id, Kind)> {
61- let shown = self.chat.stage != Stage::Hidden;65+ if self.chat.stage == Stage::Hidden {
66+ return Vec::new();
67+ }
62 self.stage_sources()68 self.stage_sources()
63- .into_iter()69+ }
64- .filter(|(_, kind)| shown || *kind == Kind::Camera)70+
65- .collect()71+ fn watch_quality(&self, source: (Id, Kind)) -> WatchQuality {
72+ if self.viewing() == Some(source) {
73+ WatchQuality::Auto
74+ } else {
75+ self.chat.stage.quality()
76+ }
77+ }
78+
79+ fn watch_tile(&self, source: (Id, Kind), cx: &mut Context<Self>) {
80+ let (user_id, kind) = source;
81+ let network = self.network.clone();
82+ let quality = self.chat.stage.quality();
83+ let volume = self.settings.share.volume;
84+ let choice = self.settings.voice.choice.clone();
85+ let top = self.share_top(user_id, kind);
86+ cx.spawn(async move |this, cx| {
87+ let watched = network
88+ .watch_share(user_id, kind, quality, top, volume, choice)
89+ .await;
90+ let live = watched.is_ok();
91+ if let Err(error) = &watched {
92+ tracing::warn!("tile watch failed: {error}");
93+ }
94+ let orphaned = this.update(cx, |yumush, _| {
95+ let Some(tile) = yumush.chat.session.tiles.get_mut(&source) else {
96+ return live && yumush.viewing() != Some(source);
97+ };
98+ tile.live = live;
99+ if live {
100+ yumush
101+ .network
102+ .set_watch_quality(user_id, kind, yumush.watch_quality(source));
103+ }
104+ false
105+ });
106+ if let Ok(true) = orphaned {
107+ let _ = network.unwatch_share(user_id, kind).await;
108+ }
109+ })
110+ .detach();
111+ }
112+
113+ pub(super) fn unwatch_tile(&self, (user_id, kind): (Id, Kind), cx: &mut Context<Self>) {
114+ let network = self.network.clone();
115+ cx.spawn(async move |_, _| {
116+ let _ = network.unwatch_share(user_id, kind).await;
117+ })
118+ .detach();
66 }119 }
67 120
68 pub(super) fn tick_tiles(121 pub(super) fn tick_tiles(
@@ -72,70 +125,59 @@ impl Yumush {
72 ) -> bool {125 ) -> bool {
73 let wanted = self.tile_sources();126 let wanted = self.tile_sources();
74 let viewing = self.viewing();127 let viewing = self.viewing();
75- let quality = tile_quality(self.chat.stage);
76 let mut changed = false;128 let mut changed = false;
77 129
78 for &source in &wanted {130 for &source in &wanted {
79- if self.chat.tiles.contains_key(&source) {131+ if self.chat.session.tiles.contains_key(&source) {
80 continue;132 continue;
81 }133 }
82- let cover = tile_cover(self.chat.stage);
83 let network = self.network.clone();134 let network = self.network.clone();
135+ let cover = self.chat.stage.cover();
84 let surface = cx.new(|cx| Surface::new(cover, network, source, cx));136 let surface = cx.new(|cx| Surface::new(cover, network, source, cx));
85- self.chat.tiles.insert(137+ let live = viewing == Some(source);
138+ self.chat.session.tiles.insert(
86 source,139 source,
87 Tile {140 Tile {
88 shown: false,141 shown: false,
142+ live,
89 surface,143 surface,
90 },144 },
91 );145 );
92 changed = true;146 changed = true;
93- if viewing == Some(source) {147+ if !live {
94- continue;148+ self.watch_tile(source, cx);
95 }149 }
96- let (user_id, kind) = source;
97- let network = self.network.clone();
98- let volume = self.settings.share.volume;
99- let choice = self.settings.voice.choice.clone();
100- let top = self.share_top(user_id, kind);
101- spawn_warn(cx, "tile watch", async move {
102- network
103- .watch_share(user_id, kind, quality, top, volume, choice)
104- .await
105- });
106 }150 }
107 151
108 let gone: Vec<(Id, Kind)> = self152 let gone: Vec<(Id, Kind)> = self
109 .chat153 .chat
154+ .session
110 .tiles155 .tiles
111 .keys()156 .keys()
112 .filter(|source| !wanted.contains(source))157 .filter(|source| !wanted.contains(source))
113 .copied()158 .copied()
114 .collect();159 .collect();
115 for source in gone {160 for source in gone {
116- if let Some(tile) = self.chat.tiles.remove(&source)161+ let Some(tile) = self.chat.session.tiles.remove(&source) else {
117- && let Some(frame) = tile162+ continue;
118- .surface163+ };
119- .update(cx, |surface, cx| surface.replace(None, cx))164+ if let Some(frame) = tile
165+ .surface
166+ .update(cx, |surface, cx| surface.replace(None, cx))
120 {167 {
121 cx.drop_image(frame, window.as_deref_mut());168 cx.drop_image(frame, window.as_deref_mut());
122 }169 }
123- if viewing != Some(source) {170+ if tile.live && viewing != Some(source) {
124- let network = self.network.clone();171+ self.unwatch_tile(source, cx);
125- let (user_id, kind) = source;
126- cx.spawn(async move |_, _| {
127- let _ = network.unwatch_share(user_id, kind).await;
128- })
129- .detach();
130 }172 }
131 changed = true;173 changed = true;
132 }174 }
133 175
134- for (&(user_id, kind), tile) in self.chat.tiles.iter_mut() {176+ for (&source, tile) in self.chat.session.tiles.iter_mut() {
135- if viewing == Some((user_id, kind)) {177+ if viewing == Some(source) {
136 continue;178 continue;
137 }179 }
138- let Some(frame) = self.network.share_frame(user_id, kind) else {180+ let Some(frame) = self.network.share_frame(source.0, source.1) else {
139 continue;181 continue;
140 };182 };
141 let next = into_render_image(frame);183 let next = into_render_image(frame);
@@ -152,42 +194,48 @@ impl Yumush {
152 if changed {194 if changed {
153 cx.notify();195 cx.notify();
154 }196 }
155- !self.chat.tiles.is_empty()197+ !self.chat.session.tiles.is_empty()
156 }198 }
157 199
158 pub(super) fn set_stage(&mut self, stage: Stage, cx: &mut Context<Self>) {200 pub(super) fn set_stage(&mut self, stage: Stage, cx: &mut Context<Self>) {
159 self.chat.stage = stage;201 self.chat.stage = stage;
160- let viewing = self.viewing();202+ for (&source, tile) in &self.chat.session.tiles {
161- let quality = tile_quality(stage);203+ self.network
162- for (&(user_id, kind), tile) in &self.chat.tiles {204+ .set_watch_quality(source.0, source.1, self.watch_quality(source));
163- if viewing != Some((user_id, kind)) {
164- self.network.set_watch_quality(user_id, kind, quality);
165- }
166 tile.surface205 tile.surface
167- .update(cx, |surface, cx| surface.set_cover(tile_cover(stage), cx));206+ .update(cx, |surface, cx| surface.set_cover(stage.cover(), cx));
168 }207 }
169 cx.notify();208 cx.notify();
170 }209 }
171 210
172 pub(super) fn toggle_camera(&mut self, window: &mut Window, cx: &mut Context<Self>) {211 pub(super) fn toggle_camera(&mut self, window: &mut Window, cx: &mut Context<Self>) {
212+ if CAMERA_BUSY.load(Ordering::Relaxed) {
213+ return;
214+ }
215+ CAMERA_BUSY.store(true, Ordering::Relaxed);
173 let network = self.network.clone();216 let network = self.network.clone();
174- let on = network.camera_on();217+ let on = network.share_source(Kind::Camera).is_some();
175 let settings = self.settings.share.clone();218 let settings = self.settings.share.clone();
219+ let device = settings.camera_device.clone();
176 220
177 cx.spawn_in(window, async move |this, cx| {221 cx.spawn_in(window, async move |this, cx| {
178- if on {222+ let started = if on {
179- let _ = network.stop_camera().await;223+ let _ = network.stop(Kind::Camera).await;
180- } else if let Err(error) = network.start_camera(&settings).await {224+ Ok(())
225+ } else {
226+ network.start(Kind::Camera, &settings, None).await
227+ };
228+ if let Err(error) = started {
181 notify_error(&this, cx, error);229 notify_error(&this, cx, error);
182 }230 }
183- let _ = this.update(cx, |_, cx| cx.notify());231+ let _ = this.update(cx, |yumush, cx| yumush.settle_camera(device, cx));
184 })232 })
185 .detach();233 .detach();
186 }234 }
187 235
188 pub(super) fn in_stage_chat(&self) -> bool {236 pub(super) fn in_stage_chat(&self) -> bool {
189 self.chat.voice_community().is_some()237 self.chat.voice_community().is_some()
190- && self.chat.selected_community_id == self.chat.voice_community()238+ && self.chat.session.selected_community_id == self.chat.voice_community()
191 }239 }
192 240
193 pub(super) fn stage_sources(&self) -> Vec<(Id, Kind)> {241 pub(super) fn stage_sources(&self) -> Vec<(Id, Kind)> {
@@ -196,6 +244,7 @@ impl Yumush {
196 };244 };
197 let mut shares: Vec<&common::share::Share> = self245 let mut shares: Vec<&common::share::Share> = self
198 .chat246 .chat
247+ .session
199 .shares248 .shares
200 .get(&community_id)249 .get(&community_id)
201 .into_iter()250 .into_iter()
@@ -208,21 +257,17 @@ impl Yumush {
208 .collect()257 .collect()
209 }258 }
210 259
211- pub(super) fn stage_strip(260+ pub(super) fn stage_strip(&self, entity: &Entity<Self>, t: Tokens) -> Option<impl IntoElement> {
212- &self,261+ let visible = match self.chat.stage {
213- entity: &Entity<Self>,
214- palette: Palette,
215- ) -> Option<impl IntoElement> {
216- let shown = match self.chat.stage {
217 Stage::Strip => true,262 Stage::Strip => true,
218- Stage::Grid => self.chat.viewer.is_some(),263+ Stage::Grid => self.chat.session.viewer.is_some(),
219 Stage::Hidden => false,264 Stage::Hidden => false,
220 };265 };
221- if !shown || !self.in_stage_chat() {266+ if !visible || !self.in_stage_chat() {
222 return None;267 return None;
223 }268 }
224 let sources = self.stage_sources();269 let sources = self.stage_sources();
225- let (shown, more) = strip_slots(self.chat.strip_size.0, sources.len());270+ let (count, more) = strip_slots(self.chat.strip_size.0, sources.len());
226 (!sources.is_empty()).then(|| {271 (!sources.is_empty()).then(|| {
227 div()272 div()
228 .id("stage_strip")273 .id("stage_strip")
@@ -237,15 +282,15 @@ impl Yumush {
237 .children(282 .children(
238 sources283 sources
239 .into_iter()284 .into_iter()
240- .take(shown)285+ .take(count)
241- .map(|source| stage_tile(entity, self, palette, source).into_any_element()),286+ .map(|source| stage_tile(entity, self, t, source).into_any_element()),
242 )287 )
243- .children((more > 0).then(|| more_tile(entity, more, palette).into_any_element()))288+ .children((more > 0).then(|| more_tile(entity, more, t).into_any_element()))
244 })289 })
245 }290 }
246 291
247 fn slots(&self, ids: &[Id]) -> (Vec<Id>, usize) {292 fn slots(&self, ids: &[Id]) -> (Vec<Id>, usize) {
248- let speaking = |id: &Id| self.chat.waves.audible(*id);293+ let speaking = |id: &Id| self.chat.session.waves.audible(*id);
249 let mut shown: Vec<Id> = ids294 let mut shown: Vec<Id> = ids
250 .iter()295 .iter()
251 .filter(|id| speaking(id))296 .filter(|id| speaking(id))
@@ -263,14 +308,25 @@ impl Yumush {
263 (shown, more)308 (shown, more)
264 }309 }
265 310
266- fn voice_captions(&self, ids: &[Id], palette: Palette) -> Vec<Div> {311+ fn voice_captions(&self, ids: &[Id], t: Tokens) -> Vec<Div> {
267- let t = palette.tokens;
268 let (shown, more) = self.slots(ids);312 let (shown, more) = self.slots(ids);
269 shown313 shown
270 .into_iter()314 .into_iter()
271 .filter_map(|id| self.chat.author(id))315 .filter_map(|id| self.chat.author(id))
272 .map(|user| {316 .map(|user| {
273- let voice = if self.chat.waves.speaking.contains(&user.id) {317+ let bands = self
318+ .chat
319+ .session
320+ .waves
321+ .voice(user.id)
322+ .map(|bands| bands.iter().copied().collect::<VecDeque<f32>>());
323+ let share = self
324+ .chat
325+ .session
326+ .waves
327+ .share(user.id)
328+ .map(|bands| bands.iter().copied().collect::<VecDeque<f32>>());
329+ let voice = if self.chat.session.waves.speaking.contains(&user.id) {
274 Voice::Live(t.person(user.id))330 Voice::Live(t.person(user.id))
275 } else {331 } else {
276 Voice::Quiet332 Voice::Quiet
@@ -284,17 +340,15 @@ impl Yumush {
284 .is_some();340 .is_some();
285 caption(341 caption(
286 user.username.clone(),342 user.username.clone(),
287- voice_line(self.chat.waves.voice(user.id), voice, t),343+ voice_line(bands.as_ref(), voice, t),
288 t,344 t,
289 )345 )
290 .h(px(size::CONTROL_SM))346 .h(px(size::CONTROL_SM))
291- .children(screen.then(|| {347+ .children(
292- super::call_bar::share_meter(348+ screen.then(|| {
293- self.chat.waves.share(user.id),349+ super::call_bar::share_meter(share.as_ref(), t.person(user.id), t)
294- t.person(user.id),350+ }),
295- t,351+ )
296- )
297- }))
298 })352 })
299 .chain(353 .chain(
300 (more > 0)354 (more > 0)
@@ -303,7 +357,7 @@ impl Yumush {
303 .collect()357 .collect()
304 }358 }
305 359
306- pub(super) fn voice_band(&self, palette: Palette) -> Div {360+ pub(super) fn voice_band(&self, t: Tokens) -> Div {
307 let ids = self361 let ids = self
308 .chat362 .chat
309 .voice_community()363 .voice_community()
@@ -316,7 +370,7 @@ impl Yumush {
316 .px(px(space::XL))370 .px(px(space::XL))
317 .py(px(space::LG))371 .py(px(space::LG))
318 .children(372 .children(
319- self.voice_captions(&ids, palette)373+ self.voice_captions(&ids, t)
320 .into_iter()374 .into_iter()
321 .map(|caption| caption.flex_1().min_w_0()),375 .map(|caption| caption.flex_1().min_w_0()),
322 )376 )
@@ -325,20 +379,20 @@ impl Yumush {
325 pub(super) fn stage_grid(379 pub(super) fn stage_grid(
326 &self,380 &self,
327 entity: &Entity<Self>,381 entity: &Entity<Self>,
328- palette: Palette,382+ t: Tokens,
329 cx: &gpui_kit::App,383 cx: &gpui_kit::App,
330 ) -> Option<impl IntoElement> {384 ) -> Option<impl IntoElement> {
331 if self.chat.stage != Stage::Grid385 if self.chat.stage != Stage::Grid
332 || !self.in_stage_chat()386 || !self.in_stage_chat()
333 || self387 || self
334 .chat388 .chat
389+ .session
335 .viewer390 .viewer
336 .as_ref()391 .as_ref()
337 .is_some_and(|viewer| !viewer.fullscreen)392 .is_some_and(|viewer| !viewer.fullscreen)
338 {393 {
339 return None;394 return None;
340 }395 }
341- self.chat.voice_community()?;
342 let sources = self.stage_sources();396 let sources = self.stage_sources();
343 if sources.is_empty() {397 if sources.is_empty() {
344 return None;398 return None;
@@ -347,6 +401,7 @@ impl Yumush {
347 .iter()401 .iter()
348 .map(|source| {402 .map(|source| {
349 self.chat403 self.chat
404+ .session
350 .tiles405 .tiles
351 .get(source)406 .get(source)
352 .map_or(WIDE, |tile| tile.surface.read(cx).aspect())407 .map_or(WIDE, |tile| tile.surface.read(cx).aspect())
@@ -357,9 +412,9 @@ impl Yumush {
357 let (cell_w, cell_h) = cell_size(sources.len(), columns, size);412 let (cell_w, cell_h) = cell_size(sources.len(), columns, size);
358 let mut cells = sources.into_iter().zip(aspects).map(|(source, aspect)| {413 let mut cells = sources.into_iter().zip(aspects).map(|(source, aspect)| {
359 let width = cell_w.min(cell_h * aspect);414 let width = cell_w.min(cell_h * aspect);
360- grid_cell(entity, self, palette, source, (width, width / aspect))415+ grid_cell(entity, self, t, source, (width, width / aspect))
361 });416 });
362- let rows = (0..sources_rows(columns, cells.len()))417+ let rows = (0..row_count(columns, cells.len()))
363 .map(|_| {418 .map(|_| {
364 div()419 div()
365 .flex()420 .flex()
@@ -369,7 +424,6 @@ impl Yumush {
369 .children(cells.by_ref().take(columns).collect::<Vec<_>>())424 .children(cells.by_ref().take(columns).collect::<Vec<_>>())
370 })425 })
371 .collect::<Vec<_>>();426 .collect::<Vec<_>>();
372- let measure = entity.clone();
373 427
374 Some(428 Some(
375 div()429 div()
@@ -380,7 +434,7 @@ impl Yumush {
380 .flex_col()434 .flex_col()
381 .justify_center()435 .justify_center()
382 .gap(px(GRID_GAP))436 .gap(px(GRID_GAP))
383- .child(probe(measure, |yumush| &mut yumush.chat.grid_size))437+ .child(probe(entity.clone(), |yumush| &mut yumush.chat.grid_size))
384 .children(rows),438 .children(rows),
385 )439 )
386 }440 }
@@ -415,15 +469,12 @@ fn strip_slots(width: f32, count: usize) -> (usize, usize) {
415 }469 }
416 }470 }
417 471
418-const WIDE: f32 = 16. / 9.;472+fn row_count(columns: usize, count: usize) -> usize {
419-const GRID_GAP: f32 = super::style::stroke::LINE;
420-
421-fn sources_rows(columns: usize, count: usize) -> usize {
422 count.div_ceil(columns.max(1))473 count.div_ceil(columns.max(1))
423 }474 }
424 475
425 fn cell_size(count: usize, columns: usize, (width, height): (f32, f32)) -> (f32, f32) {476 fn cell_size(count: usize, columns: usize, (width, height): (f32, f32)) -> (f32, f32) {
426- let rows = sources_rows(columns, count);477+ let rows = row_count(columns, count);
427 (478 (
428 (width - GRID_GAP * (columns - 1) as f32) / columns as f32,479 (width - GRID_GAP * (columns - 1) as f32) / columns as f32,
429 (height - GRID_GAP * (rows - 1) as f32) / rows as f32,480 (height - GRID_GAP * (rows - 1) as f32) / rows as f32,
@@ -464,7 +515,9 @@ pub(super) fn ticker(cx: &mut Context<Yumush>) -> Task<()> {
464 515
465 impl Yumush {516 impl Yumush {
466 fn streaming(&self) -> bool {517 fn streaming(&self) -> bool {
467- self.chat.viewer.is_some() || !self.chat.tiles.is_empty() || self.media_playing()518+ self.chat.session.viewer.is_some()
519+ || !self.chat.session.tiles.is_empty()
520+ || self.media_playing()
468 }521 }
469 522
470 fn pump(&mut self, window: &mut Window, cx: &mut Context<Self>) {523 fn pump(&mut self, window: &mut Window, cx: &mut Context<Self>) {
@@ -496,21 +549,25 @@ impl Yumush {
496 }549 }
497 }550 }
498 551
552+fn tile_surface(yumush: &Yumush, source: (Id, Kind)) -> Option<Entity<Surface>> {
553+ yumush
554+ .chat
555+ .session
556+ .tiles
557+ .get(&source)
558+ .filter(|tile| tile.shown)
559+ .map(|tile| tile.surface.clone())
560+}
561+
499 fn stage_tile(562 fn stage_tile(
500 entity: &Entity<Yumush>,563 entity: &Entity<Yumush>,
501 yumush: &Yumush,564 yumush: &Yumush,
502- palette: Palette,565+ t: Tokens,
503 (user_id, kind): (Id, Kind),566 (user_id, kind): (Id, Kind),
504 ) -> impl IntoElement {567 ) -> impl IntoElement {
505- let t = palette.tokens;
506 let entity = entity.clone();568 let entity = entity.clone();
507 let focused = yumush.is_watching(user_id, kind);569 let focused = yumush.is_watching(user_id, kind);
508- let surface = yumush570+ let surface = tile_surface(yumush, (user_id, kind));
509- .chat
510- .tiles
511- .get(&(user_id, kind))
512- .filter(|tile| tile.shown)
513- .map(|tile| tile.surface.clone());
514 571
515 div()572 div()
516 .id(format!("stage_{user_id}_{kind:?}"))573 .id(format!("stage_{user_id}_{kind:?}"))
@@ -537,8 +594,7 @@ fn stage_tile(
537 )594 )
538 }595 }
539 596
540-fn more_tile(entity: &Entity<Yumush>, more: usize, palette: Palette) -> impl IntoElement {597+fn more_tile(entity: &Entity<Yumush>, more: usize, t: Tokens) -> impl IntoElement {
541- let t = palette.tokens;
542 let entity = entity.clone();598 let entity = entity.clone();
543 div()599 div()
544 .id("stage_more")600 .id("stage_more")
@@ -575,17 +631,12 @@ fn more_tile(entity: &Entity<Yumush>, more: usize, palette: Palette) -> impl Int
575 fn grid_cell(631 fn grid_cell(
576 entity: &Entity<Yumush>,632 entity: &Entity<Yumush>,
577 yumush: &Yumush,633 yumush: &Yumush,
578- palette: Palette,634+ t: Tokens,
579 (user_id, kind): (Id, Kind),635 (user_id, kind): (Id, Kind),
580 (width, height): (f32, f32),636 (width, height): (f32, f32),
581 ) -> AnyElement {637 ) -> AnyElement {
582 let entity = entity.clone();638 let entity = entity.clone();
583- let surface = yumush639+ let surface = tile_surface(yumush, (user_id, kind));
584- .chat
585- .tiles
586- .get(&(user_id, kind))
587- .filter(|tile| tile.shown)
588- .map(|tile| tile.surface.clone());
589 div()640 div()
590 .id(format!("grid_{user_id}_{kind:?}"))641 .id(format!("grid_{user_id}_{kind:?}"))
591 .w(px(width))642 .w(px(width))
@@ -602,7 +653,7 @@ fn grid_cell(
602 })653 })
603 .child(div().absolute().inset_0().children(surface))654 .child(div().absolute().inset_0().children(surface))
604 .child(655 .child(
605- tile_label(yumush, palette, (user_id, kind))656+ tile_label(yumush, t, (user_id, kind))
606 .absolute()657 .absolute()
607 .left(px(space::MD))658 .left(px(space::MD))
608 .top(px(space::MD)),659 .top(px(space::MD)),
@@ -610,10 +661,9 @@ fn grid_cell(
610 .into_any_element()661 .into_any_element()
611 }662 }
612 663
613-pub(super) fn tile_label(yumush: &Yumush, palette: Palette, source: (Id, Kind)) -> Div {664+pub(super) fn tile_label(yumush: &Yumush, t: Tokens, source: (Id, Kind)) -> Div {
614- let t = palette.tokens;
615 let user_id = source.0;665 let user_id = source.0;
616- let muted = yumush.chat.server_muted.contains(&user_id)666+ let muted = yumush.chat.session.server_muted.contains(&user_id)
617 || (yumush.is_me(user_id) && yumush.chat.voice_flags().is_some_and(|(muted, _)| muted));667 || (yumush.is_me(user_id) && yumush.chat.voice_flags().is_some_and(|(muted, _)| muted));
618 668
619 scrim(t)669 scrim(t)
@@ -631,7 +681,7 @@ fn tile_name(
631 .chat681 .chat
632 .author(user_id)682 .author(user_id)
633 .map_or_else(|| user_id.to_string(), |user| user.username.clone());683 .map_or_else(|| user_id.to_string(), |user| user.username.clone());
634- let audible = yumush.chat.waves.audible(user_id);684+ let audible = yumush.chat.session.waves.audible(user_id);
635 let ink = if audible || focused {685 let ink = if audible || focused {
636 Ink::Paper686 Ink::Paper
637 } else {687 } else {
@@ -653,6 +703,8 @@ fn tile_name(
653 )703 )
654 }704 }
655 705
706+pub(super) static CAMERA_BUSY: AtomicBool = AtomicBool::new(false);
707+
656 #[cfg(test)]708 #[cfg(test)]
657 mod tests {709 mod tests {
658 use super::{WIDE, grid_columns};710 use super::{WIDE, grid_columns};
crates/client/src/gui/chat.rsmodified+778 -1087

Diff too large; view file

@@ -1,36 +1,35 @@
1-use super::style::{self, radius, size, space, stroke, text};1+pub(super) mod admin;
2+pub(super) mod poll_draft;
3+pub(super) mod session;
4+
5+use self::admin::Admin;
6+use self::poll_draft::PollDraft;
7+use self::session::Session;
8+use super::style::{self, Tokens, radius, size, space, stroke, text};
2 use super::text;9 use super::text;
3 use crate::gui::glyph::Fill as _;10 use crate::gui::glyph::Fill as _;
4 use crate::lang::w;11 use crate::lang::w;
5 use std::{12 use std::{
6- collections::{BTreeMap, HashMap, HashSet, VecDeque},13+ collections::{HashSet, VecDeque},
7- sync::Arc,
8 time::{Duration, Instant},14 time::{Duration, Instant},
9 };15 };
10 16
11-use crate::gui::camera_view::{Stage, Tile};17+use crate::gui::camera_view::Stage;
12-use crate::gui::social::InviteLookup;
13 use crate::gui::voice_stats::{self, SAMPLE_HISTORY};18 use crate::gui::voice_stats::{self, SAMPLE_HISTORY};
14-use crate::gui::wave::Waves;
15 use crate::gui::{19 use crate::gui::{
16- JUMP_HINT, Palette, Tooltip as _, Yumush, avatar,20+ Tooltip as _, Yumush, avatar, clickable, community_name,
17- builder::{BuilderTab, Transfer},
18- clickable, community_name,
19 community_settings::{BanSort, LogSort},21 community_settings::{BanSort, LogSort},
20 composer::{self, Composer},22 composer::{self, Composer},
21- entity_action, hoverable,23+ entity_action, hoverable, media_view, message_actions, millis_time, new_input, notify_error,
22- media_view::{self, Media},24+ parts, poll, presence_avatar,
23- message_actions, millis_time, new_input, notify_error, palette, parts, poll, presence_avatar,
24 profile::profile_popover,25 profile::profile_popover,
25- share_view::Viewer,
26 sidebar::unread_badge,26 sidebar::unread_badge,
27 snippet,27 snippet,
28 voice_note::{self, VoiceNote},28 voice_note::{self, VoiceNote},
29 widget::{ok_or_notify, search_text, spawn_done},29 widget::{ok_or_notify, search_text, spawn_done},
30 };30 };
31-use crate::net::Levels;31+use crate::net::{Fail, Levels};
32 use crate::settings::VOLUME;32 use crate::settings::VOLUME;
33-use crate::share::session::ShareSample;
34 use common::{33 use common::{
35 call::{34 call::{
36 CreateCommunity, DeclineCall, DeleteMessage, GetUser, LeaveCommunity, ListBans,35 CreateCommunity, DeclineCall, DeleteMessage, GetUser, LeaveCommunity, ListBans,
@@ -40,26 +39,22 @@ use common::{
40 constant::MESSAGE_PAGE_LIMIT,39 constant::MESSAGE_PAGE_LIMIT,
41 event::Event,40 event::Event,
42 model::{41 model::{
43- Account, AdminActionKind, AdminLogEntry, AttachmentInfo, Ban, BanScope, CallLog, Community,42+ CallLog, Community, CommunityKind, Hue, Id, Member, Message, Presence, Rank, Reply, Unread,
44- CommunityKind, CommunitySummary, CommunityUsage, DayStat, Edit, Friends, Id, Invitation,43+ User, mentions,
45- InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Reply, Report,
46- ReportStatus, ServerBan, SessionInfo, Unread, UpdateClient, Usage, User, VoiceRoom,
47- mentions,
48 },44 },
49 permission,45 permission,
50 share::{Kind, Share},46 share::{Kind, Share},
47+ stats::ShareSample,
51 };48 };
52 use gpui_kit::{49 use gpui_kit::{
53- Anchor, AnimationExt, AnyElement, App, AppContext, Context, Div, Entity, FontWeight, Image,50+ Anchor, AnimationExt, AnyElement, App, AppContext, Context, Div, Entity, FontWeight,
54 InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement,51 InteractiveElement, IntoElement, ParentElement, ScrollHandle, StatefulInteractiveElement,
55- Styled, Subscription, Task, Window,52+ Styled, Subscription, Window,
56 assets::IconName,53 assets::IconName,
57 component::{54 component::{
58- Icon, IndexPath, WindowExt,55+ Icon, WindowExt,
59 input::{InputEvent, InputState, Textarea, TextareaState},56 input::{InputEvent, InputState, Textarea, TextareaState},
60 resizable::{h_resizable, resizable_panel, v_resizable},57 resizable::{h_resizable, resizable_panel, v_resizable},
61- searchable_list::SearchableVec,
62- select::SelectState,
63 slider::{SliderEvent, SliderState},58 slider::{SliderEvent, SliderState},
64 text::TextView,59 text::TextView,
65 },60 },
@@ -74,15 +69,16 @@ pub enum StatsAt {
74 Dock,69 Dock,
75 }70 }
76 71
77-#[derive(Debug, Clone, Copy, PartialEq, Eq)]72+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
78 pub enum View {73 pub enum View {
74+ #[default]
79 Chat,75 Chat,
80 Settings,76 Settings,
81 CommunitySettings,77 CommunitySettings,
82 Builder,78 Builder,
83 }79 }
84 80
85-#[derive(Debug, Clone, Copy, PartialEq, Eq)]81+#[derive(Debug, Clone, PartialEq, Eq)]
86 pub enum Armed {82 pub enum Armed {
87 LogOut,83 LogOut,
88 Leave(Id),84 Leave(Id),
@@ -91,10 +87,17 @@ pub enum Armed {
91 DeleteAccount,87 DeleteAccount,
92 DeleteCommunity,88 DeleteCommunity,
93 RestartServer,89 RestartServer,
90+ DeleteMessage(Id),
91+ DeleteAttachment(Id),
92+ BuilderDeleteUser(Id),
93+ PurgeUser(Id),
94+ BuilderDeleteCommunity(Id),
95+ DeleteInvite(String),
94 }96 }
95 97
96-#[derive(Debug, Clone, PartialEq, Eq)]98+#[derive(Debug, Clone, PartialEq, Eq, Default)]
97 pub enum VoiceState {99 pub enum VoiceState {
100+ #[default]
98 Off,101 Off,
99 In {102 In {
100 community_id: Id,103 community_id: Id,
@@ -104,10 +107,11 @@ pub enum VoiceState {
104 },107 },
105 }108 }
106 109
107-#[derive(Debug, Clone, Copy, PartialEq, Eq)]110+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
108-enum History {111+pub(super) enum History {
109- More,112+ #[default]
110 End,113 End,
114+ More,
111 }115 }
112 116
113 impl History {117 impl History {
@@ -126,177 +130,39 @@ pub enum ReportTarget {
126 User(Id),130 User(Id),
127 }131 }
128 132
129-#[derive(Debug, Clone, Copy, PartialEq, Eq)]133+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
130 pub enum CardMenu {134 pub enum CardMenu {
135+ #[default]
131 Main,136 Main,
132 More,137 More,
133 Status,138 Status,
134 }139 }
135 140
136 pub struct Chat {141 pub struct Chat {
137- pub(super) communities: Vec<Community>,142+ pub(super) session: Session,
138- pub(super) selected_community_id: Option<Id>,143+ pub(super) admin: Admin,
139- pub(super) opened: Option<Community>,144+ pub(super) poll: PollDraft,
140- pub(super) ghost: bool,145+ pub(super) composer: Composer,
141- pub(super) members: Vec<Member>,
142- pub(super) messages: Vec<Message>,
143- pub(super) pins: Vec<Message>,
144- history: History,
145- pub(super) unread: HashMap<Id, Unread>,
146- pub(super) unread_anchor: Option<(Id, u32)>,
147- unseen: u32,
148- pub(super) muted: HashSet<Id>,
149- pub(super) pinned: HashSet<Id>,
150- pub(super) edits: HashMap<Id, Vec<Edit>>,
151- pub(super) revealed: HashSet<Id>,
152 pub(super) message_input: Entity<TextareaState>,146 pub(super) message_input: Entity<TextareaState>,
153 pub(super) search_input: Entity<InputState>,147 pub(super) search_input: Entity<InputState>,
154- pub(super) friends_open: bool,
155- pub(super) open_calls: HashSet<Id>,
156 pub(super) community_search: Entity<InputState>,148 pub(super) community_search: Entity<InputState>,
157- pub(super) community_hits: Vec<MessageHit>,
158- pub(super) found: Option<User>,
159- pub(super) invite: InviteLookup,
160- pub(super) sidebar_collapsed: bool,
161- pub(super) sidebar_toggled: Option<std::time::Instant>,
162- pub(super) composer: Composer,
163- pub(super) drafts: HashMap<Id, String>,
164- pub(super) poll_question: Entity<InputState>,
165- pub(super) poll_options: Vec<Entity<InputState>>,
166- pub(super) poll_multiple: bool,
167- pub(super) poll_public: bool,
168- pub(super) poll_duration: Option<u32>,
169- pub(super) plus_menu: composer::PlusMenu,
170- pub(super) my_votes: HashMap<Id, Vec<u32>>,
171- pub(super) poll_expanded: bool,
172- pub(super) poll_page: usize,
173- scroll: ScrollHandle,
174- pub(super) jump: Option<Id>,
175- highlight: Option<(Id, Instant)>,
176- glide: Option<(Id, gpui_kit::Pixels, Instant)>,
177- pub(super) view: View,
178- pub(super) section: Option<&'static str>,
179 pub(super) username_input: Entity<InputState>,149 pub(super) username_input: Entity<InputState>,
180 pub(super) community_name_input: Entity<InputState>,150 pub(super) community_name_input: Entity<InputState>,
181 pub(super) status_input: Entity<InputState>,151 pub(super) status_input: Entity<InputState>,
182- pub(super) avatars: HashMap<Id, Arc<Image>>,
183- pub(super) avatar_requests: HashSet<Id>,
184- pub(super) users: HashMap<Id, User>,
185- user_requests: HashSet<Id>,
186- pub(super) armed: Option<Armed>,
187- pub(super) bans: Vec<Ban>,
188 pub(super) ban_search: Entity<InputState>,152 pub(super) ban_search: Entity<InputState>,
189 pub(super) ban_sort: BanSort,153 pub(super) ban_sort: BanSort,
190- pub(super) logs: Vec<LogEntry>,
191 pub(super) log_search: Entity<InputState>,154 pub(super) log_search: Entity<InputState>,
192 pub(super) log_sort: LogSort,155 pub(super) log_sort: LogSort,
193- pub(super) friends: Friends,
194- pub(super) invitations: Vec<Invitation>,
195- pub(super) card_menu: CardMenu,
196- pub(super) presences: HashMap<Id, Presence>,
197- pub(super) slowed_until: Option<u64>,
198- pub(super) pending_builder_delete: Option<Id>,
199- pub(super) builder_users: Vec<Account>,
200- pub(super) pending_builder_password: Option<Id>,
201- pub(super) builder_password: Entity<InputState>,
202- pub(super) builder_sessions: Option<(Id, Vec<SessionInfo>)>,
203- pub(super) builder_clients: Vec<UpdateClient>,
204- pub(super) builder_clients_task: Option<Task<()>>,
205- pub(super) builder_friends: Vec<User>,
206- pub(super) pending_builder_rename: Option<Id>,
207- pub(super) builder_rename: Entity<InputState>,
208- pub(super) server_name: Entity<InputState>,
209- pub(super) server_limit: Entity<InputState>,
210- pub(super) server_user_quota: Entity<InputState>,
211- pub(super) server_community_quota: Entity<InputState>,
212- pub(super) server_message_retention: Entity<InputState>,
213- pub(super) server_attachment_retention: Entity<InputState>,
214- pub(super) server_announcement: Entity<InputState>,
215- pub(super) server_max_communities: Entity<InputState>,
216- pub(super) server_max_message_length: Entity<InputState>,
217- pub(super) server_max_avatar: Entity<InputState>,
218- pub(super) server_messages_per_minute: Entity<InputState>,
219- pub(super) server_logins_per_minute: Entity<InputState>,
220- pub(super) server_registration_open: bool,
221- pub(super) server_maintenance: bool,
222- pub(super) pending_builder_timeout: Option<Id>,
223- pub(super) builder_timeout: Entity<InputState>,
224- pub(super) pending_builder_ban: Option<Id>,
225- pub(super) builder_ban_reason: Entity<InputState>,
226- pub(super) builder_ban_scope: BanScope,
227- pub(super) builder_bans: Vec<ServerBan>,
228- pub(super) builder_invites: Vec<InviteCode>,
229- pub(super) invite_uses: Entity<InputState>,
230- pub(super) invite_hours: Entity<InputState>,
231- pub(super) pending_invite_delete: Option<String>,
232- pub(super) new_username: Entity<InputState>,
233- pub(super) new_password: Entity<InputState>,
234- pub(super) builder_tab: BuilderTab,
235- pub(super) builder_overview: Option<Overview>,
236- pub(super) builder_logs: Vec<AdminLogEntry>,
237- pub(super) builder_stats: Vec<DayStat>,
238- pub(super) builder_log_actor: Entity<InputState>,
239- pub(super) builder_log_target: Entity<InputState>,
240- pub(super) builder_log_action: Entity<SelectState<SearchableVec<&'static str>>>,
241- pub(super) builder_log_from: Entity<InputState>,
242- pub(super) builder_log_to: Entity<InputState>,
243- pub(super) builder_search: Entity<InputState>,
244- pub(super) builder_friend_search: Entity<InputState>,
245- pub(super) builder_communities: Vec<CommunitySummary>,
246- pub(super) builder_reports: Vec<Report>,
247- pub(super) report_filter: Option<ReportStatus>,
248- pub(super) open_reports: usize,
249- pub(super) report: Option<ReportTarget>,
250 pub(super) report_reason: Entity<InputState>,156 pub(super) report_reason: Entity<InputState>,
251- pub(super) pending_community_delete: Option<Id>,157+ pub(super) sidebar_collapsed: bool,
252- pub(super) builder_message_text: Entity<InputState>,158+ pub(super) sidebar_toggled: Option<Instant>,
253- pub(super) builder_message_user: Entity<InputState>,
254- pub(super) builder_message_community: Entity<InputState>,
255- pub(super) builder_message_from: Entity<InputState>,
256- pub(super) builder_message_to: Entity<InputState>,
257- pub(super) builder_messages: Vec<MessageHit>,
258- pub(super) builder_attachment_user: Entity<InputState>,
259- pub(super) builder_attachment_community: Entity<InputState>,
260- pub(super) builder_usage_users: Vec<Usage>,
261- pub(super) builder_usage_communities: Vec<CommunityUsage>,
262- pub(super) builder_attachments: Vec<AttachmentInfo>,
263- pub(super) pending_attachment_delete: Option<Id>,
264- pub(super) pending_message_delete: Option<Id>,
265- pub(super) hover_row: Option<Id>,
266- pub(super) hover_bar: Option<Id>,
267- pub(super) reacting: Option<Id>,
268- pub(super) pending_builder_purge: Option<Id>,
269- pub(super) transfer: Option<Transfer>,
270- pub(super) voice: HashMap<Id, Vec<Id>>,
271- pub(super) voice_state: VoiceState,
272- pub(super) waves: Waves,
273- pub(super) server_muted: HashSet<Id>,
274- pub(super) builder_voice_rooms: Vec<VoiceRoom>,
275- pub(super) voice_task: Option<Task<()>>,
276- pub(super) stats_task: Option<Task<()>>,
277- pub(super) goto: super::jump::Jump,
278- pub(super) server_stats: Option<common::stats::Stats>,
279- pub(super) server_stats_task: Option<Task<()>>,
280- pub(super) user_volume: Option<UserVolume>,
281- pub(super) stats: common::stats::Stats,
282- pub(super) followed: Option<(Id, common::stats::Stats)>,
283- pub(super) share_loss: HashMap<(Id, Kind), VecDeque<(u64, f32)>>,
284 pub(super) stats_at: Option<StatsAt>,159 pub(super) stats_at: Option<StatsAt>,
285- pub(super) usage_monitor: crate::usage::Monitor,
286- pub(super) storage: Vec<(crate::storage::Store, u64)>,
287- pub(super) ringing: HashSet<Id>,
288- pub(super) ring_task: Option<Task<()>>,
289- pub(super) media: Media,
290- pub(super) shares: HashMap<Id, Vec<Share>>,
291- pub(super) viewer: Option<Viewer>,
292- pub(super) float: super::share_view::Float,
293- pub(super) tiles: BTreeMap<(Id, Kind), Tile>,
294- pub(super) camera_task: Option<Task<()>>,
295 pub(super) stage: Stage,160 pub(super) stage: Stage,
296 pub(super) grid_size: (f32, f32),161 pub(super) grid_size: (f32, f32),
297 pub(super) strip_size: (f32, f32),162 pub(super) strip_size: (f32, f32),
298- pub(super) typing: HashMap<Id, HashMap<Id, Instant>>,163+ pub(super) goto: super::jump::Jump,
299- pub(super) typing_sent: HashMap<Id, Instant>,164+ pub(super) usage_monitor: crate::usage::Monitor,
165+ scroll: ScrollHandle,
300 }166 }
301 167
302 const RING_LIMIT: usize = 15;168 const RING_LIMIT: usize = 15;
@@ -382,17 +248,12 @@ impl Chat {
382 248
383 let ban_search = new_input(w().chat.search, window, cx);249 let ban_search = new_input(w().chat.search, window, cx);
384 let log_search = new_input(w().chat.search, window, cx);250 let log_search = new_input(w().chat.search, window, cx);
385- let builder_search = new_input(w().chat.search, window, cx);251+ let admin = Admin::new(window, cx);
386- let builder_friend_search = new_input(w().chat.search, window, cx);
387- let builder_password = new_input(w().chat.new_password, window, cx);
388- builder_password.update(cx, |input, cx| input.set_masked(true, window, cx));
389- let new_password = new_input(w().chat.password, window, cx);
390- new_password.update(cx, |input, cx| input.set_masked(true, window, cx));
391 for search in [252 for search in [
392 &ban_search,253 &ban_search,
393 &log_search,254 &log_search,
394- &builder_search,255+ &admin.builder_search,
395- &builder_friend_search,256+ &admin.builder_friend_search,
396 ] {257 ] {
397 cx.subscribe_in(search, window, |_, _, event, window, cx| {258 cx.subscribe_in(search, window, |_, _, event, window, cx| {
398 if matches!(event, InputEvent::Change) {259 if matches!(event, InputEvent::Change) {
@@ -404,57 +265,13 @@ impl Chat {
404 }265 }
405 266
406 Self {267 Self {
407- communities: vec![],268+ session: Session::default(),
408- selected_community_id: None,269+ admin,
409- opened: None,270+ poll: PollDraft::new(window, cx),
410- ghost: false,271+ composer: Composer::Compose { reply: None },
411- members: vec![],
412- bans: vec![],
413- ban_search,
414- ban_sort: BanSort::Newest,
415- logs: vec![],
416- log_search,
417- log_sort: LogSort::Newest,
418- friends: Friends::default(),
419- invitations: vec![],
420- messages: vec![],
421- pins: vec![],
422- poll_question: new_input(w().chat.question, window, cx),
423- poll_options: vec![
424- composer::new_poll_option(window, cx),
425- composer::new_poll_option(window, cx),
426- ],
427- poll_multiple: false,
428- poll_public: true,
429- poll_duration: None,
430- plus_menu: composer::PlusMenu::Menu,
431- my_votes: HashMap::new(),
432- poll_expanded: false,
433- poll_page: 0,
434- history: History::End,
435- scroll: ScrollHandle::new(),
436- jump: None,
437- highlight: None,
438- glide: None,
439- unread: HashMap::new(),
440- unread_anchor: None,
441- unseen: 0,
442- muted: HashSet::new(),
443- pinned: HashSet::new(),
444- edits: HashMap::new(),
445- revealed: HashSet::new(),
446 message_input,272 message_input,
447 search_input,273 search_input,
448- friends_open: false,
449- open_calls: HashSet::new(),
450 community_search,274 community_search,
451- community_hits: vec![],
452- found: None,
453- invite: InviteLookup::Idle,
454- sidebar_collapsed: false,
455- sidebar_toggled: None,
456- view: View::Chat,
457- section: None,
458 username_input: editable_input(w().chat.username, Yumush::save_username, window, cx),275 username_input: editable_input(w().chat.username, Yumush::save_username, window, cx),
459 community_name_input: editable_input(276 community_name_input: editable_input(
460 w().chat.community_name,277 w().chat.community_name,
@@ -463,152 +280,38 @@ impl Chat {
463 cx,280 cx,
464 ),281 ),
465 status_input: editable_input(w().chat.status, Yumush::save_status, window, cx),282 status_input: editable_input(w().chat.status, Yumush::save_status, window, cx),
466- avatars: HashMap::new(),283+ ban_search,
467- avatar_requests: HashSet::new(),284+ ban_sort: BanSort::Newest,
468- users: HashMap::new(),285+ log_search,
469- user_requests: HashSet::new(),286+ log_sort: LogSort::Newest,
470- armed: None,
471- card_menu: CardMenu::Main,
472- presences: HashMap::new(),
473- slowed_until: None,
474- pending_builder_delete: None,
475- builder_users: vec![],
476- builder_tab: BuilderTab::Overview,
477- builder_overview: None,
478- builder_logs: vec![],
479- builder_stats: vec![],
480- builder_log_actor: new_input(w().chat.actor, window, cx),
481- builder_log_target: new_input(w().chat.target, window, cx),
482- builder_log_action: cx.new(|cx| {
483- SelectState::new(
484- SearchableVec::new(
485- std::iter::once(w().chat.all)
486- .chain(
487- AdminActionKind::ALL
488- .into_iter()
489- .map(AdminActionKind::as_str),
490- )
491- .collect::<Vec<_>>(),
492- ),
493- Some(IndexPath::new(0)),
494- window,
495- cx,
496- )
497- }),
498- builder_log_from: new_input(w().chat.date_from, window, cx),
499- builder_log_to: new_input(w().chat.date_to, window, cx),
500- builder_search,
501- builder_friend_search,
502- builder_communities: vec![],
503- pending_community_delete: None,
504- builder_message_text: new_input(w().chat.text, window, cx),
505- builder_message_user: new_input(w().chat.user, window, cx),
506- builder_message_community: new_input(w().chat.community, window, cx),
507- builder_message_from: new_input(w().chat.date_from, window, cx),
508- builder_message_to: new_input(w().chat.date_to, window, cx),
509- builder_messages: vec![],
510- builder_attachment_user: new_input(w().chat.user, window, cx),
511- builder_attachment_community: new_input(w().chat.community, window, cx),
512- builder_usage_users: vec![],
513- builder_usage_communities: vec![],
514- builder_attachments: vec![],
515- pending_attachment_delete: None,
516- pending_message_delete: None,
517- hover_row: None,
518- hover_bar: None,
519- reacting: None,
520- pending_builder_purge: None,
521- transfer: None,
522- builder_password,
523- server_name: new_input(w().chat.server_name, window, cx),
524- server_limit: new_input("", window, cx),
525- server_user_quota: new_input("", window, cx),
526- server_community_quota: new_input("", window, cx),
527- server_message_retention: new_input("", window, cx),
528- server_attachment_retention: new_input("", window, cx),
529- server_announcement: new_input(w().chat.announcement, window, cx),
530- server_max_communities: new_input("", window, cx),
531- server_max_message_length: new_input(w().chat.max_message_length, window, cx),
532- server_max_avatar: new_input("", window, cx),
533- server_messages_per_minute: new_input("", window, cx),
534- server_logins_per_minute: new_input("", window, cx),
535- server_registration_open: true,
536- server_maintenance: false,
537- pending_builder_timeout: None,
538- builder_timeout: new_input(w().chat.minutes, window, cx),
539- pending_builder_ban: None,
540- builder_ban_reason: new_input(w().chat.reason, window, cx),
541- builder_ban_scope: BanScope::Account,
542- builder_bans: vec![],
543- builder_invites: vec![],
544- invite_uses: new_input(w().chat.uses, window, cx),
545- invite_hours: new_input(w().chat.hours, window, cx),
546- pending_invite_delete: None,
547- new_username: new_input(w().chat.username, window, cx),
548- new_password,
549- pending_builder_password: None,
550- builder_sessions: None,
551- builder_clients: Vec::new(),
552- builder_clients_task: None,
553- builder_friends: Vec::new(),
554- pending_builder_rename: None,
555- builder_rename: new_input(w().chat.new_username, window, cx),
556- builder_reports: vec![],
557- report_filter: Some(ReportStatus::Open),
558- open_reports: 0,
559- report: None,
560 report_reason: new_input(w().chat.reason, window, cx),287 report_reason: new_input(w().chat.reason, window, cx),
561- voice: HashMap::new(),288+ sidebar_collapsed: false,
562- drafts: HashMap::new(),289+ sidebar_toggled: None,
563- voice_state: VoiceState::Off,290+ stats_at: None,
564- waves: Waves::default(),291+ stage: Stage::Strip,
565- user_volume: None,292+ grid_size: (1280., 720.),
566- server_muted: HashSet::new(),293+ strip_size: (1280., 0.),
567- builder_voice_rooms: Vec::new(),
568- voice_task: None,
569- stats_task: None,
570 goto: super::jump::Jump {294 goto: super::jump::Jump {
571 open: false,295 open: false,
572 cursor: 0,296 cursor: 0,
573 input: jump_input,297 input: jump_input,
574 scroll: ScrollHandle::new(),298 scroll: ScrollHandle::new(),
575 },299 },
576- server_stats: None,
577- server_stats_task: None,
578- stats: common::stats::Stats::default(),
579- followed: None,
580- share_loss: HashMap::new(),
581- stats_at: None,
582- storage: Vec::new(),
583 usage_monitor: {300 usage_monitor: {
584- let monitor = crate::usage::Monitor::default();301+ crate::usage::Monitor::new(crate::usage::Wake::OnDemand, crate::config_dir())
585- if let Some(dir) = crate::config_dir() {
586- monitor.watch_disk(dir);
587- }
588- monitor
589 },302 },
590- ringing: HashSet::new(),303+ scroll: ScrollHandle::new(),
591- ring_task: None,
592- typing: HashMap::new(),
593- typing_sent: HashMap::new(),
594- media: Media::default(),
595- shares: HashMap::new(),
596- viewer: None,
597- float: Default::default(),
598- tiles: BTreeMap::new(),
599- camera_task: None,
600- stage: Stage::Strip,
601- grid_size: (1280., 720.),
602- strip_size: (1280., 0.),
603- composer: Composer::Compose { reply: None },
604 }304 }
605 }305 }
606 306
607 fn unread_where(&self, keep: impl Fn(&CommunityKind) -> bool) -> Unread {307 fn unread_where(&self, keep: impl Fn(&CommunityKind) -> bool) -> Unread {
608- self.communities308+ self.session
309+ .communities
609 .iter()310 .iter()
610- .filter(|community| !self.muted.contains(&community.id) && keep(&community.kind))311+ .filter(|community| {
611- .filter_map(|community| self.unread.get(&community.id))312+ !self.session.muted.contains(&community.id) && keep(&community.kind)
313+ })
314+ .filter_map(|community| self.session.unread.get(&community.id))
612 .fold(Unread::default(), |total, unread| Unread {315 .fold(Unread::default(), |total, unread| Unread {
613 messages: total.messages + unread.messages,316 messages: total.messages + unread.messages,
614 mentions: total.mentions + unread.mentions,317 mentions: total.mentions + unread.mentions,
@@ -625,7 +328,7 @@ impl Chat {
625 }328 }
626 329
627 pub fn focus(&self, window: &mut Window, cx: &mut Context<Yumush>) {330 pub fn focus(&self, window: &mut Window, cx: &mut Context<Yumush>) {
628- match self.selected_community_id {331+ match self.session.selected_community_id {
629 Some(_) => self332 Some(_) => self
630 .message_input333 .message_input
631 .update(cx, |input, cx| input.focus(window, cx)),334 .update(cx, |input, cx| input.focus(window, cx)),
@@ -635,28 +338,23 @@ impl Chat {
635 }338 }
636 }339 }
637 340
638- pub(super) fn call_run_end(&self, index: usize) -> Id {
639- let calls = self.messages[index..]
640- .iter()
641- .take_while(|message| message.call.is_some())
642- .count();
643- self.messages[index + calls.max(1) - 1].id
644- }
645-
646 pub fn name_of(&self, user_id: Id) -> String {341 pub fn name_of(&self, user_id: Id) -> String {
647 self.author(user_id)342 self.author(user_id)
648 .map_or_else(|| user_id.to_string(), |user| user.username.clone())343 .map_or_else(|| user_id.to_string(), |user| user.username.clone())
649 }344 }
650 345
651 pub fn slow_seconds(&self) -> Option<u64> {346 pub fn slow_seconds(&self) -> Option<u64> {
652- let remaining = self.slowed_until?.saturating_sub(common::time::now_ms());347+ let remaining = self
348+ .session
349+ .slowed_until?
350+ .saturating_sub(common::time::now_ms());
653 (remaining > 0).then(|| remaining.div_ceil(1000))351 (remaining > 0).then(|| remaining.div_ceil(1000))
654 }352 }
655 353
656 pub fn apply_event(&mut self, event: Event, me: Option<Id>, builder: bool) {354 pub fn apply_event(&mut self, event: Event, me: Option<Id>, builder: bool) {
657 match event {355 match event {
658 Event::MessageCreated(message) => {356 Event::MessageCreated(message) => {
659- if let Some(users) = self.typing.get_mut(&message.community_id) {357+ if let Some(users) = self.session.typing.get_mut(&message.community_id) {
660 users.remove(&message.user_id);358 users.remove(&message.user_id);
661 }359 }
662 if self.is_selected(message.community_id) {360 if self.is_selected(message.community_id) {
@@ -667,6 +365,7 @@ impl Chat {
667 if self.is_selected(message.community_id) {365 if self.is_selected(message.community_id) {
668 self.update_pin(&message);366 self.update_pin(&message);
669 if let Some(existing) = self367 if let Some(existing) = self
368+ .session
670 .messages369 .messages
671 .iter_mut()370 .iter_mut()
672 .find(|existing| existing.id == message.id)371 .find(|existing| existing.id == message.id)
@@ -686,7 +385,7 @@ impl Chat {
686 message_id,385 message_id,
687 positions,386 positions,
688 } => {387 } => {
689- self.my_votes.insert(message_id, positions);388+ self.session.my_votes.insert(message_id, positions);
690 }389 }
691 Event::MessagesDeleted { community_id, ids } => {390 Event::MessagesDeleted { community_id, ids } => {
692 if self.is_selected(community_id) {391 if self.is_selected(community_id) {
@@ -732,25 +431,25 @@ impl Chat {
732 .chain(&friends.outgoing)431 .chain(&friends.outgoing)
733 .collect::<Vec<_>>(),432 .collect::<Vec<_>>(),
734 );433 );
735- self.friends = friends;434+ self.session.friends = friends;
736- }
737- Event::InvitationsUpdated(invitations) => self.invitations = invitations,
738- Event::CommunityDeleted { community_id } | Event::Removed { community_id, .. } => {
739- self.remove_community(community_id)
740 }435 }
436+ Event::InvitationsUpdated(invitations) => self.session.invitations = invitations,
437+ Event::CommunityDeleted { community_id } => self.remove_community(community_id),
741 Event::UserDeleted { user_id } => {438 Event::UserDeleted { user_id } => {
742 self.remove_member(user_id);439 self.remove_member(user_id);
743- self.messages.retain(|message| message.user_id != user_id);440+ self.session
441+ .messages
442+ .retain(|message| message.user_id != user_id);
744 }443 }
745 Event::UserUpdated(user) => self.update_member(&user),444 Event::UserUpdated(user) => self.update_member(&user),
746 Event::PresenceChanged { user_id, presence } => {445 Event::PresenceChanged { user_id, presence } => {
747- self.presences.insert(user_id, presence);446+ self.session.presences.insert(user_id, presence);
748 }447 }
749 Event::VoiceJoined {448 Event::VoiceJoined {
750 community_id,449 community_id,
751 user_id,450 user_id,
752 } => {451 } => {
753- let ids = self.voice.entry(community_id).or_default();452+ let ids = self.session.voice.entry(community_id).or_default();
754 if !ids.contains(&user_id) {453 if !ids.contains(&user_id) {
755 ids.push(user_id);454 ids.push(user_id);
756 }455 }
@@ -759,25 +458,26 @@ impl Chat {
759 community_id,458 community_id,
760 user_id,459 user_id,
761 } => {460 } => {
762- if let Some(ids) = self.voice.get_mut(&community_id) {461+ if let Some(ids) = self.session.voice.get_mut(&community_id) {
763 ids.retain(|id| *id != user_id);462 ids.retain(|id| *id != user_id);
764 if ids.is_empty() {463 if ids.is_empty() {
765- self.ringing.remove(&community_id);464+ self.session.ringing.remove(&community_id);
766 }465 }
767 }466 }
768 }467 }
769 Event::VoiceMuted { user_id, muted, .. } => {468 Event::VoiceMuted { user_id, muted, .. } => {
770 if muted {469 if muted {
771- self.server_muted.insert(user_id);470+ self.session.server_muted.insert(user_id);
772 } else {471 } else {
773- self.server_muted.remove(&user_id);472+ self.session.server_muted.remove(&user_id);
774 }473 }
775 }474 }
776 Event::Typing {475 Event::Typing {
777 community_id,476 community_id,
778 user_id,477 user_id,
779 } => {478 } => {
780- self.typing479+ self.session
480+ .typing
781 .entry(community_id)481 .entry(community_id)
782 .or_default()482 .or_default()
783 .insert(user_id, Instant::now());483 .insert(user_id, Instant::now());
@@ -786,7 +486,7 @@ impl Chat {
786 community_id,486 community_id,
787 share,487 share,
788 } => {488 } => {
789- let shares = self.shares.entry(community_id).or_default();489+ let shares = self.session.shares.entry(community_id).or_default();
790 shares.retain(|existing| {490 shares.retain(|existing| {
791 existing.user_id != share.user_id || existing.kind != share.kind491 existing.user_id != share.user_id || existing.kind != share.kind
792 });492 });
@@ -797,17 +497,23 @@ impl Chat {
797 user_id,497 user_id,
798 kind,498 kind,
799 } => {499 } => {
800- if let Some(shares) = self.shares.get_mut(&community_id) {500+ if let Some(shares) = self.session.shares.get_mut(&community_id) {
801 shares.retain(|share| share.user_id != user_id || share.kind != kind);501 shares.retain(|share| share.user_id != user_id || share.kind != kind);
802 }502 }
803 }503 }
804 Event::StatsWanted(_) => {}504 Event::StatsWanted(_) => {}
805 Event::StatsOf { user_id, stats } => {505 Event::StatsOf { user_id, stats } => {
806- if let Some(followed) = self.followed.as_mut().filter(|(id, _)| *id == user_id) {506+ if let Some(followed) = self
507+ .session
508+ .followed
509+ .as_mut()
510+ .filter(|(id, _)| *id == user_id)
511+ {
807 followed.1 = stats;512 followed.1 = stats;
808 }513 }
809 }514 }
810 Event::ReportCreated515 Event::ReportCreated
516+ | Event::Removed { .. }
811 | Event::SettingsUpdated(_)517 | Event::SettingsUpdated(_)
812 | Event::Release518 | Event::Release
813 | Event::Imported { .. } => {}519 | Event::Imported { .. } => {}
@@ -815,12 +521,13 @@ impl Chat {
815 }521 }
816 522
817 pub(super) fn is_selected(&self, community_id: Id) -> bool {523 pub(super) fn is_selected(&self, community_id: Id) -> bool {
818- self.selected_community_id == Some(community_id)524+ self.session.selected_community_id == Some(community_id)
819 }525 }
820 526
821 pub fn typing_label(&self) -> Option<String> {527 pub fn typing_label(&self) -> Option<String> {
822- let community_id = self.selected_community_id.as_ref()?;528+ let community_id = self.session.selected_community_id.as_ref()?;
823 let names: Vec<&str> = self529 let names: Vec<&str> = self
530+ .session
824 .typing531 .typing
825 .get(community_id)?532 .get(community_id)?
826 .iter()533 .iter()
@@ -838,51 +545,53 @@ impl Chat {
838 }545 }
839 546
840 fn select(&mut self, community_id: Option<Id>) {547 fn select(&mut self, community_id: Option<Id>) {
841- if community_id != self.selected_community_id {548+ if community_id != self.session.selected_community_id {
842- self.unread_anchor = community_id549+ self.session.unread_anchor = community_id
843 .as_ref()550 .as_ref()
844- .and_then(|community_id| self.unread.get(community_id))551+ .and_then(|community_id| self.session.unread.get(community_id))
845 .filter(|unread| unread.messages > 0)552 .filter(|unread| unread.messages > 0)
846 .and_then(|unread| {553 .and_then(|unread| {
847 unread554 unread
848 .last_read555 .last_read
849 .map(|last_read| (last_read, unread.messages))556 .map(|last_read| (last_read, unread.messages))
850 });557 });
851- self.unseen = 0;558+ self.session.unseen = 0;
852 }559 }
853- if self.opened.as_ref().map(|opened| &opened.id) != community_id.as_ref() {560+ if self.session.opened.as_ref().map(|opened| &opened.id) != community_id.as_ref() {
854- self.opened = None;561+ self.session.opened = None;
855 }562 }
856- if self.view == View::CommunitySettings {563+ if self.session.view == View::CommunitySettings {
857- self.view = View::Chat;564+ self.session.view = View::Chat;
858- self.armed = None;
859 }565 }
860- self.selected_community_id = community_id;566+ self.session.selected_community_id = community_id;
861- self.users.extend(567+ self.session.users.extend(
862- self.members568+ self.session
569+ .members
863 .drain(..)570 .drain(..)
864 .map(|member| (member.user.id, member.user)),571 .map(|member| (member.user.id, member.user)),
865 );572 );
866- self.bans.clear();573+ self.session.bans.clear();
867- self.logs.clear();574+ self.session.logs.clear();
868- self.armed = None;575+ self.session.armed = None;
869- self.messages.clear();576+ self.session.messages.clear();
870- self.jump = None;577+ self.session.jump = None;
871- self.pins.clear();578+ self.session.pins.clear();
872- self.poll_expanded = false;579+ self.poll.expanded = false;
873- self.poll_page = 0;580+ self.poll.page = 0;
874- self.my_votes.clear();581+ self.session.my_votes.clear();
875- self.community_hits.clear();582+ self.session.community_hits.clear();
876- self.history = History::End;583+ self.session.history = History::End;
877- self.media.leave();584+ self.session.media.leave();
878 self.composer = Composer::Compose { reply: None };585 self.composer = Composer::Compose { reply: None };
879 }586 }
880 587
881 pub fn joined(&self, community_id: Id) -> bool {588 pub fn joined(&self, community_id: Id) -> bool {
882- self.communities589+ self.session
590+ .communities
883 .iter()591 .iter()
884 .chain(592 .chain(
885- self.opened593+ self.session
594+ .opened
886 .as_ref()595 .as_ref()
887 .filter(|opened| opened.kind.is_direct()),596 .filter(|opened| opened.kind.is_direct()),
888 )597 )
@@ -890,7 +599,8 @@ impl Chat {
890 }599 }
891 600
892 fn quotes_of(&mut self, message_id: Id) -> impl Iterator<Item = &mut common::model::Quote> {601 fn quotes_of(&mut self, message_id: Id) -> impl Iterator<Item = &mut common::model::Quote> {
893- self.messages602+ self.session
603+ .messages
894 .iter_mut()604 .iter_mut()
895 .filter_map(move |message| match &mut message.reply {605 .filter_map(move |message| match &mut message.reply {
896 Some(Reply::Quote(quote)) if quote.message_id == message_id => Some(quote),606 Some(Reply::Quote(quote)) if quote.message_id == message_id => Some(quote),
@@ -901,6 +611,7 @@ impl Chat {
901 fn remove_message(&mut self, message_id: Id, builder: bool) {611 fn remove_message(&mut self, message_id: Id, builder: bool) {
902 if builder {612 if builder {
903 if let Some(message) = self613 if let Some(message) = self
614+ .session
904 .messages615 .messages
905 .iter_mut()616 .iter_mut()
906 .find(|existing| existing.id == message_id)617 .find(|existing| existing.id == message_id)
@@ -909,9 +620,11 @@ impl Chat {
909 message.pinned = false;620 message.pinned = false;
910 }621 }
911 } else {622 } else {
912- self.messages.retain(|existing| existing.id != message_id);623+ self.session
624+ .messages
625+ .retain(|existing| existing.id != message_id);
913 }626 }
914- for message in &mut self.messages {627+ for message in &mut self.session.messages {
915 message.reply = match message.reply.take() {628 message.reply = match message.reply.take() {
916 Some(Reply::Quote(quote)) if quote.message_id == message_id => {629 Some(Reply::Quote(quote)) if quote.message_id == message_id => {
917 Some(Reply::Deleted(builder.then_some(quote)))630 Some(Reply::Deleted(builder.then_some(quote)))
@@ -925,7 +638,9 @@ impl Chat {
925 Composer::Compose { reply } if *reply == Some(message_id) => {638 Composer::Compose { reply } if *reply == Some(message_id) => {
926 self.composer = Composer::Compose { reply: None };639 self.composer = Composer::Compose { reply: None };
927 }640 }
928- Composer::Edit { message_id: edited } if *edited == message_id => {641+ Composer::Edit {
642+ message_id: edited, ..
643+ } if *edited == message_id => {
929 self.composer = Composer::Compose { reply: None };644 self.composer = Composer::Compose { reply: None };
930 }645 }
931 _ => {}646 _ => {}
@@ -933,24 +648,28 @@ impl Chat {
933 }648 }
934 649
935 pub fn communities(&self) -> &[Community] {650 pub fn communities(&self) -> &[Community] {
936- &self.communities651+ &self.session.communities
937 }652 }
938 653
939 pub fn notes(&self) -> Option<&Community> {654 pub fn notes(&self) -> Option<&Community> {
940- self.communities655+ self.session
656+ .communities
941 .iter()657 .iter()
942 .find(|community| matches!(community.kind, CommunityKind::Notes))658 .find(|community| matches!(community.kind, CommunityKind::Notes))
943 }659 }
944 660
945 fn insert_messages(&mut self, messages: impl IntoIterator<Item = Message>, me: Option<Id>) {661 fn insert_messages(&mut self, messages: impl IntoIterator<Item = Message>, me: Option<Id>) {
946- let newest = self.messages.last().map(|message| message.id);662+ let newest = self.session.messages.last().map(|message| message.id);
947 for message in messages {663 for message in messages {
948- self.messages.retain(|existing| existing.id != message.id);664+ self.session
949- self.messages.push(message);665+ .messages
666+ .retain(|existing| existing.id != message.id);
667+ self.session.messages.push(message);
950 }668 }
951- self.messages.sort_by_key(|message| message.id);669+ self.session.messages.sort_by_key(|message| message.id);
952- if self.messages.last().map(|message| message.id) != newest {670+ if self.session.messages.last().map(|message| message.id) != newest {
953 let mine = self671 let mine = self
672+ .session
954 .messages673 .messages
955 .last()674 .last()
956 .is_some_and(|message| Some(message.user_id) == me);675 .is_some_and(|message| Some(message.user_id) == me);
@@ -960,23 +679,24 @@ impl Chat {
960 None => self.scroll.scroll_to_bottom(),679 None => self.scroll.scroll_to_bottom(),
961 }680 }
962 } else if !self.away() {681 } else if !self.away() {
963- let newest = self.messages.last().map_or(0, |message| message.id);682+ let newest = self.session.messages.last().map_or(0, |message| message.id);
964- self.glide = Some((newest, self.scroll.offset().y, Instant::now()));683+ self.session.glide = Some((newest, self.scroll.offset().y, Instant::now()));
965- self.unseen = 0;684+ self.session.unseen = 0;
966 } else if mine {685 } else if mine {
967 self.jump_to_bottom();686 self.jump_to_bottom();
968 } else {687 } else {
969- self.unseen += 1;688+ self.session.unseen += 1;
970 }689 }
971 }690 }
972 self.reveal_jump();691 self.reveal_jump();
973 }692 }
974 693
975 fn reveal_jump(&mut self) {694 fn reveal_jump(&mut self) {
976- let Some(message_id) = self.jump.as_ref() else {695+ let Some(message_id) = self.session.jump.as_ref() else {
977 return;696 return;
978 };697 };
979 let Some(position) = self698 let Some(position) = self
699+ .session
980 .messages700 .messages
981 .iter()701 .iter()
982 .position(|message| &message.id == message_id)702 .position(|message| &message.id == message_id)
@@ -984,7 +704,8 @@ impl Chat {
984 return;704 return;
985 };705 };
986 self.scroll_to_index(position);706 self.scroll_to_index(position);
987- self.highlight = self707+ self.session.highlight = self
708+ .session
988 .jump709 .jump
989 .take()710 .take()
990 .map(|message_id| (message_id, Instant::now()));711 .map(|message_id| (message_id, Instant::now()));
@@ -992,7 +713,7 @@ impl Chat {
992 713
993 fn scroll_to_index(&self, position: usize) {714 fn scroll_to_index(&self, position: usize) {
994 let spacer = 1;715 let spacer = 1;
995- let older = usize::from(self.history == History::More);716+ let older = usize::from(self.session.history == History::More);
996 self.scroll.scroll_to_item(spacer + older + position);717 self.scroll.scroll_to_item(spacer + older + position);
997 }718 }
998 719
@@ -1001,72 +722,81 @@ impl Chat {
1001 }722 }
1002 723
1003 pub(super) fn engaged(&self, message_id: Id) -> bool {724 pub(super) fn engaged(&self, message_id: Id) -> bool {
1004- self.hover_bar == Some(message_id) || self.reacting == Some(message_id)725+ self.session.hover_bar == Some(message_id) || self.session.reacting == Some(message_id)
1005 }726 }
1006 727
1007 pub(super) fn jump_to_bottom(&mut self) {728 pub(super) fn jump_to_bottom(&mut self) {
1008 self.scroll.scroll_to_bottom();729 self.scroll.scroll_to_bottom();
1009- self.unseen = 0;730+ self.session.unseen = 0;
1010 }731 }
1011 732
1012 pub(super) fn settle_scroll(&mut self) {733 pub(super) fn settle_scroll(&mut self) {
1013 if !self.away() {734 if !self.away() {
1014- self.unseen = 0;735+ self.session.unseen = 0;
1015 }736 }
1016 }737 }
1017 738
1018 fn unread_covered(&self) -> bool {739 fn unread_covered(&self) -> bool {
1019- match (&self.unread_anchor, self.messages.first()) {740+ match (&self.session.unread_anchor, self.session.messages.first()) {
1020- (Some((anchor, _)), Some(first)) => self.history == History::End || first.id <= *anchor,741+ (Some((anchor, _)), Some(first)) => {
742+ self.session.history == History::End || first.id <= *anchor
743+ }
1021 _ => true,744 _ => true,
1022 }745 }
1023 }746 }
1024 747
1025 fn unread_divider(&self, me: Option<Id>) -> Option<usize> {748 fn unread_divider(&self, me: Option<Id>) -> Option<usize> {
1026- let (anchor, _) = self.unread_anchor?;749+ let (anchor, _) = self.session.unread_anchor?;
1027 if !self.unread_covered() {750 if !self.unread_covered() {
1028 return None;751 return None;
1029 }752 }
1030- self.messages753+ self.session
754+ .messages
1031 .iter()755 .iter()
1032 .position(|message| message.id > anchor && Some(message.user_id) != me)756 .position(|message| message.id > anchor && Some(message.user_id) != me)
1033 }757 }
1034 758
1035 pub(super) fn mark_read(&mut self, community_id: Id, message_id: Id) {759 pub(super) fn mark_read(&mut self, community_id: Id, message_id: Id) {
1036- let unread = self.unread.entry(community_id).or_insert_with(|| Unread {760+ let unread = self
1037- community_id,761+ .session
1038- ..Default::default()762+ .unread
1039- });763+ .entry(community_id)
764+ .or_insert_with(|| Unread {
765+ community_id,
766+ ..Default::default()
767+ });
1040 unread.messages = 0;768 unread.messages = 0;
1041 unread.mentions = 0;769 unread.mentions = 0;
1042 unread.last_read = Some(message_id);770 unread.last_read = Some(message_id);
1043 }771 }
1044 772
1045 fn add_page(&mut self, page: Vec<Message>, me: Option<Id>) {773 fn add_page(&mut self, page: Vec<Message>, me: Option<Id>) {
1046- self.history = History::of_page(page.len());774+ self.session.history = History::of_page(page.len());
1047 self.insert_messages(page, me);775 self.insert_messages(page, me);
1048 }776 }
1049 777
1050 fn insert_member(&mut self, member: Member) {778 fn insert_member(&mut self, member: Member) {
1051 style::remember(&[&member.user]);779 style::remember(&[&member.user]);
1052 self.remove_member(member.user.id);780 self.remove_member(member.user.id);
1053- self.members.push(member);781+ self.session.members.push(member);
1054- self.members.sort_by_key(|member| member.user.id);782+ self.session.members.sort_by_key(|member| member.user.id);
1055 }783 }
1056 784
1057 pub(super) fn remove_member(&mut self, user_id: Id) {785 pub(super) fn remove_member(&mut self, user_id: Id) {
1058 if let Some(index) = self786 if let Some(index) = self
787+ .session
1059 .members788 .members
1060 .iter()789 .iter()
1061 .position(|member| member.user.id == user_id)790 .position(|member| member.user.id == user_id)
1062 {791 {
1063- let member = self.members.remove(index);792+ let member = self.session.members.remove(index);
1064- self.users.insert(member.user.id, member.user);793+ self.session.users.insert(member.user.id, member.user);
1065 }794 }
1066 }795 }
1067 796
1068 fn set_rank(&mut self, user_id: Id, rank: Rank) {797 fn set_rank(&mut self, user_id: Id, rank: Rank) {
1069 if let Some(member) = self798 if let Some(member) = self
799+ .session
1070 .members800 .members
1071 .iter_mut()801 .iter_mut()
1072 .find(|member| member.user.id == user_id)802 .find(|member| member.user.id == user_id)
@@ -1076,18 +806,22 @@ impl Chat {
1076 }806 }
1077 807
1078 pub fn community(&self, community_id: Id) -> Option<&Community> {808 pub fn community(&self, community_id: Id) -> Option<&Community> {
1079- self.communities809+ self.session
810+ .communities
1080 .iter()811 .iter()
1081- .chain(self.opened.as_ref())812+ .chain(self.session.opened.as_ref())
1082 .find(|community| community.id == community_id)813 .find(|community| community.id == community_id)
1083 }814 }
1084 815
1085 pub fn selected_community(&self) -> Option<&Community> {816 pub fn selected_community(&self) -> Option<&Community> {
1086- self.community(self.selected_community_id?)817+ self.community(self.session.selected_community_id?)
1087 }818 }
1088 819
1089 fn member_entry(&self, user_id: Id) -> Option<&Member> {820 fn member_entry(&self, user_id: Id) -> Option<&Member> {
1090- self.members.iter().find(|member| member.user.id == user_id)821+ self.session
822+ .members
823+ .iter()
824+ .find(|member| member.user.id == user_id)
1091 }825 }
1092 826
1093 pub fn member(&self, user_id: Id) -> Option<&User> {827 pub fn member(&self, user_id: Id) -> Option<&User> {
@@ -1095,16 +829,18 @@ impl Chat {
1095 }829 }
1096 830
1097 pub fn author(&self, user_id: Id) -> Option<&User> {831 pub fn author(&self, user_id: Id) -> Option<&User> {
1098- self.member(user_id).or_else(|| self.users.get(&user_id))832+ self.member(user_id)
833+ .or_else(|| self.session.users.get(&user_id))
1099 }834 }
1100 835
1101 fn missing_authors(&self) -> Vec<Id> {836 fn missing_authors(&self) -> Vec<Id> {
1102- let mut ids: Vec<Id> = if self.members.is_empty() {837+ let mut ids: Vec<Id> = if self.session.members.is_empty() {
1103 vec![]838 vec![]
1104 } else {839 } else {
1105- self.messages840+ self.session
841+ .messages
1106 .iter()842 .iter()
1107- .chain(&self.pins)843+ .chain(&self.session.pins)
1108 .flat_map(|message| {844 .flat_map(|message| {
1109 std::iter::once(message.user_id)845 std::iter::once(message.user_id)
1110 .chain(846 .chain(
@@ -1127,7 +863,7 @@ impl Chat {
1127 }863 }
1128 let mut missing: Vec<Id> = ids864 let mut missing: Vec<Id> = ids
1129 .into_iter()865 .into_iter()
1130- .filter(|id| self.author(*id).is_none() && !self.user_requests.contains(id))866+ .filter(|id| self.author(*id).is_none() && !self.session.user_requests.contains(id))
1131 .collect();867 .collect();
1132 missing.sort();868 missing.sort();
1133 missing.dedup();869 missing.dedup();
@@ -1152,10 +888,12 @@ impl Chat {
1152 }888 }
1153 889
1154 fn update_pin(&mut self, message: &Message) {890 fn update_pin(&mut self, message: &Message) {
1155- self.pins.retain(|pin| pin.id != message.id);891+ self.session.pins.retain(|pin| pin.id != message.id);
1156 if message.pinned {892 if message.pinned {
1157- self.pins.push(message.clone());893+ self.session.pins.push(message.clone());
1158- self.pins.sort_by_key(|pin| std::cmp::Reverse(pin.id));894+ self.session
895+ .pins
896+ .sort_by_key(|pin| std::cmp::Reverse(pin.id));
1159 }897 }
1160 }898 }
1161 899
@@ -1169,26 +907,34 @@ impl Chat {
1169 907
1170 pub fn update_member(&mut self, user: &User) {908 pub fn update_member(&mut self, user: &User) {
1171 style::remember(&[user]);909 style::remember(&[user]);
1172- let peers = self910+ let peers =
1173- .communities911+ self.session
1174- .iter_mut()912+ .communities
1175- .filter_map(|community| match &mut community.kind {913+ .iter_mut()
1176- CommunityKind::Direct { peer } => Some(peer),914+ .filter_map(|community| match &mut community.kind {
1177- CommunityKind::Group | CommunityKind::Notes => None,915+ CommunityKind::Direct { peer } => Some(peer),
1178- });916+ CommunityKind::Group | CommunityKind::Notes => None,
917+ });
1179 let known = self918 let known = self
919+ .session
1180 .friends920 .friends
1181 .friends921 .friends
1182 .iter_mut()922 .iter_mut()
1183- .chain(self.friends.incoming.iter_mut())923+ .chain(self.session.friends.incoming.iter_mut())
1184- .chain(self.friends.outgoing.iter_mut())924+ .chain(self.session.friends.outgoing.iter_mut())
1185 .chain(925 .chain(
1186- self.invitations926+ self.session
927+ .invitations
1187 .iter_mut()928 .iter_mut()
1188 .map(|invitation| &mut invitation.inviter),929 .map(|invitation| &mut invitation.inviter),
1189 )930 )
1190- .chain(self.members.iter_mut().map(|member| &mut member.user))931+ .chain(
1191- .chain(self.users.values_mut())932+ self.session
933+ .members
934+ .iter_mut()
935+ .map(|member| &mut member.user),
936+ )
937+ .chain(self.session.users.values_mut())
1192 .chain(peers);938 .chain(peers);
1193 for existing in known.filter(|existing| existing.id == user.id) {939 for existing in known.filter(|existing| existing.id == user.id) {
1194 *existing = user.clone();940 *existing = user.clone();
@@ -1196,104 +942,43 @@ impl Chat {
1196 }942 }
1197 943
1198 pub(super) fn insert_community(&mut self, community: Community) {944 pub(super) fn insert_community(&mut self, community: Community) {
1199- self.communities945+ self.session
946+ .communities
1200 .retain(|existing| existing.id != community.id);947 .retain(|existing| existing.id != community.id);
1201- self.communities.push(community);948+ self.session.communities.push(community);
1202- self.communities.sort_by_key(|community| community.id);949+ self.session
950+ .communities
951+ .sort_by_key(|community| community.id);
1203 }952 }
1204 953
1205 pub(super) fn remove_community(&mut self, community_id: Id) {954 pub(super) fn remove_community(&mut self, community_id: Id) {
1206- self.communities955+ self.session
956+ .communities
1207 .retain(|community| community.id != community_id);957 .retain(|community| community.id != community_id);
1208- self.unread.remove(&community_id);958+ self.session.unread.remove(&community_id);
1209- self.voice.remove(&community_id);959+ self.session.voice.remove(&community_id);
1210- if self.in_voice(community_id) {
1211- self.set_voice_off();
1212- }
1213 if self.is_selected(community_id) {960 if self.is_selected(community_id) {
1214 self.select(None);961 self.select(None);
1215 }962 }
1216 }963 }
1217 964
1218 fn replace_communities(&mut self, communities: Vec<Community>) {965 fn replace_communities(&mut self, communities: Vec<Community>) {
1219- self.communities = communities;966+ self.session.communities = communities;
1220-967+ if self.selected_community().is_none() {
1221- let selected_present = self
1222- .communities
1223- .iter()
1224- .chain(self.opened.as_ref())
1225- .any(|community| self.is_selected(community.id));
1226- if !selected_present {
1227 self.select(None);968 self.select(None);
1228 }969 }
1229-
1230- if self.voice_community().is_some_and(|id| !self.joined(id)) {
1231- self.set_voice_off();
1232- }
1233 }970 }
1234 971
1235 pub fn reset(&mut self) {972 pub fn reset(&mut self) {
1236- self.communities.clear();
1237- self.presences.clear();
1238- self.slowed_until = None;
1239- self.friends = Friends::default();
1240- self.invitations.clear();
1241- self.found = None;
1242 self.select(None);973 self.select(None);
1243- self.unread.clear();974+ let camera_task = self.session.camera_task.take();
1244- self.muted.clear();975+ self.session = Session::default();
1245- self.builder_users.clear();976+ self.session.camera_task = camera_task;
1246- self.builder_tab = BuilderTab::Overview;977+ self.admin.clear();
1247- self.builder_overview = None;
1248- self.builder_logs.clear();
1249- self.builder_stats.clear();
1250- self.builder_communities.clear();
1251- self.builder_reports.clear();
1252- self.report_filter = Some(ReportStatus::Open);
1253- self.open_reports = 0;
1254- self.report = None;
1255- self.pending_community_delete = None;
1256- self.builder_messages.clear();
1257- self.builder_usage_users.clear();
1258- self.builder_usage_communities.clear();
1259- self.builder_attachments.clear();
1260- self.pending_attachment_delete = None;
1261- self.pending_message_delete = None;
1262- self.pending_builder_purge = None;
1263- self.transfer = None;
1264- self.pending_builder_delete = None;
1265- self.pending_builder_password = None;
1266- self.builder_sessions = None;
1267- self.builder_clients.clear();
1268- self.builder_clients_task = None;
1269- self.pending_builder_rename = None;
1270- self.pending_builder_timeout = None;
1271- self.pending_builder_ban = None;
1272- self.builder_ban_scope = BanScope::Account;
1273- self.builder_bans.clear();
1274- self.builder_invites.clear();
1275- self.pending_invite_delete = None;
1276- self.view = View::Chat;
1277- self.armed = None;
1278- self.voice.clear();
1279- self.server_muted.clear();
1280- self.builder_voice_rooms.clear();
1281- self.ringing.clear();
1282- self.ring_task = None;
1283- self.ghost = false;
1284- self.drafts.clear();
1285- self.shares.clear();
1286- self.typing.clear();
1287- self.typing_sent.clear();
1288- self.users.clear();
1289- self.user_requests.clear();
1290- self.user_volume = None;
1291- self.card_menu = CardMenu::Main;
1292- self.set_voice_off();
1293 }978 }
1294 979
1295 pub fn voice_community(&self) -> Option<Id> {980 pub fn voice_community(&self) -> Option<Id> {
1296- match &self.voice_state {981+ match &self.session.voice_state {
1297 VoiceState::Off => None,982 VoiceState::Off => None,
1298 VoiceState::In { community_id, .. } => Some(*community_id),983 VoiceState::In { community_id, .. } => Some(*community_id),
1299 }984 }
@@ -1308,7 +993,7 @@ impl Chat {
1308 }993 }
1309 994
1310 pub fn voice_flags(&self) -> Option<(bool, bool)> {995 pub fn voice_flags(&self) -> Option<(bool, bool)> {
1311- match &self.voice_state {996+ match &self.session.voice_state {
1312 VoiceState::Off => None,997 VoiceState::Off => None,
1313 VoiceState::In {998 VoiceState::In {
1314 muted, deafened, ..999 muted, deafened, ..
@@ -1322,27 +1007,29 @@ impl Chat {
1322 }1007 }
1323 1008
1324 pub fn share_of(&self, community_id: Id, user_id: Id, kind: Kind) -> Option<&Share> {1009 pub fn share_of(&self, community_id: Id, user_id: Id, kind: Kind) -> Option<&Share> {
1325- self.shares1010+ self.session
1011+ .shares
1326 .get(&community_id)?1012 .get(&community_id)?
1327 .iter()1013 .iter()
1328 .find(|share| share.user_id == user_id && share.kind == kind)1014 .find(|share| share.user_id == user_id && share.kind == kind)
1329 }1015 }
1330 1016
1331 pub fn voice_ids(&self, community_id: Id) -> &[Id] {1017 pub fn voice_ids(&self, community_id: Id) -> &[Id] {
1332- self.voice1018+ self.session
1019+ .voice
1333 .get(&community_id)1020 .get(&community_id)
1334 .map(Vec::as_slice)1021 .map(Vec::as_slice)
1335 .unwrap_or_default()1022 .unwrap_or_default()
1336 }1023 }
1337 1024
1338 pub fn set_voice_off(&mut self) {1025 pub fn set_voice_off(&mut self) {
1339- self.voice_state = VoiceState::Off;1026+ self.session.voice_state = VoiceState::Off;
1340- self.waves.clear();1027+ self.session.waves.clear();
1341- self.voice_task = None;1028+ self.session.voice_task = None;
1342- self.stats.voice.clear();1029+ self.session.stats.voice.clear();
1343- self.stats.traffic.clear();1030+ self.session.stats.traffic.clear();
1344- self.stats.share = ShareSample::default();1031+ self.session.stats.share = ShareSample::default();
1345- self.share_loss.clear();1032+ self.session.share_loss.clear();
1346 }1033 }
1347 1034
1348 pub fn record_share(&mut self, sample: ShareSample) {1035 pub fn record_share(&mut self, sample: ShareSample) {
@@ -1376,39 +1063,43 @@ impl Chat {
1376 "watch"1063 "watch"
1377 );1064 );
1378 }1065 }
1379- self.share_loss.retain(|key, _| {1066+ self.session.share_loss.retain(|key, _| {
1380 sample1067 sample
1381 .watching1068 .watching
1382 .iter()1069 .iter()
1383 .any(|(user_id, kind, _)| (*user_id, *kind) == *key)1070 .any(|(user_id, kind, _)| (*user_id, *kind) == *key)
1384 });1071 });
1385 for (user_id, kind, stats) in &sample.watching {1072 for (user_id, kind, stats) in &sample.watching {
1386- let history = self.share_loss.entry((*user_id, *kind)).or_default();1073+ let history = self
1074+ .session
1075+ .share_loss
1076+ .entry((*user_id, *kind))
1077+ .or_default();
1387 history.push_back((common::time::now_ms(), stats.loss));1078 history.push_back((common::time::now_ms(), stats.loss));
1388 while history.len() > SAMPLE_HISTORY {1079 while history.len() > SAMPLE_HISTORY {
1389 history.pop_front();1080 history.pop_front();
1390 }1081 }
1391 }1082 }
1392- self.stats.share = sample;1083+ self.session.stats.share = sample;
1393 }1084 }
1394 }1085 }
1395 1086
1396-fn empty_state(palette: Palette) -> impl IntoElement {1087+fn empty_state(t: Tokens) -> impl IntoElement {
1397 div()1088 div()
1398 .flex_1()1089 .flex_1()
1399 .flex()1090 .flex()
1400 .items_center()1091 .items_center()
1401 .justify_center()1092 .justify_center()
1402 .gap(px(space::SM))1093 .gap(px(space::SM))
1403- .text_color(palette.muted)1094+ .text_color(t.dim())
1404 .child(1095 .child(
1405 div()1096 div()
1406 .px(px(space::XS))1097 .px(px(space::XS))
1407 .rounded(px(radius::SM))1098 .rounded(px(radius::SM))
1408 .border_1()1099 .border_1()
1409- .border_color(palette.border)1100+ .border_color(t.thread())
1410 .text_size(text(text::CAPTION))1101 .text_size(text(text::CAPTION))
1411- .child(JUMP_HINT),1102+ .child(super::keys::label("K")),
1412 )1103 )
1413 .child(w().jump.placeholder)1104 .child(w().jump.placeholder)
1414 }1105 }
@@ -1443,20 +1134,20 @@ impl Yumush {
1443 1134
1444 pub(super) fn refresh_usage(&mut self) {1135 pub(super) fn refresh_usage(&mut self) {
1445 if let Some(usage) = self.chat.usage_monitor.latest() {1136 if let Some(usage) = self.chat.usage_monitor.latest() {
1446- self.chat.stats.usage = Some(usage);1137+ self.chat.session.stats.usage = Some(usage);
1447 }1138 }
1448 }1139 }
1449 1140
1450 pub(super) fn chat_page(&self, cx: &mut Context<Self>) -> impl IntoElement {1141 pub(super) fn chat_page(&self, cx: &mut Context<Self>) -> impl IntoElement {
1451- let palette = palette(cx);1142+ let t = Tokens::of(cx);
1452 let entity = cx.entity();1143 let entity = cx.entity();
1453 1144
1454 div()1145 div()
1455 .flex()1146 .flex()
1456 .flex_row()1147 .flex_row()
1457 .size_full()1148 .size_full()
1458- .when(self.chat.view == View::Chat, |page| {1149+ .when(self.chat.session.view == View::Chat, |page| {
1459- page.child(self.sidebar(&entity, palette))1150+ page.child(self.sidebar(&entity, t))
1460 })1151 })
1461 .relative()1152 .relative()
1462 .on_mouse_move({1153 .on_mouse_move({
@@ -1465,58 +1156,54 @@ impl Yumush {
1465 entity.update(cx, |yumush, cx| yumush.float_moved(event, window, cx))1156 entity.update(cx, |yumush, cx| yumush.float_moved(event, window, cx))
1466 }1157 }
1467 })1158 })
1468- .child(self.main_panel(&entity, palette, cx))1159+ .child(self.main_panel(&entity, t, cx))
1469- .children(self.floating_viewer(&entity, palette))1160+ .children(self.floating_viewer(&entity, t))
1470- .children(self.fullscreen_viewer(&entity, palette))1161+ .children(self.fullscreen_viewer(&entity, t))
1471 }1162 }
1472 1163
1473- fn main_panel(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> impl IntoElement {1164+ fn main_panel(&self, entity: &Entity<Self>, t: Tokens, cx: &App) -> impl IntoElement {
1474- let themed = palette;
1475-
1476 div()1165 div()
1477 .flex_1()1166 .flex_1()
1478 .min_w_0()1167 .min_w_0()
1479 .flex()1168 .flex()
1480 .flex_col()1169 .flex_col()
1481 .relative()1170 .relative()
1482- .bg(palette.window)1171+ .bg(t.ground())
1483 .overflow_hidden()1172 .overflow_hidden()
1484- .children(self.announcement_banner(entity, palette))1173+ .children(self.announcement_banner(entity, t))
1485- .children(self.call_banner(entity, palette))1174+ .children(self.call_banner(entity, t))
1486- .map(|panel| match self.chat.view {1175+ .map(|panel| match self.chat.session.view {
1487- View::Settings => panel.child(self.settings_page(entity, palette, cx)),1176+ View::Settings => panel.child(self.settings_page(entity, t, cx)),
1488- View::Builder => panel.child(self.builder_page(entity, palette, cx)),1177+ View::Builder => panel.child(self.builder_page(entity, t, cx)),
1489- View::CommunitySettings => {1178+ View::CommunitySettings => panel.child(self.community_settings_page(entity, t, cx)),
1490- panel.child(self.community_settings_page(entity, palette, cx))1179+ View::Chat => match self.chat.session.selected_community_id {
1491- }
1492- View::Chat => match self.chat.selected_community_id {
1493 Some(_) => {1180 Some(_) => {
1494- let viewer = self.inline_viewer(entity, themed);1181+ let viewer = self.inline_viewer(entity, t);
1495 let grid = viewer1182 let grid = viewer
1496 .is_none()1183 .is_none()
1497 .then(|| {1184 .then(|| {
1498- self.stage_grid(entity, themed, cx)1185+ self.stage_grid(entity, t, cx)
1499 .map(IntoElement::into_any_element)1186 .map(IntoElement::into_any_element)
1500 })1187 })
1501 .flatten();1188 .flatten();
1502 panel1189 panel
1503- .child(self.header(entity, themed))1190+ .child(self.header(entity, t))
1504- .children(self.stage_strip(entity, themed))1191+ .children(self.stage_strip(entity, t))
1505- .children(self.unread_bar(entity, themed))1192+ .children(self.unread_bar(entity, t))
1506- .children(self.poll_banner(entity, themed))1193+ .children(self.poll_banner(entity, t))
1507- .child(self.chat_body(entity, themed, viewer, grid, cx))1194+ .child(self.chat_body(entity, t, viewer, grid, cx))
1508 }1195 }
1509- None => panel.child(empty_state(palette)),1196+ None => panel.child(empty_state(t)),
1510 },1197 },
1511 })1198 })
1512- .children(self.stats_sheet(palette))1199+ .children(self.stats_sheet(t))
1513- .children(self.dock(entity, palette, cx))1200+ .children(self.dock(entity, t, cx))
1514 }1201 }
1515 1202
1516 fn chat_body(1203 fn chat_body(
1517 &self,1204 &self,
1518 entity: &Entity<Self>,1205 entity: &Entity<Self>,
1519- palette: Palette,1206+ t: Tokens,
1520 viewer: Option<Div>,1207 viewer: Option<Div>,
1521 grid: Option<AnyElement>,1208 grid: Option<AnyElement>,
1522 cx: &App,1209 cx: &App,
@@ -1526,10 +1213,10 @@ impl Yumush {
1526 .size_full()1213 .size_full()
1527 .flex()1214 .flex()
1528 .flex_col()1215 .flex_col()
1529- .child(self.message_area(entity, palette))1216+ .child(self.message_area(entity, t))
1530- .child(self.composer(entity, palette, cx))1217+ .child(self.composer(entity, t, cx))
1531 };1218 };
1532- let members = members_column(entity, self, palette);1219+ let members = members_column(entity, self, t);
1533 match (viewer, grid, members) {1220 match (viewer, grid, members) {
1534 (None, Some(grid), Some(members)) => div()1221 (None, Some(grid), Some(members)) => div()
1535 .flex_1()1222 .flex_1()
@@ -1585,20 +1272,20 @@ impl Yumush {
1585 .flex()1272 .flex()
1586 .flex_col()1273 .flex_col()
1587 .border_l_1()1274 .border_l_1()
1588- .border_color(palette.border)1275+ .border_color(t.thread())
1589 .child(members.flex_1().min_h_0())1276 .child(members.flex_1().min_h_0())
1590 }))1277 }))
1591 .into_any_element(),1278 .into_any_element(),
1592 }1279 }
1593 }1280 }
1594 1281
1595- fn stats_sheet(&self, palette: Palette) -> Option<impl IntoElement> {1282+ fn stats_sheet(&self, t: Tokens) -> Option<impl IntoElement> {
1596 let at = self1283 let at = self
1597 .chat1284 .chat
1598 .stats_at1285 .stats_at
1599 .filter(|_| self.chat.voice_community().is_some())?;1286 .filter(|_| self.chat.voice_community().is_some())?;
1600 Some(1287 Some(
1601- super::parts::surface(palette.tokens)1288+ super::parts::surface(t)
1602 .id("stats_sheet")1289 .id("stats_sheet")
1603 .absolute()1290 .absolute()
1604 .right(px(space::LG))1291 .right(px(space::LG))
@@ -1614,22 +1301,22 @@ impl Yumush {
1614 StatsAt::Dock => space::LG,1301 StatsAt::Dock => space::LG,
1615 }))1302 }))
1616 .child(voice_stats::stats_panel(1303 .child(voice_stats::stats_panel(
1617- &self.chat.stats,1304+ &self.chat.session.stats,
1618 &|id| self.chat.name_of(id),1305 &|id| self.chat.name_of(id),
1619 match at {1306 match at {
1620 StatsAt::Header => voice_stats::Detail::Full,1307 StatsAt::Header => voice_stats::Detail::Full,
1621 StatsAt::Dock => voice_stats::Detail::Connection,1308 StatsAt::Dock => voice_stats::Detail::Connection,
1622 },1309 },
1623- palette,1310+ t,
1624 )),1311 )),
1625 )1312 )
1626 }1313 }
1627 1314
1628- fn announcement_banner(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {1315+ fn announcement_banner(&self, entity: &Entity<Self>, t: Tokens) -> Option<Div> {
1629 let text = self.announcement()?;1316 let text = self.announcement()?;
1630 1317
1631 Some(1318 Some(
1632- accent_bar(palette)1319+ accent_bar(t)
1633 .child(super::glyph::line(1320 .child(super::glyph::line(
1634 text.to_string().into(),1321 text.to_string().into(),
1635 super::text(super::style::text::UI),1322 super::text(super::style::text::UI),
@@ -1637,7 +1324,7 @@ impl Yumush {
1637 .child(1324 .child(
1638 clickable(1325 clickable(
1639 "dismiss_announcement",1326 "dismiss_announcement",
1640- palette,1327+ t,
1641 entity_action(entity, |yumush, _, cx| yumush.dismiss_announcement(cx)),1328 entity_action(entity, |yumush, _, cx| yumush.dismiss_announcement(cx)),
1642 )1329 )
1643 .child("×"),1330 .child("×"),
@@ -1645,11 +1332,11 @@ impl Yumush {
1645 )1332 )
1646 }1333 }
1647 1334
1648- fn header(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {1335+ fn header(&self, entity: &Entity<Self>, t: Tokens) -> impl IntoElement {
1649 let community = self.chat.selected_community();1336 let community = self.chat.selected_community();
1650 let name = community.map(community_name).unwrap_or_default();1337 let name = community.map(community_name).unwrap_or_default();
1651 let group = community.is_some_and(|community| community.kind.is_group());1338 let group = community.is_some_and(|community| community.kind.is_group());
1652- let voice = self.voice_toggle(entity, palette);1339+ let voice = self.voice_toggle(entity, t);
1653 let peer = community.and_then(|community| match &community.kind {1340 let peer = community.and_then(|community| match &community.kind {
1654 CommunityKind::Direct { peer } => Some(self.chat.author(peer.id).unwrap_or(peer)),1341 CommunityKind::Direct { peer } => Some(self.chat.author(peer.id).unwrap_or(peer)),
1655 _ => None,1342 _ => None,
@@ -1659,7 +1346,7 @@ impl Yumush {
1659 name.to_string(),1346 name.to_string(),
1660 super::parts::Text::Title,1347 super::parts::Text::Title,
1661 super::parts::Ink::Paper,1348 super::parts::Ink::Paper,
1662- palette.tokens,1349+ t,
1663 );1350 );
1664 1351
1665 div()1352 div()
@@ -1680,11 +1367,11 @@ impl Yumush {
1680 .items_center()1367 .items_center()
1681 .gap(px(space::SM))1368 .gap(px(space::SM))
1682 .child(super::avatar(1369 .child(super::avatar(
1683- palette,1370+ t,
1684 peer,1371 peer,
1685 px(size::AVATAR),1372 px(size::AVATAR),
1686 super::text(super::style::text::CAPTION),1373 super::text(super::style::text::CAPTION),
1687- &self.chat.avatars,1374+ &self.chat.session.avatars,
1688 ))1375 ))
1689 .child(title),1376 .child(title),
1690 )1377 )
@@ -1698,11 +1385,11 @@ impl Yumush {
1698 .items_center()1385 .items_center()
1699 .gap(px(space::SM))1386 .gap(px(space::SM))
1700 .child(super::community_icon(1387 .child(super::community_icon(
1701- palette,1388+ t,
1702 room,1389 room,
1703 px(size::AVATAR),1390 px(size::AVATAR),
1704 super::text(super::style::text::CAPTION),1391 super::text(super::style::text::CAPTION),
1705- &self.chat.avatars,1392+ &self.chat.session.avatars,
1706 ))1393 ))
1707 .child(title),1394 .child(title),
1708 )1395 )
@@ -1716,14 +1403,14 @@ impl Yumush {
1716 entity,1403 entity,
1717 "header_picture",1404 "header_picture",
1718 super::community_icon(1405 super::community_icon(
1719- palette,1406+ t,
1720 community,1407 community,
1721 px(size::AVATAR),1408 px(size::AVATAR),
1722 super::text(super::style::text::CAPTION),1409 super::text(super::style::text::CAPTION),
1723- &self.chat.avatars,1410+ &self.chat.session.avatars,
1724 ),1411 ),
1725 super::Zoom::new(1412 super::Zoom::new(
1726- super::picture_of(community, &self.chat.avatars),1413+ super::picture_of(community, &self.chat.session.avatars),
1727 !community.kind.is_group(),1414 !community.kind.is_group(),
1728 name.to_string(),1415 name.to_string(),
1729 ),1416 ),
@@ -1736,7 +1423,7 @@ impl Yumush {
1736 .children(1423 .children(
1737 community1424 community
1738 .is_some()1425 .is_some()
1739- .then(|| self.stage_controls(entity, palette))1426+ .then(|| self.stage_controls(entity, t))
1740 .flatten(),1427 .flatten(),
1741 )1428 )
1742 .children(1429 .children(
@@ -1747,26 +1434,26 @@ impl Yumush {
1747 &self.chat,1434 &self.chat,
1748 self.settings.clock(),1435 self.settings.clock(),
1749 entity,1436 entity,
1750- palette,1437+ t,
1751 )1438 )
1752 }),1439 }),
1753 )1440 )
1754 .children(1441 .children(
1755- (community.is_some() && !self.chat.pins.is_empty())1442+ (community.is_some() && !self.chat.session.pins.is_empty())
1756- .then(|| message_actions::pins_popover(&self.chat, entity, palette)),1443+ .then(|| message_actions::pins_popover(&self.chat, entity, t)),
1757 )1444 )
1758- .children(self.calling_hint(palette))1445+ .children(self.calling_hint(t))
1759 .children(voice.is_some().then(|| {1446 .children(voice.is_some().then(|| {
1760 div()1447 div()
1761 .w(px(stroke::LINE))1448 .w(px(stroke::LINE))
1762 .h(px(size::CHIP))1449 .h(px(size::CHIP))
1763 .flex_none()1450 .flex_none()
1764- .bg(palette.tokens.thread())1451+ .bg(t.thread())
1765 }))1452 }))
1766 .children(voice)1453 .children(voice)
1767 }1454 }
1768 1455
1769- fn message_area(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {1456+ fn message_area(&self, entity: &Entity<Self>, t: Tokens) -> impl IntoElement {
1770 div()1457 div()
1771 .flex()1458 .flex()
1772 .flex_col()1459 .flex_col()
@@ -1780,58 +1467,56 @@ impl Yumush {
1780 .top_0()1467 .top_0()
1781 .bottom_0()1468 .bottom_0()
1782 .w(px(stroke::LINE))1469 .w(px(stroke::LINE))
1783- .bg(palette.border),1470+ .bg(t.thread()),
1784 )1471 )
1785- .child(self.message_list(entity, palette))1472+ .child(self.message_list(entity, t))
1786- .children(self.jump_bottom(entity, palette))1473+ .children(self.jump_bottom(entity, t))
1787 }1474 }
1788 1475
1789- fn unread_bar(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {1476+ fn unread_bar(&self, entity: &Entity<Self>, t: Tokens) -> Option<impl IntoElement> {
1790- let (anchor, count) = self.chat.unread_anchor?;1477+ let (anchor, count) = self.chat.session.unread_anchor?;
1791 if self.chat.unread_covered() {1478 if self.chat.unread_covered() {
1792 return None;1479 return None;
1793 }1480 }
1794 Some(1481 Some(
1795- accent_bar(palette)1482+ accent_bar(t).child(w().chat.new_messages(count)).child(
1796- .child(w().chat.new_messages(count))1483+ div()
1797- .child(1484+ .flex()
1798- div()1485+ .gap(px(space::SM))
1799- .flex()1486+ .child(
1800- .gap(px(space::SM))1487+ clickable(
1801- .child(1488+ "jump_unread",
1802- clickable(1489+ t,
1803- "jump_unread",1490+ entity_action(entity, move |yumush, window, cx| {
1804- palette,1491+ yumush.go_to_message(anchor, window, cx)
1805- entity_action(entity, move |yumush, window, cx| {1492+ }),
1806- yumush.go_to_message(anchor, window, cx)
1807- }),
1808- )
1809- .child("↑"),
1810 )1493 )
1811- .child(1494+ .child("↑"),
1812- clickable(1495+ )
1813- "dismiss_unread",1496+ .child(
1814- palette,1497+ clickable(
1815- entity_action(entity, |yumush, _, cx| {1498+ "dismiss_unread",
1816- yumush.chat.unread_anchor = None;1499+ t,
1817- cx.notify();1500+ entity_action(entity, |yumush, _, cx| {
1818- }),1501+ yumush.chat.session.unread_anchor = None;
1819- )1502+ cx.notify();
1820- .child("×"),1503+ }),
1821- ),1504+ )
1822- ),1505+ .child("×"),
1506+ ),
1507+ ),
1823 )1508 )
1824 }1509 }
1825 1510
1826- fn jump_bottom(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {1511+ fn jump_bottom(&self, entity: &Entity<Self>, t: Tokens) -> Option<impl IntoElement> {
1827 if !self.chat.away() {1512 if !self.chat.away() {
1828 return None;1513 return None;
1829 }1514 }
1830- let unseen = self.chat.unseen;1515+ let unseen = self.chat.session.unseen;
1831 Some(1516 Some(
1832 clickable(1517 clickable(
1833 "jump_bottom",1518 "jump_bottom",
1834- palette,1519+ t,
1835 entity_action(entity, |yumush, _, cx| {1520 entity_action(entity, |yumush, _, cx| {
1836 yumush.chat.jump_to_bottom();1521 yumush.chat.jump_to_bottom();
1837 cx.notify();1522 cx.notify();
@@ -1846,8 +1531,8 @@ impl Yumush {
1846 .justify_center()1531 .justify_center()
1847 .rounded_full()1532 .rounded_full()
1848 .border_1()1533 .border_1()
1849- .border_color(palette.border)1534+ .border_color(t.thread())
1850- .bg(palette.window)1535+ .bg(t.ground())
1851 .child(Icon::new(IconName::ArrowDown).size(px(size::ICON)))1536 .child(Icon::new(IconName::ArrowDown).size(px(size::ICON)))
1852 .children((unseen > 0).then(|| {1537 .children((unseen > 0).then(|| {
1853 div()1538 div()
@@ -1855,7 +1540,7 @@ impl Yumush {
1855 .top(px(-space::SM))1540 .top(px(-space::SM))
1856 .right(px(-space::SM))1541 .right(px(-space::SM))
1857 .children(unread_badge(1542 .children(unread_badge(
1858- palette,1543+ t,
1859 false,1544 false,
1860 Some(&Unread {1545 Some(&Unread {
1861 messages: unseen,1546 messages: unseen,
@@ -1866,13 +1551,14 @@ impl Yumush {
1866 )1551 )
1867 }1552 }
1868 1553
1869- fn message_list(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement {1554+ fn message_list(&self, entity: &Entity<Self>, t: Tokens) -> AnyElement {
1870 let divider = self1555 let divider = self
1871 .chat1556 .chat
1872 .unread_divider(self.user.as_ref().map(|user| user.id));1557 .unread_divider(self.user.as_ref().map(|user| user.id));
1873 let entity_scroll = entity.clone();1558 let entity_scroll = entity.clone();
1874 let glide = self1559 let glide = self
1875 .chat1560 .chat
1561+ .session
1876 .glide1562 .glide
1877 .filter(|(_, _, at)| at.elapsed() < GLIDE + GLIDE_SLACK);1563 .filter(|(_, _, at)| at.elapsed() < GLIDE + GLIDE_SLACK);
1878 let list = div()1564 let list = div()
@@ -1897,101 +1583,48 @@ impl Yumush {
1897 });1583 });
1898 })1584 })
1899 .child(div().flex_1())1585 .child(div().flex_1())
1900- .children((self.chat.history == History::More).then(|| older_button(entity, palette)))1586+ .children((self.chat.session.history == History::More).then(|| older_button(entity, t)))
1901 .children(1587 .children(
1902- self.chat1588+ message_rows(
1903- .messages1589+ &self.chat.session.messages,
1904- .iter()1590+ &self.chat.session.open_calls,
1905- .enumerate()1591+ divider,
1906- .filter(|(index, message)| {1592+ )
1907- message.call.is_none()1593+ .into_iter()
1908- || divider == Some(*index)1594+ .map(|(index, message, first, run)| {
1909- || self1595+ let row = render_message(
1910- .chat1596+ message,
1911- .messages1597+ first,
1912- .get(index + 1)1598+ index > 0,
1913- .is_none_or(|next| next.call.is_none())1599+ run,
1914- || self1600+ &self.chat,
1915- .chat1601+ self.user.as_ref(),
1916- .open_calls1602+ self.settings.clock(),
1917- .contains(&self.chat.call_run_end(*index))1603+ entity,
1918- })1604+ t,
1919- .map(|(index, message)| {1605+ );
1920- let calls = self.chat.messages[..=index]1606+ let row = match glide {
1921- .iter()1607+ Some((id, _, _)) if id == message.id => div()
1922- .rev()1608+ .child(row)
1923- .take_while(|message| message.call.is_some())1609+ .with_animation(
1924- .count();1610+ format!("chat_arrive_{id}"),
1925- let start = index + 1 - calls.max(1);1611+ gpui_kit::Animation::new(GLIDE),
1926- let calls = self.chat.messages[start..=index]1612+ |row, delta| row.opacity(delta),
1927- .iter()1613+ )
1928- .filter(|message| message.call == Some(CallLog::Started))1614+ .into_any_element(),
1929- .count();1615+ _ => row,
1930- let first = start == 0 || {1616+ };
1931- let previous = &self.chat.messages[start - 1];1617+ if divider == Some(index) {
1932- match message.call {1618+ div()
1933- Some(_) => previous.call.is_none(),1619+ .flex()
1934- None => {1620+ .flex_col()
1935- previous.user_id != message.user_id || previous.call.is_some()1621+ .child(new_divider(t))
1936- }1622+ .child(row)
1937- }1623+ .into_any_element()
1938- };1624+ } else {
1939- let run = match message.call {1625+ row
1940- Some(_)1626+ }
1941- if self1627+ }),
1942- .chat
1943- .open_calls
1944- .contains(&self.chat.call_run_end(index)) =>
1945- {
1946- if self.chat.call_run_end(index) == message.id {
1947- CallRun::Open
1948- } else {
1949- CallRun::Single
1950- }
1951- }
1952- _ if calls > 1 => CallRun::Folded(calls),
1953- _ => CallRun::Single,
1954- };
1955- let first = first
1956- && !(message.call.is_some()
1957- && index != start
1958- && self
1959- .chat
1960- .open_calls
1961- .contains(&self.chat.call_run_end(index)));
1962- let row = render_message(
1963- message,
1964- first,
1965- start > 0,
1966- run,
1967- &self.chat,
1968- self.user.as_ref(),
1969- self.settings.clock(),
1970- entity,
1971- palette,
1972- );
1973- let row = match glide {
1974- Some((id, _, _)) if id == message.id => div()
1975- .child(row)
1976- .with_animation(
1977- format!("chat_arrive_{id}"),
1978- gpui_kit::Animation::new(GLIDE),
1979- |row, delta| row.opacity(delta),
1980- )
1981- .into_any_element(),
1982- _ => row,
1983- };
1984- if divider == Some(index) {
1985- div()
1986- .flex()
1987- .flex_col()
1988- .child(new_divider(palette))
1989- .child(row)
1990- .into_any_element()
1991- } else {
1992- row
1993- }
1994- }),
1995 );1628 );
1996 let Some((id, from, _)) = glide else {1629 let Some((id, from, _)) = glide else {
1997 return list.into_any_element();1630 return list.into_any_element();
@@ -2010,41 +1643,36 @@ impl Yumush {
2010 .into_any_element()1643 .into_any_element()
2011 }1644 }
2012 1645
2013- fn composer(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> AnyElement {1646+ fn composer(&self, entity: &Entity<Self>, t: Tokens, cx: &App) -> AnyElement {
2014 if let Composer::Select { ids } = &self.chat.composer {1647 if let Composer::Select { ids } = &self.chat.composer {
2015 return div()1648 return div()
2016 .p(px(space::LG))1649 .p(px(space::LG))
2017- .child(composer::selection_bar(ids, entity, palette))1650+ .child(composer::selection_bar(ids, entity, t))
2018 .into_any_element();1651 .into_any_element();
2019 }1652 }
2020 1653
2021 let input = self.chat.message_input.clone();1654 let input = self.chat.message_input.clone();
2022- let pending = media_view::pending_row(&self.chat.media, entity, palette);1655+ let pending = media_view::pending_row(&self.chat.session.media, entity, t);
2023- let bar = composer::mode_bar(&self.chat, entity, palette);1656+ let bar = composer::mode_bar(&self.chat, entity, t);
2024 let entity = entity.clone();1657 let entity = entity.clone();
2025 1658
2026 if let VoiceNote::Recording {1659 if let VoiceNote::Recording {
2027 started, levels, ..1660 started, levels, ..
2028- } = &self.chat.media.voice_note1661+ } = &self.chat.session.media.voice_note
2029 {1662 {
2030 return div()1663 return div()
2031 .p(px(space::LG))1664 .p(px(space::LG))
2032 .children(pending)1665 .children(pending)
2033- .child(voice_note::recording_row(1666+ .child(voice_note::recording_row(*started, levels, &entity, t))
2034- *started, levels, &entity, palette,
2035- ))
2036 .into_any_element();1667 .into_any_element();
2037 }1668 }
2038 1669
2039 let ready = self.chat.message_input.read(cx).text().len() > 01670 let ready = self.chat.message_input.read(cx).text().len() > 0
2040- || !self.chat.media.pending.is_empty();1671+ || !self.chat.session.media.pending.is_empty();
2041 1672
2042 composer::format_actions(1673 composer::format_actions(
2043 &self.chat.message_input,1674 &self.chat.message_input,
2044- div()1675+ div().p(px(space::LG)).border_t_1().border_color(t.thread()),
2045- .p(px(space::LG))
2046- .border_t_1()
2047- .border_color(palette.border),
2048 )1676 )
2049 .children(pending)1677 .children(pending)
2050 .children(bar)1678 .children(bar)
@@ -2053,7 +1681,7 @@ impl Yumush {
2053 .pl(px(space::XS))1681 .pl(px(space::XS))
2054 .pb(px(space::XS))1682 .pb(px(space::XS))
2055 .text_size(text(text::CAPTION))1683 .text_size(text(text::CAPTION))
2056- .text_color(palette.muted)1684+ .text_color(t.dim())
2057 .child(label)1685 .child(label)
2058 }))1686 }))
2059 .child(1687 .child(
@@ -2065,7 +1693,7 @@ impl Yumush {
2065 .flex()1693 .flex()
2066 .items_center()1694 .items_center()
2067 .gap(px(space::SM))1695 .gap(px(space::SM))
2068- .child(composer::plus_popover(&self.chat, &entity, palette))1696+ .child(composer::plus_popover(&entity, t))
2069 .child(1697 .child(
2070 Textarea::new(&self.chat.message_input)1698 Textarea::new(&self.chat.message_input)
2071 .token(super::glyph::token)1699 .token(super::glyph::token)
@@ -2077,22 +1705,22 @@ impl Yumush {
2077 })1705 })
2078 .appearance(false)1706 .appearance(false)
2079 .text_size(text(text::BODY))1707 .text_size(text(text::BODY))
2080- .text_color(palette.text)1708+ .text_color(t.paper())
2081 .flex_1()1709 .flex_1()
2082 .min_w_0(),1710 .min_w_0(),
2083 )1711 )
2084 .child(super::glyph::picker_button(1712 .child(super::glyph::picker_button(
2085 "composer_emoji",1713 "composer_emoji",
2086 &entity,1714 &entity,
2087- palette,1715+ t,
2088 super::glyph::insert_into(self.chat.message_input.clone()),1716 super::glyph::insert_into(self.chat.message_input.clone()),
2089 ))1717 ))
2090 .when(!ready, |this| {1718 .when(!ready, |this| {
2091- this.child(voice_note::mic_button(&entity, palette))1719+ this.child(voice_note::mic_button(&entity, t))
2092 })1720 })
2093 .when(ready, |this| {1721 .when(ready, |this| {
2094 this.child(1722 this.child(
crates/client/src/gui/chat/admin.rsadded+205 -0
@@ -0,0 +1,205 @@
1+use crate::gui::builder::{BuilderTab, Transfer};
2+use crate::gui::{Yumush, new_input};
3+use crate::lang::w;
4+use common::model::{
5+ Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BanScope, CommunitySummary,
6+ CommunityUsage, DayStat, Id, InviteCode, MessageHit, Overview, Report, ReportStatus, ServerBan,
7+ SessionInfo, UpdateClient, User, UserUsage, VoiceRoom,
8+};
9+use common::stats::Stats;
10+use gpui_kit::{
11+ AppContext, Context, Entity, Task, Window,
12+ component::{
13+ IndexPath, input::InputState, searchable_list::SearchableVec, select::SelectState,
14+ },
15+};
16+
17+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18+pub enum UserEdit {
19+ Password,
20+ Rename,
21+ Timeout,
22+ Ban,
23+}
24+
25+pub struct Admin {
26+ pub builder_password: Entity<InputState>,
27+ pub builder_rename: Entity<InputState>,
28+ pub builder_timeout: Entity<InputState>,
29+ pub builder_ban_reason: Entity<InputState>,
30+ pub new_username: Entity<InputState>,
31+ pub new_password: Entity<InputState>,
32+ pub server_name: Entity<InputState>,
33+ pub server_limit: Entity<InputState>,
34+ pub server_user_quota: Entity<InputState>,
35+ pub server_community_quota: Entity<InputState>,
36+ pub server_message_retention: Entity<InputState>,
37+ pub server_attachment_retention: Entity<InputState>,
38+ pub server_announcement: Entity<InputState>,
39+ pub server_max_communities: Entity<InputState>,
40+ pub server_max_message_length: Entity<InputState>,
41+ pub server_max_avatar: Entity<InputState>,
42+ pub server_messages_per_minute: Entity<InputState>,
43+ pub server_logins_per_minute: Entity<InputState>,
44+ pub invite_uses: Entity<InputState>,
45+ pub invite_hours: Entity<InputState>,
46+ pub builder_log_actor: Entity<InputState>,
47+ pub builder_log_target: Entity<InputState>,
48+ pub builder_log_action: Entity<SelectState<SearchableVec<&'static str>>>,
49+ pub builder_log_from: Entity<InputState>,
50+ pub builder_log_to: Entity<InputState>,
51+ pub builder_search: Entity<InputState>,
52+ pub builder_friend_search: Entity<InputState>,
53+ pub builder_message_text: Entity<InputState>,
54+ pub builder_message_user: Entity<InputState>,
55+ pub builder_message_community: Entity<InputState>,
56+ pub builder_message_from: Entity<InputState>,
57+ pub builder_message_to: Entity<InputState>,
58+ pub builder_attachment_user: Entity<InputState>,
59+ pub builder_attachment_community: Entity<InputState>,
60+ pub builder_tab: BuilderTab,
61+ pub builder_users: Vec<Account>,
62+ pub builder_overview: Option<Overview>,
63+ pub builder_logs: Vec<AdminLogEntry>,
64+ pub builder_stats: Vec<DayStat>,
65+ pub builder_communities: Vec<CommunitySummary>,
66+ pub builder_reports: Vec<Report>,
67+ pub report_filter: Option<ReportStatus>,
68+ pub open_reports: usize,
69+ pub builder_messages: Vec<MessageHit>,
70+ pub builder_usage_users: Vec<UserUsage>,
71+ pub builder_usage_communities: Vec<CommunityUsage>,
72+ pub builder_attachments: Vec<AttachmentInfo>,
73+ pub transfer: Option<Transfer>,
74+ pub editing: Option<(Id, UserEdit)>,
75+ pub builder_sessions: Option<(Id, Vec<SessionInfo>)>,
76+ pub builder_clients: Vec<UpdateClient>,
77+ pub builder_clients_task: Option<Task<()>>,
78+ pub builder_friends: Vec<User>,
79+ pub builder_bans: Vec<ServerBan>,
80+ pub builder_ban_scope: BanScope,
81+ pub builder_invites: Vec<InviteCode>,
82+ pub builder_voice_rooms: Vec<VoiceRoom>,
83+ pub server_registration_open: bool,
84+ pub server_maintenance: bool,
85+ pub server_stats: Option<Stats>,
86+ pub server_stats_task: Option<Task<()>>,
87+}
88+
89+impl Admin {
90+ pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self {
91+ let builder_password = new_input(w().chat.new_password, window, cx);
92+ builder_password.update(cx, |input, cx| input.set_masked(true, window, cx));
93+ let new_password = new_input(w().chat.password, window, cx);
94+ new_password.update(cx, |input, cx| input.set_masked(true, window, cx));
95+
96+ Self {
97+ builder_password,
98+ builder_rename: new_input(w().chat.new_username, window, cx),
99+ builder_timeout: new_input(w().chat.minutes, window, cx),
100+ builder_ban_reason: new_input(w().chat.reason, window, cx),
101+ new_username: new_input(w().chat.username, window, cx),
102+ new_password,
103+ server_name: new_input(w().chat.server_name, window, cx),
104+ server_limit: new_input("", window, cx),
105+ server_user_quota: new_input("", window, cx),
106+ server_community_quota: new_input("", window, cx),
107+ server_message_retention: new_input("", window, cx),
108+ server_attachment_retention: new_input("", window, cx),
109+ server_announcement: new_input(w().chat.announcement, window, cx),
110+ server_max_communities: new_input("", window, cx),
111+ server_max_message_length: new_input(w().chat.max_message_length, window, cx),
112+ server_max_avatar: new_input("", window, cx),
113+ server_messages_per_minute: new_input("", window, cx),
114+ server_logins_per_minute: new_input("", window, cx),
115+ invite_uses: new_input(w().chat.uses, window, cx),
116+ invite_hours: new_input(w().chat.hours, window, cx),
117+ builder_log_actor: new_input(w().chat.actor, window, cx),
118+ builder_log_target: new_input(w().chat.target, window, cx),
119+ builder_log_action: cx.new(|cx| {
120+ SelectState::new(
121+ SearchableVec::new(
122+ std::iter::once(w().chat.all)
123+ .chain(
124+ AdminActionKind::ALL
125+ .into_iter()
126+ .map(AdminActionKind::as_str),
127+ )
128+ .collect::<Vec<_>>(),
129+ ),
130+ Some(IndexPath::new(0)),
131+ window,
132+ cx,
133+ )
134+ }),
135+ builder_log_from: new_input(w().chat.date_from, window, cx),
136+ builder_log_to: new_input(w().chat.date_to, window, cx),
137+ builder_search: new_input(w().chat.search, window, cx),
138+ builder_friend_search: new_input(w().chat.search, window, cx),
139+ builder_message_text: new_input(w().chat.text, window, cx),
140+ builder_message_user: new_input(w().chat.user, window, cx),
141+ builder_message_community: new_input(w().chat.community, window, cx),
142+ builder_message_from: new_input(w().chat.date_from, window, cx),
143+ builder_message_to: new_input(w().chat.date_to, window, cx),
144+ builder_attachment_user: new_input(w().chat.user, window, cx),
145+ builder_attachment_community: new_input(w().chat.community, window, cx),
146+ builder_tab: BuilderTab::Overview,
147+ builder_users: vec![],
148+ builder_overview: None,
149+ builder_logs: vec![],
150+ builder_stats: vec![],
151+ builder_communities: vec![],
152+ builder_reports: vec![],
153+ report_filter: Some(ReportStatus::Open),
154+ open_reports: 0,
155+ builder_messages: vec![],
156+ builder_usage_users: vec![],
157+ builder_usage_communities: vec![],
158+ builder_attachments: vec![],
159+ transfer: None,
160+ editing: None,
161+ builder_sessions: None,
162+ builder_clients: vec![],
163+ builder_clients_task: None,
164+ builder_friends: vec![],
165+ builder_bans: vec![],
166+ builder_ban_scope: BanScope::Account,
167+ builder_invites: vec![],
168+ builder_voice_rooms: vec![],
169+ server_registration_open: true,
170+ server_maintenance: false,
171+ server_stats: None,
172+ server_stats_task: None,
173+ }
174+ }
175+
176+ pub fn clear(&mut self) {
177+ self.builder_tab = BuilderTab::Overview;
178+ self.builder_users.clear();
179+ self.builder_overview = None;
180+ self.builder_logs.clear();
181+ self.builder_stats.clear();
182+ self.builder_communities.clear();
183+ self.builder_reports.clear();
184+ self.report_filter = Some(ReportStatus::Open);
185+ self.open_reports = 0;
186+ self.builder_messages.clear();
187+ self.builder_usage_users.clear();
188+ self.builder_usage_communities.clear();
189+ self.builder_attachments.clear();
190+ self.transfer = None;
191+ self.editing = None;
192+ self.builder_sessions = None;
193+ self.builder_clients.clear();
194+ self.builder_clients_task = None;
195+ self.builder_friends.clear();
196+ self.builder_bans.clear();
197+ self.builder_ban_scope = BanScope::Account;
198+ self.builder_invites.clear();
199+ self.builder_voice_rooms.clear();
200+ self.server_registration_open = true;
201+ self.server_maintenance = false;
202+ self.server_stats = None;
203+ self.server_stats_task = None;
204+ }
205+}
crates/client/src/gui/chat/poll_draft.rsadded+45 -0
@@ -0,0 +1,45 @@
1+use crate::gui::composer::{self, PlusMenu};
2+use crate::gui::{Yumush, new_input};
3+use crate::lang::w;
4+use common::constant::MINIMUM_POLL_OPTIONS;
5+use gpui_kit::{Context, Entity, Window, component::input::InputState};
6+
7+pub struct PollDraft {
8+ pub question: Entity<InputState>,
9+ pub options: Vec<Entity<InputState>>,
10+ pub multiple: bool,
11+ pub public: bool,
12+ pub duration: Option<u32>,
13+ pub plus_menu: PlusMenu,
14+ pub expanded: bool,
15+ pub page: usize,
16+}
17+
18+impl PollDraft {
19+ pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self {
20+ Self {
21+ question: new_input(w().chat.question, window, cx),
22+ options: (0..MINIMUM_POLL_OPTIONS)
23+ .map(|_| composer::new_poll_option(window, cx))
24+ .collect(),
25+ multiple: false,
26+ public: true,
27+ duration: None,
28+ plus_menu: PlusMenu::Menu,
29+ expanded: false,
30+ page: 0,
31+ }
32+ }
33+
34+ pub fn clear(&mut self, window: &mut Window, cx: &mut Context<Yumush>) {
35+ self.question
36+ .update(cx, |state, cx| state.set_value("", window, cx));
37+ self.options.truncate(MINIMUM_POLL_OPTIONS);
38+ for input in &self.options {
39+ input.update(cx, |state, cx| state.set_value("", window, cx));
40+ }
41+ self.multiple = false;
42+ self.public = true;
43+ self.duration = None;
44+ }
45+}
crates/client/src/gui/chat/session.rsadded+86 -0
@@ -0,0 +1,86 @@
1+use super::{Armed, CardMenu, History, ReportTarget, UserVolume, View, VoiceState};
2+use crate::gui::camera_view::Tile;
3+use crate::gui::media_view::Media;
4+use crate::gui::share_view::{Float, Viewer};
5+use crate::gui::social::InviteLookup;
6+use crate::gui::wave::Waves;
7+use common::model::{
8+ Ban, Community, Edit, Friends, Id, Invitation, LogEntry, Member, Message, MessageHit, Presence,
9+ Unread, User,
10+};
11+use common::share::Kind;
12+use common::stats::Stats;
13+use gpui_kit::{Image, Task};
14+use std::{
15+ collections::{BTreeMap, HashMap, HashSet, VecDeque},
16+ sync::Arc,
17+ time::Instant,
18+};
19+
20+#[derive(Default)]
21+pub struct Session {
22+ pub communities: Vec<Community>,
23+ pub selected_community_id: Option<Id>,
24+ pub opened: Option<Community>,
25+ pub ghost: bool,
26+ pub members: Vec<Member>,
27+ pub messages: Vec<Message>,
28+ pub pins: Vec<Message>,
29+ pub history: History,
30+ pub unread: HashMap<Id, Unread>,
31+ pub unread_anchor: Option<(Id, u32)>,
32+ pub unseen: u32,
33+ pub muted: HashSet<Id>,
34+ pub pinned: HashSet<Id>,
35+ pub edits: HashMap<Id, Vec<Edit>>,
36+ pub revealed: HashSet<Id>,
37+ pub friends_open: bool,
38+ pub open_calls: HashSet<Id>,
39+ pub community_hits: Vec<MessageHit>,
40+ pub found: Option<User>,
41+ pub invite: InviteLookup,
42+ pub drafts: HashMap<Id, String>,
43+ pub my_votes: HashMap<Id, Vec<u32>>,
44+ pub jump: Option<Id>,
45+ pub highlight: Option<(Id, Instant)>,
46+ pub glide: Option<(Id, gpui_kit::Pixels, Instant)>,
47+ pub view: View,
48+ pub section: Option<&'static str>,
49+ pub avatars: HashMap<Id, Arc<Image>>,
50+ pub avatar_requests: HashSet<Id>,
51+ pub users: HashMap<Id, User>,
52+ pub user_requests: HashSet<Id>,
53+ pub armed: Option<Armed>,
54+ pub bans: Vec<Ban>,
55+ pub logs: Vec<LogEntry>,
56+ pub friends: Friends,
57+ pub invitations: Vec<Invitation>,
58+ pub card_menu: CardMenu,
59+ pub presences: HashMap<Id, Presence>,
60+ pub slowed_until: Option<u64>,
61+ pub voice: HashMap<Id, Vec<Id>>,
62+ pub voice_state: VoiceState,
63+ pub server_muted: HashSet<Id>,
64+ pub ringing: HashSet<Id>,
65+ pub ring_task: Option<Task<()>>,
66+ pub voice_task: Option<Task<()>>,
67+ pub waves: Waves,
68+ pub typing: HashMap<Id, HashMap<Id, Instant>>,
69+ pub typing_sent: HashMap<Id, Instant>,
70+ pub shares: HashMap<Id, Vec<common::share::Share>>,
71+ pub media: Media,
72+ pub viewer: Option<Viewer>,
73+ pub float: Float,
74+ pub tiles: BTreeMap<(Id, Kind), Tile>,
75+ pub camera_task: Option<Task<()>>,
76+ pub storage: Vec<(crate::storage::Store, u64)>,
77+ pub volume_popover: Option<UserVolume>,
78+ pub stats_task: Option<Task<()>>,
79+ pub stats: Stats,
80+ pub followed: Option<(Id, Stats)>,
81+ pub share_loss: HashMap<(Id, Kind), VecDeque<(u64, f32)>>,
82+ pub report: Option<ReportTarget>,
83+ pub hover_row: Option<Id>,
84+ pub hover_bar: Option<Id>,
85+ pub reacting: Option<Id>,
86+}
crates/client/src/gui/community_card.rsmodified+23 -24
@@ -6,16 +6,15 @@ use gpui_kit::{
6 Anchor, Context, Div, Entity, FontWeight, Hsla, IntoElement, ParentElement, Styled, Window,6 Anchor, Context, Div, Entity, FontWeight, Hsla, IntoElement, ParentElement, Styled, Window,
7 assets::IconName,7 assets::IconName,
8 component::popover::{Popover, PopoverState},8 component::popover::{Popover, PopoverState},
9- div,
10 prelude::FluentBuilder as _,9 prelude::FluentBuilder as _,
11 px,10 px,
12 };11 };
13 12
14 use super::chat::Armed;13 use super::chat::Armed;
15-use super::parts::{Ink, Text, band, small_icon, stack, words};14+use super::parts::{Ink, Text, band, small_icon, stack, thread, words};
16 use super::profile::{armed_action, menu_row, yumush_action};15 use super::profile::{armed_action, menu_row, yumush_action};
17-use super::style::{size, space, stroke, text};16+use super::style::{Tokens, size, space, text};
18-use super::{Palette, Trigger, Yumush, text};17+use super::{Trigger, Yumush, text};
19 use crate::lang::w;18 use crate::lang::w;
20 use crate::marks::Mark;19 use crate::marks::Mark;
21 20
@@ -36,13 +35,13 @@ pub(super) fn community_popover(
36 .content(move |_, _, cx| {35 .content(move |_, _, cx| {
37 let popover = cx.entity();36 let popover = cx.entity();
38 let yumush = entity.read(cx);37 let yumush = entity.read(cx);
39- let palette = super::palette(cx);38+ let t = Tokens::of(cx);
40- let t = palette.tokens;
41 let id = community.id;39 let id = community.id;
42 let name = super::community_name(&community).to_string();40 let name = super::community_name(&community).to_string();
43- let members = yumush.chat.members.len();41+ let members = yumush.chat.session.members.len();
44 let online = yumush42 let online = yumush
45 .chat43 .chat
44+ .session
46 .members45 .members
47 .iter()46 .iter()
48 .filter(|member| yumush.is_online(member.user.id))47 .filter(|member| yumush.is_online(member.user.id))
@@ -56,14 +55,14 @@ pub(super) fn community_popover(
56 &entity,55 &entity,
57 "community_picture",56 "community_picture",
58 super::community_icon(57 super::community_icon(
59- palette,58+ t,
60 &community,59 &community,
61 px(size::AVATAR_LG),60 px(size::AVATAR_LG),
62 text(text::BODY),61 text(text::BODY),
63- &yumush.chat.avatars,62+ &yumush.chat.session.avatars,
64 ),63 ),
65 super::Zoom::new(64 super::Zoom::new(
66- super::picture_of(&community, &yumush.chat.avatars),65+ super::picture_of(&community, &yumush.chat.session.avatars),
67 false,66 false,
68 name.clone(),67 name.clone(),
69 ),68 ),
@@ -85,16 +84,16 @@ pub(super) fn community_popover(
85 )),84 )),
86 ),85 ),
87 )86 )
88- .child(div().w_full().h(px(stroke::LINE)).bg(t.thread()))87+ .child(thread(t))
89 .child(room_rows(88 .child(room_rows(
90 id,89 id,
91 true,90 true,
92 permission::can_leave(yumush.actor_rank()),91 permission::can_leave(yumush.actor_rank()),
93- permission::can_manage_community(yumush.actor_rank()),92+ permission::is_moderator(yumush.actor_rank()),
94 yumush,93 yumush,
95 &entity,94 &entity,
96 &popover,95 &popover,
97- palette,96+ t,
98 ))97 ))
99 })98 })
100 }99 }
@@ -107,10 +106,10 @@ pub(super) fn room_rows(
107 yumush: &Yumush,106 yumush: &Yumush,
108 entity: &Entity<Yumush>,107 entity: &Entity<Yumush>,
109 popover: &Entity<PopoverState>,108 popover: &Entity<PopoverState>,
110- palette: Palette,109+ t: Tokens,
111 ) -> Div {110 ) -> Div {
112- let pinned = yumush.chat.pinned.contains(&id);111+ let pinned = yumush.chat.session.pinned.contains(&id);
113- let muted = yumush.chat.muted.contains(&id);112+ let muted = yumush.chat.session.muted.contains(&id);
114 let words = &w().sidebar;113 let words = &w().sidebar;
115 let row = |key: &'static str,114 let row = |key: &'static str,
116 label: &'static str,115 label: &'static str,
@@ -122,7 +121,7 @@ pub(super) fn room_rows(
122 label,121 label,
123 small_icon(icon),122 small_icon(icon),
124 color,123 color,
125- palette,124+ t,
126 yumush_action(entity, popover, move |yumush, window, cx| {125 yumush_action(entity, popover, move |yumush, window, cx| {
127 run(yumush, id, window, cx)126 run(yumush, id, window, cx)
128 }),127 }),
@@ -135,7 +134,7 @@ pub(super) fn room_rows(
135 "room_invite",134 "room_invite",
136 words.invite,135 words.invite,
137 IconName::UserPlus,136 IconName::UserPlus,
138- palette.text,137+ t.paper(),
139 |yumush, id, window, cx| yumush.open_invite(id, window, cx),138 |yumush, id, window, cx| yumush.open_invite(id, window, cx),
140 ))139 ))
141 })140 })
@@ -144,7 +143,7 @@ pub(super) fn room_rows(
144 "room_settings",143 "room_settings",
145 words.settings,144 words.settings,
146 IconName::Settings,145 IconName::Settings,
147- palette.text,146+ t.paper(),
148 |yumush, id, window, cx| yumush.open_community_settings(id, window, cx),147 |yumush, id, window, cx| yumush.open_community_settings(id, window, cx),
149 ))148 ))
150 })149 })
@@ -152,7 +151,7 @@ pub(super) fn room_rows(
152 "room_pin",151 "room_pin",
153 if pinned { words.unpin } else { words.pin },152 if pinned { words.unpin } else { words.pin },
154 IconName::Pin,153 IconName::Pin,
155- palette.text,154+ t.paper(),
156 |yumush, id, _, cx| yumush.toggle_mark(Mark::Pin, id, cx),155 |yumush, id, _, cx| yumush.toggle_mark(Mark::Pin, id, cx),
157 ))156 ))
158 .child(row(157 .child(row(
@@ -163,17 +162,17 @@ pub(super) fn room_rows(
163 } else {162 } else {
164 IconName::BellOff163 IconName::BellOff
165 },164 },
166- palette.text,165+ t.paper(),
167 |yumush, id, _, cx| yumush.toggle_mark(Mark::Mute, id, cx),166 |yumush, id, _, cx| yumush.toggle_mark(Mark::Mute, id, cx),
168 ))167 ))
169 .when(can_leave, |this| {168 .when(can_leave, |this| {
170 let armed = Armed::Leave(id);169 let armed = Armed::Leave(id);
171 this.child(menu_row(170 this.child(menu_row(
172 ("room_leave", id as usize),171 ("room_leave", id as usize),
173- yumush.armed_label(armed, words.leave),172+ yumush.armed_label(armed.clone(), words.leave),
174 small_icon(IconName::LogOut),173 small_icon(IconName::LogOut),
175- palette.danger,174+ t.bad(),
176- palette,175+ t,
177 armed_action(armed, entity, popover, move |yumush, window, cx| {176 armed_action(armed, entity, popover, move |yumush, window, cx| {
178 yumush.leave_community(id, window, cx)177 yumush.leave_community(id, window, cx)
179 }),178 }),
crates/client/src/gui/community_settings.rsmodified+121 -102
@@ -19,7 +19,8 @@ use gpui_kit::{
19 };19 };
20 20
21 use super::{21 use super::{
22- Palette, Yumush, avatar,22+ Yumush, avatar,
23+ builder::BuilderTab,
23 chat::{Armed, View},24 chat::{Armed, View},
24 clickable, community_icon, entity_action, millis_time, notify_error,25 clickable, community_icon, entity_action, millis_time, notify_error,
25 profile::user_link,26 profile::user_link,
@@ -27,7 +28,7 @@ use super::{
27 Editable, Picture, Section, danger, delete_control, page, picked_avatar, picture_card, row,28 Editable, Picture, Section, danger, delete_control, page, picked_avatar, picture_card, row,
28 section, small_button, text_row,29 section, small_button, text_row,
29 },30 },
30- style::{radius, size, space, text as text_token},31+ style::{Tokens, radius, size, space, text as text_token},
31 text,32 text,
32 widget::search_text,33 widget::search_text,
33 };34 };
@@ -69,8 +70,23 @@ fn apply_community(
69 ) {70 ) {
70 match result {71 match result {
71 Ok(community) => {72 Ok(community) => {
72- let _ = this.update(cx, |yumush, cx| {73+ let _ = this.update_in(cx, |yumush, window, cx| {
73- yumush.chat.insert_community(community);74+ let id = community.id;
75+ let known = yumush
76+ .chat
77+ .session
78+ .communities
79+ .iter_mut()
80+ .chain(yumush.chat.session.opened.as_mut())
81+ .find(|known| known.id == id);
82+ if let Some(known) = known {
83+ *known = community;
84+ }
85+ if yumush.on_builder_tab(BuilderTab::Communities)
86+ || yumush.on_builder_tab(BuilderTab::Voice)
87+ {
88+ yumush.load_builder_communities(window, cx);
89+ }
74 yumush.request_social_avatars(cx);90 yumush.request_social_avatars(cx);
75 cx.notify();91 cx.notify();
76 });92 });
@@ -83,7 +99,7 @@ impl Yumush {
83 pub(super) fn community_settings_page(99 pub(super) fn community_settings_page(
84 &self,100 &self,
85 entity: &Entity<Self>,101 entity: &Entity<Self>,
86- palette: Palette,102+ t: Tokens,
87 cx: &App,103 cx: &App,
88 ) -> impl IntoElement {104 ) -> impl IntoElement {
89 let community = self.chat.selected_community();105 let community = self.chat.selected_community();
@@ -91,40 +107,40 @@ impl Yumush {
91 .map(|community| community.name.clone())107 .map(|community| community.name.clone())
92 .unwrap_or_default();108 .unwrap_or_default();
93 let actor = self.actor_rank();109 let actor = self.actor_rank();
94- let bans_count = self.chat.bans.len();110+ let bans_count = self.chat.session.bans.len();
95 let mut sections = Vec::new();111 let mut sections = Vec::new();
96 112
97- if let Some(community) = community.filter(|_| permission::can_rename_community(actor)) {113+ if permission::is_admin(actor) {
98- sections.push(Section::new(114+ if let Some(community) = community {
99- "profile",115+ sections.push(Section::new(
100- w().community_settings.profile,116+ "profile",
101- picture_card(117+ w().community_settings.profile,
102- Picture {118+ picture_card(
103- id: "community_picture_picker",119+ Picture {
104- image: community_icon(120+ id: "community_picture_picker",
105- palette,121+ image: community_icon(
106- community,122+ t,
107- px(size::AVATAR_LG),123+ community,
108- text(text_token::TITLE),124+ px(size::AVATAR_LG),
109- &self.chat.avatars,125+ text(text_token::TITLE),
110- ),126+ &self.chat.session.avatars,
111- title: community.name.clone(),127+ ),
112- subtitle: String::new(),128+ title: community.name.clone(),
113- removable: community.avatar_id.is_some(),129+ subtitle: String::new(),
114- upload: Yumush::upload_community_picture,130+ removable: community.avatar_id.is_some(),
115- remove: Yumush::remove_community_picture,131+ upload: Yumush::upload_community_picture,
116- },132+ remove: Yumush::remove_community_picture,
117- entity,133+ },
118- palette,134+ entity,
119- )135+ t,
120- .into_any_element(),136+ )
121- ));137+ .into_any_element(),
122- }138+ ));
123- if permission::can_rename_community(actor) {139+ }
124 sections.push(section(140 sections.push(section(
125 "general",141 "general",
126 w().community_settings.general,142 w().community_settings.general,
127- palette,143+ t,
128 vec![text_row(144 vec![text_row(
129 Editable {145 Editable {
130 id: "save_community_name_button",146 id: "save_community_name_button",
@@ -135,24 +151,24 @@ impl Yumush {
135 emoji: None,151 emoji: None,
136 },152 },
137 entity,153 entity,
138- palette,154+ t,
139 cx,155 cx,
140 )],156 )],
141 ));157 ));
142 }158 }
143- if let Some(community) = community.filter(|_| permission::can_manage_voice(actor)) {159+ if let Some(community) = community.filter(|_| permission::is_owner(actor)) {
144 sections.push(section(160 sections.push(section(
145 "voice",161 "voice",
146 w().community_settings.voice,162 w().community_settings.voice,
147- palette,163+ t,
148 vec![row(164 vec![row(
149 w().community_settings.voice,165 w().community_settings.voice,
150- voice_control(entity, community.id, community.voice_enabled, palette),166+ voice_control(entity, community.id, community.voice_enabled, t),
151 )],167 )],
152 ));168 ));
153 }169 }
154 let mut moderation = Vec::new();170 let mut moderation = Vec::new();
155- if permission::can_unban(actor) {171+ if permission::is_moderator(actor) {
156 moderation.push(row(172 moderation.push(row(
157 w().community_settings.bans,173 w().community_settings.bans,
158 div()174 div()
@@ -162,32 +178,32 @@ impl Yumush {
162 .child(178 .child(
163 div()179 div()
164 .text_size(text(text_token::CAPTION))180 .text_size(text(text_token::CAPTION))
165- .text_color(palette.muted)181+ .text_color(t.dim())
166 .child(bans_count.to_string()),182 .child(bans_count.to_string()),
167 )183 )
168 .child(view_control(184 .child(view_control(
169 "view_bans_button",185 "view_bans_button",
170 entity,186 entity,
171- palette,187+ t,
172 Yumush::open_bans,188 Yumush::open_bans,
173 )),189 )),
174 ));190 ));
175 }191 }
176- if permission::can_read_logs(actor) {192+ if permission::is_moderator(actor) {
177 moderation.push(row(193 moderation.push(row(
178 w().community_settings.logs,194 w().community_settings.logs,
179- view_control("view_logs_button", entity, palette, Yumush::open_logs),195+ view_control("view_logs_button", entity, t, Yumush::open_logs),
180 ));196 ));
181 }197 }
182 if !moderation.is_empty() {198 if !moderation.is_empty() {
183 sections.push(section(199 sections.push(section(
184 "moderation",200 "moderation",
185 w().community_settings.moderation,201 w().community_settings.moderation,
186- palette,202+ t,
187 moderation,203 moderation,
188 ));204 ));
189 }205 }
190- if permission::can_delete_community(actor) {206+ if permission::is_owner(actor) {
191 sections.push(danger(207 sections.push(danger(
192 "danger_zone",208 "danger_zone",
193 vec![209 vec![
@@ -196,7 +212,7 @@ impl Yumush {
196 w().community_settings.delete_community,212 w().community_settings.delete_community,
197 self.armed(Armed::DeleteCommunity),213 self.armed(Armed::DeleteCommunity),
198 entity,214 entity,
199- palette,215+ t,
200 Yumush::delete_community,216 Yumush::delete_community,
201 )217 )
202 .into_any_element(),218 .into_any_element(),
@@ -207,7 +223,7 @@ impl Yumush {
207 sections.push(section(223 sections.push(section(
208 "general",224 "general",
209 w().community_settings.general,225 w().community_settings.general,
210- palette,226+ t,
211 Vec::new(),227 Vec::new(),
212 ));228 ));
213 }229 }
@@ -215,14 +231,14 @@ impl Yumush {
215 page(231 page(
216 "community_settings_scroll",232 "community_settings_scroll",
217 entity,233 entity,
218- palette,234+ t,
219 name,235 name,
220 sections,236 sections,
221- self.chat.section,237+ self.chat.session.section,
222 )238 )
223 }239 }
224 240
225- fn set_community_voice(241+ pub(super) fn set_community_voice(
226 &mut self,242 &mut self,
227 community_id: Id,243 community_id: Id,
228 enabled: bool,244 enabled: bool,
@@ -244,7 +260,7 @@ impl Yumush {
244 }260 }
245 261
246 pub(super) fn save_community_name(&mut self, window: &mut Window, cx: &mut Context<Self>) {262 pub(super) fn save_community_name(&mut self, window: &mut Window, cx: &mut Context<Self>) {
247- let Some(community_id) = self.chat.selected_community_id else {263+ let Some(community_id) = self.chat.session.selected_community_id else {
248 return;264 return;
249 };265 };
250 let name = self266 let name = self
@@ -271,7 +287,7 @@ impl Yumush {
271 }287 }
272 288
273 fn upload_community_picture(&mut self, window: &mut Window, cx: &mut Context<Self>) {289 fn upload_community_picture(&mut self, window: &mut Window, cx: &mut Context<Self>) {
274- let Some(community_id) = self.chat.selected_community_id else {290+ let Some(community_id) = self.chat.session.selected_community_id else {
275 return;291 return;
276 };292 };
277 let picked = picked_avatar(cx, self.max_avatar_bytes());293 let picked = picked_avatar(cx, self.max_avatar_bytes());
@@ -298,7 +314,7 @@ impl Yumush {
298 }314 }
299 315
300 fn remove_community_picture(&mut self, window: &mut Window, cx: &mut Context<Self>) {316 fn remove_community_picture(&mut self, window: &mut Window, cx: &mut Context<Self>) {
301- let Some(community_id) = self.chat.selected_community_id else {317+ let Some(community_id) = self.chat.session.selected_community_id else {
302 return;318 return;
303 };319 };
304 let network = self.network.clone();320 let network = self.network.clone();
@@ -319,7 +335,7 @@ impl Yumush {
319 if !self.arm(Armed::DeleteCommunity, cx) {335 if !self.arm(Armed::DeleteCommunity, cx) {
320 return;336 return;
321 }337 }
322- let Some(community_id) = self.chat.selected_community_id else {338+ let Some(community_id) = self.chat.session.selected_community_id else {
323 return;339 return;
324 };340 };
325 let network = self.network.clone();341 let network = self.network.clone();
@@ -329,7 +345,7 @@ impl Yumush {
329 match network.call(call).await {345 match network.call(call).await {
330 Ok(()) => {346 Ok(()) => {
331 let _ = this.update_in(cx, |yumush, window, cx| {347 let _ = this.update_in(cx, |yumush, window, cx| {
332- yumush.chat.remove_community(community_id);348+ yumush.forget_community(community_id, cx);
333 yumush.show_view(View::Chat, window, cx);349 yumush.show_view(View::Chat, window, cx);
334 });350 });
335 }351 }
@@ -340,7 +356,7 @@ impl Yumush {
340 }356 }
341 357
342 pub(super) fn unban(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {358 pub(super) fn unban(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {
343- let Some(community_id) = self.chat.selected_community_id else {359+ let Some(community_id) = self.chat.session.selected_community_id else {
344 return;360 return;
345 };361 };
346 let network = self.network.clone();362 let network = self.network.clone();
@@ -353,7 +369,11 @@ impl Yumush {
353 match network.call(call).await {369 match network.call(call).await {
354 Ok(()) => {370 Ok(()) => {
355 let _ = this.update_in(cx, |yumush, window, cx| {371 let _ = this.update_in(cx, |yumush, window, cx| {
356- yumush.chat.bans.retain(|ban| ban.user.id != user_id);372+ yumush
373+ .chat
374+ .session
375+ .bans
376+ .retain(|ban| ban.user.id != user_id);
357 window.refresh();377 window.refresh();
358 cx.notify();378 cx.notify();
359 });379 });
@@ -368,12 +388,15 @@ impl Yumush {
368 let entity = cx.entity();388 let entity = cx.entity();
369 window.open_dialog(cx, move |dialog, _, cx| {389 window.open_dialog(cx, move |dialog, _, cx| {
370 let yumush = entity.read(cx);390 let yumush = entity.read(cx);
371- let palette = super::palette(cx);391+ let t = Tokens::of(cx);
372 let query = search_text(&yumush.chat.ban_search, cx);392 let query = search_text(&yumush.chat.ban_search, cx);
373- let rows: Vec<AnyElement> = ban_list(&yumush.chat.bans, &query, yumush.chat.ban_sort)393+ let rows: Vec<AnyElement> =
374- .into_iter()394+ ban_list(&yumush.chat.session.bans, &query, yumush.chat.ban_sort)
375- .map(|ban| ban_row(ban, &entity, palette, &yumush.chat.avatars).into_any_element())395+ .into_iter()
376- .collect();396+ .map(|ban| {
397+ ban_row(ban, &entity, t, &yumush.chat.session.avatars).into_any_element()
398+ })
399+ .collect();
377 400
378 dialog401 dialog
379 .title(w().community_settings.bans)402 .title(w().community_settings.bans)
@@ -384,18 +407,18 @@ impl Yumush {
384 ban_sorts(),407 ban_sorts(),
385 yumush.chat.ban_sort,408 yumush.chat.ban_sort,
386 &entity,409 &entity,
387- palette,410+ t,
388 Yumush::set_ban_sort,411 Yumush::set_ban_sort,
389 ),412 ),
390 rows,413 rows,
391 w().common.no_bans,414 w().common.no_bans,
392- palette,415+ t,
393 ))416 ))
394 });417 });
395 }418 }
396 419
397 fn open_logs(&mut self, window: &mut Window, cx: &mut Context<Self>) {420 fn open_logs(&mut self, window: &mut Window, cx: &mut Context<Self>) {
398- let Some(community_id) = self.chat.selected_community_id else {421+ let Some(community_id) = self.chat.session.selected_community_id else {
399 return;422 return;
400 };423 };
401 self.show_logs(community_id, window, cx);424 self.show_logs(community_id, window, cx);
@@ -407,16 +430,18 @@ impl Yumush {
407 window: &mut Window,430 window: &mut Window,
408 cx: &mut Context<Self>,431 cx: &mut Context<Self>,
409 ) {432 ) {
433+ self.chat.session.logs.clear();
410 self.load_logs(community_id, window, cx);434 self.load_logs(community_id, window, cx);
411 let entity = cx.entity();435 let entity = cx.entity();
412 window.open_dialog(cx, move |dialog, _, cx| {436 window.open_dialog(cx, move |dialog, _, cx| {
413 let yumush = entity.read(cx);437 let yumush = entity.read(cx);
414- let palette = super::palette(cx);438+ let t = Tokens::of(cx);
415 let query = search_text(&yumush.chat.log_search, cx);439 let query = search_text(&yumush.chat.log_search, cx);
416- let rows: Vec<AnyElement> = log_list(&yumush.chat.logs, &query, yumush.chat.log_sort)440+ let rows: Vec<AnyElement> =
417- .into_iter()441+ log_list(&yumush.chat.session.logs, &query, yumush.chat.log_sort)
418- .map(|entry| log_row(entry, palette, &yumush.chat.avatars).into_any_element())442+ .into_iter()
419- .collect();443+ .map(|entry| log_row(entry, t, &yumush.chat.session.avatars).into_any_element())
444+ .collect();
420 445
421 dialog446 dialog
422 .title(w().community_settings.logs)447 .title(w().community_settings.logs)
@@ -427,12 +452,12 @@ impl Yumush {
427 log_sorts(),452 log_sorts(),
428 yumush.chat.log_sort,453 yumush.chat.log_sort,
429 &entity,454 &entity,
430- palette,455+ t,
431 Yumush::set_log_sort,456 Yumush::set_log_sort,
432 ),457 ),
433 rows,458 rows,
434 w().community_settings.no_logs,459 w().community_settings.no_logs,
435- palette,460+ t,
436 ))461 ))
437 });462 });
438 }463 }
@@ -470,7 +495,7 @@ impl Yumush {
470 yumush.request_user_avatar(target, cx);495 yumush.request_user_avatar(target, cx);
471 }496 }
472 }497 }
473- yumush.chat.logs = logs;498+ yumush.chat.session.logs = logs;
474 window.refresh();499 window.refresh();
475 cx.notify();500 cx.notify();
476 });501 });
@@ -483,20 +508,15 @@ fn voice_control(
483 entity: &Entity<Yumush>,508 entity: &Entity<Yumush>,
484 community_id: Id,509 community_id: Id,
485 enabled: bool,510 enabled: bool,
486- palette: Palette,511+ t: Tokens,
487 ) -> impl IntoElement {512 ) -> impl IntoElement {
488 let entity = entity.clone();513 let entity = entity.clone();
489 514
490- small_button(515+ small_button("community_voice_button", t, t.paper(), move |window, cx| {
491- "community_voice_button",516+ entity.update(cx, |yumush, cx| {
492- palette,517+ yumush.set_community_voice(community_id, !enabled, window, cx)
493- palette.text,518+ });
494- move |window, cx| {519+ })
495- entity.update(cx, |yumush, cx| {
496- yumush.set_community_voice(community_id, !enabled, window, cx)
497- });
498- },
499- )
500 .child(if enabled {520 .child(if enabled {
501 w().community_settings.on521 w().community_settings.on
502 } else {522 } else {
@@ -507,18 +527,17 @@ fn voice_control(
507 fn view_control(527 fn view_control(
508 id: &'static str,528 id: &'static str,
509 entity: &Entity<Yumush>,529 entity: &Entity<Yumush>,
510- palette: Palette,530+ t: Tokens,
511 open: fn(&mut Yumush, &mut Window, &mut Context<Yumush>),531 open: fn(&mut Yumush, &mut Window, &mut Context<Yumush>),
512 ) -> impl IntoElement {532 ) -> impl IntoElement {
513- small_button(id, palette, palette.text, entity_action(entity, open))533+ small_button(id, t, t.paper(), entity_action(entity, open)).child(w().community_settings.view)
514- .child(w().community_settings.view)
515 }534 }
516 535
517 fn sort_control<T: Copy + PartialEq + 'static, const N: usize>(536 fn sort_control<T: Copy + PartialEq + 'static, const N: usize>(
518 options: [(T, &'static str, &'static str); N],537 options: [(T, &'static str, &'static str); N],
519 selected: T,538 selected: T,
520 entity: &Entity<Yumush>,539 entity: &Entity<Yumush>,
521- palette: Palette,540+ t: Tokens,
522 select: fn(&mut Yumush, T, &mut Window, &mut Context<Yumush>),541 select: fn(&mut Yumush, T, &mut Window, &mut Context<Yumush>),
523 ) -> impl IntoElement {542 ) -> impl IntoElement {
524 div()543 div()
@@ -531,7 +550,7 @@ fn sort_control<T: Copy + PartialEq + 'static, const N: usize>(
531 550
532 clickable(551 clickable(
533 id,552 id,
534- palette,553+ t,
535 entity_action(entity, move |yumush, window, cx| {554 entity_action(entity, move |yumush, window, cx| {
536 select(yumush, choice, window, cx)555 select(yumush, choice, window, cx)
537 }),556 }),
@@ -541,10 +560,10 @@ fn sort_control<T: Copy + PartialEq + 'static, const N: usize>(
541 .items_center()560 .items_center()
542 .rounded(px(radius::SM))561 .rounded(px(radius::SM))
543 .text_size(text(text_token::CAPTION))562 .text_size(text(text_token::CAPTION))
544- .text_color(if active { palette.text } else { palette.muted })563+ .text_color(if active { t.paper() } else { t.dim() })
545 .border_b(px(super::style::stroke::LINE))564 .border_b(px(super::style::stroke::LINE))
546 .border_color(if active {565 .border_color(if active {
547- palette.tokens.paper()566+ t.paper()
548 } else {567 } else {
549 gpui_kit::transparent_black()568 gpui_kit::transparent_black()
550 })569 })
@@ -558,10 +577,10 @@ fn moderation_body(
558 sort: impl IntoElement,577 sort: impl IntoElement,
559 rows: Vec<AnyElement>,578 rows: Vec<AnyElement>,
560 empty: &'static str,579 empty: &'static str,
561- palette: Palette,580+ t: Tokens,
562 ) -> impl IntoElement {581 ) -> impl IntoElement {
563 let list = if rows.is_empty() {582 let list = if rows.is_empty() {
564- crate::gui::parts::empty(empty, palette.tokens).into_any_element()583+ crate::gui::parts::empty(empty, t).into_any_element()
565 } else {584 } else {
566 div().flex().flex_col().children(rows).into_any_element()585 div().flex().flex_col().children(rows).into_any_element()
567 };586 };
@@ -570,7 +589,7 @@ fn moderation_body(
570 .flex()589 .flex()
571 .flex_col()590 .flex_col()
572 .gap(px(space::MD))591 .gap(px(space::MD))
573- .child(super::sidebar::input_box(search, palette))592+ .child(super::sidebar::input_box(search, t))
574 .child(sort)593 .child(sort)
575 .child(594 .child(
576 div()595 div()
@@ -648,7 +667,7 @@ pub(super) fn community_log_text(actor: &str, target: &str, action: &LogAction)
648 }667 }
649 }668 }
650 669
651-fn log_row(entry: &LogEntry, palette: Palette, avatars: &HashMap<Id, Arc<Image>>) -> Div {670+fn log_row(entry: &LogEntry, t: Tokens, avatars: &HashMap<Id, Arc<Image>>) -> Div {
652 div()671 div()
653 .min_h(px(size::ROW))672 .min_h(px(size::ROW))
654 .px(px(space::MD))673 .px(px(space::MD))
@@ -657,7 +676,7 @@ fn log_row(entry: &LogEntry, palette: Palette, avatars: &HashMap<Id, Arc<Image>>
657 .gap(px(space::SM))676 .gap(px(space::SM))
658 .children(entry.actor.as_ref().map(|actor| {677 .children(entry.actor.as_ref().map(|actor| {
659 avatar(678 avatar(
660- palette,679+ t,
661 actor,680 actor,
662 px(size::AVATAR),681 px(size::AVATAR),
663 text(text_token::CAPTION),682 text(text_token::CAPTION),
@@ -669,7 +688,7 @@ fn log_row(entry: &LogEntry, palette: Palette, avatars: &HashMap<Id, Arc<Image>>
669 div()688 div()
670 .flex_shrink_0()689 .flex_shrink_0()
671 .text_size(text(text_token::CAPTION))690 .text_size(text(text_token::CAPTION))
672- .text_color(palette.muted)691+ .text_color(t.dim())
673 .child(millis_time(entry.created_at, crate::lang::w().common.stamp)),692 .child(millis_time(entry.created_at, crate::lang::w().common.stamp)),
674 )693 )
675 }694 }
@@ -677,7 +696,7 @@ fn log_row(entry: &LogEntry, palette: Palette, avatars: &HashMap<Id, Arc<Image>>
677 fn ban_row(696 fn ban_row(
678 ban: &Ban,697 ban: &Ban,
679 entity: &Entity<Yumush>,698 entity: &Entity<Yumush>,
680- palette: Palette,699+ t: Tokens,
681 avatars: &HashMap<Id, Arc<Image>>,700 avatars: &HashMap<Id, Arc<Image>>,
682 ) -> Div {701 ) -> Div {
683 let entity = entity.clone();702 let entity = entity.clone();
@@ -695,7 +714,7 @@ fn ban_row(
695 Some(user),714 Some(user),
696 &entity,715 &entity,
697 avatar(716 avatar(
698- palette,717+ t,
699 user,718 user,
700 px(size::AVATAR),719 px(size::AVATAR),
701 text(text_token::CAPTION),720 text(text_token::CAPTION),
@@ -717,7 +736,7 @@ fn ban_row(
717 .children(ban.reason.clone().map(|reason| {736 .children(ban.reason.clone().map(|reason| {
718 div()737 div()
719 .text_size(text(text_token::CAPTION))738 .text_size(text(text_token::CAPTION))
720- .text_color(palette.muted)739+ .text_color(t.dim())
721 .min_w_0()740 .min_w_0()
722 .child(super::glyph::line(741 .child(super::glyph::line(
723 reason.into(),742 reason.into(),
@@ -726,7 +745,7 @@ fn ban_row(
726 })),745 })),
727 )746 )
728 .child(747 .child(
729- clickable(format!("unban_{}", user.id), palette, move |window, cx| {748+ clickable(format!("unban_{}", user.id), t, move |window, cx| {
730 entity.update(cx, |yumush, cx| yumush.unban(user_id, window, cx));749 entity.update(cx, |yumush, cx| yumush.unban(user_id, window, cx));
731 })750 })
732 .h(px(size::CONTROL_SM))751 .h(px(size::CONTROL_SM))
@@ -734,7 +753,7 @@ fn ban_row(
734 .flex()753 .flex()
735 .items_center()754 .items_center()
736 .rounded(px(radius::MD))755 .rounded(px(radius::MD))
737- .text_color(palette.danger)756+ .text_color(t.bad())
738 .child(w().community_settings.unban),757 .child(w().community_settings.unban),
739 )758 )
740 }759 }
crates/client/src/gui/composer.rsmodified+337 -308
@@ -1,11 +1,12 @@
1 use super::parts::{Scale, Tone, icon_button};1 use super::parts::{Scale, Tone, icon_button};
2-use super::style::{radius, size, space, stroke, text};2+use super::style::{Tokens, radius, size, space, stroke, text};
3 use super::text;3 use super::text;
4-use super::widget::{compact_field, panel, spawn_done};4+use super::widget::{compact_field, spawn_done};
5 use crate::gui::glyph::Fill as _;5 use crate::gui::glyph::Fill as _;
6 use common::model::Id;6 use common::model::Id;
7 use std::time::{Duration, Instant};7 use std::time::{Duration, Instant};
8 8
9+use super::keys;
9 use crate::lang::w;10 use crate::lang::w;
10 use crate::net::Fail;11 use crate::net::Fail;
11 use common::{12 use common::{
@@ -17,15 +18,15 @@ use common::{
17 validate::{validate_new_message, validate_poll},18 validate::{validate_new_message, validate_poll},
18 };19 };
19 use gpui_kit::{20 use gpui_kit::{
20- Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight, InteractiveElement,21+ Action, Anchor, AnyElement, App, Context, Div, ElementId, Entity, FontWeight,
21- IntoElement, KeyBinding, MouseButton, ParentElement, StatefulInteractiveElement as _, Styled,22+ InteractiveElement, IntoElement, KeyBinding, MouseButton, ParentElement,
22- Window, actions,23+ StatefulInteractiveElement as _, Styled, Window, actions,
23 assets::IconName,24 assets::IconName,
24 component::{25 component::{
25 WindowExt,26 WindowExt,
26 input::{InputEvent, InputState, TextareaState},27 input::{InputEvent, InputState, TextareaState},
27 notification::Notification,28 notification::Notification,
28- popover::Popover,29+ popover::{Popover, PopoverState},
29 text::TextView,30 text::TextView,
30 },31 },
31 div,32 div,
@@ -34,7 +35,7 @@ use gpui_kit::{
34 };35 };
35 36
36 use super::{37 use super::{
37- Palette, Trigger, Yumush,38+ Trigger, Yumush,
38 chat::{Chat, TYPING_SEND_INTERVAL},39 chat::{Chat, TYPING_SEND_INTERVAL},
39 clickable, hoverable, new_input, notify_error, parts,40 clickable, hoverable, new_input, notify_error, parts,
40 };41 };
@@ -43,12 +44,6 @@ actions!(composer, [Bold, Italic, Code, Strike]);
43 44
44 const CONTEXT: &str = "MessageComposer";45 const CONTEXT: &str = "MessageComposer";
45 46
46-const MOD: &str = if cfg!(target_os = "macos") {
47- "Cmd"
48-} else {
49- "Ctrl"
50-};
51-
52 const FORMAT_ROWS: [(&str, &str); 6] = [47 const FORMAT_ROWS: [(&str, &str); 6] = [
53 ("**bold**", "B"),48 ("**bold**", "B"),
54 ("*italic*", "I"),49 ("*italic*", "I"),
@@ -58,38 +53,30 @@ const FORMAT_ROWS: [(&str, &str); 6] = [
58 ("- list", ""),53 ("- list", ""),
59 ];54 ];
60 55
61-fn shortcut_label(keys: &str) -> String {
62- if keys.is_empty() {
63- String::new()
64- } else {
65- format!("{MOD}+{keys}")
66- }
67-}
68-
69 #[derive(Debug, Clone, PartialEq, Eq)]56 #[derive(Debug, Clone, PartialEq, Eq)]
70 pub enum Composer {57 pub enum Composer {
71 Compose { reply: Option<Id> },58 Compose { reply: Option<Id> },
72- Edit { message_id: Id },59+ Edit { message_id: Id, stash: String },
73 Select { ids: Vec<Id> },60 Select { ids: Vec<Id> },
74 }61 }
75 62
76 const SLOW_TICK: Duration = Duration::from_secs(1);63 const SLOW_TICK: Duration = Duration::from_secs(1);
77 64
78-pub fn mode_bar(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> Option<AnyElement> {65+pub fn mode_bar(chat: &Chat, entity: &Entity<Yumush>, t: Tokens) -> Option<AnyElement> {
79 if let Some(seconds) = chat.slow_seconds() {66 if let Some(seconds) = chat.slow_seconds() {
80- return Some(slow_bar(seconds, palette).into_any_element());67+ return Some(slow_bar(seconds, t).into_any_element());
81 }68 }
82 69
83 match &chat.composer {70 match &chat.composer {
84 Composer::Compose {71 Composer::Compose {
85 reply: Some(message_id),72 reply: Some(message_id),
86- } => Some(reply_bar(chat, *message_id, entity, palette).into_any_element()),73+ } => Some(reply_bar(chat, *message_id, entity, t).into_any_element()),
87- Composer::Edit { .. } => Some(edit_bar(entity, palette).into_any_element()),74+ Composer::Edit { .. } => Some(edit_bar(entity, t).into_any_element()),
88 Composer::Compose { reply: None } | Composer::Select { .. } => None,75 Composer::Compose { reply: None } | Composer::Select { .. } => None,
89 }76 }
90 }77 }
91 78
92-pub fn selection_bar(ids: &[Id], entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {79+pub fn selection_bar(ids: &[Id], entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
93 let count = ids.len();80 let count = ids.len();
94 let selected = ids.to_vec();81 let selected = ids.to_vec();
95 let forward_entity = entity.clone();82 let forward_entity = entity.clone();
@@ -103,23 +90,23 @@ pub fn selection_bar(ids: &[Id], entity: &Entity<Yumush>, palette: Palette) -> i
103 .gap(px(space::SM))90 .gap(px(space::SM))
104 .rounded(px(radius::MD))91 .rounded(px(radius::MD))
105 .border_1()92 .border_1()
106- .border_color(palette.border)93+ .border_color(t.thread())
107- .bg(palette.field)94+ .bg(t.raise())
108 .child(div().flex_1().child(w().composer.selected(count)))95 .child(div().flex_1().child(w().composer.selected(count)))
109 .child(parts::button(96 .child(parts::button(
110 "forward_selected",97 "forward_selected",
111 w().composer.forward,98 w().composer.forward,
112 parts::Press::Primary,99 parts::Press::Primary,
113- palette.tokens,100+ t,
114 move |window, cx| {101 move |window, cx| {
115 let selected = selected.clone();102 let selected = selected.clone();
116 forward_entity.update(cx, |yumush, cx| yumush.open_forward(selected, window, cx));103 forward_entity.update(cx, |yumush, cx| yumush.open_forward(selected, window, cx));
117 },104 },
118 ))105 ))
119- .child(cancel_button(entity, palette))106+ .child(cancel_button(entity, t))
120 }107 }
121 108
122-fn bar(palette: Palette) -> Div {109+fn bar(t: Tokens) -> Div {
123 div()110 div()
124 .h(px(size::CONTROL_SM))111 .h(px(size::CONTROL_SM))
125 .mb(px(space::SM))112 .mb(px(space::SM))
@@ -128,18 +115,14 @@ fn bar(palette: Palette) -> Div {
128 .items_center()115 .items_center()
129 .gap(px(space::SM))116 .gap(px(space::SM))
130 .border_l(px(stroke::LINE))117 .border_l(px(stroke::LINE))
131- .border_color(palette.border)118+ .border_color(t.thread())
132 .text_size(text(text::CAPTION))119 .text_size(text(text::CAPTION))
133- .text_color(palette.muted)120+ .text_color(t.dim())
134 }121 }
135 122
136-fn reply_bar(123+fn reply_bar(chat: &Chat, message_id: Id, entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
137- chat: &Chat,
138- message_id: Id,
139- entity: &Entity<Yumush>,
140- palette: Palette,
141-) -> impl IntoElement {
142 let message = chat124 let message = chat
125+ .session
143 .messages126 .messages
144 .iter()127 .iter()
145 .find(|message| message.id == message_id);128 .find(|message| message.id == message_id);
@@ -153,7 +136,7 @@ fn reply_bar(
153 136
154 let jump = entity.clone();137 let jump = entity.clone();
155 138
156- bar(palette)139+ bar(t)
157 .child(140 .child(
158 div()141 div()
159 .id("reply_jump")142 .id("reply_jump")
@@ -172,30 +155,30 @@ fn reply_bar(
172 .child(155 .child(
173 div()156 div()
174 .font_weight(FontWeight::SEMIBOLD)157 .font_weight(FontWeight::SEMIBOLD)
175- .text_color(palette.text)158+ .text_color(t.paper())
176 .child(author),159 .child(author),
177 )160 )
178 .child(div().flex_1().min_w_0().truncate().child(quote)),161 .child(div().flex_1().min_w_0().truncate().child(quote)),
179 )162 )
180- .child(cancel_button(entity, palette))163+ .child(cancel_button(entity, t))
181 }164 }
182 165
183-fn slow_bar(seconds: u64, palette: Palette) -> impl IntoElement {166+fn slow_bar(seconds: u64, t: Tokens) -> impl IntoElement {
184- bar(palette)167+ bar(t)
185- .text_color(palette.danger)168+ .text_color(t.bad())
186 .child(super::parts::small_icon(IconName::Hourglass))169 .child(super::parts::small_icon(IconName::Hourglass))
187 .child(w().composer.slow_down(seconds))170 .child(w().composer.slow_down(seconds))
188 }171 }
189 172
190-fn edit_bar(entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {173+fn edit_bar(entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
191- bar(palette)174+ bar(t)
192 .child(super::parts::small_icon(IconName::Pencil))175 .child(super::parts::small_icon(IconName::Pencil))
193 .child(w().composer.editing)176 .child(w().composer.editing)
194 .child(div().flex_1())177 .child(div().flex_1())
195- .child(cancel_button(entity, palette))178+ .child(cancel_button(entity, t))
196 }179 }
197 180
198-fn cancel_button(entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {181+fn cancel_button(entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
199 let entity = entity.clone();182 let entity = entity.clone();
200 183
201 icon_button(184 icon_button(
@@ -204,7 +187,7 @@ fn cancel_button(entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement
204 w().composer.cancel,187 w().composer.cancel,
205 Tone::Idle,188 Tone::Idle,
206 Scale::Small,189 Scale::Small,
207- palette.tokens,190+ t,
208 move |window, cx| {191 move |window, cx| {
209 entity.update(cx, |yumush, cx| yumush.cancel_composer(window, cx));192 entity.update(cx, |yumush, cx| yumush.cancel_composer(window, cx));
210 },193 },
@@ -218,7 +201,7 @@ impl Yumush {
218 window: &mut Window,201 window: &mut Window,
219 cx: &mut Context<Self>,202 cx: &mut Context<Self>,
220 ) {203 ) {
221- if self.chat.media.uploading() {204+ if self.chat.session.media.uploading() {
222 return;205 return;
223 }206 }
224 let body = input207 let body = input
@@ -231,33 +214,31 @@ impl Yumush {
231 214
232 match self.chat.composer.clone() {215 match self.chat.composer.clone() {
233 Composer::Compose { reply } => self.create_message(reply, body, input, window, cx),216 Composer::Compose { reply } => self.create_message(reply, body, input, window, cx),
234- Composer::Edit { message_id } => {217+ Composer::Edit { message_id, stash } => {
235- self.update_message(message_id, body, input, window, cx)218+ self.update_message(message_id, body, stash, input, window, cx)
236 }219 }
237 Composer::Select { .. } => {}220 Composer::Select { .. } => {}
238 }221 }
239 }222 }
240 223
241 pub(super) fn send_typing(&mut self, cx: &mut Context<Self>) {224 pub(super) fn send_typing(&mut self, cx: &mut Context<Self>) {
242- let Some(community_id) = self.chat.selected_community_id else {225+ let Some(community_id) = self.chat.session.selected_community_id else {
243 return;226 return;
244 };227 };
245- if self228+ if self.chat.message_input.read(cx).text().len() == 0
246- .chat
247- .message_input
248- .read(cx)
249- .text()
250- .to_string()
251- .is_empty()
252 || self229 || self
253 .chat230 .chat
231+ .session
254 .typing_sent232 .typing_sent
255 .get(&community_id)233 .get(&community_id)
256 .is_some_and(|at| at.elapsed() < TYPING_SEND_INTERVAL)234 .is_some_and(|at| at.elapsed() < TYPING_SEND_INTERVAL)
257 {235 {
258 return;236 return;
259 }237 }
260- self.chat.typing_sent.insert(community_id, Instant::now());238+ self.chat
239+ .session
240+ .typing_sent
241+ .insert(community_id, Instant::now());
261 let network = self.network.clone();242 let network = self.network.clone();
262 cx.spawn(async move |_, _| {243 cx.spawn(async move |_, _| {
263 let _ = network.call(Typing { community_id }).await;244 let _ = network.call(Typing { community_id }).await;
@@ -275,6 +256,7 @@ impl Yumush {
275 ) {256 ) {
276 let attachments: Vec<Id> = self257 let attachments: Vec<Id> = self
277 .chat258 .chat
259+ .session
278 .media260 .media
279 .pending261 .pending
280 .iter()262 .iter()
@@ -289,15 +271,15 @@ impl Yumush {
289 window.push_notification(Notification::error(error.to_string()), cx);271 window.push_notification(Notification::error(error.to_string()), cx);
290 return;272 return;
291 }273 }
292- let Some(community_id) = self.chat.selected_community_id else {274+ let Some(community_id) = self.chat.session.selected_community_id else {
293 window.push_notification(Notification::error(w().composer.no_community), cx);275 window.push_notification(Notification::error(w().composer.no_community), cx);
294 return;276 return;
295 };277 };
296 let network = self.network.clone();278 let network = self.network.clone();
297 let restore = input.clone();279 let restore = input.clone();
298- let pending = self.chat.media.pending.clone();280+ let pending = self.chat.session.media.pending.clone();
299 let order = self.send_order.clone();281 let order = self.send_order.clone();
300- self.chat.drafts.remove(&community_id);282+ self.chat.session.drafts.remove(&community_id);
301 283
302 cx.spawn_in(window, async move |this, cx| {284 cx.spawn_in(window, async move |this, cx| {
303 let _turn = order.lock().await;285 let _turn = order.lock().await;
@@ -315,13 +297,29 @@ impl Yumush {
315 retry_after_seconds,297 retry_after_seconds,
316 })) => {298 })) => {
317 let _ = this.update_in(cx, |yumush, window, cx| {299 let _ = this.update_in(cx, |yumush, window, cx| {
318- yumush.restore_message(&restore, community_id, body, pending, window, cx);300+ yumush.restore_message(
301+ &restore,
302+ community_id,
303+ body,
304+ pending,
305+ reply,
306+ window,
307+ cx,
308+ );
319 yumush.slow_down(retry_after_seconds, window, cx)309 yumush.slow_down(retry_after_seconds, window, cx)
320 });310 });
321 }311 }
322 Err(error) => {312 Err(error) => {
323 let _ = this.update_in(cx, |yumush, window, cx| {313 let _ = this.update_in(cx, |yumush, window, cx| {
324- yumush.restore_message(&restore, community_id, body, pending, window, cx)314+ yumush.restore_message(
315+ &restore,
316+ community_id,
317+ body,
318+ pending,
319+ reply,
320+ window,
321+ cx,
322+ )
325 });323 });
326 notify_error(&this, cx, error);324 notify_error(&this, cx, error);
327 }325 }
@@ -330,7 +328,7 @@ impl Yumush {
330 .detach();328 .detach();
331 329
332 input.update(cx, |state, cx| state.set_value("", window, cx));330 input.update(cx, |state, cx| state.set_value("", window, cx));
333- self.chat.media.pending.clear();331+ self.chat.session.media.pending.clear();
334 self.chat.composer = Composer::Compose { reply: None };332 self.chat.composer = Composer::Compose { reply: None };
335 }333 }
336 334
@@ -340,24 +338,28 @@ impl Yumush {
340 community_id: Id,338 community_id: Id,
341 body: String,339 body: String,
342 pending: Vec<Attachment>,340 pending: Vec<Attachment>,
341+ reply: Option<Id>,
343 window: &mut Window,342 window: &mut Window,
344 cx: &mut Context<Self>,343 cx: &mut Context<Self>,
345 ) {344 ) {
346- if self.chat.selected_community_id != Some(community_id) {345+ if self.chat.session.selected_community_id != Some(community_id) {
347- self.chat.drafts.insert(community_id, body);346+ self.chat.session.drafts.insert(community_id, body);
348 return;347 return;
349 }348 }
350 if input.read(cx).text().len() == 0 {349 if input.read(cx).text().len() == 0 {
351 input.update(cx, |state, cx| state.fill(body, window, cx));350 input.update(cx, |state, cx| state.fill(body, window, cx));
352 }351 }
353- if self.chat.media.pending.is_empty() {352+ if self.chat.session.media.pending.is_empty() {
354- self.chat.media.pending = pending;353+ self.chat.session.media.pending = pending;
354+ }
355+ if self.chat.composer == (Composer::Compose { reply: None }) {
356+ self.chat.composer = Composer::Compose { reply };
355 }357 }
356 cx.notify();358 cx.notify();
357 }359 }
358 360
359 fn slow_down(&mut self, seconds: u64, window: &mut Window, cx: &mut Context<Self>) {361 fn slow_down(&mut self, seconds: u64, window: &mut Window, cx: &mut Context<Self>) {
360- self.chat.slowed_until = Some(now_ms() + seconds * 1000);362+ self.chat.session.slowed_until = Some(now_ms() + seconds * 1000);
361 363
362 cx.spawn_in(window, async move |this, cx| {364 cx.spawn_in(window, async move |this, cx| {
363 loop {365 loop {
@@ -378,6 +380,7 @@ impl Yumush {
378 &mut self,380 &mut self,
379 message_id: Id,381 message_id: Id,
380 body: String,382 body: String,
383+ stash: String,
381 input: &Entity<TextareaState>,384 input: &Entity<TextareaState>,
382 window: &mut Window,385 window: &mut Window,
383 cx: &mut Context<Self>,386 cx: &mut Context<Self>,
@@ -390,21 +393,30 @@ impl Yumush {
390 let restore = input.clone();393 let restore = input.clone();
391 394
392 cx.spawn_in(window, async move |this, cx| {395 cx.spawn_in(window, async move |this, cx| {
393- if let Err(error) = network396+ match network
394 .call(UpdateMessage {397 .call(UpdateMessage {
395 message_id,398 message_id,
396 body: body.clone(),399 body: body.clone(),
397 })400 })
398 .await401 .await
399 {402 {
400- let _ = this.update_in(cx, |yumush, window, cx| {403+ Ok(_) => {
401- if restore.read(cx).text().len() == 0 {404+ let _ = this.update_in(cx, |_, window, cx| {
402- restore.update(cx, |state, cx| state.fill(body, window, cx));405+ if restore.read(cx).text().len() == 0 {
403- yumush.chat.composer = Composer::Edit { message_id };406+ restore.update(cx, |state, cx| state.fill(stash, window, cx));
404- cx.notify();407+ }
405- }408+ });
406- });409+ }
407- notify_error(&this, cx, error);410+ Err(error) => {
411+ let _ = this.update_in(cx, |yumush, window, cx| {
412+ if restore.read(cx).text().len() == 0 {
413+ restore.update(cx, |state, cx| state.fill(body, window, cx));
414+ yumush.chat.composer = Composer::Edit { message_id, stash };
415+ cx.notify();
416+ }
417+ });
418+ notify_error(&this, cx, error);
419+ }
408 }420 }
409 })421 })
410 .detach();422 .detach();
@@ -415,14 +427,14 @@ impl Yumush {
415 }427 }
416 428
417 pub(super) fn save_draft(&mut self, cx: &mut Context<Self>) {429 pub(super) fn save_draft(&mut self, cx: &mut Context<Self>) {
418- let Some(community_id) = self.chat.selected_community_id else {430+ let Some(community_id) = self.chat.session.selected_community_id else {
419 return;431 return;
420 };432 };
421 let text = self.chat.message_input.read(cx).text().to_string();433 let text = self.chat.message_input.read(cx).text().to_string();
422 if text.is_empty() || !matches!(self.chat.composer, Composer::Compose { .. }) {434 if text.is_empty() || !matches!(self.chat.composer, Composer::Compose { .. }) {
423- self.chat.drafts.remove(&community_id);435+ self.chat.session.drafts.remove(&community_id);
424 } else {436 } else {
425- self.chat.drafts.insert(community_id, text);437+ self.chat.session.drafts.insert(community_id, text);
426 }438 }
427 }439 }
428 440
@@ -434,6 +446,7 @@ impl Yumush {
434 ) {446 ) {
435 let text = self447 let text = self
436 .chat448 .chat
449+ .session
437 .drafts450 .drafts
438 .get(&community_id)451 .get(&community_id)
439 .cloned()452 .cloned()
@@ -454,6 +467,7 @@ impl Yumush {
454 pub(super) fn edit(&mut self, message_id: Id, window: &mut Window, cx: &mut Context<Self>) {467 pub(super) fn edit(&mut self, message_id: Id, window: &mut Window, cx: &mut Context<Self>) {
455 let Some(body) = self468 let Some(body) = self
456 .chat469 .chat
470+ .session
457 .messages471 .messages
458 .iter()472 .iter()
459 .find(|message| message.id == message_id)473 .find(|message| message.id == message_id)
@@ -462,10 +476,16 @@ impl Yumush {
462 return;476 return;
463 };477 };
464 478
479+ let previous =
480+ std::mem::replace(&mut self.chat.composer, Composer::Compose { reply: None });
481+ let stash = match previous {
482+ Composer::Edit { stash, .. } => stash,
483+ _ => self.chat.message_input.read(cx).text().to_string(),
484+ };
465 self.chat485 self.chat
466 .message_input486 .message_input
467 .update(cx, |input, cx| input.fill(body, window, cx));487 .update(cx, |input, cx| input.fill(body, window, cx));
468- self.chat.composer = Composer::Edit { message_id };488+ self.chat.composer = Composer::Edit { message_id, stash };
469 self.chat.focus(window, cx);489 self.chat.focus(window, cx);
470 cx.notify();490 cx.notify();
471 }491 }
@@ -492,19 +512,21 @@ impl Yumush {
492 } else if ids.len() < MAXIMUM_FORWARD_MESSAGES {512 } else if ids.len() < MAXIMUM_FORWARD_MESSAGES {
493 ids.push(message_id);513 ids.push(message_id);
494 }514 }
515+ if ids.is_empty() {
516+ self.chat.composer = Composer::Compose { reply: None };
517+ }
495 cx.notify();518 cx.notify();
496 }519 }
497 520
498 pub(super) fn cancel_composer(&mut self, window: &mut Window, cx: &mut Context<Self>) {521 pub(super) fn cancel_composer(&mut self, window: &mut Window, cx: &mut Context<Self>) {
499- match self.chat.composer.clone() {522+ match std::mem::replace(&mut self.chat.composer, Composer::Compose { reply: None }) {
500 Composer::Compose { reply: None } => return,523 Composer::Compose { reply: None } => return,
501 Composer::Compose { reply: Some(_) } | Composer::Select { .. } => {}524 Composer::Compose { reply: Some(_) } | Composer::Select { .. } => {}
502- Composer::Edit { .. } => self525+ Composer::Edit { stash, .. } => self
503 .chat526 .chat
504 .message_input527 .message_input
505- .update(cx, |input, cx| input.set_value("", window, cx)),528+ .update(cx, |input, cx| input.fill(stash, window, cx)),
506 }529 }
507- self.chat.composer = Composer::Compose { reply: None };
508 self.chat.focus(window, cx);530 self.chat.focus(window, cx);
509 cx.notify();531 cx.notify();
510 }532 }
@@ -513,20 +535,27 @@ impl Yumush {
513 pub fn bind_keys(cx: &mut App) {535 pub fn bind_keys(cx: &mut App) {
514 let scope = format!("{CONTEXT} > Input");536 let scope = format!("{CONTEXT} > Input");
515 cx.bind_keys([537 cx.bind_keys([
516- KeyBinding::new("ctrl-b", Bold, Some(scope.as_str())),538+ KeyBinding::new(keys::bind!("b"), Bold, Some(scope.as_str())),
517- KeyBinding::new("ctrl-i", Italic, Some(scope.as_str())),539+ KeyBinding::new(keys::bind!("i"), Italic, Some(scope.as_str())),
518- KeyBinding::new("ctrl-e", Code, Some(scope.as_str())),540+ KeyBinding::new(keys::bind!("e"), Code, Some(scope.as_str())),
519- KeyBinding::new("ctrl-shift-x", Strike, Some(scope.as_str())),541+ KeyBinding::new(keys::bind!("shift-x"), Strike, Some(scope.as_str())),
520 ]);542 ]);
521 }543 }
522 544
523 pub fn format_actions(input: &Entity<TextareaState>, row: Div) -> Div {545 pub fn format_actions(input: &Entity<TextareaState>, row: Div) -> Div {
524- let (bold, italic, code, strike) = (input.clone(), input.clone(), input.clone(), input.clone());
525 row.key_context(CONTEXT)546 row.key_context(CONTEXT)
526- .on_action(move |_: &Bold, window, cx| wrap(&bold, "**", window, cx))547+ .on_action(mark_action::<Bold>(input, "**"))
527- .on_action(move |_: &Italic, window, cx| wrap(&italic, "*", window, cx))548+ .on_action(mark_action::<Italic>(input, "*"))
528- .on_action(move |_: &Code, window, cx| wrap(&code, "`", window, cx))549+ .on_action(mark_action::<Code>(input, "`"))
529- .on_action(move |_: &Strike, window, cx| wrap(&strike, "~~", window, cx))550+ .on_action(mark_action::<Strike>(input, "~~"))
551+}
552+
553+fn mark_action<A: Action>(
554+ input: &Entity<TextareaState>,
555+ mark: &'static str,
556+) -> impl Fn(&A, &mut Window, &mut App) + 'static {
557+ let input = input.clone();
558+ move |_: &A, window, cx| wrap(&input, mark, window, cx)
530 }559 }
531 560
532 fn wrap(input: &Entity<TextareaState>, mark: &str, window: &mut Window, cx: &mut App) {561 fn wrap(input: &Entity<TextareaState>, mark: &str, window: &mut Window, cx: &mut App) {
@@ -542,7 +571,7 @@ pub(super) fn trigger_icon(
542 id: impl Into<ElementId>,571 id: impl Into<ElementId>,
543 icon: IconName,572 icon: IconName,
544 size: f32,573 size: f32,
545- palette: Palette,574+ t: Tokens,
546 ) -> Trigger {575 ) -> Trigger {
547 Trigger::new(hoverable(576 Trigger::new(hoverable(
548 id,577 id,
@@ -552,14 +581,14 @@ pub(super) fn trigger_icon(
552 .items_center()581 .items_center()
553 .justify_center()582 .justify_center()
554 .rounded(px(radius::MD))583 .rounded(px(radius::MD))
555- .text_color(palette.muted)584+ .text_color(t.dim())
556 .child(super::parts::small_icon(icon)),585 .child(super::parts::small_icon(icon)),
557- palette,586+ t,
558 ))587 ))
559 }588 }
560 589
561-fn format_panel(palette: Palette) -> impl IntoElement {590+fn format_panel(t: Tokens) -> impl IntoElement {
562- panel(palette)591+ parts::surface(t)
563 .w(px(size::SHEET))592 .w(px(size::SHEET))
564 .p(px(space::SM))593 .p(px(space::SM))
565 .flex()594 .flex()
@@ -571,18 +600,13 @@ fn format_panel(palette: Palette) -> impl IntoElement {
571 .flex()600 .flex()
572 .items_center()601 .items_center()
573 .gap(px(space::MD))602 .gap(px(space::MD))
574- .child(603+ .child(div().w(px(size::THUMB)).text_color(t.dim()).child(syntax))
575- div()
576- .w(px(size::THUMB))
577- .text_color(palette.muted)
578- .child(syntax),
579- )
580 .child(div().flex_1().child(TextView::markdown(syntax, syntax)))604 .child(div().flex_1().child(TextView::markdown(syntax, syntax)))
581- .child(605+ .child(div().text_color(t.dim()).child(if shortcut.is_empty() {
582- div()606+ String::new()
583- .text_color(palette.muted)607+ } else {
584- .child(shortcut_label(shortcut)),608+ keys::label(shortcut)
585- )609+ }))
586 }))610 }))
587 }611 }
588 612
@@ -598,10 +622,10 @@ fn plus_row(
598 id: &'static str,622 id: &'static str,
599 icon: IconName,623 icon: IconName,
600 label: &'static str,624 label: &'static str,
601- palette: Palette,625+ t: Tokens,
602 on_click: impl Fn(&mut Window, &mut App) + 'static,626 on_click: impl Fn(&mut Window, &mut App) + 'static,
603 ) -> impl IntoElement {627 ) -> impl IntoElement {
604- clickable(id, palette, on_click)628+ clickable(id, t, on_click)
605 .h(px(size::CONTROL))629 .h(px(size::CONTROL))
606 .px(px(space::SM))630 .px(px(space::SM))
607 .gap(px(space::SM))631 .gap(px(space::SM))
@@ -610,18 +634,13 @@ fn plus_row(
610 .items_center()634 .items_center()
611 .child(635 .child(
612 div()636 div()
613- .text_color(palette.muted)637+ .text_color(t.dim())
614 .child(super::parts::small_icon(icon)),638 .child(super::parts::small_icon(icon)),
615 )639 )
616 .child(label)640 .child(label)
617 }641 }
618 642
619-pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {643+pub fn plus_popover(entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
620- let question = chat.poll_question.clone();
621- let options = chat.poll_options.clone();
622- let multiple = chat.poll_multiple;
623- let public = chat.poll_public;
624- let duration = chat.poll_duration;
625 let reset = entity.clone();644 let reset = entity.clone();
626 let entity = entity.clone();645 let entity = entity.clone();
627 646
@@ -637,180 +656,189 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
637 .items_center()656 .items_center()
638 .justify_center()657 .justify_center()
639 .rounded(px(radius::MD))658 .rounded(px(radius::MD))
640- .text_color(palette.muted)659+ .text_color(t.dim())
641 .child(super::parts::small_icon(IconName::Plus)),660 .child(super::parts::small_icon(IconName::Plus)),
642- palette,661+ t,
643 )662 )
644 .on_mouse_down(MouseButton::Left, move |_, _, cx| {663 .on_mouse_down(MouseButton::Left, move |_, _, cx| {
645- reset.update(cx, |yumush, _| yumush.chat.plus_menu = PlusMenu::Menu)664+ reset.update(cx, |yumush, _| yumush.chat.poll.plus_menu = PlusMenu::Menu)
646 }),665 }),
647 ))666 ))
648 .content(move |_, _, cx| {667 .content(move |_, _, cx| {
649 let popover = cx.entity();668 let popover = cx.entity();
650- if entity.read(cx).chat.plus_menu == PlusMenu::Format {669+ match entity.read(cx).chat.poll.plus_menu {
651- return format_panel(palette).into_any_element();670+ PlusMenu::Format => format_panel(t).into_any_element(),
671+ PlusMenu::Menu => menu_panel(&entity, &popover, t).into_any_element(),
672+ PlusMenu::Poll => poll_panel(&entity, &popover, t, cx).into_any_element(),
652 }673 }
653- if entity.read(cx).chat.plus_menu == PlusMenu::Menu {674+ })
654- let file = entity.clone();675+}
655- let poll = entity.clone();676+
656- let format = entity.clone();677+fn menu_panel(
657- return panel(palette)678+ entity: &Entity<Yumush>,
658- .w(px(size::SIDEBAR))679+ popover: &Entity<PopoverState>,
659- .p(px(space::XS))680+ t: Tokens,
681+) -> impl IntoElement {
682+ let file = entity.clone();
683+ let poll = entity.clone();
684+ let format = entity.clone();
685+ let dismiss = popover.clone();
686+
687+ parts::surface(t)
688+ .w(px(size::SIDEBAR))
689+ .p(px(space::XS))
690+ .flex()
691+ .flex_col()
692+ .gap(px(space::XS))
693+ .child(plus_row(
694+ "plus_file",
695+ IconName::File,
696+ w().composer.file,
697+ t,
698+ move |window, cx| {
699+ dismiss.update(cx, |state, cx| state.dismiss(window, cx));
700+ file.update(cx, |yumush, cx| yumush.attach_files(window, cx));
701+ },
702+ ))
703+ .child(plus_row(
704+ "plus_poll",
705+ IconName::ChartBar,
706+ w().composer.poll,
707+ t,
708+ move |_, cx| {
709+ poll.update(cx, |yumush, cx| {
710+ yumush.chat.poll.plus_menu = PlusMenu::Poll;
711+ cx.notify();
712+ })
713+ },
714+ ))
715+ .child(plus_row(
716+ "plus_format",
717+ IconName::Type,
718+ w().composer.format,
719+ t,
720+ move |_, cx| {
721+ format.update(cx, |yumush, cx| {
722+ yumush.chat.poll.plus_menu = PlusMenu::Format;
723+ cx.notify();
724+ })
725+ },
726+ ))
727+}
728+
729+fn poll_panel(
730+ entity: &Entity<Yumush>,
731+ popover: &Entity<PopoverState>,
732+ t: Tokens,
733+ cx: &App,
734+) -> impl IntoElement {
735+ let draft = &entity.read(cx).chat.poll;
736+ let duration = draft.duration;
737+ let toggle = entity.clone();
738+ let toggle_public = entity.clone();
739+ let duration_entity = entity.clone();
740+ let submit = entity.clone();
741+ let submit_popover = popover.clone();
742+ let options = draft.options.len();
743+
744+ parts::surface(t)
745+ .w(px(size::POPOVER))
746+ .p(px(space::SM))
747+ .flex()
748+ .flex_col()
749+ .gap(px(space::SM))
750+ .text_size(text(text::CAPTION))
751+ .child(compact_field(t, &draft.question))
752+ .children(draft.options.iter().enumerate().map(|(index, option)| {
753+ let remove = entity.clone();
754+ let trailing_blank = index + 1 == options && option_text(option, cx).is_empty();
755+ div()
756+ .flex()
757+ .items_center()
758+ .gap(px(space::SM))
759+ .child(div().flex_1().min_w_0().child(compact_field(t, option)))
760+ .children(
761+ (options > MINIMUM_POLL_OPTIONS && !trailing_blank).then(|| {
762+ icon_button(
763+ format!("poll_remove_{index}"),
764+ IconName::Close,
765+ w().composer.remove_option,
766+ Tone::Idle,
767+ Scale::Small,
768+ t,
769+ move |window, cx| {
770+ remove.update(cx, |yumush, cx| {
771+ yumush.remove_poll_option(index, window, cx)
772+ });
773+ },
774+ )
775+ }),
776+ )
777+ }))
778+ .child(
779+ div()
780+ .flex()
781+ .items_center()
782+ .gap(px(space::XS))
783+ .text_color(t.dim())
784+ .child(super::parts::small_icon(IconName::Timer))
785+ .children(poll_durations().map(|(label, seconds)| {
786+ let set = duration_entity.clone();
787+ let active = duration == seconds;
788+ clickable(label, t, move |_, cx| {
789+ set.update(cx, |yumush, cx| {
790+ yumush.chat.poll.duration = seconds;
791+ cx.notify();
792+ })
793+ })
794+ .px(px(space::SM))
795+ .py(px(space::XXS))
796+ .rounded(px(radius::SM))
797+ .text_color(if active { t.paper() } else { t.dim() })
798+ .when(active, |this| this.bg(t.press()))
799+ .child(label)
800+ })),
801+ )
802+ .child(
803+ div().flex().items_center().justify_between().child(
804+ div()
660 .flex()805 .flex()
661- .flex_col()806+ .items_center()
662- .gap(px(space::XS))807+ .gap(px(space::MD))
663- .child(plus_row(808+ .child(super::parts::labeled_toggle(
664- "plus_file",809+ "poll_multiple",
665- IconName::File,810+ w().composer.multiple_answers,
666- w().composer.file,811+ draft.multiple,
667- palette,812+ t,
668- move |window, cx| {
669- popover.update(cx, |state, cx| state.dismiss(window, cx));
670- file.update(cx, |yumush, cx| yumush.attach_files(window, cx));
671- },
672- ))
673- .child(plus_row(
674- "plus_poll",
675- IconName::ChartBar,
676- w().composer.poll,
677- palette,
678 move |_, cx| {813 move |_, cx| {
679- poll.update(cx, |yumush, cx| {814+ toggle.update(cx, |yumush, cx| {
680- yumush.chat.plus_menu = PlusMenu::Poll;815+ yumush.chat.poll.multiple = !yumush.chat.poll.multiple;
681 cx.notify();816 cx.notify();
682 })817 })
683 },818 },
684 ))819 ))
685- .child(plus_row(820+ .child(super::parts::labeled_toggle(
686- "plus_format",821+ "poll_public",
687- IconName::Type,822+ w().composer.show_voters,
688- w().composer.format,823+ draft.public,
689- palette,824+ t,
690 move |_, cx| {825 move |_, cx| {
691- format.update(cx, |yumush, cx| {826+ toggle_public.update(cx, |yumush, cx| yumush.toggle_poll_public(cx))
692- yumush.chat.plus_menu = PlusMenu::Format;
693- cx.notify();
694- })
695 },827 },
696- ))828+ )),
697- .into_any_element();829+ ),
698- }830+ )
699- let toggle = entity.clone();831+ .child(parts::button(
700- let toggle_public = entity.clone();832+ "poll_create",
701- let duration_entity = entity.clone();833+ w().composer.create,
702- let submit = entity.clone();834+ parts::Press::Primary,
703- panel(palette)835+ t,
704- .w(px(size::POPOVER))836+ move |window, cx| {
705- .p(px(space::SM))837+ if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) {
706- .flex()838+ submit_popover.update(cx, |state, cx| state.dismiss(window, cx));
707- .flex_col()839+ }
708- .gap(px(space::SM))840+ },
709- .text_size(text(text::CAPTION))841+ ))
710- .child(compact_field(palette, &question))
711- .children(options.iter().enumerate().map(|(index, option)| {
712- let remove = entity.clone();
713- let trailing_blank =
714- index + 1 == options.len() && option_text(option, cx).is_empty();
715- div()
716- .flex()
717- .items_center()
718- .gap(px(space::SM))
719- .child(
720- div()
721- .flex_1()
722- .min_w_0()
723- .child(compact_field(palette, option)),
724- )
725- .children(
726- (options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(|| {
727- icon_button(
728- format!("poll_remove_{index}"),
729- IconName::Close,
730- w().composer.remove_option,
731- Tone::Idle,
732- Scale::Small,
733- palette.tokens,
734- move |_, cx| {
735- remove.update(cx, |yumush, cx| {
736- yumush.remove_poll_option(index, cx)
737- });
738- },
739- )
740- }),
741- )
742- }))
743- .child(
744- div()
745- .flex()
746- .items_center()
747- .gap(px(space::XS))
748- .text_color(palette.muted)
749- .child(super::parts::small_icon(IconName::Timer))
750- .children(poll_durations().map(|(label, seconds)| {
751- let set = duration_entity.clone();
752- let active = duration == seconds;
753- clickable(label, palette, move |_, cx| {
754- set.update(cx, |yumush, cx| {
755- yumush.chat.poll_duration = seconds;
756- cx.notify();
757- })
758- })
759- .px(px(space::SM))
760- .py(px(space::XXS))
761- .rounded(px(radius::SM))
762- .text_color(if active {
763- palette.accent
764- } else {
765- palette.muted
766- })
767- .when(active, |this| this.bg(palette.tokens.press()))
768- .child(label)
769- })),
770- )
771- .child(
772- div().flex().items_center().justify_between().child(
773- div()
774- .flex()
775- .items_center()
776- .gap(px(space::MD))
777- .child(super::parts::labeled_toggle(
778- "poll_multiple",
779- w().composer.multiple_answers,
780- multiple,
781- palette.tokens,
782- move |_, cx| {
783- toggle.update(cx, |yumush, cx| {
784- yumush.chat.poll_multiple = !yumush.chat.poll_multiple;
785- cx.notify();
786- })
787- },
788- ))
789- .child(super::parts::labeled_toggle(
790- "poll_public",
791- w().composer.show_voters,
792- public,
793- palette.tokens,
794- move |_, cx| {
795- toggle_public
796- .update(cx, |yumush, cx| yumush.toggle_poll_public(cx))
797- },
798- )),
799- ),
800- )
801- .child(parts::button(
802- "poll_create",
803- w().composer.create,
804- parts::Press::Primary,
805- palette.tokens,
806- move |window, cx| {
807- if submit.update(cx, |yumush, cx| yumush.send_poll(window, cx)) {
808- popover.update(cx, |state, cx| state.dismiss(window, cx));
809- }
810- },
811- ))
812- .into_any_element()
813- })
814 }842 }
815 843
816 fn poll_durations() -> [(&'static str, Option<u32>); 4] {844 fn poll_durations() -> [(&'static str, Option<u32>); 4] {
@@ -844,37 +872,47 @@ impl Yumush {
844 window: &mut Window,872 window: &mut Window,
845 cx: &mut Context<Self>,873 cx: &mut Context<Self>,
846 ) {874 ) {
847- let last = self.chat.poll_options.last() == Some(input);875+ let last = self.chat.poll.options.last() == Some(input);
848 if last && !option_text(input, cx).is_empty() {876 if last && !option_text(input, cx).is_empty() {
849 self.add_poll_option(window, cx);877 self.add_poll_option(window, cx);
850 }878 }
851 }879 }
852 880
853- pub(super) fn add_poll_option(&mut self, window: &mut Window, cx: &mut Context<Self>) {881+ fn add_poll_option(&mut self, window: &mut Window, cx: &mut Context<Self>) {
854- if self.chat.poll_options.len() < MAXIMUM_POLL_OPTIONS {882+ if self.chat.poll.options.len() < MAXIMUM_POLL_OPTIONS {
855 let input = new_poll_option(window, cx);883 let input = new_poll_option(window, cx);
856- self.chat.poll_options.push(input);884+ self.chat.poll.options.push(input);
857 cx.notify();885 cx.notify();
858 }886 }
859 }887 }
860 888
861- pub(super) fn remove_poll_option(&mut self, index: usize, cx: &mut Context<Self>) {889+ fn remove_poll_option(&mut self, index: usize, window: &mut Window, cx: &mut Context<Self>) {
862- if self.chat.poll_options.len() > MINIMUM_POLL_OPTIONS890+ if self.chat.poll.options.len() > MINIMUM_POLL_OPTIONS
863- && index < self.chat.poll_options.len()891+ && index < self.chat.poll.options.len()
864 {892 {
865- self.chat.poll_options.remove(index);893+ self.chat.poll.options.remove(index);
894+ let last_filled = self
895+ .chat
896+ .poll
897+ .options
898+ .last()
899+ .is_some_and(|input| !option_text(input, cx).is_empty());
900+ if last_filled {
901+ self.add_poll_option(window, cx);
902+ }
866 cx.notify();903 cx.notify();
867 }904 }
868 }905 }
869 906
870 pub(super) fn send_poll(&mut self, window: &mut Window, cx: &mut Context<Self>) -> bool {907 pub(super) fn send_poll(&mut self, window: &mut Window, cx: &mut Context<Self>) -> bool {
871- let Some(community_id) = self.chat.selected_community_id else {908+ let Some(community_id) = self.chat.session.selected_community_id else {
872 return false;909 return false;
873 };910 };
874- let question = self.chat.poll_question.read(cx).text().to_string();911+ let question = self.chat.poll.question.read(cx).text().to_string();
875 let options: Vec<String> = self912 let options: Vec<String> = self
876 .chat913 .chat
877- .poll_options914+ .poll
915+ .options
878 .iter()916 .iter()
879 .map(|input| option_text(input, cx))917 .map(|input| option_text(input, cx))
880 .filter(|text| !text.is_empty())918 .filter(|text| !text.is_empty())
@@ -883,9 +921,9 @@ impl Yumush {
883 window.push_notification(Notification::error(error.to_string()), cx);921 window.push_notification(Notification::error(error.to_string()), cx);
884 return false;922 return false;
885 }923 }
886- let multiple = self.chat.poll_multiple;924+ let multiple = self.chat.poll.multiple;
887- let public = self.chat.poll_public;925+ let public = self.chat.poll.public;
888- let duration = self.chat.poll_duration;926+ let duration = self.chat.poll.duration;
889 let network = self.network.clone();927 let network = self.network.clone();
890 928
891 spawn_done(window, cx, async move {929 spawn_done(window, cx, async move {
@@ -901,22 +939,13 @@ impl Yumush {
901 .await939 .await
902 });940 });
903 941
904- self.chat942+ self.chat.poll.clear(window, cx);
905- .poll_question
906- .update(cx, |state, cx| state.set_value("", window, cx));
907- self.chat.poll_options.truncate(MINIMUM_POLL_OPTIONS);
908- for input in &self.chat.poll_options {
909- input.update(cx, |state, cx| state.set_value("", window, cx));
910- }
911- self.chat.poll_multiple = false;
912- self.chat.poll_public = true;
913- self.chat.poll_duration = None;
914 cx.notify();943 cx.notify();
915 true944 true
916 }945 }
917 946
918 pub(super) fn toggle_poll_public(&mut self, cx: &mut Context<Self>) {947 pub(super) fn toggle_poll_public(&mut self, cx: &mut Context<Self>) {
919- self.chat.poll_public = !self.chat.poll_public;948+ self.chat.poll.public = !self.chat.poll.public;
920 cx.notify();949 cx.notify();
921 }950 }
922 }951 }
crates/client/src/gui/dock.rsmodified+27 -30
@@ -1,12 +1,9 @@
1-use std::rc::Rc;
2-
3 use common::share::Kind;1 use common::share::Kind;
4 use gpui_kit::{App, Entity, IntoElement};2 use gpui_kit::{App, Entity, IntoElement};
5 3
6 use super::{4 use super::{
7- Palette, Yumush,5+ Yumush,
8 call_bar::{self, CallActions, CallBar},6 call_bar::{self, CallActions, CallBar},
9- chat::VoiceState,
10 entity_action,7 entity_action,
11 parts::Voice,8 parts::Voice,
12 style::Tokens,9 style::Tokens,
@@ -17,32 +14,31 @@ impl Yumush {
17 pub(super) fn dock(14 pub(super) fn dock(
18 &self,15 &self,
19 entity: &Entity<Self>,16 entity: &Entity<Self>,
20- palette: Palette,17+ t: Tokens,
21 cx: &App,18 cx: &App,
22 ) -> Option<impl IntoElement> {19 ) -> Option<impl IntoElement> {
23 let community = self.chat.voice_room()?;20 let community = self.chat.voice_room()?;
24- let VoiceState::In { .. } = &self.chat.voice_state else {
25- return None;
26- };
27 let (muted, deafened) = self.chat.voice_flags()?;21 let (muted, deafened) = self.chat.voice_flags()?;
28 let user = self.user.as_ref()?;22 let user = self.user.as_ref()?;
29 let me = user.id;23 let me = user.id;
30- let t = Tokens::of(cx);24+ let quality = voice_stats::quality(&self.chat.session.stats.voice);
31- let frayed = voice_stats::quality(&self.chat.stats.voice) == Some(Quality::Poor);25+ let frayed = quality == Some(Quality::Poor);
26+ let screen = self.network.share_source(Kind::Screen).is_some();
32 let voice = if frayed {27 let voice = if frayed {
33 Voice::Frayed28 Voice::Frayed
34- } else if !muted && self.chat.waves.speaking.contains(&me) {29+ } else if !muted && self.chat.session.waves.speaking.contains(&me) {
35 Voice::Live(t.person(me))30 Voice::Live(t.person(me))
36 } else {31 } else {
37 Voice::Quiet32 Voice::Quiet
38 };33 };
39 let bar = CallBar {34 let bar = CallBar {
40 place: super::community_name(community).to_string().into(),35 place: super::community_name(community).to_string().into(),
41- bands: self.chat.waves.voice(me).cloned(),36+ bands: self.chat.session.waves.voice(me).map(super::chat::to_bands),
42 voice,37 voice,
43- quality: super::voice_stats::quality(&self.chat.stats.voice),38+ quality,
44 pings: self39 pings: self
45 .chat40 .chat
41+ .session
46 .stats42 .stats
47 .voice43 .voice
48 .iter()44 .iter()
@@ -51,51 +47,52 @@ impl Yumush {
51 muted,47 muted,
52 deafened,48 deafened,
53 camera: self.network.share_source(Kind::Camera).is_some(),49 camera: self.network.share_source(Kind::Camera).is_some(),
54- screen: self.network.share_source(Kind::Screen).is_some(),50+ ghost: self.chat.session.ghost,
55- ghost: self.chat.ghost,51+ share: screen.then(|| {
56- share: self52+ (
57- .network53+ self.chat.session.waves.share(me).map(super::chat::to_bands),
58- .share_source(Kind::Screen)54+ t.person(me),
59- .map(|_| (self.chat.waves.share(me).cloned(), t.person(me))),55+ )
56+ }),
60 stats: self.chat.stats_at == Some(super::chat::StatsAt::Dock),57 stats: self.chat.stats_at == Some(super::chat::StatsAt::Dock),
61 };58 };
62 let go_id = community.id;59 let go_id = community.id;
63 let actions = CallActions {60 let actions = CallActions {
64- go: Rc::new(entity_action(entity, move |yumush, window, cx| {61+ go: Box::new(entity_action(entity, move |yumush, window, cx| {
65 yumush.select_community(go_id, window, cx);62 yumush.select_community(go_id, window, cx);
66 })),63 })),
67- mute: Rc::new(entity_action(entity, |yumush, window, cx| {64+ mute: Box::new(entity_action(entity, |yumush, window, cx| {
68 yumush.toggle_mute(window, cx)65 yumush.toggle_mute(window, cx)
69 })),66 })),
70- deafen: Rc::new(entity_action(entity, |yumush, _, cx| {67+ deafen: Box::new(entity_action(entity, |yumush, _, cx| {
71 yumush.toggle_deafen(cx)68 yumush.toggle_deafen(cx)
72 })),69 })),
73- camera: Rc::new(entity_action(entity, |yumush, window, cx| {70+ camera: Box::new(entity_action(entity, |yumush, window, cx| {
74 yumush.toggle_camera(window, cx)71 yumush.toggle_camera(window, cx)
75 })),72 })),
76- screen: Rc::new(entity_action(entity, |yumush, window, cx| {73+ screen: Box::new(entity_action(entity, |yumush, window, cx| {
77 yumush.toggle_share(window, cx)74 yumush.toggle_share(window, cx)
78 })),75 })),
79- leave: Rc::new(entity_action(entity, |yumush, _, cx| {76+ leave: Box::new(entity_action(entity, |yumush, _, cx| {
80 yumush.end_voice(cx);77 yumush.end_voice(cx);
81 cx.notify();78 cx.notify();
82 })),79 })),
83- stats: Rc::new(entity_action(entity, move |yumush, window, cx| {80+ stats: Box::new(entity_action(entity, move |yumush, window, cx| {
84 yumush.select_community(go_id, window, cx);81 yumush.select_community(go_id, window, cx);
85 yumush.toggle_stats(super::chat::StatsAt::Dock);82 yumush.toggle_stats(super::chat::StatsAt::Dock);
86 cx.notify();83 cx.notify();
87 })),84 })),
88 mic_more: self85 mic_more: self
89- .audio_button(entity, palette, super::voice_settings::Side::Input, cx)86+ .audio_button(entity, t, super::voice_settings::Side::Input, cx)
90 .into_any_element(),87 .into_any_element(),
91 speaker_more: self88 speaker_more: self
92- .audio_button(entity, palette, super::voice_settings::Side::Output, cx)89+ .audio_button(entity, t, super::voice_settings::Side::Output, cx)
93 .into_any_element(),90 .into_any_element(),
94 camera_more: self91 camera_more: self
95- .share_settings_button(entity, palette, Kind::Camera, cx)92+ .share_settings_button(entity, t, Kind::Camera, cx)
96 .into_any_element(),93 .into_any_element(),
97 screen_more: self94 screen_more: self
98- .share_settings_button(entity, palette, Kind::Screen, cx)95+ .share_settings_button(entity, t, Kind::Screen, cx)
99 .into_any_element(),96 .into_any_element(),
100 };97 };
101 Some(call_bar::view(bar, actions, t))98 Some(call_bar::view(bar, actions, t))
crates/client/src/gui/forward.rsmodified+7 -7
@@ -1,4 +1,4 @@
1-use super::style::{radius, size, space, text};1+use super::style::{Tokens, radius, size, space, text};
2 use crate::lang::w;2 use crate::lang::w;
3 use common::call::ForwardMessages;3 use common::call::ForwardMessages;
4 use common::model::Id;4 use common::model::Id;
@@ -15,7 +15,6 @@ use gpui_kit::{
15 use super::{15 use super::{
16 Yumush, clickable, community_name,16 Yumush, clickable, community_name,
17 composer::Composer,17 composer::Composer,
18- palette,
19 widget::{compact_field, search_text, spawn_done},18 widget::{compact_field, search_text, spawn_done},
20 };19 };
21 20
@@ -57,7 +56,7 @@ impl Forward {
57 56
58 impl Render for Forward {57 impl Render for Forward {
59 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {58 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
60- let palette = palette(cx);59+ let t = Tokens::of(cx);
61 let query = search_text(&self.filter, cx);60 let query = search_text(&self.filter, cx);
62 let entity = cx.entity();61 let entity = cx.entity();
63 let keep_authors = self.keep_authors;62 let keep_authors = self.keep_authors;
@@ -74,7 +73,7 @@ impl Render for Forward {
74 let selected = self.selected.clone();73 let selected = self.selected.clone();
75 let forward_entity = self.yumush.clone();74 let forward_entity = self.yumush.clone();
76 75
77- clickable(("forward_to", index), palette, move |window, cx| {76+ clickable(("forward_to", index), t, move |window, cx| {
78 let selected = selected.clone();77 let selected = selected.clone();
79 forward_entity.update(cx, |yumush, cx| {78 forward_entity.update(cx, |yumush, cx| {
80 yumush.forward_to(selected, community_id, keep_authors, window, cx)79 yumush.forward_to(selected, community_id, keep_authors, window, cx)
@@ -90,7 +89,7 @@ impl Render for Forward {
90 community,89 community,
91 px(size::ICON),90 px(size::ICON),
92 super::text(text::CAPTION),91 super::text(text::CAPTION),
93- palette,92+ t,
94 ))93 ))
95 .child(94 .child(
96 div()95 div()
@@ -107,12 +106,12 @@ impl Render for Forward {
107 .flex()106 .flex()
108 .flex_col()107 .flex_col()
109 .gap(px(space::MD))108 .gap(px(space::MD))
110- .child(compact_field(palette, &self.filter))109+ .child(compact_field(t, &self.filter))
111 .child(super::parts::labeled_toggle(110 .child(super::parts::labeled_toggle(
112 "keep_authors",111 "keep_authors",
113 w().forward.keep_authors,112 w().forward.keep_authors,
114 keep_authors,113 keep_authors,
115- palette.tokens,114+ t,
116 move |_, cx| {115 move |_, cx| {
117 entity.update(cx, |this, cx| {116 entity.update(cx, |this, cx| {
118 this.keep_authors = !this.keep_authors;117 this.keep_authors = !this.keep_authors;
@@ -169,6 +168,7 @@ impl Yumush {
169 168
170 let ids: Vec<Id> = self169 let ids: Vec<Id> = self
171 .chat170 .chat
171+ .session
172 .messages172 .messages
173 .iter()173 .iter()
174 .filter(|message| selected.contains(&message.id))174 .filter(|message| selected.contains(&message.id))
crates/client/src/gui/gallery.rsmodified+22 -10
@@ -15,7 +15,6 @@ use super::{
15 style::{Theme, Tokens, size, space},15 style::{Theme, Tokens, size, space},
16 };16 };
17 use crate::settings::FontSize;17 use crate::settings::FontSize;
18-use std::rc::Rc;
19 18
20 #[derive(Debug, Clone, Copy, PartialEq, Eq)]19 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
21 pub enum State {20 pub enum State {
@@ -80,13 +79,29 @@ impl State {
80 }79 }
81 }80 }
82 81
82+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
83+pub enum Page {
84+ Parts,
85+ Call,
86+}
87+
88+impl Page {
89+ pub fn parse(text: &str) -> Option<Self> {
90+ match text {
91+ "parts" => Some(Page::Parts),
92+ "call" => Some(Page::Call),
93+ _ => None,
94+ }
95+ }
96+}
97+
83 pub struct Gallery {98 pub struct Gallery {
84- page: String,99+ page: Page,
85 state: State,100 state: State,
86 }101 }
87 102
88 impl Gallery {103 impl Gallery {
89- pub fn new(page: String, state: State) -> Self {104+ pub fn new(page: Page, state: State) -> Self {
90 Self { page, state }105 Self { page, state }
91 }106 }
92 }107 }
@@ -94,11 +109,9 @@ impl Gallery {
94 impl Render for Gallery {109 impl Render for Gallery {
95 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {110 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
96 let t = Tokens::of(cx);111 let t = Tokens::of(cx);
97- let page = match self.page.as_str() {112+ let page = match self.page {
98- "parts" => parts_page(self.state, t).into_any_element(),113+ Page::Parts => parts_page(self.state, t).into_any_element(),
99- "call" => call_page(self.state, t).into_any_element(),114+ Page::Call => call_page(self.state, t).into_any_element(),
100- other => words(format!("no gallery page {other}"), Text::Body, Ink::Bad, t)
101- .into_any_element(),
102 };115 };
103 div()116 div()
104 .size_full()117 .size_full()
@@ -341,12 +354,11 @@ fn call_page(state: State, t: Tokens) -> impl IntoElement {
341 muted: bad,354 muted: bad,
342 deafened: false,355 deafened: false,
343 camera: state == State::Many,356 camera: state == State::Many,
344- screen: state == State::Many,
345 share: (state == State::Many).then(|| (Some(bands(2.)), t.hue(Hue::Amber))),357 share: (state == State::Many).then(|| (Some(bands(2.)), t.hue(Hue::Amber))),
346 stats: false,358 stats: false,
347 ghost: false,359 ghost: false,
348 };360 };
349- let none = || -> call_bar::Action { Rc::new(|_, _| {}) };361+ let none = || -> call_bar::Action { Box::new(|_, _| {}) };
350 let actions = CallActions {362 let actions = CallActions {
351 go: none(),363 go: none(),
352 mute: none(),364 mute: none(),
crates/client/src/gui/glyph.rsmodified+39 -46
@@ -15,8 +15,8 @@ use gpui_kit::{
15 };15 };
16 16
17 use super::{17 use super::{
18- Palette, Yumush, clickable,18+ Yumush, clickable,
19- style::{radius, size, space},19+ style::{Tokens, radius, size, space},
20 };20 };
21 use crate::emoji::{self, Piece};21 use crate::emoji::{self, Piece};
22 22
@@ -30,13 +30,13 @@ pub fn picture(emoji: &str, size: impl Into<gpui_kit::AbsoluteLength> + Copy) ->
30 }30 }
31 }31 }
32 32
33-pub fn sized(text: Rems) -> Rems {33+fn sized(text: Rems) -> Rems {
34 rems(text.0 * SCALE)34 rems(text.0 * SCALE)
35 }35 }
36 36
37 pub fn line(content: SharedString, text: Rems) -> Div {37 pub fn line(content: SharedString, text: Rems) -> Div {
38 let row = div().flex().items_center().min_w_0().overflow_hidden();38 let row = div().flex().items_center().min_w_0().overflow_hidden();
39- if emoji::plain(&content) {39+ if content.is_ascii() {
40 return row.child(div().min_w_0().truncate().child(content));40 return row.child(div().min_w_0().truncate().child(content));
41 }41 }
42 let size = sized(text);42 let size = sized(text);
@@ -54,30 +54,31 @@ pub fn line(content: SharedString, text: Rems) -> Div {
54 }54 }
55 55
56 pub fn wrapped(content: SharedString, text: Rems) -> Div {56 pub fn wrapped(content: SharedString, text: Rems) -> Div {
57- let flow = div().flex().flex_wrap().items_center().min_w_0();57+ if content.is_ascii() {
58- if emoji::plain(&content) {
59 return div().min_w_0().child(content);58 return div().min_w_0().child(content);
60 }59 }
61 let size = sized(text);60 let size = sized(text);
62- flow.children(emoji::pieces(&content).into_iter().flat_map(|piece| {61+ div().flex().flex_wrap().items_center().min_w_0().children(
63- match piece {62+ emoji::pieces(&content)
64- Piece::Text(text) => text63+ .into_iter()
65- .split_inclusive(' ')64+ .flat_map(|piece| match piece {
66- .map(|word| {65+ Piece::Text(text) => text
67- div()66+ .split_inclusive(' ')
68- .whitespace_nowrap()67+ .map(|word| {
69- .child(word.replace(' ', "\u{a0}"))68+ div()
70- .into_any_element()69+ .whitespace_nowrap()
71- })70+ .child(word.replace(' ', "\u{a0}"))
72- .collect::<Vec<_>>(),71+ .into_any_element()
73- Piece::Emoji(emoji) => vec![picture(emoji, size)],72+ })
74- }73+ .collect::<Vec<_>>(),
75- }))74+ Piece::Emoji(emoji) => vec![picture(emoji, size)],
75+ }),
76+ )
76 }77 }
77 78
78 const TOKEN: f32 = 0.85;79 const TOKEN: f32 = 0.85;
79 80
80-pub fn content(text: &str) -> InputContent {81+fn content(text: &str) -> InputContent {
81 let base = text.as_ptr() as usize;82 let base = text.as_ptr() as usize;
82 emoji::pieces(text)83 emoji::pieces(text)
83 .into_iter()84 .into_iter()
@@ -88,13 +89,10 @@ pub fn content(text: &str) -> InputContent {
88 .fold(InputContent::new(text.to_string()), |content, emoji| {89 .fold(InputContent::new(text.to_string()), |content, emoji| {
89 let start = emoji.as_ptr() as usize - base;90 let start = emoji.as_ptr() as usize - base;
90 let token = InlineToken::new(emoji::key(emoji), emoji.to_string());91 let token = InlineToken::new(emoji::key(emoji), emoji.to_string());
91- match content92+ content
92 .clone()93 .clone()
93 .with_token(start..start + emoji.len(), token)94 .with_token(start..start + emoji.len(), token)
94- {95+ .unwrap_or(content)
95- Ok(content) => content,
96- Err(_) => content,
97- }
98 })96 })
99 }97 }
100 98
@@ -103,16 +101,10 @@ pub fn token(context: &InlineTokenContext, _: &mut Window, _: &mut App) -> AnyEl
103 picture(context.token().text(), size)101 picture(context.token().text(), size)
104 }102 }
105 103
106-pub trait Fill {104+pub trait Fill: Sized {
107- fn fill(&mut self, text: impl Into<SharedString>, window: &mut Window, cx: &mut Context<Self>)105+ fn fill(&mut self, text: impl Into<SharedString>, window: &mut Window, cx: &mut Context<Self>);
108- where106+ fn mark(&mut self, cx: &mut Context<Self>);
109- Self: Sized;107+ fn put(&mut self, emoji: &'static str, window: &mut Window, cx: &mut Context<Self>);
110- fn mark(&mut self, cx: &mut Context<Self>)
111- where
112- Self: Sized;
113- fn put(&mut self, emoji: &'static str, window: &mut Window, cx: &mut Context<Self>)
114- where
115- Self: Sized;
116 }108 }
117 109
118 macro_rules! fill {110 macro_rules! fill {
@@ -182,15 +174,17 @@ pub type Pick = std::rc::Rc<dyn Fn(&'static str, &mut Window, &mut App)>;
182 174
183 pub fn insert_into<T: Fill + 'static>(input: Entity<T>) -> Pick {175 pub fn insert_into<T: Fill + 'static>(input: Entity<T>) -> Pick {
184 std::rc::Rc::new(move |emoji, window, cx| {176 std::rc::Rc::new(move |emoji, window, cx| {
185- input.update(cx, |state, cx| state.put(emoji, window, cx));177+ input.update(cx, |state, cx| {
186- input.update(cx, |state, cx| state.mark(cx));178+ state.put(emoji, window, cx);
179+ state.mark(cx);
180+ });
187 })181 })
188 }182 }
189 183
190 pub fn picker_button(184 pub fn picker_button(
191 id: &'static str,185 id: &'static str,
192 entity: &Entity<Yumush>,186 entity: &Entity<Yumush>,
193- palette: Palette,187+ t: Tokens,
194 pick: Pick,188 pick: Pick,
195 ) -> impl IntoElement {189 ) -> impl IntoElement {
196 let entity = entity.clone();190 let entity = entity.clone();
@@ -201,7 +195,7 @@ pub fn picker_button(
201 SharedString::from(format!("{id}_trigger")),195 SharedString::from(format!("{id}_trigger")),
202 IconName::FaceSlightlySmiling,196 IconName::FaceSlightlySmiling,
203 size::CONTROL_SM,197 size::CONTROL_SM,
204- palette,198+ t,
205 ))199 ))
206 .content(move |_, _, cx| {200 .content(move |_, _, cx| {
207 let popover = cx.entity();201 let popover = cx.entity();
@@ -210,16 +204,15 @@ pub fn picker_button(
210 popover.update(cx, |state, cx| state.dismiss(window, cx));204 popover.update(cx, |state, cx| state.dismiss(window, cx));
211 pick(emoji, window, cx);205 pick(emoji, window, cx);
212 });206 });
213- picker(&entity, entity.read(cx).emoji_group, palette, close)207+ picker(&entity, entity.read(cx).emoji_group, t, close)
214 })208 })
215 }209 }
216 210
217-pub fn picker(entity: &Entity<Yumush>, group: usize, palette: Palette, pick: Pick) -> Div {211+fn picker(entity: &Entity<Yumush>, group: usize, t: Tokens, pick: Pick) -> Div {
218- let t = palette.tokens;
219 let tabs = emoji::GROUPS.iter().enumerate().map(|(index, _)| {212 let tabs = emoji::GROUPS.iter().enumerate().map(|(index, _)| {
220 let entity = entity.clone();213 let entity = entity.clone();
221 let face = emoji::group(index).first().copied().unwrap_or_default();214 let face = emoji::group(index).first().copied().unwrap_or_default();
222- clickable(("emoji_group", index), palette, move |_, cx| {215+ clickable(("emoji_group", index), t, move |_, cx| {
223 entity.update(cx, |yumush, cx| {216 entity.update(cx, |yumush, cx| {
224 yumush.emoji_group = index;217 yumush.emoji_group = index;
225 cx.notify();218 cx.notify();
@@ -238,7 +231,7 @@ pub fn picker(entity: &Entity<Yumush>, group: usize, palette: Palette, pick: Pic
238 let emoji: &'static str = emoji;231 let emoji: &'static str = emoji;
239 clickable(232 clickable(
240 SharedString::from(format!("emoji_{emoji}")),233 SharedString::from(format!("emoji_{emoji}")),
241- palette,234+ t,
242 move |window, cx| pick(emoji, window, cx),235 move |window, cx| pick(emoji, window, cx),
243 )236 )
244 .size(px(size::CONTROL_SM))237 .size(px(size::CONTROL_SM))
@@ -266,7 +259,7 @@ pub fn picker(entity: &Entity<Yumush>, group: usize, palette: Palette, pick: Pic
266 .child(259 .child(
267 div()260 div()
268 .text_size(super::text(super::style::text::CAPTION))261 .text_size(super::text(super::style::text::CAPTION))
269- .text_color(palette.muted)262+ .text_color(t.dim())
270 .child("Twemoji · CC-BY 4.0"),263 .child("Twemoji · CC-BY 4.0"),
271 )264 )
272 }265 }
crates/client/src/gui/jump.rsmodified+33 -44
@@ -1,6 +1,7 @@
1 use crate::lang::{Label as _, Lang, w};1 use crate::lang::{Label as _, Lang, w};
2 use crate::settings::{Activation, FontSize};2 use crate::settings::{Activation, FontSize};
3 use common::model::{Community, CommunityKind, Id, Presence, User};3 use common::model::{Community, CommunityKind, Id, Presence, User};
4+use common::share::Kind;
4 use gpui_kit::{5 use gpui_kit::{
5 Context, Div, Entity, FontWeight, InteractiveElement, KeyDownEvent, ParentElement,6 Context, Div, Entity, FontWeight, InteractiveElement, KeyDownEvent, ParentElement,
6 ScrollHandle, StatefulInteractiveElement, Styled, Window,7 ScrollHandle, StatefulInteractiveElement, Styled, Window,
@@ -12,7 +13,7 @@ use gpui_kit::{
12 };13 };
13 14
14 use super::{15 use super::{
15- Palette, Yumush, avatar,16+ Yumush, avatar,
16 builder::BuilderTab,17 builder::BuilderTab,
17 chat::{Armed, View},18 chat::{Armed, View},
18 community_icon, community_name,19 community_icon, community_name,
@@ -123,12 +124,14 @@ impl Yumush {
123 let call = self.chat.voice_community();124 let call = self.chat.voice_community();
124 let unread = |id: Id| {125 let unread = |id: Id| {
125 self.chat126 self.chat
127+ .session
126 .unread128 .unread
127 .get(&id)129 .get(&id)
128 .is_some_and(|unread| unread.messages > 0)130 .is_some_and(|unread| unread.messages > 0)
129 };131 };
130 let mut rooms: Vec<_> = self132 let mut rooms: Vec<_> = self
131 .chat133 .chat
134+ .session
132 .communities135 .communities
133 .iter()136 .iter()
134 .filter(|community| !matches!(community.kind, CommunityKind::Notes))137 .filter(|community| !matches!(community.kind, CommunityKind::Notes))
@@ -143,6 +146,7 @@ impl Yumush {
143 });146 });
144 let directs: Vec<Id> = self147 let directs: Vec<Id> = self
145 .chat148 .chat
149+ .session
146 .communities150 .communities
147 .iter()151 .iter()
148 .filter_map(|community| community.kind.peer().map(|peer| peer.id))152 .filter_map(|community| community.kind.peer().map(|peer| peer.id))
@@ -150,10 +154,11 @@ impl Yumush {
150 let mut seen = std::collections::HashSet::new();154 let mut seen = std::collections::HashSet::new();
151 let people = self155 let people = self
152 .chat156 .chat
157+ .session
153 .friends158 .friends
154 .friends159 .friends
155 .iter()160 .iter()
156- .chain(self.chat.members.iter().map(|member| &member.user))161+ .chain(self.chat.session.members.iter().map(|member| &member.user))
157 .filter(|user| {162 .filter(|user| {
158 !directs.contains(&user.id)163 !directs.contains(&user.id)
159 && self.user.as_ref().is_none_or(|me| me.id != user.id)164 && self.user.as_ref().is_none_or(|me| me.id != user.id)
@@ -217,36 +222,22 @@ impl Yumush {
217 Row::new(place, label.to_string(), Glyph::Icon(icon))222 Row::new(place, label.to_string(), Glyph::Icon(icon))
218 };223 };
219 let call = self.chat.voice_flags().map(|(muted, deafened)| {224 let call = self.chat.voice_flags().map(|(muted, deafened)| {
225+ let (mute, mute_icon) = if muted {
226+ (w().jump.unmute, IconName::MicOff)
227+ } else {
228+ (w().jump.mute, IconName::Mic)
229+ };
230+ let (deafen, deafen_icon) = if deafened {
231+ (w().jump.undeafen, IconName::HeadphoneOff)
232+ } else {
233+ (w().jump.deafen, IconName::Headphones)
234+ };
220 [235 [
221- action(236+ action(Place::Mute, mute, mute_icon),
222- Place::Mute,237+ action(Place::Deafen, deafen, deafen_icon),
223- if muted {
224- w().jump.unmute
225- } else {
226- w().jump.mute
227- },
228- if muted {
229- IconName::MicOff
230- } else {
231- IconName::Mic
232- },
233- ),
234- action(
235- Place::Deafen,
236- if deafened {
237- w().jump.undeafen
238- } else {
239- w().jump.deafen
240- },
241- if deafened {
242- IconName::HeadphoneOff
243- } else {
244- IconName::Headphones
245- },
246- ),
247 action(238 action(
248 Place::Share,239 Place::Share,
249- if self.network.sharing() {240+ if self.network.share_source(Kind::Screen).is_some() {
250 w().jump.stop_sharing241 w().jump.stop_sharing
251 } else {242 } else {
252 w().jump.share_screen243 w().jump.share_screen
@@ -255,7 +246,7 @@ impl Yumush {
255 ),246 ),
256 action(247 action(
257 Place::Camera,248 Place::Camera,
258- if self.network.camera_on() {249+ if self.network.share_source(Kind::Camera).is_some() {
259 w().jump.camera_off250 w().jump.camera_off
260 } else {251 } else {
261 w().jump.camera_on252 w().jump.camera_on
@@ -363,7 +354,7 @@ impl Yumush {
363 354
364 pub(super) fn close_jump(&mut self, window: &mut Window, cx: &mut Context<Self>) {355 pub(super) fn close_jump(&mut self, window: &mut Window, cx: &mut Context<Self>) {
365 self.chat.goto.open = false;356 self.chat.goto.open = false;
366- self.chat.armed = None;357+ self.chat.session.armed = None;
367 window.focus(&self.focus, cx);358 window.focus(&self.focus, cx);
368 cx.notify();359 cx.notify();
369 }360 }
@@ -411,11 +402,11 @@ impl Yumush {
411 Place::Friends => self.open_friends(window, cx),402 Place::Friends => self.open_friends(window, cx),
412 Place::Settings(section) => {403 Place::Settings(section) => {
413 self.show_view(View::Settings, window, cx);404 self.show_view(View::Settings, window, cx);
414- self.chat.section = Some(section.id());405+ self.chat.session.section = Some(section.id());
415 }406 }
416 Place::Setting(index) => {407 Place::Setting(index) => {
417 self.show_view(View::Settings, window, cx);408 self.show_view(View::Settings, window, cx);
418- self.chat.section = Some(setting_rows()[index].0.id());409+ self.chat.session.section = Some(setting_rows()[index].0.id());
419 }410 }
420 Place::Builder(tab) => {411 Place::Builder(tab) => {
421 self.show_view(View::Builder, window, cx);412 self.show_view(View::Builder, window, cx);
@@ -439,30 +430,29 @@ impl Yumush {
439 cx.notify();430 cx.notify();
440 }431 }
441 432
442- fn glyph(&self, glyph: Glyph, palette: Palette) -> Div {433+ fn glyph(&self, glyph: Glyph, t: Tokens) -> Div {
443- let t = palette.tokens;
444 let face = match glyph {434 let face = match glyph {
445 Glyph::Icon(icon) => div()435 Glyph::Icon(icon) => div()
446 .text_color(t.faint())436 .text_color(t.faint())
447 .child(Icon::new(icon).size(px(size::ICON))),437 .child(Icon::new(icon).size(px(size::ICON))),
448 Glyph::Person(user) => presence_avatar(438 Glyph::Person(user) => presence_avatar(
449 avatar(439 avatar(
450- palette,440+ t,
451 &user,441 &user,
452 px(size::CHIP),442 px(size::CHIP),
453 t.text(text::CAPTION),443 t.text(text::CAPTION),
454- &self.chat.avatars,444+ &self.chat.session.avatars,
455 ),445 ),
456 self.presence_of(user.id),446 self.presence_of(user.id),
457 px(size::CHIP),447 px(size::CHIP),
458- palette,448+ t,
459 ),449 ),
460 Glyph::Room(community) => community_icon(450 Glyph::Room(community) => community_icon(
461- palette,451+ t,
462 &community,452 &community,
463 px(size::CHIP),453 px(size::CHIP),
464 t.text(text::CAPTION),454 t.text(text::CAPTION),
465- &self.chat.avatars,455+ &self.chat.session.avatars,
466 ),456 ),
467 };457 };
468 div()458 div()
@@ -474,11 +464,10 @@ impl Yumush {
474 .child(face)464 .child(face)
475 }465 }
476 466
477- pub(super) fn jump_box(&self, palette: Palette, cx: &mut Context<Self>) -> Option<Div> {467+ pub(super) fn jump_box(&self, t: Tokens, cx: &mut Context<Self>) -> Option<Div> {
478 if !self.chat.goto.open {468 if !self.chat.goto.open {
479 return None;469 return None;
480 }470 }
481- let t = palette.tokens;
482 let query = self.chat.goto.input.read(cx).value().trim().to_lowercase();471 let query = self.chat.goto.input.read(cx).value().trim().to_lowercase();
483 let places = self.places(cx);472 let places = self.places(cx);
484 let cursor = self.chat.goto.cursor.min(places.len().saturating_sub(1));473 let cursor = self.chat.goto.cursor.min(places.len().saturating_sub(1));
@@ -534,7 +523,7 @@ impl Yumush {
534 .min_w_0()523 .min_w_0()
535 .text_size(t.text(text::BODY))524 .text_size(t.text(text::BODY))
536 .child(bare_input(525 .child(bare_input(
537- palette,526+ t,
538 Input::new(&self.chat.goto.input)527 Input::new(&self.chat.goto.input)
539 .token(super::glyph::token),528 .token(super::glyph::token),
540 )),529 )),
@@ -568,7 +557,7 @@ impl Yumush {
568 yumush.pick(place, window, cx)557 yumush.pick(place, window, cx)
569 })558 })
570 })559 })
571- .child(self.glyph(row.glyph, palette))560+ .child(self.glyph(row.glyph, t))
572 .child(label_line(&row.label, &query, selected, t))561 .child(label_line(&row.label, &query, selected, t))
573 .when_some(row.hint, |line, hint| {562 .when_some(row.hint, |line, hint| {
574 line.child(words(hint, Text::Caption, Ink::Faint, t))563 line.child(words(hint, Text::Caption, Ink::Faint, t))
crates/client/src/gui/keys.rsadded+21 -0
@@ -0,0 +1,21 @@
1+const MOD_LABEL: &str = if cfg!(target_os = "macos") {
2+ "Cmd"
3+} else {
4+ "Ctrl"
5+};
6+
7+macro_rules! bind {
8+ ($keys:literal) => {
9+ if cfg!(target_os = "macos") {
10+ concat!("cmd-", $keys)
11+ } else {
12+ concat!("ctrl-", $keys)
13+ }
14+ };
15+}
16+
17+pub(crate) use bind;
18+
19+pub fn label(keys: &str) -> String {
20+ format!("{MOD_LABEL}+{keys}")
21+}
crates/client/src/gui/media_view.rsmodified+232 -220
@@ -1,4 +1,4 @@
1-use super::style::{radius, size, space, text};1+use super::style::{Tokens, radius, size, space, text};
2 use super::text;2 use super::text;
3 use crate::lang::w;3 use crate::lang::w;
4 use crate::storage::Store;4 use crate::storage::Store;
@@ -6,16 +6,18 @@ use common::model::Id;
6 use std::{6 use std::{
7 collections::{HashMap, HashSet},7 collections::{HashMap, HashSet},
8 path::PathBuf,8 path::PathBuf,
9- sync::Arc,9+ sync::{
10+ Arc,
11+ atomic::{AtomicU64, Ordering},
12+ },
10 time::Duration,13 time::Duration,
11 };14 };
12 15
13 use common::model::{Attachment, AttachmentKind, Message};16 use common::model::{Attachment, AttachmentKind, Message};
14 use gpui_kit::{17 use gpui_kit::{
15- App, AppContext, AsyncWindowContext, ClipboardEntry, ClipboardItem, Context, Entity,18+ App, AppContext, ClipboardEntry, ClipboardItem, Context, Entity, FontWeight, Image,
16- FontWeight, Image, ImageFormat, InteractiveElement, IntoElement, ParentElement,19+ ImageFormat, InteractiveElement, IntoElement, ParentElement, PathPromptOptions, RenderImage,
17- PathPromptOptions, RenderImage, StatefulInteractiveElement, Styled, Subscription, Task,20+ StatefulInteractiveElement, Styled, Subscription, Task, Window,
18- WeakEntity, Window,
19 assets::IconName,21 assets::IconName,
20 component::{22 component::{
21 Icon, WindowExt,23 Icon, WindowExt,
@@ -28,13 +30,13 @@ use gpui_kit::{
28 };30 };
29 31
30 use super::{32 use super::{
31- Palette, Tooltip as _, Yumush, clickable, notify_error, storage,33+ Tooltip as _, Yumush, clickable, notify_error, storage,
32 voice_note::{VoiceNote, bars},34 voice_note::{VoiceNote, bars},
33 };35 };
34 use crate::{36 use crate::{
35 embed::{self, Embed, EmbedKind},37 embed::{self, Embed, EmbedKind},
36 media::{Player, voice_note as note},38 media::{Player, voice_note as note},
37- net::{Fail, NetworkHandle},39+ net::Fail,
38 };40 };
39 41
40 const IMAGE_BOX: (f32, f32) = (size::MEDIA, 300.);42 const IMAGE_BOX: (f32, f32) = (size::MEDIA, 300.);
@@ -46,9 +48,13 @@ pub struct LoadedEmbed {
46 image: Option<Arc<Image>>,48 image: Option<Arc<Image>>,
47 }49 }
48 50
49-pub enum PlayState {51+#[derive(Default)]
50- Loading,52+pub enum Playing {
53+ #[default]
54+ Idle,
55+ Loading(Id),
51 Ready {56 Ready {
57+ id: Id,
52 player: Player,58 player: Player,
53 frame: Option<Arc<RenderImage>>,59 frame: Option<Arc<RenderImage>>,
54 generation: u64,60 generation: u64,
@@ -57,9 +63,20 @@ pub enum PlayState {
57 },63 },
58 }64 }
59 65
60-pub struct Playing {66+impl Playing {
61- attachment_id: Id,67+ fn id(&self) -> Option<Id> {
62- state: PlayState,68+ match self {
69+ Playing::Idle => None,
70+ Playing::Loading(id) | Playing::Ready { id, .. } => Some(*id),
71+ }
72+ }
73+
74+ fn player(&self) -> Option<&Player> {
75+ match self {
76+ Playing::Ready { player, .. } => Some(player),
77+ Playing::Idle | Playing::Loading(_) => None,
78+ }
79+ }
63 }80 }
64 81
65 #[derive(Default)]82 #[derive(Default)]
@@ -72,7 +89,8 @@ pub struct Media {
72 embeds: HashMap<String, LoadedEmbed>,89 embeds: HashMap<String, LoadedEmbed>,
73 requested: HashSet<Id>,90 requested: HashSet<Id>,
74 requested_links: HashSet<String>,91 requested_links: HashSet<String>,
75- playing: Option<Playing>,92+ playing: Playing,
93+ retired: Vec<Arc<RenderImage>>,
76 }94 }
77 95
78 impl Media {96 impl Media {
@@ -82,8 +100,25 @@ impl Media {
82 100
83 pub fn leave(&mut self) {101 pub fn leave(&mut self) {
84 self.pending.clear();102 self.pending.clear();
85- self.playing = None;103+ self.stop();
86 self.voice_note = VoiceNote::Idle;104 self.voice_note = VoiceNote::Idle;
105+ self.requested
106+ .retain(|id| self.thumbnails.contains_key(id) || self.waveforms.contains_key(id));
107+ self.requested_links
108+ .retain(|url| self.embeds.contains_key(url));
109+ }
110+
111+ fn stop(&mut self) {
112+ if let Playing::Ready {
113+ frame: Some(frame), ..
114+ } = std::mem::take(&mut self.playing)
115+ {
116+ self.retired.push(frame);
117+ }
118+ }
119+
120+ fn drain_retired(&mut self) -> std::vec::Drain<'_, Arc<RenderImage>> {
121+ self.retired.drain(..)
87 }122 }
88 }123 }
89 124
@@ -124,12 +159,21 @@ fn fit(width: Option<u32>, height: Option<u32>, limit: (f32, f32)) -> (f32, f32)
124 (width * scale, height * scale)159 (width * scale, height * scale)
125 }160 }
126 161
162+const SAFE_EXTENSIONS: [&str; 16] = [
163+ "png", "jpg", "jpeg", "gif", "webp", "mp4", "webm", "mkv", "mov", "mp3", "m4a", "aac", "ogg",
164+ "opus", "wav", "flac",
165+];
166+
167+static TEMP: AtomicU64 = AtomicU64::new(0);
168+
127 fn cache_path(attachment: &Attachment) -> Option<PathBuf> {169 fn cache_path(attachment: &Attachment) -> Option<PathBuf> {
128 let directory = crate::storage::media_dir()?;170 let directory = crate::storage::media_dir()?;
129 let extension = attachment171 let extension = attachment
130 .name172 .name
131 .rsplit_once('.')173 .rsplit_once('.')
132- .map(|(_, extension)| format!(".{extension}"))174+ .map(|(_, extension)| extension.to_ascii_lowercase())
175+ .filter(|extension| SAFE_EXTENSIONS.contains(&extension.as_str()))
176+ .map(|extension| format!(".{extension}"))
133 .unwrap_or_default();177 .unwrap_or_default();
134 Some(directory.join(format!("{}{extension}", attachment.id)))178 Some(directory.join(format!("{}{extension}", attachment.id)))
135 }179 }
@@ -148,26 +192,6 @@ fn duration_secs(player: &Player) -> f32 {
148 .max(0.1)192 .max(0.1)
149 }193 }
150 194
151-pub(super) async fn upload_file(
152- this: &WeakEntity<Yumush>,
153- network: &NetworkHandle,
154- community_id: Id,
155- path: PathBuf,
156- maximum: Option<u64>,
157- cx: &mut AsyncWindowContext,
158-) -> Result<Attachment, Fail> {
159- let _ = this.update(cx, |yumush, cx| {
160- yumush.chat.media.uploading += 1;
161- cx.notify();
162- });
163- let uploaded = network.upload_attachment(community_id, path, maximum).await;
164- let _ = this.update(cx, |yumush, cx| {
165- yumush.chat.media.uploading -= 1;
166- cx.notify();
167- });
168- uploaded
169-}
170-
171 fn save_pasted(image: &Image) -> Option<PathBuf> {195 fn save_pasted(image: &Image) -> Option<PathBuf> {
172 let path = crate::storage::media_dir()?.join(format!(196 let path = crate::storage::media_dir()?.join(format!(
173 "paste-{}.{}",197 "paste-{}.{}",
@@ -184,18 +208,13 @@ pub(super) fn into_render_image(frame: crate::media::Frame) -> Option<Arc<Render
184 Some(Arc::new(RenderImage::new(vec![image::Frame::new(buffer)])))208 Some(Arc::new(RenderImage::new(vec![image::Frame::new(buffer)])))
185 }209 }
186 210
187-pub(super) fn to_render_image(frame: &crate::media::Frame) -> Option<Arc<RenderImage>> {
188- let buffer = image::RgbaImage::from_raw(frame.width, frame.height, frame.bgra.to_vec())?;
189- Some(Arc::new(RenderImage::new(vec![image::Frame::new(buffer)])))
190-}
191-
192 impl Yumush {211 impl Yumush {
193 pub(super) fn request_media(&mut self, cx: &mut Context<Self>) {212 pub(super) fn request_media(&mut self, cx: &mut Context<Self>) {
194 let mut thumbnails = Vec::new();213 let mut thumbnails = Vec::new();
195 let mut links = Vec::new();214 let mut links = Vec::new();
196 let mut avatars = Vec::new();215 let mut avatars = Vec::new();
197 let mut voices = Vec::new();216 let mut voices = Vec::new();
198- for message in &self.chat.messages {217+ for message in &self.chat.session.messages {
199 let forwarded = message.snippet.iter().flat_map(|snippet| &snippet.messages);218 let forwarded = message.snippet.iter().flat_map(|snippet| &snippet.messages);
200 for item in forwarded.clone() {219 for item in forwarded.clone() {
201 if let Some(avatar_id) = item.avatar_id {220 if let Some(avatar_id) = item.avatar_id {
@@ -208,18 +227,18 @@ impl Yumush {
208 .chain(forwarded.flat_map(|item| &item.attachments))227 .chain(forwarded.flat_map(|item| &item.attachments))
209 {228 {
210 if attachment.kind == AttachmentKind::Image229 if attachment.kind == AttachmentKind::Image
211- && self.chat.media.requested.insert(attachment.id)230+ && self.chat.session.media.requested.insert(attachment.id)
212 {231 {
213 thumbnails.push(attachment.id);232 thumbnails.push(attachment.id);
214 }233 }
215 if note::is_voice_note(attachment)234 if note::is_voice_note(attachment)
216- && self.chat.media.requested.insert(attachment.id)235+ && self.chat.session.media.requested.insert(attachment.id)
217 {236 {
218 voices.push(attachment.clone());237 voices.push(attachment.clone());
219 }238 }
220 }239 }
221 for url in embed::urls(&message.body) {240 for url in embed::urls(&message.body) {
222- if self.chat.media.requested_links.insert(url.clone()) {241+ if self.chat.session.media.requested_links.insert(url.clone()) {
223 links.push(url);242 links.push(url);
224 }243 }
225 }244 }
@@ -237,7 +256,12 @@ impl Yumush {
237 };256 };
238 let _ = this.update(cx, |yumush, cx| {257 let _ = this.update(cx, |yumush, cx| {
239 if let Some(image) = to_image(bytes) {258 if let Some(image) = to_image(bytes) {
240- yumush.chat.media.thumbnails.insert(attachment_id, image);259+ yumush
260+ .chat
261+ .session
262+ .media
263+ .thumbnails
264+ .insert(attachment_id, image);
241 cx.notify();265 cx.notify();
242 }266 }
243 });267 });
@@ -260,7 +284,12 @@ impl Yumush {
260 return;284 return;
261 };285 };
262 let _ = this.update(cx, |yumush, cx| {286 let _ = this.update(cx, |yumush, cx| {
263- yumush.chat.media.waveforms.insert(attachment_id, waveform);287+ yumush
288+ .chat
289+ .session
290+ .media
291+ .waveforms
292+ .insert(attachment_id, waveform);
264 cx.notify();293 cx.notify();
265 });294 });
266 })295 })
@@ -283,6 +312,7 @@ impl Yumush {
283 let _ = this.update(cx, |yumush, cx| {312 let _ = this.update(cx, |yumush, cx| {
284 yumush313 yumush
285 .chat314 .chat
315+ .session
286 .media316 .media
287 .embeds317 .embeds
288 .insert(url, LoadedEmbed { embed, image });318 .insert(url, LoadedEmbed { embed, image });
@@ -335,25 +365,25 @@ impl Yumush {
335 }365 }
336 366
337 fn attach_paths(&mut self, paths: Vec<PathBuf>, window: &mut Window, cx: &mut Context<Self>) {367 fn attach_paths(&mut self, paths: Vec<PathBuf>, window: &mut Window, cx: &mut Context<Self>) {
338- let Some(community_id) = self.chat.selected_community_id else {368+ let Some(community_id) = self.chat.session.selected_community_id else {
339 return;369 return;
340 };370 };
341- let network = self.network.clone();371+ let uploads: Vec<_> = paths
342- let maximum = self372+ .into_iter()
343- .server373+ .map(|path| (path.clone(), self.upload(community_id, path, cx)))
344- .as_ref()374+ .collect();
345- .map(|settings| settings.max_attachment_bytes);
346 375
347 cx.spawn_in(window, async move |this, cx| {376 cx.spawn_in(window, async move |this, cx| {
348- for path in paths {377+ for (path, upload) in uploads {
349- let result =378+ let result = upload.await;
350- upload_file(&this, &network, community_id, path.clone(), maximum, cx).await;
351 if Store::Media.holds(&path) {379 if Store::Media.holds(&path) {
352 let _ = std::fs::remove_file(&path);380 let _ = std::fs::remove_file(&path);
353 }381 }
354 let _ = this.update(cx, |yumush, cx| {382 let _ = this.update(cx, |yumush, cx| {
355- if let Ok(attachment) = &result {383+ if let Ok(attachment) = &result
356- yumush.chat.media.pending.push(attachment.clone());384+ && yumush.chat.session.selected_community_id == Some(community_id)
385+ {
386+ yumush.chat.session.media.pending.push(attachment.clone());
357 }387 }
358 cx.notify();388 cx.notify();
359 });389 });
@@ -365,8 +395,32 @@ impl Yumush {
365 .detach();395 .detach();
366 }396 }
367 397
398+ pub(super) fn upload(
399+ &mut self,
400+ community_id: Id,
401+ path: PathBuf,
402+ cx: &mut Context<Self>,
403+ ) -> Task<Result<Attachment, Fail>> {
404+ let network = self.network.clone();
405+ let maximum = self
406+ .server
407+ .as_ref()
408+ .map(|settings| settings.max_attachment_bytes);
409+ self.chat.session.media.uploading += 1;
410+ cx.notify();
411+ cx.spawn(async move |this, cx| {
412+ let uploaded = network.upload_attachment(community_id, path, maximum).await;
413+ let _ = this.update(cx, |yumush, cx| {
414+ yumush.chat.session.media.uploading -= 1;
415+ cx.notify();
416+ });
417+ uploaded
418+ })
419+ }
420+
368 fn remove_pending(&mut self, attachment_id: Id, cx: &mut Context<Self>) {421 fn remove_pending(&mut self, attachment_id: Id, cx: &mut Context<Self>) {
369 self.chat422 self.chat
423+ .session
370 .media424 .media
371 .pending425 .pending
372 .retain(|attachment| attachment.id != attachment_id);426 .retain(|attachment| attachment.id != attachment_id);
@@ -386,10 +440,14 @@ impl Yumush {
386 return Ok(path);440 return Ok(path);
387 }441 }
388 let bytes = network.download_attachment(attachment.id, false).await?;442 let bytes = network.download_attachment(attachment.id, false).await?;
443+ let temp =
444+ path.with_extension(format!("{}.part", TEMP.fetch_add(1, Ordering::Relaxed)));
389 cx.background_executor()445 cx.background_executor()
390 .spawn({446 .spawn({
391 let path = path.clone();447 let path = path.clone();
392- async move { std::fs::write(&path, bytes) }448+ async move {
449+ std::fs::write(&temp, bytes).and_then(|()| std::fs::rename(&temp, &path))
450+ }
393 })451 })
394 .await452 .await
395 .map_err(|_| Fail::Protocol)?;453 .map_err(|_| Fail::Protocol)?;
@@ -398,7 +456,7 @@ impl Yumush {
398 }456 }
399 457
400 fn open_attachment(458 fn open_attachment(
401- &self,459+ &mut self,
402 attachment: &Attachment,460 attachment: &Attachment,
403 window: &mut Window,461 window: &mut Window,
404 cx: &mut Context<Self>,462 cx: &mut Context<Self>,
@@ -414,7 +472,7 @@ impl Yumush {
414 }472 }
415 473
416 fn save_attachment(474 fn save_attachment(
417- &self,475+ &mut self,
418 attachment: &Attachment,476 attachment: &Attachment,
419 window: &mut Window,477 window: &mut Window,
420 cx: &mut Context<Self>,478 cx: &mut Context<Self>,
@@ -437,20 +495,16 @@ impl Yumush {
437 }495 }
438 496
439 fn play(&mut self, attachment: &Attachment, window: &mut Window, cx: &mut Context<Self>) {497 fn play(&mut self, attachment: &Attachment, window: &mut Window, cx: &mut Context<Self>) {
440- if let Some(playing) = &self.chat.media.playing498+ let playing = &self.chat.session.media.playing;
441- && playing.attachment_id == attachment.id499+ if playing.id() == Some(attachment.id) {
442- {500+ if let Some(player) = playing.player() {
443- if let PlayState::Ready { player, .. } = &playing.state {
444 player.toggle();501 player.toggle();
445 }502 }
446 cx.notify();503 cx.notify();
447 return;504 return;
448 }505 }
449 self.stop_playing(cx);506 self.stop_playing(cx);
450- self.chat.media.playing = Some(Playing {507+ self.chat.session.media.playing = Playing::Loading(attachment.id);
451- attachment_id: attachment.id,
452- state: PlayState::Loading,
453- });
454 cx.notify();508 cx.notify();
455 509
456 let fetched = self.fetch_file(attachment, cx);510 let fetched = self.fetch_file(attachment, cx);
@@ -466,19 +520,14 @@ impl Yumush {
466 Err(error) => Err(error.to_string()),520 Err(error) => Err(error.to_string()),
467 };521 };
468 let _ = this.update_in(cx, |yumush, window, cx| {522 let _ = this.update_in(cx, |yumush, window, cx| {
469- let current = yumush523+ if !matches!(yumush.chat.session.media.playing, Playing::Loading(id) if id == attachment_id)
470- .chat524+ {
471- .media
472- .playing
473- .as_ref()
474- .is_some_and(|playing| playing.attachment_id == attachment_id);
475- if !current {
476 return;525 return;
477 }526 }
478 match opened {527 match opened {
479 Ok(player) => yumush.start_player(attachment_id, player, cx),528 Ok(player) => yumush.start_player(attachment_id, player, cx),
480 Err(error) => {529 Err(error) => {
481- yumush.chat.media.playing = None;530+ yumush.chat.session.media.playing = Playing::Idle;
482 window.push_notification(Notification::error(error), cx);531 window.push_notification(Notification::error(error), cx);
483 }532 }
484 }533 }
@@ -498,40 +547,36 @@ impl Yumush {
498 yumush.seek_playing(value.start(), cx);547 yumush.seek_playing(value.start(), cx);
499 });548 });
500 player.play();549 player.play();
501- self.chat.media.playing = Some(Playing {550+ self.chat.session.media.playing = Playing::Ready {
502- attachment_id,551+ id: attachment_id,
503- state: PlayState::Ready {552+ player,
504- player,553+ frame: None,
505- frame: None,554+ generation: 0,
506- generation: 0,555+ seek,
507- seek,556+ _subscription: subscription,
508- _subscription: subscription,557+ };
509- },
510- });
511 }558 }
512 559
513 pub(super) fn media_playing(&self) -> bool {560 pub(super) fn media_playing(&self) -> bool {
514- matches!(561+ self.chat
515- &self.chat.media.playing,562+ .session
516- Some(Playing {563+ .media
517- state: PlayState::Ready { player, .. },564+ .playing
518- ..565+ .player()
519- }) if player.playing()566+ .is_some_and(|player| player.playing())
520- )
521 }567 }
522 568
523 pub(super) fn tick_player(&mut self, window: &mut Window, cx: &mut Context<Self>) {569 pub(super) fn tick_player(&mut self, window: &mut Window, cx: &mut Context<Self>) {
524- let Some(Playing {570+ for frame in self.chat.session.media.drain_retired() {
525- state:571+ cx.drop_image(frame, Some(&mut *window));
526- PlayState::Ready {572+ }
527- player,573+ let Playing::Ready {
528- frame,574+ player,
529- generation,575+ frame,
530- seek,576+ generation,
531- ..577+ seek,
532- },
533 ..578 ..
534- }) = &mut self.chat.media.playing579+ } = &mut self.chat.session.media.playing
535 else {580 else {
536 return;581 return;
537 };582 };
@@ -542,8 +587,9 @@ impl Yumush {
542 && next.generation != *generation587 && next.generation != *generation
543 {588 {
544 *generation = next.generation;589 *generation = next.generation;
545- if let Some(old) = std::mem::replace(frame, to_render_image(&next)) {590+ let image = into_render_image(next);
546- cx.drop_image(old, Some(window));591+ if let Some(old) = std::mem::replace(frame, image) {
592+ cx.drop_image(old, Some(&mut *window));
547 }593 }
548 }594 }
549 let position = player.position().as_secs_f32();595 let position = player.position().as_secs_f32();
@@ -552,24 +598,15 @@ impl Yumush {
552 }598 }
553 599
554 fn seek_playing(&mut self, seconds: f32, cx: &mut Context<Self>) {600 fn seek_playing(&mut self, seconds: f32, cx: &mut Context<Self>) {
555- if let Some(Playing {601+ if let Some(player) = self.chat.session.media.playing.player() {
556- state: PlayState::Ready { player, .. },
557- ..
558- }) = &self.chat.media.playing
559- {
560 player.seek(Duration::from_secs_f32(seconds.max(0.)));602 player.seek(Duration::from_secs_f32(seconds.max(0.)));
561 }603 }
562 cx.notify();604 cx.notify();
563 }605 }
564 606
565 pub(super) fn stop_playing(&mut self, cx: &mut Context<Self>) {607 pub(super) fn stop_playing(&mut self, cx: &mut Context<Self>) {
566- if let Some(Playing {608+ self.chat.session.media.stop();
567- state: PlayState::Ready {609+ for frame in self.chat.session.media.drain_retired() {
568- frame: Some(frame), ..
569- },
570- ..
571- }) = self.chat.media.playing.take()
572- {
573 cx.defer(move |cx| cx.drop_image(frame, None));610 cx.defer(move |cx| cx.drop_image(frame, None));
574 }611 }
575 }612 }
@@ -579,7 +616,7 @@ pub fn attachments(
579 attachments: &[Attachment],616 attachments: &[Attachment],
580 media: &Media,617 media: &Media,
581 entity: &Entity<Yumush>,618 entity: &Entity<Yumush>,
582- palette: Palette,619+ t: Tokens,
583 ) -> Option<impl IntoElement> {620 ) -> Option<impl IntoElement> {
584 if attachments.is_empty() {621 if attachments.is_empty() {
585 return None;622 return None;
@@ -588,7 +625,7 @@ pub fn attachments(
588 div().flex().flex_col().gap(px(space::SM)).children(625 div().flex().flex_col().gap(px(space::SM)).children(
589 attachments626 attachments
590 .iter()627 .iter()
591- .map(|attachment| attachment_view(attachment, media, entity, palette)),628+ .map(|attachment| attachment_view(attachment, media, entity, t)),
592 ),629 ),
593 )630 )
594 }631 }
@@ -597,14 +634,14 @@ fn attachment_view(
597 attachment: &Attachment,634 attachment: &Attachment,
598 media: &Media,635 media: &Media,
599 entity: &Entity<Yumush>,636 entity: &Entity<Yumush>,
600- palette: Palette,637+ t: Tokens,
601 ) -> gpui_kit::AnyElement {638 ) -> gpui_kit::AnyElement {
602 match attachment.kind {639 match attachment.kind {
603- AttachmentKind::Image => image_view(attachment, media, entity, palette).into_any_element(),640+ AttachmentKind::Image => image_view(attachment, media, entity, t).into_any_element(),
604 AttachmentKind::Video | AttachmentKind::Audio => {641 AttachmentKind::Video | AttachmentKind::Audio => {
605- player_view(attachment, media, entity, palette).into_any_element()642+ player_view(attachment, media, entity, t).into_any_element()
606 }643 }
607- AttachmentKind::File => file_view(attachment, entity, palette).into_any_element(),644+ AttachmentKind::File => file_view(attachment, entity, t).into_any_element(),
608 }645 }
609 }646 }
610 647
@@ -624,19 +661,17 @@ fn image_view(
624 attachment: &Attachment,661 attachment: &Attachment,
625 media: &Media,662 media: &Media,
626 entity: &Entity<Yumush>,663 entity: &Entity<Yumush>,
627- palette: Palette,664+ t: Tokens,
628 ) -> impl IntoElement {665 ) -> impl IntoElement {
629 let (width, height) = fit(attachment.width, attachment.height, IMAGE_BOX);666 let (width, height) = fit(attachment.width, attachment.height, IMAGE_BOX);
630- let open = on_attachment(entity, attachment, |yumush, attachment, window, cx| {667+ let open = on_attachment(entity, attachment, Yumush::open_attachment);
631- yumush.open_attachment(attachment, window, cx)
632- });
633 div()668 div()
634 .id(format!("attachment_{}", attachment.id))669 .id(format!("attachment_{}", attachment.id))
635 .w(px(width))670 .w(px(width))
636 .h(px(height))671 .h(px(height))
637 .rounded(px(radius::MD))672 .rounded(px(radius::MD))
638 .overflow_hidden()673 .overflow_hidden()
639- .bg(palette.field)674+ .bg(t.raise())
640 .cursor_pointer()675 .cursor_pointer()
641 .on_click(move |_, window, cx| open(window, cx))676 .on_click(move |_, window, cx| open(window, cx))
642 .children(677 .children(
@@ -647,7 +682,7 @@ fn image_view(
647 )682 )
648 }683 }
649 684
650-fn card(palette: Palette) -> gpui_kit::Div {685+fn card(t: Tokens) -> gpui_kit::Div {
651 div()686 div()
652 .max_w(px(VIDEO_BOX.0))687 .max_w(px(VIDEO_BOX.0))
653 .flex()688 .flex()
@@ -656,10 +691,10 @@ fn card(palette: Palette) -> gpui_kit::Div {
656 .px(px(space::MD))691 .px(px(space::MD))
657 .py(px(space::MD))692 .py(px(space::MD))
658 .rounded(px(radius::MD))693 .rounded(px(radius::MD))
659- .bg(palette.panel)694+ .bg(t.ground())
660 }695 }
661 696
662-fn name_block(attachment: &Attachment, detail: String, palette: Palette) -> impl IntoElement {697+fn name_block(attachment: &Attachment, detail: String, t: Tokens) -> impl IntoElement {
663 div()698 div()
664 .flex_1()699 .flex_1()
665 .min_w_0()700 .min_w_0()
@@ -668,7 +703,7 @@ fn name_block(attachment: &Attachment, detail: String, palette: Palette) -> impl
668 .child(703 .child(
669 div()704 div()
670 .min_w_0()705 .min_w_0()
671- .text_color(palette.text)706+ .text_color(t.paper())
672 .child(super::glyph::line(707 .child(super::glyph::line(
673 attachment.name.clone().into(),708 attachment.name.clone().into(),
674 super::text(super::style::text::UI),709 super::text(super::style::text::UI),
@@ -677,7 +712,7 @@ fn name_block(attachment: &Attachment, detail: String, palette: Palette) -> impl
677 .child(712 .child(
678 div()713 div()
679 .text_size(text(text::CAPTION))714 .text_size(text(text::CAPTION))
680- .text_color(palette.muted)715+ .text_color(t.dim())
681 .child(detail),716 .child(detail),
682 )717 )
683 }718 }
@@ -686,7 +721,7 @@ fn icon_button(
686 id: String,721 id: String,
687 icon: IconName,722 icon: IconName,
688 tip: &'static str,723 tip: &'static str,
689- palette: Palette,724+ t: Tokens,
690 on_click: impl Fn(&mut Window, &mut App) + 'static,725 on_click: impl Fn(&mut Window, &mut App) + 'static,
691 ) -> impl IntoElement {726 ) -> impl IntoElement {
692 super::parts::icon_button(727 super::parts::icon_button(
@@ -695,31 +730,25 @@ fn icon_button(
695 tip,730 tip,
696 super::parts::Tone::Idle,731 super::parts::Tone::Idle,
697 super::parts::Scale::Normal,732 super::parts::Scale::Normal,
698- palette.tokens,733+ t,
699 on_click,734 on_click,
700 )735 )
701 }736 }
702 737
703-fn file_view(738+fn file_view(attachment: &Attachment, entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
704- attachment: &Attachment,739+ card(t)
705- entity: &Entity<Yumush>,
706- palette: Palette,
707-) -> impl IntoElement {
708- card(palette)
709 .child(740 .child(
710 Icon::new(IconName::File)741 Icon::new(IconName::File)
711 .size(px(size::ICON))742 .size(px(size::ICON))
712- .text_color(palette.muted),743+ .text_color(t.dim()),
713 )744 )
714- .child(name_block(attachment, storage(attachment.size), palette))745+ .child(name_block(attachment, storage(attachment.size), t))
715 .child(icon_button(746 .child(icon_button(
716 format!("save_{}", attachment.id),747 format!("save_{}", attachment.id),
717 IconName::ArrowDown,748 IconName::ArrowDown,
718 w().media_view.save,749 w().media_view.save,
719- palette,750+ t,
720- on_attachment(entity, attachment, |yumush, attachment, window, cx| {751+ on_attachment(entity, attachment, Yumush::save_attachment),
721- yumush.save_attachment(attachment, window, cx)
722- }),
723 ))752 ))
724 }753 }
725 754
@@ -727,14 +756,12 @@ fn player_view(
727 attachment: &Attachment,756 attachment: &Attachment,
728 media: &Media,757 media: &Media,
729 entity: &Entity<Yumush>,758 entity: &Entity<Yumush>,
730- palette: Palette,759+ t: Tokens,
731 ) -> impl IntoElement {760 ) -> impl IntoElement {
732- let state = media761+ let state = Some(&media.playing).filter(|playing| playing.id() == Some(attachment.id));
733- .playing762+ let playing = state
734- .as_ref()763+ .and_then(Playing::player)
735- .filter(|playing| playing.attachment_id == attachment.id)764+ .is_some_and(|player| player.playing());
736- .map(|playing| &playing.state);
737- let playing = matches!(state, Some(PlayState::Ready { player, .. }) if player.playing());
738 let toggle = icon_button(765 let toggle = icon_button(
739 format!("play_{}_{playing}", attachment.id),766 format!("play_{}_{playing}", attachment.id),
740 if playing {767 if playing {
@@ -747,55 +774,52 @@ fn player_view(
747 } else {774 } else {
748 w().media_view.play775 w().media_view.play
749 },776 },
750- palette,777+ t,
751- on_attachment(entity, attachment, |yumush, attachment, window, cx| {778+ on_attachment(entity, attachment, Yumush::play),
752- yumush.play(attachment, window, cx)
753- }),
754 );779 );
755 let voice = note::is_voice_note(attachment);780 let voice = note::is_voice_note(attachment);
756 let detail = match state {781 let detail = match state {
757- Some(PlayState::Loading) => "…".to_string(),782+ Some(Playing::Loading(_)) => "…".to_string(),
758- Some(PlayState::Ready { player, .. }) => format!(783+ Some(Playing::Ready { player, .. }) => format!(
759 "{} / {}",784 "{} / {}",
760 time_text(player.position()),785 time_text(player.position()),
761 time_text(player.info().duration.unwrap_or_default())786 time_text(player.info().duration.unwrap_or_default())
762 ),787 ),
763- None if voice => media788+ Some(Playing::Idle) | None if voice => media
764 .waveforms789 .waveforms
765 .get(&attachment.id)790 .get(&attachment.id)
766 .map_or("…".to_string(), |waveform| time_text(waveform.duration)),791 .map_or("…".to_string(), |waveform| time_text(waveform.duration)),
767- None => storage(attachment.size),792+ Some(Playing::Idle) | None => storage(attachment.size),
768 };793 };
769- let controls = card(palette)794+ let controls = if voice {
770- .child(toggle)795+ card(t)
771- .when(voice, |this| {796+ .child(toggle)
772- this.child(waveform_view(attachment, media, entity, state, palette))797+ .child(waveform_view(attachment, media, entity, state, t))
773- .child(798+ .child(
774- div()799+ div()
775- .text_size(text(text::CAPTION))800+ .text_size(text(text::CAPTION))
776- .text_color(palette.muted)801+ .text_color(t.dim())
777- .child(detail.clone()),802+ .child(detail),
778- )803+ )
779- })804+ } else {
780- .when(!voice, |this| {805+ let seek = match state {
781- this.child(name_block(attachment, detail, palette))806+ Some(Playing::Ready { seek, .. }) => Some(seek),
782- })807+ _ => None,
783- .when_some(808+ };
784- match state {809+ card(t)
785- Some(PlayState::Ready { seek, .. }) if !voice => Some(seek),810+ .child(toggle)
786- _ => None,811+ .child(name_block(attachment, detail, t))
787- },812+ .when_some(seek, |this, seek| {
788- |this, seek| {
789 this.child(813 this.child(
790 div()814 div()
791 .w(px(size::THUMB))815 .w(px(size::THUMB))
792- .child(super::parts::slider(seek, palette.tokens)),816+ .child(super::parts::slider(seek, t)),
793 )817 )
794- },818+ })
795- );819+ };
796 820
797 let video = match state {821 let video = match state {
798- Some(PlayState::Ready { player, frame, .. }) => player822+ Some(Playing::Ready { player, frame, .. }) => player
799 .info()823 .info()
800 .video824 .video
801 .map(|(width, height)| (frame, width, height)),825 .map(|(width, height)| (frame, width, height)),
@@ -814,7 +838,7 @@ fn player_view(
814 .h(px(height))838 .h(px(height))
815 .rounded(px(radius::MD))839 .rounded(px(radius::MD))
816 .overflow_hidden()840 .overflow_hidden()
817- .bg(palette.tokens.ground())841+ .bg(t.ground())
818 .children(frame.clone().map(|frame| img(frame).size_full())),842 .children(frame.clone().map(|frame| img(frame).size_full())),
819 )843 )
820 })844 })
@@ -825,42 +849,40 @@ fn waveform_view(
825 attachment: &Attachment,849 attachment: &Attachment,
826 media: &Media,850 media: &Media,
827 entity: &Entity<Yumush>,851 entity: &Entity<Yumush>,
828- state: Option<&PlayState>,852+ state: Option<&Playing>,
829- palette: Palette,853+ t: Tokens,
830 ) -> impl IntoElement {854 ) -> impl IntoElement {
831 let levels = media855 let levels = media
832 .waveforms856 .waveforms
833 .get(&attachment.id)857 .get(&attachment.id)
834 .map_or(&[][..], |waveform| waveform.peaks.as_slice());858 .map_or(&[][..], |waveform| waveform.peaks.as_slice());
835 match state {859 match state {
836- Some(PlayState::Ready { player, .. }) => {860+ Some(Playing::Ready { player, .. }) => {
837 let duration = duration_secs(player);861 let duration = duration_secs(player);
838 let progress = player.position().as_secs_f32() / duration;862 let progress = player.position().as_secs_f32() / duration;
839 let entity = entity.clone();863 let entity = entity.clone();
840- bars(levels, progress, palette, move |index, _, cx| {864+ bars(levels, progress, t, true, move |index, _, cx| {
841 entity.update(cx, |yumush, cx| {865 entity.update(cx, |yumush, cx| {
842 yumush.seek_playing(index as f32 / note::BARS as f32 * duration, cx)866 yumush.seek_playing(index as f32 / note::BARS as f32 * duration, cx)
843 })867 })
844 })868 })
845 }869 }
846 _ => {870 _ => {
847- let play = on_attachment(entity, attachment, |yumush, attachment, window, cx| {871+ let play = on_attachment(entity, attachment, Yumush::play);
848- yumush.play(attachment, window, cx)872+ bars(levels, 0., t, false, move |_, window, cx| play(window, cx))
849- });
850- bars(levels, 0., palette, move |_, window, cx| play(window, cx))
851 }873 }
852 }874 }
853 }875 }
854 876
855-pub fn embeds(message: &Message, media: &Media, palette: Palette) -> Vec<impl IntoElement> {877+pub fn embeds(message: &Message, media: &Media, t: Tokens) -> Vec<impl IntoElement> {
856 embed::urls(&message.body)878 embed::urls(&message.body)
857 .into_iter()879 .into_iter()
858 .filter_map(|url| media.embeds.get(&url))880 .filter_map(|url| media.embeds.get(&url))
859- .map(|loaded| embed_view(loaded, palette))881+ .map(|loaded| embed_view(loaded, t))
860 .collect()882 .collect()
861 }883 }
862 884
863-fn embed_view(loaded: &LoadedEmbed, palette: Palette) -> impl IntoElement {885+fn embed_view(loaded: &LoadedEmbed, t: Tokens) -> impl IntoElement {
864 let embed = &loaded.embed;886 let embed = &loaded.embed;
865 let url = embed.url.clone();887 let url = embed.url.clone();
866 let image = loaded.image.clone().map(|image| {888 let image = loaded.image.clone().map(|image| {
@@ -890,19 +912,19 @@ fn embed_view(loaded: &LoadedEmbed, palette: Palette) -> impl IntoElement {
890 .py(px(space::MD))912 .py(px(space::MD))
891 .rounded(px(radius::MD))913 .rounded(px(radius::MD))
892 .border_l_2()914 .border_l_2()
893- .border_color(palette.border)915+ .border_color(t.thread())
894- .bg(palette.panel)916+ .bg(t.ground())
895 .children(embed.site.clone().map(|site| {917 .children(embed.site.clone().map(|site| {
896 div()918 div()
897 .text_size(text(text::CAPTION))919 .text_size(text(text::CAPTION))
898- .text_color(palette.muted)920+ .text_color(t.dim())
899 .child(site)921 .child(site)
900 }))922 }))
901 .children(embed.title.clone().map(|title| {923 .children(embed.title.clone().map(|title| {
902 div()924 div()
903 .id(format!("embed_{url}"))925 .id(format!("embed_{url}"))
904 .font_weight(FontWeight::SEMIBOLD)926 .font_weight(FontWeight::SEMIBOLD)
905- .text_color(palette.text)927+ .text_color(t.paper())
906 .cursor_pointer()928 .cursor_pointer()
907 .hover(|style| style.underline())929 .hover(|style| style.underline())
908 .on_click(move |_, _, cx| cx.open_url(&url))930 .on_click(move |_, _, cx| cx.open_url(&url))
@@ -914,7 +936,7 @@ fn embed_view(loaded: &LoadedEmbed, palette: Palette) -> impl IntoElement {
914 .children(embed.description.clone().map(|description| {936 .children(embed.description.clone().map(|description| {
915 div()937 div()
916 .text_size(text(text::LABEL))938 .text_size(text(text::LABEL))
917- .text_color(palette.body)939+ .text_color(t.paper())
918 .line_clamp(3)940 .line_clamp(3)
919 .child(super::glyph::wrapped(941 .child(super::glyph::wrapped(
920 description.into(),942 description.into(),
@@ -924,11 +946,7 @@ fn embed_view(loaded: &LoadedEmbed, palette: Palette) -> impl IntoElement {
924 .children(image)946 .children(image)
925 }947 }
926 948
927-pub fn pending_row(949+pub fn pending_row(media: &Media, entity: &Entity<Yumush>, t: Tokens) -> Option<impl IntoElement> {
928- media: &Media,
929- entity: &Entity<Yumush>,
930- palette: Palette,
931-) -> Option<impl IntoElement> {
932 if media.pending.is_empty() && !media.uploading() {950 if media.pending.is_empty() && !media.uploading() {
933 return None;951 return None;
934 }952 }
@@ -949,22 +967,16 @@ pub fn pending_row(
949 .pr(px(space::XS))967 .pr(px(space::XS))
950 .py(px(space::XS))968 .py(px(space::XS))
951 .rounded(px(radius::MD))969 .rounded(px(radius::MD))
952- .bg(palette.hover)970+ .bg(t.hov())
953 .text_size(text(text::CAPTION))971 .text_size(text(text::CAPTION))
954 .child(div().max_w(px(size::SIDEBAR)).child(super::glyph::line(972 .child(div().max_w(px(size::SIDEBAR)).child(super::glyph::line(
955 attachment.name.clone().into(),973 attachment.name.clone().into(),
956 super::text(super::style::text::CAPTION),974 super::text(super::style::text::CAPTION),
957 )))975 )))
958 .child(976 .child(
959- clickable(977+ clickable(format!("unattach_{}", attachment.id), t, move |_, cx| {
960- format!("unattach_{}", attachment.id),978+ entity.update(cx, |yumush, cx| yumush.remove_pending(attachment_id, cx))
961- palette,979+ })
962- move |_, cx| {
963- entity.update(cx, |yumush, cx| {
964- yumush.remove_pending(attachment_id, cx)
965- })
966- },
967- )
968 .tip(w().media_view.remove)980 .tip(w().media_view.remove)
969 .size(px(size::CHIP))981 .size(px(size::CHIP))
970 .flex()982 .flex()
@@ -980,7 +992,7 @@ pub fn pending_row(
980 .px(px(space::MD))992 .px(px(space::MD))
981 .py(px(space::XS))993 .py(px(space::XS))
982 .text_size(text(text::CAPTION))994 .text_size(text(text::CAPTION))
983- .text_color(palette.muted)995+ .text_color(t.dim())
984 .child("…"),996 .child("…"),
985 )997 )
986 }),998 }),
crates/client/src/gui/message_actions.rsmodified+131 -156
@@ -20,22 +20,22 @@ use gpui_kit::{
20 };20 };
21 21
22 use super::{22 use super::{
23- Palette, Trigger, Yumush, avatar,23+ Trigger, Yumush, avatar,
24- chat::{Chat, ReportTarget},24+ chat::{Armed, Chat, ReportTarget},
25 clickable,25 clickable,
26 composer::trigger_icon,26 composer::trigger_icon,
27 entity_action, millis_time, notify_error,27 entity_action, millis_time, notify_error,
28- parts::{Press, Scale, Tone, button, icon_button},28+ parts::{Press, Scale, Tone, button, icon_button, surface},
29 sidebar,29 sidebar,
30- style::{radius, size, space, text},30+ style::{Tokens, radius, size, space, text},
31- widget::{field, panel, search_text, spawn_done},31+ widget::{field, search_text, spawn_done},
32 };32 };
33 33
34 pub fn reactions(34 pub fn reactions(
35 message: &Message,35 message: &Message,
36 me: Option<&User>,36 me: Option<&User>,
37 entity: &Entity<Yumush>,37 entity: &Entity<Yumush>,
38- palette: Palette,38+ t: Tokens,
39 ) -> impl IntoElement {39 ) -> impl IntoElement {
40 let me_id = me.map(|me| me.id);40 let me_id = me.map(|me| me.id);
41 41
@@ -56,7 +56,7 @@ pub fn reactions(
56 56
57 clickable(57 clickable(
58 format!("reaction_{}_{}", message.id, reaction.emoji),58 format!("reaction_{}_{}", message.id, reaction.emoji),
59- palette,59+ t,
60 move |window, cx| {60 move |window, cx| {
61 let emoji = emoji.clone();61 let emoji = emoji.clone();
62 entity.update(cx, |yumush, cx| {62 entity.update(cx, |yumush, cx| {
@@ -71,23 +71,15 @@ pub fn reactions(
71 .px(px(space::SM))71 .px(px(space::SM))
72 .rounded_full()72 .rounded_full()
73 .border_1()73 .border_1()
74- .border_color(if mine { palette.accent } else { palette.border })74+ .border_color(if mine { t.paper() } else { t.thread() })
75- .bg(if mine {75+ .bg(if mine { t.press() } else { t.ground() })
76- palette.tokens.press()
77- } else {
78- palette.panel
79- })
80 .text_size(text(text::CAPTION))76 .text_size(text(text::CAPTION))
81 .child(super::glyph::picture(&chip_emoji, px(size::ICON_SM)))77 .child(super::glyph::picture(&chip_emoji, px(size::ICON_SM)))
82- .child(div().text_color(palette.muted).child(count.to_string()))78+ .child(div().text_color(t.dim()).child(count.to_string()))
83 }))79 }))
84 }80 }
85 81
86-pub fn react_popover(82+pub fn react_popover(message: &Message, entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
87- message: &Message,
88- entity: &Entity<Yumush>,
89- palette: Palette,
90-) -> impl IntoElement {
91 let message_id = message.id;83 let message_id = message.id;
92 let entity = entity.clone();84 let entity = entity.clone();
93 let reacting = entity.clone();85 let reacting = entity.clone();
@@ -96,7 +88,7 @@ pub fn react_popover(
96 .anchor(Anchor::BottomRight)88 .anchor(Anchor::BottomRight)
97 .on_open_change(move |open, _, cx| {89 .on_open_change(move |open, _, cx| {
98 reacting.update(cx, |yumush, cx| {90 reacting.update(cx, |yumush, cx| {
99- if track(&mut yumush.chat.reacting, message_id, *open) {91+ if track(&mut yumush.chat.session.reacting, message_id, *open) {
100 cx.notify();92 cx.notify();
101 }93 }
102 });94 });
@@ -106,11 +98,11 @@ pub fn react_popover(
106 format!("react_trigger_{}", message.id),98 format!("react_trigger_{}", message.id),
107 IconName::FaceSlightlySmiling,99 IconName::FaceSlightlySmiling,
108 24.,100 24.,
109- palette,101+ t,
110 ))102 ))
111 .content(move |_, _, cx| {103 .content(move |_, _, cx| {
112 let popover = cx.entity();104 let popover = cx.entity();
113- panel(palette)105+ surface(t)
114 .flex()106 .flex()
115 .gap(px(space::XXS))107 .gap(px(space::XXS))
116 .p(px(space::XS))108 .p(px(space::XS))
@@ -119,7 +111,7 @@ pub fn react_popover(
119 let popover = popover.clone();111 let popover = popover.clone();
120 clickable(112 clickable(
121 format!("react_{emoji}_{message_id}"),113 format!("react_{emoji}_{message_id}"),
122- palette,114+ t,
123 move |window, cx| {115 move |window, cx| {
124 popover.update(cx, |state, cx| state.dismiss(window, cx));116 popover.update(cx, |state, cx| state.dismiss(window, cx));
125 entity.update(cx, |yumush, cx| {117 entity.update(cx, |yumush, cx| {
@@ -156,7 +148,7 @@ pub fn quote_line(
156 message: &Message,148 message: &Message,
157 chat: &Chat,149 chat: &Chat,
158 entity: &Entity<Yumush>,150 entity: &Entity<Yumush>,
159- palette: Palette,151+ t: Tokens,
160 ) -> Option<impl IntoElement> {152 ) -> Option<impl IntoElement> {
161 let frame = div()153 let frame = div()
162 .id(format!("quote_{}", message.id))154 .id(format!("quote_{}", message.id))
@@ -165,12 +157,14 @@ pub fn quote_line(
165 .gap(px(space::SM))157 .gap(px(space::SM))
166 .pl(px(space::SM))158 .pl(px(space::SM))
167 .border_l_2()159 .border_l_2()
168- .border_color(palette.border)160+ .border_color(t.thread())
169 .text_size(text(text::CAPTION))161 .text_size(text(text::CAPTION))
170- .text_color(palette.muted);162+ .text_color(t.dim());
171 let (quote, deleted) = match message.reply.as_ref()? {163 let (quote, deleted) = match message.reply.as_ref()? {
172 Reply::Quote(quote) => (quote, false),164 Reply::Quote(quote) => (quote, false),
173- Reply::Deleted(Some(quote)) if chat.revealed.contains(&quote.message_id) => (quote, true),165+ Reply::Deleted(Some(quote)) if chat.session.revealed.contains(&quote.message_id) => {
166+ (quote, true)
167+ }
174 Reply::Deleted(Some(quote)) => {168 Reply::Deleted(Some(quote)) => {
175 return Some(reveal(frame.italic(), quote.message_id, entity));169 return Some(reveal(frame.italic(), quote.message_id, entity));
176 }170 }
@@ -191,18 +185,18 @@ pub fn quote_line(
191 })185 })
192 .children(author.map(|user| {186 .children(author.map(|user| {
193 avatar(187 avatar(
194- palette,188+ t,
195 user,189 user,
196 px(size::ICON_SM),190 px(size::ICON_SM),
197 text(text::CAPTION),191 text(text::CAPTION),
198- &chat.avatars,192+ &chat.session.avatars,
199 )193 )
200 }))194 }))
201 .children(author.map(|user| {195 .children(author.map(|user| {
202 div()196 div()
203 .flex_shrink_0()197 .flex_shrink_0()
204 .font_weight(FontWeight::SEMIBOLD)198 .font_weight(FontWeight::SEMIBOLD)
205- .text_color(palette.tinted(user.id))199+ .text_color(t.person(user.id))
206 .child(user.username.clone())200 .child(user.username.clone())
207 }))201 }))
208 .child(div().flex_1().min_w_0().child(super::glyph::line(202 .child(div().flex_1().min_w_0().child(super::glyph::line(
@@ -218,19 +212,19 @@ fn reveal(frame: Stateful<Div>, message_id: Id, entity: &Entity<Yumush>) -> Stat
218 .cursor_pointer()212 .cursor_pointer()
219 .on_click(move |_, _, cx| {213 .on_click(move |_, _, cx| {
220 entity.update(cx, |yumush, cx| {214 entity.update(cx, |yumush, cx| {
221- yumush.chat.revealed.insert(message_id);215+ yumush.chat.session.revealed.insert(message_id);
222 cx.notify();216 cx.notify();
223 })217 })
224 })218 })
225 .child(w().message_actions.deleted)219 .child(w().message_actions.deleted)
226 }220 }
227 221
228-pub fn reveal_deleted(message_id: Id, entity: &Entity<Yumush>, palette: Palette) -> Stateful<Div> {222+pub fn reveal_deleted(message_id: Id, entity: &Entity<Yumush>, t: Tokens) -> Stateful<Div> {
229 reveal(223 reveal(
230 div()224 div()
231 .id(format!("reveal_{message_id}"))225 .id(format!("reveal_{message_id}"))
232 .italic()226 .italic()
233- .text_color(palette.muted),227+ .text_color(t.dim()),
234 message_id,228 message_id,
235 entity,229 entity,
236 )230 )
@@ -243,7 +237,7 @@ pub fn collapse_deleted(message_id: Id, entity: &Entity<Yumush>) -> Stateful<Div
243 .cursor_pointer()237 .cursor_pointer()
244 .on_click(move |_, _, cx| {238 .on_click(move |_, _, cx| {
245 entity.update(cx, |yumush, cx| {239 entity.update(cx, |yumush, cx| {
246- yumush.chat.revealed.remove(&message_id);240+ yumush.chat.session.revealed.remove(&message_id);
247 cx.notify();241 cx.notify();
248 })242 })
249 })243 })
@@ -254,7 +248,7 @@ pub fn edited_mark(
254 message: &Message,248 message: &Message,
255 builder: bool,249 builder: bool,
256 entity: &Entity<Yumush>,250 entity: &Entity<Yumush>,
257- palette: Palette,251+ t: Tokens,
258 ) -> AnyElement {252 ) -> AnyElement {
259 let message_id = message.id;253 let message_id = message.id;
260 if !builder {254 if !builder {
@@ -282,12 +276,13 @@ pub fn edited_mark(
282 let clock = yumush.settings.clock();276 let clock = yumush.settings.clock();
283 let mut edits = yumush277 let mut edits = yumush
284 .chat278 .chat
279+ .session
285 .edits280 .edits
286 .get(&message_id)281 .get(&message_id)
287 .cloned()282 .cloned()
288 .unwrap_or_default();283 .unwrap_or_default();
289 edits.sort_by_key(|edit| std::cmp::Reverse(edit.edited_at));284 edits.sort_by_key(|edit| std::cmp::Reverse(edit.edited_at));
290- panel(palette)285+ surface(t)
291 .flex()286 .flex()
292 .flex_col()287 .flex_col()
293 .gap(px(space::XS))288 .gap(px(space::XS))
@@ -301,7 +296,7 @@ pub fn edited_mark(
301 .child(296 .child(
302 div()297 div()
303 .flex_shrink_0()298 .flex_shrink_0()
304- .text_color(palette.muted)299+ .text_color(t.dim())
305 .child(millis_time(edit.edited_at, clock)),300 .child(millis_time(edit.edited_at, clock)),
306 )301 )
307 .child(div().min_w_0().child(edit.body))302 .child(div().min_w_0().child(edit.body))
@@ -310,10 +305,10 @@ pub fn edited_mark(
310 .into_any_element()305 .into_any_element()
311 }306 }
312 307
313-pub fn pin_mark(palette: Palette) -> impl IntoElement {308+pub fn pin_mark(t: Tokens) -> impl IntoElement {
314 div()309 div()
315 .flex_shrink_0()310 .flex_shrink_0()
316- .text_color(palette.muted)311+ .text_color(t.dim())
317 .child(super::parts::small_icon(IconName::Pin))312 .child(super::parts::small_icon(IconName::Pin))
318 }313 }
319 314
@@ -329,22 +324,18 @@ fn jump_row(
329 hit: &Hit,324 hit: &Hit,
330 entity: &Entity<Yumush>,325 entity: &Entity<Yumush>,
331 popover: &Entity<PopoverState>,326 popover: &Entity<PopoverState>,
332- palette: Palette,327+ t: Tokens,
333 ) -> Stateful<Div> {328 ) -> Stateful<Div> {
334 let entity = entity.clone();329 let entity = entity.clone();
335 let popover = popover.clone();330 let popover = popover.clone();
336 let message_id = hit.message_id;331 let message_id = hit.message_id;
337 332
338- clickable(333+ clickable(format!("{prefix}_{message_id}"), t, move |window, cx| {
339- format!("{prefix}_{message_id}"),334+ popover.update(cx, |state, cx| state.dismiss(window, cx));
340- palette,335+ entity.update(cx, |yumush, cx| {
341- move |window, cx| {336+ yumush.go_to_message(message_id, window, cx)
342- popover.update(cx, |state, cx| state.dismiss(window, cx));337+ });
343- entity.update(cx, |yumush, cx| {338+ })
344- yumush.go_to_message(message_id, window, cx)
345- });
346- },
347- )
348 .flex()339 .flex()
349 .gap(px(space::SM))340 .gap(px(space::SM))
350 .px(px(space::SM))341 .px(px(space::SM))
@@ -363,20 +354,16 @@ fn person_row(
363 user: &User,354 user: &User,
364 entity: &Entity<Yumush>,355 entity: &Entity<Yumush>,
365 popover: &Entity<PopoverState>,356 popover: &Entity<PopoverState>,
366- palette: Palette,357+ t: Tokens,
367 ) -> Stateful<Div> {358 ) -> Stateful<Div> {
368 let entity = entity.clone();359 let entity = entity.clone();
369 let popover = popover.clone();360 let popover = popover.clone();
370 let user_id = user.id;361 let user_id = user.id;
371 362
372- clickable(363+ clickable(format!("search_person_{user_id}"), t, move |window, cx| {
373- format!("search_person_{user_id}"),364+ popover.update(cx, |state, cx| state.dismiss(window, cx));
374- palette,365+ entity.update(cx, |yumush, cx| yumush.open_direct(user_id, window, cx));
375- move |window, cx| {366+ })
376- popover.update(cx, |state, cx| state.dismiss(window, cx));
377- entity.update(cx, |yumush, cx| yumush.open_direct(user_id, window, cx));
378- },
379- )
380 .flex()367 .flex()
381 .items_center()368 .items_center()
382 .gap(px(space::SM))369 .gap(px(space::SM))
@@ -390,24 +377,10 @@ pub fn search_popover(
390 chat: &Chat,377 chat: &Chat,
391 clock: &'static str,378 clock: &'static str,
392 entity: &Entity<Yumush>,379 entity: &Entity<Yumush>,
393- palette: Palette,380+ t: Tokens,
394 ) -> impl IntoElement {381 ) -> impl IntoElement {
395 let entity = entity.clone();382 let entity = entity.clone();
396 let input = chat.community_search.clone();383 let input = chat.community_search.clone();
397- let hits: Vec<Hit> = chat
398- .community_hits
399- .iter()
400- .map(|hit| Hit {
401- message_id: hit.message.id,
402- name: hit
403- .author
404- .as_ref()
405- .map(|user| user.username.clone())
406- .unwrap_or_default(),
407- time: Some(millis_time(hit.message.created_at, clock)),
408- body: message_text(&hit.message),
409- })
410- .collect();
411 384
412 Popover::new("search_popover")385 Popover::new("search_popover")
413 .anchor(Anchor::TopRight)386 .anchor(Anchor::TopRight)
@@ -423,10 +396,10 @@ pub fn search_popover(
423 .items_center()396 .items_center()
424 .gap(px(space::SM))397 .gap(px(space::SM))
425 .rounded(px(radius::MD))398 .rounded(px(radius::MD))
426- .bg(palette.tokens.raise())399+ .bg(t.raise())
427 .cursor_pointer()400 .cursor_pointer()
428 .text_size(text(text::UI))401 .text_size(text(text::UI))
429- .text_color(palette.tokens.faint())402+ .text_color(t.faint())
430 .child(super::parts::small_icon(IconName::Search))403 .child(super::parts::small_icon(IconName::Search))
431 .child(w().chat.find),404 .child(w().chat.find),
432 ))405 ))
@@ -437,11 +410,32 @@ pub fn search_popover(
437 }410 }
438 let query = search_text(&input, cx);411 let query = search_text(&input, cx);
439 let yumush = entity.read(cx);412 let yumush = entity.read(cx);
413+ let hits: Vec<Hit> = if query.is_empty() {
414+ Vec::new()
415+ } else {
416+ yumush
417+ .chat
418+ .session
419+ .community_hits
420+ .iter()
421+ .map(|hit| Hit {
422+ message_id: hit.message.id,
423+ name: hit
424+ .author
425+ .as_ref()
426+ .map(|user| user.username.clone())
427+ .unwrap_or_default(),
428+ time: Some(millis_time(hit.message.created_at, clock)),
429+ body: message_text(&hit.message),
430+ })
431+ .collect()
432+ };
440 let people: Vec<&User> = if query.is_empty() {433 let people: Vec<&User> = if query.is_empty() {
441 vec![]434 vec![]
442 } else {435 } else {
443 yumush436 yumush
444 .chat437 .chat
438+ .session
445 .members439 .members
446 .iter()440 .iter()
447 .map(|member| &member.user)441 .map(|member| &member.user)
@@ -451,24 +445,25 @@ pub fn search_popover(
451 .take(5)445 .take(5)
452 .collect()446 .collect()
453 };447 };
454- panel(palette)448+ surface(t)
455 .w(px(size::POPOVER))449 .w(px(size::POPOVER))
456 .p(px(space::XS))450 .p(px(space::XS))
457 .flex()451 .flex()
458 .flex_col()452 .flex_col()
459 .gap(px(space::XS))453 .gap(px(space::XS))
460- .child(sidebar::input_box(&input, palette))454+ .child(sidebar::input_box(&input, t))
461- .children((!people.is_empty()).then(|| {455+ .children(
462- super::parts::caption_head(w().message_actions.people, palette.tokens)456+ (!people.is_empty())
463- }))457+ .then(|| super::parts::caption_head(w().message_actions.people, t)),
458+ )
464 .children(people.iter().map(|user| {459 .children(people.iter().map(|user| {
465- person_row(user, &entity, &popover, palette)460+ person_row(user, &entity, &popover, t)
466 .child(avatar(461 .child(avatar(
467- palette,462+ t,
468 user,463 user,
469 px(size::ICON_SM),464 px(size::ICON_SM),
470 text(text::CAPTION),465 text(text::CAPTION),
471- &yumush.chat.avatars,466+ &yumush.chat.session.avatars,
472 ))467 ))
473 .child(468 .child(
474 div()469 div()
@@ -478,15 +473,14 @@ pub fn search_popover(
478 )473 )
479 }))474 }))
480 .children(475 .children(
481- (!query.is_empty() && !hits.is_empty())476+ (!hits.is_empty()).then(|| super::parts::caption_head(w().common.messages, t)),
482- .then(|| super::parts::caption_head(w().common.messages, palette.tokens)),
483 )477 )
484 .children(hits.iter().map(|hit| {478 .children(hits.iter().map(|hit| {
485- jump_row("search_hit", hit, &entity, &popover, palette)479+ jump_row("search_hit", hit, &entity, &popover, t)
486 .children(hit.time.as_ref().map(|time| {480 .children(hit.time.as_ref().map(|time| {
487 div()481 div()
488 .flex_shrink_0()482 .flex_shrink_0()
489- .text_color(palette.muted)483+ .text_color(t.dim())
490 .child(time.clone())484 .child(time.clone())
491 }))485 }))
492 .child(div().flex_1().min_w_0().child(super::glyph::line(486 .child(div().flex_1().min_w_0().child(super::glyph::line(
@@ -497,9 +491,10 @@ pub fn search_popover(
497 })491 })
498 }492 }
499 493
500-pub fn pins_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {494+pub fn pins_popover(chat: &Chat, entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
501 let entity = entity.clone();495 let entity = entity.clone();
502 let pins: Vec<Hit> = chat496 let pins: Vec<Hit> = chat
497+ .session
503 .pins498 .pins
504 .iter()499 .iter()
505 .map(|pin| Hit {500 .map(|pin| Hit {
@@ -516,23 +511,25 @@ pub fn pins_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i
516 Popover::new("pins_popover")511 Popover::new("pins_popover")
517 .anchor(Anchor::TopRight)512 .anchor(Anchor::TopRight)
518 .appearance(false)513 .appearance(false)
519- .trigger(trigger_icon("pins_trigger", IconName::Pin, 24., palette))514+ .trigger(trigger_icon("pins_trigger", IconName::Pin, 24., t))
520 .content(move |_, _, cx| {515 .content(move |_, _, cx| {
521 let popover = cx.entity();516 let popover = cx.entity();
522- panel(palette)517+ surface(t)
523 .w(px(size::POPOVER))518 .w(px(size::POPOVER))
524 .p(px(space::XS))519 .p(px(space::XS))
525 .flex()520 .flex()
526 .flex_col()521 .flex_col()
527 .gap(px(space::XXS))522 .gap(px(space::XXS))
528 .children(pins.iter().map(|hit| {523 .children(pins.iter().map(|hit| {
529- jump_row("pin_hit", hit, &entity, &popover, palette).child(524+ jump_row("pin_hit", hit, &entity, &popover, t).child(
530- div().flex_1().min_w_0().text_color(palette.muted).child(525+ div()
531- super::glyph::line(526+ .flex_1()
527+ .min_w_0()
528+ .text_color(t.dim())
529+ .child(super::glyph::line(
532 hit.body.clone().into(),530 hit.body.clone().into(),
533 super::text(super::style::text::UI),531 super::text(super::style::text::UI),
534- ),532+ )),
535- ),
536 )533 )
537 }))534 }))
538 })535 })
@@ -543,7 +540,7 @@ pub fn actions(
543 chat: &Chat,540 chat: &Chat,
544 me: Option<&User>,541 me: Option<&User>,
545 entity: &Entity<Yumush>,542 entity: &Entity<Yumush>,
546- palette: Palette,543+ t: Tokens,
547 ) -> impl IntoElement {544 ) -> impl IntoElement {
548 let mine = me.is_some_and(|me| me.id == message.user_id);545 let mine = me.is_some_and(|me| me.id == message.user_id);
549 let editable = mine && !message.body.is_empty() && message.snippet.is_none();546 let editable = mine && !message.body.is_empty() && message.snippet.is_none();
@@ -551,11 +548,22 @@ pub fn actions(
551 let pinnable = me.is_some_and(|me| chat.can_pin(me));548 let pinnable = me.is_some_and(|me| chat.can_pin(me));
552 let reportable = me.is_some_and(|me| me.id != message.user_id);549 let reportable = me.is_some_and(|me| me.id != message.user_id);
553 let id = message.id;550 let id = message.id;
554- let armed = chat.pending_message_delete == Some(id);551+ let armed = chat.session.armed == Some(Armed::DeleteMessage(id));
555- let shown = armed || chat.hover_row == Some(id) || chat.engaged(id);552+ let shown = armed || chat.session.hover_row == Some(id) || chat.engaged(id);
556 let hover = entity.clone();553 let hover = entity.clone();
554+ let (pin_tip, pin_icon) = if message.pinned {
555+ (w().message_actions.unpin, IconName::PinOff)
556+ } else {
557+ (w().message_actions.pin, IconName::Pin)
558+ };
559+ let button = |name: &'static str,
560+ tip: &'static str,
561+ icon: IconName,
562+ run: fn(&mut Yumush, Id, &mut Window, &mut Context<Yumush>)| {
563+ action(entity, t, id, name, tip, icon, run)
564+ };
557 565
558- panel(palette)566+ surface(t)
559 .id(format!("message_actions_{id}"))567 .id(format!("message_actions_{id}"))
560 .flex()568 .flex()
561 .items_center()569 .items_center()
@@ -571,75 +579,46 @@ pub fn actions(
571 .on_hover(move |hovered, _, cx| {579 .on_hover(move |hovered, _, cx| {
572 if shown || !*hovered {580 if shown || !*hovered {
573 hover.update(cx, |yumush, cx| {581 hover.update(cx, |yumush, cx| {
574- if track(&mut yumush.chat.hover_bar, id, *hovered) {582+ if track(&mut yumush.chat.session.hover_bar, id, *hovered) {
575 cx.notify();583 cx.notify();
576 }584 }
577 });585 });
578 }586 }
579 })587 })
580- .child(action(588+ .child(button(
581- entity,
582- palette,
583- id,
584 "reply",589 "reply",
585 w().message_actions.reply,590 w().message_actions.reply,
586 IconName::Reply,591 IconName::Reply,
587 |yumush, id, window, cx| yumush.reply(id, window, cx),592 |yumush, id, window, cx| yumush.reply(id, window, cx),
588 ))593 ))
589- .child(react_popover(message, entity, palette))594+ .child(react_popover(message, entity, t))
590 .children(editable.then(|| {595 .children(editable.then(|| {
591- action(596+ button(
592- entity,
593- palette,
594- id,
595 "edit",597 "edit",
596 w().message_actions.edit,598 w().message_actions.edit,
597 IconName::Pencil,599 IconName::Pencil,
598 |yumush, id, window, cx| yumush.edit(id, window, cx),600 |yumush, id, window, cx| yumush.edit(id, window, cx),
599 )601 )
600 }))602 }))
601- .child(action(603+ .child(button(
602- entity,
603- palette,
604- id,
605 "forward",604 "forward",
606 w().message_actions.forward,605 w().message_actions.forward,
607 IconName::Forward,606 IconName::Forward,
608 |yumush, id, window, cx| yumush.open_forward(vec![id], window, cx),607 |yumush, id, window, cx| yumush.open_forward(vec![id], window, cx),
609 ))608 ))
610- .child(action(609+ .child(button(
611- entity,
612- palette,
613- id,
614 "select",610 "select",
615 w().message_actions.select,611 w().message_actions.select,
616 IconName::ListChecks,612 IconName::ListChecks,
617 |yumush, id, window, cx| yumush.start_select(id, window, cx),613 |yumush, id, window, cx| yumush.start_select(id, window, cx),
618 ))614 ))
619 .children(pinnable.then(|| {615 .children(pinnable.then(|| {
620- action(616+ button("pin", pin_tip, pin_icon, |yumush, id, window, cx| {
621- entity,617+ yumush.toggle_pin(id, window, cx)
622- palette,618+ })
623- id,
624- "pin",
625- if message.pinned {
626- w().message_actions.unpin
627- } else {
628- w().message_actions.pin
629- },
630- if message.pinned {
631- IconName::PinOff
632- } else {
633- IconName::Pin
634- },
635- |yumush, id, window, cx| yumush.toggle_pin(id, window, cx),
636- )
637 }))619 }))
638 .children(reportable.then(|| {620 .children(reportable.then(|| {
639- action(621+ button(
640- entity,
641- palette,
642- id,
643 "report",622 "report",
644 w().message_actions.report,623 w().message_actions.report,
645 IconName::TriangleAlert,624 IconName::TriangleAlert,
@@ -647,10 +626,7 @@ pub fn actions(
647 )626 )
648 }))627 }))
649 .children(deletable.then(|| {628 .children(deletable.then(|| {
650- action(629+ button(
651- entity,
652- palette,
653- id,
654 "delete",630 "delete",
655 if armed {631 if armed {
656 w().message_actions.confirm632 w().message_actions.confirm
@@ -660,27 +636,25 @@ pub fn actions(
660 IconName::Trash,636 IconName::Trash,
661 |yumush, id, window, cx| yumush.request_message_delete(id, window, cx),637 |yumush, id, window, cx| yumush.request_message_delete(id, window, cx),
662 )638 )
663- .when(armed, |this| {639+ .when(armed, |this| this.text_color(t.bad()).bg(t.press()))
664- this.text_color(palette.danger).bg(palette.tokens.press())
665- })
666 }))640 }))
667 }641 }
668 642
669 pub fn report_bar(643 pub fn report_bar(
670 reason: &Entity<InputState>,644 reason: &Entity<InputState>,
671 entity: &Entity<Yumush>,645 entity: &Entity<Yumush>,
672- palette: Palette,646+ t: Tokens,
673 ) -> impl IntoElement {647 ) -> impl IntoElement {
674 div()648 div()
675 .flex()649 .flex()
676 .items_center()650 .items_center()
677 .gap(px(space::SM))651 .gap(px(space::SM))
678- .child(div().flex_1().min_w_0().child(field(palette, reason)))652+ .child(div().flex_1().min_w_0().child(field(t, reason)))
679 .child(button(653 .child(button(
680 "send_report",654 "send_report",
681 w().message_actions.send,655 w().message_actions.send,
682 Press::Primary,656 Press::Primary,
683- palette.tokens,657+ t,
684 entity_action(entity, |yumush, window, cx| yumush.send_report(window, cx)),658 entity_action(entity, |yumush, window, cx| yumush.send_report(window, cx)),
685 ))659 ))
686 }660 }
@@ -694,6 +668,7 @@ impl Yumush {
694 ) {668 ) {
695 let pinned = self669 let pinned = self
696 .chat670 .chat
671+ .session
697 .messages672 .messages
698 .iter()673 .iter()
699 .any(|message| message.id == message_id && message.pinned);674 .any(|message| message.id == message_id && message.pinned);
@@ -729,10 +704,10 @@ impl Yumush {
729 window: &mut Window,704 window: &mut Window,
730 cx: &mut Context<Self>,705 cx: &mut Context<Self>,
731 ) {706 ) {
732- if self.chat.report.as_ref() == Some(&target) {707+ if self.chat.session.report.as_ref() == Some(&target) {
733- self.chat.report = None;708+ self.chat.session.report = None;
734 } else {709 } else {
735- self.chat.report = Some(target);710+ self.chat.session.report = Some(target);
736 self.chat711 self.chat
737 .report_reason712 .report_reason
738 .update(cx, |input, cx| input.focus(window, cx));713 .update(cx, |input, cx| input.focus(window, cx));
@@ -741,7 +716,7 @@ impl Yumush {
741 }716 }
742 717
743 pub(super) fn send_report(&mut self, window: &mut Window, cx: &mut Context<Self>) {718 pub(super) fn send_report(&mut self, window: &mut Window, cx: &mut Context<Self>) {
744- let Some(target) = self.chat.report.clone() else {719+ let Some(target) = self.chat.session.report.clone() else {
745 return;720 return;
746 };721 };
747 let reason = self.chat.report_reason.read(cx).text().to_string();722 let reason = self.chat.report_reason.read(cx).text().to_string();
@@ -758,7 +733,7 @@ impl Yumush {
758 match result {733 match result {
759 Ok(()) => {734 Ok(()) => {
760 let _ = this.update_in(cx, |yumush, window, cx| {735 let _ = this.update_in(cx, |yumush, window, cx| {
761- yumush.chat.report = None;736+ yumush.chat.session.report = None;
762 yumush737 yumush
763 .chat738 .chat
764 .report_reason739 .report_reason
@@ -775,7 +750,7 @@ impl Yumush {
775 750
776 fn action(751 fn action(
777 entity: &Entity<Yumush>,752 entity: &Entity<Yumush>,
778- palette: Palette,753+ t: Tokens,
779 message_id: Id,754 message_id: Id,
780 name: &'static str,755 name: &'static str,
781 tip: &'static str,756 tip: &'static str,
@@ -790,7 +765,7 @@ fn action(
790 tip,765 tip,
791 Tone::Idle,766 Tone::Idle,
792 Scale::Small,767 Scale::Small,
793- palette.tokens,768+ t,
794 move |window, cx| {769 move |window, cx| {
795 entity.update(cx, |yumush, cx| run(yumush, message_id, window, cx));770 entity.update(cx, |yumush, cx| run(yumush, message_id, window, cx));
796 },771 },
crates/client/src/gui/parts.rsmodified+12 -5
@@ -261,15 +261,20 @@ pub fn button(
261 ) -> Stateful<Div> {261 ) -> Stateful<Div> {
262 let label = label.into();262 let label = label.into();
263 match kind {263 match kind {
264- Press::Plain => press(id, t, on_click)
265- .child(words(label, Text::Ui, Ink::Paper, t).font_weight(FontWeight::MEDIUM)),
266- Press::Danger => press(id, t, on_click)
267- .child(words(label, Text::Ui, Ink::Bad, t).font_weight(FontWeight::MEDIUM)),
268 Press::Primary => pill(id, t, on_click).child(264 Press::Primary => pill(id, t, on_click).child(
269 words(label, Text::Ui, Ink::Paper, t)265 words(label, Text::Ui, Ink::Paper, t)
270 .font_weight(FontWeight::SEMIBOLD)266 .font_weight(FontWeight::SEMIBOLD)
271 .text_color(t.ground()),267 .text_color(t.ground()),
272 ),268 ),
269+ Press::Plain | Press::Danger => {
270+ let ink = if kind == Press::Danger {
271+ Ink::Bad
272+ } else {
273+ Ink::Paper
274+ };
275+ press(id, t, on_click)
276+ .child(words(label, Text::Ui, ink, t).font_weight(FontWeight::MEDIUM))
277+ }
273 }278 }
274 }279 }
275 280
@@ -406,7 +411,7 @@ pub fn popover(t: Tokens) -> Div {
406 .py(px(space::LG))411 .py(px(space::LG))
407 }412 }
408 413
409-pub const QUICK_LABEL: f32 = size::ROW + space::XL;414+const QUICK_LABEL: f32 = size::ROW + space::XL;
410 415
411 pub fn quick(t: Tokens) -> Div {416 pub fn quick(t: Tokens) -> Div {
412 popover(t).gap(px(space::XS))417 popover(t).gap(px(space::XS))
@@ -639,6 +644,8 @@ pub fn motion() -> gpui_kit::Animation {
639 gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint())644 gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint())
640 }645 }
641 646
647+pub const DISABLED: f32 = 0.4;
648+
642 const SLIDER_DOT: f32 = 10.;649 const SLIDER_DOT: f32 = 10.;
643 650
644 #[derive(gpui_kit::IntoElement)]651 #[derive(gpui_kit::IntoElement)]
crates/client/src/gui/poll.rsmodified+129 -136
@@ -10,19 +10,15 @@ use gpui_kit::{
10 };10 };
11 11
12 use super::{12 use super::{
13- Palette, Tooltip as _, Trigger, Yumush, avatar,13+ Tooltip as _, Trigger, Yumush, avatar,
14 chat::Chat,14 chat::Chat,
15- clickable, hoverable,15+ clickable, hoverable, notify_error,
16- parts::{Scale, Tone, icon_button},16+ parts::{Scale, Tone, icon_button, surface},
17- style::{radius, size, space, text},17+ style::{Tokens, radius, size, space, text},
18 text,18 text,
19- widget::{panel, spawn_done},19+ widget::spawn_done,
20 };20 };
21 21
22-pub fn voter_count(poll: &Poll) -> usize {
23- poll.voters as usize
24-}
25-
26 fn my_positions(poll: &Poll, user_id: Id) -> Vec<u32> {22 fn my_positions(poll: &Poll, user_id: Id) -> Vec<u32> {
27 poll.options23 poll.options
28 .iter()24 .iter()
@@ -54,17 +50,12 @@ pub enum PollMode<'a> {
54 Snapshot(Id),50 Snapshot(Id),
55 }51 }
56 52
57-fn status_icon(53+fn status_icon(id: String, icon: IconName, tip: &'static str, t: Tokens) -> impl IntoElement {
58- id: String,
59- icon: IconName,
60- tip: &'static str,
61- palette: Palette,
62-) -> impl IntoElement {
63 div()54 div()
64 .id(id)55 .id(id)
65 .tip(tip)56 .tip(tip)
66 .flex_shrink_0()57 .flex_shrink_0()
67- .text_color(palette.muted)58+ .text_color(t.dim())
68 .child(super::parts::small_icon(icon))59 .child(super::parts::small_icon(icon))
69 }60 }
70 61
@@ -77,7 +68,7 @@ fn voters_label(voters: usize) -> Div {
77 .child(format!("{voters}"))68 .child(format!("{voters}"))
78 }69 }
79 70
80-fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Palette) -> AnyElement {71+fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, t: Tokens) -> AnyElement {
81 let options = poll.options.clone();72 let options = poll.options.clone();
82 let list = format!("poll_voters_list_{key}");73 let list = format!("poll_voters_list_{key}");
83 let open = entity.clone();74 let open = entity.clone();
@@ -86,8 +77,8 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale
86 .appearance(false)77 .appearance(false)
87 .trigger(Trigger::new(hoverable(78 .trigger(Trigger::new(hoverable(
88 format!("poll_voters_trigger_{key}"),79 format!("poll_voters_trigger_{key}"),
89- voters_label(voter_count(poll)),80+ voters_label(poll.voters as usize),
90- palette,81+ t,
91 )))82 )))
92 .content(move |_, _, cx| {83 .content(move |_, _, cx| {
93 let yumush = open.read(cx);84 let yumush = open.read(cx);
@@ -106,7 +97,7 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale
106 .items_center()97 .items_center()
107 .gap(px(space::SM))98 .gap(px(space::SM))
108 .text_size(text(text::CAPTION))99 .text_size(text(text::CAPTION))
109- .text_color(palette.muted)100+ .text_color(t.dim())
110 .child(div().flex_1().min_w_0().child(super::glyph::line(101 .child(div().flex_1().min_w_0().child(super::glyph::line(
111 option.text.clone().into(),102 option.text.clone().into(),
112 super::text(super::style::text::UI),103 super::text(super::style::text::UI),
@@ -126,11 +117,11 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale
126 .gap(px(space::SM))117 .gap(px(space::SM))
127 .text_size(text(text::CAPTION))118 .text_size(text(text::CAPTION))
128 .child(avatar(119 .child(avatar(
129- palette,120+ t,
130 user,121 user,
131 px(size::AVATAR),122 px(size::AVATAR),
132 text(text::CAPTION),123 text(text::CAPTION),
133- &chat.avatars,124+ &chat.session.avatars,
134 ))125 ))
135 .child(126 .child(
136 div()127 div()
@@ -142,7 +133,7 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale
142 })133 })
143 }))134 }))
144 });135 });
145- panel(palette)136+ surface(t)
146 .w(px(size::SIDEBAR))137 .w(px(size::SIDEBAR))
147 .id(list.clone())138 .id(list.clone())
148 .max_h(px(size::POPOVER))139 .max_h(px(size::POPOVER))
@@ -176,45 +167,41 @@ pub fn poll_card(
176 me: Option<&User>,167 me: Option<&User>,
177 chat: &Chat,168 chat: &Chat,
178 entity: &Entity<Yumush>,169 entity: &Entity<Yumush>,
179- palette: Palette,170+ t: Tokens,
180 ) -> impl IntoElement {171 ) -> impl IntoElement {
181- let voters = voter_count(poll);172+ let voters = poll.voters as usize;
182 let closed = is_closed(poll);173 let closed = is_closed(poll);
183- let me_id = me.map(|me| me.id);174+ let (key, mine, vote_id, close_id) = match mode {
184- let (key, live) = match mode {175+ PollMode::Live(message) => {
185- PollMode::Live(message) => (message.id.to_string(), Some(message)),176+ let mine = match me {
186- PollMode::Snapshot(id) => (format!("snapshot_{id}"), None),177+ Some(me) if poll.public => my_positions(poll, me.id),
187- };178+ _ => chat
188- let mine = match me_id {179+ .session
189- Some(id) if poll.public => my_positions(poll, id),180+ .my_votes
190- _ => live181+ .get(&message.id)
191- .and_then(|message| chat.my_votes.get(&message.id))182+ .cloned()
192- .cloned()183+ .unwrap_or_default(),
193- .unwrap_or_default(),184+ };
194- };185+ let vote_id = (!closed && me.is_some()).then_some(message.id);
195- let vote_id = live186+ let close_id = (!closed
196- .filter(|_| !closed && me_id.is_some())
197- .map(|message| message.id);
198- let close_id = live
199- .filter(|message| {
200- !closed
201 && me.is_some_and(|me| {187 && me.is_some_and(|me| {
202 me.id == message.user_id || chat.rank_of(me) >= Some(Rank::Moderator)188 me.id == message.user_id || chat.rank_of(me) >= Some(Rank::Moderator)
203- })189+ }))
204- })190+ .then_some(message.id);
205- .map(|message| message.id);191+ (message.id.to_string(), mine, vote_id, close_id)
192+ }
193+ PollMode::Snapshot(id) => (format!("snapshot_{id}"), Vec::new(), None, None),
194+ };
206 195
207 let rows = poll.options.iter().enumerate().map(|(position, option)| {196 let rows = poll.options.iter().enumerate().map(|(position, option)| {
208 let share = percent(option.votes as usize, voters);197 let share = percent(option.votes as usize, voters);
209 let picked = mine.contains(&(position as u32));198 let picked = mine.contains(&(position as u32));
210- let next = me_id199+ let next = next_votes(&mine, position as u32, poll.multiple);
211- .map(|_| next_votes(&mine, position as u32, poll.multiple))
212- .unwrap_or_default();
213 let voters_here: &[Id] = if poll.public { &option.voter_ids } else { &[] };200 let voters_here: &[Id] = if poll.public { &option.voter_ids } else { &[] };
214 let entity = entity.clone();201 let entity = entity.clone();
215 let id = format!("poll_option_{key}_{position}");202 let id = format!("poll_option_{key}_{position}");
216 match vote_id {203 match vote_id {
217- Some(message_id) => clickable(id, palette, move |window, cx| {204+ Some(message_id) => clickable(id, t, move |window, cx| {
218 let next = next.clone();205 let next = next.clone();
219 entity.update(cx, |yumush, cx| yumush.vote(message_id, next, window, cx));206 entity.update(cx, |yumush, cx| yumush.vote(message_id, next, window, cx));
220 }),207 }),
@@ -228,13 +215,9 @@ pub fn poll_card(
228 .gap(px(space::SM))215 .gap(px(space::SM))
229 .rounded(px(radius::MD))216 .rounded(px(radius::MD))
230 .border_1()217 .border_1()
231- .border_color(if picked {218+ .border_color(if picked { t.paper() } else { t.raise() })
232- palette.accent
233- } else {
234- palette.field
235- })
236 .overflow_hidden()219 .overflow_hidden()
237- .bg(palette.field)220+ .bg(t.raise())
238 .child(221 .child(
239 div()222 div()
240 .absolute()223 .absolute()
@@ -242,11 +225,7 @@ pub fn poll_card(
242 .top_0()225 .top_0()
243 .h_full()226 .h_full()
244 .w(relative(share as f32 / 100.))227 .w(relative(share as f32 / 100.))
245- .bg(if picked {228+ .bg(if picked { t.press() } else { t.hov() }),
246- palette.tokens.press()
247- } else {
248- palette.hover
249- }),
250 )229 )
251 .child(230 .child(
252 div()231 div()
@@ -257,15 +236,11 @@ pub fn poll_card(
257 .justify_center()236 .justify_center()
258 .rounded_full()237 .rounded_full()
259 .border_1()238 .border_1()
260- .border_color(if picked {239+ .border_color(if picked { t.paper() } else { t.dim() })
261- palette.accent
262- } else {
263- palette.muted
264- })
265 .when(picked, |marker| {240 .when(picked, |marker| {
266 marker241 marker
267- .bg(palette.accent)242+ .bg(t.paper())
268- .text_color(palette.on_accent)243+ .text_color(t.ground())
269 .child(super::parts::small_icon(IconName::Check))244 .child(super::parts::small_icon(IconName::Check))
270 }),245 }),
271 )246 )
@@ -285,14 +260,14 @@ pub fn poll_card(
285 .filter_map(|(index, id)| {260 .filter_map(|(index, id)| {
286 chat.author(*id).map(|user| {261 chat.author(*id).map(|user| {
287 avatar(262 avatar(
288- palette,263+ t,
289 user,264 user,
290 px(size::AVATAR),265 px(size::AVATAR),
291 text(text::CAPTION),266 text(text::CAPTION),
292- &chat.avatars,267+ &chat.session.avatars,
293 )268 )
294 .border_2()269 .border_2()
295- .border_color(palette.panel)270+ .border_color(t.ground())
296 .when(index > 0, |el| el.ml(px(-space::SM)))271 .when(index > 0, |el| el.ml(px(-space::SM)))
297 })272 })
298 }),273 }),
@@ -301,7 +276,7 @@ pub fn poll_card(
301 div()276 div()
302 .ml(px(space::XS))277 .ml(px(space::XS))
303 .text_size(text(text::CAPTION))278 .text_size(text(text::CAPTION))
304- .text_color(palette.muted)279+ .text_color(t.dim())
305 .child(format!("+{}", voters_here.len() - 3))280 .child(format!("+{}", voters_here.len() - 3))
306 }))281 }))
307 }))282 }))
@@ -310,13 +285,13 @@ pub fn poll_card(
310 .flex_shrink_0()285 .flex_shrink_0()
311 .text_size(text(text::CAPTION))286 .text_size(text(text::CAPTION))
312 .font_weight(FontWeight::SEMIBOLD)287 .font_weight(FontWeight::SEMIBOLD)
313- .text_color(if picked { palette.text } else { palette.muted })288+ .text_color(if picked { t.paper() } else { t.dim() })
314 .child(format!("{share}%")),289 .child(format!("{share}%")),
315 )290 )
316 });291 });
317 292
318 let voters_view = if poll.public {293 let voters_view = if poll.public {
319- voters_popover(&key, poll, entity, palette)294+ voters_popover(&key, poll, entity, t)
320 } else {295 } else {
321 voters_label(voters).into_any_element()296 voters_label(voters).into_any_element()
322 };297 };
@@ -335,7 +310,7 @@ pub fn poll_card(
335 .items_center()310 .items_center()
336 .justify_between()311 .justify_between()
337 .text_size(text(text::CAPTION))312 .text_size(text(text::CAPTION))
338- .text_color(palette.muted)313+ .text_color(t.dim())
339 .child(voters_view)314 .child(voters_view)
340 .child(315 .child(
341 div()316 div()
@@ -351,7 +326,7 @@ pub fn poll_card(
351 w().poll.end_poll,326 w().poll.end_poll,
352 Tone::Idle,327 Tone::Idle,
353 Scale::Small,328 Scale::Small,
354- palette.tokens,329+ t,
355 move |window, cx| {330 move |window, cx| {
356 close_entity331 close_entity
357 .update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx));332 .update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx));
@@ -374,7 +349,7 @@ pub fn poll_card(
374 .w(px(size::SHEET))349 .w(px(size::SHEET))
375 .max_w_full()350 .max_w_full()
376 .rounded(px(radius::LG))351 .rounded(px(radius::LG))
377- .bg(palette.panel)352+ .bg(t.ground())
378 .child(353 .child(
379 div()354 div()
380 .flex()355 .flex()
@@ -401,14 +376,14 @@ pub fn poll_card(
401 format!("poll_public_{key}_{}", poll.public),376 format!("poll_public_{key}_{}", poll.public),
402 visibility,377 visibility,
403 visibility_tip,378 visibility_tip,
404- palette,379+ t,
405 ))380 ))
406 .children(poll.multiple.then(|| {381 .children(poll.multiple.then(|| {
407 status_icon(382 status_icon(
408 format!("poll_multiple_{key}"),383 format!("poll_multiple_{key}"),
409 IconName::ListChecks,384 IconName::ListChecks,
410 w().poll.multiple_choice,385 w().poll.multiple_choice,
411- palette,386+ t,
412 )387 )
413 }))388 }))
414 .children(closed.then(|| {389 .children(closed.then(|| {
@@ -416,7 +391,7 @@ pub fn poll_card(
416 format!("poll_closed_{key}"),391 format!("poll_closed_{key}"),
417 IconName::Lock,392 IconName::Lock,
418 w().poll.closed,393 w().poll.closed,
419- palette,394+ t,
420 )395 )
421 })),396 })),
422 ),397 ),
@@ -426,9 +401,9 @@ pub fn poll_card(
426 }401 }
427 402
428 impl Yumush {403 impl Yumush {
429- pub(super) fn poll_banner(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {404+ fn open_polls(&self) -> Vec<(&Message, &Poll)> {
430- let open: Vec<(&Message, &Poll)> = self405+ self.chat
431- .chat406+ .session
432 .pins407 .pins
433 .iter()408 .iter()
434 .filter_map(|pin| {409 .filter_map(|pin| {
@@ -437,12 +412,16 @@ impl Yumush {
437 .filter(|poll| !is_closed(poll))412 .filter(|poll| !is_closed(poll))
438 .map(|poll| (pin, poll))413 .map(|poll| (pin, poll))
439 })414 })
440- .collect();415+ .collect()
416+ }
417+
418+ pub(super) fn poll_banner(&self, entity: &Entity<Self>, t: Tokens) -> Option<Div> {
419+ let open = self.open_polls();
441 let count = open.len();420 let count = open.len();
442- let page = self.chat.poll_page % count.max(1);421+ let page = self.chat.poll.page % count.max(1);
443 let (message, poll) = *open.get(page)?;422 let (message, poll) = *open.get(page)?;
444 let me = self.user.as_ref();423 let me = self.user.as_ref();
445- let expanded = self.chat.poll_expanded;424+ let expanded = self.chat.poll.expanded;
446 let toggle = entity.clone();425 let toggle = entity.clone();
447 let jump = entity.clone();426 let jump = entity.clone();
448 let message_id = message.id;427 let message_id = message.id;
@@ -455,17 +434,17 @@ impl Yumush {
455 .px(px(space::LG))434 .px(px(space::LG))
456 .py(px(space::SM))435 .py(px(space::SM))
457 .border_b_1()436 .border_b_1()
458- .border_color(palette.border)437+ .border_color(t.thread())
459- .bg(palette.panel)438+ .bg(t.ground())
460 .child(439 .child(
461 div()440 div()
462 .flex()441 .flex()
463 .items_center()442 .items_center()
464 .gap(px(space::SM))443 .gap(px(space::SM))
465 .child(444 .child(
466- clickable("poll_banner_toggle", palette, move |_, cx| {445+ clickable("poll_banner_toggle", t, move |_, cx| {
467 toggle.update(cx, |yumush, cx| {446 toggle.update(cx, |yumush, cx| {
468- yumush.chat.poll_expanded = !yumush.chat.poll_expanded;447+ yumush.chat.poll.expanded = !yumush.chat.poll.expanded;
469 cx.notify();448 cx.notify();
470 })449 })
471 })450 })
@@ -478,7 +457,7 @@ impl Yumush {
478 .child(457 .child(
479 div()458 div()
480 .flex_shrink_0()459 .flex_shrink_0()
481- .text_color(palette.muted)460+ .text_color(t.dim())
482 .child(super::parts::small_icon(IconName::ChartBar)),461 .child(super::parts::small_icon(IconName::ChartBar)),
483 )462 )
484 .child(div().min_w_0().font_weight(FontWeight::SEMIBOLD).child(463 .child(div().min_w_0().font_weight(FontWeight::SEMIBOLD).child(
@@ -490,11 +469,11 @@ impl Yumush {
490 .child(469 .child(
491 div()470 div()
492 .flex_shrink_0()471 .flex_shrink_0()
493- .text_color(palette.muted)472+ .text_color(t.dim())
494- .child(w().poll.votes(voter_count(poll))),473+ .child(w().poll.votes(poll.voters as usize)),
495 )474 )
496 .child(475 .child(
497- div().flex_shrink_0().text_color(palette.muted).child(476+ div().flex_shrink_0().text_color(t.dim()).child(
498 super::parts::small_icon(if expanded {477 super::parts::small_icon(if expanded {
499 IconName::ChevronUp478 IconName::ChevronUp
500 } else {479 } else {
@@ -509,14 +488,14 @@ impl Yumush {
509 .items_center()488 .items_center()
510 .gap(px(space::XXS))489 .gap(px(space::XXS))
511 .text_size(text(text::CAPTION))490 .text_size(text(text::CAPTION))
512- .text_color(palette.muted)491+ .text_color(t.dim())
513 .child(page_button(492 .child(page_button(
514 "poll_page_back",493 "poll_page_back",
515 IconName::ChevronLeft,494 IconName::ChevronLeft,
516 w().poll.previous,495 w().poll.previous,
517- count - 1,496+ -1,
518 entity,497 entity,
519- palette,498+ t,
520 ))499 ))
521 .child(format!("{}/{count}", page + 1))500 .child(format!("{}/{count}", page + 1))
522 .child(page_button(501 .child(page_button(
@@ -525,7 +504,7 @@ impl Yumush {
525 w().poll.next,504 w().poll.next,
526 1,505 1,
527 entity,506 entity,
528- palette,507+ t,
529 ))508 ))
530 }))509 }))
531 .child(icon_button(510 .child(icon_button(
@@ -534,7 +513,7 @@ impl Yumush {
534 w().poll.jump_to_message,513 w().poll.jump_to_message,
535 Tone::Idle,514 Tone::Idle,
536 Scale::Small,515 Scale::Small,
537- palette.tokens,516+ t,
538 move |window, cx| {517 move |window, cx| {
539 jump.update(cx, |yumush, cx| {518 jump.update(cx, |yumush, cx| {
540 yumush.go_to_message(message_id, window, cx)519 yumush.go_to_message(message_id, window, cx)
@@ -542,25 +521,21 @@ impl Yumush {
542 },521 },
543 )),522 )),
544 )523 )
545- .children(expanded.then(|| {524+ .children(
546- poll_card(525+ expanded.then(|| {
547- poll,526+ poll_card(poll, PollMode::Live(message), me, &self.chat, entity, t)
548- PollMode::Live(message),527+ }),
549- me,528+ ),
550- &self.chat,
551- entity,
552- palette,
553- )
554- })),
555 )529 )
556 }530 }
557 531
558 pub(super) fn request_poll_votes(&mut self, cx: &mut Context<Self>) {532 pub(super) fn request_poll_votes(&mut self, cx: &mut Context<Self>) {
559 let anonymous: Vec<Id> = self533 let anonymous: Vec<Id> = self
560 .chat534 .chat
535+ .session
561 .messages536 .messages
562 .iter()537 .iter()
563- .chain(&self.chat.pins)538+ .chain(&self.chat.session.pins)
564 .filter(|message| message.poll.as_ref().is_some_and(|poll| !poll.public))539 .filter(|message| message.poll.as_ref().is_some_and(|poll| !poll.public))
565 .map(|message| message.id)540 .map(|message| message.id)
566 .collect();541 .collect();
@@ -570,19 +545,24 @@ impl Yumush {
570 }545 }
571 546
572 pub(super) fn request_my_votes(&mut self, message_id: Id, cx: &mut Context<Self>) {547 pub(super) fn request_my_votes(&mut self, message_id: Id, cx: &mut Context<Self>) {
573- if self.chat.my_votes.contains_key(&message_id) {548+ if self.chat.session.my_votes.contains_key(&message_id) {
574 return;549 return;
575 }550 }
576- self.chat.my_votes.insert(message_id, Vec::new());551+ self.chat.session.my_votes.insert(message_id, Vec::new());
577 552
578 let network = self.network.clone();553 let network = self.network.clone();
579 554
580 cx.spawn(async move |this, cx| {555 cx.spawn(async move |this, cx| {
581- let Ok(positions) = network.call(MyVotes { message_id }).await else {556+ let positions = network.call(MyVotes { message_id }).await;
582- return;
583- };
584 let _ = this.update(cx, |yumush, cx| {557 let _ = this.update(cx, |yumush, cx| {
585- yumush.chat.my_votes.insert(message_id, positions);558+ match positions {
559+ Ok(positions) => {
560+ yumush.chat.session.my_votes.insert(message_id, positions);
561+ }
562+ Err(_) => {
563+ yumush.chat.session.my_votes.remove(&message_id);
564+ }
565+ }
586 cx.notify();566 cx.notify();
587 });567 });
588 })568 })
@@ -596,17 +576,36 @@ impl Yumush {
596 window: &mut Window,576 window: &mut Window,
597 cx: &mut Context<Self>,577 cx: &mut Context<Self>,
598 ) {578 ) {
599- self.chat.my_votes.insert(message_id, positions.clone());579+ let previous = self
580+ .chat
581+ .session
582+ .my_votes
583+ .insert(message_id, positions.clone());
600 let network = self.network.clone();584 let network = self.network.clone();
601 585
602- spawn_done(window, cx, async move {586+ cx.spawn_in(window, async move |this, cx| {
603- network587+ if let Err(error) = network
604 .call(Vote {588 .call(Vote {
605 message_id,589 message_id,
606 positions,590 positions,
607 })591 })
608 .await592 .await
609- });593+ {
594+ let _ = this.update_in(cx, |yumush, _, cx| {
595+ match previous {
596+ Some(previous) => {
597+ yumush.chat.session.my_votes.insert(message_id, previous);
598+ }
599+ None => {
600+ yumush.chat.session.my_votes.remove(&message_id);
601+ }
602+ }
603+ cx.notify();
604+ });
605+ notify_error(&this, cx, error);
606+ }
607+ })
608+ .detach();
610 }609 }
611 610
612 pub(super) fn close_poll(611 pub(super) fn close_poll(
@@ -627,23 +626,17 @@ fn page_button(
627 id: &'static str,626 id: &'static str,
628 icon: IconName,627 icon: IconName,
629 tip: &'static str,628 tip: &'static str,
630- step: usize,629+ step: isize,
631 entity: &Entity<Yumush>,630 entity: &Entity<Yumush>,
632- palette: Palette,631+ t: Tokens,
633 ) -> impl IntoElement {632 ) -> impl IntoElement {
634 let entity = entity.clone();633 let entity = entity.clone();
635- icon_button(634+ icon_button(id, icon, tip, Tone::Idle, Scale::Small, t, move |_, cx| {
636- id,635+ entity.update(cx, |yumush, cx| {
637- icon,636+ let count = yumush.open_polls().len().max(1) as isize;
638- tip,637+ yumush.chat.poll.page =
639- Tone::Idle,638+ (yumush.chat.poll.page as isize + step).rem_euclid(count) as usize;
640- Scale::Small,639+ cx.notify();
641- palette.tokens,640+ });
642- move |_, cx| {641+ })
643- entity.update(cx, |yumush, cx| {
644- yumush.chat.poll_page = yumush.chat.poll_page.wrapping_add(step);
645- cx.notify();
646- });
647- },
648- )
649 }642 }
crates/client/src/gui/profile.rsmodified+139 -139
@@ -3,8 +3,10 @@ use crate::gui::glyph::Fill as _;
3 use crate::lang::{Label as _, w};3 use crate::lang::{Label as _, w};
4 use common::model::Id;4 use common::model::Id;
5 use gpui_kit::prelude::FluentBuilder as _;5 use gpui_kit::prelude::FluentBuilder as _;
6-use std::collections::VecDeque;6+use std::{
7-use std::{collections::HashMap, sync::Arc};7+ collections::{HashMap, VecDeque},
8+ sync::Arc,
9+};
8 10
9 use common::{11 use common::{
10 call::{BanMember, DeleteUser, Kick, SetRank, UpdatePresence},12 call::{BanMember, DeleteUser, Kick, SetRank, UpdatePresence},
@@ -31,11 +33,11 @@ use super::parts::{
31 Ink, Scale, Text, Tone, Voice, band, icon_button, small_icon, stack, voice_line, words,33 Ink, Scale, Text, Tone, Voice, band, icon_button, small_icon, stack, voice_line, words,
32 };34 };
33 use super::social::Relation;35 use super::social::Relation;
34-use super::style::{radius, size, space, stroke, text};36+use super::style::{Tokens, radius, size, space, stroke, text};
35 use super::widget::spawn_done;37 use super::widget::spawn_done;
36 use super::{38 use super::{
37- Palette, Tooltip as _, Trigger, Yumush, avatar, clickable, entity_action, input_dialog,39+ Tooltip as _, Trigger, Yumush, avatar, clickable, entity_action, input_dialog, millis_time,
38- millis_time, notify_error, palette, text,40+ notify_error, text,
39 };41 };
40 42
41 #[derive(Debug, Clone, Copy, PartialEq, Eq)]43 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -91,8 +93,8 @@ pub(super) fn profile_popover(
91 .appearance(false)93 .appearance(false)
92 .on_open_change(move |_, _, cx| {94 .on_open_change(move |_, _, cx| {
93 notify_entity.update(cx, |yumush, cx| {95 notify_entity.update(cx, |yumush, cx| {
94- yumush.chat.card_menu = CardMenu::Main;96+ yumush.chat.session.card_menu = CardMenu::Main;
95- yumush.chat.armed = None;97+ yumush.chat.session.armed = None;
96 yumush.open_user_volume(volume_user_id, cx);98 yumush.open_user_volume(volume_user_id, cx);
97 cx.notify()99 cx.notify()
98 })100 })
@@ -101,19 +103,26 @@ pub(super) fn profile_popover(
101 .content(move |_, _, cx| {103 .content(move |_, _, cx| {
102 let yumush = entity.read(cx);104 let yumush = entity.read(cx);
103 let card = Card {105 let card = Card {
104- viewer: yumush.user.clone(),106+ is_self: yumush
107+ .user
108+ .as_ref()
109+ .is_some_and(|viewer| viewer.id == user.id),
110+ deletable: yumush.user.as_ref().is_some_and(|viewer| {
111+ permission::can_delete_user(viewer.role, false, user.role)
112+ }),
105 actor: yumush.actor_rank(),113 actor: yumush.actor_rank(),
106 target: yumush.chat.rank_of(&user),114 target: yumush.chat.rank_of(&user),
107 relation: yumush.relation(user.id),115 relation: yumush.relation(user.id),
108- card_menu: yumush.chat.card_menu,116+ card_menu: yumush.chat.session.card_menu,
109 presence: yumush.presence_of(user.id),117 presence: yumush.presence_of(user.id),
110- armed: yumush.chat.armed,118+ armed: yumush.chat.session.armed.clone(),
111- reporting: yumush.chat.report == Some(ReportTarget::User(user.id)),119+ reporting: yumush.chat.session.report == Some(ReportTarget::User(user.id)),
112 reason: yumush.chat.report_reason.clone(),120 reason: yumush.chat.report_reason.clone(),
113 status: yumush.chat.status_input.clone(),121 status: yumush.chat.status_input.clone(),
114 volume: yumush122 volume: yumush
115 .chat123 .chat
116- .user_volume124+ .session
125+ .volume_popover
117 .as_ref()126 .as_ref()
118 .filter(|volume| volume.user_id == user.id)127 .filter(|volume| volume.user_id == user.id)
119 .map(|volume| (volume.slider.clone(), yumush.user_volume(user.id))),128 .map(|volume| (volume.slider.clone(), yumush.user_volume(user.id))),
@@ -124,12 +133,22 @@ pub(super) fn profile_popover(
124 community.name.clone()133 community.name.clone()
125 }134 }
126 }),135 }),
127- wave: yumush.chat.waves.voice(user.id).cloned(),136+ wave: yumush
128- speaking: yumush.chat.waves.speaking.contains(&user.id),137+ .chat
138+ .session
139+ .waves
140+ .voice(user.id)
141+ .map(|bars| bars.iter().copied().collect()),
142+ speaking: yumush.chat.session.waves.speaking.contains(&user.id),
129 user: user.clone(),143 user: user.clone(),
130 };144 };
131 145
132- card.render(&entity, cx.entity(), palette(cx), &yumush.chat.avatars)146+ card.render(
147+ &entity,
148+ cx.entity(),
149+ Tokens::of(cx),
150+ &yumush.chat.session.avatars,
151+ )
133 })152 })
134 }153 }
135 154
@@ -138,7 +157,8 @@ struct Card {
138 call: Option<String>,157 call: Option<String>,
139 wave: Option<VecDeque<f32>>,158 wave: Option<VecDeque<f32>>,
140 speaking: bool,159 speaking: bool,
141- viewer: Option<User>,160+ is_self: bool,
161+ deletable: bool,
142 actor: Option<Rank>,162 actor: Option<Rank>,
143 target: Option<Rank>,163 target: Option<Rank>,
144 relation: Relation,164 relation: Relation,
@@ -156,7 +176,7 @@ impl Card {
156 &self,176 &self,
157 entity: &Entity<Yumush>,177 entity: &Entity<Yumush>,
158 popover: &Entity<PopoverState>,178 popover: &Entity<PopoverState>,
159- palette: Palette,179+ t: Tokens,
160 ) -> Vec<AnyElement> {180 ) -> Vec<AnyElement> {
161 let user_id = self.user.id;181 let user_id = self.user.id;
162 let message_id = user_id;182 let message_id = user_id;
@@ -165,8 +185,8 @@ impl Card {
165 "profile_message",185 "profile_message",
166 w().profile.message,186 w().profile.message,
167 small_icon(IconName::MessageSquare),187 small_icon(IconName::MessageSquare),
168- palette.text,188+ t.paper(),
169- palette,189+ t,
170 yumush_action(entity, popover, move |yumush, window, cx| {190 yumush_action(entity, popover, move |yumush, window, cx| {
171 yumush.open_direct(message_id, window, cx)191 yumush.open_direct(message_id, window, cx)
172 }),192 }),
@@ -176,8 +196,8 @@ impl Card {
176 "profile_call",196 "profile_call",
177 w().profile.call,197 w().profile.call,
178 small_icon(IconName::Phone),198 small_icon(IconName::Phone),
179- palette.text,199+ t.paper(),
180- palette,200+ t,
181 yumush_action(entity, popover, move |yumush, window, cx| {201 yumush_action(entity, popover, move |yumush, window, cx| {
182 yumush.call_direct(message_id, window, cx)202 yumush.call_direct(message_id, window, cx)
183 }),203 }),
@@ -191,8 +211,8 @@ impl Card {
191 "profile_report",211 "profile_report",
192 w().profile.report,212 w().profile.report,
193 small_icon(IconName::TriangleAlert),213 small_icon(IconName::TriangleAlert),
194- palette.danger,214+ t.bad(),
195- palette,215+ t,
196 entity_action(entity, move |yumush, window, cx| {216 entity_action(entity, move |yumush, window, cx| {
197 yumush.start_report(ReportTarget::User(report_user_id), window, cx)217 yumush.start_report(ReportTarget::User(report_user_id), window, cx)
198 }),218 }),
@@ -207,8 +227,8 @@ impl Card {
207 "profile_friend",227 "profile_friend",
208 label,228 label,
209 small_icon(icon),229 small_icon(icon),
210- palette.text,230+ t.paper(),
211- palette,231+ t,
212 yumush_action(entity, popover, move |yumush, window, cx| {232 yumush_action(entity, popover, move |yumush, window, cx| {
213 yumush.friend_action(relation, user_id, window, cx)233 yumush.friend_action(relation, user_id, window, cx)
214 }),234 }),
@@ -224,25 +244,21 @@ impl Card {
224 self,244 self,
225 entity: &Entity<Yumush>,245 entity: &Entity<Yumush>,
226 popover: Entity<PopoverState>,246 popover: Entity<PopoverState>,
227- palette: Palette,247+ t: Tokens,
228 avatars: &HashMap<Id, Arc<Image>>,248 avatars: &HashMap<Id, Arc<Image>>,
229 ) -> Div {249 ) -> Div {
230- let is_self = self250+ let is_self = self.is_self;
231- .viewer
232- .as_ref()
233- .is_some_and(|viewer| viewer.id == self.user.id);
234- let t = palette.tokens;
235 let actions = if is_self {251 let actions = if is_self {
236 div()252 div()
237 .flex()253 .flex()
238 .flex_col()254 .flex_col()
239 .gap(px(space::XS))255 .gap(px(space::XS))
240- .children(main_self_rows(self.armed, entity, &popover, palette))256+ .children(main_self_rows(self.armed, entity, &popover, t))
241 .into_any_element()257 .into_any_element()
242 } else {258 } else {
243- let mut rows = self.social_rows(entity, &popover, palette);259+ let mut rows = self.social_rows(entity, &popover, t);
244- rows.extend(self.moderation_rows(entity, &popover, palette));260+ rows.extend(self.moderation_rows(entity, &popover, t));
245- if self.card_menu == CardMenu::More || rows.len() < 3 {261+ if self.card_menu == CardMenu::More {
246 div()262 div()
247 .flex()263 .flex()
248 .flex_col()264 .flex_col()
@@ -275,15 +291,15 @@ impl Card {
275 let place = match self.target {291 let place = match self.target {
276 Some(Rank::Builder) => {292 Some(Rank::Builder) => {
277 let badge = band(space::XXS)293 let badge = band(space::XXS)
278- .child(small_icon(IconName::Shield).text_color(palette.accent))294+ .child(small_icon(IconName::Shield).text_color(t.paper()))
279 .child(295 .child(
280 words(Rank::Builder.label(), Text::Caption, Ink::Faint, t)296 words(Rank::Builder.label(), Text::Caption, Ink::Faint, t)
281- .text_color(palette.accent),297+ .text_color(t.paper()),
282 );298 );
283 if is_self {299 if is_self {
284 clickable(300 clickable(
285 "profile_builder",301 "profile_builder",
286- palette,302+ t,
287 yumush_action(entity, &popover, |yumush, window, cx| {303 yumush_action(entity, &popover, |yumush, window, cx| {
288 yumush.show_view(View::Builder, window, cx)304 yumush.show_view(View::Builder, window, cx)
289 }),305 }),
@@ -341,7 +357,7 @@ impl Card {
341 entity,357 entity,
342 "profile_picture",358 "profile_picture",
343 avatar(359 avatar(
344- palette,360+ t,
345 &self.user,361 &self.user,
346 px(size::AVATAR_LG),362 px(size::AVATAR_LG),
347 text(text::BODY),363 text(text::BODY),
@@ -366,14 +382,14 @@ impl Card {
366 .absolute()382 .absolute()
367 .right(px(-space::XXS))383 .right(px(-space::XXS))
368 .bottom(px(-space::XXS))384 .bottom(px(-space::XXS))
369- .child(presence_menu(self.presence, entity, palette)),385+ .child(presence_menu(self.presence, entity, t)),
370 )386 )
371 } else {387 } else {
372 super::presence_avatar(388 super::presence_avatar(
373 picture,389 picture,
374 self.presence,390 self.presence,
375 px(size::AVATAR_LG),391 px(size::AVATAR_LG),
376- palette,392+ t,
377 )393 )
378 }394 }
379 }),395 }),
@@ -396,7 +412,7 @@ impl Card {
396 .truncate(),412 .truncate(),
397 )413 )
398 .when(is_self, |name| {414 .when(is_self, |name| {
399- name.child(account_menu(entity, &popover, palette))415+ name.child(account_menu(entity, &popover, t))
400 }),416 }),
401 )417 )
402 .map(|names| {418 .map(|names| {
@@ -422,7 +438,7 @@ impl Card {
422 .border_color(t.paper())438 .border_color(t.paper())
423 .child(439 .child(
424 super::widget::bare_input(440 super::widget::bare_input(
425- palette,441+ t,
426 gpui_kit::component::input::Input::new(442 gpui_kit::component::input::Input::new(
427 &self.status,443 &self.status,
428 )444 )
@@ -435,7 +451,7 @@ impl Card {
435 .child(super::glyph::picker_button(451 .child(super::glyph::picker_button(
436 "status_emoji",452 "status_emoji",
437 entity,453 entity,
438- palette,454+ t,
439 super::glyph::insert_into(status),455 super::glyph::insert_into(status),
440 )),456 )),
441 );457 );
@@ -452,7 +468,7 @@ impl Card {
452 .min_w_0()468 .min_w_0()
453 .truncate()469 .truncate()
454 }))470 }))
455- .child(edit_status(entity, &self.user.status, palette)),471+ .child(edit_status(entity, &self.user.status, t)),
456 )472 )
457 }),473 }),
458 ),474 ),
@@ -483,10 +499,7 @@ impl Card {
483 .text_right(),499 .text_right(),
484 )500 )
485 }))501 }))
486- .children(502+ .children(self.reporting.then(|| report_bar(&self.reason, entity, t)))
487- self.reporting
488- .then(|| report_bar(&self.reason, entity, palette)),
489- )
490 .child(actions)503 .child(actions)
491 }504 }
492 505
@@ -494,7 +507,7 @@ impl Card {
494 &self,507 &self,
495 entity: &Entity<Yumush>,508 entity: &Entity<Yumush>,
496 popover: &Entity<PopoverState>,509 popover: &Entity<PopoverState>,
497- palette: Palette,510+ t: Tokens,
498 ) -> Vec<AnyElement> {511 ) -> Vec<AnyElement> {
499 let actor = self.actor;512 let actor = self.actor;
500 let target = self.target;513 let target = self.target;
@@ -509,8 +522,8 @@ impl Card {
509 label.clone(),522 label.clone(),
510 label,523 label,
511 small_icon(IconName::Shield),524 small_icon(IconName::Shield),
512- palette.text,525+ t.paper(),
513- palette,526+ t,
514 yumush_action(entity, popover, move |yumush, window, cx| {527 yumush_action(entity, popover, move |yumush, window, cx| {
515 yumush.set_member_rank(user_id, rank, window, cx)528 yumush.set_member_rank(user_id, rank, window, cx)
516 }),529 }),
@@ -521,43 +534,29 @@ impl Card {
521 }534 }
522 535
523 if permission::can_moderate(actor, target) {536 if permission::can_moderate(actor, target) {
524- let kick_id = user_id;537+ for (id, removal, icon) in [
525- let ban_id = user_id;538+ ("kick", Removal::Kick, IconName::Close),
526- rows.push(539+ ("ban", Removal::Ban, IconName::Ban),
527- menu_row(540+ ] {
528- "kick",541+ rows.push(
529- w().profile.kick,542+ menu_row(
530- small_icon(IconName::Close),543+ id,
531- palette.danger,544+ removal.title(),
532- palette,545+ small_icon(icon),
533- yumush_action(entity, popover, move |yumush, window, cx| {546+ t.bad(),
534- yumush.open_removal(kick_id, Removal::Kick, window, cx)547+ t,
535- }),548+ yumush_action(entity, popover, move |yumush, window, cx| {
536- )549+ yumush.open_removal(user_id, removal, window, cx)
537- .into_any_element(),550+ }),
538- );551+ )
539- rows.push(552+ .into_any_element(),
540- menu_row(553+ );
541- "ban",554+ }
542- w().profile.ban,
543- small_icon(IconName::Ban),
544- palette.danger,
545- palette,
546- yumush_action(entity, popover, move |yumush, window, cx| {
547- yumush.open_removal(ban_id, Removal::Ban, window, cx)
548- }),
549- )
550- .into_any_element(),
551- );
552 }555 }
553 556
554- let deletable = self557+ if self.deletable {
555- .viewer
556- .as_ref()
557- .is_some_and(|viewer| permission::can_delete_user(viewer.role, false, self.user.role));
558- if deletable {
559 let armed = Armed::DeleteUser(user_id);558 let armed = Armed::DeleteUser(user_id);
560- let label = if self.armed == Some(armed) {559+ let label = if self.armed == Some(armed.clone()) {
561 w().common.confirm560 w().common.confirm
562 } else {561 } else {
563 w().profile.delete_user562 w().profile.delete_user
@@ -568,8 +567,8 @@ impl Card {
568 "delete_user",567 "delete_user",
569 label,568 label,
570 small_icon(IconName::Trash),569 small_icon(IconName::Trash),
571- palette.danger,570+ t.bad(),
572- palette,571+ t,
573 armed_action(armed, entity, popover, move |yumush, window, cx| {572 armed_action(armed, entity, popover, move |yumush, window, cx| {
574 yumush.delete_member_account(user_id, window, cx)573 yumush.delete_member_account(user_id, window, cx)
575 }),574 }),
@@ -586,22 +585,20 @@ fn main_self_rows(
586 armed: Option<Armed>,585 armed: Option<Armed>,
587 entity: &Entity<Yumush>,586 entity: &Entity<Yumush>,
588 popover: &Entity<PopoverState>,587 popover: &Entity<PopoverState>,
589- palette: Palette,588+ t: Tokens,
590 ) -> Vec<AnyElement> {589 ) -> Vec<AnyElement> {
591- let mut rows = vec![590+ vec![
592 menu_row(591 menu_row(
593 "profile_settings",592 "profile_settings",
594 w().profile.settings,593 w().profile.settings,
595 small_icon(IconName::Settings),594 small_icon(IconName::Settings),
596- palette.text,595+ t.paper(),
597- palette,596+ t,
598 yumush_action(entity, popover, |yumush, window, cx| {597 yumush_action(entity, popover, |yumush, window, cx| {
599 yumush.show_view(View::Settings, window, cx)598 yumush.show_view(View::Settings, window, cx)
600 }),599 }),
601 )600 )
602 .into_any_element(),601 .into_any_element(),
603- ];
604- rows.push(
605 menu_row(602 menu_row(
606 "profile_logout",603 "profile_logout",
607 if armed == Some(Armed::LogOut) {604 if armed == Some(Armed::LogOut) {
@@ -610,49 +607,41 @@ fn main_self_rows(
610 w().profile.log_out607 w().profile.log_out
611 },608 },
612 small_icon(IconName::LogOut),609 small_icon(IconName::LogOut),
613- palette.danger,610+ t.bad(),
614- palette,611+ t,
615 armed_action(Armed::LogOut, entity, popover, |yumush, window, cx| {612 armed_action(Armed::LogOut, entity, popover, |yumush, window, cx| {
616 yumush.logout(window, cx)613 yumush.logout(window, cx)
617 }),614 }),
618 )615 )
619 .into_any_element(),616 .into_any_element(),
620- );617+ ]
621- rows
622 }618 }
623 619
624-fn account_menu(entity: &Entity<Yumush>, card: &Entity<PopoverState>, palette: Palette) -> Popover {620+fn account_menu(entity: &Entity<Yumush>, card: &Entity<PopoverState>, t: Tokens) -> Popover {
625 let entity = entity.clone();621 let entity = entity.clone();
626 let card = card.clone();622 let card = card.clone();
627 Popover::new("account_menu")623 Popover::new("account_menu")
628 .anchor(Anchor::TopLeft)624 .anchor(Anchor::TopLeft)
629 .appearance(false)625 .appearance(false)
630 .trigger(Trigger::new(626 .trigger(Trigger::new(
631- clickable("profile_accounts", palette, |_, _| {})627+ clickable("profile_accounts", t, |_, _| {})
632 .tip(w().profile.accounts)628 .tip(w().profile.accounts)
633 .rounded(px(radius::SM))629 .rounded(px(radius::SM))
634 .flex_shrink_0()630 .flex_shrink_0()
635- .child(small_icon(IconName::ChevronDown).text_color(palette.muted)),631+ .child(small_icon(IconName::ChevronDown).text_color(t.dim())),
636 ))632 ))
637 .content(move |_, _, cx| {633 .content(move |_, _, cx| {
638 let yumush = entity.read(cx);634 let yumush = entity.read(cx);
639- super::parts::popover(palette.tokens)635+ super::parts::popover(t)
640 .p(px(space::XS))636 .p(px(space::XS))
641 .w(px(size::SIDEBAR))637 .w(px(size::SIDEBAR))
642- .child(account_list(638+ .child(account_list(yumush, &entity, Some(card.clone()), t, cx))
643- yumush,
644- &entity,
645- true,
646- Some(card.clone()),
647- palette,
648- cx,
649- ))
650 .child(menu_row(639 .child(menu_row(
651 "profile_add_account",640 "profile_add_account",
652 w().profile.add_account,641 w().profile.add_account,
653 small_icon(IconName::UserPlus),642 small_icon(IconName::UserPlus),
654- palette.text,643+ t.paper(),
655- palette,644+ t,
656 yumush_action(&entity, &card, |yumush, window, cx| {645 yumush_action(&entity, &card, |yumush, window, cx| {
657 yumush.add_account(window, cx)646 yumush.add_account(window, cx)
658 }),647 }),
@@ -660,13 +649,13 @@ fn account_menu(entity: &Entity<Yumush>, card: &Entity<PopoverState>, palette: P
660 })649 })
661 }650 }
662 651
663-fn edit_status(entity: &Entity<Yumush>, status: &str, palette: Palette) -> impl IntoElement {652+fn edit_status(entity: &Entity<Yumush>, status: &str, t: Tokens) -> impl IntoElement {
664 let status = status.to_string();653 let status = status.to_string();
665 clickable(654 clickable(
666 "edit_status",655 "edit_status",
667- palette,656+ t,
668 entity_action(entity, move |yumush, window, cx| {657 entity_action(entity, move |yumush, window, cx| {
669- yumush.chat.card_menu = CardMenu::Status;658+ yumush.chat.session.card_menu = CardMenu::Status;
670 yumush.chat.status_input.update(cx, |input, cx| {659 yumush.chat.status_input.update(cx, |input, cx| {
671 input.fill(status.clone(), window, cx);660 input.fill(status.clone(), window, cx);
672 input.focus(window, cx);661 input.focus(window, cx);
@@ -678,7 +667,7 @@ fn edit_status(entity: &Entity<Yumush>, status: &str, palette: Palette) -> impl
678 .flex_none()667 .flex_none()
679 .p(px(space::XXS))668 .p(px(space::XXS))
680 .rounded(px(radius::SM))669 .rounded(px(radius::SM))
681- .child(small_icon(IconName::Pencil).text_color(palette.tokens.faint()))670+ .child(small_icon(IconName::Pencil).text_color(t.faint()))
682 }671 }
683 672
684 fn card_menu_action(673 fn card_menu_action(
@@ -686,7 +675,7 @@ fn card_menu_action(
686 menu: CardMenu,675 menu: CardMenu,
687 ) -> impl Fn(&mut Window, &mut App) + 'static {676 ) -> impl Fn(&mut Window, &mut App) + 'static {
688 entity_action(entity, move |yumush, _, cx| {677 entity_action(entity, move |yumush, _, cx| {
689- yumush.chat.card_menu = menu;678+ yumush.chat.session.card_menu = menu;
690 cx.notify();679 cx.notify();
691 })680 })
692 }681 }
@@ -715,35 +704,35 @@ pub(super) fn armed_action(
715 let popover = popover.clone();704 let popover = popover.clone();
716 705
717 move |window, cx| {706 move |window, cx| {
718- if entity.update(cx, |yumush, cx| yumush.arm(armed, cx)) {707+ if entity.update(cx, |yumush, cx| yumush.arm(armed.clone(), cx)) {
719 popover.update(cx, |state, cx| state.dismiss(window, cx));708 popover.update(cx, |state, cx| state.dismiss(window, cx));
720 entity.update(cx, |yumush, cx| run(yumush, window, cx));709 entity.update(cx, |yumush, cx| run(yumush, window, cx));
721 }710 }
722 }711 }
723 }712 }
724 713
725-fn presence_dot(presence: Presence, palette: Palette) -> Div {714+fn presence_dot(presence: Presence, t: Tokens) -> Div {
726 div()715 div()
727 .size(px(space::LG))716 .size(px(space::LG))
728 .rounded_full()717 .rounded_full()
729 .border_2()718 .border_2()
730- .border_color(palette.tokens.raise())719+ .border_color(t.raise())
731- .bg(super::presence_color(presence, palette))720+ .bg(super::presence_color(presence, t))
732 }721 }
733 722
734-fn presence_menu(current: Presence, entity: &Entity<Yumush>, palette: Palette) -> Popover {723+fn presence_menu(current: Presence, entity: &Entity<Yumush>, t: Tokens) -> Popover {
735 let entity = entity.clone();724 let entity = entity.clone();
736 Popover::new("presence_menu")725 Popover::new("presence_menu")
737 .anchor(Anchor::TopLeft)726 .anchor(Anchor::TopLeft)
738 .appearance(false)727 .appearance(false)
739 .trigger(Trigger::new(728 .trigger(Trigger::new(
740- clickable("presence_dot", palette, |_, _| {})729+ clickable("presence_dot", t, |_, _| {})
741 .rounded_full()730 .rounded_full()
742- .child(presence_dot(current, palette)),731+ .child(presence_dot(current, t)),
743 ))732 ))
744 .content(move |_, _, cx| {733 .content(move |_, _, cx| {
745 let popover = cx.entity();734 let popover = cx.entity();
746- super::parts::popover(palette.tokens)735+ super::parts::popover(t)
747 .p(px(space::XS))736 .p(px(space::XS))
748 .children(Presence::ALL.into_iter().map(|presence| {737 .children(Presence::ALL.into_iter().map(|presence| {
749 let popover = popover.clone();738 let popover = popover.clone();
@@ -759,14 +748,14 @@ fn presence_menu(current: Presence, entity: &Entity<Yumush>, palette: Palette) -
759 div()748 div()
760 .size(px(space::SM))749 .size(px(space::SM))
761 .rounded_full()750 .rounded_full()
762- .bg(super::presence_color(presence, palette)),751+ .bg(super::presence_color(presence, t)),
763 ),752 ),
764 if presence == current {753 if presence == current {
765- palette.text754+ t.paper()
766 } else {755 } else {
767- palette.muted756+ t.dim()
768 },757 },
769- palette,758+ t,
770 {759 {
771 let entity = entity.clone();760 let entity = entity.clone();
772 move |window, cx| {761 move |window, cx| {
@@ -786,10 +775,10 @@ pub(super) fn menu_row(
786 label: impl Into<SharedString>,775 label: impl Into<SharedString>,
787 leading: impl IntoElement,776 leading: impl IntoElement,
788 color: Hsla,777 color: Hsla,
789- palette: Palette,778+ t: Tokens,
790 on_click: impl Fn(&mut Window, &mut App) + 'static,779 on_click: impl Fn(&mut Window, &mut App) + 'static,
791 ) -> Stateful<Div> {780 ) -> Stateful<Div> {
792- clickable(id, palette, on_click)781+ clickable(id, t, on_click)
793 .h(px(size::CONTROL))782 .h(px(size::CONTROL))
794 .px(px(space::SM))783 .px(px(space::SM))
795 .flex()784 .flex()
@@ -809,7 +798,7 @@ impl Yumush {
809 window: &mut Window,798 window: &mut Window,
810 cx: &mut Context<Self>,799 cx: &mut Context<Self>,
811 ) {800 ) {
812- let Some(community_id) = self.chat.selected_community_id else {801+ let Some(community_id) = self.chat.session.selected_community_id else {
813 return;802 return;
814 };803 };
815 input_dialog(804 input_dialog(
@@ -880,7 +869,7 @@ impl Yumush {
880 window: &mut Window,869 window: &mut Window,
881 cx: &mut Context<Self>,870 cx: &mut Context<Self>,
882 ) {871 ) {
883- let Some(community_id) = self.chat.selected_community_id else {872+ let Some(community_id) = self.chat.session.selected_community_id else {
884 return;873 return;
885 };874 };
886 let network = self.network.clone();875 let network = self.network.clone();
@@ -902,17 +891,28 @@ impl Yumush {
902 window: &mut Window,891 window: &mut Window,
903 cx: &mut Context<Self>,892 cx: &mut Context<Self>,
904 ) {893 ) {
905- if let Some(me) = &self.user {894+ let me = self.user.as_ref().map(|me| me.id);
906- self.chat.presences.insert(me.id, presence);895+ let before = me.map(|me| self.presence_of(me));
896+ if let Some(me) = me {
897+ self.chat.session.presences.insert(me, presence);
907 }898 }
908- self.chat.card_menu = CardMenu::Main;899+ self.chat.session.card_menu = CardMenu::Main;
909 cx.notify();900 cx.notify();
910 901
911 let network = self.network.clone();902 let network = self.network.clone();
912 903
913- spawn_done(window, cx, async move {904+ cx.spawn_in(window, async move |this, cx| {
914- network.call(UpdatePresence { presence }).await905+ if let Err(error) = network.call(UpdatePresence { presence }).await {
915- });906+ let _ = this.update(cx, |yumush, cx| {
907+ if let (Some(me), Some(before)) = (me, before) {
908+ yumush.chat.session.presences.insert(me, before);
909+ }
910+ cx.notify();
911+ });
912+ notify_error(&this, cx, error);
913+ }
914+ })
915+ .detach();
916 }916 }
917 917
918 pub(super) fn delete_member_account(918 pub(super) fn delete_member_account(
crates/client/src/gui/settings_page.rsmodified+117 -150
@@ -15,7 +15,7 @@ use gpui_kit::{
15 };15 };
16 16
17 use super::{17 use super::{
18- Palette, Tooltip as _, Yumush, avatar,18+ Tooltip as _, Yumush, avatar,
19 chat::Armed,19 chat::Armed,
20 chat::View,20 chat::View,
21 clickable, notify_error, parts,21 clickable, notify_error, parts,
@@ -24,7 +24,7 @@ use super::{
24 widget::field,24 widget::field,
25 };25 };
26 use crate::{26 use crate::{
27- gui::style::{self, Theme, radius, size, space, stroke, text},27+ gui::style::{self, Theme, Tokens, radius, size, space, stroke, text},
28 settings::{self, FontSize, Launch, ShareAudio, ShareCodec},28 settings::{self, FontSize, Launch, ShareAudio, ShareCodec},
29 share::encode::capabilities,29 share::encode::capabilities,
30 storage::Store,30 storage::Store,
@@ -78,10 +78,10 @@ impl SettingsSection {
78 }78 }
79 }79 }
80 80
81-pub(super) fn setting_rows() -> [(SettingsSection, &'static str); 30] {81+pub(super) fn setting_rows() -> Vec<(SettingsSection, &'static str)> {
82 let s = &w().settings_page;82 let s = &w().settings_page;
83 let v = &w().voice_settings;83 let v = &w().voice_settings;
84- [84+ vec![
85 (SettingsSection::Profile, s.name),85 (SettingsSection::Profile, s.name),
86 (SettingsSection::Profile, s.status),86 (SettingsSection::Profile, s.status),
87 (SettingsSection::Profile, s.presence),87 (SettingsSection::Profile, s.presence),
@@ -92,8 +92,8 @@ pub(super) fn setting_rows() -> [(SettingsSection, &'static str); 30] {
92 (SettingsSection::Voice, v.input_volume),92 (SettingsSection::Voice, v.input_volume),
93 (SettingsSection::Voice, v.output_volume),93 (SettingsSection::Voice, v.output_volume),
94 (SettingsSection::Voice, v.mode),94 (SettingsSection::Voice, v.mode),
95- (SettingsSection::Voice, v.hear_yourself),95+ (SettingsSection::Voice, v.profile),
96- (SettingsSection::Voice, v.play_sound),96+ (SettingsSection::Voice, v.test),
97 (SettingsSection::Voice, v.sensitivity),97 (SettingsSection::Voice, v.sensitivity),
98 (SettingsSection::Voice, v.key),98 (SettingsSection::Voice, v.key),
99 (SettingsSection::CameraShare, s.camera),99 (SettingsSection::CameraShare, s.camera),
@@ -119,7 +119,7 @@ impl Yumush {
119 pub(super) fn settings_page(119 pub(super) fn settings_page(
120 &self,120 &self,
121 entity: &Entity<Self>,121 entity: &Entity<Self>,
122- palette: Palette,122+ t: Tokens,
123 cx: &App,123 cx: &App,
124 ) -> impl IntoElement {124 ) -> impl IntoElement {
125 let mut sections = Vec::new();125 let mut sections = Vec::new();
@@ -136,11 +136,11 @@ impl Yumush {
136 Picture {136 Picture {
137 id: "avatar_picker",137 id: "avatar_picker",
138 image: avatar(138 image: avatar(
139- palette,139+ t,
140 user,140 user,
141 px(size::AVATAR_LG),141 px(size::AVATAR_LG),
142 text(text::TITLE),142 text(text::TITLE),
143- &self.chat.avatars,143+ &self.chat.session.avatars,
144 ),144 ),
145 title: user.username.clone(),145 title: user.username.clone(),
146 subtitle: user.status.clone(),146 subtitle: user.status.clone(),
@@ -149,13 +149,13 @@ impl Yumush {
149 remove: Yumush::remove_avatar,149 remove: Yumush::remove_avatar,
150 },150 },
151 entity,151 entity,
152- palette,152+ t,
153 ))153 ))
154 .child(titled(154 .child(titled(
155 w().settings_page.identity,155 w().settings_page.identity,
156- palette,156+ t,
157 rows_column(157 rows_column(
158- palette,158+ t,
159 vec![159 vec![
160 text_row(160 text_row(
161 Editable {161 Editable {
@@ -167,7 +167,7 @@ impl Yumush {
167 emoji: None,167 emoji: None,
168 },168 },
169 entity,169 entity,
170- palette,170+ t,
171 cx,171 cx,
172 ),172 ),
173 text_row(173 text_row(
@@ -180,7 +180,7 @@ impl Yumush {
180 emoji: Some("status_settings_emoji"),180 emoji: Some("status_settings_emoji"),
181 },181 },
182 entity,182 entity,
183- palette,183+ t,
184 cx,184 cx,
185 ),185 ),
186 row(186 row(
@@ -189,7 +189,7 @@ impl Yumush {
189 "presence",189 "presence",
190 Presence::ALL.map(|presence| (presence, presence.label())),190 Presence::ALL.map(|presence| (presence, presence.label())),
191 self.presence_of(user.id),191 self.presence_of(user.id),
192- palette.tokens,192+ t,
193 move |presence, window, cx| {193 move |presence, window, cx| {
194 presence_entity.update(cx, |yumush, cx| {194 presence_entity.update(cx, |yumush, cx| {
195 yumush.set_presence(presence, window, cx)195 yumush.set_presence(presence, window, cx)
@@ -206,13 +206,13 @@ impl Yumush {
206 sections.push(section(206 sections.push(section(
207 SettingsSection::Voice.id(),207 SettingsSection::Voice.id(),
208 SettingsSection::Voice.label(),208 SettingsSection::Voice.label(),
209- palette,209+ t,
210- self.voice_rows(entity, palette, cx),210+ self.voice_rows(entity, t, cx),
211 ));211 ));
212 sections.push(Section::new(212 sections.push(Section::new(
213 SettingsSection::CameraShare.id(),213 SettingsSection::CameraShare.id(),
214 SettingsSection::CameraShare.label(),214 SettingsSection::CameraShare.label(),
215- camera_share(self, entity, palette),215+ camera_share(self, entity, t),
216 ));216 ));
217 let mut appearance = vec![217 let mut appearance = vec![
218 row(218 row(
@@ -221,7 +221,7 @@ impl Yumush {
221 Theme::ALL.map(|choice| (choice, choice.label())),221 Theme::ALL.map(|choice| (choice, choice.label())),
222 self.settings.theme,222 self.settings.theme,
223 entity,223 entity,
224- palette,224+ t,
225 Yumush::set_theme,225 Yumush::set_theme,
226 ),226 ),
227 ),227 ),
@@ -231,7 +231,7 @@ impl Yumush {
231 FontSize::ALL.map(|size| (size, size.label())),231 FontSize::ALL.map(|size| (size, size.label())),
232 self.settings.font_size,232 self.settings.font_size,
233 entity,233 entity,
234- palette,234+ t,
235 Yumush::set_font_size,235 Yumush::set_font_size,
236 ),236 ),
237 ),237 ),
@@ -241,21 +241,16 @@ impl Yumush {
241 Lang::ALL.map(|lang| (lang, lang.words().common.language)),241 Lang::ALL.map(|lang| (lang, lang.words().common.language)),
242 self.settings.language,242 self.settings.language,
243 entity,243 entity,
244- palette,244+ t,
245 Yumush::set_language,245 Yumush::set_language,
246 ),246 ),
247 ),247 ),
248 row(248 row(
249 w().settings_page.close_to_tray,249 w().settings_page.close_to_tray,
250- super::parts::toggle(250+ super::parts::toggle("close_to_tray_switch", self.settings.close_to_tray, t, {
251- "close_to_tray_switch",251+ let entity = entity.clone();
252- self.settings.close_to_tray,252+ move |_, cx| entity.update(cx, |yumush, cx| yumush.toggle_close_to_tray(cx))
253- palette.tokens,253+ }),
254- {
255- let entity = entity.clone();
256- move |_, cx| entity.update(cx, |yumush, cx| yumush.toggle_close_to_tray(cx))
257- },
258- ),
259 ),254 ),
260 row(255 row(
261 w().settings_page.launch,256 w().settings_page.launch,
@@ -263,56 +258,52 @@ impl Yumush {
263 Launch::options().map(|launch| (launch, launch.label())),258 Launch::options().map(|launch| (launch, launch.label())),
264 self.settings.launch,259 self.settings.launch,
265 entity,260 entity,
266- palette,261+ t,
267 Yumush::set_launch,262 Yumush::set_launch,
268 ),263 ),
269 ),264 ),
270 row(265 row(
271 w().settings_page.clock_seconds,266 w().settings_page.clock_seconds,
272- super::parts::toggle(267+ super::parts::toggle("clock_seconds_switch", self.settings.clock_seconds, t, {
273- "clock_seconds_switch",268+ let entity = entity.clone();
274- self.settings.clock_seconds,269+ move |_, cx| entity.update(cx, |yumush, cx| yumush.toggle_clock_seconds(cx))
275- palette.tokens,270+ }),
276- {
277- let entity = entity.clone();
278- move |_, cx| entity.update(cx, |yumush, cx| yumush.toggle_clock_seconds(cx))
279- },
280- ),
281 ),271 ),
282 ];272 ];
283 if let Some(user) = self.user.as_ref() {273 if let Some(user) = self.user.as_ref() {
284 appearance.push(row(274 appearance.push(row(
285 w().settings_page.your_hue,275 w().settings_page.your_hue,
286- hue_picker(Some(style::hue_of(user.id)), entity, palette),276+ hue_picker(style::hue_of(user.id), entity, t),
287 ));277 ));
288 }278 }
289 sections.push(section(279 sections.push(section(
290 SettingsSection::Appearance.id(),280 SettingsSection::Appearance.id(),
291 SettingsSection::Appearance.label(),281 SettingsSection::Appearance.label(),
292- palette,282+ t,
293 appearance,283 appearance,
294 ));284 ));
295 sections.push(section(285 sections.push(section(
296 SettingsSection::Storage.id(),286 SettingsSection::Storage.id(),
297 SettingsSection::Storage.label(),287 SettingsSection::Storage.label(),
298- palette,288+ t,
299 self.chat289 self.chat
290+ .session
300 .storage291 .storage
301 .iter()292 .iter()
302- .map(|&(store, bytes)| storage_row(store, bytes, entity, palette))293+ .map(|&(store, bytes)| storage_row(store, bytes, entity, t))
303 .collect(),294 .collect(),
304 ));295 ));
305 sections.push(section(296 sections.push(section(
306 SettingsSection::About.id(),297 SettingsSection::About.id(),
307 SettingsSection::About.label(),298 SettingsSection::About.label(),
308- palette,299+ t,
309 [300 [
310 (w().settings_page.version, crate::VERSION),301 (w().settings_page.version, crate::VERSION),
311 (w().settings_page.commit, crate::COMMIT),302 (w().settings_page.commit, crate::COMMIT),
312 (w().settings_page.target, crate::TARGET),303 (w().settings_page.target, crate::TARGET),
313 ]304 ]
314 .into_iter()305 .into_iter()
315- .map(|(label, value)| row(label, div().text_color(palette.muted).child(value)))306+ .map(|(label, value)| row(label, div().text_color(t.dim()).child(value)))
316 .collect(),307 .collect(),
317 ));308 ));
318 if self.user.is_some() {309 if self.user.is_some() {
@@ -324,7 +315,7 @@ impl Yumush {
324 w().settings_page.delete_account,315 w().settings_page.delete_account,
325 self.armed(Armed::DeleteAccount),316 self.armed(Armed::DeleteAccount),
326 entity,317 entity,
327- palette,318+ t,
328 Yumush::delete_account,319 Yumush::delete_account,
329 )320 )
330 .into_any_element(),321 .into_any_element(),
@@ -335,10 +326,10 @@ impl Yumush {
335 page(326 page(
336 "settings_scroll",327 "settings_scroll",
337 entity,328 entity,
338- palette,329+ t,
339 w().settings_page.title,330 w().settings_page.title,
340 sections,331 sections,
341- self.chat.section,332+ self.chat.session.section,
342 )333 )
343 }334 }
344 335
@@ -373,7 +364,7 @@ impl Yumush {
373 pub(super) fn save_status(&mut self, window: &mut Window, cx: &mut Context<Self>) {364 pub(super) fn save_status(&mut self, window: &mut Window, cx: &mut Context<Self>) {
374 let status = self.chat.status_input.read(cx).text().to_string();365 let status = self.chat.status_input.read(cx).text().to_string();
375 let network = self.network.clone();366 let network = self.network.clone();
376- self.chat.card_menu = super::chat::CardMenu::Main;367+ self.chat.session.card_menu = super::chat::CardMenu::Main;
377 cx.notify();368 cx.notify();
378 369
379 cx.spawn_in(window, async move |this, cx| {370 cx.spawn_in(window, async move |this, cx| {
@@ -423,6 +414,7 @@ impl Yumush {
423 match network.call(DeleteUser { user_id }).await {414 match network.call(DeleteUser { user_id }).await {
424 Ok(()) => {415 Ok(()) => {
425 let _ = this.update_in(cx, |yumush, window, cx| {416 let _ = this.update_in(cx, |yumush, window, cx| {
417+ yumush.accounts.forget(user_id);
426 yumush.end_session(window, cx);418 yumush.end_session(window, cx);
427 });419 });
428 if let Err(error) = network.detach().await {420 if let Err(error) = network.detach().await {
@@ -477,7 +469,7 @@ impl Yumush {
477 .spawn(async { Store::ALL.map(|store| (store, store.size())).to_vec() })469 .spawn(async { Store::ALL.map(|store| (store, store.size())).to_vec() })
478 .await;470 .await;
479 let _ = this.update(cx, |yumush, cx| {471 let _ = this.update(cx, |yumush, cx| {
480- yumush.chat.storage = storage;472+ yumush.chat.session.storage = storage;
481 cx.notify();473 cx.notify();
482 });474 });
483 })475 })
@@ -510,7 +502,7 @@ fn apply_user(this: &WeakEntity<Yumush>, cx: &mut AsyncWindowContext, result: Re
510 }502 }
511 }503 }
512 504
513-fn storage_row(store: Store, bytes: u64, entity: &Entity<Yumush>, palette: Palette) -> Div {505+fn storage_row(store: Store, bytes: u64, entity: &Entity<Yumush>, t: Tokens) -> Div {
514 let w = &w().settings_page;506 let w = &w().settings_page;
515 let (label, id) = match store {507 let (label, id) = match store {
516 Store::Media => (w.media, "clear_media"),508 Store::Media => (w.media, "clear_media"),
@@ -523,10 +515,10 @@ fn storage_row(store: Store, bytes: u64, entity: &Entity<Yumush>, palette: Palet
523 .flex()515 .flex()
524 .items_center()516 .items_center()
525 .gap(px(space::SM))517 .gap(px(space::SM))
526- .child(div().text_color(palette.muted).child(super::storage(bytes)))518+ .child(div().text_color(t.dim()).child(super::storage(bytes)))
527 .when(store.clearable() && bytes > 0, |this| {519 .when(store.clearable() && bytes > 0, |this| {
528 this.child(520 this.child(
529- small_button(id, palette, palette.danger, move |_, cx| {521+ small_button(id, t, t.bad(), move |_, cx| {
530 entity.update(cx, |yumush, cx| yumush.clear_storage(store, cx));522 entity.update(cx, |yumush, cx| yumush.clear_storage(store, cx));
531 })523 })
532 .child(w.clear),524 .child(w.clear),
@@ -535,8 +527,7 @@ fn storage_row(store: Store, bytes: u64, entity: &Entity<Yumush>, palette: Palet
535 )527 )
536 }528 }
537 529
538-fn hue_picker(current: Option<Hue>, entity: &Entity<Yumush>, palette: Palette) -> Div {530+fn hue_picker(current: Hue, entity: &Entity<Yumush>, t: Tokens) -> Div {
539- let t = palette.tokens;
540 div()531 div()
541 .flex()532 .flex()
542 .items_center()533 .items_center()
@@ -551,7 +542,7 @@ fn hue_picker(current: Option<Hue>, entity: &Entity<Yumush>, palette: Palette) -
551 .justify_center()542 .justify_center()
552 .rounded(px(radius::FULL))543 .rounded(px(radius::FULL))
553 .border(px(stroke::LINE))544 .border(px(stroke::LINE))
554- .border_color(if current == Some(hue) {545+ .border_color(if current == hue {
555 t.paper()546 t.paper()
556 } else {547 } else {
557 transparent_black()548 transparent_black()
@@ -569,25 +560,25 @@ fn hue_picker(current: Option<Hue>, entity: &Entity<Yumush>, palette: Palette) -
569 }))560 }))
570 }561 }
571 562
572-fn camera_share(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> AnyElement {563+fn camera_share(yumush: &Yumush, entity: &Entity<Yumush>, t: Tokens) -> AnyElement {
573 div()564 div()
574 .flex()565 .flex()
575 .flex_col()566 .flex_col()
576 .gap(px(space::XL))567 .gap(px(space::XL))
577 .child(titled(568 .child(titled(
578 w().settings_page.camera,569 w().settings_page.camera,
579- palette,570+ t,
580- rows_column(palette, camera_rows(yumush, entity, palette)),571+ rows_column(t, camera_rows(yumush, entity, t)),
581 ))572 ))
582 .child(titled(573 .child(titled(
583 w().settings_page.screen_share,574 w().settings_page.screen_share,
584- palette,575+ t,
585- rows_column(palette, screen_rows(yumush, entity, palette)),576+ rows_column(t, screen_rows(yumush, entity, t)),
586 ))577 ))
587 .into_any_element()578 .into_any_element()
588 }579 }
589 580
590-fn camera_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Vec<Div> {581+fn camera_rows(yumush: &Yumush, entity: &Entity<Yumush>, t: Tokens) -> Vec<Div> {
591 let modes = share_modes(yumush, Kind::Camera);582 let modes = share_modes(yumush, Kind::Camera);
592 let max_height = capabilities().max_height;583 let max_height = capabilities().max_height;
593 let top = share::clamp(yumush.settings.share.top(Kind::Camera), &modes, max_height);584 let top = share::clamp(yumush.settings.share.top(Kind::Camera), &modes, max_height);
@@ -601,7 +592,7 @@ fn camera_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Ve
601 .into_iter()592 .into_iter()
602 .filter(|(resolution, _)| resolutions.contains(resolution)),593 .filter(|(resolution, _)| resolutions.contains(resolution)),
603 top.resolution,594 top.resolution,
604- palette.tokens,595+ t,
605 share_pick(entity, Kind::Camera, Yumush::set_share_resolution),596 share_pick(entity, Kind::Camera, Yumush::set_share_resolution),
606 ),597 ),
607 ),598 ),
@@ -611,14 +602,14 @@ fn camera_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Ve
611 "camera_fps",602 "camera_fps",
612 FPS.into_iter().filter(|(value, _)| fps.contains(value)),603 FPS.into_iter().filter(|(value, _)| fps.contains(value)),
613 top.fps,604 top.fps,
614- palette.tokens,605+ t,
615 share_pick(entity, Kind::Camera, Yumush::set_share_fps),606 share_pick(entity, Kind::Camera, Yumush::set_share_fps),
616 ),607 ),
617 ),608 ),
618 ]609 ]
619 }610 }
620 611
621-fn screen_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Vec<Div> {612+fn screen_rows(yumush: &Yumush, entity: &Entity<Yumush>, t: Tokens) -> Vec<Div> {
622 let settings = &yumush.settings.share;613 let settings = &yumush.settings.share;
623 let modes = share_modes(yumush, Kind::Screen);614 let modes = share_modes(yumush, Kind::Screen);
624 let max_height = capabilities().max_height;615 let max_height = capabilities().max_height;
@@ -635,7 +626,7 @@ fn screen_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Ve
635 .into_iter()626 .into_iter()
636 .filter(|(resolution, _)| resolutions.contains(resolution)),627 .filter(|(resolution, _)| resolutions.contains(resolution)),
637 top.resolution,628 top.resolution,
638- palette.tokens,629+ t,
639 share_pick(entity, Kind::Screen, Yumush::set_share_resolution),630 share_pick(entity, Kind::Screen, Yumush::set_share_resolution),
640 ),631 ),
641 ),632 ),
@@ -645,7 +636,7 @@ fn screen_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Ve
645 "screen_fps",636 "screen_fps",
646 FPS.into_iter().filter(|(value, _)| fps.contains(value)),637 FPS.into_iter().filter(|(value, _)| fps.contains(value)),
647 top.fps,638 top.fps,
648- palette.tokens,639+ t,
649 share_pick(entity, Kind::Screen, Yumush::set_share_fps),640 share_pick(entity, Kind::Screen, Yumush::set_share_fps),
650 ),641 ),
651 ),642 ),
@@ -658,27 +649,28 @@ fn screen_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Ve
658 ShareCodec::Only(codec) => capabilities().encode.contains(codec),649 ShareCodec::Only(codec) => capabilities().encode.contains(codec),
659 }),650 }),
660 settings.codec,651 settings.codec,
661- palette.tokens,652+ t,
662- share_pick(entity, Kind::Screen, Yumush::set_share_codec),653+ share_pick(
654+ entity,
655+ Kind::Screen,
656+ |yumush: &mut Yumush, _: Kind, codec: ShareCodec, cx: &mut Context<Yumush>| {
657+ yumush.set_share_codec(codec, cx)
658+ },
659+ ),
663 ),660 ),
664 ),661 ),
665 row(662 row(
666 w().settings_page.share_audio,663 w().settings_page.share_audio,
667- parts::toggle(664+ parts::toggle("share_audio_switch", audio_on, t, move |_, cx| {
668- "share_audio_switch",665+ audio_entity.update(cx, |yumush, cx| {
669- audio_on,666+ let mode = if audio_on {
670- palette.tokens,667+ AudioMode::Off
671- move |_, cx| {668+ } else {
672- audio_entity.update(cx, |yumush, cx| {669+ AudioMode::Everything
673- let mode = if audio_on {670+ };
674- AudioMode::Off671+ yumush.set_share_audio_mode(mode, cx)
675- } else {672+ })
676- AudioMode::Everything673+ }),
677- };
678- yumush.set_share_audio_mode(mode, cx)
679- })
680- },
681- ),
682 ),674 ),
683 ]675 ]
684 }676 }
@@ -686,16 +678,10 @@ fn screen_rows(yumush: &Yumush, entity: &Entity<Yumush>, palette: Palette) -> Ve
686 fn share_pick<T: Copy + 'static>(678 fn share_pick<T: Copy + 'static>(
687 entity: &Entity<Yumush>,679 entity: &Entity<Yumush>,
688 kind: Kind,680 kind: Kind,
689- set: fn(&mut Yumush, T, &mut Context<Yumush>),681+ set: fn(&mut Yumush, Kind, T, &mut Context<Yumush>),
690 ) -> impl Fn(T, &mut Window, &mut App) + Clone + 'static {682 ) -> impl Fn(T, &mut Window, &mut App) + Clone + 'static {
691 let entity = entity.clone();683 let entity = entity.clone();
692- move |value, _, cx| {684+ move |value, _, cx| entity.update(cx, |yumush, cx| set(yumush, kind, value, cx))
693- entity.update(cx, |yumush, cx| {
694- let tab = std::mem::replace(&mut yumush.share_tab, kind);
695- set(yumush, value, cx);
696- yumush.share_tab = tab;
697- })
698- }
699 }685 }
700 686
701 pub(super) fn picked_avatar(687 pub(super) fn picked_avatar(
@@ -738,7 +724,7 @@ impl Section {
738 pub(super) fn page(724 pub(super) fn page(
739 id: &'static str,725 id: &'static str,
740 entity: &Entity<Yumush>,726 entity: &Entity<Yumush>,
741- palette: Palette,727+ t: Tokens,
742 title: impl IntoElement,728 title: impl IntoElement,
743 sections: Vec<Section>,729 sections: Vec<Section>,
744 selected: Option<&'static str>,730 selected: Option<&'static str>,
@@ -757,11 +743,11 @@ pub(super) fn page(
757 gpui_kit::ElementId::Name(format!("{id}_index_{key}").into()),743 gpui_kit::ElementId::Name(format!("{id}_index_{key}").into()),
758 section.title,744 section.title,
759 position == selected,745 position == selected,
760- palette.tokens,746+ t,
761 move |_, cx| {747 move |_, cx| {
762 entity.update(cx, |yumush, cx| {748 entity.update(cx, |yumush, cx| {
763- yumush.chat.section = Some(key);749+ yumush.chat.session.section = Some(key);
764- yumush.chat.armed = None;750+ yumush.chat.session.armed = None;
765 cx.notify();751 cx.notify();
766 })752 })
767 },753 },
@@ -773,21 +759,21 @@ pub(super) fn page(
773 title: name, body, ..759 title: name, body, ..
774 }) = sections.into_iter().nth(selected)760 }) = sections.into_iter().nth(selected)
775 else {761 else {
776- return frame(id, entity, palette, title, index, Vec::new(), Vec::new());762+ return frame(id, entity, t, title, index, Vec::new(), Vec::new());
777 };763 };
778 764
779 frame(765 frame(
780 id,766 id,
781 entity,767 entity,
782- palette,768+ t,
783 title,769 title,
784 index,770 index,
785 Vec::new(),771 Vec::new(),
786- vec![heading(name, Vec::new(), palette).into_any_element(), body],772+ vec![heading(name, Vec::new(), t).into_any_element(), body],
787 )773 )
788 }774 }
789 775
790-pub(super) fn heading(title: &str, actions: Vec<AnyElement>, palette: Palette) -> Div {776+pub(super) fn heading(title: &str, actions: Vec<AnyElement>, t: Tokens) -> Div {
791 div()777 div()
792 .h(px(size::CONTROL))778 .h(px(size::CONTROL))
793 .flex()779 .flex()
@@ -800,7 +786,7 @@ pub(super) fn heading(title: &str, actions: Vec<AnyElement>, palette: Palette) -
800 .truncate()786 .truncate()
801 .text_size(text(text::TITLE))787 .text_size(text(text::TITLE))
802 .font_weight(FontWeight::SEMIBOLD)788 .font_weight(FontWeight::SEMIBOLD)
803- .text_color(palette.tokens.paper())789+ .text_color(t.paper())
804 .child(title.to_string()),790 .child(title.to_string()),
805 )791 )
806 .children(actions)792 .children(actions)
@@ -809,7 +795,7 @@ pub(super) fn heading(title: &str, actions: Vec<AnyElement>, palette: Palette) -
809 pub(super) fn frame(795 pub(super) fn frame(
810 id: &'static str,796 id: &'static str,
811 entity: &Entity<Yumush>,797 entity: &Entity<Yumush>,
812- palette: Palette,798+ t: Tokens,
813 title: impl IntoElement,799 title: impl IntoElement,
814 index: Vec<AnyElement>,800 index: Vec<AnyElement>,
815 footer: Vec<AnyElement>,801 footer: Vec<AnyElement>,
@@ -834,7 +820,7 @@ pub(super) fn frame(
834 .flex()820 .flex()
835 .flex_col()821 .flex_col()
836 .child(822 .child(
837- clickable("page_back", palette, move |window, cx| {823+ clickable("page_back", t, move |window, cx| {
838 back.update(cx, |yumush, cx| yumush.show_view(View::Chat, window, cx));824 back.update(cx, |yumush, cx| yumush.show_view(View::Chat, window, cx));
839 })825 })
840 .tip(w().settings_page.back_esc)826 .tip(w().settings_page.back_esc)
@@ -848,7 +834,7 @@ pub(super) fn frame(
848 .gap(px(space::SM))834 .gap(px(space::SM))
849 .min_w_0()835 .min_w_0()
850 .text_size(text(text::UI))836 .text_size(text(text::UI))
851- .text_color(palette.muted)837+ .text_color(t.dim())
852 .child(838 .child(
853 super::parts::small_icon(gpui_kit::assets::IconName::ArrowLeft)839 super::parts::small_icon(gpui_kit::assets::IconName::ArrowLeft)
854 .flex_shrink_0(),840 .flex_shrink_0(),
@@ -881,13 +867,8 @@ pub(super) fn frame(
881 )867 )
882 }868 }
883 869
884-pub(super) fn section(870+pub(super) fn section(id: &'static str, title: &'static str, t: Tokens, rows: Vec<Div>) -> Section {
885- id: &'static str,871+ Section::new(id, title, rows_column(t, rows).into_any_element())
886- title: &'static str,
887- palette: Palette,
888- rows: Vec<Div>,
889-) -> Section {
890- Section::new(id, title, rows_column(palette, rows).into_any_element())
891 }872 }
892 873
893 pub(super) fn danger(id: &'static str, actions: Vec<AnyElement>) -> Section {874 pub(super) fn danger(id: &'static str, actions: Vec<AnyElement>) -> Section {
@@ -904,15 +885,15 @@ pub(super) fn danger(id: &'static str, actions: Vec<AnyElement>) -> Section {
904 )885 )
905 }886 }
906 887
907-fn titled(title: &'static str, palette: Palette, rows: impl IntoElement) -> Div {888+fn titled(title: &'static str, t: Tokens, rows: impl IntoElement) -> Div {
908 div()889 div()
909 .flex()890 .flex()
910 .flex_col()891 .flex_col()
911- .child(parts::section(title, palette.tokens))892+ .child(parts::section(title, t))
912 .child(rows)893 .child(rows)
913 }894 }
914 895
915-fn rows_column(_palette: Palette, rows: Vec<Div>) -> AnyElement {896+fn rows_column(_t: Tokens, rows: Vec<Div>) -> AnyElement {
916 div().flex().flex_col().children(rows).into_any_element()897 div().flex().flex_col().children(rows).into_any_element()
917 }898 }
918 899
@@ -925,18 +906,13 @@ pub(super) struct Editable<'a> {
925 pub emoji: Option<&'static str>,906 pub emoji: Option<&'static str>,
926 }907 }
927 908
928-pub(super) fn text_row(909+pub(super) fn text_row(editable: Editable, entity: &Entity<Yumush>, t: Tokens, cx: &App) -> Div {
929- editable: Editable,
930- entity: &Entity<Yumush>,
931- palette: Palette,
932- cx: &App,
933-) -> Div {
934 let dirty = editable.input.read(cx).text() != editable.current;910 let dirty = editable.input.read(cx).text() != editable.current;
935 let picker = editable.emoji.map(|id| {911 let picker = editable.emoji.map(|id| {
936 super::glyph::picker_button(912 super::glyph::picker_button(
937 id,913 id,
938 entity,914 entity,
939- palette,915+ t,
940 super::glyph::insert_into(editable.input.clone()),916 super::glyph::insert_into(editable.input.clone()),
941 )917 )
942 });918 });
@@ -958,18 +934,18 @@ pub(super) fn text_row(
958 .flex()934 .flex()
959 .items_center()935 .items_center()
960 .gap(px(space::SM))936 .gap(px(space::SM))
961- .child(field(palette, editable.input).flex_1())937+ .child(field(t, editable.input).flex_1())
962 .children(picker)938 .children(picker)
963 .when(dirty, |this| {939 .when(dirty, |this| {
964 this.child(940 this.child(
965- clickable(editable.id, palette, move |window, cx| {941+ clickable(editable.id, t, move |window, cx| {
966 entity.update(cx, |yumush, cx| save(yumush, window, cx));942 entity.update(cx, |yumush, cx| save(yumush, window, cx));
967 })943 })
968 .tip(w().settings_page.save)944 .tip(w().settings_page.save)
969 .px(px(space::XS))945 .px(px(space::XS))
970 .rounded(px(radius::SM))946 .rounded(px(radius::SM))
971 .text_size(text(text::CAPTION))947 .text_size(text(text::CAPTION))
972- .text_color(palette.tokens.paper())948+ .text_color(t.paper())
973 .child("↵"),949 .child("↵"),
974 )950 )
975 }),951 }),
@@ -986,7 +962,7 @@ pub(super) struct Picture {
986 pub remove: fn(&mut Yumush, &mut Window, &mut Context<Yumush>),962 pub remove: fn(&mut Yumush, &mut Window, &mut Context<Yumush>),
987 }963 }
988 964
989-pub(super) fn picture_card(picture: Picture, entity: &Entity<Yumush>, palette: Palette) -> Div {965+pub(super) fn picture_card(picture: Picture, entity: &Entity<Yumush>, t: Tokens) -> Div {
990 let Picture {966 let Picture {
991 id,967 id,
992 image,968 image,
@@ -1031,7 +1007,7 @@ pub(super) fn picture_card(picture: Picture, entity: &Entity<Yumush>, palette: P
1031 this.child(1007 this.child(
1032 div()1008 div()
1033 .text_size(text(text::CAPTION))1009 .text_size(text(text::CAPTION))
1034- .text_color(palette.muted)1010+ .text_color(t.dim())
1035 .min_w_0()1011 .min_w_0()
1036 .child(super::glyph::line(1012 .child(super::glyph::line(
1037 subtitle.into(),1013 subtitle.into(),
@@ -1041,25 +1017,20 @@ pub(super) fn picture_card(picture: Picture, entity: &Entity<Yumush>, palette: P
1041 }),1017 }),
1042 )1018 )
1043 .children(removable.then(|| {1019 .children(removable.then(|| {
1044- small_button(1020+ small_button("remove_picture_button", t, t.bad(), move |window, cx| {
1045- "remove_picture_button",1021+ remove_entity.update(cx, |yumush, cx| remove(yumush, window, cx));
1046- palette,1022+ })
1047- palette.danger,
1048- move |window, cx| {
1049- remove_entity.update(cx, |yumush, cx| remove(yumush, window, cx));
1050- },
1051- )
1052 .child(w().settings_page.remove)1023 .child(w().settings_page.remove)
1053 }))1024 }))
1054 }1025 }
1055 1026
1056 pub(super) fn small_button(1027 pub(super) fn small_button(
1057 id: &'static str,1028 id: &'static str,
1058- palette: Palette,1029+ t: Tokens,
1059 color: Hsla,1030 color: Hsla,
1060 on_click: impl Fn(&mut Window, &mut App) + 'static,1031 on_click: impl Fn(&mut Window, &mut App) + 'static,
1061 ) -> Stateful<Div> {1032 ) -> Stateful<Div> {
1062- super::parts::press(id, palette.tokens, on_click)1033+ super::parts::press(id, t, on_click)
1063 .px(px(space::SM))1034 .px(px(space::SM))
1064 .text_size(text(text::UI))1035 .text_size(text(text::UI))
1065 .text_color(color)1036 .text_color(color)
@@ -1070,11 +1041,11 @@ pub(super) fn delete_control(
1070 label: &'static str,1041 label: &'static str,
1071 confirming: bool,1042 confirming: bool,
1072 entity: &Entity<Yumush>,1043 entity: &Entity<Yumush>,
1073- palette: Palette,1044+ t: Tokens,
1074 action: fn(&mut Yumush, &mut Window, &mut Context<Yumush>),1045 action: fn(&mut Yumush, &mut Window, &mut Context<Yumush>),
1075 ) -> impl IntoElement {1046 ) -> impl IntoElement {
1076 let entity = entity.clone();1047 let entity = entity.clone();
1077- small_button(id, palette, palette.danger, move |window, cx| {1048+ small_button(id, t, t.bad(), move |window, cx| {
1078 entity.update(cx, |yumush, cx| action(yumush, window, cx));1049 entity.update(cx, |yumush, cx| action(yumush, window, cx));
1079 })1050 })
1080 .when(confirming, |this| this.font_weight(FontWeight::MEDIUM))1051 .when(confirming, |this| this.font_weight(FontWeight::MEDIUM))
@@ -1097,15 +1068,15 @@ pub(super) fn row(label: &'static str, control: impl IntoElement) -> Div {
1097 .child(control)1068 .child(control)
1098 }1069 }
1099 1070
1100-pub(super) fn segment_track(_palette: Palette) -> Div {1071+pub(super) fn segment_track(_t: Tokens) -> Div {
1101 div().h(px(size::CONTROL)).flex().gap(px(space::LG))1072 div().h(px(size::CONTROL)).flex().gap(px(space::LG))
1102 }1073 }
1103 1074
1104-pub(super) fn segment<E: Styled>(item: E, active: bool, palette: Palette) -> E {1075+pub(super) fn segment<E: Styled>(item: E, active: bool, t: Tokens) -> E {
1105 let (border, text) = if active {1076 let (border, text) = if active {
1106- (palette.tokens.paper(), palette.tokens.paper())1077+ (t.paper(), t.paper())
1107 } else {1078 } else {
1108- (transparent_black(), palette.muted)1079+ (transparent_black(), t.dim())
1109 };1080 };
1110 1081
1111 item.flex()1082 item.flex()
@@ -1120,7 +1091,7 @@ pub(super) fn segmented<T: Copy + PartialEq + 'static>(
1120 options: impl IntoIterator<Item = (T, &'static str)>,1091 options: impl IntoIterator<Item = (T, &'static str)>,
1121 selected: T,1092 selected: T,
1122 entity: &Entity<Yumush>,1093 entity: &Entity<Yumush>,
1123- palette: Palette,1094+ t: Tokens,
1124 select: fn(&mut Yumush, T, &mut Context<Yumush>),1095 select: fn(&mut Yumush, T, &mut Context<Yumush>),
1125 ) -> impl IntoElement {1096 ) -> impl IntoElement {
1126 div()1097 div()
@@ -1138,17 +1109,13 @@ pub(super) fn segmented<T: Copy + PartialEq + 'static>(
1138 .gap(px(space::XXS))1109 .gap(px(space::XXS))
1139 .text_size(text(text::UI))1110 .text_size(text(text::UI))
1140 .font_weight(FontWeight::MEDIUM)1111 .font_weight(FontWeight::MEDIUM)
1141- .text_color(if on {1112+ .text_color(if on { t.paper() } else { t.dim() })
1142- palette.tokens.paper()
1143- } else {
1144- palette.muted
1145- })
1146 .on_click(move |_, _, cx| {1113 .on_click(move |_, _, cx| {
1147 entity.update(cx, |yumush, cx| select(yumush, choice, cx));1114 entity.update(cx, |yumush, cx| select(yumush, choice, cx));
1148 })1115 })
1149 .child(label)1116 .child(label)
1150 .child(div().h(px(stroke::LINE)).bg(if on {1117 .child(div().h(px(stroke::LINE)).bg(if on {
1151- palette.tokens.paper()1118+ t.paper()
1152 } else {1119 } else {
1153 transparent_black()1120 transparent_black()
1154 }))1121 }))
crates/client/src/gui/share_view.rsmodified+250 -185
@@ -1,34 +1,17 @@
1-use common::model::Id;
2 use std::{1 use std::{
3 collections::HashMap,2 collections::HashMap,
4 sync::Arc,3 sync::Arc,
5 time::{Duration, Instant},4 time::{Duration, Instant},
6 };5 };
7 6
7+use super::camera_view::CAMERA_BUSY;
8+use common::model::Id;
8 use common::share::{Codec, Fps, Kind, Mode, Quality, Resolution, clamp, options};9 use common::share::{Codec, Fps, Kind, Mode, Quality, Resolution, clamp, options};
10+use std::sync::atomic::Ordering;
9 11
10 use crate::lang::w;12 use crate::lang::w;
11 use crate::share::Target;13 use crate::share::Target;
12 14
13-const FULL_VOLUME: f32 = 100.;
14-const VOLUME_WIDTH: f32 = 80.;
15-const APPS_HEIGHT: f32 = 160.;
16-const PICK_COLUMNS: usize = 3;
17-const PICK_REFRESH: Duration = Duration::from_millis(1500);
18-
19-const PICK_ROW: f32 = size::THUMB + size::ROW;
20-const PREVIEW_AGE: Duration = Duration::from_secs(3);
21-
22-#[derive(Default)]
23-struct Picker {
24- sources: Vec<(Target, String)>,
25- previews: HashMap<Target, (Instant, Arc<RenderImage>)>,
26-}
27-
28-const TOP_QUALITY: Quality = Quality {
29- resolution: Resolution::P2160,
30- fps: Fps::F60,
31-};
32 use gpui_kit::{15 use gpui_kit::{
33 Anchor, AnyElement, App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement,16 Anchor, AnyElement, App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement,
34 KeyDownEvent, Keystroke, Modifiers, MouseButton, ObjectFit, ParentElement, PlatformInput,17 KeyDownEvent, Keystroke, Modifiers, MouseButton, ObjectFit, ParentElement, PlatformInput,
@@ -45,7 +28,7 @@ use gpui_kit::{
45 };28 };
46 29
47 use super::{30 use super::{
48- Palette, Tooltip as _, Trigger, Yumush, camera_view,31+ Tooltip as _, Trigger, Yumush, camera_view,
49 chat::View,32 chat::View,
50 clickable, entity_action,33 clickable, entity_action,
51 media_view::into_render_image,34 media_view::into_render_image,
@@ -53,7 +36,7 @@ use super::{
53 parts::{self, Scale, Tone, icon_button, scrim},36 parts::{self, Scale, Tone, icon_button, scrim},
54 settings_page::segmented,37 settings_page::segmented,
55 stream_stats::{stream_card, watch_stats},38 stream_stats::{stream_card, watch_stats},
56- style::{radius, size, space, text},39+ style::{Tokens, radius, size, space, text},
57 surface::Surface,40 surface::Surface,
58 text,41 text,
59 widget::spawn_warn,42 widget::spawn_warn,
@@ -63,27 +46,65 @@ use crate::{
63 share::{46 share::{
64 audio::{AudioApp, AudioKind, is_excluded, is_picked},47 audio::{AudioApp, AudioKind, is_excluded, is_picked},
65 encode::capabilities,48 encode::capabilities,
66- session::WatchQuality,49+ watch::WatchQuality,
67 },50 },
68 };51 };
69 52
53+const FULL_VOLUME: f32 = 100.;
54+const VOLUME_WIDTH: f32 = 80.;
55+const APPS_HEIGHT: f32 = 160.;
56+const PICK_COLUMNS: usize = 3;
57+const PICK_REFRESH: Duration = Duration::from_millis(1500);
58+const PICK_ROW: f32 = size::THUMB + size::ROW;
59+const PREVIEW_AGE: Duration = Duration::from_secs(3);
60+const TOP_QUALITY: Quality = Quality {
61+ resolution: Resolution::P2160,
62+ fps: Fps::F60,
63+};
70 const FLOAT_RIGHT: f32 = space::LG;64 const FLOAT_RIGHT: f32 = space::LG;
71 const FLOAT_BOTTOM: f32 = size::ROW * 2. + space::XL;65 const FLOAT_BOTTOM: f32 = size::ROW * 2. + space::XL;
72 const FLOAT_WIDTH: f32 = size::MEDIA;66 const FLOAT_WIDTH: f32 = size::MEDIA;
73 const FLOAT_HEIGHT: f32 = size::MEDIA * 9. / 16.;67 const FLOAT_HEIGHT: f32 = size::MEDIA * 9. / 16.;
74 const DRAG_SLOP: f32 = 4.;68 const DRAG_SLOP: f32 = 4.;
69+const BAR_TTL: Duration = Duration::from_millis(2500);
70+const APPS_REFRESH: Duration = Duration::from_secs(2);
71+const APPS_IDLE: Duration = Duration::from_secs(5);
72+
73+#[derive(Default)]
74+struct Picker {
75+ sources: Vec<(Target, String)>,
76+ previews: HashMap<Target, (Instant, Arc<RenderImage>)>,
77+}
78+
79+#[derive(Default, Clone, Copy)]
80+enum Drag {
81+ #[default]
82+ Idle,
83+ Pressed {
84+ start: gpui_kit::Point<gpui_kit::Pixels>,
85+ from: (f32, f32),
86+ },
87+ Dragging {
88+ start: gpui_kit::Point<gpui_kit::Pixels>,
89+ from: (f32, f32),
90+ },
91+}
92+
93+impl Drag {
94+ fn grab(self) -> Option<(gpui_kit::Point<gpui_kit::Pixels>, (f32, f32))> {
95+ match self {
96+ Drag::Idle => None,
97+ Drag::Pressed { start, from } | Drag::Dragging { start, from } => Some((start, from)),
98+ }
99+ }
100+}
75 101
76 #[derive(Default)]102 #[derive(Default)]
77 pub(super) struct Float {103 pub(super) struct Float {
78 shift: (f32, f32),104 shift: (f32, f32),
79- grab: Option<(gpui_kit::Point<gpui_kit::Pixels>, (f32, f32))>,105+ drag: Drag,
80- moved: bool,
81 }106 }
82 107
83-const BAR_TTL: Duration = Duration::from_millis(2500);
84-const APPS_REFRESH: Duration = Duration::from_secs(2);
85-const APPS_IDLE: Duration = Duration::from_secs(5);
86-
87 pub(super) const RESOLUTIONS: [(Resolution, &str); 6] = [108 pub(super) const RESOLUTIONS: [(Resolution, &str); 6] = [
88 (Resolution::P360, "360"),109 (Resolution::P360, "360"),
89 (Resolution::P480, "480"),110 (Resolution::P480, "480"),
@@ -128,7 +149,7 @@ impl AudioMode {
128 }149 }
129 }150 }
130 151
131-fn pick(app: &AudioApp) -> ShareAudio {152+fn audio_choice(app: &AudioApp) -> ShareAudio {
132 match app.kind {153 match app.kind {
133 AudioKind::App => ShareAudio::App {154 AudioKind::App => ShareAudio::App {
134 name: app.name.clone(),155 name: app.name.clone(),
@@ -138,7 +159,7 @@ fn pick(app: &AudioApp) -> ShareAudio {
138 }159 }
139 }160 }
140 161
141-fn chosen(audio: &ShareAudio, app: &AudioApp) -> bool {162+fn is_chosen(audio: &ShareAudio, app: &AudioApp) -> bool {
142 match audio {163 match audio {
143 ShareAudio::App { name, pid } => {164 ShareAudio::App { name, pid } => {
144 app.kind == AudioKind::App && is_picked((name, *pid), &app.name, app.pid)165 app.kind == AudioKind::App && is_picked((name, *pid), &app.name, app.pid)
@@ -196,10 +217,10 @@ fn pick_tile(
196 name: String,217 name: String,
197 preview: Option<Arc<RenderImage>>,218 preview: Option<Arc<RenderImage>>,
198 entity: &Entity<Yumush>,219 entity: &Entity<Yumush>,
199- palette: Palette,220+ t: Tokens,
200 ) -> impl IntoElement {221 ) -> impl IntoElement {
201 let entity = entity.clone();222 let entity = entity.clone();
202- clickable(("share_target", index), palette, move |window, cx| {223+ clickable(("share_target", index), t, move |window, cx| {
203 window.close_dialog(cx);224 window.close_dialog(cx);
204 entity.update(cx, |yumush, cx| yumush.share_to(Some(target), window, cx));225 entity.update(cx, |yumush, cx| yumush.share_to(Some(target), window, cx));
205 })226 })
@@ -215,7 +236,7 @@ fn pick_tile(
215 .h(px(size::THUMB))236 .h(px(size::THUMB))
216 .rounded(px(radius::SM))237 .rounded(px(radius::SM))
217 .overflow_hidden()238 .overflow_hidden()
218- .bg(palette.field)239+ .bg(t.raise())
219 .children(preview.map(|image| img(image).size_full().object_fit(ObjectFit::Contain))),240 .children(preview.map(|image| img(image).size_full().object_fit(ObjectFit::Contain))),
220 )241 )
221 .child(div().truncate().text_size(px(text::LABEL)).child(name))242 .child(div().truncate().text_size(px(text::LABEL)).child(name))
@@ -230,7 +251,7 @@ impl Yumush {
230 return;251 return;
231 };252 };
232 let _ = this.update(cx, |yumush, cx| {253 let _ = this.update(cx, |yumush, cx| {
233- yumush.chat.shares.insert(community_id, shares);254+ yumush.chat.session.shares.insert(community_id, shares);
234 cx.notify();255 cx.notify();
235 });256 });
236 })257 })
@@ -241,7 +262,7 @@ impl Yumush {
241 if self.share_busy {262 if self.share_busy {
242 return;263 return;
243 }264 }
244- if self.network.sharing() || !crate::share::capture::PICKS {265+ if self.network.share_source(Kind::Screen).is_some() || !crate::share::capture::PICKS {
245 self.share_to(None, window, cx);266 self.share_to(None, window, cx);
246 return;267 return;
247 }268 }
@@ -250,7 +271,7 @@ impl Yumush {
250 271
251 fn pick_share(&mut self, window: &mut Window, cx: &mut Context<Self>) {272 fn pick_share(&mut self, window: &mut Window, cx: &mut Context<Self>) {
252 let entity = cx.entity();273 let entity = cx.entity();
253- let palette = super::palette(cx);274+ let t = Tokens::of(cx);
254 let picker: Entity<Picker> = cx.new(|_| Picker::default());275 let picker: Entity<Picker> = cx.new(|_| Picker::default());
255 let weak = picker.downgrade();276 let weak = picker.downgrade();
256 window.open_dialog(cx, move |dialog, _, cx| {277 window.open_dialog(cx, move |dialog, _, cx| {
@@ -268,7 +289,7 @@ impl Yumush {
268 let (target, name) = &picker.sources[index];289 let (target, name) = &picker.sources[index];
269 let preview =290 let preview =
270 picker.previews.get(target).map(|(_, image)| image.clone());291 picker.previews.get(target).map(|(_, image)| image.clone());
271- pick_tile(index, *target, name.clone(), preview, &entity, palette)292+ pick_tile(index, *target, name.clone(), preview, &entity, t)
272 });293 });
273 let fillers = (end..start + PICK_COLUMNS).map(|_| div().flex_1());294 let fillers = (end..start + PICK_COLUMNS).map(|_| div().flex_1());
274 div()295 div()
@@ -305,7 +326,7 @@ impl Yumush {
305 ages.get(&target)326 ages.get(&target)
306 .is_none_or(|taken| taken.elapsed() >= PREVIEW_AGE)327 .is_none_or(|taken| taken.elapsed() >= PREVIEW_AGE)
307 };328 };
308- crate::share::capture::targets(&stale).unwrap_or_default()329+ crate::share::capture::targets(&stale)
309 })330 })
310 .await;331 .await;
311 let Some(picker) = weak.upgrade() else {332 let Some(picker) = weak.upgrade() else {
@@ -330,14 +351,14 @@ impl Yumush {
330 351
331 fn share_to(&mut self, target: Option<Target>, window: &mut Window, cx: &mut Context<Self>) {352 fn share_to(&mut self, target: Option<Target>, window: &mut Window, cx: &mut Context<Self>) {
332 let network = self.network.clone();353 let network = self.network.clone();
333- let sharing = network.sharing();354+ let sharing = network.share_source(Kind::Screen).is_some();
334 let settings = self.settings.share.clone();355 let settings = self.settings.share.clone();
335 self.share_busy = true;356 self.share_busy = true;
336 357
337 cx.spawn_in(window, async move |this, cx| {358 cx.spawn_in(window, async move |this, cx| {
338 if sharing {359 if sharing {
339- let _ = network.stop_share().await;360+ let _ = network.stop(Kind::Screen).await;
340- } else if let Err(error) = network.start_share(&settings, target).await {361+ } else if let Err(error) = network.start(Kind::Screen, &settings, target).await {
341 notify_error(&this, cx, error);362 notify_error(&this, cx, error);
342 }363 }
343 let _ = this.update(cx, |yumush, cx| {364 let _ = this.update(cx, |yumush, cx| {
@@ -350,7 +371,7 @@ impl Yumush {
350 371
351 fn toggle_share_mute(&mut self, window: &mut Window, cx: &mut Context<Self>) {372 fn toggle_share_mute(&mut self, window: &mut Window, cx: &mut Context<Self>) {
352 let current = self.settings.share.volume;373 let current = self.settings.share.volume;
353- let Some(viewer) = self.chat.viewer.as_mut() else {374+ let Some(viewer) = self.chat.session.viewer.as_mut() else {
354 return;375 return;
355 };376 };
356 let next = if current > 0. {377 let next = if current > 0. {
@@ -384,13 +405,16 @@ impl Yumush {
384 if self.share_apps_task.is_some() {405 if self.share_apps_task.is_some() {
385 return;406 return;
386 }407 }
387- let network = self.network.clone();
388 self.share_apps_task = Some(cx.spawn(async move |this, cx| {408 self.share_apps_task = Some(cx.spawn(async move |this, cx| {
389 loop {409 loop {
390- let network = network.clone();
391 let (apps, cameras) = cx410 let (apps, cameras) = cx
392 .background_executor()411 .background_executor()
393- .spawn(async move { (network.audio_apps(), crate::share::camera::devices()) })412+ .spawn(async move {
413+ (
414+ crate::share::audio_capture::apps(),
415+ crate::share::camera::devices(),
416+ )
417+ })
394 .await;418 .await;
395 let shown = this419 let shown = this
396 .update(cx, |yumush, cx| {420 .update(cx, |yumush, cx| {
@@ -413,15 +437,11 @@ impl Yumush {
413 let device = self.settings.share.camera_device.clone();437 let device = self.settings.share.camera_device.clone();
414 let fresh = self.network.share_modes(Kind::Camera).is_none();438 let fresh = self.network.share_modes(Kind::Camera).is_none();
415 cx.spawn(async move |this, cx| {439 cx.spawn(async move |this, cx| {
416- let (devices, modes) = cx440+ let modes = cx
417 .background_executor()441 .background_executor()
418- .spawn(async move {442+ .spawn(async move { fresh.then(|| crate::share::camera::list(device.as_deref())) })
419- let modes = fresh.then(|| crate::share::camera::list(device.as_deref()));
420- (crate::share::camera::devices(), modes)
421- })
422 .await;443 .await;
423 let _ = this.update(cx, |yumush, cx| {444 let _ = this.update(cx, |yumush, cx| {
424- yumush.camera_devices = devices;
425 if let Some(modes) = modes {445 if let Some(modes) = modes {
426 yumush.camera_modes = modes;446 yumush.camera_modes = modes;
427 }447 }
@@ -434,18 +454,48 @@ impl Yumush {
434 pub(super) fn set_camera_device(&mut self, device: String, cx: &mut Context<Self>) {454 pub(super) fn set_camera_device(&mut self, device: String, cx: &mut Context<Self>) {
435 self.update_share(cx, |settings| settings.camera_device = Some(device));455 self.update_share(cx, |settings| settings.camera_device = Some(device));
436 self.refresh_camera_modes(cx);456 self.refresh_camera_modes(cx);
437- if self.network.camera_on() {457+ if !CAMERA_BUSY.load(Ordering::Relaxed) && self.network.share_source(Kind::Camera).is_some()
438- let network = self.network.clone();458+ {
439- let settings = self.settings.share.clone();459+ self.switch_camera(cx);
440- spawn_warn(cx, "camera switch", async move {460+ }
441- network.stop_camera().await?;461+ }
442- network.start_camera(&settings).await462+
443- });463+ fn switch_camera(&mut self, cx: &mut Context<Self>) {
464+ CAMERA_BUSY.store(true, Ordering::Relaxed);
465+ let network = self.network.clone();
466+ let settings = self.settings.share.clone();
467+ let device = settings.camera_device.clone();
468+ cx.spawn(async move |this, cx| {
469+ let switched = async {
470+ network.stop(Kind::Camera).await?;
471+ network.start(Kind::Camera, &settings, None).await
472+ }
473+ .await;
474+ if let Err(error) = switched {
475+ tracing::warn!("camera switch failed: {error}");
476+ }
477+ let _ = this.update(cx, |yumush, cx| yumush.settle_camera(device, cx));
478+ })
479+ .detach();
480+ }
481+
482+ pub(super) fn settle_camera(&mut self, device: Option<String>, cx: &mut Context<Self>) {
483+ CAMERA_BUSY.store(false, Ordering::Relaxed);
484+ if self.network.share_source(Kind::Camera).is_some()
485+ && self.settings.share.camera_device != device
486+ {
487+ self.switch_camera(cx);
488+ } else {
489+ cx.notify();
444 }490 }
445 }491 }
446 492
447- pub(super) fn set_share_resolution(&mut self, resolution: Resolution, cx: &mut Context<Self>) {493+ pub(super) fn set_share_resolution(
448- let kind = self.share_tab;494+ &mut self,
495+ kind: Kind,
496+ resolution: Resolution,
497+ cx: &mut Context<Self>,
498+ ) {
449 self.update_share(cx, |settings| match kind {499 self.update_share(cx, |settings| match kind {
450 Kind::Screen => settings.top.resolution = resolution,500 Kind::Screen => settings.top.resolution = resolution,
451 Kind::Camera => settings.camera.resolution = resolution,501 Kind::Camera => settings.camera.resolution = resolution,
@@ -456,8 +506,7 @@ impl Yumush {
456 self.update_share(cx, |settings| settings.codec = codec);506 self.update_share(cx, |settings| settings.codec = codec);
457 }507 }
458 508
459- pub(super) fn set_share_fps(&mut self, fps: Fps, cx: &mut Context<Self>) {509+ pub(super) fn set_share_fps(&mut self, kind: Kind, fps: Fps, cx: &mut Context<Self>) {
460- let kind = self.share_tab;
461 self.update_share(cx, |settings| match kind {510 self.update_share(cx, |settings| match kind {
462 Kind::Screen => settings.top.fps = fps,511 Kind::Screen => settings.top.fps = fps,
463 Kind::Camera => settings.camera.fps = fps,512 Kind::Camera => settings.camera.fps = fps,
@@ -469,14 +518,14 @@ impl Yumush {
469 let audio = match (mode, self.share_apps.first()) {518 let audio = match (mode, self.share_apps.first()) {
470 (AudioMode::Off, _) => ShareAudio::Off,519 (AudioMode::Off, _) => ShareAudio::Off,
471 (AudioMode::Everything, _) => ShareAudio::Everything,520 (AudioMode::Everything, _) => ShareAudio::Everything,
472- (AudioMode::App, Some(app)) => pick(app),521+ (AudioMode::App, Some(app)) => audio_choice(app),
473 (AudioMode::App, None) => return,522 (AudioMode::App, None) => return,
474 };523 };
475 self.update_share(cx, |settings| settings.audio = audio);524 self.update_share(cx, |settings| settings.audio = audio);
476 }525 }
477 526
478 pub(super) fn set_share_source(&mut self, app: &AudioApp, cx: &mut Context<Self>) {527 pub(super) fn set_share_source(&mut self, app: &AudioApp, cx: &mut Context<Self>) {
479- let audio = pick(app);528+ let audio = audio_choice(app);
480 self.update_share(cx, |settings| settings.audio = audio);529 self.update_share(cx, |settings| settings.audio = audio);
481 }530 }
482 531
@@ -522,6 +571,7 @@ impl Yumush {
522 571
523 pub(super) fn is_watching(&self, user_id: Id, kind: Kind) -> bool {572 pub(super) fn is_watching(&self, user_id: Id, kind: Kind) -> bool {
524 self.chat573 self.chat
574+ .session
525 .viewer575 .viewer
526 .as_ref()576 .as_ref()
527 .is_some_and(|viewer| viewer.user_id == user_id && viewer.kind == kind)577 .is_some_and(|viewer| viewer.user_id == user_id && viewer.kind == kind)
@@ -529,6 +579,7 @@ impl Yumush {
529 579
530 pub(super) fn viewing(&self) -> Option<(Id, Kind)> {580 pub(super) fn viewing(&self) -> Option<(Id, Kind)> {
531 self.chat581 self.chat
582+ .session
532 .viewer583 .viewer
533 .as_ref()584 .as_ref()
534 .map(|viewer| (viewer.user_id, viewer.kind))585 .map(|viewer| (viewer.user_id, viewer.kind))
@@ -561,7 +612,7 @@ impl Yumush {
561 }612 }
562 })];613 })];
563 614
564- self.chat.viewer = Some(Viewer {615+ self.chat.session.viewer = Some(Viewer {
565 user_id,616 user_id,
566 kind,617 kind,
567 shown: false,618 shown: false,
@@ -580,7 +631,7 @@ impl Yumush {
580 let volume = self.settings.share.volume;631 let volume = self.settings.share.volume;
581 let choice = self.settings.voice.choice.clone();632 let choice = self.settings.voice.choice.clone();
582 let top = self.share_top(user_id, kind);633 let top = self.share_top(user_id, kind);
583- if self.chat.tiles.contains_key(&(user_id, kind)) {634+ if self.chat.session.tiles.contains_key(&(user_id, kind)) {
584 network.set_watch_quality(user_id, kind, watch);635 network.set_watch_quality(user_id, kind, watch);
585 } else {636 } else {
586 cx.spawn_in(window, async move |this, cx| {637 cx.spawn_in(window, async move |this, cx| {
@@ -602,7 +653,7 @@ impl Yumush {
602 }653 }
603 654
604 pub(super) fn close_viewer(&mut self, cx: &mut Context<Self>) {655 pub(super) fn close_viewer(&mut self, cx: &mut Context<Self>) {
605- let Some(viewer) = self.chat.viewer.take() else {656+ let Some(viewer) = self.chat.session.viewer.take() else {
606 return;657 return;
607 };658 };
608 let surface = viewer.surface.clone();659 let surface = viewer.surface.clone();
@@ -611,26 +662,18 @@ impl Yumush {
611 cx.drop_image(frame, None);662 cx.drop_image(frame, None);
612 }663 }
613 });664 });
614- let network = self.network.clone();665+ let source = (viewer.user_id, viewer.kind);
615- if self.chat.tiles.contains_key(&(viewer.user_id, viewer.kind)) {666+ if self.chat.session.tiles.contains_key(&source) {
616- network.set_watch_quality(667+ self.network
617- viewer.user_id,668+ .set_watch_quality(source.0, source.1, self.chat.stage.quality());
618- viewer.kind,
619- camera_view::tile_quality(self.chat.stage),
620- );
621 } else {669 } else {
622- let user_id = viewer.user_id;670+ self.unwatch_tile(source, cx);
623- let kind = viewer.kind;
624- cx.spawn(async move |_, _| {
625- let _ = network.unwatch_share(user_id, kind).await;
626- })
627- .detach();
628 }671 }
629 cx.notify();672 cx.notify();
630 }673 }
631 674
632 pub(super) fn tick_viewer(&mut self, mut window: Option<&mut Window>, cx: &mut Context<Self>) {675 pub(super) fn tick_viewer(&mut self, mut window: Option<&mut Window>, cx: &mut Context<Self>) {
633- let Some(viewer) = self.chat.viewer.as_mut() else {676+ let Some(viewer) = self.chat.session.viewer.as_mut() else {
634 return;677 return;
635 };678 };
636 let Some(frame) = self.network.share_frame(viewer.user_id, viewer.kind) else {679 let Some(frame) = self.network.share_frame(viewer.user_id, viewer.kind) else {
@@ -642,7 +685,12 @@ impl Yumush {
642 let previous = viewer685 let previous = viewer
643 .surface686 .surface
644 .update(cx, |surface, cx| surface.replace(next.clone(), cx));687 .update(cx, |surface, cx| surface.replace(next.clone(), cx));
645- if let Some(tile) = self.chat.tiles.get_mut(&(viewer.user_id, viewer.kind)) {688+ if let Some(tile) = self
689+ .chat
690+ .session
691+ .tiles
692+ .get_mut(&(viewer.user_id, viewer.kind))
693+ {
646 tile.shown |= next.is_some();694 tile.shown |= next.is_some();
647 if let Some(old) = tile695 if let Some(old) = tile
648 .surface696 .surface
@@ -663,7 +711,7 @@ impl Yumush {
663 }711 }
664 712
665 pub(super) fn toggle_fullscreen(&mut self, cx: &mut Context<Self>) {713 pub(super) fn toggle_fullscreen(&mut self, cx: &mut Context<Self>) {
666- if let Some(viewer) = self.chat.viewer.as_mut() {714+ if let Some(viewer) = self.chat.session.viewer.as_mut() {
667 viewer.fullscreen = !viewer.fullscreen;715 viewer.fullscreen = !viewer.fullscreen;
668 }716 }
669 cx.notify();717 cx.notify();
@@ -672,7 +720,7 @@ impl Yumush {
672 pub(super) fn share_settings_button(720 pub(super) fn share_settings_button(
673 &self,721 &self,
674 entity: &Entity<Self>,722 entity: &Entity<Self>,
675- palette: Palette,723+ t: Tokens,
676 kind: Kind,724 kind: Kind,
677 cx: &App,725 cx: &App,
678 ) -> impl IntoElement {726 ) -> impl IntoElement {
@@ -711,36 +759,49 @@ impl Yumush {
711 ))759 ))
712 .content(move |_, _, cx| {760 .content(move |_, _, cx| {
713 let entity = settings.clone();761 let entity = settings.clone();
714- settings_card(&entity, entity.read(cx), palette)762+ settings_card(&entity, entity.read(cx), t)
715 })763 })
716 }764 }
717 765
718- pub(super) fn inline_viewer(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {766+ pub(super) fn inline_viewer(&self, entity: &Entity<Self>, t: Tokens) -> Option<Div> {
719 let viewer = self767 let viewer = self
720 .chat768 .chat
769+ .session
721 .viewer770 .viewer
722 .as_ref()771 .as_ref()
723 .filter(|viewer| !viewer.fullscreen)772 .filter(|viewer| !viewer.fullscreen)
724- .filter(|_| self.chat.selected_community_id == self.chat.voice_community())?;773+ .filter(|_| self.chat.session.selected_community_id == self.chat.voice_community())?;
725- Some(self.viewer_pane(viewer, entity, palette))774+ Some(self.viewer_pane(viewer, entity, t))
726 }775 }
727 776
728 fn drag_float(&mut self, position: gpui_kit::Point<gpui_kit::Pixels>, window: &Window) -> bool {777 fn drag_float(&mut self, position: gpui_kit::Point<gpui_kit::Pixels>, window: &Window) -> bool {
729- let Some((start, from)) = self.chat.float.grab else {778+ let Some((start, from)) = self.chat.session.float.drag.grab() else {
730 return false;779 return false;
731 };780 };
732 let viewport = window.viewport_size();781 let viewport = window.viewport_size();
733 let (width, height) = (f32::from(viewport.width), f32::from(viewport.height));782 let (width, height) = (f32::from(viewport.width), f32::from(viewport.height));
734 let x = (from.0 + f32::from(position.x - start.x))783 let x = (from.0 + f32::from(position.x - start.x))
735- .clamp(FLOAT_RIGHT - (width - FLOAT_WIDTH), FLOAT_RIGHT);784+ .max(FLOAT_RIGHT - (width - FLOAT_WIDTH))
785+ .min(FLOAT_RIGHT);
736 let y = (from.1 + f32::from(position.y - start.y))786 let y = (from.1 + f32::from(position.y - start.y))
737- .clamp(FLOAT_BOTTOM - (height - FLOAT_HEIGHT), FLOAT_BOTTOM);787+ .max(FLOAT_BOTTOM - (height - FLOAT_HEIGHT))
788+ .min(FLOAT_BOTTOM);
738 let moved = (x - from.0).abs() + (y - from.1).abs() > DRAG_SLOP;789 let moved = (x - from.0).abs() + (y - from.1).abs() > DRAG_SLOP;
739- self.chat.float.moved |= moved;790+ let float = &mut self.chat.session.float;
740- self.chat.float.shift = (x, y);791+ float.shift = (x, y);
792+ if moved {
793+ float.drag = Drag::Dragging { start, from };
794+ }
741 true795 true
742 }796 }
743 797
798+ fn release_float(&mut self) {
799+ let float = &mut self.chat.session.float;
800+ if let Drag::Pressed { .. } = float.drag {
801+ float.drag = Drag::Idle;
802+ }
803+ }
804+
744 pub(super) fn float_moved(805 pub(super) fn float_moved(
745 &mut self,806 &mut self,
746 event: &gpui_kit::MouseMoveEvent,807 event: &gpui_kit::MouseMoveEvent,
@@ -748,7 +809,7 @@ impl Yumush {
748 cx: &mut Context<Self>,809 cx: &mut Context<Self>,
749 ) {810 ) {
750 if event.pressed_button != Some(MouseButton::Left) {811 if event.pressed_button != Some(MouseButton::Left) {
751- self.chat.float.grab = None;812+ self.release_float();
752 return;813 return;
753 }814 }
754 if self.drag_float(event.position, window) {815 if self.drag_float(event.position, window) {
@@ -756,17 +817,20 @@ impl Yumush {
756 }817 }
757 }818 }
758 819
759- pub(super) fn floating_viewer(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {820+ pub(super) fn floating_viewer(&self, entity: &Entity<Self>, t: Tokens) -> Option<Div> {
760 let viewer = self821 let viewer = self
761 .chat822 .chat
823+ .session
762 .viewer824 .viewer
763 .as_ref()825 .as_ref()
764 .filter(|viewer| !viewer.fullscreen)?;826 .filter(|viewer| !viewer.fullscreen)?;
765 let community = self.chat.voice_community()?;827 let community = self.chat.voice_community()?;
766- if self.chat.view == View::Chat && self.chat.selected_community_id == Some(community) {828+ if self.chat.session.view == View::Chat
829+ && self.chat.session.selected_community_id == Some(community)
830+ {
767 return None;831 return None;
768 }832 }
769- let (dx, dy) = self.chat.float.shift;833+ let (dx, dy) = self.chat.session.float.shift;
770 let (grab, drag, release) = (entity.clone(), entity.clone(), entity.clone());834 let (grab, drag, release) = (entity.clone(), entity.clone(), entity.clone());
771 let entity = entity.clone();835 let entity = entity.clone();
772 Some(836 Some(
@@ -787,20 +851,23 @@ impl Yumush {
787 .cursor_pointer()851 .cursor_pointer()
788 .on_mouse_down(MouseButton::Left, move |event, _, cx| {852 .on_mouse_down(MouseButton::Left, move |event, _, cx| {
789 grab.update(cx, |yumush, _| {853 grab.update(cx, |yumush, _| {
790- let float = &mut yumush.chat.float;854+ let float = &mut yumush.chat.session.float;
791- float.grab = Some((event.position, float.shift));855+ float.drag = Drag::Pressed {
792- float.moved = false;856+ start: event.position,
857+ from: float.shift,
858+ };
793 })859 })
794 })860 })
795 .on_mouse_move(move |event, window, cx| {861 .on_mouse_move(move |event, window, cx| {
796 drag.update(cx, |yumush, cx| yumush.float_moved(event, window, cx))862 drag.update(cx, |yumush, cx| yumush.float_moved(event, window, cx))
797 })863 })
798 .on_mouse_up(MouseButton::Left, move |_, _, cx| {864 .on_mouse_up(MouseButton::Left, move |_, _, cx| {
799- release.update(cx, |yumush, _| yumush.chat.float.grab = None)865+ release.update(cx, |yumush, _| yumush.release_float())
800 })866 })
801 .on_click(move |_, window, cx| {867 .on_click(move |_, window, cx| {
802 entity.update(cx, |yumush, cx| {868 entity.update(cx, |yumush, cx| {
803- if std::mem::take(&mut yumush.chat.float.moved) {869+ let dragged = std::mem::take(&mut yumush.chat.session.float.drag);
870+ if matches!(dragged, Drag::Dragging { .. }) {
804 return;871 return;
805 }872 }
806 yumush.select_community(community, window, cx);873 yumush.select_community(community, window, cx);
@@ -809,7 +876,7 @@ impl Yumush {
809 .when(viewer.shown, |video| video.child(viewer.surface.clone())),876 .when(viewer.shown, |video| video.child(viewer.surface.clone())),
810 )877 )
811 .child(878 .child(
812- camera_view::tile_label(self, palette, (viewer.user_id, viewer.kind))879+ camera_view::tile_label(self, t, (viewer.user_id, viewer.kind))
813 .absolute()880 .absolute()
814 .left(px(space::SM))881 .left(px(space::SM))
815 .top(px(space::SM)),882 .top(px(space::SM)),
@@ -818,7 +885,7 @@ impl Yumush {
818 }885 }
819 886
820 pub(super) fn hide_idle_cursor(&mut self, window: &mut Window, cx: &mut App) {887 pub(super) fn hide_idle_cursor(&mut self, window: &mut Window, cx: &mut App) {
821- let Some(viewer) = self.chat.viewer.as_mut().filter(|viewer| {888+ let Some(viewer) = self.chat.session.viewer.as_mut().filter(|viewer| {
822 viewer.fullscreen && !viewer.cursor_hidden && viewer.active.elapsed() >= BAR_TTL889 viewer.fullscreen && !viewer.cursor_hidden && viewer.active.elapsed() >= BAR_TTL
823 }) else {890 }) else {
824 return;891 return;
@@ -840,12 +907,13 @@ impl Yumush {
840 });907 });
841 }908 }
842 909
843- pub(super) fn fullscreen_viewer(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {910+ pub(super) fn fullscreen_viewer(&self, entity: &Entity<Self>, t: Tokens) -> Option<Div> {
844 let viewer = self911 let viewer = self
845 .chat912 .chat
913+ .session
846 .viewer914 .viewer
847 .as_ref()915 .as_ref()
848- .filter(|viewer| viewer.fullscreen && self.chat.view == View::Chat)?;916+ .filter(|viewer| viewer.fullscreen && self.chat.session.view == View::Chat)?;
849 let bar = viewer.active.elapsed() < BAR_TTL;917 let bar = viewer.active.elapsed() < BAR_TTL;
850 Some(918 Some(
851 div()919 div()
@@ -853,7 +921,7 @@ impl Yumush {
853 .inset_0()921 .inset_0()
854 .flex()922 .flex()
855 .bg(gpui_kit::black())923 .bg(gpui_kit::black())
856- .child(self.viewer_pane(viewer, entity, palette))924+ .child(self.viewer_pane(viewer, entity, t))
857 .when(bar, |this| {925 .when(bar, |this| {
858 this.child(926 this.child(
859 div()927 div()
@@ -861,7 +929,7 @@ impl Yumush {
861 .left_0()929 .left_0()
862 .right_0()930 .right_0()
863 .bottom(px(size::CONTROL + space::LG))931 .bottom(px(size::CONTROL + space::LG))
864- .child(self.voice_band(palette).bg(palette.tokens.ground())),932+ .child(self.voice_band(t).bg(t.ground())),
865 )933 )
866 .child(934 .child(
867 div()935 div()
@@ -871,25 +939,24 @@ impl Yumush {
871 .right_0()939 .right_0()
872 .flex()940 .flex()
873 .justify_center()941 .justify_center()
874- .child(scrim(palette.tokens).child(parts::words(942+ .child(scrim(t).child(parts::words(
875 w().share_view.esc_exit,943 w().share_view.esc_exit,
876 parts::Text::Label,944 parts::Text::Label,
877 parts::Ink::Dim,945 parts::Ink::Dim,
878- palette.tokens,946+ t,
879 ))),947 ))),
880 )948 )
881 }),949 }),
882 )950 )
883 }951 }
884 952
885- fn viewer_pane(&self, viewer: &Viewer, entity: &Entity<Self>, palette: Palette) -> Div {953+ fn viewer_pane(&self, viewer: &Viewer, entity: &Entity<Self>, t: Tokens) -> Div {
886 let (fullscreen_icon, fullscreen_tip) = if viewer.fullscreen {954 let (fullscreen_icon, fullscreen_tip) = if viewer.fullscreen {
887 (IconName::Minimize, w().share_view.exit_fullscreen)955 (IconName::Minimize, w().share_view.exit_fullscreen)
888 } else {956 } else {
889 (IconName::Maximize, w().share_view.fullscreen)957 (IconName::Maximize, w().share_view.fullscreen)
890 };958 };
891 let audio = viewer.kind == Kind::Screen;959 let audio = viewer.kind == Kind::Screen;
892- let t = palette.tokens;
893 let (user_id, kind) = (viewer.user_id, viewer.kind);960 let (user_id, kind) = (viewer.user_id, viewer.kind);
894 let stats = watch_stats(self, user_id, kind);961 let stats = watch_stats(self, user_id, kind);
895 let bar = viewer.active.elapsed() < BAR_TTL;962 let bar = viewer.active.elapsed() < BAR_TTL;
@@ -899,12 +966,12 @@ impl Yumush {
899 .min_h_0()966 .min_h_0()
900 .relative()967 .relative()
901 .occlude()968 .occlude()
902- .when(!viewer.fullscreen, |this| this.bg(palette.window))969+ .when(!viewer.fullscreen, |this| this.bg(t.ground()))
903 .on_mouse_move({970 .on_mouse_move({
904 let entity = entity.clone();971 let entity = entity.clone();
905 move |_, _, cx| {972 move |_, _, cx| {
906 entity.update(cx, |yumush, cx| {973 entity.update(cx, |yumush, cx| {
907- if let Some(viewer) = yumush.chat.viewer.as_mut() {974+ if let Some(viewer) = yumush.chat.session.viewer.as_mut() {
908 let hidden = viewer.active.elapsed() >= BAR_TTL;975 let hidden = viewer.active.elapsed() >= BAR_TTL;
909 viewer.active = Instant::now();976 viewer.active = Instant::now();
910 viewer.cursor_hidden = false;977 viewer.cursor_hidden = false;
@@ -928,7 +995,7 @@ impl Yumush {
928 .when(viewer.shown, |video| video.child(viewer.surface.clone())),995 .when(viewer.shown, |video| video.child(viewer.surface.clone())),
929 )996 )
930 .child(997 .child(
931- camera_view::tile_label(self, palette, (viewer.user_id, viewer.kind))998+ camera_view::tile_label(self, t, (viewer.user_id, viewer.kind))
932 .absolute()999 .absolute()
933 .left(px(space::MD))1000 .left(px(space::MD))
934 .top(px(space::MD))1001 .top(px(space::MD))
@@ -945,7 +1012,7 @@ impl Yumush {
945 t,1012 t,
946 move |_, cx| {1013 move |_, cx| {
947 entity.update(cx, |yumush, cx| {1014 entity.update(cx, |yumush, cx| {
948- if let Some(viewer) = yumush.chat.viewer.as_mut() {1015+ if let Some(viewer) = yumush.chat.session.viewer.as_mut() {
949 viewer.stats = !viewer.stats;1016 viewer.stats = !viewer.stats;
950 }1017 }
951 cx.notify();1018 cx.notify();
@@ -965,7 +1032,7 @@ impl Yumush {
965 .absolute()1032 .absolute()
966 .right(px(space::MD))1033 .right(px(space::MD))
967 .top(px(space::XXL))1034 .top(px(space::XXL))
968- .child(stream_card(self, user_id, kind, palette)),1035+ .child(stream_card(self, user_id, kind, t)),
969 )1036 )
970 })1037 })
971 .child(1038 .child(
@@ -999,7 +1066,7 @@ impl Yumush {
999 },1066 },
1000 Tone::Idle,1067 Tone::Idle,
1001 Scale::Small,1068 Scale::Small,
1002- palette.tokens,1069+ t,
1003 entity_action(entity, |yumush, window, cx| {1070 entity_action(entity, |yumush, window, cx| {
1004 yumush.toggle_share_mute(window, cx)1071 yumush.toggle_share_mute(window, cx)
1005 }),1072 }),
@@ -1016,7 +1083,7 @@ impl Yumush {
1016 fullscreen_tip,1083 fullscreen_tip,
1017 Tone::Idle,1084 Tone::Idle,
1018 Scale::Small,1085 Scale::Small,
1019- palette.tokens,1086+ t,
1020 entity_action(entity, |yumush, _, cx| yumush.toggle_fullscreen(cx)),1087 entity_action(entity, |yumush, _, cx| yumush.toggle_fullscreen(cx)),
1021 ))1088 ))
1022 .child(icon_button(1089 .child(icon_button(
@@ -1025,7 +1092,7 @@ impl Yumush {
1025 w().share_view.close,1092 w().share_view.close,
1026 Tone::Idle,1093 Tone::Idle,
1027 Scale::Small,1094 Scale::Small,
1028- palette.tokens,1095+ t,
1029 entity_action(entity, |yumush, _, cx| yumush.close_viewer(cx)),1096 entity_action(entity, |yumush, _, cx| yumush.close_viewer(cx)),
1030 )),1097 )),
1031 ),1098 ),
@@ -1033,30 +1100,29 @@ impl Yumush {
1033 }1100 }
1034 }1101 }
1035 1102
1036-fn settings_card(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> Div {1103+fn settings_card(entity: &Entity<Yumush>, yumush: &Yumush, t: Tokens) -> Div {
1037 let settings = &yumush.settings.share;1104 let settings = &yumush.settings.share;
1038- let t = palette.tokens;
1039 let card = super::parts::quick(t).min_w(px(size::POPOVER));1105 let card = super::parts::quick(t).min_w(px(size::POPOVER));
1040 let card = match yumush.share_tab {1106 let card = match yumush.share_tab {
1041- Kind::Camera => card.child(camera_devices(entity, yumush, palette)),1107+ Kind::Camera => card.child(camera_devices(entity, yumush, t)),
1042 Kind::Screen => card1108 Kind::Screen => card
1043 .child(div().px(px(space::SM)).child(segmented(1109 .child(div().px(px(space::SM)).child(segmented(
1044 AudioMode::all(),1110 AudioMode::all(),
1045 AudioMode::of(&settings.audio),1111 AudioMode::of(&settings.audio),
1046 entity,1112 entity,
1047- palette,1113+ t,
1048 Yumush::set_share_audio_mode,1114 Yumush::set_share_audio_mode,
1049 )))1115 )))
1050- .children(audio_list(entity, yumush, palette)),1116+ .children(audio_list(entity, yumush, t)),
1051 };1117 };
1052 card.child(super::parts::thread(t))1118 card.child(super::parts::thread(t))
1053- .child(quality_toggle(entity, yumush, palette))1119+ .child(quality_toggle(entity, yumush, t))
1054 .when(yumush.share_more, |card| {1120 .when(yumush.share_more, |card| {
1055- card.children(quality_rows(entity, yumush, palette))1121+ card.children(quality_rows(entity, yumush, t))
1056 })1122 })
1057 }1123 }
1058 1124
1059-fn camera_devices(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> Div {1125+fn camera_devices(entity: &Entity<Yumush>, yumush: &Yumush, t: Tokens) -> Div {
1060 let chosen = yumush1126 let chosen = yumush
1061 .settings1127 .settings
1062 .share1128 .share
@@ -1067,7 +1133,7 @@ fn camera_devices(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) ->
1067 if yumush.camera_devices.is_empty() {1133 if yumush.camera_devices.is_empty() {
1068 return div()1134 return div()
1069 .px(px(space::SM))1135 .px(px(space::SM))
1070- .text_color(palette.muted)1136+ .text_color(t.dim())
1071 .child(w().share_view.no_camera);1137 .child(w().share_view.no_camera);
1072 }1138 }
1073 div().flex().flex_col().gap(px(space::XXS)).children(1139 div().flex().flex_col().gap(px(space::XXS)).children(
@@ -1078,14 +1144,10 @@ fn camera_devices(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) ->
1078 .map(|(index, name)| {1144 .map(|(index, name)| {
1079 let entity = entity.clone();1145 let entity = entity.clone();
1080 let device = name.clone();1146 let device = name.clone();
1081- row_style(clickable(1147+ row_style(clickable(("camera_device", index), t, move |_, cx| {
1082- ("camera_device", index),1148+ let device = device.clone();
1083- palette,1149+ entity.update(cx, |yumush, cx| yumush.set_camera_device(device, cx));
1084- move |_, cx| {1150+ }))
1085- let device = device.clone();
1086- entity.update(cx, |yumush, cx| yumush.set_camera_device(device, cx));
1087- },
1088- ))
1089 .child(1151 .child(
1090 div()1152 div()
1091 .flex_1()1153 .flex_1()
@@ -1096,7 +1158,7 @@ fn camera_devices(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) ->
1096 .children((chosen.as_ref() == Some(name)).then(|| {1158 .children((chosen.as_ref() == Some(name)).then(|| {
1097 super::parts::small_icon(IconName::Check)1159 super::parts::small_icon(IconName::Check)
1098 .flex_shrink_0()1160 .flex_shrink_0()
1099- .text_color(palette.text)1161+ .text_color(t.paper())
1100 }))1162 }))
1101 }),1163 }),
1102 )1164 )
@@ -1108,15 +1170,19 @@ fn label<T: PartialEq>(list: &[(T, &'static str)], value: T) -> &'static str {
1108 .map_or("", |(_, name)| *name)1170 .map_or("", |(_, name)| *name)
1109 }1171 }
1110 1172
1111-fn quality_toggle(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> impl IntoElement {1173+fn shown_top(yumush: &Yumush, kind: Kind) -> (Vec<Mode>, Quality) {
1112- let open = yumush.share_more;
1113- let kind = yumush.share_tab;
1114 let modes = share_modes(yumush, kind);1174 let modes = share_modes(yumush, kind);
1115 let top = clamp(1175 let top = clamp(
1116 yumush.settings.share.top(kind),1176 yumush.settings.share.top(kind),
1117 &modes,1177 &modes,
1118 capabilities().max_height,1178 capabilities().max_height,
1119 );1179 );
1180+ (modes, top)
1181+}
1182+
1183+fn quality_toggle(entity: &Entity<Yumush>, yumush: &Yumush, t: Tokens) -> impl IntoElement {
1184+ let open = yumush.share_more;
1185+ let (_, top) = shown_top(yumush, yumush.share_tab);
1120 let summary = format!(1186 let summary = format!(
1121 "{} · {} fps · {}",1187 "{} · {} fps · {}",
1122 label(&RESOLUTIONS, top.resolution),1188 label(&RESOLUTIONS, top.resolution),
@@ -1124,13 +1190,13 @@ fn quality_toggle(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) ->
1124 label(&codecs(), yumush.settings.share.codec),1190 label(&codecs(), yumush.settings.share.codec),
1125 );1191 );
1126 let entity = entity.clone();1192 let entity = entity.clone();
1127- row_style(clickable("share_quality", palette, move |_, cx| {1193+ row_style(clickable("share_quality", t, move |_, cx| {
1128 entity.update(cx, |yumush, cx| {1194 entity.update(cx, |yumush, cx| {
1129 yumush.share_more = !yumush.share_more;1195 yumush.share_more = !yumush.share_more;
1130 cx.notify();1196 cx.notify();
1131 })1197 })
1132 }))1198 }))
1133- .text_color(palette.muted)1199+ .text_color(t.dim())
1134 .child(div().flex_1().child(summary))1200 .child(div().flex_1().child(summary))
1135 .child(super::parts::small_icon(if open {1201 .child(super::parts::small_icon(if open {
1136 IconName::ChevronUp1202 IconName::ChevronUp
@@ -1139,14 +1205,25 @@ fn quality_toggle(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) ->
1139 }))1205 }))
1140 }1206 }
1141 1207
1142-fn quality_rows(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> [Div; 3] {1208+fn quality_rows(entity: &Entity<Yumush>, yumush: &Yumush, t: Tokens) -> [Div; 3] {
1143 let settings = &yumush.settings.share;1209 let settings = &yumush.settings.share;
1144 let kind = yumush.share_tab;1210 let kind = yumush.share_tab;
1145- let modes = share_modes(yumush, kind);1211+ let (modes, top) = shown_top(yumush, kind);
1146 let max_height = capabilities().max_height;1212 let max_height = capabilities().max_height;
1147- let top = clamp(settings.top(kind), &modes, max_height);
1148 let (resolutions, fps) = options(&modes, top.resolution, max_height);1213 let (resolutions, fps) = options(&modes, top.resolution, max_height);
1149- let t = palette.tokens;1214+ let (set_resolution, set_fps): (
1215+ fn(&mut Yumush, Resolution, &mut Context<Yumush>),
1216+ fn(&mut Yumush, Fps, &mut Context<Yumush>),
1217+ ) = match kind {
1218+ Kind::Screen => (
1219+ |yumush, resolution, cx| yumush.set_share_resolution(Kind::Screen, resolution, cx),
1220+ |yumush, fps, cx| yumush.set_share_fps(Kind::Screen, fps, cx),
1221+ ),
1222+ Kind::Camera => (
1223+ |yumush, resolution, cx| yumush.set_share_resolution(Kind::Camera, resolution, cx),
1224+ |yumush, fps, cx| yumush.set_share_fps(Kind::Camera, fps, cx),
1225+ ),
1226+ };
1150 [1227 [
1151 super::parts::quick_row(1228 super::parts::quick_row(
1152 w().share_view.resolution,1229 w().share_view.resolution,
@@ -1156,8 +1233,8 @@ fn quality_rows(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> [
1156 .filter(|(resolution, _)| resolutions.contains(resolution)),1233 .filter(|(resolution, _)| resolutions.contains(resolution)),
1157 top.resolution,1234 top.resolution,
1158 entity,1235 entity,
1159- palette,1236+ t,
1160- Yumush::set_share_resolution,1237+ set_resolution,
1161 ),1238 ),
1162 t,1239 t,
1163 ),1240 ),
@@ -1167,8 +1244,8 @@ fn quality_rows(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> [
1167 FPS.into_iter().filter(|(value, _)| fps.contains(value)),1244 FPS.into_iter().filter(|(value, _)| fps.contains(value)),
1168 top.fps,1245 top.fps,
1169 entity,1246 entity,
1170- palette,1247+ t,
1171- Yumush::set_share_fps,1248+ set_fps,
1172 ),1249 ),
1173 t,1250 t,
1174 ),1251 ),
@@ -1181,7 +1258,7 @@ fn quality_rows(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> [
1181 }),1258 }),
1182 settings.codec,1259 settings.codec,
1183 entity,1260 entity,
1184- palette,1261+ t,
1185 Yumush::set_share_codec,1262 Yumush::set_share_codec,
1186 ),1263 ),
1187 t,1264 t,
@@ -1198,7 +1275,7 @@ pub(super) fn share_modes(yumush: &Yumush, kind: Kind) -> Vec<Mode> {
1198 .unwrap_or_else(|| vec![(u32::MAX, u32::MAX)])1275 .unwrap_or_else(|| vec![(u32::MAX, u32::MAX)])
1199 }1276 }
1200 1277
1201-fn audio_list(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> Option<AnyElement> {1278+fn audio_list(entity: &Entity<Yumush>, yumush: &Yumush, t: Tokens) -> Option<AnyElement> {
1202 yumush.share_apps_seen.set(Instant::now());1279 yumush.share_apps_seen.set(Instant::now());
1203 let settings = &yumush.settings.share;1280 let settings = &yumush.settings.share;
1204 1281
@@ -1214,14 +1291,12 @@ fn audio_list(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> Opt
1214 (!apps.is_empty()).then(|| {1291 (!apps.is_empty()).then(|| {
1215 let rows = div().flex().flex_col().gap(px(space::XXS)).children(1292 let rows = div().flex().flex_col().gap(px(space::XXS)).children(
1216 apps.into_iter()1293 apps.into_iter()
1217- .map(|app| include_row(entity, settings, app, palette)),1294+ .map(|app| include_row(entity, settings, app, t)),
1218 );1295 );
1219- field(w().share_view.sound_from, app_list(rows), palette).into_any_element()1296+ field(w().share_view.sound_from, app_list(rows), t).into_any_element()
1220 })1297 })
1221 }1298 }
1222- audio => {1299+ audio => Some(app_list(pick_list(entity, audio, &yumush.share_apps, t)).into_any_element()),
1223- Some(app_list(pick_list(entity, audio, &yumush.share_apps, palette)).into_any_element())
1224- }
1225 }1300 }
1226 }1301 }
1227 1302
@@ -1233,12 +1308,7 @@ fn app_list(rows: impl IntoElement) -> impl IntoElement {
1233 .child(rows)1308 .child(rows)
1234 }1309 }
1235 1310
1236-fn pick_list(1311+fn pick_list(entity: &Entity<Yumush>, audio: &ShareAudio, apps: &[AudioApp], t: Tokens) -> Div {
1237- entity: &Entity<Yumush>,
1238- audio: &ShareAudio,
1239- apps: &[AudioApp],
1240- palette: Palette,
1241-) -> Div {
1242 let groups = [1312 let groups = [
1243 (AudioKind::App, w().share_view.apps),1313 (AudioKind::App, w().share_view.apps),
1244 (AudioKind::Output, w().share_view.outputs),1314 (AudioKind::Output, w().share_view.outputs),
@@ -1253,22 +1323,22 @@ fn pick_list(
1253 let rows: Vec<_> = apps1323 let rows: Vec<_> = apps
1254 .iter()1324 .iter()
1255 .filter(|app| app.kind == kind)1325 .filter(|app| app.kind == kind)
1256- .map(|app| pick_row(entity, chosen(audio, app), app, palette))1326+ .map(|app| pick_row(entity, is_chosen(audio, app), app, t))
1257 .collect();1327 .collect();
1258- (!rows.is_empty()).then(|| group(label, rows, palette))1328+ (!rows.is_empty()).then(|| group(label, rows, t))
1259 }))1329 }))
1260 }1330 }
1261 1331
1262-fn group(label: &'static str, rows: Vec<impl IntoElement>, palette: Palette) -> Div {1332+fn group(label: &'static str, rows: Vec<impl IntoElement>, t: Tokens) -> Div {
1263 div()1333 div()
1264 .flex()1334 .flex()
1265 .flex_col()1335 .flex_col()
1266 .gap(px(space::XXS))1336 .gap(px(space::XXS))
1267- .child(parts::caption_head(label, palette.tokens))1337+ .child(parts::caption_head(label, t))
1268 .children(rows)1338 .children(rows)
1269 }1339 }
1270 1340
1271-fn field(label: &'static str, control: impl IntoElement, palette: Palette) -> Div {1341+fn field(label: &'static str, control: impl IntoElement, t: Tokens) -> Div {
1272 div()1342 div()
1273 .flex()1343 .flex()
1274 .flex_col()1344 .flex_col()
@@ -1276,7 +1346,7 @@ fn field(label: &'static str, control: impl IntoElement, palette: Palette) -> Di
1276 .child(1346 .child(
1277 div()1347 div()
1278 .text_size(text(text::CAPTION))1348 .text_size(text(text::CAPTION))
1279- .text_color(palette.muted)1349+ .text_color(t.dim())
1280 .child(label),1350 .child(label),
1281 )1351 )
1282 .child(control)1352 .child(control)
@@ -1291,7 +1361,7 @@ pub(super) fn row_style<E: Styled>(item: E) -> E {
1291 .rounded(px(radius::MD))1361 .rounded(px(radius::MD))
1292 }1362 }
1293 1363
1294-fn name_cell(app: &AudioApp, palette: Palette) -> Div {1364+fn name_cell(app: &AudioApp, t: Tokens) -> Div {
1295 div()1365 div()
1296 .flex_1()1366 .flex_1()
1297 .min_w_0()1367 .min_w_0()
@@ -1304,7 +1374,7 @@ fn name_cell(app: &AudioApp, palette: Palette) -> Div {
1304 .min_w_0()1374 .min_w_0()
1305 .truncate()1375 .truncate()
1306 .text_size(text(text::CAPTION))1376 .text_size(text(text::CAPTION))
1307- .text_color(palette.muted)1377+ .text_color(t.dim())
1308 .child(app.detail.clone()),1378 .child(app.detail.clone()),
1309 )1379 )
1310 }1380 }
@@ -1313,18 +1383,18 @@ fn include_row(
1313 entity: &Entity<Yumush>,1383 entity: &Entity<Yumush>,
1314 settings: &ShareSettings,1384 settings: &ShareSettings,
1315 app: &AudioApp,1385 app: &AudioApp,
1316- palette: Palette,1386+ t: Tokens,
1317 ) -> impl IntoElement {1387 ) -> impl IntoElement {
1318 let entity = entity.clone();1388 let entity = entity.clone();
1319 let included = !is_excluded(&settings.excluded, &app.name, app.pid);1389 let included = !is_excluded(&settings.excluded, &app.name, app.pid);
1320 let target = app.clone();1390 let target = app.clone();
1321 1391
1322 row_style(div())1392 row_style(div())
1323- .child(name_cell(app, palette))1393+ .child(name_cell(app, t))
1324 .child(div().flex_shrink_0().child(super::parts::toggle(1394 .child(div().flex_shrink_0().child(super::parts::toggle(
1325 gpui_kit::ElementId::Name(format!("share_app_{}", app.key()).into()),1395 gpui_kit::ElementId::Name(format!("share_app_{}", app.key()).into()),
1326 included,1396 included,
1327- palette.tokens,1397+ t,
1328 move |_, cx| {1398 move |_, cx| {
1329 entity.update(cx, |yumush, cx| {1399 entity.update(cx, |yumush, cx| {
1330 yumush.set_share_included(&target, !included, cx)1400 yumush.set_share_included(&target, !included, cx)
@@ -1333,26 +1403,21 @@ fn include_row(
1333 )))1403 )))
1334 }1404 }
1335 1405
1336-fn pick_row(1406+fn pick_row(entity: &Entity<Yumush>, chosen: bool, app: &AudioApp, t: Tokens) -> impl IntoElement {
1337- entity: &Entity<Yumush>,
1338- chosen: bool,
1339- app: &AudioApp,
1340- palette: Palette,
1341-) -> impl IntoElement {
1342 let entity = entity.clone();1407 let entity = entity.clone();
1343 let target = app.clone();1408 let target = app.clone();
1344 1409
1345 row_style(clickable(1410 row_style(clickable(
1346 format!("share_app_{}", app.key()),1411 format!("share_app_{}", app.key()),
1347- palette,1412+ t,
1348 move |_, cx| {1413 move |_, cx| {
1349 entity.update(cx, |yumush, cx| yumush.set_share_source(&target, cx));1414 entity.update(cx, |yumush, cx| yumush.set_share_source(&target, cx));
1350 },1415 },
1351 ))1416 ))
1352- .child(name_cell(app, palette))1417+ .child(name_cell(app, t))
1353 .children(chosen.then(|| {1418 .children(chosen.then(|| {
1354 super::parts::small_icon(IconName::Check)1419 super::parts::small_icon(IconName::Check)
1355 .flex_shrink_0()1420 .flex_shrink_0()
1356- .text_color(palette.text)1421+ .text_color(t.paper())
1357 }))1422 }))
1358 }1423 }
crates/client/src/gui/sidebar.rsmodified+185 -239
@@ -22,15 +22,15 @@ use gpui_kit::{
22 };22 };
23 23
24 use super::{24 use super::{
25- Palette, Tooltip as _, Yumush, avatar,25+ Tooltip as _, Yumush, avatar,
26 chat::{Armed, View, create_community},26 chat::{Armed, View, create_community},
27 clickable, community_icon, community_name, entity_action, hoverable, input_dialog,27 clickable, community_icon, community_name, entity_action, hoverable, input_dialog,
28 parts::{Scale, Tone, icon_button},28 parts::{Scale, Tone, icon_button},
29 presence_avatar,29 presence_avatar,
30 profile::profile_popover,30 profile::profile_popover,
31 social::Relation,31 social::Relation,
32- style::{radius, size, space, text},32+ style::{Tokens, radius, size, space, text},
33- widget::{bare_input, compact_frame},33+ widget::{bare_input, underline},
34 };34 };
35 35
36 const SLIDE: std::time::Duration = std::time::Duration::from_millis(320);36 const SLIDE: std::time::Duration = std::time::Duration::from_millis(320);
@@ -40,11 +40,11 @@ fn slide() -> gpui_kit::Animation {
40 }40 }
41 41
42 impl Yumush {42 impl Yumush {
43- pub(super) fn sidebar(&self, entity: &Entity<Self>, palette: Palette) -> impl IntoElement {43+ pub(super) fn sidebar(&self, entity: &Entity<Self>, t: Tokens) -> impl IntoElement {
44 let content = if self.chat.sidebar_collapsed && !self.sliding() {44 let content = if self.chat.sidebar_collapsed && !self.sliding() {
45- self.collapsed_sidebar(entity, palette).into_any_element()45+ self.collapsed_sidebar(entity, t).into_any_element()
46 } else {46 } else {
47- self.expanded_sidebar(entity, palette)47+ self.expanded_sidebar(entity, t)
48 };48 };
49 49
50 self.folding(50 self.folding(
@@ -88,7 +88,7 @@ impl Yumush {
88 }88 }
89 }89 }
90 90
91- fn collapsed_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> Div {91+ fn collapsed_sidebar(&self, entity: &Entity<Self>, t: Tokens) -> Div {
92 div()92 div()
93 .h_full()93 .h_full()
94 .w(px(size::RAIL))94 .w(px(size::RAIL))
@@ -104,11 +104,7 @@ impl Yumush {
104 .flex_col()104 .flex_col()
105 .items_center()105 .items_center()
106 .gap(px(space::MD))106 .gap(px(space::MD))
107- .child(self.logo_toggle(107+ .child(self.logo_toggle(entity, t, logo_mark(t).size(px(size::CONTROL)))),
108- entity,
109- palette,
110- logo_mark(palette).size(px(size::CONTROL)),
111- )),
112 )108 )
113 .child(109 .child(
114 div()110 div()
@@ -119,14 +115,14 @@ impl Yumush {
119 .children(115 .children(
120 self.user116 self.user
121 .as_ref()117 .as_ref()
122- .map(|user| self.account_trigger(entity, user, false, palette)),118+ .map(|user| self.account_trigger(entity, user, false, t)),
123 ),119 ),
124 )120 )
125 }121 }
126 122
127- fn expanded_sidebar(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement {123+ fn expanded_sidebar(&self, entity: &Entity<Self>, t: Tokens) -> AnyElement {
128- let friends_alert =124+ let friends_alert = !self.chat.session.friends.incoming.is_empty()
129- !self.chat.friends.incoming.is_empty() || !self.chat.invitations.is_empty();125+ || !self.chat.session.invitations.is_empty();
130 126
131 div()127 div()
132 .relative()128 .relative()
@@ -147,10 +143,10 @@ impl Yumush {
147 "logo",143 "logo",
148 div().relative().child(self.logo_toggle(144 div().relative().child(self.logo_toggle(
149 entity,145 entity,
150- palette,146+ t,
151 self.folding(147 self.folding(
152 "logo_mark",148 "logo_mark",
153- logo_mark(palette).when(towing(self.wordmark_flipped), |mark| {149+ logo_mark(t).when(towing(self.wordmark_flipped), |mark| {
154 mark.path(crate::logo::NEEDLE)150 mark.path(crate::logo::NEEDLE)
155 }),151 }),
156 |mark, f| mark.size(px(lerp(size::CHIP, size::CONTROL, f))),152 |mark, f| mark.size(px(lerp(size::CHIP, size::CONTROL, f))),
@@ -172,7 +168,7 @@ impl Yumush {
172 .text_size(text(text::TITLE))168 .text_size(text(text::TITLE))
173 .line_height(gpui_kit::relative(LEADING))169 .line_height(gpui_kit::relative(LEADING))
174 .font_weight(FontWeight::SEMIBOLD)170 .font_weight(FontWeight::SEMIBOLD)
175- .text_color(palette.text)171+ .text_color(t.paper())
176 .cursor_pointer()172 .cursor_pointer()
177 .on_click({173 .on_click({
178 let entity = entity.clone();174 let entity = entity.clone();
@@ -186,7 +182,7 @@ impl Yumush {
186 .child(wordmark_tail(182 .child(wordmark_tail(
187 self.wordmark_flips,183 self.wordmark_flips,
188 self.wordmark_flipped,184 self.wordmark_flipped,
189- palette,185+ t,
190 )),186 )),
191 |word, f| {187 |word, f| {
192 word.relative()188 word.relative()
@@ -197,11 +193,11 @@ impl Yumush {
197 )193 )
198 .child(self.folding(194 .child(self.folding(
199 "friends_fold",195 "friends_fold",
200- div().child(self.friends_button(entity, friends_alert, palette)),196+ div().child(self.friends_button(entity, friends_alert, t)),
201 fade,197 fade,
202 )),198 )),
203 )199 )
204- .children(self.update_control(palette))200+ .children(self.update_control(t))
205 .child(201 .child(
206 self.folding(202 self.folding(
207 "list_fold",203 "list_fold",
@@ -213,18 +209,17 @@ impl Yumush {
213 .flex()209 .flex()
214 .flex_col()210 .flex_col()
215 .gap(px(space::MD))211 .gap(px(space::MD))
216- .children(self.sections(entity, palette)),212+ .children(self.sections(entity, t)),
217 |list, f| fade(list, f).flex_1().min_h_0(),213 |list, f| fade(list, f).flex_1().min_h_0(),
218 ),214 ),
219 )215 )
220- .children(self.build_control(entity, palette))216+ .children(self.build_control(entity, t))
221- .children(self.account_row(entity, palette))217+ .children(self.account_row(entity, t))
222 .into_any_element()218 .into_any_element()
223 }219 }
224 220
225- fn voice_chip(&self, community_id: Id, palette: Palette) -> AnyElement {221+ fn voice_chip(&self, community_id: Id, t: Tokens) -> AnyElement {
226 let ids = self.chat.voice_ids(community_id);222 let ids = self.chat.voice_ids(community_id);
227- let t = palette.tokens;
228 let direct = self.is_direct(community_id);223 let direct = self.is_direct(community_id);
229 let heard: Vec<Id> = ids224 let heard: Vec<Id> = ids
230 .iter()225 .iter()
@@ -233,13 +228,18 @@ impl Yumush {
233 .collect();228 .collect();
234 let mut speakers = heard229 let mut speakers = heard
235 .iter()230 .iter()
236- .filter(|id| self.chat.waves.speaking.contains(id));231+ .filter(|id| self.chat.session.waves.speaking.contains(id));
237 let voice = match (speakers.next(), speakers.next()) {232 let voice = match (speakers.next(), speakers.next()) {
238 (Some(id), None) => super::parts::Voice::Live(t.person(*id)),233 (Some(id), None) => super::parts::Voice::Live(t.person(*id)),
239 (Some(_), Some(_)) => super::parts::Voice::Live(t.paper()),234 (Some(_), Some(_)) => super::parts::Voice::Live(t.paper()),
240 _ => super::parts::Voice::Quiet,235 _ => super::parts::Voice::Quiet,
241 };236 };
242- let total = self.chat.waves.total(&heard);237+ let total = self
238+ .chat
239+ .session
240+ .waves
241+ .total(&heard)
242+ .map(|bars| super::chat::to_bands(&bars));
243 div()243 div()
244 .id(format!("voice_chip_{community_id}"))244 .id(format!("voice_chip_{community_id}"))
245 .tip(w().sidebar.in_call)245 .tip(w().sidebar.in_call)
@@ -258,7 +258,7 @@ impl Yumush {
258 this.child(258 this.child(
259 div()259 div()
260 .text_size(text(text::CAPTION))260 .text_size(text(text::CAPTION))
261- .text_color(palette.muted)261+ .text_color(t.dim())
262 .child(ids.len().to_string()),262 .child(ids.len().to_string()),
263 )263 )
264 })264 })
@@ -281,12 +281,7 @@ impl Yumush {
281 );281 );
282 }282 }
283 283
284- fn logo_toggle(284+ fn logo_toggle(&self, entity: &Entity<Self>, t: Tokens, mark: impl IntoElement) -> AnyElement {
285- &self,
286- entity: &Entity<Self>,
287- palette: Palette,
288- mark: impl IntoElement,
289- ) -> AnyElement {
290 let tip = if self.chat.sidebar_collapsed {285 let tip = if self.chat.sidebar_collapsed {
291 w().sidebar.expand286 w().sidebar.expand
292 } else {287 } else {
@@ -294,7 +289,7 @@ impl Yumush {
294 };289 };
295 clickable(290 clickable(
296 "sidebar_toggle",291 "sidebar_toggle",
297- palette,292+ t,
298 entity_action(entity, |yumush, _, cx| {293 entity_action(entity, |yumush, _, cx| {
299 yumush.toggle_sidebar();294 yumush.toggle_sidebar();
300 cx.notify();295 cx.notify();
@@ -309,7 +304,7 @@ impl Yumush {
309 }304 }
310 305
311 pub(super) fn open_friends(&mut self, window: &mut Window, cx: &mut Context<Self>) {306 pub(super) fn open_friends(&mut self, window: &mut Window, cx: &mut Context<Self>) {
312- self.chat.friends_open = true;307+ self.chat.session.friends_open = true;
313 self.chat308 self.chat
314 .search_input309 .search_input
315 .update(cx, |input, cx| input.focus(window, cx));310 .update(cx, |input, cx| input.focus(window, cx));
@@ -317,30 +312,31 @@ impl Yumush {
317 }312 }
318 313
319 pub(super) fn close_friends(&mut self, window: &mut Window, cx: &mut Context<Self>) {314 pub(super) fn close_friends(&mut self, window: &mut Window, cx: &mut Context<Self>) {
320- self.chat.friends_open = false;315+ self.chat.session.friends_open = false;
321 window.focus(&self.focus, cx);316 window.focus(&self.focus, cx);
322 cx.notify();317 cx.notify();
323 }318 }
324 319
325- fn friends_sheet(&self, entity: &Entity<Self>, cx: &App, palette: Palette) -> Div {320+ fn friends_sheet(&self, entity: &Entity<Self>, cx: &App, t: Tokens) -> Div {
326 let query = super::widget::search_text(&self.chat.search_input, cx);321 let query = super::widget::search_text(&self.chat.search_input, cx);
327- let found = self.chat.found.as_ref().filter(|found| {322+ let found = self.chat.session.found.as_ref().filter(|found| {
328 !self323 !self
329 .chat324 .chat
325+ .session
330 .friends326 .friends
331 .friends327 .friends
332 .iter()328 .iter()
333 .any(|user| user.id == found.id)329 .any(|user| user.id == found.id)
334 });330 });
335- let friends = self.friend_list(entity, &query, palette);331+ let friends = self.friend_list(entity, &query, t);
336- super::parts::popover(palette.tokens)332+ super::parts::popover(t)
337 .w(px(size::POPOVER))333 .w(px(size::POPOVER))
338 .px(px(space::MD))334 .px(px(space::MD))
339 .py(px(space::MD))335 .py(px(space::MD))
340 .gap(px(space::MD))336 .gap(px(space::MD))
341- .child(input_box(&self.chat.search_input, palette))337+ .child(input_box(&self.chat.search_input, t))
342- .children(found.map(|user| self.found_row(entity, user, palette)))338+ .children(found.map(|user| self.found_row(entity, user, t)))
343- .children(self.requests(entity, palette))339+ .children(self.requests(entity, t))
344 .when(!friends.is_empty(), |sheet| {340 .when(!friends.is_empty(), |sheet| {
345 sheet.child(341 sheet.child(
346 div()342 div()
@@ -355,18 +351,13 @@ impl Yumush {
355 })351 })
356 }352 }
357 353
358- fn friends_button(354+ fn friends_button(&self, entity: &Entity<Self>, alert: bool, t: Tokens) -> impl IntoElement {
359- &self,
360- entity: &Entity<Self>,
361- alert: bool,
362- palette: Palette,
363- ) -> impl IntoElement {
364 let opened = entity.clone();355 let opened = entity.clone();
365 let content = entity.clone();356 let content = entity.clone();
366 gpui_kit::component::popover::Popover::new("friends_sheet")357 gpui_kit::component::popover::Popover::new("friends_sheet")
367 .anchor(Anchor::TopLeft)358 .anchor(Anchor::TopLeft)
368 .appearance(false)359 .appearance(false)
369- .open(self.chat.friends_open)360+ .open(self.chat.session.friends_open)
370 .on_open_change(move |open, window, cx| {361 .on_open_change(move |open, window, cx| {
371 let open = *open;362 let open = *open;
372 opened.update(cx, |yumush, cx| {363 opened.update(cx, |yumush, cx| {
@@ -386,7 +377,7 @@ impl Yumush {
386 .items_center()377 .items_center()
387 .justify_center()378 .justify_center()
388 .rounded_full()379 .rounded_full()
389- .text_color(palette.muted)380+ .text_color(t.dim())
390 .child(super::parts::small_icon(IconName::Users))381 .child(super::parts::small_icon(IconName::Users))
391 .children(alert.then(|| {382 .children(alert.then(|| {
392 div()383 div()
@@ -395,23 +386,24 @@ impl Yumush {
395 .right(px(space::XXS))386 .right(px(space::XXS))
396 .size(px(space::XS + space::XXS))387 .size(px(space::XS + space::XXS))
397 .rounded_full()388 .rounded_full()
398- .bg(palette.text)389+ .bg(t.paper())
399 })),390 })),
400- palette,391+ t,
401 )))392 )))
402 .content(move |_, _, cx| {393 .content(move |_, _, cx| {
403 let yumush = content.read(cx);394 let yumush = content.read(cx);
404- yumush.friends_sheet(&content, cx, palette)395+ yumush.friends_sheet(&content, cx, t)
405 })396 })
406 }397 }
407 398
408- fn friend_list(&self, entity: &Entity<Self>, query: &str, palette: Palette) -> Vec<AnyElement> {399+ fn friend_list(&self, entity: &Entity<Self>, query: &str, t: Tokens) -> Vec<AnyElement> {
409 let mut friends: Vec<&User> = self400 let mut friends: Vec<&User> = self
410 .chat401 .chat
402+ .session
411 .friends403 .friends
412 .friends404 .friends
413 .iter()405 .iter()
414- .filter(|user| matches_query(&user.username, query))406+ .filter(|user| user.username.to_lowercase().contains(query))
415 .collect();407 .collect();
416 friends.sort_by_key(|user| (self.doing(user.id), user.username.to_lowercase()));408 friends.sort_by_key(|user| (self.doing(user.id), user.username.to_lowercase()));
417 friends409 friends
@@ -422,8 +414,8 @@ impl Yumush {
422 let remove = entity.clone();414 let remove = entity.clone();
423 let row = hoverable(415 let row = hoverable(
424 format!("friend_{}", user.id),416 format!("friend_{}", user.id),
425- self.user_row(palette, user, None),417+ self.user_row(t, user, None),
426- palette,418+ t,
427 )419 )
428 .on_click(move |_, window, cx| {420 .on_click(move |_, window, cx| {
429 open.update(cx, |yumush, cx| {421 open.update(cx, |yumush, cx| {
@@ -441,12 +433,12 @@ impl Yumush {
441 ("remove_friend", user_id as usize),433 ("remove_friend", user_id as usize),
442 remove434 remove
443 .read(cx)435 .read(cx)
444- .armed_label(armed, w().sidebar.remove_friend),436+ .armed_label(armed.clone(), w().sidebar.remove_friend),
445 super::parts::small_icon(IconName::UserMinus),437 super::parts::small_icon(IconName::UserMinus),
446- palette.danger,438+ t.bad(),
447- palette,439+ t,
448 super::profile::armed_action(440 super::profile::armed_action(
449- armed,441+ armed.clone(),
450 &remove,442 &remove,
451 popover,443 popover,
452 move |yumush, window, cx| yumush.remove_friend(user_id, window, cx),444 move |yumush, window, cx| yumush.remove_friend(user_id, window, cx),
@@ -459,8 +451,8 @@ impl Yumush {
459 .collect()451 .collect()
460 }452 }
461 453
462- fn sections(&self, entity: &Entity<Self>, palette: Palette) -> Vec<AnyElement> {454+ fn sections(&self, entity: &Entity<Self>, t: Tokens) -> Vec<AnyElement> {
463- let pinned = &self.chat.pinned;455+ let pinned = &self.chat.session.pinned;
464 let list = |rows: Vec<AnyElement>| {456 let list = |rows: Vec<AnyElement>| {
465 div()457 div()
466 .flex()458 .flex()
@@ -469,12 +461,12 @@ impl Yumush {
469 .children(rows)461 .children(rows)
470 .into_any_element()462 .into_any_element()
471 };463 };
472- let pins = self.rooms(entity, palette, |room| pinned.contains(&room.id));464+ let pins = self.rooms(entity, t, |room| pinned.contains(&room.id));
473- let groups = self.rooms(entity, palette, |room| {465+ let groups = self.rooms(entity, t, |room| {
474 room.kind.is_group() && !pinned.contains(&room.id)466 room.kind.is_group() && !pinned.contains(&room.id)
475 });467 });
476- let people = std::iter::once(self.notes_row(entity, palette))468+ let people = std::iter::once(self.notes_row(entity, t))
477- .chain(self.rooms(entity, palette, |room| {469+ .chain(self.rooms(entity, t, |room| {
478 room.kind.is_direct() && !pinned.contains(&room.id)470 room.kind.is_direct() && !pinned.contains(&room.id)
479 }))471 }))
480 .collect();472 .collect();
@@ -488,31 +480,30 @@ impl Yumush {
488 .into_iter()480 .into_iter()
489 .enumerate()481 .enumerate()
490 .flat_map(|(index, section)| {482 .flat_map(|(index, section)| {
491- std::iter::once(section).chain((index + 1 < count).then(|| {483+ std::iter::once(section).chain(
492- super::parts::thread(palette.tokens)484+ (index + 1 < count)
493- .mx(px(space::SM))485+ .then(|| super::parts::thread(t).mx(px(space::SM)).into_any_element()),
494- .into_any_element()486+ )
495- }))
496 })487 })
497 .collect()488 .collect()
498 }489 }
499 490
500- fn notes_row(&self, entity: &Entity<Self>, palette: Palette) -> AnyElement {491+ fn notes_row(&self, entity: &Entity<Self>, t: Tokens) -> AnyElement {
501 let notes = self.chat.notes();492 let notes = self.chat.notes();
502 let active = notes.is_some_and(|notes| self.chat.is_selected(notes.id));493 let active = notes.is_some_and(|notes| self.chat.is_selected(notes.id));
503- let unread = notes.and_then(|notes| self.chat.unread.get(&notes.id));494+ let unread = notes.and_then(|notes| self.chat.session.unread.get(&notes.id));
504 let open = entity.clone();495 let open = entity.clone();
505 496
506 hoverable(497 hoverable(
507 "notes",498 "notes",
508 room_row(499 room_row(
509- palette,500+ t,
510 active,501 active,
511- Some(notes_tile(palette)),502+ notes_tile(t),
512 w().sidebar.notes.to_string(),503 w().sidebar.notes.to_string(),
513- unread_badge(palette, false, unread),504+ unread_badge(t, false, unread),
514 ),505 ),
515- palette,506+ t,
516 )507 )
517 .on_click(move |_, window, cx| open.update(cx, |yumush, cx| yumush.open_notes(window, cx)))508 .on_click(move |_, window, cx| open.update(cx, |yumush, cx| yumush.open_notes(window, cx)))
518 .into_any_element()509 .into_any_element()
@@ -521,15 +512,17 @@ impl Yumush {
521 fn rooms(512 fn rooms(
522 &self,513 &self,
523 entity: &Entity<Self>,514 entity: &Entity<Self>,
524- palette: Palette,515+ t: Tokens,
525 keep: impl Fn(&Community) -> bool,516 keep: impl Fn(&Community) -> bool,
526 ) -> Vec<AnyElement> {517 ) -> Vec<AnyElement> {
527 self.unread_first(518 self.unread_first(
528 self.chat519 self.chat
520+ .session
529 .communities521 .communities
530 .iter()522 .iter()
531 .chain(523 .chain(
532 self.chat524 self.chat
525+ .session
533 .opened526 .opened
534 .as_ref()527 .as_ref()
535 .filter(|opened| opened.kind.is_group())528 .filter(|opened| opened.kind.is_group())
@@ -539,84 +532,50 @@ impl Yumush {
539 .filter(|community| keep(community)),532 .filter(|community| keep(community)),
540 )533 )
541 .into_iter()534 .into_iter()
542- .map(|community| self.room_entry(entity, community, palette))535+ .map(|community| self.sidebar_community_row(entity, community, t))
543 .collect()536 .collect()
544 }537 }
545 538
546- fn room_entry(
547- &self,
548- entity: &Entity<Self>,
549- community: &Community,
550- palette: Palette,
551- ) -> AnyElement {
552- self.sidebar_community_row(entity, community, palette)
553- }
554-
555 fn sidebar_community_row(539 fn sidebar_community_row(
556 &self,540 &self,
557 entity: &Entity<Self>,541 entity: &Entity<Self>,
558 community: &Community,542 community: &Community,
559- palette: Palette,543+ t: Tokens,
560 ) -> AnyElement {544 ) -> AnyElement {
561 let active = self.chat.is_selected(community.id);545 let active = self.chat.is_selected(community.id);
562 let group = community.kind.is_group();546 let group = community.kind.is_group();
563 let can_leave = group && (!active || permission::can_leave(self.actor_rank()));547 let can_leave = group && (!active || permission::can_leave(self.actor_rank()));
564- let can_manage = !active || permission::can_manage_community(self.actor_rank());548+ let can_manage = !active || permission::is_moderator(self.actor_rank());
565- let muted = self.chat.muted.contains(&community.id);549+ let muted = self.chat.session.muted.contains(&community.id);
566- let unread = self.chat.unread.get(&community.id);550+ let unread = self.chat.session.unread.get(&community.id);
567 let community_id = community.id;551 let community_id = community.id;
568 let select = entity.clone();552 let select = entity.clone();
569 553
570- let pinned = self.chat.pinned.contains(&community.id);554+ let pinned = self.chat.session.pinned.contains(&community.id);
571 let trailing = if self.chat.voice_ids(community_id).is_empty() {555 let trailing = if self.chat.voice_ids(community_id).is_empty() {
572- unread_badge(palette, muted, unread).or_else(|| {556+ unread_badge(t, muted, unread).or_else(|| {
573 pinned.then(|| {557 pinned.then(|| {
574 super::parts::small_icon(IconName::Pin)558 super::parts::small_icon(IconName::Pin)
575- .text_color(palette.muted)559+ .text_color(t.dim())
576 .into_any_element()560 .into_any_element()
577 })561 })
578 })562 })
579 } else {563 } else {
580- Some(self.voice_chip(community_id, palette))564+ Some(self.voice_chip(community_id, t))
581- };
582- let face = match &community.kind {
583- CommunityKind::Direct { peer } => Some(
584- presence_avatar(
585- avatar(
586- palette,
587- peer,
588- px(size::AVATAR),
589- text(text::CAPTION),
590- &self.chat.avatars,
591- ),
592- self.presence_of(peer.id),
593- px(size::AVATAR),
594- palette,
595- )
596- .into_any_element(),
597- ),
598- CommunityKind::Group => Some(
599- community_icon(
600- palette,
601- community,
602- px(size::AVATAR),
603- text(text::CAPTION),
604- &self.chat.avatars,
605- )
606- .into_any_element(),
607- ),
608- CommunityKind::Notes => Some(notes_tile(palette)),
609 };565 };
566+ let face = self
567+ .community_badge(community, px(size::AVATAR), text(text::CAPTION), t)
568+ .into_any_element();
610 let row = hoverable(569 let row = hoverable(
611 format!("room_{}", community.id),570 format!("room_{}", community.id),
612 room_row(571 room_row(
613- palette,572+ t,
614 active,573 active,
615 face,574 face,
616 community_name(community).to_string(),575 community_name(community).to_string(),
617 trailing,576 trailing,
618 ),577 ),
619- palette,578+ t,
620 )579 )
621 .on_click(move |_, window, cx| {580 .on_click(move |_, window, cx| {
622 select.update(cx, |yumush, cx| {581 select.update(cx, |yumush, cx| {
@@ -638,40 +597,49 @@ impl Yumush {
638 yumush,597 yumush,
639 &menu,598 &menu,
640 popover,599 popover,
641- palette,600+ t,
642 )601 )
643 },602 },
644 )603 )
645 .into_any_element()604 .into_any_element()
646 }605 }
647 606
648- fn requests(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> {607+ fn requests(&self, entity: &Entity<Self>, t: Tokens) -> Option<Div> {
649- let friends = &self.chat.friends;608+ let friends = &self.chat.session.friends;
650 let rows: Vec<AnyElement> = friends609 let rows: Vec<AnyElement> = friends
651 .incoming610 .incoming
652 .iter()611 .iter()
653- .map(|user| self.incoming_row(entity, user, palette))612+ .map(|user| self.incoming_row(entity, user, t))
654 .chain(613 .chain(
655 friends614 friends
656 .outgoing615 .outgoing
657 .iter()616 .iter()
658- .map(|user| self.outgoing_row(entity, user, palette)),617+ .map(|user| self.outgoing_row(entity, user, t)),
659 )618 )
660 .chain(619 .chain(
661 self.chat620 self.chat
621+ .session
662 .invitations622 .invitations
663 .iter()623 .iter()
664- .map(|invitation| self.invitation_row(entity, invitation, palette)),624+ .map(|invitation| self.invitation_row(entity, invitation, t)),
665 )625 )
666 .collect();626 .collect();
667 627
668- group(w().sidebar.requests, palette, rows)628+ (!rows.is_empty()).then(|| {
629+ div()
630+ .flex()
631+ .flex_col()
632+ .gap(px(space::XXS))
633+ .child(super::parts::caption_head(w().sidebar.requests, t))
634+ .children(rows)
635+ })
669 }636 }
670 637
671 fn unread_first<'a>(&self, rooms: impl Iterator<Item = &'a Community>) -> Vec<&'a Community> {638 fn unread_first<'a>(&self, rooms: impl Iterator<Item = &'a Community>) -> Vec<&'a Community> {
672 let mut rooms: Vec<&Community> = rooms.collect();639 let mut rooms: Vec<&Community> = rooms.collect();
673 rooms.sort_by_key(|community| {640 rooms.sort_by_key(|community| {
674 self.chat641 self.chat
642+ .session
675 .unread643 .unread
676 .get(&community.id)644 .get(&community.id)
677 .map_or((true, true), |unread| {645 .map_or((true, true), |unread| {
@@ -684,11 +652,13 @@ impl Yumush {
684 pub(super) fn call_of(&self, user_id: Id) -> Option<&Community> {652 pub(super) fn call_of(&self, user_id: Id) -> Option<&Community> {
685 let community_id = self653 let community_id = self
686 .chat654 .chat
655+ .session
687 .voice656 .voice
688 .iter()657 .iter()
689 .find(|(_, ids)| ids.contains(&user_id))658 .find(|(_, ids)| ids.contains(&user_id))
690 .map(|(community_id, _)| *community_id)?;659 .map(|(community_id, _)| *community_id)?;
691 self.chat660 self.chat
661+ .session
692 .communities662 .communities
693 .iter()663 .iter()
694 .find(|community| community.id == community_id)664 .find(|community| community.id == community_id)
@@ -704,7 +674,7 @@ impl Yumush {
704 }674 }
705 }675 }
706 676
707- fn found_row(&self, entity: &Entity<Self>, user: &User, palette: Palette) -> AnyElement {677+ fn found_row(&self, entity: &Entity<Self>, user: &User, t: Tokens) -> AnyElement {
708 let relation = self.relation(user.id);678 let relation = self.relation(user.id);
709 let mut trailing = Vec::new();679 let mut trailing = Vec::new();
710 680
@@ -713,7 +683,7 @@ impl Yumush {
713 entity,683 entity,
714 "message",684 "message",
715 user.id,685 user.id,
716- palette,686+ t,
717 IconName::MessageSquare,687 IconName::MessageSquare,
718 w().sidebar.message,688 w().sidebar.message,
719 |yumush, id, window, cx| {689 |yumush, id, window, cx| {
@@ -731,43 +701,42 @@ impl Yumush {
731 entity,701 entity,
732 "friend_action",702 "friend_action",
733 user.id,703 user.id,
734- palette,704+ t,
735 icon,705 icon,
736 label,706 label,
737 move |yumush, id, window, cx| yumush.friend_action(relation, id, window, cx),707 move |yumush, id, window, cx| yumush.friend_action(relation, id, window, cx),
738 ));708 ));
739 }709 }
740 710
741- self.user_row(palette, user, trailing).into_any_element()711+ self.user_row(t, user, trailing).into_any_element()
742 }712 }
743 713
744 fn user_row(714 fn user_row(
745 &self,715 &self,
746- palette: Palette,716+ t: Tokens,
747 user: &User,717 user: &User,
748 trailing: impl IntoIterator<Item = AnyElement>,718 trailing: impl IntoIterator<Item = AnyElement>,
749 ) -> Div {719 ) -> Div {
750 entry(720 entry(
751- palette,721+ t,
752- false,
753 presence_avatar(722 presence_avatar(
754 avatar(723 avatar(
755- palette,724+ t,
756 user,725 user,
757 px(size::AVATAR),726 px(size::AVATAR),
758 text(text::CAPTION),727 text(text::CAPTION),
759- &self.chat.avatars,728+ &self.chat.session.avatars,
760 ),729 ),
761 self.presence_of(user.id),730 self.presence_of(user.id),
762 px(size::AVATAR),731 px(size::AVATAR),
763- palette,732+ t,
764 ),733 ),
765 div().flex().flex_col().child(user.username.clone()).when(734 div().flex().flex_col().child(user.username.clone()).when(
766 !user.status.is_empty(),735 !user.status.is_empty(),
767 |this| {736 |this| {
768 this.child(737 this.child(
769 div()738 div()
770- .text_color(palette.muted)739+ .text_color(t.dim())
771 .child(super::glyph::line(740 .child(super::glyph::line(
772 user.status.clone().into(),741 user.status.clone().into(),
773 text(text::CAPTION),742 text(text::CAPTION),
@@ -780,16 +749,16 @@ impl Yumush {
780 )749 )
781 }750 }
782 751
783- fn incoming_row(&self, entity: &Entity<Self>, user: &User, palette: Palette) -> AnyElement {752+ fn incoming_row(&self, entity: &Entity<Self>, user: &User, t: Tokens) -> AnyElement {
784 self.user_row(753 self.user_row(
785- palette,754+ t,
786 user,755 user,
787 [756 [
788 row_button(757 row_button(
789 entity,758 entity,
790 "accept_friend",759 "accept_friend",
791 user.id,760 user.id,
792- palette,761+ t,
793 IconName::Check,762 IconName::Check,
794 w().sidebar.accept,763 w().sidebar.accept,
795 |yumush, id, window, cx| yumush.accept_friend(id, window, cx),764 |yumush, id, window, cx| yumush.accept_friend(id, window, cx),
@@ -798,7 +767,7 @@ impl Yumush {
798 entity,767 entity,
799 "decline_friend",768 "decline_friend",
800 user.id,769 user.id,
801- palette,770+ t,
802 IconName::X,771 IconName::X,
803 w().sidebar.decline,772 w().sidebar.decline,
804 |yumush, id, window, cx| yumush.remove_friend(id, window, cx),773 |yumush, id, window, cx| yumush.remove_friend(id, window, cx),
@@ -808,15 +777,15 @@ impl Yumush {
808 .into_any_element()777 .into_any_element()
809 }778 }
810 779
811- fn outgoing_row(&self, entity: &Entity<Self>, user: &User, palette: Palette) -> AnyElement {780+ fn outgoing_row(&self, entity: &Entity<Self>, user: &User, t: Tokens) -> AnyElement {
812 self.user_row(781 self.user_row(
813- palette,782+ t,
814 user,783 user,
815 [row_button(784 [row_button(
816 entity,785 entity,
817 "cancel_friend",786 "cancel_friend",
818 user.id,787 user.id,
819- palette,788+ t,
820 IconName::X,789 IconName::X,
821 w().sidebar.cancel,790 w().sidebar.cancel,
822 |yumush, id, window, cx| yumush.remove_friend(id, window, cx),791 |yumush, id, window, cx| yumush.remove_friend(id, window, cx),
@@ -829,25 +798,24 @@ impl Yumush {
829 &self,798 &self,
830 entity: &Entity<Self>,799 entity: &Entity<Self>,
831 invitation: &Invitation,800 invitation: &Invitation,
832- palette: Palette,801+ t: Tokens,
833 ) -> AnyElement {802 ) -> AnyElement {
834 let community = &invitation.community;803 let community = &invitation.community;
835 let label = div().flex().flex_col().child(community.name.clone()).child(804 let label = div().flex().flex_col().child(community.name.clone()).child(
836 div()805 div()
837 .text_size(text(text::CAPTION))806 .text_size(text(text::CAPTION))
838- .text_color(palette.muted)807+ .text_color(t.dim())
839 .child(w().sidebar.from_user(&invitation.inviter.username)),808 .child(w().sidebar.from_user(&invitation.inviter.username)),
840 );809 );
841 810
842 entry(811 entry(
843- palette,812+ t,
844- false,
845 community_icon(813 community_icon(
846- palette,814+ t,
847 community,815 community,
848 px(size::ICON),816 px(size::ICON),
849 text(text::CAPTION),817 text(text::CAPTION),
850- &self.chat.avatars,818+ &self.chat.session.avatars,
851 ),819 ),
852 label,820 label,
853 [821 [
@@ -855,7 +823,7 @@ impl Yumush {
855 entity,823 entity,
856 "accept_invitation",824 "accept_invitation",
857 community.id,825 community.id,
858- palette,826+ t,
859 IconName::Check,827 IconName::Check,
860 w().sidebar.accept,828 w().sidebar.accept,
861 |yumush, id, window, cx| yumush.accept_invitation(id, window, cx),829 |yumush, id, window, cx| yumush.accept_invitation(id, window, cx),
@@ -864,7 +832,7 @@ impl Yumush {
864 entity,832 entity,
865 "decline_invitation",833 "decline_invitation",
866 community.id,834 community.id,
867- palette,835+ t,
868 IconName::X,836 IconName::X,
869 w().sidebar.decline,837 w().sidebar.decline,
870 |yumush, id, window, cx| yumush.decline_invitation(id, window, cx),838 |yumush, id, window, cx| yumush.decline_invitation(id, window, cx),
@@ -874,7 +842,7 @@ impl Yumush {
874 .into_any_element()842 .into_any_element()
875 }843 }
876 844
877- fn account_row(&self, entity: &Entity<Self>, palette: Palette) -> Option<impl IntoElement> {845+ fn account_row(&self, entity: &Entity<Self>, t: Tokens) -> Option<impl IntoElement> {
878 let user = self.user.as_ref()?;846 let user = self.user.as_ref()?;
879 Some(847 Some(
880 div()848 div()
@@ -882,8 +850,8 @@ impl Yumush {
882 .flex()850 .flex()
883 .items_center()851 .items_center()
884 .gap(px(space::XS))852 .gap(px(space::XS))
885- .child(self.account_trigger(entity, user, true, palette))853+ .child(self.account_trigger(entity, user, true, t))
886- .children((self.is_builder() && self.chat.ghost).then(|| {854+ .children((self.is_builder() && self.chat.session.ghost).then(|| {
887 self.folding(855 self.folding(
888 "builder_fold",856 "builder_fold",
889 div().child(857 div().child(
@@ -893,12 +861,12 @@ impl Yumush {
893 w().sidebar.ghost_on,861 w().sidebar.ghost_on,
894 Tone::Idle,862 Tone::Idle,
895 Scale::Small,863 Scale::Small,
896- palette.tokens,864+ t,
897 entity_action(entity, |yumush, window, cx| {865 entity_action(entity, |yumush, window, cx| {
898 yumush.show_view(View::Builder, window, cx)866 yumush.show_view(View::Builder, window, cx)
899 }),867 }),
900 )868 )
901- .text_color(palette.tokens.hue(super::style::my_hue())),869+ .text_color(t.hue(super::style::my_hue())),
902 ),870 ),
903 fade,871 fade,
904 )872 )
@@ -911,15 +879,15 @@ impl Yumush {
911 entity: &Entity<Self>,879 entity: &Entity<Self>,
912 user: &User,880 user: &User,
913 named: bool,881 named: bool,
914- palette: Palette,882+ t: Tokens,
915 ) -> impl IntoElement {883 ) -> impl IntoElement {
916 let face = if named { size::AVATAR } else { size::CONTROL };884 let face = if named { size::AVATAR } else { size::CONTROL };
917 let picture = avatar(885 let picture = avatar(
918- palette,886+ t,
919 user,887 user,
920 px(face),888 px(face),
921 text(text::CAPTION),889 text(text::CAPTION),
922- &self.chat.avatars,890+ &self.chat.session.avatars,
923 );891 );
924 let picture = if named {892 let picture = if named {
925 self.folding("avatar_face", picture, |picture, f| {893 self.folding("avatar_face", picture, |picture, f| {
@@ -928,7 +896,7 @@ impl Yumush {
928 } else {896 } else {
929 picture.into_any_element()897 picture.into_any_element()
930 };898 };
931- let picture = presence_avatar(picture, self.presence_of(user.id), px(face), palette);899+ let picture = presence_avatar(picture, self.presence_of(user.id), px(face), t);
932 let picture = if named {900 let picture = if named {
933 self.folding("avatar", picture, |picture, f| {901 self.folding("avatar", picture, |picture, f| {
934 picture902 picture
@@ -963,13 +931,13 @@ impl Yumush {
963 div()931 div()
964 .min_w_0()932 .min_w_0()
965 .truncate()933 .truncate()
966- .text_color(palette.muted)934+ .text_color(t.dim())
967 .child(user.username.clone()),935 .child(user.username.clone()),
968 fade,936 fade,
969 ),937 ),
970 )938 )
971 }),939 }),
972- palette,940+ t,
973 ),941 ),
974 )942 )
975 .when(named, |trigger| trigger.flex_1().min_w_0())943 .when(named, |trigger| trigger.flex_1().min_w_0())
@@ -991,8 +959,8 @@ pub(super) fn watch_pill(
991 user_id: Id,959 user_id: Id,
992 kind: Kind,960 kind: Kind,
993 watching: bool,961 watching: bool,
994- audio: Option<&std::collections::VecDeque<f32>>,962+ audio: Option<std::collections::VecDeque<f32>>,
995- palette: Palette,963+ t: Tokens,
996 ) -> impl IntoElement {964 ) -> impl IntoElement {
997 let icon = match kind {965 let icon = match kind {
998 Kind::Camera => IconName::Video,966 Kind::Camera => IconName::Video,
@@ -1005,7 +973,7 @@ pub(super) fn watch_pill(
1005 };973 };
1006 clickable(974 clickable(
1007 format!("voice_watch_{user_id}_{kind:?}"),975 format!("voice_watch_{user_id}_{kind:?}"),
1008- palette,976+ t,
1009 entity_action(entity, move |yumush, window, cx| {977 entity_action(entity, move |yumush, window, cx| {
1010 yumush.toggle_viewer(user_id, kind, window, cx)978 yumush.toggle_viewer(user_id, kind, window, cx)
1011 }),979 }),
@@ -1022,27 +990,19 @@ pub(super) fn watch_pill(
1022 .w(px(size::CONTROL))990 .w(px(size::CONTROL))
1023 .h(px(space::LG))991 .h(px(space::LG))
1024 .child(super::parts::voice_line(992 .child(super::parts::voice_line(
1025- Some(audio),993+ Some(&audio),
1026- super::parts::Voice::Live(palette.tokens.person(user_id)),994+ super::parts::Voice::Live(t.person(user_id)),
1027- palette.tokens,995+ t,
1028 ))996 ))
1029 }))997 }))
1030- .child(super::parts::small_icon(icon).text_color(if watching {998+ .child(super::parts::small_icon(icon).text_color(if watching { t.paper() } else { t.dim() }))
1031- palette.text
1032- } else {
1033- palette.muted
1034- }))
1035 }999 }
1036 1000
1037-pub(super) fn unread_badge(1001+pub(super) fn unread_badge(t: Tokens, muted: bool, unread: Option<&Unread>) -> Option<AnyElement> {
1038- palette: Palette,
1039- muted: bool,
1040- unread: Option<&Unread>,
1041-) -> Option<AnyElement> {
1042 if muted {1002 if muted {
1043 return Some(1003 return Some(
1044 div()1004 div()
1045- .text_color(palette.muted)1005+ .text_color(t.dim())
1046 .child(super::parts::small_icon(IconName::BellOff))1006 .child(super::parts::small_icon(IconName::BellOff))
1047 .into_any_element(),1007 .into_any_element(),
1048 );1008 );
@@ -1053,7 +1013,7 @@ pub(super) fn unread_badge(
1053 div()1013 div()
1054 .size(px(space::XS + space::XXS))1014 .size(px(space::XS + space::XXS))
1055 .rounded_full()1015 .rounded_full()
1056- .bg(palette.text)1016+ .bg(t.paper())
1057 .into_any_element(),1017 .into_any_element(),
1058 );1018 );
1059 }1019 }
@@ -1064,39 +1024,27 @@ pub(super) fn unread_badge(
1064 Some(1024 Some(
1065 div()1025 div()
1066 .text_size(text(text::CAPTION))1026 .text_size(text(text::CAPTION))
1067- .text_color(palette.text)1027+ .text_color(t.paper())
1068 .child(count)1028 .child(count)
1069 .into_any_element(),1029 .into_any_element(),
1070 )1030 )
1071 }1031 }
1072 1032
1073-fn matches_query(name: &str, query: &str) -> bool {1033+pub(super) fn input_box(input: &Entity<InputState>, t: Tokens) -> Div {
1074- name.to_lowercase().contains(query)1034+ underline(
1075-}1035+ t,
1076-1036+ size::CONTROL_SM + space::XS,
1077-pub(super) fn input_box(input: &Entity<InputState>, palette: Palette) -> Div {
1078- compact_frame(palette)
1079- .gap(px(space::SM))
1080- .text_color(palette.muted)
1081- .child(super::parts::small_icon(IconName::Search))
1082- .child(bare_input(
1083- palette,
1084- Input::new(input).token(super::glyph::token),
1085- ))
1086-}
1087-
1088-fn group(title: &'static str, palette: Palette, rows: Vec<AnyElement>) -> Option<Div> {
1089- (!rows.is_empty()).then(|| {
1090 div()1037 div()
1091 .flex()1038 .flex()
1092- .flex_col()1039+ .items_center()
1093- .gap(px(space::XXS))1040+ .gap(px(space::SM))
1094- .child(super::parts::caption_head(title, palette.tokens))1041+ .text_color(t.dim())
1095- .children(rows)1042+ .child(super::parts::small_icon(IconName::Search))
1096- })1043+ .child(bare_input(t, Input::new(input).token(super::glyph::token))),
1044+ )
1097 }1045 }
1098 1046
1099-fn notes_tile(palette: Palette) -> AnyElement {1047+fn notes_tile(t: Tokens) -> AnyElement {
1100 div()1048 div()
1101 .size(px(size::AVATAR))1049 .size(px(size::AVATAR))
1102 .flex_none()1050 .flex_none()
@@ -1104,15 +1052,15 @@ fn notes_tile(palette: Palette) -> AnyElement {
1104 .items_center()1052 .items_center()
1105 .justify_center()1053 .justify_center()
1106 .rounded(px(radius::SM))1054 .rounded(px(radius::SM))
1107- .bg(palette.tokens.press())1055+ .bg(t.press())
1108- .child(super::parts::small_icon(IconName::Bookmark).text_color(palette.muted))1056+ .child(super::parts::small_icon(IconName::Bookmark).text_color(t.dim()))
1109 .into_any_element()1057 .into_any_element()
1110 }1058 }
1111 1059
1112 fn room_row(1060 fn room_row(
1113- palette: Palette,1061+ t: Tokens,
1114 active: bool,1062 active: bool,
1115- face: Option<AnyElement>,1063+ face: AnyElement,
1116 label: String,1064 label: String,
1117 trailing: Option<AnyElement>,1065 trailing: Option<AnyElement>,
1118 ) -> Div {1066 ) -> Div {
@@ -1123,16 +1071,15 @@ fn room_row(
1123 .flex()1071 .flex()
1124 .items_center()1072 .items_center()
1125 .gap(px(space::SM))1073 .gap(px(space::SM))
1126- .text_color(if active { palette.text } else { palette.muted })1074+ .text_color(if active { t.paper() } else { t.dim() })
1127 .when(active, |row| row.font_weight(FontWeight::MEDIUM))1075 .when(active, |row| row.font_weight(FontWeight::MEDIUM))
1128- .children(face)1076+ .child(face)
1129 .child(div().flex_1().min_w_0().truncate().child(label))1077 .child(div().flex_1().min_w_0().truncate().child(label))
1130 .children(trailing)1078 .children(trailing)
1131 }1079 }
1132 1080
1133 fn entry(1081 fn entry(
1134- palette: Palette,1082+ t: Tokens,
1135- active: bool,
1136 leading: impl IntoElement,1083 leading: impl IntoElement,
1137 label: impl IntoElement,1084 label: impl IntoElement,
1138 trailing: impl IntoIterator<Item = AnyElement>,1085 trailing: impl IntoIterator<Item = AnyElement>,
@@ -1145,8 +1092,7 @@ fn entry(
1145 .items_center()1092 .items_center()
1146 .gap(px(space::SM))1093 .gap(px(space::SM))
1147 .rounded(px(radius::MD))1094 .rounded(px(radius::MD))
1148- .text_color(if active { palette.text } else { palette.body })1095+ .text_color(t.paper())
1149- .when(active, |this| this.bg(palette.tokens.press()))
1150 .child(leading)1096 .child(leading)
1151 .child(div().flex_1().min_w_0().truncate().child(label))1097 .child(div().flex_1().min_w_0().truncate().child(label))
1152 .children(trailing)1098 .children(trailing)
@@ -1156,7 +1102,7 @@ fn row_button(
1156 entity: &Entity<Yumush>,1102 entity: &Entity<Yumush>,
1157 key: &str,1103 key: &str,
1158 id: Id,1104 id: Id,
1159- palette: Palette,1105+ t: Tokens,
1160 icon: IconName,1106 icon: IconName,
1161 tip: &'static str,1107 tip: &'static str,
1162 run: impl Fn(&mut Yumush, Id, &mut Window, &mut Context<Yumush>) + 'static,1108 run: impl Fn(&mut Yumush, Id, &mut Window, &mut Context<Yumush>) + 'static,
@@ -1167,7 +1113,7 @@ fn row_button(
1167 tip,1113 tip,
1168 Tone::Idle,1114 Tone::Idle,
1169 Scale::Small,1115 Scale::Small,
1170- palette.tokens,1116+ t,
1171 entity_action(entity, move |yumush, window, cx| {1117 entity_action(entity, move |yumush, window, cx| {
1172 run(yumush, id, window, cx)1118 run(yumush, id, window, cx)
1173 }),1119 }),
@@ -1190,8 +1136,8 @@ fn right_menu(
1190 .trigger(super::Trigger::new(trigger))1136 .trigger(super::Trigger::new(trigger))
1191 .content(move |_, _, cx| {1137 .content(move |_, _, cx| {
1192 let popover = cx.entity();1138 let popover = cx.entity();
1193- let palette = super::palette(cx);1139+ let t = Tokens::of(cx);
1194- super::parts::popover(palette.tokens)1140+ super::parts::popover(t)
1195 .w(px(size::SIDEBAR))1141 .w(px(size::SIDEBAR))
1196 .p(px(space::XS))1142 .p(px(space::XS))
1197 .child(rows(&popover, cx))1143 .child(rows(&popover, cx))
@@ -1215,21 +1161,21 @@ const WANDER: std::time::Duration = std::time::Duration::from_secs(10);
1215 const LINGER: std::time::Duration = std::time::Duration::from_secs(6);1161 const LINGER: std::time::Duration = std::time::Duration::from_secs(6);
1216 const TOW: std::time::Duration = std::time::Duration::from_millis(2300);1162 const TOW: std::time::Duration = std::time::Duration::from_millis(2300);
1217 1163
1218-fn lerp(from: f32, to: f32, f: f32) -> f32 {
1219- from + (to - from) * f
1220-}
1221-
1222 fn fade<E: Styled>(element: E, f: f32) -> E {1164 fn fade<E: Styled>(element: E, f: f32) -> E {
1223 let shown = 1. - f;1165 let shown = 1. - f;
1224 element.opacity(shown)1166 element.opacity(shown)
1225 }1167 }
1226 1168
1227-fn logo_mark(palette: Palette) -> gpui_kit::Svg {1169+fn lerp(from: f32, to: f32, f: f32) -> f32 {
1170+ from + (to - from) * f
1171+}
1172+
1173+fn logo_mark(t: Tokens) -> gpui_kit::Svg {
1228 gpui_kit::svg()1174 gpui_kit::svg()
1229 .path(crate::logo::PATH)1175 .path(crate::logo::PATH)
1230 .size(px(size::CHIP))1176 .size(px(size::CHIP))
1231 .flex_none()1177 .flex_none()
1232- .text_color(palette.text)1178+ .text_color(t.paper())
1233 }1179 }
1234 1180
1235 pub(super) fn wander(cx: &mut Context<Yumush>) {1181 pub(super) fn wander(cx: &mut Context<Yumush>) {
@@ -1254,7 +1200,7 @@ fn towing(flipped: Option<std::time::Instant>) -> bool {
1254 flipped.is_some_and(|at| at.elapsed() < TOW)1200 flipped.is_some_and(|at| at.elapsed() < TOW)
1255 }1201 }
1256 1202
1257-fn wordmark_tail(flips: u32, flipped: Option<std::time::Instant>, palette: Palette) -> AnyElement {1203+fn wordmark_tail(flips: u32, flipped: Option<std::time::Instant>, t: Tokens) -> AnyElement {
1258 let turkish = flips % 2 == 1;1204 let turkish = flips % 2 == 1;
1259 let em = super::style::text::TITLE / super::style::text::UI;1205 let em = super::style::text::TITLE / super::style::text::UI;
1260 if !towing(flipped) {1206 if !towing(flipped) {
@@ -1271,7 +1217,7 @@ fn wordmark_tail(flips: u32, flipped: Option<std::time::Instant>, palette: Palet
1271 }1217 }
1272 .into_any_element();1218 .into_any_element();
1273 }1219 }
1274- let (ink, ground) = (palette.text, palette.panel);1220+ let (ink, ground) = (t.paper(), t.ground());
1275 div()1221 div()
1276 .relative()1222 .relative()
1277 .child("s")1223 .child("s")
crates/client/src/gui/snippet.rsmodified+15 -16
@@ -1,4 +1,4 @@
1-use super::style::{size, space, text};1+use super::style::{Tokens, size, space, text};
2 use crate::lang::w;2 use crate::lang::w;
3 use common::model::{Message, Role, SnippetMessage, User};3 use common::model::{Message, Role, SnippetMessage, User};
4 use gpui_kit::{4 use gpui_kit::{
@@ -7,8 +7,7 @@ use gpui_kit::{
7 };7 };
8 8
9 use super::{9 use super::{
10- Palette, Yumush, avatar, chat::Chat, media_view, millis_time, poll, profile::user_link,10+ Yumush, avatar, chat::Chat, media_view, millis_time, parts::surface, poll, profile::user_link,
11- widget::panel,
12 };11 };
13 12
14 pub fn snippet_card(13 pub fn snippet_card(
@@ -16,7 +15,7 @@ pub fn snippet_card(
16 clock: &'static str,15 clock: &'static str,
17 chat: &Chat,16 chat: &Chat,
18 entity: &Entity<Yumush>,17 entity: &Entity<Yumush>,
19- palette: Palette,18+ t: Tokens,
20 ) -> Option<impl IntoElement> {19 ) -> Option<impl IntoElement> {
21 let snippet = message.snippet.as_ref()?;20 let snippet = message.snippet.as_ref()?;
22 let header = match &snippet.origin {21 let header = match &snippet.origin {
@@ -25,7 +24,7 @@ pub fn snippet_card(
25 };24 };
26 25
27 Some(26 Some(
28- panel(palette)27+ surface(t)
29 .flex()28 .flex()
30 .flex_col()29 .flex_col()
31 .gap(px(space::MD))30 .gap(px(space::MD))
@@ -33,14 +32,14 @@ pub fn snippet_card(
33 .child(32 .child(
34 div()33 div()
35 .text_size(super::text(text::CAPTION))34 .text_size(super::text(text::CAPTION))
36- .text_color(palette.muted)35+ .text_color(t.dim())
37 .child(header),36 .child(header),
38 )37 )
39 .children(38 .children(
40 snippet39 snippet
41 .messages40 .messages
42 .iter()41 .iter()
43- .map(|item| snippet_row(item, clock, chat, entity, palette)),42+ .map(|item| snippet_row(item, clock, chat, entity, t)),
44 ),43 ),
45 )44 )
46 }45 }
@@ -50,7 +49,7 @@ fn snippet_row(
50 clock: &'static str,49 clock: &'static str,
51 chat: &Chat,50 chat: &Chat,
52 entity: &Entity<Yumush>,51 entity: &Entity<Yumush>,
53- palette: Palette,52+ t: Tokens,
54 ) -> impl IntoElement {53 ) -> impl IntoElement {
55 let user = chat.author(item.user_id).cloned().unwrap_or_else(|| User {54 let user = chat.author(item.user_id).cloned().unwrap_or_else(|| User {
56 id: item.user_id,55 id: item.user_id,
@@ -70,11 +69,11 @@ fn snippet_row(
70 Some(&user),69 Some(&user),
71 entity,70 entity,
72 avatar(71 avatar(
73- palette,72+ t,
74 &user,73 &user,
75 px(size::AVATAR),74 px(size::AVATAR),
76 super::text(text::CAPTION),75 super::text(text::CAPTION),
77- &chat.avatars,76+ &chat.session.avatars,
78 ),77 ),
79 ))78 ))
80 .child(79 .child(
@@ -95,13 +94,13 @@ fn snippet_row(
95 entity,94 entity,
96 div()95 div()
97 .font_weight(FontWeight::SEMIBOLD)96 .font_weight(FontWeight::SEMIBOLD)
98- .text_color(palette.tinted(item.user_id))97+ .text_color(t.person(item.user_id))
99 .child(item.username.clone()),98 .child(item.username.clone()),
100 ))99 ))
101 .child(100 .child(
102 div()101 div()
103 .text_size(super::text(text::CAPTION))102 .text_size(super::text(text::CAPTION))
104- .text_color(palette.muted)103+ .text_color(t.dim())
105 .child(millis_time(item.created_at, clock)),104 .child(millis_time(item.created_at, clock)),
106 ),105 ),
107 )106 )
@@ -109,7 +108,7 @@ fn snippet_row(
109 this.child(108 this.child(
110 div()109 div()
111 .line_height(relative(1.5))110 .line_height(relative(1.5))
112- .text_color(palette.body)111+ .text_color(t.paper())
113 .child(super::glyph::wrapped(112 .child(super::glyph::wrapped(
114 item.body.clone().into(),113 item.body.clone().into(),
115 super::text(super::style::text::UI),114 super::text(super::style::text::UI),
@@ -118,9 +117,9 @@ fn snippet_row(
118 })117 })
119 .children(media_view::attachments(118 .children(media_view::attachments(
120 &item.attachments,119 &item.attachments,
121- &chat.media,120+ &chat.session.media,
122 entity,121 entity,
123- palette,122+ t,
124 ))123 ))
125 .children(item.poll.as_ref().map(|poll| {124 .children(item.poll.as_ref().map(|poll| {
126 poll::poll_card(125 poll::poll_card(
@@ -129,7 +128,7 @@ fn snippet_row(
129 None,128 None,
130 chat,129 chat,
131 entity,130 entity,
132- palette,131+ t,
133 )132 )
134 })),133 })),
135 )134 )
crates/client/src/gui/social.rsmodified+65 -54
@@ -22,8 +22,8 @@ use gpui_kit::{
22 };22 };
23 23
24 use super::{24 use super::{
25- Palette, Yumush, avatar, new_input, notify_error, parts,25+ Yumush, avatar, new_input, notify_error, parts,
26- style::{size, space},26+ style::{Tokens, size, space},
27 text,27 text,
28 widget::{search_text, spawn_done},28 widget::{search_text, spawn_done},
29 };29 };
@@ -61,12 +61,17 @@ impl Relation {
61 fn spawn_community<E: Display + 'static>(61 fn spawn_community<E: Display + 'static>(
62 window: &mut Window,62 window: &mut Window,
63 cx: &mut Context<Yumush>,63 cx: &mut Context<Yumush>,
64+ join_voice: bool,
64 call: impl Future<Output = Result<Community, E>> + 'static,65 call: impl Future<Output = Result<Community, E>> + 'static,
65 ) {66 ) {
66 cx.spawn_in(window, async move |this, cx| match call.await {67 cx.spawn_in(window, async move |this, cx| match call.await {
67 Ok(community) => {68 Ok(community) => {
68 let _ = this.update_in(cx, |yumush, window, cx| {69 let _ = this.update_in(cx, |yumush, window, cx| {
70+ let community_id = community.id;
69 yumush.enter_community(community, window, cx);71 yumush.enter_community(community, window, cx);
72+ if join_voice && !yumush.chat.in_voice(community_id) {
73+ yumush.toggle_voice(community_id, window, cx);
74+ }
70 });75 });
71 }76 }
72 Err(error) => notify_error(&this, cx, error),77 Err(error) => notify_error(&this, cx, error),
@@ -76,7 +81,7 @@ fn spawn_community<E: Display + 'static>(
76 81
77 impl Yumush {82 impl Yumush {
78 pub(super) fn relation(&self, user_id: Id) -> Relation {83 pub(super) fn relation(&self, user_id: Id) -> Relation {
79- let friends = &self.chat.friends;84+ let friends = &self.chat.session.friends;
80 85
81 if self.is_me(user_id) {86 if self.is_me(user_id) {
82 Relation::Myself87 Relation::Myself
@@ -94,25 +99,27 @@ impl Yumush {
94 pub(super) fn request_social_avatars(&mut self, cx: &mut Context<Self>) {99 pub(super) fn request_social_avatars(&mut self, cx: &mut Context<Self>) {
95 let chat = &self.chat;100 let chat = &self.chat;
96 let users = chat101 let users = chat
102+ .session
97 .friends103 .friends
98 .friends104 .friends
99 .iter()105 .iter()
100- .chain(&chat.friends.incoming)106+ .chain(&chat.session.friends.incoming)
101- .chain(&chat.friends.outgoing)107+ .chain(&chat.session.friends.outgoing)
102 .chain(108 .chain(
103- chat.invitations109+ chat.session
110+ .invitations
104 .iter()111 .iter()
105 .map(|invitation| &invitation.inviter),112 .map(|invitation| &invitation.inviter),
106 )113 )
107 .chain(114 .chain(
108- chat.communities115+ chat.communities()
109 .iter()116 .iter()
110 .filter_map(|community| community.kind.peer()),117 .filter_map(|community| community.kind.peer()),
111 );118 );
112 let avatar_ids: Vec<Id> = users119 let avatar_ids: Vec<Id> = users
113 .filter_map(|user| user.avatar_id)120 .filter_map(|user| user.avatar_id)
114 .chain(121 .chain(
115- chat.communities122+ chat.communities()
116 .iter()123 .iter()
117 .filter_map(|community| community.avatar_id),124 .filter_map(|community| community.avatar_id),
118 )125 )
@@ -148,9 +155,9 @@ impl Yumush {
148 .chain(&friends.outgoing)155 .chain(&friends.outgoing)
149 .collect::<Vec<_>>(),156 .collect::<Vec<_>>(),
150 );157 );
151- yumush.chat.friends = friends;158+ yumush.chat.session.friends = friends;
152- yumush.chat.invitations = invitations;159+ yumush.chat.session.invitations = invitations;
153- yumush.chat.presences = presences.into_iter().collect();160+ yumush.chat.session.presences = presences.into_iter().collect();
154 yumush.request_social_avatars(cx);161 yumush.request_social_avatars(cx);
155 cx.notify();162 cx.notify();
156 });163 });
@@ -159,7 +166,7 @@ impl Yumush {
159 }166 }
160 167
161 pub(super) fn search_user(&mut self, window: &mut Window, cx: &mut Context<Self>) {168 pub(super) fn search_user(&mut self, window: &mut Window, cx: &mut Context<Self>) {
162- self.chat.found = None;169+ self.chat.session.found = None;
163 cx.notify();170 cx.notify();
164 let username = search_text(&self.chat.search_input, cx);171 let username = search_text(&self.chat.search_input, cx);
165 if validate_username(&username).is_err() {172 if validate_username(&username).is_err() {
@@ -181,7 +188,7 @@ impl Yumush {
181 if let Some(user) = &found {188 if let Some(user) = &found {
182 yumush.request_user_avatar(user, cx);189 yumush.request_user_avatar(user, cx);
183 }190 }
184- yumush.chat.found = found;191+ yumush.chat.session.found = found;
185 cx.notify();192 cx.notify();
186 });193 });
187 })194 })
@@ -189,9 +196,15 @@ impl Yumush {
189 }196 }
190 197
191 pub(super) fn open_found(&mut self, window: &mut Window, cx: &mut Context<Self>) {198 pub(super) fn open_found(&mut self, window: &mut Window, cx: &mut Context<Self>) {
192- if let Some(user) = &self.chat.found {199+ let Some(user) = &self.chat.session.found else {
193- self.chat.friends_open = false;200+ return;
194- self.open_direct(user.id, window, cx);201+ };
202+ let user_id = user.id;
203+ self.close_friends(window, cx);
204+ if self.relation(user_id) == Relation::Myself {
205+ self.open_notes(window, cx);
206+ } else {
207+ self.open_direct(user_id, window, cx);
195 }208 }
196 }209 }
197 210
@@ -203,34 +216,28 @@ impl Yumush {
203 }216 }
204 let network = self.network.clone();217 let network = self.network.clone();
205 218
206- spawn_community(window, cx, async move { network.call(OpenNotes).await });219+ spawn_community(
220+ window,
221+ cx,
222+ false,
223+ async move { network.call(OpenNotes).await },
224+ );
207 }225 }
208 226
209 pub(super) fn open_direct(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {227 pub(super) fn open_direct(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {
210 let network = self.network.clone();228 let network = self.network.clone();
211 229
212- spawn_community(window, cx, async move {230+ spawn_community(window, cx, false, async move {
213 network.call(OpenDirect { user_id }).await231 network.call(OpenDirect { user_id }).await
214 });232 });
215 }233 }
216 234
217 pub(super) fn call_direct(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {235 pub(super) fn call_direct(&self, user_id: Id, window: &mut Window, cx: &mut Context<Self>) {
218 let network = self.network.clone();236 let network = self.network.clone();
219- cx.spawn_in(window, async move |this, cx| {237+
220- match network.call(OpenDirect { user_id }).await {238+ spawn_community(window, cx, true, async move {
221- Ok(community) => {239+ network.call(OpenDirect { user_id }).await
222- let _ = this.update_in(cx, |yumush, window, cx| {240+ });
223- let community_id = community.id;
224- yumush.enter_community(community, window, cx);
225- if !yumush.chat.in_voice(community_id) {
226- yumush.toggle_voice(community_id, window, cx);
227- }
228- });
229- }
230- Err(error) => notify_error(&this, cx, error),
231- }
232- })
233- .detach();
234 }241 }
235 242
236 pub(super) fn friend_action(243 pub(super) fn friend_action(
@@ -280,7 +287,7 @@ impl Yumush {
280 ) {287 ) {
281 let network = self.network.clone();288 let network = self.network.clone();
282 289
283- spawn_community(window, cx, async move {290+ spawn_community(window, cx, false, async move {
284 network.call(AcceptInvitation { community_id }).await291 network.call(AcceptInvitation { community_id }).await
285 });292 });
286 }293 }
@@ -304,17 +311,15 @@ impl Yumush {
304 window: &mut Window,311 window: &mut Window,
305 cx: &mut Context<Self>,312 cx: &mut Context<Self>,
306 ) {313 ) {
307- self.chat.invite = InviteLookup::Idle;314+ self.chat.session.invite = InviteLookup::Idle;
308 let input = new_input(w().social.username_placeholder, window, cx);315 let input = new_input(w().social.username_placeholder, window, cx);
309- let enter_id = community_id;
310- let lookup_id = community_id;
311 316
312 cx.subscribe_in(317 cx.subscribe_in(
313 &input,318 &input,
314 window,319 window,
315 move |this, input, event, window, cx| match event {320 move |this, input, event, window, cx| match event {
316- InputEvent::Change => this.lookup_invite(lookup_id, input, window, cx),321+ InputEvent::Change => this.lookup_invite(community_id, input, window, cx),
317- InputEvent::PressEnter { .. } => this.send_invite(enter_id, window, cx),322+ InputEvent::PressEnter { .. } => this.send_invite(community_id, window, cx),
318 _ => {}323 _ => {}
319 },324 },
320 )325 )
@@ -324,15 +329,21 @@ impl Yumush {
324 let dialog_input = input.clone();329 let dialog_input = input.clone();
325 window.open_dialog(cx, move |dialog, _, cx| {330 window.open_dialog(cx, move |dialog, _, cx| {
326 let yumush = entity.read(cx);331 let yumush = entity.read(cx);
327- let palette = super::palette(cx);332+ let t = Tokens::of(cx);
328- let result = invite_result(&yumush.chat.invite, community_id, &entity, yumush, palette);333+ let result = invite_result(
334+ &yumush.chat.session.invite,
335+ community_id,
336+ &entity,
337+ yumush,
338+ t,
339+ );
329 340
330 dialog.title(w().social.invite).child(341 dialog.title(w().social.invite).child(
331 div()342 div()
332 .flex()343 .flex()
333 .flex_col()344 .flex_col()
334 .gap(px(space::MD))345 .gap(px(space::MD))
335- .child(super::sidebar::input_box(&dialog_input, palette))346+ .child(super::sidebar::input_box(&dialog_input, t))
336 .children(result),347 .children(result),
337 )348 )
338 });349 });
@@ -349,7 +360,7 @@ impl Yumush {
349 cx: &mut Context<Self>,360 cx: &mut Context<Self>,
350 ) {361 ) {
351 let username = search_text(input, cx);362 let username = search_text(input, cx);
352- self.chat.invite = InviteLookup::Idle;363+ self.chat.session.invite = InviteLookup::Idle;
353 window.refresh();364 window.refresh();
354 if validate_username(&username).is_err() {365 if validate_username(&username).is_err() {
355 return;366 return;
@@ -384,7 +395,7 @@ impl Yumush {
384 if let InviteLookup::Found(user) | InviteLookup::Member(user) = &lookup {395 if let InviteLookup::Found(user) | InviteLookup::Member(user) = &lookup {
385 yumush.request_user_avatar(user, cx);396 yumush.request_user_avatar(user, cx);
386 }397 }
387- yumush.chat.invite = lookup;398+ yumush.chat.session.invite = lookup;
388 window.refresh();399 window.refresh();
389 });400 });
390 })401 })
@@ -392,7 +403,7 @@ impl Yumush {
392 }403 }
393 404
394 fn send_invite(&self, community_id: Id, window: &mut Window, cx: &mut Context<Self>) {405 fn send_invite(&self, community_id: Id, window: &mut Window, cx: &mut Context<Self>) {
395- let InviteLookup::Found(user) = &self.chat.invite else {406+ let InviteLookup::Found(user) = &self.chat.session.invite else {
396 return;407 return;
397 };408 };
398 let network = self.network.clone();409 let network = self.network.clone();
@@ -421,23 +432,23 @@ fn invite_result(
421 community_id: Id,432 community_id: Id,
422 entity: &Entity<Yumush>,433 entity: &Entity<Yumush>,
423 yumush: &Yumush,434 yumush: &Yumush,
424- palette: Palette,435+ t: Tokens,
425 ) -> Option<AnyElement> {436 ) -> Option<AnyElement> {
426 match lookup {437 match lookup {
427 InviteLookup::Idle => None,438 InviteLookup::Idle => None,
428 InviteLookup::Missing => Some(439 InviteLookup::Missing => Some(
429 div()440 div()
430 .text_size(text(super::style::text::LABEL))441 .text_size(text(super::style::text::LABEL))
431- .text_color(palette.muted)442+ .text_color(t.dim())
432 .child(w().social.no_such_user)443 .child(w().social.no_such_user)
433 .into_any_element(),444 .into_any_element(),
434 ),445 ),
435 InviteLookup::Member(user) => Some(446 InviteLookup::Member(user) => Some(
436- user_row(user, yumush, palette)447+ user_row(user, yumush, t)
437 .child(448 .child(
438 div()449 div()
439 .text_size(text(super::style::text::LABEL))450 .text_size(text(super::style::text::LABEL))
440- .text_color(palette.muted)451+ .text_color(t.dim())
441 .child(Rank::Member.label()),452 .child(Rank::Member.label()),
442 )453 )
443 .into_any_element(),454 .into_any_element(),
@@ -446,12 +457,12 @@ fn invite_result(
446 let entity = entity.clone();457 let entity = entity.clone();
447 458
448 Some(459 Some(
449- user_row(user, yumush, palette)460+ user_row(user, yumush, t)
450 .child(parts::button(461 .child(parts::button(
451 "invite_send",462 "invite_send",
452 w().social.invite,463 w().social.invite,
453 parts::Press::Primary,464 parts::Press::Primary,
454- palette.tokens,465+ t,
455 move |window, cx| {466 move |window, cx| {
456 entity.update(cx, |yumush, cx| {467 entity.update(cx, |yumush, cx| {
457 yumush.send_invite(community_id, window, cx)468 yumush.send_invite(community_id, window, cx)
@@ -464,17 +475,17 @@ fn invite_result(
464 }475 }
465 }476 }
466 477
467-fn user_row(user: &User, yumush: &Yumush, palette: Palette) -> Div {478+fn user_row(user: &User, yumush: &Yumush, t: Tokens) -> Div {
468 div()479 div()
469 .flex()480 .flex()
470 .items_center()481 .items_center()
471 .gap(px(space::MD))482 .gap(px(space::MD))
472 .child(avatar(483 .child(avatar(
473- palette,484+ t,
474 user,485 user,
475 px(size::AVATAR),486 px(size::AVATAR),
476 text(super::style::text::UI),487 text(super::style::text::UI),
477- &yumush.chat.avatars,488+ &yumush.chat.session.avatars,
478 ))489 ))
479 .child(490 .child(
480 div()491 div()
crates/client/src/gui/stream_stats.rsmodified+8 -21
@@ -3,18 +3,17 @@ use common::{model::Id, share::Kind};
3 use gpui_kit::{Div, FontWeight, ParentElement, Styled, div, px};3 use gpui_kit::{Div, FontWeight, ParentElement, Styled, div, px};
4 4
5 use super::{5 use super::{
6- Palette, Yumush,6+ Yumush,
7 parts::{Ink, Text, band, chart, popover, words},7 parts::{Ink, Text, band, chart, popover, words},
8- style::{size, space},8+ style::{Tokens, size, space},
9- voice_stats::{9+ voice_stats::{GOOD_LOSS, SAMPLE_HISTORY, kind_word, number, stamp, stream_detail},
10- GOOD_LOSS, SAMPLE_HISTORY, engine_label, kind_word, number, resolution_text, stamp,
11- },
12 };10 };
13-use crate::share::session::WatchStats;11+use common::stats::WatchStats;
14 12
15 pub(super) fn watch_stats(yumush: &Yumush, user_id: Id, kind: Kind) -> Option<&WatchStats> {13 pub(super) fn watch_stats(yumush: &Yumush, user_id: Id, kind: Kind) -> Option<&WatchStats> {
16 yumush14 yumush
17 .chat15 .chat
16+ .session
18 .stats17 .stats
19 .share18 .share
20 .watching19 .watching
@@ -23,8 +22,7 @@ pub(super) fn watch_stats(yumush: &Yumush, user_id: Id, kind: Kind) -> Option<&W
23 .map(|(_, _, stats)| stats)22 .map(|(_, _, stats)| stats)
24 }23 }
25 24
26-pub(super) fn stream_card(yumush: &Yumush, user_id: Id, kind: Kind, palette: Palette) -> Div {25+pub(super) fn stream_card(yumush: &Yumush, user_id: Id, kind: Kind, t: Tokens) -> Div {
27- let t = palette.tokens;
28 let name = yumush26 let name = yumush
29 .chat27 .chat
30 .author(user_id)28 .author(user_id)
@@ -32,6 +30,7 @@ pub(super) fn stream_card(yumush: &Yumush, user_id: Id, kind: Kind, palette: Pal
32 let stats = watch_stats(yumush, user_id, kind);30 let stats = watch_stats(yumush, user_id, kind);
33 let losses: Vec<(u64, f32)> = yumush31 let losses: Vec<(u64, f32)> = yumush
34 .chat32 .chat
33+ .session
35 .share_loss34 .share_loss
36 .get(&(user_id, kind))35 .get(&(user_id, kind))
37 .into_iter()36 .into_iter()
@@ -44,19 +43,7 @@ pub(super) fn stream_card(yumush: &Yumush, user_id: Id, kind: Kind, palette: Pal
44 let loss = stats.map(|stats| stats.loss * 100.);43 let loss = stats.map(|stats| stats.loss * 100.);
45 let bad = loss.is_some_and(|loss| loss > GOOD_LOSS);44 let bad = loss.is_some_and(|loss| loss > GOOD_LOSS);
46 let field = |value: Option<String>| value.unwrap_or_else(|| "…".into());45 let field = |value: Option<String>| value.unwrap_or_else(|| "…".into());
47- let detail = stats.map_or("…".to_string(), |stats| {46+ let detail = stats.map_or("…".to_string(), stream_detail);
48- let layer = stats.layer.map_or("…".to_string(), |layer| {
49- format!(
50- "{} · {}",
51- resolution_text(layer, stats.fps),
52- layer.codec.name()
53- )
54- });
55- match stats.engine {
56- Some(engine) => format!("{layer} · {}", engine_label(engine)),
57- None => layer,
58- }
59- });
60 47
61 popover(t)48 popover(t)
62 .w(px(size::POPOVER))49 .w(px(size::POPOVER))
crates/client/src/gui/style.rsmodified+18 -21
@@ -1,4 +1,7 @@
1-use std::{cell::RefCell, collections::HashMap};1+use std::{
2+ cell::{Cell, RefCell},
3+ collections::HashMap,
4+};
2 5
3 use common::model::{Hue, Id, User};6 use common::model::{Hue, Id, User};
4 use gpui_kit::{App, Global, Hsla, Rems, rems, rgb};7 use gpui_kit::{App, Global, Hsla, Rems, rems, rgb};
@@ -16,31 +19,26 @@ impl Theme {
16 }19 }
17 }20 }
18 21
19-pub struct Look {
20- pub theme: Theme,
21- pub size: FontSize,
22-}
23-
24-impl Global for Look {}
25-
26 #[derive(Clone, Copy)]22 #[derive(Clone, Copy)]
27 pub struct Tokens {23 pub struct Tokens {
28 pub theme: Theme,24 pub theme: Theme,
29 pub size: FontSize,25 pub size: FontSize,
30 }26 }
31 27
28+impl Default for Tokens {
29+ fn default() -> Self {
30+ Tokens {
31+ theme: Theme::Gece,
32+ size: FontSize::Medium,
33+ }
34+ }
35+}
36+
37+impl Global for Tokens {}
38+
32 impl Tokens {39 impl Tokens {
33 pub fn of(cx: &App) -> Self {40 pub fn of(cx: &App) -> Self {
34- cx.try_global::<Look>().map_or(41+ cx.try_global::<Tokens>().copied().unwrap_or_default()
35- Tokens {
36- theme: Theme::Gece,
37- size: FontSize::Medium,
38- },
39- |look| Tokens {
40- theme: look.theme,
41- size: look.size,
42- },
43- )
44 }42 }
45 43
46 fn colors(self) -> &'static Colors {44 fn colors(self) -> &'static Colors {
@@ -122,7 +120,7 @@ thread_local! {
122 static CHOSEN: RefCell<HashMap<Id, Hue>> = RefCell::default();120 static CHOSEN: RefCell<HashMap<Id, Hue>> = RefCell::default();
123 static AVATAR: RefCell<HashMap<Id, Id>> = RefCell::default();121 static AVATAR: RefCell<HashMap<Id, Id>> = RefCell::default();
124 static PICTURED: RefCell<HashMap<Id, Hue>> = RefCell::default();122 static PICTURED: RefCell<HashMap<Id, Hue>> = RefCell::default();
125- static ME: std::cell::Cell<Option<Id>> = const { std::cell::Cell::new(None) };123+ static ME: Cell<Option<Id>> = const { Cell::new(None) };
126 }124 }
127 125
128 pub fn remember_me(id: Id) {126 pub fn remember_me(id: Id) {
@@ -231,7 +229,6 @@ mod tests {
231 assert_eq!(names, HUE_NAMES);229 assert_eq!(names, HUE_NAMES);
232 }230 }
233 231
234- const UNMIGRATED: [&str; 0] = [];
235 const FREE: [&str; 2] = ["gui/style.rs", "gui/parts.rs"];232 const FREE: [&str; 2] = ["gui/style.rs", "gui/parts.rs"];
236 233
237 fn sources(dir: &std::path::Path, out: &mut Vec<std::path::PathBuf>) {234 fn sources(dir: &std::path::Path, out: &mut Vec<std::path::PathBuf>) {
@@ -279,7 +276,7 @@ mod tests {
279 .expect("under src")276 .expect("under src")
280 .to_string_lossy()277 .to_string_lossy()
281 .replace('\\', "/");278 .replace('\\', "/");
282- if FREE.contains(&name.as_str()) || UNMIGRATED.contains(&name.as_str()) {279+ if FREE.contains(&name.as_str()) {
283 continue;280 continue;
284 }281 }
285 let content = std::fs::read_to_string(&file).expect("read source");282 let content = std::fs::read_to_string(&file).expect("read source");
crates/client/src/gui/tow.rsmodified+45 -44
@@ -110,6 +110,13 @@ pub fn scene(rig: &Rig, progress: f32, turkish: bool, time: f32) -> Scene {
110 }110 }
111 }111 }
112 112
113+#[derive(PartialEq)]
114+enum Stage {
115+ Reach,
116+ Pull,
117+ Return,
118+}
119+
113 struct Beat {120 struct Beat {
114 out: f32,121 out: f32,
115 back: f32,122 back: f32,
@@ -117,14 +124,20 @@ struct Beat {
117 lift: f32,124 lift: f32,
118 settle: f32,125 settle: f32,
119 ahead: f32,126 ahead: f32,
120- pulling: bool,127+ stage: Stage,
121- reaching: bool,
122 }128 }
123 129
124 impl Beat {130 impl Beat {
125 fn new(progress: f32) -> Self {131 fn new(progress: f32) -> Self {
126 let v = ease(0., 1., progress);132 let v = ease(0., 1., progress);
127 let pull = clamp(0.32, 0.78, v);133 let pull = clamp(0.32, 0.78, v);
134+ let stage = if v < 0.32 {
135+ Stage::Reach
136+ } else if v < 0.78 {
137+ Stage::Pull
138+ } else {
139+ Stage::Return
140+ };
128 Beat {141 Beat {
129 out: ease(0., 0.3, v),142 out: ease(0., 0.3, v),
130 back: ease(0.78, 1., v),143 back: ease(0.78, 1., v),
@@ -132,13 +145,12 @@ impl Beat {
132 lift: heave(0.18, 0.82, pull),145 lift: heave(0.18, 0.82, pull),
133 settle: clamp(0.82, 1., pull),146 settle: clamp(0.82, 1., pull),
134 ahead: heave(0.18, 0.82, pull + 0.02).min(1.),147 ahead: heave(0.18, 0.82, pull + 0.02).min(1.),
135- pulling: (0.32..0.78).contains(&v),148+ stage,
136- reaching: v < 0.32,
137 }149 }
138 }150 }
139 151
140 fn amp(&self, grown: f32) -> f32 {152 fn amp(&self, grown: f32) -> f32 {
141- if self.pulling {153+ if self.stage == Stage::Pull {
142 45. * (1. - self.slack)154 45. * (1. - self.slack)
143 } else {155 } else {
144 80. * (PI * grown).sin()156 80. * (PI * grown).sin()
@@ -150,37 +162,34 @@ impl Beat {
150 }162 }
151 }163 }
152 164
165+fn pull_speed(beat: &Beat, anchor: Point, path: impl Fn(f32) -> Point) -> f32 {
166+ if beat.stage == Stage::Pull {
167+ (path(beat.ahead)[0] - anchor[0]) / 0.02 / 3000.
168+ } else {
169+ 0.
170+ }
171+}
172+
153 fn over(rig: &Rig, beat: &Beat, time: f32) -> (Vec<Point>, Vec<Point>, Vec<Point>) {173 fn over(rig: &Rig, beat: &Beat, time: f32) -> (Vec<Point>, Vec<Point>, Vec<Point>) {
154 let top = [H_X + STEM, H_TOP];174 let top = [H_X + STEM, H_TOP];
155 let grab = [S_X + 380., 140.];175 let grab = [S_X + 380., 140.];
156 let load = |t: f32| cubic(&[grab, [H_X + 54., 150.], [H_X + STEM, -200.], top], t);176 let load = |t: f32| cubic(&[grab, [H_X + 54., 150.], [H_X + STEM, -200.], top], t);
157 let bounce = 0.06 * (beat.settle * PI * 2.).sin() * (1. - beat.settle);177 let bounce = 0.06 * (beat.settle * PI * 2.).sin() * (1. - beat.settle);
158- let t = if beat.reaching {178+ let t = match beat.stage {
159- 0.179+ Stage::Reach => 0.,
160- } else if beat.pulling {180+ Stage::Pull if beat.settle > 0. => 1. - bounce,
161- if beat.settle > 0. {181+ Stage::Pull => beat.lift,
162- 1. - bounce182+ Stage::Return => 1.,
163- } else {
164- beat.lift
165- }
166- } else {
167- 1.
168 };183 };
169 let anchor = load(t);184 let anchor = load(t);
170- let speed = if beat.pulling {185+ let speed = pull_speed(beat, anchor, load);
171- (load(beat.ahead)[0] - anchor[0]) / 0.02 / 3000.186+ let (curl, grown) = match beat.stage {
172- } else {187+ Stage::Reach => (ease(0., 0.45, beat.out), ease(0.35, 1., beat.out)),
173- 0.188+ Stage::Pull => (1., 1.),
174- };189+ Stage::Return => (
175- let (curl, grown) = if beat.reaching {
176- (ease(0., 0.45, beat.out), ease(0.35, 1., beat.out))
177- } else if beat.pulling {
178- (1., 1.)
179- } else {
180- (
181 1. - ease(0.55, 1., beat.back),190 1. - ease(0.55, 1., beat.back),
182 1. - ease(0., 0.6, beat.back),191 1. - ease(0., 0.6, beat.back),
183- )192+ ),
184 };193 };
185 let [first, low] = rig.strand();194 let [first, low] = rig.strand();
186 let looped = [195 let looped = [
@@ -222,29 +231,21 @@ fn under(rig: &Rig, beat: &Beat, time: f32) -> (Vec<Point>, Vec<Point>, Vec<Poin
222 let foot = [H_X + STEM, 0.];231 let foot = [H_X + STEM, 0.];
223 let grab = [S_X + 380., 140.];232 let grab = [S_X + 380., 140.];
224 let drop = |t: f32| cubic(&[foot, [H_X + STEM, 130.], [S_X + 495., 170.], grab], t);233 let drop = |t: f32| cubic(&[foot, [H_X + STEM, 130.], [S_X + 495., 170.], grab], t);
225- let t = if beat.reaching {234+ let t = match beat.stage {
226- 0.235+ Stage::Reach => 0.,
227- } else if beat.pulling {236+ Stage::Pull => beat.lift,
228- beat.lift237+ Stage::Return => 1.,
229- } else {
230- 1.
231 };238 };
232 let anchor = drop(t);239 let anchor = drop(t);
233- let speed = if beat.pulling {240+ let speed = pull_speed(beat, anchor, drop);
234- (drop(beat.ahead)[0] - anchor[0]) / 0.02 / 3000.
235- } else {
236- 0.
237- };
238 let mut segments = rig.strand().to_vec();241 let mut segments = rig.strand().to_vec();
239 segments.extend(rig.below(anchor));242 segments.extend(rig.below(anchor));
240 let route = Route::new(&segments);243 let route = Route::new(&segments);
241 let rest = route.marks[1];244 let rest = route.marks[1];
242- let grown = if beat.reaching {245+ let grown = match beat.stage {
243- beat.out246+ Stage::Reach => beat.out,
244- } else if beat.pulling {247+ Stage::Pull => 1.,
245- 1.248+ Stage::Return => 1. - beat.back,
246- } else {
247- 1. - beat.back
248 };249 };
249 let thread = route.wave(250 let thread = route.wave(
250 rest + (route.end() - rest) * grown,251 rest + (route.end() - rest) * grown,
crates/client/src/gui/update_view.rsmodified+10 -18
@@ -3,8 +3,8 @@ use crate::update::Phase;
3 use gpui_kit::{AnyElement, IntoElement, ParentElement, Styled, div, px};3 use gpui_kit::{AnyElement, IntoElement, ParentElement, Styled, div, px};
4 4
5 use super::{5 use super::{
6- Palette, Yumush, parts,6+ Yumush, parts,
7- style::{size, space, text},7+ style::{Tokens, size, space, text},
8 };8 };
9 9
10 fn percent(fraction: f32) -> String {10 fn percent(fraction: f32) -> String {
@@ -21,16 +21,15 @@ fn status(phase: Phase) -> &'static str {
21 }21 }
22 22
23 impl Yumush {23 impl Yumush {
24- pub(super) fn update_control(&self, palette: Palette) -> Option<AnyElement> {24+ pub(super) fn update_control(&self, t: Tokens) -> Option<AnyElement> {
25 if self.update.required() {25 if self.update.required() {
26 return None;26 return None;
27 }27 }
28- let t = palette.tokens;28+ let (label, action): (&str, fn()) = match self.update {
29- let (label, restart) = match self.update {
30 Phase::Idle => return None,29 Phase::Idle => return None,
31- Phase::Available(_) => (w().update.update, false),30+ Phase::Available(_) => (w().update.update, crate::update::install),
32- Phase::Ready(_) => (w().update.restart, true),31+ Phase::Ready(_) => (w().update.restart, crate::update::restart),
33- Phase::Failed(_) => (w().update.retry, false),32+ Phase::Failed(_) => (w().update.retry, crate::update::install),
34 Phase::Downloading { .. } | Phase::Installing { .. } => {33 Phase::Downloading { .. } | Phase::Installing { .. } => {
35 let fraction = self.update.progress().unwrap_or_default();34 let fraction = self.update.progress().unwrap_or_default();
36 return Some(35 return Some(
@@ -43,7 +42,7 @@ impl Yumush {
43 .flex()42 .flex()
44 .justify_between()43 .justify_between()
45 .text_size(t.text(text::CAPTION))44 .text_size(t.text(text::CAPTION))
46- .text_color(palette.muted)45+ .text_color(t.dim())
47 .child(status(self.update))46 .child(status(self.update))
48 .child(percent(fraction)),47 .child(percent(fraction)),
49 )48 )
@@ -58,20 +57,13 @@ impl Yumush {
58 label,57 label,
59 parts::Press::Plain,58 parts::Press::Plain,
60 t,59 t,
61- move |_, _| {60+ move |_, _| action(),
62- if restart {
63- crate::update::restart();
64- } else {
65- crate::update::install();
66- }
67- },
68 )61 )
69 .into_any_element(),62 .into_any_element(),
70 )63 )
71 }64 }
72 65
73- pub(super) fn update_required(&self, palette: Palette) -> impl IntoElement {66+ pub(super) fn update_required(&self, t: Tokens) -> impl IntoElement {
74- let t = palette.tokens;
75 let status = status(self.update);67 let status = status(self.update);
76 let label = match self.update.progress() {68 let label = match self.update.progress() {
77 Some(fraction) => format!("{status} {}", percent(fraction)),69 Some(fraction) => format!("{status} {}", percent(fraction)),
crates/client/src/gui/voice_note.rsmodified+41 -33
@@ -12,17 +12,19 @@ use gpui_kit::{
12 Task, Window,12 Task, Window,
13 assets::IconName,13 assets::IconName,
14 component::{Icon, WindowExt, notification::Notification},14 component::{Icon, WindowExt, notification::Notification},
15- div, px,15+ div,
16+ prelude::FluentBuilder as _,
17+ px,
16 };18 };
17 use rtrb::{Consumer, RingBuffer};19 use rtrb::{Consumer, RingBuffer};
18 20
19 use super::{21 use super::{
20- Palette, Tooltip as _, Yumush,22+ Tooltip as _, Yumush,
21 chat::VoiceState,23 chat::VoiceState,
22 clickable,24 clickable,
23- media_view::{time_text, upload_file},25+ media_view::time_text,
24 notify_error, parts,26 notify_error, parts,
25- style::{self, radius, size, space},27+ style::{self, Tokens, radius, size, space},
26 text,28 text,
27 widget::ok_or_notify,29 widget::ok_or_notify,
28 };30 };
@@ -68,7 +70,8 @@ fn drain(consumer: &mut Consumer<f32>, samples: &mut Vec<f32>) {
68 pub fn bars(70 pub fn bars(
69 levels: &[f32],71 levels: &[f32],
70 progress: f32,72 progress: f32,
71- palette: Palette,73+ t: Tokens,
74+ scrub: bool,
72 on_pick: impl Fn(usize, &mut Window, &mut App) + 'static,75 on_pick: impl Fn(usize, &mut Window, &mut App) + 'static,
73 ) -> Div {76 ) -> Div {
74 let on_pick = Rc::new(on_pick);77 let on_pick = Rc::new(on_pick);
@@ -85,9 +88,9 @@ pub fn bars(
85 .copied()88 .copied()
86 .unwrap_or(0.);89 .unwrap_or(0.);
87 let color = if (index as f32) < progress * BARS as f32 {90 let color = if (index as f32) < progress * BARS as f32 {
88- palette.accent91+ t.paper()
89 } else {92 } else {
90- palette.muted93+ t.dim()
91 };94 };
92 let (down, drag) = (on_pick.clone(), on_pick.clone());95 let (down, drag) = (on_pick.clone(), on_pick.clone());
93 div()96 div()
@@ -99,10 +102,12 @@ pub fn bars(
99 .on_mouse_down(MouseButton::Left, move |_, window, cx| {102 .on_mouse_down(MouseButton::Left, move |_, window, cx| {
100 down(index, window, cx)103 down(index, window, cx)
101 })104 })
102- .on_mouse_move(move |event, window, cx| {105+ .when(scrub, |slot| {
103- if event.pressed_button == Some(MouseButton::Left) {106+ slot.on_mouse_move(move |event, window, cx| {
104- drag(index, window, cx);107+ if event.pressed_button == Some(MouseButton::Left) {
105- }108+ drag(index, window, cx);
109+ }
110+ })
106 })111 })
107 .child(112 .child(
108 div()113 div()
@@ -118,7 +123,7 @@ pub fn recording_row(
118 started: Instant,123 started: Instant,
119 levels: &[f32],124 levels: &[f32],
120 entity: &Entity<Yumush>,125 entity: &Entity<Yumush>,
121- palette: Palette,126+ t: Tokens,
122 ) -> impl IntoElement {127 ) -> impl IntoElement {
123 let cancel = entity.clone();128 let cancel = entity.clone();
124 let send = entity.clone();129 let send = entity.clone();
@@ -132,9 +137,9 @@ pub fn recording_row(
132 .items_center()137 .items_center()
133 .gap(px(space::SM))138 .gap(px(space::SM))
134 .rounded(px(radius::MD))139 .rounded(px(radius::MD))
135- .bg(palette.field)140+ .bg(t.raise())
136 .child(141 .child(
137- clickable("cancel_voice_note", palette, move |_, cx| {142+ clickable("cancel_voice_note", t, move |_, cx| {
138 cancel.update(cx, |yumush, cx| yumush.cancel_voice_note(cx))143 cancel.update(cx, |yumush, cx| yumush.cancel_voice_note(cx))
139 })144 })
140 .tip(w().voice_note.cancel)145 .tip(w().voice_note.cancel)
@@ -143,7 +148,7 @@ pub fn recording_row(
143 .items_center()148 .items_center()
144 .justify_center()149 .justify_center()
145 .rounded(px(radius::MD))150 .rounded(px(radius::MD))
146- .text_color(palette.muted)151+ .text_color(t.dim())
147 .child(Icon::new(IconName::X).size(px(size::ICON))),152 .child(Icon::new(IconName::X).size(px(size::ICON))),
148 )153 )
149 .child(154 .child(
@@ -153,17 +158,17 @@ pub fn recording_row(
153 .items_center()158 .items_center()
154 .gap(px(space::SM))159 .gap(px(space::SM))
155 .text_size(text(style::text::LABEL))160 .text_size(text(style::text::LABEL))
156- .text_color(palette.text)161+ .text_color(t.paper())
157 .child(super::parts::small_icon(IconName::Mic))162 .child(super::parts::small_icon(IconName::Mic))
158 .child(time_text(163 .child(time_text(
159 started164 started
160 .elapsed()165 .elapsed()
161 .min(Duration::from_secs(MAX_SECONDS as u64)),166 .min(Duration::from_secs(MAX_SECONDS as u64)),
162 ))167 ))
163- .child(bars(levels, 1., palette, |_, _, _| {})),168+ .child(bars(levels, 1., t, false, |_, _, _| {})),
164 )169 )
165 .child(170 .child(
166- parts::pill("send_voice_note", palette.tokens, move |window, cx| {171+ parts::pill("send_voice_note", t, move |window, cx| {
167 send.update(cx, |yumush, cx| yumush.send_voice_note(window, cx))172 send.update(cx, |yumush, cx| yumush.send_voice_note(window, cx))
168 })173 })
169 .tip(w().voice_note.send)174 .tip(w().voice_note.send)
@@ -173,10 +178,10 @@ pub fn recording_row(
173 )178 )
174 }179 }
175 180
176-pub fn mic_button(entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement {181+pub fn mic_button(entity: &Entity<Yumush>, t: Tokens) -> impl IntoElement {
177 let entity = entity.clone();182 let entity = entity.clone();
178 183
179- clickable("voice_note_button", palette, move |window, cx| {184+ clickable("voice_note_button", t, move |window, cx| {
180 entity.update(cx, |yumush, cx| yumush.start_voice_note(window, cx))185 entity.update(cx, |yumush, cx| yumush.start_voice_note(window, cx))
181 })186 })
182 .tip(w().voice_note.voice_message)187 .tip(w().voice_note.voice_message)
@@ -185,13 +190,13 @@ pub fn mic_button(entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement
185 .items_center()190 .items_center()
186 .justify_center()191 .justify_center()
187 .rounded(px(radius::MD))192 .rounded(px(radius::MD))
188- .text_color(palette.muted)193+ .text_color(t.dim())
189 .child(Icon::new(IconName::Mic).size(px(size::ICON)))194 .child(Icon::new(IconName::Mic).size(px(size::ICON)))
190 }195 }
191 196
192 impl Yumush {197 impl Yumush {
193 fn start_voice_note(&mut self, window: &mut Window, cx: &mut Context<Self>) {198 fn start_voice_note(&mut self, window: &mut Window, cx: &mut Context<Self>) {
194- if !matches!(self.chat.voice_state, VoiceState::Off) {199+ if !matches!(self.chat.session.voice_state, VoiceState::Off) {
195 window.push_notification(Notification::error(w().voice_note.leave_call_first), cx);200 window.push_notification(Notification::error(w().voice_note.leave_call_first), cx);
196 return;201 return;
197 }202 }
@@ -211,7 +216,7 @@ impl Yumush {
211 }216 }
212 }217 }
213 });218 });
214- self.chat.media.voice_note = VoiceNote::Recording {219+ self.chat.session.media.voice_note = VoiceNote::Recording {
215 started: Instant::now(),220 started: Instant::now(),
216 _audio: audio,221 _audio: audio,
217 consumer,222 consumer,
@@ -223,12 +228,15 @@ impl Yumush {
223 }228 }
224 229
225 fn tick_voice_note(&mut self, cx: &mut Context<Self>) {230 fn tick_voice_note(&mut self, cx: &mut Context<Self>) {
231+ if !matches!(self.chat.session.voice_state, VoiceState::Off) {
232+ self.chat.session.media.voice_note = VoiceNote::Idle;
233+ }
226 if let VoiceNote::Recording {234 if let VoiceNote::Recording {
227 consumer,235 consumer,
228 samples,236 samples,
229 levels,237 levels,
230 ..238 ..
231- } = &mut self.chat.media.voice_note239+ } = &mut self.chat.session.media.voice_note
232 {240 {
233 let start = samples.len();241 let start = samples.len();
234 drain(consumer, samples);242 drain(consumer, samples);
@@ -241,7 +249,7 @@ impl Yumush {
241 }249 }
242 250
243 fn cancel_voice_note(&mut self, cx: &mut Context<Self>) {251 fn cancel_voice_note(&mut self, cx: &mut Context<Self>) {
244- self.chat.media.voice_note = VoiceNote::Idle;252+ self.chat.session.media.voice_note = VoiceNote::Idle;
245 cx.notify();253 cx.notify();
246 }254 }
247 255
@@ -250,19 +258,15 @@ impl Yumush {
250 mut consumer,258 mut consumer,
251 mut samples,259 mut samples,
252 ..260 ..
253- } = std::mem::take(&mut self.chat.media.voice_note)261+ } = std::mem::take(&mut self.chat.session.media.voice_note)
254 else {262 else {
255 return;263 return;
256 };264 };
257 drain(&mut consumer, &mut samples);265 drain(&mut consumer, &mut samples);
258- let Some(community_id) = self.chat.selected_community_id else {266+ let Some(community_id) = self.chat.session.selected_community_id else {
259 return;267 return;
260 };268 };
261 let network = self.network.clone();269 let network = self.network.clone();
262- let maximum = self
263- .server
264- .as_ref()
265- .map(|settings| settings.max_attachment_bytes);
266 cx.notify();270 cx.notify();
267 271
268 let order = self.send_order.clone();272 let order = self.send_order.clone();
@@ -274,8 +278,12 @@ impl Yumush {
274 else {278 else {
275 return;279 return;
276 };280 };
277- let uploaded =281+ let Ok(upload) = this.update(cx, |yumush, cx| {
278- upload_file(&this, &network, community_id, path.clone(), maximum, cx).await;282+ yumush.upload(community_id, path.clone(), cx)
283+ }) else {
284+ return;
285+ };
286+ let uploaded = upload.await;
279 let _ = std::fs::remove_file(&path);287 let _ = std::fs::remove_file(&path);
280 let attachment = match uploaded {288 let attachment = match uploaded {
281 Ok(attachment) => attachment,289 Ok(attachment) => attachment,
crates/client/src/gui/voice_settings.rsmodified+152 -218

Diff too large; view file

@@ -1,33 +1,34 @@
1 use std::time::Duration;1 use std::time::Duration;
2 2
3 use gpui_kit::{3 use gpui_kit::{
4- Anchor, App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, KeyDownEvent,4+ Anchor, AnyElement, App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement,
5- KeyUpEvent, Keystroke, ModifiersChangedEvent, MouseButton, ParentElement, SharedString,5+ KeyDownEvent, KeyUpEvent, Keystroke, ModifiersChangedEvent, MouseButton, ParentElement,
6- Stateful, Styled, Subscription, Task, Window,6+ SharedString, Stateful, Styled, Subscription, Task, Window,
7 assets::IconName,7 assets::IconName,
8 component::{8 component::{
9- IndexPath,
10 kbd::Kbd,9 kbd::Kbd,
11 popover::Popover,10 popover::Popover,
12- searchable_list::{SearchableListItem, SearchableVec},
13- select::{Select, SelectEvent, SelectState},
14 slider::{SliderEvent, SliderState},11 slider::{SliderEvent, SliderState},
15 },12 },
16 div, px, relative,13 div, px, relative,
17 };14 };
18 15
19 use super::{16 use super::{
20- Palette, Tooltip as _, Trigger, Yumush, clickable,17+ Tooltip as _, Trigger, Yumush, clickable,
21 settings_page::{row, segmented},18 settings_page::{row, segmented},
22- style::{radius, size, space},19+ style::{Tokens, radius, size, space},
23 };20 };
24 use crate::{21 use crate::{
25 lang::w,22 lang::w,
26 settings::{Activation, Profile, SENSITIVITY_DB, VOLUME, VoiceSettings},23 settings::{Activation, Profile, SENSITIVITY_DB, VOLUME, VoiceSettings},
27- voice::audio::{self, Device, Devices},24+ voice::{
25+ self, Sound,
26+ audio::{self, Device, Devices},
27+ },
28 };28 };
29 29
30 const LEVEL_INTERVAL: Duration = Duration::from_millis(50);30 const LEVEL_INTERVAL: Duration = Duration::from_millis(50);
31+
31 pub(super) fn modes() -> [(Activation, &'static str); 2] {32 pub(super) fn modes() -> [(Activation, &'static str); 2] {
32 [33 [
33 (Activation::VoiceActivity, w().voice_settings.voice_activity),34 (Activation::VoiceActivity, w().voice_settings.voice_activity),
@@ -52,7 +53,6 @@ pub(super) enum Side {
52 pub(super) enum MicTest {53 pub(super) enum MicTest {
53 Off,54 Off,
54 On,55 On,
55- MutingCall,
56 }56 }
57 57
58 #[derive(Clone, Copy, PartialEq, Eq)]58 #[derive(Clone, Copy, PartialEq, Eq)]
@@ -76,28 +76,12 @@ impl DeviceItem {
76 }76 }
77 }77 }
78 78
79-impl SearchableListItem for DeviceItem {
80- type Value = Option<String>;
81-
82- fn title(&self) -> SharedString {
83- self.name.clone()
84- }
85-
86- fn value(&self) -> &Option<String> {
87- &self.id
88- }
89-}
90-
91-type DeviceList = SearchableVec<DeviceItem>;
92-
93 pub(super) struct VoiceControls {79 pub(super) struct VoiceControls {
94- pub(super) inputs: Entity<SelectState<DeviceList>>,
95- pub(super) outputs: Entity<SelectState<DeviceList>>,
96 pub(super) sensitivity: Entity<SliderState>,80 pub(super) sensitivity: Entity<SliderState>,
97 pub(super) input_volume: Entity<SliderState>,81 pub(super) input_volume: Entity<SliderState>,
98 pub(super) output_volume: Entity<SliderState>,82 pub(super) output_volume: Entity<SliderState>,
99- pub(super) input_items: Vec<DeviceItem>,83+ pub(super) inputs: Vec<DeviceItem>,
100- pub(super) output_items: Vec<DeviceItem>,84+ pub(super) outputs: Vec<DeviceItem>,
101 pub(super) mic_test: MicTest,85 pub(super) mic_test: MicTest,
102 pub(super) key: KeyCapture,86 pub(super) key: KeyCapture,
103 level_poll: Option<Task<()>>,87 level_poll: Option<Task<()>>,
@@ -105,28 +89,12 @@ pub(super) struct VoiceControls {
105 }89 }
106 90
107 impl VoiceControls {91 impl VoiceControls {
108- pub(super) fn new(92+ pub(super) fn new(settings: &VoiceSettings, cx: &mut Context<Yumush>) -> Self {
109- settings: &VoiceSettings,
110- window: &mut Window,
111- cx: &mut Context<Yumush>,
112- ) -> Self {
113- let inputs = device_select(window, cx);
114- let outputs = device_select(window, cx);
115 let sensitivity = slider(&SENSITIVITY_DB, settings.sensitivity_db, cx);93 let sensitivity = slider(&SENSITIVITY_DB, settings.sensitivity_db, cx);
116 let input_volume = slider(&VOLUME, settings.input_volume, cx);94 let input_volume = slider(&VOLUME, settings.input_volume, cx);
117 let output_volume = slider(&VOLUME, settings.output_volume, cx);95 let output_volume = slider(&VOLUME, settings.output_volume, cx);
118 96
119 let subscriptions = vec![97 let subscriptions = vec![
120- cx.subscribe(&inputs, |this, _, event: &SelectEvent<DeviceList>, cx| {
121- if let SelectEvent::Confirm(Some(id)) = event {
122- this.set_voice_device(Side::Input, id.clone(), cx);
123- }
124- }),
125- cx.subscribe(&outputs, |this, _, event: &SelectEvent<DeviceList>, cx| {
126- if let SelectEvent::Confirm(Some(id)) = event {
127- this.set_voice_device(Side::Output, id.clone(), cx);
128- }
129- }),
130 cx.subscribe(&sensitivity, |this, _, event: &SliderEvent, cx| {98 cx.subscribe(&sensitivity, |this, _, event: &SliderEvent, cx| {
131 this.slider_changed(event, |voice, value| voice.sensitivity_db = value, cx);99 this.slider_changed(event, |voice, value| voice.sensitivity_db = value, cx);
132 }),100 }),
@@ -139,13 +107,11 @@ impl VoiceControls {
139 ];107 ];
140 108
141 Self {109 Self {
142- inputs,
143- outputs,
144 sensitivity,110 sensitivity,
145 input_volume,111 input_volume,
146 output_volume,112 output_volume,
147- input_items: vec![DeviceItem::default_choice()],113+ inputs: vec![DeviceItem::default_choice()],
148- output_items: vec![DeviceItem::default_choice()],114+ outputs: vec![DeviceItem::default_choice()],
149 mic_test: MicTest::Off,115 mic_test: MicTest::Off,
150 key: KeyCapture::Idle,116 key: KeyCapture::Idle,
151 level_poll: None,117 level_poll: None,
@@ -154,17 +120,6 @@ impl VoiceControls {
154 }120 }
155 }121 }
156 122
157-fn device_select(window: &mut Window, cx: &mut Context<Yumush>) -> Entity<SelectState<DeviceList>> {
158- cx.new(|cx| {
159- SelectState::new(
160- SearchableVec::new(vec![DeviceItem::default_choice()]),
161- Some(IndexPath::new(0)),
162- window,
163- cx,
164- )
165- })
166-}
167-
168 fn slider(123 fn slider(
169 range: &std::ops::RangeInclusive<f32>,124 range: &std::ops::RangeInclusive<f32>,
170 value: f32,125 value: f32,
@@ -193,7 +148,47 @@ fn device_list(devices: Vec<Device>) -> Vec<DeviceItem> {
193 items148 items
194 }149 }
195 150
196-fn volume_control(state: &Entity<SliderState>, value: f32, palette: Palette) -> Div {151+fn device_rows(entity: &Entity<Yumush>, yumush: &Yumush, side: Side, t: Tokens) -> Vec<AnyElement> {
152+ let (items, chosen) = match side {
153+ Side::Input => (&yumush.voice.inputs, &yumush.settings.voice.choice.input),
154+ Side::Output => (&yumush.voice.outputs, &yumush.settings.voice.choice.output),
155+ };
156+ let chosen = in_use(items, chosen);
157+ items
158+ .iter()
159+ .enumerate()
160+ .map(|(index, item)| {
161+ let entity = entity.clone();
162+ let id = item.id.clone();
163+ super::share_view::row_style(clickable(
164+ SharedString::from(format!("audio_device_{index}")),
165+ t,
166+ move |_, cx| {
167+ let id = id.clone();
168+ entity.update(cx, |yumush, cx| yumush.set_voice_device(side, id, cx));
169+ },
170+ ))
171+ .child(div().flex_1().min_w_0().truncate().child(item.name.clone()))
172+ .children((item.id == chosen).then(|| {
173+ super::parts::small_icon(IconName::Check)
174+ .flex_shrink_0()
175+ .text_color(t.paper())
176+ }))
177+ .into_any_element()
178+ })
179+ .collect()
180+}
181+
182+fn percent(value: f32, t: Tokens) -> Div {
183+ div()
184+ .w(px(size::ROW))
185+ .flex_none()
186+ .text_right()
187+ .text_color(t.dim())
188+ .child(format!("{value:.0}%"))
189+}
190+
191+fn volume_control(state: &Entity<SliderState>, value: f32, t: Tokens) -> Div {
197 div()192 div()
198 .flex()193 .flex()
199 .items_center()194 .items_center()
@@ -201,18 +196,12 @@ fn volume_control(state: &Entity<SliderState>, value: f32, palette: Palette) ->
201 .child(196 .child(
202 div()197 div()
203 .w(px(size::THUMB))198 .w(px(size::THUMB))
204- .child(super::parts::slider(state, palette.tokens)),199+ .child(super::parts::slider(state, t)),
205- )
206- .child(
207- div()
208- .w(px(size::ROW))
209- .text_right()
210- .text_color(palette.muted)
211- .child(format!("{value:.0}%")),
212 )200 )
201+ .child(percent(value, t))
213 }202 }
214 203
215-fn level_bar(level: Option<f32>, threshold: f32, hue: gpui_kit::Hsla, palette: Palette) -> Div {204+fn level_bar(level: Option<f32>, threshold: f32, hue: gpui_kit::Hsla, t: Tokens) -> Div {
216 let range = SENSITIVITY_DB;205 let range = SENSITIVITY_DB;
217 let fraction = level.map_or(0.0, |db| {206 let fraction = level.map_or(0.0, |db| {
218 ((db - range.start()) / (range.end() - range.start())).clamp(0.0, 1.0)207 ((db - range.start()) / (range.end() - range.start())).clamp(0.0, 1.0)
@@ -220,14 +209,14 @@ fn level_bar(level: Option<f32>, threshold: f32, hue: gpui_kit::Hsla, palette: P
220 let color = if level.is_some_and(|db| db >= threshold) {209 let color = if level.is_some_and(|db| db >= threshold) {
221 hue210 hue
222 } else {211 } else {
223- palette.muted212+ t.dim()
224 };213 };
225 214
226 div()215 div()
227 .h(px(space::XS))216 .h(px(space::XS))
228 .w_full()217 .w_full()
229 .rounded(px(radius::SM))218 .rounded(px(radius::SM))
230- .bg(palette.border)219+ .bg(t.thread())
231 .child(220 .child(
232 div()221 div()
233 .h_full()222 .h_full()
@@ -238,38 +227,30 @@ fn level_bar(level: Option<f32>, threshold: f32, hue: gpui_kit::Hsla, palette: P
238 }227 }
239 228
240 impl Yumush {229 impl Yumush {
241- pub(super) fn voice_rows(&self, entity: &Entity<Self>, palette: Palette, cx: &App) -> Vec<Div> {230+ pub(super) fn voice_rows(&self, entity: &Entity<Self>, t: Tokens, cx: &App) -> Vec<Div> {
242 let voice = &self.settings.voice;231 let voice = &self.settings.voice;
243 let controls = &self.voice;232 let controls = &self.voice;
244 233
245 let mut rows = vec![234 let mut rows = vec![
246 row(235 row(
247 w().voice_settings.input_device,236 w().voice_settings.input_device,
248- super::widget::underline(palette, Select::new(&controls.inputs).appearance(false))237+ self.device_column(entity, Side::Input, t),
249- .w(px(size::SIDEBAR)),
250 ),238 ),
251 row(239 row(
252 w().voice_settings.output_device,240 w().voice_settings.output_device,
253- super::widget::underline(palette, Select::new(&controls.outputs).appearance(false))241+ self.device_column(entity, Side::Output, t),
254- .w(px(size::SIDEBAR)),
255 ),242 ),
256 row(243 row(
257 w().voice_settings.input_volume,244 w().voice_settings.input_volume,
258- volume_control(&controls.input_volume, voice.input_volume, palette),245+ volume_control(&controls.input_volume, voice.input_volume, t),
259 ),246 ),
260 row(247 row(
261 w().voice_settings.output_volume,248 w().voice_settings.output_volume,
262- volume_control(&controls.output_volume, voice.output_volume, palette),249+ volume_control(&controls.output_volume, voice.output_volume, t),
263 ),250 ),
264 row(251 row(
265 w().voice_settings.mode,252 w().voice_settings.mode,
266- segmented(253+ segmented(modes(), voice.activation, entity, t, Yumush::set_voice_mode),
267- modes(),
268- voice.activation,
269- entity,
270- palette,
271- Yumush::set_voice_mode,
272- ),
273 ),254 ),
274 row(255 row(
275 w().voice_settings.profile,256 w().voice_settings.profile,
@@ -277,32 +258,39 @@ impl Yumush {
277 profiles(),258 profiles(),
278 voice.profile,259 voice.profile,
279 entity,260 entity,
280- palette,261+ t,
281 Yumush::set_voice_profile,262 Yumush::set_voice_profile,
282 ),263 ),
283 ),264 ),
284 ];265 ];
285 266
286- rows.push(row(267+ if self.chat.voice_flags().is_none() {
287- w().voice_settings.test,268+ rows.push(row(w().voice_settings.test, self.test_control(entity, t)));
288- self.test_control(entity, palette),269+ }
289- ));
290 match voice.activation {270 match voice.activation {
291 Activation::VoiceActivity => rows.push(row(271 Activation::VoiceActivity => rows.push(row(
292 w().voice_settings.sensitivity,272 w().voice_settings.sensitivity,
293- self.sensitivity_control(palette),273+ self.sensitivity_control(t),
294 )),274 )),
295 Activation::PushToTalk => rows.push(row(275 Activation::PushToTalk => rows.push(row(
296 w().voice_settings.key,276 w().voice_settings.key,
297- self.key_control(&voice.push_to_talk_key, entity, palette, cx),277+ self.key_control(&voice.push_to_talk_key, entity, t, cx),
298 )),278 )),
299 }279 }
300 280
301 rows281 rows
302 }282 }
303 283
304- fn test_control(&self, entity: &Entity<Self>, palette: Palette) -> Div {284+ fn device_column(&self, entity: &Entity<Self>, side: Side, t: Tokens) -> Div {
305- let testing = self.voice.mic_test != MicTest::Off;285+ div()
286+ .w(px(size::SIDEBAR))
287+ .flex()
288+ .flex_col()
289+ .children(device_rows(entity, self, side, t))
290+ }
291+
292+ fn test_control(&self, entity: &Entity<Self>, t: Tokens) -> Div {
293+ let testing = self.voice.mic_test == MicTest::On;
306 let mic = entity.clone();294 let mic = entity.clone();
307 let speaker = entity.clone();295 let speaker = entity.clone();
308 296
@@ -311,7 +299,7 @@ impl Yumush {
311 .items_center()299 .items_center()
312 .gap(px(space::SM))300 .gap(px(space::SM))
313 .child(301 .child(
314- test_button("mic_test_button", palette, testing, move |_, cx| {302+ test_button("mic_test_button", t, testing, move |_, cx| {
315 mic.update(cx, |yumush, cx| yumush.toggle_mic_test(cx));303 mic.update(cx, |yumush, cx| yumush.toggle_mic_test(cx));
316 })304 })
317 .child(super::parts::small_icon(IconName::Mic))305 .child(super::parts::small_icon(IconName::Mic))
@@ -322,9 +310,9 @@ impl Yumush {
322 }),310 }),
323 )311 )
324 .child(312 .child(
325- test_button("speaker_test_button", palette, false, move |_, cx| {313+ test_button("speaker_test_button", t, false, move |_, cx| {
326 speaker.update(cx, |yumush, _| {314 speaker.update(cx, |yumush, _| {
327- yumush.network.play_chime(&yumush.settings.voice)315+ voice::play_sound(Sound::Chime, &yumush.settings.voice)
328 });316 });
329 })317 })
330 .child(super::parts::small_icon(IconName::Volume2))318 .child(super::parts::small_icon(IconName::Volume2))
@@ -332,7 +320,7 @@ impl Yumush {
332 )320 )
333 }321 }
334 322
335- fn sensitivity_control(&self, palette: Palette) -> Div {323+ fn sensitivity_control(&self, t: Tokens) -> Div {
336 let level = self.network.voice_level_db();324 let level = self.network.voice_level_db();
337 325
338 div().flex().items_center().gap(px(space::SM)).child(326 div().flex().items_center().gap(px(space::SM)).child(
@@ -341,15 +329,12 @@ impl Yumush {
341 .flex()329 .flex()
342 .flex_col()330 .flex_col()
343 .gap(px(space::SM))331 .gap(px(space::SM))
344- .child(super::parts::slider(332+ .child(super::parts::slider(&self.voice.sensitivity, t))
345- &self.voice.sensitivity,
346- palette.tokens,
347- ))
348 .child(level_bar(333 .child(level_bar(
349 level,334 level,
350 self.settings.voice.sensitivity_db,335 self.settings.voice.sensitivity_db,
351- palette.tokens.hue(super::style::my_hue()),336+ t.hue(super::style::my_hue()),
352- palette,337+ t,
353 )),338 )),
354 )339 )
355 }340 }
@@ -358,7 +343,7 @@ impl Yumush {
358 &self,343 &self,
359 key: &str,344 key: &str,
360 entity: &Entity<Self>,345 entity: &Entity<Self>,
361- palette: Palette,346+ t: Tokens,
362 cx: &App,347 cx: &App,
363 ) -> impl IntoElement {348 ) -> impl IntoElement {
364 let content = match self.voice.key {349 let content = match self.voice.key {
@@ -370,7 +355,7 @@ impl Yumush {
370 };355 };
371 let entity = entity.clone();356 let entity = entity.clone();
372 357
373- clickable("ptt_key_button", palette, move |window, cx| {358+ clickable("ptt_key_button", t, move |window, cx| {
374 entity.update(cx, |yumush, cx| yumush.capture_key(window, cx));359 entity.update(cx, |yumush, cx| yumush.capture_key(window, cx));
375 })360 })
376 .h(px(size::CONTROL_SM))361 .h(px(size::CONTROL_SM))
@@ -436,7 +421,20 @@ impl Yumush {
436 cx.notify();421 cx.notify();
437 }422 }
438 423
439- pub(super) fn voice_key_down(&mut self, event: &KeyDownEvent, cx: &mut Context<Self>) {424+ fn cancel_stale_capture(&mut self, window: &Window, cx: &mut Context<Self>) {
425+ if self.voice.key == KeyCapture::Waiting && !self.focus.is_focused(window) {
426+ self.voice.key = KeyCapture::Idle;
427+ cx.notify();
428+ }
429+ }
430+
431+ pub(super) fn voice_key_down(
432+ &mut self,
433+ event: &KeyDownEvent,
434+ window: &Window,
435+ cx: &mut Context<Self>,
436+ ) {
437+ self.cancel_stale_capture(window, cx);
440 let key = event.keystroke.key.clone();438 let key = event.keystroke.key.clone();
441 439
442 match self.voice.key {440 match self.voice.key {
@@ -466,8 +464,10 @@ impl Yumush {
466 pub(super) fn voice_modifiers(464 pub(super) fn voice_modifiers(
467 &mut self,465 &mut self,
468 event: &ModifiersChangedEvent,466 event: &ModifiersChangedEvent,
467+ window: &Window,
469 cx: &mut Context<Self>,468 cx: &mut Context<Self>,
470 ) {469 ) {
470+ self.cancel_stale_capture(window, cx);
471 let modifiers = event.modifiers;471 let modifiers = event.modifiers;
472 let held = [472 let held = [
473 ("ctrl", modifiers.control),473 ("ctrl", modifiers.control),
@@ -493,16 +493,10 @@ impl Yumush {
493 493
494 pub(super) fn toggle_mic_test(&mut self, cx: &mut Context<Self>) {494 pub(super) fn toggle_mic_test(&mut self, cx: &mut Context<Self>) {
495 match self.voice.mic_test {495 match self.voice.mic_test {
496- MicTest::On | MicTest::MutingCall => self.stop_mic_test(),496+ MicTest::On => self.stop_mic_test(),
497 MicTest::Off => {497 MicTest::Off => {
498 self.network.start_mic_test(&self.settings.voice);498 self.network.start_mic_test(&self.settings.voice);
499- self.voice.mic_test = if self.chat.voice_flags().is_some_and(|(muted, _)| !muted) {499+ self.voice.mic_test = MicTest::On;
500- self.set_call_muted(true);
501- MicTest::MutingCall
502- } else {
503- MicTest::On
504- };
505- self.start_level_poll(cx);
506 }500 }
507 }501 }
508 cx.notify();502 cx.notify();
@@ -510,91 +504,73 @@ impl Yumush {
510 504
511 pub(super) fn stop_mic_test(&mut self) {505 pub(super) fn stop_mic_test(&mut self) {
512 self.network.stop_mic_test();506 self.network.stop_mic_test();
513- if self.voice.mic_test == MicTest::MutingCall {
514- self.set_call_muted(false);
515- }
516 self.voice.mic_test = MicTest::Off;507 self.voice.mic_test = MicTest::Off;
517- self.voice.level_poll = None;
518 }508 }
519 509
520 pub(super) fn leave_settings(&mut self) {510 pub(super) fn leave_settings(&mut self) {
521 self.stop_mic_test();511 self.stop_mic_test();
522 self.voice.key = KeyCapture::Idle;512 self.voice.key = KeyCapture::Idle;
513+ self.voice.level_poll = None;
523 }514 }
524 515
525- pub(super) fn enter_settings(&mut self, window: &mut Window, cx: &mut Context<Self>) {516+ pub(super) fn enter_settings(&mut self, cx: &mut Context<Self>) {
526- self.load_audio_devices(window, cx);517+ self.load_audio_devices(cx);
527 self.measure_storage(cx);518 self.measure_storage(cx);
528- if self.network.voice_level_db().is_some() {519+ self.start_level_poll(cx);
529- self.start_level_poll(cx);
530- }
531 }520 }
532 521
533 fn start_level_poll(&mut self, cx: &mut Context<Self>) {522 fn start_level_poll(&mut self, cx: &mut Context<Self>) {
534 self.voice.level_poll = Some(cx.spawn(async move |this, cx| {523 self.voice.level_poll = Some(cx.spawn(async move |this, cx| {
535 loop {524 loop {
536 cx.background_executor().timer(LEVEL_INTERVAL).await;525 cx.background_executor().timer(LEVEL_INTERVAL).await;
537- let live = this.update(cx, |yumush, cx| {526+ if this.update(cx, |yumush, cx| yumush.tick_level(cx)).is_err() {
538- let live = yumush.network.voice_level_db().is_some();
539- cx.notify();
540- live
541- });
542- if !matches!(live, Ok(true)) {
543 break;527 break;
544 }528 }
545 }529 }
546 }));530 }));
547 }531 }
548 532
549- pub(super) fn load_audio_devices(&self, window: &mut Window, cx: &mut Context<Self>) {533+ fn tick_level(&mut self, cx: &mut Context<Self>) {
550- cx.spawn_in(window, async move |this, cx| {534+ if self.voice.mic_test == MicTest::On && self.chat.voice_flags().is_some() {
535+ self.stop_mic_test();
536+ }
537+ cx.notify();
538+ }
539+
540+ pub(super) fn load_audio_devices(&self, cx: &mut Context<Self>) {
541+ cx.spawn(async move |this, cx| {
551 let devices = cx542 let devices = cx
552 .background_executor()543 .background_executor()
553 .spawn(async { audio::devices() })544 .spawn(async { audio::devices() })
554 .await;545 .await;
555- let _ = this.update_in(cx, |yumush, window, cx| {546+ let _ = this.update(cx, |yumush, cx| yumush.apply_devices(devices, cx));
556- yumush.apply_devices(devices, window, cx);
557- });
558 })547 })
559 .detach();548 .detach();
560 }549 }
561 550
562- fn apply_devices(&mut self, devices: Devices, window: &mut Window, cx: &mut Context<Self>) {551+ fn apply_devices(&mut self, devices: Devices, cx: &mut Context<Self>) {
563- let choice = self.settings.voice.choice.clone();552+ self.voice.inputs = device_list(devices.inputs);
564-553+ self.voice.outputs = device_list(devices.outputs);
565- let inputs = device_list(devices.inputs);554+ cx.notify();
566- let outputs = device_list(devices.outputs);
567- self.voice.input_items = inputs.clone();
568- self.voice.output_items = outputs.clone();
569- self.voice.inputs.update(cx, |state, cx| {
570- let chosen = in_use(&inputs, &choice.input);
571- state.set_items(SearchableVec::new(inputs), window, cx);
572- state.set_selected_value(&chosen, window, cx);
573- });
574- self.voice.outputs.update(cx, |state, cx| {
575- let chosen = in_use(&outputs, &choice.output);
576- state.set_items(SearchableVec::new(outputs), window, cx);
577- state.set_selected_value(&chosen, window, cx);
578- });
579 }555 }
580 }556 }
581 557
582 fn test_button(558 fn test_button(
583 id: &'static str,559 id: &'static str,
584- palette: Palette,560+ t: Tokens,
585 active: bool,561 active: bool,
586 on_click: impl Fn(&mut Window, &mut App) + 'static,562 on_click: impl Fn(&mut Window, &mut App) + 'static,
587 ) -> Stateful<Div> {563 ) -> Stateful<Div> {
588- super::parts::press(id, palette.tokens, on_click)564+ super::parts::press(id, t, on_click)
589 .font_weight(gpui_kit::FontWeight::MEDIUM)565 .font_weight(gpui_kit::FontWeight::MEDIUM)
590- .text_color(if active { palette.text } else { palette.muted })566+ .text_color(if active { t.paper() } else { t.dim() })
591 }567 }
592 568
593 impl Yumush {569 impl Yumush {
594 pub(super) fn audio_button(570 pub(super) fn audio_button(
595 &self,571 &self,
596 entity: &Entity<Self>,572 entity: &Entity<Self>,
597- palette: Palette,573+ t: Tokens,
598 side: Side,574 side: Side,
599 cx: &App,575 cx: &App,
600 ) -> impl IntoElement {576 ) -> impl IntoElement {
@@ -616,63 +592,26 @@ impl Yumush {
616 .anchor(Anchor::BottomRight)592 .anchor(Anchor::BottomRight)
617 .appearance(false)593 .appearance(false)
618 .trigger(Trigger::new(594 .trigger(Trigger::new(
619- super::parts::chevron_face(false, super::style::Tokens::of(cx))595+ super::parts::chevron_face(false, Tokens::of(cx))
620 .id(button)596 .id(button)
621- .on_mouse_down(MouseButton::Left, move |_, window, cx| {597+ .on_mouse_down(MouseButton::Left, move |_, _, cx| {
622- refresh.update(cx, |yumush, cx| yumush.load_audio_devices(window, cx));598+ refresh.update(cx, |yumush, cx| yumush.load_audio_devices(cx));
623 })599 })
624 .tip(tip),600 .tip(tip),
625 ))601 ))
626- .content(move |_, _, cx| audio_card(&content, content.read(cx), side, palette))602+ .content(move |_, _, cx| audio_card(&content, content.read(cx), side, t))
627 }603 }
628 }604 }
629 605
630-fn audio_card(entity: &Entity<Yumush>, yumush: &Yumush, side: Side, palette: Palette) -> Div {606+fn audio_card(entity: &Entity<Yumush>, yumush: &Yumush, side: Side, t: Tokens) -> Div {
631- let t = palette.tokens;
632 let voice = &yumush.settings.voice;607 let voice = &yumush.settings.voice;
633- let controls = &yumush.voice;
634- let (items, chosen, volume, value) = match side {
635- Side::Input => (
crates/client/src/gui/voice_stats.rsmodified+35 -29

Diff too large; view file

crates/client/src/gui/wave.rsmodified+11 -14

Diff too large; view file

crates/client/src/gui/widget.rsmodified+18 -36

Diff too large; view file

crates/client/src/instance.rsmodified+22 -4

Diff too large; view file

crates/client/src/lang.rsmodified+5 -6

Diff too large; view file

crates/client/src/lib.rsmodified+32 -16

Diff too large; view file

crates/client/src/logo.rsmodified+3 -1

Diff too large; view file

crates/client/src/main.rsmodified+5 -2

Diff too large; view file

crates/client/src/media/convert.rsdeleted+0 -4

Diff too large; view file

crates/client/src/media/decode.rsmodified+21 -24

Diff too large; view file

crates/client/src/media/meter.rsmodified+0 -8

Diff too large; view file

crates/client/src/media/mod.rsmodified+11 -14

Diff too large; view file

crates/client/src/net/datagram.rsdeleted+0 -23

Diff too large; view file

crates/client/src/net/events.rsdeleted+0 -40

Diff too large; view file

crates/client/src/net/fetch.rsmodified+1 -1

Diff too large; view file

crates/client/src/net/link.rsmodified+138 -163

Diff too large; view file

crates/client/src/net/media.rsmodified+503 -378

Diff too large; view file

crates/client/src/net/mod.rsmodified+62 -85

Diff too large; view file

crates/client/src/net/receive.rsadded+57 -0

Diff too large; view file

crates/client/src/settings.rsmodified+3 -8

Diff too large; view file

crates/client/src/share/audio_capture.rsmodified+39 -175

Diff too large; view file

crates/client/src/share/audio_capture_windows.rsmodified+7 -29

Diff too large; view file

crates/client/src/share/camera.rsmodified+96 -129

Diff too large; view file

crates/client/src/share/capture.rsmodified+60 -72

Diff too large; view file

crates/client/src/share/capture_windows.rsmodified+47 -69

Diff too large; view file

crates/client/src/share/congestion.rsmodified+20 -18

Diff too large; view file

crates/client/src/share/encode.rsmodified+200 -91

Diff too large; view file

crates/client/src/share/fake.rsmodified+11 -18

Diff too large; view file

crates/client/src/share/frame.rsmodified+39 -4

Diff too large; view file

crates/client/src/share/mod.rsmodified+17 -11

Diff too large; view file

crates/client/src/share/reassembly.rsmodified+47 -43

Diff too large; view file

crates/client/src/share/send.rsadded+537 -0

Diff too large; view file

crates/client/src/share/unsupported.rsmodified+14 -23

Diff too large; view file

crates/client/src/share/session.rs → crates/client/src/share/watch.rsrenamed+87 -651

Diff too large; view file

crates/client/src/tray.rsmodified+10 -24

Diff too large; view file

crates/client/src/update.rsmodified+20 -26

Diff too large; view file

crates/client/src/voice/audio.rsmodified+18 -92

Diff too large; view file

crates/client/src/voice/audio/coreaudio.rsmodified+24 -40

Diff too large; view file

crates/client/src/voice/audio/pipewire.rsmodified+27 -132

Diff too large; view file

crates/client/src/voice/audio/pw.rsadded+154 -0

Diff too large; view file

crates/client/src/voice/audio/wasapi.rsmodified+8 -8

Diff too large; view file

crates/client/src/voice/engine.rsmodified+25 -14

Diff too large; view file

crates/client/src/voice/mod.rsmodified+44 -164

Diff too large; view file

crates/client/src/voice/sound.rsadded+127 -0

Diff too large; view file

crates/client/src/worker.rsadded+86 -0

Diff too large; view file

crates/common/Cargo.tomlmodified+5 -5

Diff too large; view file

crates/common/src/call.rsmodified+21 -21

Diff too large; view file

crates/common/src/datagram.rsmodified+61 -40

Diff too large; view file

crates/common/src/error.rsmodified+3 -0

Diff too large; view file

crates/common/src/frame.rsmodified+1 -1

Diff too large; view file

crates/common/src/model.rsmodified+63 -117

Diff too large; view file

crates/common/src/permission.rsmodified+13 -45

Diff too large; view file

crates/common/src/session.rsmodified+0 -1

Diff too large; view file

crates/common/src/transport.rsmodified+44 -29

Diff too large; view file

crates/common/src/update.rsmodified+37 -32

Diff too large; view file

crates/common/src/validate.rsmodified+14 -8

Diff too large; view file

crates/pixel/src/lib.rsmodified+5 -7

Diff too large; view file

crates/server/Cargo.tomlmodified+10 -10

Diff too large; view file

crates/server/src/authentication.rsmodified+47 -50

Diff too large; view file

crates/server/src/backup.rsmodified+17 -12

Diff too large; view file

crates/server/src/call/admin.rsmodified+114 -131

Diff too large; view file

crates/server/src/call/community.rsmodified+39 -52

Diff too large; view file

crates/server/src/call/message.rsmodified+45 -68

Diff too large; view file

crates/server/src/call/mod.rsmodified+345 -30

Diff too large; view file

crates/server/src/call/release.rsmodified+22 -31

Diff too large; view file

crates/server/src/call/shared.rsadded+311 -0

Diff too large; view file

crates/server/src/call/social.rsmodified+20 -39

Diff too large; view file

crates/server/src/call/stats.rsmodified+6 -5

Diff too large; view file

crates/server/src/call/user.rsmodified+80 -84

Diff too large; view file

crates/server/src/call/voice.rsmodified+73 -71

Diff too large; view file

crates/server/src/certificate.rsmodified+13 -16

Diff too large; view file

crates/server/src/datagram.rsdeleted+0 -18

Diff too large; view file

crates/server/src/db/attachment.rsmodified+24 -23

Diff too large; view file

crates/server/src/db/avatar.rsmodified+17 -30

Diff too large; view file

crates/server/src/db/community.rsmodified+8 -11

Diff too large; view file

crates/server/src/db/direct.rsmodified+11 -1

Diff too large; view file

crates/server/src/db/friend.rsmodified+9 -17

Diff too large; view file

crates/server/src/db/invitation.rsmodified+7 -13

Diff too large; view file

crates/server/src/db/log.rsmodified+16 -27

Diff too large; view file

crates/server/src/db/member.rsmodified+11 -21

Diff too large; view file

crates/server/src/db/message.rsmodified+34 -42

Diff too large; view file

crates/server/src/db/mod.rsmodified+19 -2

Diff too large; view file

crates/server/src/db/registration_code.rsmodified+3 -4

Diff too large; view file

crates/server/src/db/release.rsmodified+4 -19

Diff too large; view file

crates/server/src/db/report.rsmodified+17 -12

Diff too large; view file

crates/server/src/db/server_ban.rsmodified+11 -21

Diff too large; view file

crates/server/src/db/session.rsmodified+8 -16

Diff too large; view file

crates/server/src/db/settings.rsmodified+3 -5

Diff too large; view file

crates/server/src/db/stats.rsmodified+3 -5

Diff too large; view file

crates/server/src/db/user.rsmodified+63 -71

Diff too large; view file

crates/server/src/error.rsmodified+0 -1

Diff too large; view file

crates/server/src/files.rsmodified+23 -20

Diff too large; view file

crates/server/src/forge.rsmodified+22 -28

Diff too large; view file

crates/server/src/hub.rsmodified+9 -29

Diff too large; view file

crates/server/src/lib.rsmodified+12 -20

Diff too large; view file

crates/server/src/main.rsmodified+2 -2

Diff too large; view file

crates/server/src/network.rsmodified+128 -125

Diff too large; view file

crates/server/src/publish.rsmodified+41 -23

Diff too large; view file

crates/server/src/request.rsdeleted+0 -669

Diff too large; view file

crates/server/src/retention.rsmodified+30 -24

Diff too large; view file

crates/server/src/rooms.rsmodified+142 -115

Diff too large; view file

crates/server/src/stats.rsmodified+13 -8

Diff too large; view file

crates/server/src/test.rsmodified+14 -1

Diff too large; view file

crates/server/src/update.rsmodified+162 -109

Diff too large; view file

crates/usage/Cargo.tomlmodified+3 -3

Diff too large; view file

crates/usage/src/drm.rsmodified+53 -49

Diff too large; view file

crates/usage/src/lib.rsmodified+20 -35

Diff too large; view file

crates/usage/src/mac.rsmodified+1 -2

Diff too large; view file

crates/usage/src/nvidia.rsmodified+10 -12

Diff too large; view file

crates/usage/src/threads.rsmodified+13 -13

Diff too large; view file

crates/usage/src/windows.rsmodified+21 -27

Diff too large; view file

harness/audio.shmodified+2 -1

Diff too large; view file

harness/bench.shmodified+4 -8

Diff too large; view file

harness/client.shmodified+2 -3

Diff too large; view file

harness/codec.shmodified+4 -2

Diff too large; view file

harness/compare.shmodified+4 -4

Diff too large; view file

harness/down.shmodified+2 -2

Diff too large; view file

harness/fps.pymodified+2 -0

Diff too large; view file

harness/gallery.shmodified+3 -5

Diff too large; view file

harness/imports.shmodified+1 -1

Diff too large; view file

harness/lib.shadded+10 -0

Diff too large; view file

harness/niri.kdlmodified+6 -0

Diff too large; view file

harness/session.shmodified+7 -4

Diff too large; view file

harness/shot.shmodified+2 -1

Diff too large; view file

harness/talk.shmodified+3 -1

Diff too large; view file

harness/ui.shmodified+5 -3

Diff too large; view file

harness/up.shmodified+4 -6

Diff too large; view file

harness/usage.shmodified+5 -5

Diff too large; view file

harness/win.shmodified+5 -3

Diff too large; view file