BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / message_row.rs

message_row.rs

message_row.rs 24.3 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{Icon, h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5use std::time::Duration;
6
7use super::adaptive_card::cards_view;
8use super::attachments::{FileActions, ImageActions, attachments_view, message_body};
9use super::avatar::{bot_avatar, person_avatar};
10use super::call_card::{CallActions, call_card_row};
11use super::jumbo_emoji::jumbo_row;
12use super::link_preview::{link_preview_card, meeting_join_chip};
13use super::message_actions::{MessageMenu, message_toolbar};
14use super::profile_card::opens_profile;
15use super::reaction_picker::PickHandler;
16use super::reaction_pills::{ReactionControls, reaction_pills};
17use super::reaction_proposal_pill::{ReactionPill, reaction_pill};
18use super::scheduled_toolbar::{ScheduledMenu, scheduled_toolbar};
19use super::toolbar_placement::{HoverChange, TimelineBounds, placed_toolbar};
20use super::translation_line::{TranslationActions, translation_line};
21use super::widgets::{icon, symbol};
22use crate::agents::{AgentRun, run_chip};
23use crate::card_state::BotIdentity;
24use crate::data::Directory;
25use crate::render::Block;
26use crate::restorable_deletes::{DELETED_TOMBSTONE, UNDO_DELETE_LABEL};
27use crate::rows::{Delivery, MessageRow, Receipt, ScheduledState, Skeleton, bubble_corners};
28use crate::sidebar_model::DELETED_PREVIEW;
29use crate::theme;
30use app_ui_kit::layout::ROW_PADDING;
31
32pub type RowAction = Option<Box<dyn Fn(&mut App)>>;
33pub type SharedRowAction = Option<std::rc::Rc<dyn Fn(&mut App)>>;
34
35pub const BUBBLE_TAGS: [&str; 12] = [
36 "message-bubble/0",
37 "message-bubble/1",
38 "message-bubble/2",
39 "message-bubble/3",
40 "message-bubble/4",
41 "message-bubble/5",
42 "message-bubble/6",
43 "message-bubble/7",
44 "message-bubble/8",
45 "message-bubble/9",
46 "message-bubble/10",
47 "message-bubble/11",
48];
49pub(super) const AVATAR_SIZE: f32 = 28.;
50pub(super) const AVATAR_GAP: f32 = 8.;
51const SERIES_START_GAP: f32 = 8.;
52const SERIES_GAP: f32 = 2.;
53const COMPACT_SERIES_START_GAP: f32 = 4.;
54const COMPACT_SERIES_GAP: f32 = 1.;
55const COMPACT_BUBBLE_PADDING_Y: f32 = 4.;
56pub(super) const BODY_SIZE: f32 = 13.5;
57const MAX_WIDTH_RATIO: f32 = 0.7;
58const NARROW_BUBBLE_WIDTH: f32 = 300.;
59const BUBBLE_PADDING_Y: f32 = 8.;
60const META_BOTTOM_INSET: f32 = 4.;
61const META_SIZE: f32 = 11.;
62const META_CHECK_SIZE: f32 = 15.;
63const SAVED_MARK_SIZE: f32 = 12.;
64const FORWARDED_SIZE: f32 = 11.;
65const FIGURE_SPACE_WIDTH: f32 = 7.4;
66const PULSE_PERIOD: Duration = Duration::from_millis(1600);
67const RECEIPT_FADE_PERIOD: Duration = Duration::from_millis(600);
68const SKELETON_LINE_HEIGHT: f32 = 20.;
69
70pub struct DeliveryActions {
71 pub retry: RowAction,
72 pub delete: RowAction,
73 pub send_now: RowAction,
74}
75
76pub struct RowActions {
77 pub bot: Option<BotIdentity>,
78 pub delivery: DeliveryActions,
79 pub reply: RowAction,
80 pub hovered: Option<HoverChange>,
81 pub menu: Option<MessageMenu>,
82 pub scheduled_menu: Option<ScheduledMenu>,
83 pub react: Option<PickHandler>,
84 pub reaction_controls: Option<ReactionControls>,
85 pub files: Option<FileActions>,
86 pub open_image: Option<ImageActions>,
87 pub highlighted: bool,
88 pub saved: bool,
89 pub pinned: bool,
90 pub translation: Option<TranslationActions>,
91 pub timeline: TimelineBounds,
92 pub agent_run: Option<AgentRun>,
93 pub call: CallActions,
94 pub reaction_proposal: Option<ReactionPill>,
95 pub undo_delete: SharedRowAction,
96 pub compact: bool,
97}
98
99pub fn row_spacing(has_previous: bool, compact: bool) -> f32 {
100 match (has_previous, compact) {
101 (true, false) => SERIES_GAP,
102 (true, true) => COMPACT_SERIES_GAP,
103 (false, false) => SERIES_START_GAP,
104 (false, true) => COMPACT_SERIES_START_GAP,
105 }
106}
107
108pub fn bubble_padding_y(compact: bool) -> f32 {
109 if compact {
110 COMPACT_BUBBLE_PADDING_Y
111 } else {
112 BUBBLE_PADDING_Y
113 }
114}
115
116const TOOLBAR_RIGHT_INSET: f32 = 0.;
117
118fn separator_pill(label: &str, fill: Hsla, text_color: Hsla) -> Div {
119 h_flex()
120 .w_full()
121 .justify_center()
122 .mt(px(12.))
123 .mb(px(6.))
124 .child(
125 div()
126 .h(px(24.))
127 .px(px(8.))
128 .flex()
129 .items_center()
130 .rounded(px(12.))
131 .bg(fill)
132 .text_size(px(11.))
133 .text_color(text_color)
134 .child(label.to_owned()),
135 )
136}
137
138pub(super) fn day_separator(label: &str) -> Div {
139 separator_pill(label, theme::row_hover(), theme::text_muted())
140}
141
142pub(super) fn new_marker() -> Div {
143 separator_pill(
144 "New",
145 theme::mention_background(false),
146 theme::accent_text(),
147 )
148}
149
150pub(super) fn deleted_tombstone(index: usize, undo_delete: SharedRowAction) -> Div {
151 let line =
152 h_flex()
153 .gap(px(8.))
154 .items_baseline()
155 .text_size(px(13.))
156 .child(div().italic().text_color(theme::text_muted()).child(
157 if undo_delete.is_some() {
158 DELETED_TOMBSTONE
159 } else {
160 DELETED_PREVIEW
161 },
162 ));
163 match undo_delete {
164 Some(undo) => line.child(
165 div()
166 .id(ElementId::Name(format!("undo-delete-{index}").into()))
167 .cursor_pointer()
168 .font_weight(FontWeight::SEMIBOLD)
169 .text_color(theme::accent_text())
170 .hover(|link| link.underline())
171 .child(UNDO_DELETE_LABEL)
172 .on_click(move |_, _, cx| undo(cx)),
173 ),
174 None => line,
175 }
176}
177
178fn bubble_max_width(timeline: &TimelineBounds, reserved: f32) -> Length {
179 let Some(bounds) = timeline.get() else {
180 return relative(MAX_WIDTH_RATIO).into();
181 };
182 let row_width = (f32::from(bounds.size.width) - 2. * ROW_PADDING - reserved).max(0.);
183 px((row_width * MAX_WIDTH_RATIO).max(row_width.min(NARROW_BUBBLE_WIDTH))).into()
184}
185
186fn bubble(
187 row: &MessageRow,
188 index: usize,
189 own: bool,
190 directory: &Directory,
191 extras: BubbleExtras,
192 cx: &App,
193) -> Stateful<Div> {
194 let corners = bubble_corners(own, row.series);
195 let jumbo = row.jumbo.as_deref().filter(|_| {
196 !row.deleted && matches!(row.delivery, Delivery::Delivered | Delivery::Sending)
197 });
198 let mut element = div()
199 .id(ElementId::Name(format!("bubble-{index}").into()))
200 .when_some(extras.hover.clone(), |element, hover| {
201 element.on_hover(move |is_hovered, _, cx| hover(*is_hovered, cx))
202 })
203 .relative()
204 .max_w_full()
205 .when_some(BUBBLE_TAGS.get(index).copied(), |element, tag| {
206 element.debug_selector(|| tag.into())
207 })
208 .when(jumbo.is_none(), |element| {
209 element
210 .rounded_tl(px(corners.top_left))
211 .rounded_tr(px(corners.top_right))
212 .rounded_br(px(corners.bottom_right))
213 .rounded_bl(px(corners.bottom_left))
214 .px(px(12.))
215 .py(px(bubble_padding_y(extras.compact)))
216 })
217 .text_size(px(BODY_SIZE))
218 .line_height(relative(1.45));
219 if row.deleted {
220 return element
221 .border_1()
222 .border_color(theme::border_strong())
223 .py(px(6.))
224 .child(deleted_tombstone(index, extras.undo_delete));
225 }
226 let failed = matches!(row.delivery, Delivery::Failed(_));
227 let scheduled = matches!(row.delivery, Delivery::Scheduled(_));
228 element = element
229 .when(!scheduled && jumbo.is_none(), |bubble| {
230 bubble.bg(if own && !failed {
231 theme::bubble_own()
232 } else {
233 theme::bubble_other()
234 })
235 })
236 .when(failed, |bubble| {
237 bubble.border_1().border_color(theme::red())
238 })
239 .when(scheduled, |bubble| {
240 bubble.border_1().border_color(
241 if row.delivery == Delivery::Scheduled(ScheduledState::DeliveryFailed) {
242 theme::red()
243 } else {
244 theme::accent()
245 },
246 )
247 });
248 let has_reactions = !row.reactions.is_empty();
249 let saved = extras.saved;
250 let mut content = v_flex().gap(px(6.));
251 if row.forwarded {
252 content = content.child(forwarded_header());
253 }
254 let attachments = attachments_view(
255 &row.blocks,
256 &row.images,
257 &row.local_images,
258 &row.files,
259 &format!("message-{index}"),
260 directory,
261 extras.files.as_ref(),
262 extras.open_image.as_ref(),
263 );
264 let cards = cards_view(&row.adaptive_cards, &row.conversation_id, &row.key, cx);
265 let trailing_content = attachments.is_some()
266 || row.meeting_link.is_some()
267 || row.link_preview.is_some()
268 || !cards.is_empty();
269 let padded_blocks = if has_reactions || trailing_content || jumbo.is_some() {
270 None
271 } else {
272 with_meta_room(&row.blocks, meta_room(row, own, saved))
273 };
274 let meta_inline = has_text(row) && padded_blocks.is_some();
275 if let Some(jumbo) = jumbo {
276 content = content.child(jumbo_row(&row.key, jumbo, own));
277 } else if has_text(row) {
278 content = content.children(message_body(
279 padded_blocks.as_deref().unwrap_or(&row.blocks),
280 &row.images,
281 &row.local_images,
282 &format!("message-{index}"),
283 own,
284 directory,
285 extras.open_image.as_ref(),
286 cx,
287 ));
288 }
289 content = content.children(attachments);
290 content = content.children(
291 row.meeting_link
292 .clone()
293 .map(|url| meeting_join_chip(format!("message-{index}-join"), url)),
294 );
295 content = content.children(row.link_preview.as_ref().map(|preview| {
296 link_preview_card(
297 preview,
298 format!("message-{index}-link"),
299 directory,
300 false,
301 None,
302 )
303 }));
304 content = content.children(cards);
305 if has_reactions {
306 content = content.child(
307 h_flex()
308 .gap(px(8.))
309 .items_end()
310 .child(
311 reaction_pills(
312 &row.reactions,
313 index,
314 own,
315 directory,
316 extras.react.clone(),
317 extras.controls.as_ref(),
318 )
319 .flex_auto(),
320 )
321 .child(
322 h_flex()
323 .flex_none()
324 .mb(px(META_BOTTOM_INSET - bubble_padding_y(extras.compact)))
325 .child(bubble_meta(row, own, saved)),
326 ),
327 );
328 } else if !meta_inline {
329 content = content.child(h_flex().justify_end().child(bubble_meta(row, own, saved)));
330 }
331 element = element.child(content);
332 if meta_inline {
333 element = element.child(
334 div()
335 .absolute()
336 .right(px(8.))
337 .bottom(px(META_BOTTOM_INSET))
338 .child(bubble_meta(row, own, saved)),
339 );
340 }
341 if let Some(menu) = extras.menu {
342 element = element.child(placed_toolbar(
343 message_toolbar(menu, cx),
344 extras.timeline.clone(),
345 TOOLBAR_RIGHT_INSET,
346 ));
347 }
348 if let Some(menu) = extras.scheduled_menu {
349 element = element.child(placed_toolbar(
350 scheduled_toolbar(menu),
351 extras.timeline.clone(),
352 TOOLBAR_RIGHT_INSET,
353 ));
354 }
355 element
356}
357
358#[derive(Default)]
359struct BubbleExtras {
360 hover: Option<HoverChange>,
361 menu: Option<MessageMenu>,
362 scheduled_menu: Option<ScheduledMenu>,
363 react: Option<PickHandler>,
364 controls: Option<ReactionControls>,
365 files: Option<FileActions>,
366 open_image: Option<ImageActions>,
367 saved: bool,
368 translation: Option<TranslationActions>,
369 timeline: TimelineBounds,
370 agent_run: Option<AgentRun>,
371 reaction_proposal: Option<ReactionPill>,
372 undo_delete: SharedRowAction,
373 compact: bool,
374}
375
376fn agent_chip(run: Option<AgentRun>) -> Option<Div> {
377 run.map(|run| div().py(px(2.)).child(run_chip(&run, theme::row_hover())))
378}
379
380pub(super) fn forwarded_header() -> Div {
381 h_flex()
382 .gap(px(4.))
383 .items_center()
384 .text_size(px(FORWARDED_SIZE))
385 .text_color(theme::text_muted())
386 .child(icon(IconName::Forward, FORWARDED_SIZE, theme::text_muted()))
387 .child("Forwarded")
388}
389
390fn bubble_meta(row: &MessageRow, own: bool, saved: bool) -> Div {
391 let tint = if own {
392 theme::own_meta()
393 } else {
394 theme::text_muted()
395 };
396 h_flex()
397 .gap(px(4.))
398 .items_center()
399 .text_size(px(META_SIZE))
400 .line_height(px(14.))
401 .italic()
402 .text_color(tint)
403 .when(row.edited, |meta| meta.child("Edited"))
404 .when(saved, |meta| {
405 meta.child(icon(
406 IconName::Bookmark,
407 SAVED_MARK_SIZE,
408 theme::accent_text(),
409 ))
410 })
411 .child(row.time.clone())
412 .when(own && row.delivery == Delivery::Sending, |meta| {
413 meta.child(symbol("schedule", META_CHECK_SIZE, tint))
414 })
415 .when(matches!(row.delivery, Delivery::Scheduled(_)), |meta| {
416 meta.child(symbol("schedule", META_SIZE + 3., tint))
417 })
418 .when(
419 own && row.delivery == Delivery::Delivered,
420 |meta| match row.receipt {
421 Receipt::Hidden => meta,
422 Receipt::Sent => meta.child(on_baseline(symbol("done", META_CHECK_SIZE, tint))),
423 Receipt::Read => meta.child(on_baseline(symbol(
424 "done_all",
425 META_CHECK_SIZE,
426 theme::own_read(),
427 ))),
428 Receipt::ReadLive => meta.child(receipt_fade_in(
429 &row.key,
430 on_baseline(symbol("done_all", META_CHECK_SIZE, theme::own_read())),
431 )),
432 },
433 )
434}
435
436fn on_baseline(check: Icon) -> Div {
437 div().relative().top(px(1.)).child(check)
438}
439
440fn pulse<E: IntoElement + Styled + 'static>(id: &'static str, element: E) -> AnimationElement<E> {
441 element.with_animation(
442 id,
443 Animation::new(PULSE_PERIOD)
444 .repeat_synced()
445 .with_easing(pulsating_between(0.35, 1.)),
446 |element, opacity| element.opacity(opacity),
447 )
448}
449
450fn receipt_fade_in(message_key: &str, check: Div) -> AnimationElement<Div> {
451 check.with_animation(
452 SharedString::from(format!("receipt-fade/{message_key}")),
453 Animation::new(RECEIPT_FADE_PERIOD).with_easing(ease_in_out),
454 |check, delta| check.opacity(0.25 + 0.75 * delta),
455 )
456}
457
458pub fn render_skeleton_row(skeleton: &Skeleton, index: usize) -> AnyElement {
459 let corners = bubble_corners(skeleton.own, Default::default());
460 let height = 14. + SKELETON_LINE_HEIGHT * f32::from(skeleton.lines);
461 let shape = div()
462 .w(relative(skeleton.width_ratio))
463 .h(px(height))
464 .rounded_tl(px(corners.top_left))
465 .rounded_tr(px(corners.top_right))
466 .rounded_br(px(corners.bottom_right))
467 .rounded_bl(px(corners.bottom_left))
468 .bg(if skeleton.own {
469 theme::bubble_own().opacity(0.55)
470 } else {
471 theme::bubble_other()
472 });
473 let line = h_flex()
474 .w_full()
475 .when(skeleton.own, |line| line.justify_end())
476 .when(!skeleton.own, |line| {
477 line.gap(px(AVATAR_GAP)).child(
478 div()
479 .size(px(AVATAR_SIZE))
480 .flex_none()
481 .rounded_full()
482 .bg(theme::bubble_other()),
483 )
484 })
485 .child(shape);
486 div()
487 .id(ElementId::Name(format!("row-{index}").into()))
488 .w_full()
489 .px(px(ROW_PADDING))
490 .pt(px(SERIES_START_GAP))
491 .child(pulse("skeleton", line))
492 .into_any_element()
493}
494
495fn meta_room(row: &MessageRow, own: bool, saved: bool) -> usize {
496 let mut width = 12. + row.time.chars().count() as f32 * 6.;
497 if saved {
498 width += SAVED_MARK_SIZE + 4.;
499 }
500 if row.edited {
501 width += 56.;
502 }
503 if own {
504 width += META_CHECK_SIZE + 4.;
505 }
506 (width / FIGURE_SPACE_WIDTH).ceil() as usize
507}
508
509fn with_meta_room(blocks: &[Block], room: usize) -> Option<Vec<Block>> {
510 let mut padded = blocks.to_vec();
511 let inline = padded.last_mut()?.last_inline_mut()?;
512 *inline = inline.with_trailing_room(room);
513 Some(padded)
514}
515
516pub(super) fn has_text(row: &MessageRow) -> bool {
517 !row.blocks.is_empty()
518 || (row.images.is_empty()
519 && row.local_images.is_empty()
520 && row.files.is_empty()
521 && row.adaptive_cards.is_empty())
522}
523
524fn delivery_link(
525 index: usize,
526 name: &str,
527 label: &'static str,
528 action: RowAction,
529) -> Stateful<Div> {
530 div()
531 .id(ElementId::Name(format!("{name}-{index}").into()))
532 .cursor_pointer()
533 .text_color(theme::red_tint())
534 .underline()
535 .child(label)
536 .when_some(action, |link, action| {
537 link.on_click(move |_, _, cx| action(cx))
538 })
539}
540
541pub(super) fn delivery_note(
542 row: &MessageRow,
543 delivery: DeliveryActions,
544 index: usize,
545) -> Option<AnyElement> {
546 let DeliveryActions {
547 retry,
548 delete,
549 send_now,
550 } = delivery;
551 let note = |text: &'static str| {
552 h_flex()
553 .gap(px(4.))
554 .text_size(px(11.))
555 .text_color(theme::red_soft())
556 .child(text)
557 };
558 match &row.delivery {
559 Delivery::Delivered | Delivery::Sending | Delivery::Scheduled(ScheduledState::Waiting) => {
560 None
561 }
562 Delivery::Failed(_) => Some(
563 note("Failed to send.")
564 .child(delivery_link(index, "retry", "Retry", retry))
565 .child(delivery_link(index, "delete", "Delete", delete))
566 .into_any_element(),
567 ),
568 Delivery::Scheduled(ScheduledState::DeliveryFailed) => Some(
569 note("Couldn't send at the scheduled time.")
570 .child(delivery_link(index, "send-now", "Send now", send_now))
571 .child(delivery_link(index, "delete", "Delete", delete))
572 .into_any_element(),
573 ),
574 Delivery::Scheduled(ScheduledState::ChangeFailed) => Some(
575 note("Couldn't change the scheduled message.")
576 .child(delivery_link(index, "retry", "Retry", retry))
577 .into_any_element(),
578 ),
579 }
580}
581
582fn others_row(
583 row: &MessageRow,
584 index: usize,
585 directory: &Directory,
586 bot: Option<&BotIdentity>,
587 delivery: DeliveryActions,
588 mut extras: BubbleExtras,
589 cx: &App,
590) -> Div {
591 let translation = extras.translation.take();
592 let agent_run = extras.agent_run.take();
593 let reaction_proposal = extras.reaction_proposal.take();
594 let first = !row.series.has_prev;
595 let author = bot.map_or_else(|| row.author.clone(), |bot| bot.name.clone());
596 let profile_user = row.sender_id.as_deref().filter(|_| bot.is_none());
597 let mut column = v_flex()
598 .gap(px(2.))
599 .flex_1()
600 .min_w_0()
601 .max_w(bubble_max_width(&extras.timeline, AVATAR_SIZE + AVATAR_GAP))
602 .items_start();
603 if first {
604 column = column.child(
605 h_flex().gap(px(8.)).items_baseline().pl(px(2.)).child(
606 opens_profile(
607 div().id(ElementId::Name(format!("author-{index}").into())),
608 profile_user,
609 )
610 .text_size(px(12.))
611 .font_weight(FontWeight::SEMIBOLD)
612 .text_color(theme::text_soft())
613 .child(author.clone()),
614 ),
615 );
616 }
617 column = column.child(bubble(row, index, false, directory, extras, cx));
618 column = column.children(agent_chip(agent_run));
619 column = column.children(reaction_proposal.map(|pill| reaction_pill(pill, &row.key)));
620 column = column.children(translation_line(row, index, translation.as_ref()));
621 if let Some(note) = delivery_note(row, delivery, index) {
622 column = column.child(note);
623 }
624 let lead = if let Some(bot) = bot.filter(|_| first) {
625 bot_avatar(bot, AVATAR_SIZE)
626 } else if first {
627 person_avatar(
628 directory,
629 row.sender_id.as_deref(),
630 &row.author,
631 AVATAR_SIZE,
632 )
633 } else {
634 div().size(px(AVATAR_SIZE)).into_any_element()
635 };
636 h_flex()
637 .w_full()
638 .gap(px(AVATAR_GAP))
639 .items_start()
640 .child(
641 opens_profile(
642 div().id(ElementId::Name(format!("author-avatar-{index}").into())),
643 profile_user.filter(|_| first),
644 )
645 .w(px(AVATAR_SIZE))
646 .flex_none()
647 .child(lead),
648 )
649 .child(column)
650}
651
652fn own_row(
653 row: &MessageRow,
654 index: usize,
655 directory: &Directory,
656 delivery: DeliveryActions,
657 mut extras: BubbleExtras,
658 cx: &App,
659) -> Div {
660 let translation = extras.translation.take();
661 let agent_run = extras.agent_run.take();
662 let reaction_proposal = extras.reaction_proposal.take();
663 let mut column = v_flex().w_full().items_end().gap(px(2.));
664 column = column.child(
665 h_flex().w_full().justify_end().child(
666 div()
667 .min_w_0()
668 .max_w(bubble_max_width(&extras.timeline, 0.))
669 .child(bubble(row, index, true, directory, extras, cx)),
670 ),
671 );
672 column = column.children(agent_chip(agent_run));
673 column = column.children(reaction_proposal.map(|pill| reaction_pill(pill, &row.key)));
674 column = column.children(translation_line(row, index, translation.as_ref()));
675 if let Some(note) = delivery_note(row, delivery, index) {
676 column = column.child(note);
677 }
678 column
679}
680
681pub fn render_message_row(
682 row: &MessageRow,
683 index: usize,
684 actions: RowActions,
685 directory: &Directory,
686 cx: &App,
687) -> AnyElement {
688 if let Some(call) = &row.call {
689 return call_card_row(row, call, index, directory, actions.call);
690 }
691 let RowActions {
692 bot,
693 delivery,
694 reply,
695 hovered,
696 menu,
697 scheduled_menu,
698 react,
699 reaction_controls,
700 files,
701 open_image,
702 highlighted,
703 saved,
704 translation,
705 timeline,
706 agent_run,
707 call: _,
708 pinned: _,
709 reaction_proposal,
710 undo_delete,
711 compact,
712 } = actions;
713 let extras = BubbleExtras {
714 hover: hovered,
715 menu,
716 scheduled_menu,
717 react,
718 controls: reaction_controls,
719 files,
720 open_image,
721 saved,
722 translation,
723 timeline,
724 agent_run,
725 reaction_proposal,
726 undo_delete,
727 compact,
728 };
729 let own = row.own;
730 let spacing = px(row_spacing(row.series.has_prev, compact));
731 let mut container = v_flex().w_full().px(px(ROW_PADDING));
732 if let Some(day) = &row.day_header {
733 container = container.child(day_separator(day));
734 }
735 if row.new_marker {
736 container = container.child(new_marker());
737 }
738 let body = if own {
739 own_row(row, index, directory, delivery, extras, cx)
740 } else {
741 others_row(row, index, directory, bot.as_ref(), delivery, extras, cx)
742 };
743 container
744 .child(
745 div()
746 .id(ElementId::Name(format!("row-{index}").into()))
747 .w_full()
748 .pt(spacing)
749 .when_some(reply, |element, reply| {
750 element.on_mouse_down(MouseButton::Right, move |_, _, cx| reply(cx))
751 })
752 .child(
753 div()
754 .w_full()
755 .rounded(px(10.))
756 .when(highlighted, |element| {
757 element.bg(theme::accent().opacity(0.2))
758 })
759 .child(body),
760 ),
761 )
762 .into_any_element()
763}
764
765#[cfg(test)]
766mod density_tests {
767 use super::{META_BOTTOM_INSET, bubble_padding_y, row_spacing};
768
769 #[test]
770 fn compact_density_tightens_gaps_and_bubble_padding() {
771 assert!(row_spacing(false, true) < row_spacing(false, false));
772 assert!(row_spacing(true, true) < row_spacing(true, false));
773 assert!(bubble_padding_y(true) < bubble_padding_y(false));
774 assert!(META_BOTTOM_INSET - bubble_padding_y(true) >= 0.);
775 }
776}