Skip to content

Lightweight native Discord client for Windows, Linux and macOS, written in Rust. No Electron, no browser engine.

Watch Go Live streams in DM and group DM calls (#67)

SolomonNumb1a11d63a03302
diff --git a/apps/rustcord/src/app.rs b/apps/rustcord/src/app.rs
index a55ddb6..f1d2a54 100644
--- a/apps/rustcord/src/app.rs
+++ b/apps/rustcord/src/app.rs
@@ -2155,6 +2155,20 @@ impl RustCord {
}
// `wave-big:<user>` / `wave-pill:<user>`: that DM with "Wave to …" forced.
let wave = dev.strip_prefix("wave-big:").map(|n| (n, false)).or_else(|| dev.strip_prefix("wave-pill:").map(|n| (n, true)));
+ // `dm-call`: the first group DM with a call going on, as Discord would
+ // announce it: one person live, one being rung (nothing is sent).
+ if dev == "dm-call" {
+ let group = self.store.dm_list().into_iter().find(|id| self.store.channels.get(id).is_some_and(|c| c.recipients.len() >= 2));
+ if let Some(ch) = group {
+ let people: Vec<Id> = self.store.channels[&ch].recipients.iter().map(|u| u.id).collect();
+ self.store.voice.insert(ch, vec![people[0]]);
+ self.store.voice_flags.entry(people[0]).or_default().streaming = true;
+ self.calls.insert(ch, crate::voice_call::DmCall { ringing: vec![people[1]] });
+ }
+ self.current_guild = None;
+ self.select_channel(group);
+ return;
+ }
// `dm:<part of a username>` opens that 1:1 DM (profile panel and all).
if let Some(name) = dev.strip_prefix("dm:").or(wave.map(|w| w.0)) {
let name = name.to_lowercase();
diff --git a/apps/rustcord/src/backend.rs b/apps/rustcord/src/backend.rs
index a0b386f..96f84b6 100644
--- a/apps/rustcord/src/backend.rs
+++ b/apps/rustcord/src/backend.rs
@@ -366,7 +366,9 @@ impl Emitter {
"MESSAGE_CREATE" | "MESSAGE_UPDATE" | "MESSAGE_DELETE" | "MESSAGE_DELETE_BULK" | "MESSAGE_ACK"
| "TYPING_START" | "CHANNEL_CREATE" | "CHANNEL_UPDATE" | "CHANNEL_DELETE" | "CHANNEL_RECIPIENT_ADD" | "CHANNEL_RECIPIENT_REMOVE" | "THREAD_CREATE" | "THREAD_UPDATE" | "THREAD_DELETE" | "CHANNEL_PINS_UPDATE"
| "GUILD_CREATE" | "GUILD_DELETE" | "GUILD_MEMBERS_CHUNK" | "GUILD_MEMBER_LIST_UPDATE"
- | "VOICE_STATE_UPDATE" | "VOICE_SERVER_UPDATE" | "RELATIONSHIP_ADD" | "RELATIONSHIP_UPDATE"
+ | "VOICE_STATE_UPDATE" | "VOICE_SERVER_UPDATE" | "CALL_CREATE" | "CALL_UPDATE" | "CALL_DELETE"
+ | "STREAM_CREATE" | "STREAM_SERVER_UPDATE" | "STREAM_UPDATE" | "STREAM_DELETE"
+ | "RELATIONSHIP_ADD" | "RELATIONSHIP_UPDATE"
| "RELATIONSHIP_REMOVE" | "INTERACTION_FAILURE" | "MESSAGE_POLL_VOTE_ADD" | "MESSAGE_POLL_VOTE_REMOVE" => Some(100),
n if n.starts_with("MESSAGE_REACTION") => Some(100),
// PRESENCE_UPDATE, GUILD_MEMBER_UPDATE, SESSIONS_REPLACE,
diff --git a/apps/rustcord/src/ui/call.rs b/apps/rustcord/src/ui/call.rs
index bbde37f..2fe199c 100644
--- a/apps/rustcord/src/ui/call.rs
+++ b/apps/rustcord/src/ui/call.rs
@@ -37,10 +37,14 @@ struct Tile {
speaking: bool,
/// Live (Go Live): a LIVE badge, and others' tiles offer "Watch Stream".
streaming: bool,
+ /// Discord's preview thumbnail URL for a live stream.
+ stream_preview: Option<String>,
/// Your own screen on your tile while you're live.
preview: Option<egui::TextureHandle>,
/// This is you.
me: bool,
+ /// Being rung (DM calls): Discord's dimmed tile with a pulsing outline.
+ ringing: bool,
}
fn rgb(c: u32) -> Color32 {
@@ -141,41 +145,6 @@ impl RustCord {
let bold = |size: f32| FontId::new(size, egui::FontFamily::Name(crate::style::BOLD.into()));
let title = paint_text_emoji(ui, &p, pos2(header.left() + 42.0, cy), &name, bold(16.0), t.header_primary);
let watching = self.watching.as_ref().filter(|w| w.channel == channel).map(|w| (w.streamer, w.viewers.clone()));
- let mut x = title.right();
- if let Some((streamer, _)) = &watching {
- p.text(pos2(x + 12.0, cy), Align2::CENTER_CENTER, crate::style::icon::CHEVRON, icon_font(10.0), t.text_muted);
- x += 24.0;
- let user = self.store.users.get(streamer).cloned();
- let av = Rect::from_center_size(pos2(x + 11.0, cy), vec2(22.0, 22.0));
- paint_avatar(ui, av, user.as_ref().map(|u| u.avatar_or_default(48)), user.as_ref().map_or("?", |u| u.display_name()));
- x = av.right() + 8.0;
- let nick = self.store.nick_in(gid, Some(channel), *streamer);
- let shown = nick.or_else(|| user.as_ref().map(|u| u.display_name().to_string())).unwrap_or_default();
- let handle = user.as_ref().map(|u| format!(" (@{})", u.username)).unwrap_or_default();
- let r = paint_text_emoji(ui, &p, pos2(x, cy), &format!("{shown}{handle}"), bold(14.5), t.header_primary);
- x = r.right();
- if let Some((verb, what, _, _)) = self.stream_activity(*streamer) {
- let r = p.text(pos2(x + 6.0, cy), Align2::LEFT_CENTER, format!("{verb} {what}"), FontId::proportional(14.0), t.text_muted);
- x = r.right();
- }
- } else if in_call {
- let (text, color) = match self.voice.as_ref().and_then(|v| v.connected_at) {
- Some(at) => (elapsed(at.elapsed()), VOICE_GREEN),
- None => (
- match self.voice.as_ref().map(|v| v.phase) {
- Some("securing") => "Securing…".to_string(),
- Some("discovering") => "Connecting (network)…".to_string(),
- _ => "Connecting…".to_string(),
- },
- t.text_muted,
- ),
- };
- p.circle_filled(pos2(title.right() + 12.0, cy), 2.0, t.text_muted);
- p.text(pos2(title.right() + 22.0, cy), Align2::LEFT_CENTER, text, FontId::proportional(13.0), color);
- }
- let _ = x;
- ui.painter().hline(header.x_range(), header.bottom() - 0.5, Stroke::new(1.0_f32, t.border_subtle));
- // Right side, right to left: invite, voice chat, then the stream's badges.
let mut right = header.right() - 12.0;
let mut header_button = |ui: &mut Ui, id: &str, glyph: &str, on: bool, tip: &str| -> bool {
let b = Rect::from_center_size(pos2(right - 17.0, cy), vec2(34.0, 34.0));
@@ -194,49 +163,24 @@ impl RustCord {
if header_button(ui, "call_header_chat", crate::style::icon::MESSAGE, chat_on, if chat_on { "Hide Chat" } else { "Show Chat" }) {
self.golive_ui.chat_open = !chat_on;
}
- if let Some((_, viewers)) = &watching {
- let stats = self.watching_stats();
- // LIVE, then the quality ("1440p 60FPS").
- let pg = p.layout_no_wrap("LIVE".into(), bold(11.0), Color32::WHITE);
- let live = Rect::from_min_max(pos2(right - pg.size().x - 12.0, cy - 10.0), pos2(right - 2.0, cy + 10.0));
- p.rect_filled(live, Rounding { nw: 0.0, sw: 0.0, ne: 6.0, se: 6.0 }, crate::golive::LIVE_RED);
- p.galley(live.center() - pg.size() / 2.0, pg, Color32::WHITE);
- right = live.left();
- if let Some(q) = crate::app::RustCord::quality_label(&stats) {
- let qg = p.layout_no_wrap(format!("{} {q}", crate::golive::SCREEN), icon_font(12.0), Color32::WHITE);
- let badge = Rect::from_min_max(pos2(right - qg.size().x - 14.0, cy - 10.0), pos2(right, cy + 10.0));
- p.rect_filled(badge, Rounding { nw: 6.0, sw: 6.0, ne: 0.0, se: 0.0 }, Color32::from_black_alpha(170));
- p.galley(pos2(badge.left() + 7.0, cy - qg.size().y / 2.0), qg, Color32::WHITE);
- let tip = if crate::golive::quality_tier(stats.width, stats.height) > 720 || crate::golive::quality_fps(stats.fps) > 30 { "Nitro streaming quality" } else { "Streaming quality" };
- ui.interact(badge, egui::Id::new("call_quality_badge"), Sense::hover()).on_hover_text(tip);
- right = badge.left();
- } else {
- right = live.left();
- }
- // Viewers: up to four faces, then "+N".
- if !viewers.is_empty() {
- right -= 10.0;
- let extra = viewers.len().saturating_sub(4);
- if extra > 0 {
- let g = p.layout_no_wrap(format!("+{extra}"), bold(12.0), t.header_primary);
- let r = Rect::from_center_size(pos2(right - 13.0, cy), vec2(26.0, 22.0));
- p.rect_filled(r, 11.0, overlay(0.2));
- p.galley(r.center() - g.size() / 2.0, g, t.header_primary);
- right = r.left() + 6.0;
- }
- let names: Vec<String> = viewers.iter().filter_map(|v| self.store.users.get(v).map(|u| u.display_name().to_string())).collect();
- let first = right;
- for v in viewers.iter().take(4).rev() {
- let user = self.store.users.get(v);
- let av = Rect::from_center_size(pos2(right - 11.0, cy), vec2(22.0, 22.0));
- p.circle_filled(av.center(), 12.5, t.bg_tertiary);
- paint_avatar(ui, av, user.map(|u| u.avatar_or_default(48)), user.map_or("?", |u| u.display_name()));
- right -= 16.0;
- }
- let spectators = Rect::from_min_max(pos2(right, cy - 12.0), pos2(first, cy + 12.0));
- ui.interact(spectators, egui::Id::new("call_spectators"), Sense::hover()).on_hover_text(format!("Watching: {}", names.join(", ")));
- }
+ if let Some((streamer, viewers)) = &watching {
+ self.paint_watching_header(ui, &p, &t, channel, gid, *streamer, viewers, title.right(), right, cy, true);
+ } else if in_call {
+ let (text, color) = match self.voice.as_ref().and_then(|v| v.connected_at) {
+ Some(at) => (elapsed(at.elapsed()), VOICE_GREEN),
+ None => (
+ match self.voice.as_ref().map(|v| v.phase) {
+ Some("securing") => "Securing…".to_string(),
+ Some("discovering") => "Connecting (network)…".to_string(),
+ _ => "Connecting…".to_string(),
+ },
+ t.text_muted,
+ ),
+ };
+ p.circle_filled(pos2(title.right() + 12.0, cy), 2.0, t.text_muted);
+ p.text(pos2(title.right() + 22.0, cy), Align2::LEFT_CENTER, text, FontId::proportional(13.0), color);
}
+ ui.painter().hline(header.x_range(), header.bottom() - 0.5, Stroke::new(1.0_f32, t.border_subtle));
let bar_h: f32 = if in_call { 88.0 } else { 0.0 };
// The voice channel's text chat, on the right.
@@ -263,16 +207,91 @@ impl RustCord {
}
}
- /// Everyone in `channel` (us first, even before the gateway confirms).
+ /// Streamer name, activity, viewer faces, quality badge and LIVE pill for a watched stream.
+ #[allow(clippy::too_many_arguments)]
+ fn paint_watching_header(&self, ui: &mut Ui, p: &egui::Painter, t: &Theme, channel: Id, gid: Option<Id>, streamer: Id, viewers: &[Id], left_start: f32, right_start: f32, cy: f32, show_chevron: bool) {
+ let bold = |size: f32| FontId::new(size, egui::FontFamily::Name(crate::style::BOLD.into()));
+ let mut right = right_start;
+ let stats = self.watching_stats();
+ // LIVE, then the quality ("1440p 60FPS").
+ let pg = p.layout_no_wrap("LIVE".into(), bold(11.0), Color32::WHITE);
+ let live = Rect::from_min_max(pos2(right - pg.size().x - 12.0, cy - 10.0), pos2(right - 2.0, cy + 10.0));
+ p.rect_filled(live, Rounding { nw: 0.0, sw: 0.0, ne: 6.0, se: 6.0 }, crate::golive::LIVE_RED);
+ p.galley(live.center() - pg.size() / 2.0, pg, Color32::WHITE);
+ right = live.left();
+ if let Some(q) = crate::app::RustCord::quality_label(&stats) {
+ let qg = p.layout_no_wrap(format!("{} {q}", crate::golive::SCREEN), icon_font(12.0), Color32::WHITE);
+ let badge = Rect::from_min_max(pos2(right - qg.size().x - 14.0, cy - 10.0), pos2(right, cy + 10.0));
+ p.rect_filled(badge, Rounding { nw: 6.0, sw: 6.0, ne: 0.0, se: 0.0 }, Color32::from_black_alpha(170));
+ p.galley(pos2(badge.left() + 7.0, cy - qg.size().y / 2.0), qg, Color32::WHITE);
+ let tip = if crate::golive::quality_tier(stats.width, stats.height) > 720 || crate::golive::quality_fps(stats.fps) > 30 { "Nitro streaming quality" } else { "Streaming quality" };
+ ui.interact(badge, egui::Id::new("call_quality_badge"), Sense::hover()).on_hover_text(tip);
+ right = badge.left();
+ }
+ // Viewers: up to four faces, then "+N".
+ if !viewers.is_empty() {
+ right -= 10.0;
+ let extra = viewers.len().saturating_sub(4);
+ if extra > 0 {
+ let g = p.layout_no_wrap(format!("+{extra}"), bold(12.0), t.header_primary);
+ let r = Rect::from_center_size(pos2(right - 13.0, cy), vec2(26.0, 22.0));
+ p.rect_filled(r, 11.0, overlay(0.2));
+ p.galley(r.center() - g.size() / 2.0, g, t.header_primary);
+ right = r.left() + 6.0;
+ }
+ let names: Vec<String> = viewers.iter().filter_map(|v| self.store.users.get(v).map(|u| u.display_name().to_string())).collect();
+ let first = right;
+ for v in viewers.iter().take(4).rev() {
+ let user = self.store.users.get(v);
+ let av = Rect::from_center_size(pos2(right - 11.0, cy), vec2(22.0, 22.0));
+ p.circle_filled(av.center(), 12.5, t.bg_tertiary);
+ paint_avatar(ui, av, user.map(|u| u.avatar_or_default(48)), user.map_or("?", |u| u.display_name()));
+ right -= 16.0;
+ }
+ let spectators = Rect::from_min_max(pos2(right, cy - 12.0), pos2(first, cy + 12.0));
+ ui.interact(spectators, egui::Id::new("call_spectators"), Sense::hover()).on_hover_text(format!("Watching: {}", names.join(", ")));
+ }
+ let mut x = left_start;
+ if show_chevron {
+ p.text(pos2(x + 12.0, cy), Align2::CENTER_CENTER, crate::style::icon::CHEVRON, icon_font(10.0), t.text_muted);
+ x += 24.0;
+ }
+ let left_clip = ui.painter_at(Rect::from_min_max(pos2(x, cy - 16.0), pos2((right - 8.0).max(x), cy + 16.0)));
+ let user = self.store.users.get(&streamer).cloned();
+ let av = Rect::from_center_size(pos2(x + 11.0, cy), vec2(22.0, 22.0));
+ paint_avatar(ui, av, user.as_ref().map(|u| u.avatar_or_default(48)), user.as_ref().map_or("?", |u| u.display_name()));
+ x = av.right() + 8.0;
+ let nick = self.store.nick_in(gid, Some(channel), streamer);
+ let shown = nick.or_else(|| user.as_ref().map(|u| u.display_name().to_string())).unwrap_or_default();
+ let handle = user.as_ref().map(|u| format!(" (@{})", u.username)).unwrap_or_default();
+ let r = paint_text_emoji(ui, &left_clip, pos2(x, cy), &format!("{shown}{handle}"), bold(14.5), t.header_primary);
+ x = r.right();
+ if let Some((verb, what, _, _)) = self.stream_activity(streamer) {
+ left_clip.text(pos2(x + 6.0, cy), Align2::LEFT_CENTER, format!("{verb} {what}"), FontId::proportional(14.0), t.text_muted);
+ }
+ }
+
+ /// Everyone in `channel` (us first when we're in it, even before the gateway confirms).
fn call_tile_data(&self, channel: Id, gid: Option<Id>) -> Vec<Tile> {
let me = self.store.me_id();
+ let in_call = self.voice.as_ref().is_some_and(|v| v.channel == channel);
let mut ids = self.store.voice.get(&channel).cloned().unwrap_or_default();
if let Some(me) = me {
- ids.retain(|u| *u != me);
- ids.insert(0, me);
+ if in_call {
+ ids.retain(|u| *u != me);
+ ids.insert(0, me);
+ }
}
+ // A DM call's people being rung have a tile too, as in Discord (and
+ // people who are neither there nor rung have none).
+ let ringing: Vec<Id> = match gid {
+ None => self.calls.get(&channel).map(|c| c.ringing.iter().filter(|u| !ids.contains(u)).copied().collect()).unwrap_or_default(),
+ Some(_) => Vec::new(),
+ };
ids.into_iter()
- .map(|id| {
+ .map(|id| (id, false))
+ .chain(ringing.into_iter().map(|id| (id, true)))
+ .map(|(id, ringing)| {
let user = if Some(id) == me { self.store.me.clone() } else { self.store.users.get(&id).cloned() };
let nick = self.store.nick_in(gid, Some(channel), id);
let name = nick.or_else(|| user.as_ref().map(|u| u.display_name().to_string())).unwrap_or_else(|| "Loading…".into());
@@ -287,8 +306,9 @@ impl RustCord {
let flags = self.store.voice_flags.get(&id).copied().unwrap_or_default();
let (muted, deafened) = if Some(id) == me { (self.self_mute || self.self_deaf, self.self_deaf) } else { (flags.muted, flags.deafened) };
let me_tile = Some(id) == me;
- let streaming = if me_tile { self.go_live.as_ref().is_some_and(|g| g.channel == channel) } else { flags.streaming };
- Tile { id, user, name, color, banner, muted, deafened, server: flags.server_muted, speaking: self.is_speaking(id), streaming, preview: None, me: me_tile }
+ let streaming = !ringing && if me_tile { self.go_live.as_ref().is_some_and(|g| g.channel == channel) } else { flags.streaming };
+ let speaking = !ringing && self.is_speaking(id);
+ Tile { id, user, name, color, banner, muted, deafened, server: flags.server_muted, speaking, streaming, stream_preview: None, preview: None, me: me_tile, ringing }
})
.collect()
}
@@ -299,7 +319,7 @@ impl RustCord {
let ctx = ui.ctx().clone();
// Your tile shows your stream, else your camera.
let own = self.own_stream_texture(&ctx).or_else(|| self.camera_texture(&ctx));
- let watched = self.watching.as_ref().map(|w| w.streamer);
+ let watched = self.watching.as_ref().filter(|w| w.channel == channel).map(|w| w.streamer);
let in_this_call = self.voice.as_ref().is_some_and(|v| v.channel == channel);
for tile in tiles.iter_mut() {
if tile.me {
@@ -311,6 +331,9 @@ impl RustCord {
// The one you're watching is on the big stage already.
if Some(tile.id) == watched {
tile.streaming = false;
+ } else if tile.streaming && !tile.me && tile.preview.is_none() {
+ let key = crate::golive::stream_key(gid, channel, tile.id);
+ tile.stream_preview = self.stream_preview(&key);
}
}
// "Show Non-Video Participants" off: only people sharing video.
@@ -390,7 +413,7 @@ impl RustCord {
}
if let Some((i, at)) = clicked {
if tiles[i].streaming && !tiles[i].me {
- self.watch_stream(tiles[i].id);
+ self.watch_from_list(tiles[i].id, channel);
} else if let Some(user) = tiles[i].user.clone() {
self.open_profile(user, gid, at + vec2(12.0, -60.0));
}
@@ -642,11 +665,48 @@ fn square_button(ui: &mut Ui, rect: Rect, id: egui::Id, fill: Color32, hover: Co
/// One participant: colour or banner, avatar (green ring while talking),
/// name pill with mute / deafen marks.
fn paint_tile(ui: &mut Ui, t: &Theme, rect: Rect, tile: &Tile) -> egui::Response {
+ if !tile.ringing {
+ return paint_tile_body(ui, t, rect, tile);
+ }
+ // Discord's ringing tile: the whole tile at 30 %, and around it a 3 px
+ // outline that pulses twice every 2.5 s, growing 2.5 % as it fades.
+ let mut dim = ui.new_child(egui::UiBuilder::new().max_rect(rect.expand(rect.width().max(rect.height()) * 0.0125 + 4.0)));
+ dim.multiply_opacity(0.3);
+ let resp = paint_tile_body(&mut dim, t, rect, tile);
+ let outline = |grow: f32, alpha: f32| {
+ let r = Rect::from_center_size(rect.center(), rect.size() * grow).expand(1.5);
+ dim.painter().rect_stroke(r, 15.5, Stroke::new(3.0_f32, Color32::WHITE.gamma_multiply(alpha)));
+ };
+ if super::REDUCED_MOTION.load(std::sync::atomic::Ordering::Relaxed) {
+ outline(1.0, 1.0);
+ } else {
+ let phase = (ui.input(|i| i.time) / 2.5).fract() as f32;
+ // Two pulses: at 0 (fading in over the first 11.56 %) and at 39.04 %,
+ // each gone by 39.02 % / 66.48 %.
+ let pulse = |start: f32, end: f32, fade_in: f32| {
+ let k = (phase - start) / (end - start);
+ (0.0..=1.0).contains(&k).then(|| {
+ let alpha = if phase < fade_in { (phase - start) / (fade_in - start) } else { 1.0 - (phase - fade_in) / (end - fade_in) };
+ (1.0 + 0.025 * k, alpha.clamp(0.0, 1.0))
+ })
+ };
+ if let Some((grow, alpha)) = pulse(0.0, 0.3902, 0.1156).or_else(|| pulse(0.3904, 0.6648, 0.3904)) {
+ outline(grow, alpha);
+ }
+ ui.ctx().request_repaint_after(std::time::Duration::from_millis(33));
+ }
+ resp
+}
+
+fn paint_tile_body(ui: &mut Ui, t: &Theme, rect: Rect, tile: &Tile) -> egui::Response {
let resp = ui.interact(rect, egui::Id::new(("call_tile", tile.id.0)), Sense::click()).on_hover_cursor(CursorIcon::PointingHand);
let r = 14.0;
let p = ui.painter_at(rect.expand(2.0));
gradient_rrect(&p, rect, r, tile.color.lerp_to_gamma(Color32::BLACK, 0.32), tile.color.lerp_to_gamma(Color32::BLACK, 0.62));
- if let Some(url) = &tile.banner {
+ if let Some(url) = &tile.stream_preview {
+ paint_cover(ui, rect, url, Rounding::same(r));
+ p.rect_filled(rect, r, Color32::from_black_alpha(95));
+ } else if let Some(url) = &tile.banner {
paint_cover(ui, rect, url, Rounding::same(r));
p.rect_filled(rect, r, Color32::from_black_alpha(120));
}
@@ -659,16 +719,19 @@ fn paint_tile(ui: &mut Ui, t: &Theme, rect: Rect, tile: &Tile) -> egui::Response
} else {
ui.ctx().animate_bool_with_time(egui::Id::new(("call_speaking", tile.id.0)), tile.speaking, 0.16)
};
- let size = (rect.width().min(rect.height() * 1.6) * 0.22).clamp(40.0, 112.0).min(rect.height() * 0.5);
- let av = Rect::from_center_size(rect.center() - vec2(0.0, rect.height() * 0.03), vec2(size, size));
- if s > 0.0 {
- p.circle_filled(av.center(), size / 2.0 + 4.0 + 6.0 * s, VOICE_GREEN.gamma_multiply(0.16 * s));
- }
- // A thin dark ring keeps light avatars off light tiles.
- p.circle_filled(av.center(), size / 2.0 + 3.0, Color32::from_black_alpha(70));
- paint_avatar(ui, av, tile.user.as_ref().map(|u| u.avatar_or_default(if size > 64.0 { 256 } else { 128 })), &tile.name);
- if s > 0.0 {
- p.circle_stroke(av.center(), size / 2.0 + 3.0, Stroke::new(3.0_f32, VOICE_GREEN.gamma_multiply(s)));
+ let show_avatar = tile.preview.is_some() || tile.stream_preview.is_none() || rect.height() < 130.0;
+ if show_avatar {
+ let size = (rect.width().min(rect.height() * 1.6) * 0.22).clamp(40.0, 112.0).min(rect.height() * 0.5);
+ let av = Rect::from_center_size(rect.center() - vec2(0.0, rect.height() * 0.03), vec2(size, size));
+ if s > 0.0 {
+ p.circle_filled(av.center(), size / 2.0 + 4.0 + 6.0 * s, VOICE_GREEN.gamma_multiply(0.16 * s));
+ }
+ // A thin dark ring keeps light avatars off light tiles.
+ p.circle_filled(av.center(), size / 2.0 + 3.0, Color32::from_black_alpha(70));
+ paint_avatar(ui, av, tile.user.as_ref().map(|u| u.avatar_or_default(if size > 64.0 { 256 } else { 128 })), &tile.name);
+ if s > 0.0 {
+ p.circle_stroke(av.center(), size / 2.0 + 3.0, Stroke::new(3.0_f32, VOICE_GREEN.gamma_multiply(s)));
+ }
}
// Your own screen while you're live, over the avatar.
if let Some(tex) = &tile.preview {
@@ -684,11 +747,22 @@ fn paint_tile(ui: &mut Ui, t: &Theme, rect: Rect, tile: &Tile) -> egui::Response
}
if tile.streaming {
crate::golive::paint_live(&p, pos2(rect.left() + 12.0, rect.top() + 20.0), 11.0);
- // Someone else's stream: "Watch Stream" on hover (the click watches).
- if !tile.me && resp.hovered() {
- let b = Rect::from_center_size(rect.center() + vec2(0.0, rect.height() * 0.28), vec2(140.0, 34.0));
- p.rect_filled(b, 10.0, Color32::from_black_alpha(190));
- p.text(b.center(), Align2::CENTER_CENTER, "Watch Stream", FontId::new(13.0, egui::FontFamily::Name(crate::style::BOLD.into())), Color32::WHITE);
+ // Someone else's stream: always show "Watch Stream" on full tiles, and on hover in compact strips.
+ if !tile.me && (rect.height() >= 130.0 || resp.hovered()) {
+ let compact = rect.height() < 130.0;
+ let b = Rect::from_center_size(
+ if compact { rect.center() } else { rect.center() + vec2(0.0, rect.height() * 0.24) },
+ vec2(if compact { 84.0 } else { 142.0 }, if compact { 26.0 } else { 34.0 }),
+ );
+ p.rect_filled(b, 10.0, Color32::from_black_alpha(if resp.hovered() { 225 } else { 175 }));
+ p.rect_stroke(b, 10.0, Stroke::new(1.0_f32, rgba(255, 255, 255, if resp.hovered() { 70 } else { 28 })));
+ p.text(
+ b.center(),
+ Align2::CENTER_CENTER,
+ if compact { "Watch" } else { "Watch Stream" },
+ FontId::new(if compact { 12.0 } else { 13.0 }, egui::FontFamily::Name(crate::style::BOLD.into())),
+ Color32::WHITE,
+ );
}
}
// Name pill, bottom-left.
@@ -726,10 +800,31 @@ mod tests {
assert_eq!(elapsed(std::time::Duration::from_secs(75)), "1:15");
assert_eq!(elapsed(std::time::Duration::from_secs(3723)), "1:02:03");
}
+
+ #[test]
+ fn dm_avatars_fit_narrow_calls() {
+ let (size, gap) = dm_avatar_layout(500.0, 200.0, 4);
+ assert_eq!(size, 80.0);
+ assert_eq!(gap, 32.0);
+ let (size_tight, gap_tight) = dm_avatar_layout(300.0, 200.0, 8);
+ assert!(8.0 * size_tight + 7.0 * gap_tight <= 276.0 + 0.01);
+ }
}
// ---- DM calls ------------------------------------------------------------------------
+/// Avatar size and spacing that keep `count` participants centred inside `avail_w`.
+fn dm_avatar_layout(avail_w: f32, height: f32, count: usize) -> (f32, f32) {
+ let count = count.max(1);
+ let usable = (avail_w - 24.0).max(32.0);
+ let min_gap = 8.0_f32;
+ let (base_size, max_gap) = ((height * 0.5).clamp(48.0, 80.0), 32.0);
+ let max_size = ((usable - (count - 1) as f32 * min_gap) / count as f32).max(24.0);
+ let size = base_size.min(max_size);
+ let gap = if count > 1 { ((usable - count as f32 * size) / (count - 1) as f32).clamp(min_gap, max_gap) } else { max_gap };
+ (size, gap)
+}
+
/// How a DM participant shows in the call area.
#[derive(Clone, Copy, PartialEq)]
enum Presence {
@@ -753,8 +848,19 @@ fn paint_ringing(ui: &Ui, p: &egui::Painter, center: egui::Pos2, radius: f32) {
}
impl RustCord {
+ /// Whether this DM / group DM call currently has any video, Go Live stream,
+ /// or watched stream (used to switch the DM call panel into grid / stage mode).
+ pub fn dm_call_has_video(&self, channel: Id) -> bool {
+ let in_call = self.voice.as_ref().is_some_and(|v| v.channel == channel);
+ if in_call && (self.watching.as_ref().is_some_and(|w| w.channel == channel) || self.go_live.as_ref().is_some_and(|g| g.channel == channel) || self.camera.on.is_some()) {
+ return true;
+ }
+ self.store.voice.get(&channel).is_some_and(|users| users.iter().any(|id| self.store.voice_flags.get(id).is_some_and(|f| f.streaming || f.video)))
+ }
+
/// Discord's call area above a DM's messages: everyone in the DM (in the call, being
- /// rung, or not there), then the call controls, or "Join Call" while we're not in it.
+ /// rung, or not there), switching to video tiles / stage when someone streams or uses
+ /// camera, then the call controls or "Join Call" while we're not in it.
pub fn dm_call_panel(&mut self, ui: &mut Ui, channel: Id) {
let t = self.theme.clone();
let area = ui.max_rect();
@@ -763,87 +869,116 @@ impl RustCord {
let connected = self.voice.as_ref().is_some_and(|v| v.channel == channel && v.connected);
let there = self.store.voice.get(&channel).cloned().unwrap_or_default();
let ringing = self.calls.get(&channel).map(|c| c.ringing.clone()).unwrap_or_default();
- // Us first, then the others in the DM.
- let mut people: Vec<(Id, Option<User>)> = Vec::new();
- if let Some(me) = me {
- people.push((me, self.store.me.clone()));
- }
- for user in self.store.channels.get(&channel).map(|c| c.recipients.clone()).unwrap_or_default() {
- if Some(user.id) != me {
- people.push((user.id, Some(user)));
- }
- }
let bar_h = 76.0;
let stage = Rect::from_min_max(area.min, pos2(area.right(), area.bottom() - bar_h));
- let size = (stage.height() * 0.5).clamp(48.0, 80.0);
- let gap = 32.0;
- let row_w = people.len() as f32 * size + people.len().saturating_sub(1) as f32 * gap;
- let mut x = stage.center().x - row_w / 2.0;
- let p = ui.painter_at(area);
- let mut open: Option<(User, egui::Pos2)> = None;
- for (id, user) in &people {
- let presence = if (Some(*id) == me && in_call) || there.contains(id) {
- Presence::InCall
- } else if ringing.contains(id) {
- Presence::Ringing
+ let watched = in_call.then(|| self.watching.as_ref().filter(|w| w.channel == channel).map(|w| (w.streamer, w.viewers.clone()))).flatten();
+ if self.dm_call_has_video(channel) {
+ if let Some((streamer, viewers)) = watched {
+ let hdr = Rect::from_min_size(stage.min, vec2(stage.width(), 32.0));
+ let hp = ui.painter_at(hdr);
+ self.paint_watching_header(ui, &hp, &t, channel, None, streamer, &viewers, hdr.left() + 12.0, hdr.right() - 12.0, hdr.center().y, false);
+ hp.hline(hdr.x_range(), hdr.bottom() - 0.5, Stroke::new(1.0_f32, t.border_subtle));
+ let stage_body = stage.with_min_y(hdr.bottom()).shrink2(vec2(12.0, 4.0));
+ let tiles_area = self.watching_stage(ui, &t, stage_body);
+ self.call_tiles(ui, &t, tiles_area, channel, None, false);
} else {
- Presence::Absent
- };
- let av = Rect::from_min_size(pos2(x, stage.center().y - size / 2.0), vec2(size, size));
- x += size + gap;
- let name = user.as_ref().map_or("?", |u| u.display_name()).to_string();
- if presence == Presence::Ringing {
- paint_ringing(ui, &p, av.center(), size / 2.0);
+ self.call_tiles(ui, &t, stage.shrink2(vec2(12.0, 8.0)), channel, None, false);
}
- paint_avatar(ui, av, user.as_ref().map(|u| u.avatar_or_default(256)), &name);
- if presence != Presence::InCall {
- // Not in the call (yet): dimmed, as in Discord.
- p.circle_filled(av.center(), size / 2.0 + 0.5, Color32::from_black_alpha(if presence == Presence::Ringing { 110 } else { 170 }));
+ } else {
+ // Voice-only call: centred circular avatars, speaking rings and status text.
+ let mut people: Vec<(Id, Option<User>)> = Vec::new();
+ if let Some(me) = me {
+ people.push((me, self.store.me.clone()));
}
- let speaking = presence == Presence::InCall && self.is_speaking(*id);
- let s = if super::REDUCED_MOTION.load(std::sync::atomic::Ordering::Relaxed) {
- f32::from(u8::from(speaking))
- } else {
- ui.ctx().animate_bool_with_time(egui::Id::new(("dm_call_speaking", id.0)), speaking, 0.12)
- };
- if s > 0.0 {
- // Discord's speaking ring: 2 px of green, 2 px out from the avatar.
- p.circle_stroke(av.center(), size / 2.0 + 3.0, Stroke::new(2.0_f32, VOICE_GREEN.gamma_multiply(s)));
+ for user in self.store.channels.get(&channel).map(|c| c.recipients.clone()).unwrap_or_default() {
+ if Some(user.id) != me {
+ people.push((user.id, Some(user)));
+ }
+ }
+ for uid in &there {
+ if !people.iter().any(|(id, _)| id == uid) {
+ people.push((*uid, self.store.users.get(uid).cloned()));
+ }
}
- if presence == Presence::InCall {
- let flags = self.store.voice_flags.get(id).copied().unwrap_or_default();
- let (muted, deafened) = if Some(*id) == me { (self.self_mute || self.self_deaf, self.self_deaf) } else { (flags.muted, flags.deafened) };
- if muted || deafened {
- let badge = pos2(av.right() - 8.0, av.bottom() - 8.0);
- p.circle_filled(badge, 12.0, Color32::BLACK);
- p.circle_filled(badge, 10.0, Color32::from_rgb(0x2b, 0x2d, 0x31));
- p.text(badge, Align2::CENTER_CENTER, if deafened { crate::style::icon::DEAFENED } else { MIC_OFF }, icon_font(11.0), Color32::from_rgb(0xf2, 0x3f, 0x43));
+ let (size, gap) = dm_avatar_layout(stage.width(), stage.height(), people.len());
+ let row_w = people.len() as f32 * size + people.len().saturating_sub(1) as f32 * gap;
+ let mut x = stage.center().x - row_w / 2.0;
+ let p = ui.painter_at(area);
+ let mut open: Option<(User, egui::Pos2)> = None;
+ let mut menu: Option<(Id, egui::Pos2)> = None;
+ for (id, user) in &people {
+ let is_me = Some(*id) == me;
+ let presence = if (is_me && in_call) || there.contains(id) {
+ Presence::InCall
+ } else if ringing.contains(id) {
+ Presence::Ringing
+ } else {
+ Presence::Absent
+ };
+ let av = Rect::from_min_size(pos2(x, stage.center().y - size / 2.0), vec2(size, size));
+ x += size + gap;
+ let name = user.as_ref().map_or("?", |u| u.display_name()).to_string();
+ if presence == Presence::Ringing {
+ paint_ringing(ui, &p, av.center(), size / 2.0);
+ }
+ paint_avatar(ui, av, user.as_ref().map(|u| u.avatar_or_default(256)), &name);
+ if presence != Presence::InCall {
+ // Not in the call (yet): dimmed, as in Discord.
+ p.circle_filled(av.center(), size / 2.0 + 0.5, Color32::from_black_alpha(if presence == Presence::Ringing { 110 } else { 170 }));
+ }
+ let speaking = presence == Presence::InCall && self.is_speaking(*id);
+ let s = if super::REDUCED_MOTION.load(std::sync::atomic::Ordering::Relaxed) {
+ f32::from(u8::from(speaking))
+ } else {
+ ui.ctx().animate_bool_with_time(egui::Id::new(("dm_call_speaking", id.0)), speaking, 0.12)
+ };
+ if s > 0.0 {
+ // Discord's speaking ring: 2 px of green, 2 px out from the avatar.
+ p.circle_stroke(av.center(), size / 2.0 + 3.0, Stroke::new(2.0_f32, VOICE_GREEN.gamma_multiply(s)));
+ }
+ if presence == Presence::InCall {
+ let flags = self.store.voice_flags.get(id).copied().unwrap_or_default();
+ let (muted, deafened) = if is_me { (self.self_mute || self.self_deaf, self.self_deaf) } else { (flags.muted, flags.deafened) };
+ if muted || deafened {
+ let badge = pos2(av.right() - 8.0, av.bottom() - 8.0);
+ p.circle_filled(badge, 12.0, Color32::BLACK);
+ p.circle_filled(badge, 10.0, Color32::from_rgb(0x2b, 0x2d, 0x31));
+ p.text(badge, Align2::CENTER_CENTER, if deafened { crate::style::icon::DEAFENED } else { MIC_OFF }, icon_font(11.0), Color32::from_rgb(0xf2, 0x3f, 0x43));
+ }
+ }
+ let resp = ui.interact(av, egui::Id::new(("dm_call_person", id.0)), Sense::click()).on_hover_cursor(CursorIcon::PointingHand);
+ if let (true, Some(user)) = (resp.clicked(), user) {
+ open = Some((user.clone(), av.right_top()));
}
+ if resp.secondary_clicked() && presence == Presence::InCall {
+ menu = Some((*id, resp.interact_pointer_pos().unwrap_or(av.center())));
+ }
+ resp.on_hover_text(match presence {
+ Presence::InCall => name,
+ Presence::Ringing => format!("{name} (ringing…)"),
+ Presence::Absent => format!("{name} (not in the call)"),
+ });
}
- let resp = ui.interact(av, egui::Id::new(("dm_call_person", id.0)), Sense::click()).on_hover_cursor(CursorIcon::PointingHand);
- if let (true, Some(user)) = (resp.clicked(), user) {
- open = Some((user.clone(), av.right_top()));
+ // What the call is doing, under the faces.
+ let status = if in_call && !connected {
+ Some("Connecting…".to_string())
+ } else if in_call && ringing.iter().any(|r| Some(*r) != me) && there.iter().filter(|u| Some(**u) != me).count() == 0 {
+ Some("Calling…".to_string())
+ } else if in_call {
+ self.voice.as_ref().and_then(|v| v.connected_at).map(|at| elapsed(at.elapsed()))
+ } else if me.is_some_and(|m| ringing.contains(&m)) {
+ Some("Incoming Call…".to_string())
+ } else {
+ None
+ };
+ if let Some(status) = status {
+ p.text(pos2(stage.center().x, stage.center().y + size / 2.0 + 22.0), Align2::CENTER_CENTER, status, FontId::proportional(13.0), rgba(255, 255, 255, 170));
+ }
+ if let Some((uid, at)) = menu {
+ self.toggle_voice_menu(super::voice_menu::VoiceMenuKind::User(uid), Rect::from_min_size(at, vec2(1.0, 1.0)));
+ } else if let Some((user, at)) = open {
+ self.open_profile(user, None, at + vec2(12.0, 0.0));
}
- resp.on_hover_text(match presence {
- Presence::InCall => name,
- Presence::Ringing => format!("{name} (ringing…)"),
- Presence::Absent => format!("{name} (not in the call)"),
- });
- }
- // What the call is doing, under the faces.
- let status = if in_call && !connected {
- Some("Connecting…".to_string())
- } else if in_call && ringing.iter().any(|r| Some(*r) != me) && there.iter().filter(|u| Some(**u) != me).count() == 0 {
- Some("Calling…".to_string())
- } else if in_call {
- self.voice.as_ref().and_then(|v| v.connected_at).map(|at| elapsed(at.elapsed()))
- } else if me.is_some_and(|m| ringing.contains(&m)) {
- Some("Incoming Call…".to_string())
- } else {
- None
- };
- if let Some(status) = status {
- p.text(pos2(stage.center().x, stage.center().y + size / 2.0 + 22.0), Align2::CENTER_CENTER, status, FontId::proportional(13.0), rgba(255, 255, 255, 170));
}
let bar = Rect::from_min_max(pos2(area.left(), area.bottom() - bar_h), area.max);
if in_call {
@@ -873,9 +1008,6 @@ impl RustCord {
}
}
ui.painter().hline(area.x_range(), area.bottom() - 0.5, Stroke::new(1.0_f32, t.border_subtle));
- if let Some((user, at)) = open {
- self.open_profile(user, None, at + vec2(12.0, 0.0));
- }
}
/// Discord's incoming call box: who is calling, "Incoming Call…", decline and accept.
diff --git a/apps/rustcord/src/ui/chat.rs b/apps/rustcord/src/ui/chat.rs
index cba00f3..0160aec 100644
--- a/apps/rustcord/src/ui/chat.rs
+++ b/apps/rustcord/src/ui/chat.rs
@@ -954,7 +954,15 @@ impl RustCord {
self.chat_side_panel(ui);
// A call in this DM: Discord's call area above the messages.
if channel.guild_id.is_none() && self.dm_call_visible(ch) {
- let height = (ui.available_height() * 0.42).clamp(200.0, 300.0);
+ let watching = self.voice.as_ref().is_some_and(|v| v.channel == ch) && self.watching.as_ref().is_some_and(|w| w.channel == ch);
+ let height = if watching {
+ let max_h = (ui.available_height() - 150.0).max(320.0);
+ (ui.available_height() * 0.68).clamp(320.0, max_h)
+ } else if self.dm_call_has_video(ch) {
+ (ui.available_height() * 0.50).clamp(260.0, 380.0)
+ } else {
+ (ui.available_height() * 0.42).clamp(200.0, 300.0)
+ };
TopBottomPanel::top("dm_call_area")
.show_separator_line(false)
.exact_height(height)
diff --git a/apps/rustcord/src/ui/voice_menu.rs b/apps/rustcord/src/ui/voice_menu.rs
index cd258e8..b6961de 100644
--- a/apps/rustcord/src/ui/voice_menu.rs
+++ b/apps/rustcord/src/ui/voice_menu.rs
@@ -85,6 +85,7 @@ enum Act {
UserVolume(Id, f32, bool),
StreamVolume(f32, bool),
StreamFullscreen,
+ WatchStream(Id),
StopWatching,
LocalMute(Id),
Profile(Id),
@@ -560,6 +561,13 @@ impl RustCord {
acts.push(Act::Message(uid));
}
if !is_me {
+ if flags.streaming {
+ let watching_them = self.watching.as_ref().is_some_and(|w| w.streamer == uid);
+ let label = if watching_them { "Stop Watching" } else { "Watch Stream" };
+ if item_row(ui, &t, Some(crate::golive::SCREEN), label, false).clicked() {
+ acts.push(if watching_them { Act::StopWatching } else { Act::WatchStream(uid) });
+ }
+ }
separator(ui, &t);
let mut v = vol;
let (changed, done) = slider_row(ui, &t, egui::Id::new(("vm_user_vol", uid.0)), "User Volume", &mut v, 200.0);
@@ -734,6 +742,12 @@ impl RustCord {
self.toggle_watch_fullscreen();
close = true;
}
+ Act::WatchStream(uid) => {
+ if let Some((_, ch)) = self.voice_place_of(uid) {
+ self.watch_from_list(uid, ch);
+ }
+ close = true;
+ }
Act::StopWatching => {
self.stop_watching();
close = true;