Call grid view, poll show-voters option with anonymous counts, poll card refresh
Browse files at this commitc3c7ee247eb87b88bbaf5ab9953729622be52bbaParent: 6d19ee2- feat
- call grid view, poll show-voters option with anonymous counts, poll card refresh
12 changed files +542 -120
- crates/client/src/gui/camera_view.rs +264 -52
- crates/client/src/gui/chat.rs +21 -12
- crates/client/src/gui/composer.rs +36 -9
- crates/client/src/gui/poll.rs +142 -31
- crates/client/src/gui/share_view.rs +10 -7
- crates/common/src/call.rs +7 -0
- crates/common/src/model.rs +3 -0
- crates/server/src/call/message.rs +13 -1
- crates/server/src/call/mod.rs +1 -0
- crates/server/src/db/message.rs +2 -1
- crates/server/src/db/poll.rs +41 -6
- crates/server/src/db/schema.sql +2 -1
crates/client/src/gui/camera_view.rsmodified+264 -52
| @@ -3,15 +3,15 @@ use std::sync::Arc; | |||
| 3 | 3 | ||
| 4 | use common::share::{Fps, Kind, Quality, Resolution}; | 4 | use common::share::{Fps, Kind, Quality, Resolution}; |
| 5 | use gpui_kit::{ | 5 | use gpui_kit::{ |
| 6 | - Context, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement, RenderImage, | 6 | + AnyElement, Context, Entity, InteractiveElement, IntoElement, ObjectFit, ParentElement, |
| 7 | - StatefulInteractiveElement, Styled, StyledImage, Task, Window, | 7 | + RenderImage, StatefulInteractiveElement, Styled, StyledImage, Task, Window, |
| 8 | assets::IconName, | 8 | assets::IconName, |
| 9 | component::Icon, | 9 | component::Icon, |
| 10 | div, img, px, | 10 | div, img, px, |
| 11 | }; | 11 | }; |
| 12 | 12 | ||
| 13 | use super::{ | 13 | use super::{ |
| 14 | - Palette, Tooltip as _, Yumush, avatar, clickable, | 14 | + Palette, Tooltip as _, Yumush, avatar, clickable, entity_action, |
| 15 | media_view::to_render_image, | 15 | media_view::to_render_image, |
| 16 | notify_error, | 16 | notify_error, |
| 17 | share_view::{self, FRAME_TICK}, | 17 | share_view::{self, FRAME_TICK}, |
| @@ -20,86 +20,100 @@ use super::{ | |||
| 20 | }; | 20 | }; |
| 21 | use crate::share::session::WatchQuality; | 21 | use crate::share::session::WatchQuality; |
| 22 | 22 | ||
| 23 | -pub(super) const CAMERA_TILE: WatchQuality = WatchQuality::Fixed(Quality { | 23 | +pub(super) const TILE_QUALITY: WatchQuality = WatchQuality::Fixed(Quality { |
| 24 | resolution: Resolution::P360, | 24 | resolution: Resolution::P360, |
| 25 | fps: Fps::F30, | 25 | fps: Fps::F30, |
| 26 | }); | 26 | }); |
| 27 | 27 | ||
| 28 | -pub(super) struct CameraTile { | 28 | +#[derive(Clone, Copy, PartialEq, Eq)] |
| 29 | +pub(super) enum Stage { | ||
| 30 | + Strip, | ||
| 31 | + Grid, | ||
| 32 | + Hidden, | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +pub(super) fn tile_quality(stage: Stage) -> WatchQuality { | ||
| 36 | + match stage { | ||
| 37 | + Stage::Grid => WatchQuality::Auto, | ||
| 38 | + Stage::Strip | Stage::Hidden => TILE_QUALITY, | ||
| 39 | + } | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +pub(super) struct Tile { | ||
| 29 | pub(super) generation: Option<u64>, | 43 | pub(super) generation: Option<u64>, |
| 30 | pub(super) frame: Option<Arc<RenderImage>>, | 44 | pub(super) frame: Option<Arc<RenderImage>>, |
| 31 | } | 45 | } |
| 32 | 46 | ||
| 33 | impl Yumush { | 47 | impl Yumush { |
| 34 | - fn camera_users(&self) -> Vec<Id> { | 48 | + fn tile_sources(&self) -> Vec<(Id, Kind)> { |
| 35 | - let Some(community_id) = self.chat.voice_community() else { | 49 | + let grid = self.chat.stage == Stage::Grid; |
| 36 | - return Vec::new(); | 50 | + self.stage_sources() |
| 37 | - }; | ||
| 38 | - self.chat | ||
| 39 | - .shares | ||
| 40 | - .get(&community_id) | ||
| 41 | .into_iter() | 51 | .into_iter() |
| 42 | - .flatten() | 52 | + .filter(|(_, kind)| grid || *kind == Kind::Camera) |
| 43 | - .filter(|share| share.kind == Kind::Camera) | ||
| 44 | - .map(|share| share.user_id) | ||
| 45 | .collect() | 53 | .collect() |
| 46 | } | 54 | } |
| 47 | 55 | ||
| 48 | - pub(super) fn tick_cameras(&mut self, cx: &mut Context<Self>) { | 56 | + pub(super) fn tick_tiles(&mut self, cx: &mut Context<Self>) { |
| 49 | - let wanted = self.camera_users(); | 57 | + let wanted = self.tile_sources(); |
| 50 | - let viewing = self.viewing_camera(); | 58 | + let viewing = self.viewing(); |
| 59 | + let quality = tile_quality(self.chat.stage); | ||
| 51 | let mut changed = false; | 60 | let mut changed = false; |
| 52 | 61 | ||
| 53 | - for &user_id in &wanted { | 62 | + for &source in &wanted { |
| 54 | - if self.chat.cameras.contains_key(&user_id) { | 63 | + if self.chat.tiles.contains_key(&source) { |
| 55 | continue; | 64 | continue; |
| 56 | } | 65 | } |
| 57 | - self.chat.cameras.insert( | 66 | + self.chat.tiles.insert( |
| 58 | - user_id, | 67 | + source, |
| 59 | - CameraTile { | 68 | + Tile { |
| 60 | generation: None, | 69 | generation: None, |
| 61 | frame: None, | 70 | frame: None, |
| 62 | }, | 71 | }, |
| 63 | ); | 72 | ); |
| 73 | + changed = true; | ||
| 74 | + if viewing == Some(source) { | ||
| 75 | + continue; | ||
| 76 | + } | ||
| 77 | + let (user_id, kind) = source; | ||
| 64 | let network = self.network.clone(); | 78 | let network = self.network.clone(); |
| 65 | let volume = self.settings.share.volume; | 79 | let volume = self.settings.share.volume; |
| 66 | let choice = self.settings.voice.choice.clone(); | 80 | let choice = self.settings.voice.choice.clone(); |
| 67 | - spawn_warn(cx, "camera watch", async move { | 81 | + spawn_warn(cx, "tile watch", async move { |
| 68 | network | 82 | network |
| 69 | - .watch_share(user_id, Kind::Camera, CAMERA_TILE, volume, choice) | 83 | + .watch_share(user_id, kind, quality, volume, choice) |
| 70 | .await | 84 | .await |
| 71 | }); | 85 | }); |
| 72 | - changed = true; | ||
| 73 | } | 86 | } |
| 74 | 87 | ||
| 75 | - let gone: Vec<Id> = self | 88 | + let gone: Vec<(Id, Kind)> = self |
| 76 | .chat | 89 | .chat |
| 77 | - .cameras | 90 | + .tiles |
| 78 | .keys() | 91 | .keys() |
| 79 | - .filter(|user_id| !wanted.contains(user_id)) | 92 | + .filter(|source| !wanted.contains(source)) |
| 80 | .copied() | 93 | .copied() |
| 81 | .collect(); | 94 | .collect(); |
| 82 | - for user_id in gone { | 95 | + for source in gone { |
| 83 | if let Some(frame) = self | 96 | if let Some(frame) = self |
| 84 | .chat | 97 | .chat |
| 85 | - .cameras | 98 | + .tiles |
| 86 | - .remove(&user_id) | 99 | + .remove(&source) |
| 87 | .and_then(|tile| tile.frame) | 100 | .and_then(|tile| tile.frame) |
| 88 | { | 101 | { |
| 89 | cx.drop_image(frame, None); | 102 | cx.drop_image(frame, None); |
| 90 | } | 103 | } |
| 91 | - if viewing != Some(user_id) { | 104 | + if viewing != Some(source) { |
| 92 | let network = self.network.clone(); | 105 | let network = self.network.clone(); |
| 106 | + let (user_id, kind) = source; | ||
| 93 | cx.spawn(async move |_, _| { | 107 | cx.spawn(async move |_, _| { |
| 94 | - let _ = network.unwatch_share(user_id, Kind::Camera).await; | 108 | + let _ = network.unwatch_share(user_id, kind).await; |
| 95 | }) | 109 | }) |
| 96 | .detach(); | 110 | .detach(); |
| 97 | } | 111 | } |
| 98 | changed = true; | 112 | changed = true; |
| 99 | } | 113 | } |
| 100 | 114 | ||
| 101 | - for (user_id, tile) in self.chat.cameras.iter_mut() { | 115 | + for (&(user_id, kind), tile) in self.chat.tiles.iter_mut() { |
| 102 | - let Some(frame) = self.network.share_frame(*user_id, Kind::Camera) else { | 116 | + let Some(frame) = self.network.share_frame(user_id, kind) else { |
| 103 | continue; | 117 | continue; |
| 104 | }; | 118 | }; |
| 105 | if tile.generation == Some(frame.generation) { | 119 | if tile.generation == Some(frame.generation) { |
| @@ -118,6 +132,18 @@ impl Yumush { | |||
| 118 | } | 132 | } |
| 119 | } | 133 | } |
| 120 | 134 | ||
| 135 | + pub(super) fn set_stage(&mut self, stage: Stage, cx: &mut Context<Self>) { | ||
| 136 | + self.chat.stage = stage; | ||
| 137 | + let viewing = self.viewing(); | ||
| 138 | + let quality = tile_quality(stage); | ||
| 139 | + for &(user_id, kind) in self.chat.tiles.keys() { | ||
| 140 | + if viewing != Some((user_id, kind)) { | ||
| 141 | + self.network.set_watch_quality(user_id, kind, quality); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + cx.notify(); | ||
| 145 | + } | ||
| 146 | + | ||
| 121 | pub(super) fn toggle_camera(&mut self, window: &mut Window, cx: &mut Context<Self>) { | 147 | pub(super) fn toggle_camera(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 122 | let network = self.network.clone(); | 148 | let network = self.network.clone(); |
| 123 | let on = network.camera_on(); | 149 | let on = network.camera_on(); |
| @@ -134,6 +160,11 @@ impl Yumush { | |||
| 134 | .detach(); | 160 | .detach(); |
| 135 | } | 161 | } |
| 136 | 162 | ||
| 163 | + pub(super) fn in_stage_chat(&self) -> bool { | ||
| 164 | + self.chat.voice_community().is_some() | ||
| 165 | + && self.chat.selected_community_id == self.chat.voice_community() | ||
| 166 | + } | ||
| 167 | + | ||
| 137 | pub(super) fn stage_sources(&self) -> Vec<(Id, Kind)> { | 168 | pub(super) fn stage_sources(&self) -> Vec<(Id, Kind)> { |
| 138 | let Some(community_id) = self.chat.voice_community() else { | 169 | let Some(community_id) = self.chat.voice_community() else { |
| 139 | return Vec::new(); | 170 | return Vec::new(); |
| @@ -155,14 +186,16 @@ impl Yumush { | |||
| 155 | entity: &Entity<Self>, | 186 | entity: &Entity<Self>, |
| 156 | palette: Palette, | 187 | palette: Palette, |
| 157 | ) -> Option<impl IntoElement> { | 188 | ) -> Option<impl IntoElement> { |
| 158 | - let sources = self.stage_sources(); | 189 | + let shown = match self.chat.stage { |
| 159 | - if self.chat.stage_hidden | 190 | + Stage::Strip => true, |
| 160 | - || sources.is_empty() | 191 | + Stage::Grid => self.chat.viewer.is_some(), |
| 161 | - || self.chat.selected_community_id != self.chat.voice_community() | 192 | + Stage::Hidden => false, |
| 162 | - { | 193 | + }; |
| 194 | + if !shown || !self.in_stage_chat() { | ||
| 163 | return None; | 195 | return None; |
| 164 | } | 196 | } |
| 165 | - let tiles: Vec<_> = sources | 197 | + let tiles: Vec<_> = self |
| 198 | + .stage_sources() | ||
| 166 | .into_iter() | 199 | .into_iter() |
| 167 | .map(|source| stage_tile(entity, self, palette, source)) | 200 | .map(|source| stage_tile(entity, self, palette, source)) |
| 168 | .collect(); | 201 | .collect(); |
| @@ -178,7 +211,92 @@ impl Yumush { | |||
| 178 | .overflow_x_scroll() | 211 | .overflow_x_scroll() |
| 179 | .border_b_1() | 212 | .border_b_1() |
| 180 | .border_color(palette.border) | 213 | .border_color(palette.border) |
| 181 | - .children(tiles), | 214 | + .children(tiles) |
| 215 | + .child(icon_button( | ||
| 216 | + "stage_grid", | ||
| 217 | + palette, | ||
| 218 | + IconName::LayoutDashboard, | ||
| 219 | + "Grid", | ||
| 220 | + entity_action(entity, |yumush, _, cx| { | ||
| 221 | + yumush.set_stage(Stage::Grid, cx) | ||
| 222 | + }), | ||
| 223 | + )), | ||
| 224 | + ) | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + pub(super) fn stage_grid( | ||
| 228 | + &self, | ||
| 229 | + entity: &Entity<Self>, | ||
| 230 | + palette: Palette, | ||
| 231 | + ) -> Option<impl IntoElement> { | ||
| 232 | + if self.chat.stage != Stage::Grid | ||
| 233 | + || !self.in_stage_chat() | ||
| 234 | + || self | ||
| 235 | + .chat | ||
| 236 | + .viewer | ||
| 237 | + .as_ref() | ||
| 238 | + .is_some_and(|viewer| !viewer.fullscreen) | ||
| 239 | + { | ||
| 240 | + return None; | ||
| 241 | + } | ||
| 242 | + let community_id = self.chat.voice_community()?; | ||
| 243 | + let sources = self.stage_sources(); | ||
| 244 | + let cells: Vec<AnyElement> = self | ||
| 245 | + .chat | ||
| 246 | + .voice_ids(community_id) | ||
| 247 | + .iter() | ||
| 248 | + .map(|&user_id| { | ||
| 249 | + let shared = sources.contains(&(user_id, Kind::Camera)); | ||
| 250 | + grid_cell(entity, self, palette, (user_id, Kind::Camera), shared) | ||
| 251 | + }) | ||
| 252 | + .chain( | ||
| 253 | + sources | ||
| 254 | + .iter() | ||
| 255 | + .filter(|(_, kind)| *kind == Kind::Screen) | ||
| 256 | + .map(|&source| grid_cell(entity, self, palette, source, true)), | ||
| 257 | + ) | ||
| 258 | + .collect(); | ||
| 259 | + let columns = ((cells.len() as f32).sqrt().ceil() as usize).max(1); | ||
| 260 | + let rows = cells.len().div_ceil(columns); | ||
| 261 | + let mut cells = cells.into_iter(); | ||
| 262 | + | ||
| 263 | + Some( | ||
| 264 | + div() | ||
| 265 | + .relative() | ||
| 266 | + .flex_1() | ||
| 267 | + .min_h_0() | ||
| 268 | + .p(px(8.)) | ||
| 269 | + .flex() | ||
| 270 | + .flex_col() | ||
| 271 | + .gap(px(8.)) | ||
| 272 | + .children((0..rows).map(|_| { | ||
| 273 | + div() | ||
| 274 | + .flex_1() | ||
| 275 | + .min_h_0() | ||
| 276 | + .flex() | ||
| 277 | + .gap(px(8.)) | ||
| 278 | + .children((0..columns).map(|_| { | ||
| 279 | + cells | ||
| 280 | + .next() | ||
| 281 | + .unwrap_or_else(|| div().flex_1().into_any_element()) | ||
| 282 | + })) | ||
| 283 | + })) | ||
| 284 | + .child( | ||
| 285 | + icon_button( | ||
| 286 | + "stage_minimize", | ||
| 287 | + palette, | ||
| 288 | + IconName::Minimize, | ||
| 289 | + "Strip", | ||
| 290 | + entity_action(entity, |yumush, _, cx| { | ||
| 291 | + yumush.set_stage(Stage::Strip, cx) | ||
| 292 | + }), | ||
| 293 | + ) | ||
| 294 | + .absolute() | ||
| 295 | + .top(px(12.)) | ||
| 296 | + .right(px(12.)) | ||
| 297 | + .bg(palette.panel) | ||
| 298 | + .occlude(), | ||
| 299 | + ), | ||
| 182 | ) | 300 | ) |
| 183 | } | 301 | } |
| 184 | } | 302 | } |
| @@ -188,7 +306,7 @@ pub(super) fn ticker(cx: &mut Context<Yumush>) -> Task<()> { | |||
| 188 | loop { | 306 | loop { |
| 189 | cx.background_executor().timer(FRAME_TICK).await; | 307 | cx.background_executor().timer(FRAME_TICK).await; |
| 190 | if this | 308 | if this |
| 191 | - .update(cx, |yumush, cx| yumush.tick_cameras(cx)) | 309 | + .update(cx, |yumush, cx| yumush.tick_tiles(cx)) |
| 192 | .is_err() | 310 | .is_err() |
| 193 | { | 311 | { |
| 194 | break; | 312 | break; |
| @@ -233,14 +351,12 @@ fn stage_tile( | |||
| 233 | let entity = entity.clone(); | 351 | let entity = entity.clone(); |
| 234 | let focused = yumush.is_watching(user_id, kind); | 352 | let focused = yumush.is_watching(user_id, kind); |
| 235 | let speaking = yumush.chat.waves.speaking.contains(&user_id); | 353 | let speaking = yumush.chat.waves.speaking.contains(&user_id); |
| 236 | - let frame = match kind { | 354 | + let frame = yumush |
| 237 | - Kind::Camera => yumush | 355 | + .chat |
| 238 | - .chat | 356 | + .tiles |
| 239 | - .cameras | 357 | + .get(&(user_id, kind)) |
| 240 | - .get(&user_id) | 358 | + .and_then(|tile| tile.frame.clone()) |
| 241 | - .and_then(|tile| tile.frame.clone()), | 359 | + .or_else(|| yumush.viewer_frame(user_id, kind)); |
| 242 | - Kind::Screen => yumush.viewer_frame(user_id, kind), | ||
| 243 | - }; | ||
| 244 | let user = yumush.chat.author(user_id); | 360 | let user = yumush.chat.author(user_id); |
| 245 | let name = user.map_or("Someone", |user| user.username.as_str()); | 361 | let name = user.map_or("Someone", |user| user.username.as_str()); |
| 246 | let content = match (frame, user) { | 362 | let content = match (frame, user) { |
| @@ -307,3 +423,99 @@ fn stage_tile( | |||
| 307 | .child(name.to_string()), | 423 | .child(name.to_string()), |
| 308 | ) | 424 | ) |
| 309 | } | 425 | } |
| 426 | + | ||
| 427 | +fn grid_cell( | ||
| 428 | + entity: &Entity<Yumush>, | ||
| 429 | + yumush: &Yumush, | ||
| 430 | + palette: Palette, | ||
| 431 | + (user_id, kind): (Id, Kind), | ||
| 432 | + shared: bool, | ||
| 433 | +) -> AnyElement { | ||
| 434 | + let frame = yumush | ||
| 435 | + .chat | ||
| 436 | + .tiles | ||
| 437 | + .get(&(user_id, kind)) | ||
| 438 | + .and_then(|tile| tile.frame.clone()); | ||
| 439 | + let speaking = yumush.chat.waves.speaking.contains(&user_id); | ||
| 440 | + let user = yumush.chat.author(user_id); | ||
| 441 | + let name = user.map_or("Someone", |user| user.username.as_str()); | ||
| 442 | + let content = match (frame, user) { | ||
| 443 | + (Some(frame), _) => img(frame) | ||
| 444 | + .size_full() | ||
| 445 | + .object_fit(ObjectFit::Contain) | ||
| 446 | + .into_any_element(), | ||
| 447 | + (None, Some(user)) => div() | ||
| 448 | + .size_full() | ||
| 449 | + .flex() | ||
| 450 | + .items_center() | ||
| 451 | + .justify_center() | ||
| 452 | + .child(avatar( | ||
| 453 | + palette, | ||
| 454 | + user, | ||
| 455 | + px(64.), | ||
| 456 | + text(24.), | ||
| 457 | + &yumush.chat.avatars, | ||
| 458 | + )) | ||
| 459 | + .into_any_element(), | ||
| 460 | + (None, None) => div().into_any_element(), | ||
| 461 | + }; | ||
| 462 | + | ||
| 463 | + let cell = div() | ||
| 464 | + .id(format!("grid_{user_id}_{kind:?}")) | ||
| 465 | + .relative() | ||
| 466 | + .flex_1() | ||
| 467 | + .min_w_0() | ||
| 468 | + .min_h_0() | ||
| 469 | + .rounded(px(10.)) | ||
| 470 | + .overflow_hidden() | ||
| 471 | + .bg(gpui_kit::black()) | ||
| 472 | + .border_2() | ||
| 473 | + .border_color(if speaking { | ||
| 474 | + palette.ok | ||
| 475 | + } else { | ||
| 476 | + palette.ok.opacity(0.) | ||
| 477 | + }) | ||
| 478 | + .child(content) | ||
| 479 | + .child( | ||
| 480 | + div() | ||
| 481 | + .absolute() | ||
| 482 | + .left(px(6.)) | ||
| 483 | + .bottom(px(6.)) | ||
| 484 | + .px(px(6.)) | ||
| 485 | + .py(px(2.)) | ||
| 486 | + .rounded(px(4.)) | ||
| 487 | + .bg(palette.panel) | ||
| 488 | + .text_size(text(11.)) | ||
| 489 | + .flex() | ||
| 490 | + .items_center() | ||
| 491 | + .gap(px(4.)) | ||
| 492 | + .children((kind == Kind::Screen).then(|| { | ||
| 493 | + Icon::new(share_view::kind_icon(kind)) | ||
| 494 | + .w(px(12.)) | ||
| 495 | + .h(px(12.)) | ||
| 496 | + })) | ||
| 497 | + .child(name.to_string()), | ||
| 498 | + ); | ||
| 499 | + | ||
| 500 | + if shared { | ||
| 501 | + let entity = entity.clone(); | ||
| 502 | + cell.cursor_pointer() | ||
| 503 | + .on_click(move |_, window, cx| { | ||
| 504 | + entity.update(cx, |yumush, cx| { | ||
| 505 | + yumush.toggle_viewer(user_id, kind, window, cx) | ||
| 506 | + }); | ||
| 507 | + }) | ||
| 508 | + .into_any_element() | ||
| 509 | + } else { | ||
| 510 | + cell.into_any_element() | ||
| 511 | + } | ||
| 512 | +} | ||
| 513 | + | ||
| 514 | +pub(super) fn stage_toggle(yumush: &mut Yumush, cx: &mut Context<Yumush>) { | ||
| 515 | + let next = if yumush.chat.stage == Stage::Hidden { | ||
| 516 | + Stage::Strip | ||
| 517 | + } else { | ||
| 518 | + Stage::Hidden | ||
| 519 | + }; | ||
| 520 | + yumush.set_stage(next, cx); | ||
| 521 | +} | ||
crates/client/src/gui/chat.rsmodified+21 -12
| @@ -6,7 +6,7 @@ use std::{ | |||
| 6 | time::{Duration, Instant}, | 6 | time::{Duration, Instant}, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | -use crate::gui::camera_view::CameraTile; | 9 | +use crate::gui::camera_view::{self, Stage, Tile}; |
| 10 | use crate::gui::social::InviteLookup; | 10 | use crate::gui::social::InviteLookup; |
| 11 | use crate::gui::voice_stats::{SAMPLE_HISTORY, StatsTab}; | 11 | use crate::gui::voice_stats::{SAMPLE_HISTORY, StatsTab}; |
| 12 | use crate::gui::wave::Waves; | 12 | use crate::gui::wave::Waves; |
| @@ -148,6 +148,8 @@ pub struct Chat { | |||
| 148 | pub(super) poll_question: Entity<InputState>, | 148 | pub(super) poll_question: Entity<InputState>, |
| 149 | pub(super) poll_options: Vec<Entity<InputState>>, | 149 | pub(super) poll_options: Vec<Entity<InputState>>, |
| 150 | pub(super) poll_multiple: bool, | 150 | pub(super) poll_multiple: bool, |
| 151 | + pub(super) poll_public: bool, | ||
| 152 | + pub(super) my_votes: HashMap<Id, Vec<u32>>, | ||
| 151 | pub(super) poll_expanded: bool, | 153 | pub(super) poll_expanded: bool, |
| 152 | scroll: ScrollHandle, | 154 | scroll: ScrollHandle, |
| 153 | pub(super) jump: Option<Id>, | 155 | pub(super) jump: Option<Id>, |
| @@ -255,9 +257,9 @@ pub struct Chat { | |||
| 255 | pub(super) media: Media, | 257 | pub(super) media: Media, |
| 256 | pub(super) shares: HashMap<Id, Vec<Share>>, | 258 | pub(super) shares: HashMap<Id, Vec<Share>>, |
| 257 | pub(super) viewer: Option<Viewer>, | 259 | pub(super) viewer: Option<Viewer>, |
| 258 | - pub(super) cameras: BTreeMap<Id, CameraTile>, | 260 | + pub(super) tiles: BTreeMap<(Id, Kind), Tile>, |
| 259 | pub(super) camera_task: Option<Task<()>>, | 261 | pub(super) camera_task: Option<Task<()>>, |
| 260 | - pub(super) stage_hidden: bool, | 262 | + pub(super) stage: Stage, |
| 261 | pub(super) typing: HashMap<Id, HashMap<Id, Instant>>, | 263 | pub(super) typing: HashMap<Id, HashMap<Id, Instant>>, |
| 262 | pub(super) typing_sent: HashMap<Id, Instant>, | 264 | pub(super) typing_sent: HashMap<Id, Instant>, |
| 263 | } | 265 | } |
| @@ -351,6 +353,8 @@ impl Chat { | |||
| 351 | new_input("Option", window, cx), | 353 | new_input("Option", window, cx), |
| 352 | ], | 354 | ], |
| 353 | poll_multiple: false, | 355 | poll_multiple: false, |
| 356 | + poll_public: false, | ||
| 357 | + my_votes: HashMap::new(), | ||
| 354 | poll_expanded: false, | 358 | poll_expanded: false, |
| 355 | history: History::End, | 359 | history: History::End, |
| 356 | scroll: ScrollHandle::new(), | 360 | scroll: ScrollHandle::new(), |
| @@ -486,9 +490,9 @@ impl Chat { | |||
| 486 | media: Media::default(), | 490 | media: Media::default(), |
| 487 | shares: HashMap::new(), | 491 | shares: HashMap::new(), |
| 488 | viewer: None, | 492 | viewer: None, |
| 489 | - cameras: BTreeMap::new(), | 493 | + tiles: BTreeMap::new(), |
| 490 | camera_task: None, | 494 | camera_task: None, |
| 491 | - stage_hidden: false, | 495 | + stage: Stage::Strip, |
| 492 | composer: Composer::Compose { reply: None }, | 496 | composer: Composer::Compose { reply: None }, |
| 493 | } | 497 | } |
| 494 | } | 498 | } |
| @@ -714,6 +718,7 @@ impl Chat { | |||
| 714 | self.jump = None; | 718 | self.jump = None; |
| 715 | self.pins.clear(); | 719 | self.pins.clear(); |
| 716 | self.poll_expanded = false; | 720 | self.poll_expanded = false; |
| 721 | + self.my_votes.clear(); | ||
| 717 | self.community_hits.clear(); | 722 | self.community_hits.clear(); |
| 718 | self.history = History::End; | 723 | self.history = History::End; |
| 719 | self.media.leave(); | 724 | self.media.leave(); |
| @@ -1280,9 +1285,12 @@ impl Yumush { | |||
| 1280 | .children(self.poll_banner(entity, themed)) | 1285 | .children(self.poll_banner(entity, themed)) |
| 1281 | .map(|panel| match self.inline_viewer(entity, themed) { | 1286 | .map(|panel| match self.inline_viewer(entity, themed) { |
| 1282 | Some(viewer) => panel.child(viewer), | 1287 | Some(viewer) => panel.child(viewer), |
| 1283 | - None => panel | 1288 | + None => match self.stage_grid(entity, themed) { |
| 1284 | - .child(self.message_area(entity, themed)) | 1289 | + Some(grid) => panel.child(grid), |
| 1285 | - .child(self.composer(entity, themed)), | 1290 | + None => panel |
| 1291 | + .child(self.message_area(entity, themed)) | ||
| 1292 | + .child(self.composer(entity, themed)), | ||
| 1293 | + }, | ||
| 1286 | }), | 1294 | }), |
| 1287 | None => panel.child(empty_state(palette)), | 1295 | None => panel.child(empty_state(palette)), |
| 1288 | }, | 1296 | }, |
| @@ -1713,6 +1721,7 @@ impl Yumush { | |||
| 1713 | let _ = this.update(cx, |yumush, cx| { | 1721 | let _ = this.update(cx, |yumush, cx| { |
| 1714 | if yumush.chat.is_selected(community_id) { | 1722 | if yumush.chat.is_selected(community_id) { |
| 1715 | yumush.chat.pins = pins; | 1723 | yumush.chat.pins = pins; |
| 1724 | + yumush.request_poll_votes(cx); | ||
| 1716 | cx.notify(); | 1725 | cx.notify(); |
| 1717 | } | 1726 | } |
| 1718 | }); | 1727 | }); |
| @@ -1886,6 +1895,7 @@ impl Yumush { | |||
| 1886 | yumush.mark_read(community_id, message_id, cx); | 1895 | yumush.mark_read(community_id, message_id, cx); |
| 1887 | } | 1896 | } |
| 1888 | yumush.request_media(cx); | 1897 | yumush.request_media(cx); |
| 1898 | + yumush.request_poll_votes(cx); | ||
| 1889 | yumush.request_authors(cx); | 1899 | yumush.request_authors(cx); |
| 1890 | cx.notify(); | 1900 | cx.notify(); |
| 1891 | } | 1901 | } |
| @@ -2456,7 +2466,7 @@ impl Yumush { | |||
| 2456 | return None; | 2466 | return None; |
| 2457 | } | 2467 | } |
| 2458 | let stage = self.stage_sources().len(); | 2468 | let stage = self.stage_sources().len(); |
| 2459 | - let hidden = self.chat.stage_hidden; | 2469 | + let hidden = self.chat.stage == Stage::Hidden; |
| 2460 | 2470 | ||
| 2461 | Some( | 2471 | Some( |
| 2462 | div() | 2472 | div() |
| @@ -2483,14 +2493,13 @@ impl Yumush { | |||
| 2483 | ) | 2493 | ) |
| 2484 | })) | 2494 | })) |
| 2485 | .children( | 2495 | .children( |
| 2486 | - (stage > 0 && self.chat.selected_community_id == self.chat.voice_community()) | 2496 | + self.in_stage_chat() |
| 2487 | .then(|| { | 2497 | .then(|| { |
| 2488 | clickable( | 2498 | clickable( |
| 2489 | "stage_toggle", | 2499 | "stage_toggle", |
| 2490 | palette, | 2500 | palette, |
| 2491 | entity_action(entity, |yumush: &mut Yumush, _, cx| { | 2501 | entity_action(entity, |yumush: &mut Yumush, _, cx| { |
| 2492 | - yumush.chat.stage_hidden = !yumush.chat.stage_hidden; | 2502 | + camera_view::stage_toggle(yumush, cx) |
| 2493 | - cx.notify(); | ||
| 2494 | }), | 2503 | }), |
| 2495 | ) | 2504 | ) |
| 2496 | .tip(if hidden { "Show stage" } else { "Hide stage" }) | 2505 | .tip(if hidden { "Show stage" } else { "Hide stage" }) |
crates/client/src/gui/composer.rsmodified+36 -9
| @@ -565,6 +565,7 @@ pub fn poll_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 565 | let question = chat.poll_question.clone(); | 565 | let question = chat.poll_question.clone(); |
| 566 | let options = chat.poll_options.clone(); | 566 | let options = chat.poll_options.clone(); |
| 567 | let multiple = chat.poll_multiple; | 567 | let multiple = chat.poll_multiple; |
| 568 | + let public = chat.poll_public; | ||
| 568 | let entity = entity.clone(); | 569 | let entity = entity.clone(); |
| 569 | 570 | ||
| 570 | Popover::new("poll_popover") | 571 | Popover::new("poll_popover") |
| @@ -579,6 +580,7 @@ pub fn poll_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 579 | .content(move |_, _, cx| { | 580 | .content(move |_, _, cx| { |
| 580 | let popover = cx.entity(); | 581 | let popover = cx.entity(); |
| 581 | let toggle = entity.clone(); | 582 | let toggle = entity.clone(); |
| 583 | + let toggle_public = entity.clone(); | ||
| 582 | let add = entity.clone(); | 584 | let add = entity.clone(); |
| 583 | let submit = entity.clone(); | 585 | let submit = entity.clone(); |
| 584 | pop_in( | 586 | pop_in( |
| @@ -623,15 +625,32 @@ pub fn poll_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 623 | .items_center() | 625 | .items_center() |
| 624 | .justify_between() | 626 | .justify_between() |
| 625 | .child( | 627 | .child( |
| 626 | - Checkbox::new("poll_multiple") | 628 | + div() |
| 627 | - .label("Multiple answers") | 629 | + .flex() |
| 628 | - .checked(multiple) | 630 | + .items_center() |
| 629 | - .on_click(move |_, _, cx| { | 631 | + .gap(px(12.)) |
| 630 | - toggle.update(cx, |yumush, cx| { | 632 | + .child( |
| 631 | - yumush.chat.poll_multiple = !yumush.chat.poll_multiple; | 633 | + Checkbox::new("poll_multiple") |
| 632 | - cx.notify(); | 634 | + .label("Multiple answers") |
| 633 | - }) | 635 | + .checked(multiple) |
| 634 | - }), | 636 | + .on_click(move |_, _, cx| { |
| 637 | + toggle.update(cx, |yumush, cx| { | ||
| 638 | + yumush.chat.poll_multiple = | ||
| 639 | + !yumush.chat.poll_multiple; | ||
| 640 | + cx.notify(); | ||
| 641 | + }) | ||
| 642 | + }), | ||
| 643 | + ) | ||
| 644 | + .child( | ||
| 645 | + Checkbox::new("poll_public") | ||
| 646 | + .label("Show voters") | ||
| 647 | + .checked(public) | ||
| 648 | + .on_click(move |_, _, cx| { | ||
| 649 | + toggle_public.update(cx, |yumush, cx| { | ||
| 650 | + yumush.toggle_poll_public(cx) | ||
| 651 | + }) | ||
| 652 | + }), | ||
| 653 | + ), | ||
| 635 | ) | 654 | ) |
| 636 | .children((options.len() < MAXIMUM_POLL_OPTIONS).then(|| { | 655 | .children((options.len() < MAXIMUM_POLL_OPTIONS).then(|| { |
| 637 | icon_button( | 656 | icon_button( |
| @@ -699,6 +718,7 @@ impl Yumush { | |||
| 699 | return false; | 718 | return false; |
| 700 | } | 719 | } |
| 701 | let multiple = self.chat.poll_multiple; | 720 | let multiple = self.chat.poll_multiple; |
| 721 | + let public = self.chat.poll_public; | ||
| 702 | let network = self.network.clone(); | 722 | let network = self.network.clone(); |
| 703 | 723 | ||
| 704 | spawn_done(window, cx, async move { | 724 | spawn_done(window, cx, async move { |
| @@ -708,6 +728,7 @@ impl Yumush { | |||
| 708 | question, | 728 | question, |
| 709 | options, | 729 | options, |
| 710 | multiple, | 730 | multiple, |
| 731 | + public, | ||
| 711 | }) | 732 | }) |
| 712 | .await | 733 | .await |
| 713 | }); | 734 | }); |
| @@ -720,7 +741,13 @@ impl Yumush { | |||
| 720 | input.update(cx, |state, cx| state.set_value("", window, cx)); | 741 | input.update(cx, |state, cx| state.set_value("", window, cx)); |
| 721 | } | 742 | } |
| 722 | self.chat.poll_multiple = false; | 743 | self.chat.poll_multiple = false; |
| 744 | + self.chat.poll_public = false; | ||
| 723 | cx.notify(); | 745 | cx.notify(); |
| 724 | true | 746 | true |
| 725 | } | 747 | } |
| 748 | + | ||
| 749 | + pub(super) fn toggle_poll_public(&mut self, cx: &mut Context<Self>) { | ||
| 750 | + self.chat.poll_public = !self.chat.poll_public; | ||
| 751 | + cx.notify(); | ||
| 752 | + } | ||
| 726 | } | 753 | } |
crates/client/src/gui/poll.rsmodified+142 -31
| @@ -1,7 +1,5 @@ | |||
| 1 | use common::model::Id; | 1 | use common::model::Id; |
| 2 | -use std::collections::HashSet; | 2 | +use common::call::{ClosePoll, MyVotes, Vote}; |
| 3 | - | ||
| 4 | -use common::call::{ClosePoll, Vote}; | ||
| 5 | use common::model::{Message, Poll, Rank, User}; | 3 | use common::model::{Message, Poll, Rank, User}; |
| 6 | use gpui_kit::{ | 4 | use gpui_kit::{ |
| 7 | Context, Div, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, Styled, | 5 | Context, Div, Entity, FontWeight, InteractiveElement, IntoElement, ParentElement, Styled, |
| @@ -9,18 +7,14 @@ use gpui_kit::{ | |||
| 9 | }; | 7 | }; |
| 10 | 8 | ||
| 11 | use super::{ | 9 | use super::{ |
| 12 | - Palette, Yumush, | 10 | + Palette, Tooltip as _, Yumush, avatar, |
| 13 | chat::Chat, | 11 | chat::Chat, |
| 14 | clickable, text, | 12 | clickable, text, |
| 15 | widget::{icon_button, spawn_done}, | 13 | widget::{icon_button, spawn_done}, |
| 16 | }; | 14 | }; |
| 17 | 15 | ||
| 18 | pub fn voter_count(poll: &Poll) -> usize { | 16 | pub fn voter_count(poll: &Poll) -> usize { |
| 19 | - poll.options | 17 | + poll.voters as usize |
| 20 | - .iter() | ||
| 21 | - .flat_map(|option| &option.voter_ids) | ||
| 22 | - .collect::<HashSet<_>>() | ||
| 23 | - .len() | ||
| 24 | } | 18 | } |
| 25 | 19 | ||
| 26 | fn my_positions(poll: &Poll, user_id: Id) -> Vec<u32> { | 20 | fn my_positions(poll: &Poll, user_id: Id) -> Vec<u32> { |
| @@ -54,6 +48,15 @@ pub enum PollMode<'a> { | |||
| 54 | Snapshot(Id), | 48 | Snapshot(Id), |
| 55 | } | 49 | } |
| 56 | 50 | ||
| 51 | +fn status_icon(id: String, icon: IconName, tip: &'static str, palette: Palette) -> impl IntoElement { | ||
| 52 | + div() | ||
| 53 | + .id(id) | ||
| 54 | + .tip(tip) | ||
| 55 | + .flex_shrink_0() | ||
| 56 | + .text_color(palette.muted) | ||
| 57 | + .child(Icon::new(icon).w(px(12.)).h(px(12.))) | ||
| 58 | +} | ||
| 59 | + | ||
| 57 | pub fn poll_card( | 60 | pub fn poll_card( |
| 58 | poll: &Poll, | 61 | poll: &Poll, |
| 59 | mode: PollMode, | 62 | mode: PollMode, |
| @@ -64,11 +67,17 @@ pub fn poll_card( | |||
| 64 | ) -> impl IntoElement { | 67 | ) -> impl IntoElement { |
| 65 | let voters = voter_count(poll); | 68 | let voters = voter_count(poll); |
| 66 | let me_id = me.map(|me| me.id); | 69 | let me_id = me.map(|me| me.id); |
| 67 | - let mine = me_id.map(|id| my_positions(poll, id)).unwrap_or_default(); | ||
| 68 | let (key, live) = match mode { | 70 | let (key, live) = match mode { |
| 69 | PollMode::Live(message) => (message.id.to_string(), Some(message)), | 71 | PollMode::Live(message) => (message.id.to_string(), Some(message)), |
| 70 | PollMode::Snapshot(id) => (format!("snapshot_{id}"), None), | 72 | PollMode::Snapshot(id) => (format!("snapshot_{id}"), None), |
| 71 | }; | 73 | }; |
| 74 | + let mine = match me_id { | ||
| 75 | + Some(id) if poll.public => my_positions(poll, id), | ||
| 76 | + _ => live | ||
| 77 | + .and_then(|message| chat.my_votes.get(&message.id)) | ||
| 78 | + .cloned() | ||
| 79 | + .unwrap_or_default(), | ||
| 80 | + }; | ||
| 72 | let vote_id = live | 81 | let vote_id = live |
| 73 | .filter(|_| !poll.closed && me_id.is_some()) | 82 | .filter(|_| !poll.closed && me_id.is_some()) |
| 74 | .map(|message| message.id); | 83 | .map(|message| message.id); |
| @@ -82,12 +91,16 @@ pub fn poll_card( | |||
| 82 | .map(|message| message.id); | 91 | .map(|message| message.id); |
| 83 | 92 | ||
| 84 | let rows = poll.options.iter().enumerate().map(|(position, option)| { | 93 | let rows = poll.options.iter().enumerate().map(|(position, option)| { |
| 85 | - let count = option.voter_ids.len(); | 94 | + let share = percent(option.votes as usize, voters); |
| 86 | - let share = percent(count, voters); | ||
| 87 | let picked = mine.contains(&(position as u32)); | 95 | let picked = mine.contains(&(position as u32)); |
| 88 | let next = me_id | 96 | let next = me_id |
| 89 | .map(|_| next_votes(&mine, position as u32, poll.multiple)) | 97 | .map(|_| next_votes(&mine, position as u32, poll.multiple)) |
| 90 | .unwrap_or_default(); | 98 | .unwrap_or_default(); |
| 99 | + let voters_here: &[Id] = if poll.public { | ||
| 100 | + &option.voter_ids | ||
| 101 | + } else { | ||
| 102 | + &[] | ||
| 103 | + }; | ||
| 91 | let entity = entity.clone(); | 104 | let entity = entity.clone(); |
| 92 | let id = format!("poll_option_{key}_{position}"); | 105 | let id = format!("poll_option_{key}_{position}"); |
| 93 | match vote_id { | 106 | match vote_id { |
| @@ -98,12 +111,18 @@ pub fn poll_card( | |||
| 98 | None => div().id(id), | 111 | None => div().id(id), |
| 99 | } | 112 | } |
| 100 | .relative() | 113 | .relative() |
| 101 | - .h(px(32.)) | 114 | + .h(px(36.)) |
| 102 | .px(px(10.)) | 115 | .px(px(10.)) |
| 103 | .flex() | 116 | .flex() |
| 104 | .items_center() | 117 | .items_center() |
| 105 | .gap(px(8.)) | 118 | .gap(px(8.)) |
| 106 | - .rounded(px(6.)) | 119 | + .rounded(px(8.)) |
| 120 | + .border_1() | ||
| 121 | + .border_color(if picked { | ||
| 122 | + palette.accent | ||
| 123 | + } else { | ||
| 124 | + palette.accent.opacity(0.) | ||
| 125 | + }) | ||
| 107 | .overflow_hidden() | 126 | .overflow_hidden() |
| 108 | .bg(palette.field) | 127 | .bg(palette.field) |
| 109 | .child( | 128 | .child( |
| @@ -143,6 +162,28 @@ pub fn poll_card( | |||
| 143 | .truncate() | 162 | .truncate() |
| 144 | .child(option.text.clone()), | 163 | .child(option.text.clone()), |
| 145 | ) | 164 | ) |
| 165 | + .children((!voters_here.is_empty()).then(|| { | ||
| 166 | + div() | ||
| 167 | + .flex() | ||
| 168 | + .items_center() | ||
| 169 | + .children(voters_here.iter().take(3).enumerate().filter_map( | ||
| 170 | + |(index, id)| { | ||
| 171 | + chat.author(*id).map(|user| { | ||
| 172 | + avatar(palette, user, px(18.), text(8.), &chat.avatars) | ||
| 173 | + .border_2() | ||
| 174 | + .border_color(palette.panel) | ||
| 175 | + .when(index > 0, |el| el.ml(px(-6.))) | ||
| 176 | + }) | ||
| 177 | + }, | ||
| 178 | + )) | ||
| 179 | + .children((voters_here.len() > 3).then(|| { | ||
| 180 | + div() | ||
| 181 | + .ml(px(4.)) | ||
| 182 | + .text_size(text(11.)) | ||
| 183 | + .text_color(palette.muted) | ||
| 184 | + .child(format!("+{}", voters_here.len() - 3)) | ||
| 185 | + })) | ||
| 186 | + })) | ||
| 146 | .child( | 187 | .child( |
| 147 | div() | 188 | div() |
| 148 | .flex_shrink_0() | 189 | .flex_shrink_0() |
| @@ -159,11 +200,14 @@ pub fn poll_card( | |||
| 159 | .justify_between() | 200 | .justify_between() |
| 160 | .text_size(text(12.)) | 201 | .text_size(text(12.)) |
| 161 | .text_color(palette.muted) | 202 | .text_color(palette.muted) |
| 162 | - .child(match voters { | 203 | + .child( |
| 163 | - 1 => "1 vote".to_string(), | 204 | + div() |
| 164 | - _ => format!("{voters} votes"), | 205 | + .flex() |
| 165 | - }) | 206 | + .items_center() |
| 166 | - .children(poll.closed.then_some("Closed")) | 207 | + .gap(px(4.)) |
| 208 | + .child(Icon::new(IconName::Users).w(px(12.)).h(px(12.))) | ||
| 209 | + .child(format!("{voters}")), | ||
| 210 | + ) | ||
| 167 | .children(close_id.map(|close_id| { | 211 | .children(close_id.map(|close_id| { |
| 168 | let close_entity = entity.clone(); | 212 | let close_entity = entity.clone(); |
| 169 | icon_button( | 213 | icon_button( |
| @@ -177,32 +221,64 @@ pub fn poll_card( | |||
| 177 | ) | 221 | ) |
| 178 | })); | 222 | })); |
| 179 | 223 | ||
| 224 | + let (visibility, visibility_tip) = if poll.public { | ||
| 225 | + (IconName::Eye, "Voters visible") | ||
| 226 | + } else { | ||
| 227 | + (IconName::EyeOff, "Anonymous") | ||
| 228 | + }; | ||
| 229 | + | ||
| 180 | div() | 230 | div() |
| 181 | .flex() | 231 | .flex() |
| 182 | .flex_col() | 232 | .flex_col() |
| 183 | - .gap(px(6.)) | 233 | + .gap(px(8.)) |
| 184 | - .p(px(12.)) | 234 | + .p(px(14.)) |
| 185 | - .w(px(320.)) | 235 | + .w(px(360.)) |
| 186 | .max_w_full() | 236 | .max_w_full() |
| 187 | - .rounded(px(10.)) | 237 | + .rounded(px(12.)) |
| 238 | + .border_1() | ||
| 239 | + .border_color(palette.border) | ||
| 188 | .bg(palette.panel) | 240 | .bg(palette.panel) |
| 189 | .child( | 241 | .child( |
| 190 | div() | 242 | div() |
| 191 | .flex() | 243 | .flex() |
| 192 | - .items_center() | 244 | + .items_start() |
| 245 | + .justify_between() | ||
| 193 | .gap(px(8.)) | 246 | .gap(px(8.)) |
| 194 | - .mb(px(2.)) | ||
| 195 | - .child( | ||
| 196 | - div() | ||
| 197 | - .flex_shrink_0() | ||
| 198 | - .text_color(palette.accent) | ||
| 199 | - .child(Icon::new(IconName::ChartBar).w(px(14.)).h(px(14.))), | ||
| 200 | - ) | ||
| 201 | .child( | 247 | .child( |
| 202 | div() | 248 | div() |
| 203 | .min_w_0() | 249 | .min_w_0() |
| 204 | .font_weight(FontWeight::SEMIBOLD) | 250 | .font_weight(FontWeight::SEMIBOLD) |
| 251 | + .text_size(text(15.)) | ||
| 205 | .child(poll.question.clone()), | 252 | .child(poll.question.clone()), |
| 253 | + ) | ||
| 254 | + .child( | ||
| 255 | + div() | ||
| 256 | + .flex_shrink_0() | ||
| 257 | + .flex() | ||
| 258 | + .items_center() | ||
| 259 | + .gap(px(6.)) | ||
| 260 | + .child(status_icon( | ||
| 261 | + format!("poll_public_{key}"), | ||
| 262 | + visibility, | ||
| 263 | + visibility_tip, | ||
| 264 | + palette, | ||
| 265 | + )) | ||
| 266 | + .children(poll.multiple.then(|| { | ||
| 267 | + status_icon( | ||
| 268 | + format!("poll_multiple_{key}"), | ||
| 269 | + IconName::ListChecks, | ||
| 270 | + "Multiple choice", | ||
| 271 | + palette, | ||
| 272 | + ) | ||
| 273 | + })) | ||
| 274 | + .children(poll.closed.then(|| { | ||
| 275 | + status_icon( | ||
| 276 | + format!("poll_closed_{key}"), | ||
| 277 | + IconName::Lock, | ||
| 278 | + "Closed", | ||
| 279 | + palette, | ||
| 280 | + ) | ||
| 281 | + })), | ||
| 206 | ), | 282 | ), |
| 207 | ) | 283 | ) |
| 208 | .children(rows) | 284 | .children(rows) |
| @@ -307,6 +383,40 @@ impl Yumush { | |||
| 307 | ) | 383 | ) |
| 308 | } | 384 | } |
| 309 | 385 | ||
| 386 | + pub(super) fn request_poll_votes(&mut self, cx: &mut Context<Self>) { | ||
| 387 | + let anonymous: Vec<Id> = self | ||
| 388 | + .chat | ||
| 389 | + .messages | ||
| 390 | + .iter() | ||
| 391 | + .chain(&self.chat.pins) | ||
| 392 | + .filter(|message| message.poll.as_ref().is_some_and(|poll| !poll.public)) | ||
| 393 | + .map(|message| message.id) | ||
| 394 | + .collect(); | ||
| 395 | + for message_id in anonymous { | ||
| 396 | + self.request_my_votes(message_id, cx); | ||
| 397 | + } | ||
| 398 | + } | ||
| 399 | + | ||
| 400 | + pub(super) fn request_my_votes(&mut self, message_id: Id, cx: &mut Context<Self>) { | ||
| 401 | + if self.chat.my_votes.contains_key(&message_id) { | ||
| 402 | + return; | ||
| 403 | + } | ||
| 404 | + self.chat.my_votes.insert(message_id, Vec::new()); | ||
| 405 | + | ||
| 406 | + let network = self.network.clone(); | ||
| 407 | + | ||
| 408 | + cx.spawn(async move |this, cx| { | ||
| 409 | + let Ok(positions) = network.call(MyVotes { message_id }).await else { | ||
| 410 | + return; | ||
| 411 | + }; | ||
| 412 | + let _ = this.update(cx, |yumush, cx| { | ||
| 413 | + yumush.chat.my_votes.insert(message_id, positions); | ||
| 414 | + cx.notify(); | ||
| 415 | + }); | ||
| 416 | + }) | ||
| 417 | + .detach(); | ||
| 418 | + } | ||
| 419 | + | ||
| 310 | pub(super) fn vote( | 420 | pub(super) fn vote( |
| 311 | &mut self, | 421 | &mut self, |
| 312 | message_id: Id, | 422 | message_id: Id, |
| @@ -314,6 +424,7 @@ impl Yumush { | |||
| 314 | window: &mut Window, | 424 | window: &mut Window, |
| 315 | cx: &mut Context<Self>, | 425 | cx: &mut Context<Self>, |
| 316 | ) { | 426 | ) { |
| 427 | + self.chat.my_votes.insert(message_id, positions.clone()); | ||
| 317 | let network = self.network.clone(); | 428 | let network = self.network.clone(); |
| 318 | 429 | ||
| 319 | spawn_done(window, cx, async move { | 430 | spawn_done(window, cx, async move { |
crates/client/src/gui/share_view.rsmodified+10 -7
| @@ -82,7 +82,7 @@ pub(super) struct Viewer { | |||
| 82 | kind: Kind, | 82 | kind: Kind, |
| 83 | generation: Option<u64>, | 83 | generation: Option<u64>, |
| 84 | frame: Option<Arc<RenderImage>>, | 84 | frame: Option<Arc<RenderImage>>, |
| 85 | - fullscreen: bool, | 85 | + pub(super) fullscreen: bool, |
| 86 | volume: Entity<SliderState>, | 86 | volume: Entity<SliderState>, |
| 87 | _subscriptions: Vec<Subscription>, | 87 | _subscriptions: Vec<Subscription>, |
| 88 | _tick: Task<()>, | 88 | _tick: Task<()>, |
| @@ -207,12 +207,11 @@ impl Yumush { | |||
| 207 | .and_then(|viewer| viewer.frame.clone()) | 207 | .and_then(|viewer| viewer.frame.clone()) |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | - pub(super) fn viewing_camera(&self) -> Option<Id> { | 210 | + pub(super) fn viewing(&self) -> Option<(Id, Kind)> { |
| 211 | self.chat | 211 | self.chat |
| 212 | .viewer | 212 | .viewer |
| 213 | .as_ref() | 213 | .as_ref() |
| 214 | - .filter(|viewer| viewer.kind == Kind::Camera) | 214 | + .map(|viewer| (viewer.user_id, viewer.kind)) |
| 215 | - .map(|viewer| viewer.user_id) | ||
| 216 | } | 215 | } |
| 217 | 216 | ||
| 218 | pub(super) fn toggle_viewer( | 217 | pub(super) fn toggle_viewer( |
| @@ -268,7 +267,7 @@ impl Yumush { | |||
| 268 | let watch = WatchQuality::Auto; | 267 | let watch = WatchQuality::Auto; |
| 269 | let volume = self.settings.share.volume; | 268 | let volume = self.settings.share.volume; |
| 270 | let choice = self.settings.voice.choice.clone(); | 269 | let choice = self.settings.voice.choice.clone(); |
| 271 | - if kind == Kind::Camera && self.chat.cameras.contains_key(&user_id) { | 270 | + if self.chat.tiles.contains_key(&(user_id, kind)) { |
| 272 | network.set_watch_quality(user_id, kind, watch); | 271 | network.set_watch_quality(user_id, kind, watch); |
| 273 | } else { | 272 | } else { |
| 274 | cx.spawn_in(window, async move |this, cx| { | 273 | cx.spawn_in(window, async move |this, cx| { |
| @@ -297,8 +296,12 @@ impl Yumush { | |||
| 297 | cx.defer(move |cx| cx.drop_image(frame, None)); | 296 | cx.defer(move |cx| cx.drop_image(frame, None)); |
| 298 | } | 297 | } |
| 299 | let network = self.network.clone(); | 298 | let network = self.network.clone(); |
| 300 | - if viewer.kind == Kind::Camera && self.chat.cameras.contains_key(&viewer.user_id) { | 299 | + if self.chat.tiles.contains_key(&(viewer.user_id, viewer.kind)) { |
| 301 | - network.set_watch_quality(viewer.user_id, viewer.kind, camera_view::CAMERA_TILE); | 300 | + network.set_watch_quality( |
| 301 | + viewer.user_id, | ||
| 302 | + viewer.kind, | ||
| 303 | + camera_view::tile_quality(self.chat.stage), | ||
| 304 | + ); | ||
| 302 | } else { | 305 | } else { |
| 303 | let user_id = viewer.user_id; | 306 | let user_id = viewer.user_id; |
| 304 | let kind = viewer.kind; | 307 | let kind = viewer.kind; |
crates/common/src/call.rsmodified+7 -0
| @@ -221,6 +221,7 @@ pub struct CreatePoll { | |||
| 221 | pub question: String, | 221 | pub question: String, |
| 222 | pub options: Vec<String>, | 222 | pub options: Vec<String>, |
| 223 | pub multiple: bool, | 223 | pub multiple: bool, |
| 224 | + pub public: bool, | ||
| 224 | } | 225 | } |
| 225 | 226 | ||
| 226 | #[derive(Debug, Clone, Encode, Decode)] | 227 | #[derive(Debug, Clone, Encode, Decode)] |
| @@ -234,6 +235,11 @@ pub struct ClosePoll { | |||
| 234 | pub message_id: Id, | 235 | pub message_id: Id, |
| 235 | } | 236 | } |
| 236 | 237 | ||
| 238 | +#[derive(Debug, Clone, Encode, Decode)] | ||
| 239 | +pub struct MyVotes { | ||
| 240 | + pub message_id: Id, | ||
| 241 | +} | ||
| 242 | + | ||
| 237 | #[derive(Debug, Clone, Encode, Decode)] | 243 | #[derive(Debug, Clone, Encode, Decode)] |
| 238 | pub struct React { | 244 | pub struct React { |
| 239 | pub message_id: Id, | 245 | pub message_id: Id, |
| @@ -648,6 +654,7 @@ calls! { | |||
| 648 | CreatePoll: User -> Message, |c| validate_poll(&c.question, &c.options); | 654 | CreatePoll: User -> Message, |c| validate_poll(&c.question, &c.options); |
| 649 | Vote: User -> (); | 655 | Vote: User -> (); |
| 650 | ClosePoll: User -> (); | 656 | ClosePoll: User -> (); |
| 657 | + MyVotes: User -> Vec<u32>; | ||
| 651 | React: User -> (), |c| validate_reaction(&c.emoji); | 658 | React: User -> (), |c| validate_reaction(&c.emoji); |
| 652 | Pin: User -> (); | 659 | Pin: User -> (); |
| 653 | ListPins: User -> Vec<Message>; | 660 | ListPins: User -> Vec<Message>; |
crates/common/src/model.rsmodified+3 -0
| @@ -566,6 +566,7 @@ pub struct Reaction { | |||
| 566 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | 566 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] |
| 567 | pub struct PollOption { | 567 | pub struct PollOption { |
| 568 | pub text: String, | 568 | pub text: String, |
| 569 | + pub votes: u32, | ||
| 569 | pub voter_ids: Vec<Id>, | 570 | pub voter_ids: Vec<Id>, |
| 570 | } | 571 | } |
| 571 | 572 | ||
| @@ -575,6 +576,8 @@ pub struct Poll { | |||
| 575 | pub options: Vec<PollOption>, | 576 | pub options: Vec<PollOption>, |
| 576 | pub multiple: bool, | 577 | pub multiple: bool, |
| 577 | pub closed: bool, | 578 | pub closed: bool, |
| 579 | + pub public: bool, | ||
| 580 | + pub voters: u32, | ||
| 578 | } | 581 | } |
| 579 | 582 | ||
| 580 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | 583 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] |
crates/server/src/call/message.rsmodified+13 -1
| @@ -1,7 +1,7 @@ | |||
| 1 | use common::{ | 1 | use common::{ |
| 2 | call::{ | 2 | call::{ |
| 3 | ClosePoll, CreateMessage, CreatePoll, DeleteMessage, ForwardMessages, ListMessages, | 3 | ClosePoll, CreateMessage, CreatePoll, DeleteMessage, ForwardMessages, ListMessages, |
| 4 | - ListPins, ListUnreads, MarkRead, Pin, React, Typing, UpdateMessage, Vote, | 4 | + ListPins, ListUnreads, MarkRead, MyVotes, Pin, React, Typing, UpdateMessage, Vote, |
| 5 | }, | 5 | }, |
| 6 | error::Error, | 6 | error::Error, |
| 7 | event::Event, | 7 | event::Event, |
| @@ -166,6 +166,7 @@ impl Handle for CreatePoll { | |||
| 166 | &self.question, | 166 | &self.question, |
| 167 | &self.options, | 167 | &self.options, |
| 168 | self.multiple, | 168 | self.multiple, |
| 169 | + self.public, | ||
| 169 | cx.db, | 170 | cx.db, |
| 170 | ) | 171 | ) |
| 171 | .await?; | 172 | .await?; |
| @@ -192,6 +193,17 @@ impl Handle for Vote { | |||
| 192 | } | 193 | } |
| 193 | } | 194 | } |
| 194 | 195 | ||
| 196 | +impl Handle for MyVotes { | ||
| 197 | + async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<Vec<u32>, ServerError> { | ||
| 198 | + let me = me.user()?; | ||
| 199 | + let existing = db::message::read(self.message_id, cx.db).await?; | ||
| 200 | + ensure(permission::can_read( | ||
| 201 | + actor_rank(&me, existing.community_id, cx.db).await?, | ||
| 202 | + ))?; | ||
| 203 | + db::poll::my_votes(self.message_id, me.id, cx.db).await | ||
| 204 | + } | ||
| 205 | +} | ||
| 206 | + | ||
| 195 | impl Handle for ClosePoll { | 207 | impl Handle for ClosePoll { |
| 196 | async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> { | 208 | async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> { |
| 197 | let me = me.user()?; | 209 | let me = me.user()?; |
crates/server/src/call/mod.rsmodified+1 -0
| @@ -138,6 +138,7 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> { | |||
| 138 | Request::CreatePoll(call) => serve(call, cx).await, | 138 | Request::CreatePoll(call) => serve(call, cx).await, |
| 139 | Request::Vote(call) => serve(call, cx).await, | 139 | Request::Vote(call) => serve(call, cx).await, |
| 140 | Request::ClosePoll(call) => serve(call, cx).await, | 140 | Request::ClosePoll(call) => serve(call, cx).await, |
| 141 | + Request::MyVotes(call) => serve(call, cx).await, | ||
| 141 | Request::React(call) => serve(call, cx).await, | 142 | Request::React(call) => serve(call, cx).await, |
| 142 | Request::Pin(call) => serve(call, cx).await, | 143 | Request::Pin(call) => serve(call, cx).await, |
| 143 | Request::ListPins(call) => serve(call, cx).await, | 144 | Request::ListPins(call) => serve(call, cx).await, |
crates/server/src/db/message.rsmodified+2 -1
| @@ -192,10 +192,11 @@ pub async fn create_poll( | |||
| 192 | question: &str, | 192 | question: &str, |
| 193 | options: &[String], | 193 | options: &[String], |
| 194 | multiple: bool, | 194 | multiple: bool, |
| 195 | + public: bool, | ||
| 195 | db: &Connection, | 196 | db: &Connection, |
| 196 | ) -> Result<Message, ServerError> { | 197 | ) -> Result<Message, ServerError> { |
| 197 | let id = insert(user_id, community_id, "", None, db).await?; | 198 | let id = insert(user_id, community_id, "", None, db).await?; |
| 198 | - poll::create(id, question, options, multiple, db).await?; | 199 | + poll::create(id, question, options, multiple, public, db).await?; |
| 199 | 200 | ||
| 200 | read(id, db).await | 201 | read(id, db).await |
| 201 | } | 202 | } |
crates/server/src/db/poll.rsmodified+41 -6
| @@ -1,3 +1,5 @@ | |||
| 1 | +use std::collections::HashSet; | ||
| 2 | + | ||
| 1 | use common::{ | 3 | use common::{ |
| 2 | error::Error, | 4 | error::Error, |
| 3 | model::{Id, Poll, PollOption}, | 5 | model::{Id, Poll, PollOption}, |
| @@ -11,12 +13,13 @@ pub async fn create( | |||
| 11 | question: &str, | 13 | question: &str, |
| 12 | options: &[String], | 14 | options: &[String], |
| 13 | multiple: bool, | 15 | multiple: bool, |
| 16 | + public: bool, | ||
| 14 | db: &Connection, | 17 | db: &Connection, |
| 15 | ) -> Result<(), ServerError> { | 18 | ) -> Result<(), ServerError> { |
| 16 | run( | 19 | run( |
| 17 | db, | 20 | db, |
| 18 | - "INSERT INTO poll (message_id, question, multiple) VALUES (?1, ?2, ?3)", | 21 | + "INSERT INTO poll (message_id, question, multiple, public) VALUES (?1, ?2, ?3, ?4)", |
| 19 | - (message_id, question, multiple), | 22 | + (message_id, question, multiple, public), |
| 20 | ) | 23 | ) |
| 21 | .await?; | 24 | .await?; |
| 22 | for (position, text) in (0u32..).zip(options) { | 25 | for (position, text) in (0u32..).zip(options) { |
| @@ -32,11 +35,18 @@ pub async fn create( | |||
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerError> { | 37 | pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerError> { |
| 35 | - let Some((question, multiple, closed)) = maybe( | 38 | + let Some((question, multiple, closed, public)) = maybe( |
| 36 | db, | 39 | db, |
| 37 | - "SELECT question, multiple, closed FROM poll WHERE message_id = ?1", | 40 | + "SELECT question, multiple, closed, public FROM poll WHERE message_id = ?1", |
| 38 | (message_id,), | 41 | (message_id,), |
| 39 | - |r| Ok((r.get::<String>()?, r.get::<bool>()?, r.get::<bool>()?)), | 42 | + |r| { |
| 43 | + Ok(( | ||
| 44 | + r.get::<String>()?, | ||
| 45 | + r.get::<bool>()?, | ||
| 46 | + r.get::<bool>()?, | ||
| 47 | + r.get::<bool>()?, | ||
| 48 | + )) | ||
| 49 | + }, | ||
| 40 | ) | 50 | ) |
| 41 | .await? | 51 | .await? |
| 42 | else { | 52 | else { |
| @@ -50,6 +60,7 @@ pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerE | |||
| 50 | |r| { | 60 | |r| { |
| 51 | Ok(PollOption { | 61 | Ok(PollOption { |
| 52 | text: r.get()?, | 62 | text: r.get()?, |
| 63 | + votes: 0, | ||
| 53 | voter_ids: Vec::new(), | 64 | voter_ids: Vec::new(), |
| 54 | }) | 65 | }) |
| 55 | }, | 66 | }, |
| @@ -62,9 +73,17 @@ pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerE | |||
| 62 | |r| Ok((r.get()?, r.get()?)), | 73 | |r| Ok((r.get()?, r.get()?)), |
| 63 | ) | 74 | ) |
| 64 | .await?; | 75 | .await?; |
| 76 | + let voters = votes | ||
| 77 | + .iter() | ||
| 78 | + .map(|(_, user_id)| user_id) | ||
| 79 | + .collect::<HashSet<_>>() | ||
| 80 | + .len() as u32; | ||
| 65 | for (position, user_id) in votes { | 81 | for (position, user_id) in votes { |
| 66 | if let Some(option) = options.get_mut(position as usize) { | 82 | if let Some(option) = options.get_mut(position as usize) { |
| 67 | - option.voter_ids.push(user_id); | 83 | + option.votes += 1; |
| 84 | + if public { | ||
| 85 | + option.voter_ids.push(user_id); | ||
| 86 | + } | ||
| 68 | } | 87 | } |
| 69 | } | 88 | } |
| 70 | 89 | ||
| @@ -73,6 +92,8 @@ pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerE | |||
| 73 | options, | 92 | options, |
| 74 | multiple, | 93 | multiple, |
| 75 | closed, | 94 | closed, |
| 95 | + public, | ||
| 96 | + voters, | ||
| 76 | })) | 97 | })) |
| 77 | } | 98 | } |
| 78 | 99 | ||
| @@ -100,6 +121,20 @@ pub async fn set_votes( | |||
| 100 | Ok(()) | 121 | Ok(()) |
| 101 | } | 122 | } |
| 102 | 123 | ||
| 124 | +pub async fn my_votes( | ||
| 125 | + message_id: Id, | ||
| 126 | + user_id: Id, | ||
| 127 | + db: &Connection, | ||
| 128 | +) -> Result<Vec<u32>, ServerError> { | ||
| 129 | + all( | ||
| 130 | + db, | ||
| 131 | + "SELECT position FROM poll_vote WHERE message_id = ?1 AND user_id = ?2 ORDER BY position", | ||
| 132 | + (message_id, user_id), | ||
| 133 | + |r| r.get(), | ||
| 134 | + ) | ||
| 135 | + .await | ||
| 136 | +} | ||
| 137 | + | ||
| 103 | pub async fn close(message_id: Id, db: &Connection) -> Result<(), ServerError> { | 138 | pub async fn close(message_id: Id, db: &Connection) -> Result<(), ServerError> { |
| 104 | ensure_with( | 139 | ensure_with( |
| 105 | run( | 140 | run( |
crates/server/src/db/schema.sqlmodified+2 -1
| @@ -122,7 +122,8 @@ CREATE TABLE poll ( | |||
| 122 | message_id INTEGER PRIMARY KEY REFERENCES message (id) ON DELETE CASCADE, | 122 | message_id INTEGER PRIMARY KEY REFERENCES message (id) ON DELETE CASCADE, |
| 123 | question TEXT NOT NULL, | 123 | question TEXT NOT NULL, |
| 124 | multiple INTEGER NOT NULL, | 124 | multiple INTEGER NOT NULL, |
| 125 | - closed INTEGER NOT NULL DEFAULT 0 | 125 | + closed INTEGER NOT NULL DEFAULT 0, |
| 126 | + public INTEGER NOT NULL DEFAULT 0 | ||
| 126 | ) STRICT; | 127 | ) STRICT; |
| 127 | 128 | ||
| 128 | CREATE TABLE poll_option ( | 129 | CREATE TABLE poll_option ( |