Pinned poll banner pages through every open pin, poll pins and replies show the question, ghost shows as ghost in own voice panel
Browse files at this commit252f2ce08661294552f37d529dc3368add3f9ee0Parent: ba30ecf- fix
- pinned poll banner pages through every open pin, poll pins and replies show the question, ghost shows as ghost in own voice panel
6 changed files +68 -11
- crates/client/src/gui/chat.rs +4 -0
- crates/client/src/gui/composer.rs +1 -1
- crates/client/src/gui/message_actions.rs +9 -2
- crates/client/src/gui/poll.rs +42 -6
- crates/client/src/gui/sidebar.rs +11 -1
- crates/server/src/db/message.rs +1 -1
crates/client/src/gui/chat.rsmodified+4 -0
| @@ -153,6 +153,7 @@ pub struct Chat { | |||
| 153 | pub(super) plus_menu: composer::PlusMenu, | 153 | pub(super) plus_menu: composer::PlusMenu, |
| 154 | pub(super) my_votes: HashMap<Id, Vec<u32>>, | 154 | pub(super) my_votes: HashMap<Id, Vec<u32>>, |
| 155 | pub(super) poll_expanded: bool, | 155 | pub(super) poll_expanded: bool, |
| 156 | + pub(super) poll_page: usize, | ||
| 156 | scroll: ScrollHandle, | 157 | scroll: ScrollHandle, |
| 157 | pub(super) jump: Option<Id>, | 158 | pub(super) jump: Option<Id>, |
| 158 | highlight: Option<(Id, Instant)>, | 159 | highlight: Option<(Id, Instant)>, |
| @@ -366,6 +367,7 @@ impl Chat { | |||
| 366 | plus_menu: composer::PlusMenu::Menu, | 367 | plus_menu: composer::PlusMenu::Menu, |
| 367 | my_votes: HashMap::new(), | 368 | my_votes: HashMap::new(), |
| 368 | poll_expanded: false, | 369 | poll_expanded: false, |
| 370 | + poll_page: 0, | ||
| 369 | history: History::End, | 371 | history: History::End, |
| 370 | scroll: ScrollHandle::new(), | 372 | scroll: ScrollHandle::new(), |
| 371 | jump: None, | 373 | jump: None, |
| @@ -733,6 +735,7 @@ impl Chat { | |||
| 733 | self.jump = None; | 735 | self.jump = None; |
| 734 | self.pins.clear(); | 736 | self.pins.clear(); |
| 735 | self.poll_expanded = false; | 737 | self.poll_expanded = false; |
| 738 | + self.poll_page = 0; | ||
| 736 | self.my_votes.clear(); | 739 | self.my_votes.clear(); |
| 737 | self.community_hits.clear(); | 740 | self.community_hits.clear(); |
| 738 | self.history = History::End; | 741 | self.history = History::End; |
| @@ -2468,6 +2471,7 @@ impl Yumush { | |||
| 2468 | .chat | 2471 | .chat |
| 2469 | .voice_ids(community_id) | 2472 | .voice_ids(community_id) |
| 2470 | .iter() | 2473 | .iter() |
| 2474 | + .filter(|id| !(self.chat.ghost && self.is_me(**id))) | ||
| 2471 | .filter_map(|id| self.chat.member(*id)) | 2475 | .filter_map(|id| self.chat.member(*id)) |
| 2472 | .collect(); | 2476 | .collect(); |
| 2473 | if users.is_empty() { | 2477 | if users.is_empty() { |
crates/client/src/gui/composer.rsmodified+1 -1
| @@ -142,7 +142,7 @@ fn reply_bar( | |||
| 142 | .to_string(); | 142 | .to_string(); |
| 143 | let quote = message | 143 | let quote = message |
| 144 | .map(|message| { | 144 | .map(|message| { |
| 145 | - super::message_actions::quote_text(&message.body, message.attachments.len() as u32) | 145 | + super::message_actions::message_text(message) |
| 146 | }) | 146 | }) |
| 147 | .unwrap_or_default(); | 147 | .unwrap_or_default(); |
| 148 | 148 | ||
crates/client/src/gui/message_actions.rsmodified+9 -2
| @@ -143,6 +143,13 @@ pub fn quote_text(body: &str, attachments: u32) -> String { | |||
| 143 | } | 143 | } |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | +pub fn message_text(message: &Message) -> String { | ||
| 147 | + match &message.poll { | ||
| 148 | + Some(poll) if message.body.is_empty() => poll.question.clone(), | ||
| 149 | + _ => quote_text(&message.body, message.attachments.len() as u32), | ||
| 150 | + } | ||
| 151 | +} | ||
| 152 | + | ||
| 146 | pub fn quote_line(message: &Message, chat: &Chat, palette: Palette) -> Option<impl IntoElement> { | 153 | pub fn quote_line(message: &Message, chat: &Chat, palette: Palette) -> Option<impl IntoElement> { |
| 147 | let quote = message.reply.as_ref()?; | 154 | let quote = message.reply.as_ref()?; |
| 148 | let author = chat.author(quote.user_id); | 155 | let author = chat.author(quote.user_id); |
| @@ -265,7 +272,7 @@ pub fn search_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> | |||
| 265 | .map(|user| user.username.clone()) | 272 | .map(|user| user.username.clone()) |
| 266 | .unwrap_or_default(), | 273 | .unwrap_or_default(), |
| 267 | time: Some(millis_time(hit.message.created_at, CLOCK)), | 274 | time: Some(millis_time(hit.message.created_at, CLOCK)), |
| 268 | - body: quote_text(&hit.message.body, hit.message.attachments.len() as u32), | 275 | + body: message_text(&hit.message), |
| 269 | }) | 276 | }) |
| 270 | .collect(); | 277 | .collect(); |
| 271 | 278 | ||
| @@ -316,7 +323,7 @@ pub fn pins_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 316 | .map(|user| user.username.clone()) | 323 | .map(|user| user.username.clone()) |
| 317 | .unwrap_or_default(), | 324 | .unwrap_or_default(), |
| 318 | time: None, | 325 | time: None, |
| 319 | - body: quote_text(&pin.body, pin.attachments.len() as u32), | 326 | + body: message_text(pin), |
| 320 | }) | 327 | }) |
| 321 | .collect(); | 328 | .collect(); |
| 322 | 329 | ||
crates/client/src/gui/poll.rsmodified+42 -6
| @@ -418,12 +418,20 @@ pub fn poll_card( | |||
| 418 | 418 | ||
| 419 | impl Yumush { | 419 | impl Yumush { |
| 420 | pub(super) fn poll_banner(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> { | 420 | pub(super) fn poll_banner(&self, entity: &Entity<Self>, palette: Palette) -> Option<Div> { |
| 421 | - let (message, poll) = self.chat.pins.iter().find_map(|pin| { | 421 | + let open: Vec<(&Message, &Poll)> = self |
| 422 | - pin.poll | 422 | + .chat |
| 423 | - .as_ref() | 423 | + .pins |
| 424 | - .filter(|poll| !is_closed(poll)) | 424 | + .iter() |
| 425 | - .map(|poll| (pin, poll)) | 425 | + .filter_map(|pin| { |
| 426 | - })?; | 426 | + pin.poll |
| 427 | + .as_ref() | ||
| 428 | + .filter(|poll| !is_closed(poll)) | ||
| 429 | + .map(|poll| (pin, poll)) | ||
| 430 | + }) | ||
| 431 | + .collect(); | ||
| 432 | + let count = open.len(); | ||
| 433 | + let page = self.chat.poll_page % count.max(1); | ||
| 434 | + let (message, poll) = *open.get(page)?; | ||
| 427 | let me = self.user.as_ref(); | 435 | let me = self.user.as_ref(); |
| 428 | let expanded = self.chat.poll_expanded; | 436 | let expanded = self.chat.poll_expanded; |
| 429 | let toggle = entity.clone(); | 437 | let toggle = entity.clone(); |
| @@ -489,6 +497,17 @@ impl Yumush { | |||
| 489 | ), | 497 | ), |
| 490 | ), | 498 | ), |
| 491 | ) | 499 | ) |
| 500 | + .children((count > 1).then(|| { | ||
| 501 | + div() | ||
| 502 | + .flex() | ||
| 503 | + .items_center() | ||
| 504 | + .gap(px(2.)) | ||
| 505 | + .text_size(text(11.)) | ||
| 506 | + .text_color(palette.muted) | ||
| 507 | + .child(page_button("poll_page_back", IconName::ChevronLeft, "Previous", count - 1, entity, palette)) | ||
| 508 | + .child(format!("{}/{count}", page + 1)) | ||
| 509 | + .child(page_button("poll_page_next", IconName::ChevronRight, "Next", 1, entity, palette)) | ||
| 510 | + })) | ||
| 492 | .child(icon_button( | 511 | .child(icon_button( |
| 493 | "poll_banner_jump", | 512 | "poll_banner_jump", |
| 494 | palette, | 513 | palette, |
| @@ -581,3 +600,20 @@ impl Yumush { | |||
| 581 | }); | 600 | }); |
| 582 | } | 601 | } |
| 583 | } | 602 | } |
| 603 | + | ||
| 604 | +fn page_button( | ||
| 605 | + id: &'static str, | ||
| 606 | + icon: IconName, | ||
| 607 | + tip: &'static str, | ||
| 608 | + step: usize, | ||
| 609 | + entity: &Entity<Yumush>, | ||
| 610 | + palette: Palette, | ||
| 611 | +) -> impl IntoElement { | ||
| 612 | + let entity = entity.clone(); | ||
| 613 | + icon_button(id, palette, icon, tip, move |_, cx| { | ||
| 614 | + entity.update(cx, |yumush, cx| { | ||
| 615 | + yumush.chat.poll_page = yumush.chat.poll_page.wrapping_add(step); | ||
| 616 | + cx.notify(); | ||
| 617 | + }); | ||
| 618 | + }) | ||
| 619 | +} | ||
crates/client/src/gui/sidebar.rsmodified+11 -1
| @@ -244,6 +244,7 @@ impl Yumush { | |||
| 244 | let watch_screen = entity.clone(); | 244 | let watch_screen = entity.clone(); |
| 245 | let watch_camera = entity.clone(); | 245 | let watch_camera = entity.clone(); |
| 246 | let sharing = self.chat.waves.share(user_id).is_some(); | 246 | let sharing = self.chat.waves.share(user_id).is_some(); |
| 247 | + let ghost = self.chat.ghost && self.is_me(user_id); | ||
| 247 | 248 | ||
| 248 | let member = profile_popover( | 249 | let member = profile_popover( |
| 249 | format!("voice_member_{user_id}"), | 250 | format!("voice_member_{user_id}"), |
| @@ -274,7 +275,15 @@ impl Yumush { | |||
| 274 | .text_size(text(12.)) | 275 | .text_size(text(12.)) |
| 275 | .text_color(palette.text) | 276 | .text_color(palette.text) |
| 276 | .child(user.username.clone()), | 277 | .child(user.username.clone()), |
| 277 | - ), | 278 | + ) |
| 279 | + .when(ghost, |row| { | ||
| 280 | + row.child( | ||
| 281 | + Icon::new(IconName::Ghost) | ||
| 282 | + .w(px(12.)) | ||
| 283 | + .h(px(12.)) | ||
| 284 | + .text_color(palette.muted), | ||
| 285 | + ) | ||
| 286 | + }), | ||
| 278 | ); | 287 | ); |
| 279 | 288 | ||
| 280 | div() | 289 | div() |
| @@ -284,6 +293,7 @@ impl Yumush { | |||
| 284 | .px(px(4.)) | 293 | .px(px(4.)) |
| 285 | .py(px(2.)) | 294 | .py(px(2.)) |
| 286 | .rounded(px(6.)) | 295 | .rounded(px(6.)) |
| 296 | + .when(ghost, |row| row.opacity(0.5)) | ||
| 287 | .hover(move |style| style.bg(palette.hover)) | 297 | .hover(move |style| style.bg(palette.hover)) |
| 288 | .child(div().flex_1().min_w_0().child(member)) | 298 | .child(div().flex_1().min_w_0().child(member)) |
| 289 | .child( | 299 | .child( |
crates/server/src/db/message.rsmodified+1 -1
| @@ -11,7 +11,7 @@ use crate::error::{ServerError, ensure_with}; | |||
| 11 | const SEARCH_LIMIT: u32 = 200; | 11 | const SEARCH_LIMIT: u32 = 200; |
| 12 | const PAGE_LIMIT: u32 = MESSAGE_PAGE_LIMIT as u32; | 12 | const PAGE_LIMIT: u32 = MESSAGE_PAGE_LIMIT as u32; |
| 13 | 13 | ||
| 14 | -const SELECT: &str = "SELECT m.id, m.user_id, m.community_id, m.created_at, m.body, m.edited, r.id, r.user_id, r.body, (SELECT COUNT(*) FROM attachment a WHERE a.message_id = r.id AND a.snippet_position IS NULL), m.call, m.call_seconds, m.pinned FROM message m LEFT JOIN message r ON r.id = m.reply_to"; | 14 | +const SELECT: &str = "SELECT m.id, m.user_id, m.community_id, m.created_at, m.body, m.edited, r.id, r.user_id, COALESCE(NULLIF(r.body, ''), (SELECT question FROM poll p WHERE p.message_id = r.id), r.body), (SELECT COUNT(*) FROM attachment a WHERE a.message_id = r.id AND a.snippet_position IS NULL), m.call, m.call_seconds, m.pinned FROM message m LEFT JOIN message r ON r.id = m.reply_to"; |
| 15 | 15 | ||
| 16 | fn row(r: &mut Reader) -> Result<Message, ServerError> { | 16 | fn row(r: &mut Reader) -> Result<Message, ServerError> { |
| 17 | let id = r.get()?; | 17 | let id = r.get()?; |