BlueGit

ict rusty-teams

Files

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

message_row.rs

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