BlueGit

ict rusty-teams

Files

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

call_notice.rs

call_notice.rs 11.9 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
4
5use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
6use super::widgets::symbol;
7use crate::data::Directory;
8use crate::rows::{CallCard, CallIcon, CallNotice, MessageRow, RecapCard, RecordingCard};
9use crate::theme;
10
11const ROW_TOP: f32 = 8.;
12const LINE_HEIGHT: f32 = 20.;
13const TEXT_SIZE: f32 = 12.;
14const ICON_SIZE: f32 = 20.;
15const STAMP_GAP: &str = "\u{2003}";
16const CARD_TOP: f32 = 14.;
17const CARD_MAX_WIDTH: f32 = 646.;
18const CARD_RADIUS: f32 = 8.;
19const CARD_PADDING_X: f32 = 20.;
20const CARD_PADDING_TOP: f32 = 14.;
21const TITLE_SIZE: f32 = 16.;
22const BUTTON_HEIGHT: f32 = 32.;
23const BUTTON_RADIUS: f32 = 4.;
24const VIEW_RECAP_WIDTH: f32 = 108.;
25const VIEW_RECAP_SIZE: f32 = 14.;
26const DIVIDER_GAP: f32 = 12.;
27const CONTENT_GAP_TOP: f32 = 12.;
28const CONTENT_GAP_BOTTOM: f32 = 16.;
29const CHIP_MIN_WIDTH: f32 = 96.;
30const CHIP_ICON_GAP: f32 = 6.;
31const THUMB_WIDTH: f32 = 108.;
32const THUMB_HEIGHT: f32 = 60.;
33const THUMB_RADIUS: f32 = 6.;
34const BADGE_INSET_RIGHT: f32 = 6.;
35const BADGE_INSET_BOTTOM: f32 = 8.;
36const EXPIRY_SIZE: f32 = 10.;
37const EXPIRY_LINE: f32 = 24.;
38const EXPIRY_ICON_GAP: f32 = 4.;
39const CONTENT_LABEL: &str = "Content";
40
41pub struct RecapActions {
42 pub view_recap: RowAction,
43 pub open_recording: RowAction,
44 pub transcript: RowAction,
45 pub share: RowAction,
46}
47
48fn notice_icon(icon: CallIcon) -> (&'static str, Hsla) {
49 match icon {
50 CallIcon::Record => ("fluent_record", theme::accent_text()),
51 CallIcon::RecordStop => ("fluent_record_stop", theme::text_muted()),
52 CallIcon::Saved => ("fluent_cloud_arrow_up", theme::text_muted()),
53 CallIcon::Video | CallIcon::Call | CallIcon::Missed => {
54 ("fluent_video", theme::text_muted())
55 }
56 }
57}
58
59fn notice_text(notice: &CallNotice) -> StyledText {
60 let mut text = format!("{}{STAMP_GAP}{}", notice.stamp, notice.text);
61 let mut highlights = Vec::new();
62 if let Some(emphasis) = &notice.emphasis {
63 text.push('\u{a0}');
64 let start = text.len();
65 text.push_str(emphasis);
66 highlights.push((
67 start..text.len(),
68 HighlightStyle {
69 font_weight: Some(FontWeight::BOLD),
70 ..HighlightStyle::default()
71 },
72 ));
73 }
74 StyledText::new(text).with_highlights(highlights)
75}
76
77fn plain_button(id: String, action: RowAction) -> Stateful<Div> {
78 h_flex()
79 .id(ElementId::Name(id.into()))
80 .h(px(BUTTON_HEIGHT))
81 .flex_none()
82 .items_center()
83 .justify_center()
84 .rounded(px(BUTTON_RADIUS))
85 .cursor_pointer()
86 .when_some(action, |button, action| {
87 button.on_click(move |_, _, cx| action(cx))
88 })
89}
90
91fn recap_header(recap: &RecapCard, index: usize, open: RowAction, share: RowAction) -> Div {
92 h_flex()
93 .w_full()
94 .items_start()
95 .gap(px(4.))
96 .child(
97 v_flex()
98 .flex_1()
99 .min_w_0()
100 .line_height(px(LINE_HEIGHT))
101 .child(
102 div()
103 .truncate()
104 .text_size(px(TITLE_SIZE))
105 .font_weight(FontWeight::SEMIBOLD)
106 .text_color(theme::text())
107 .child(recap.title.clone()),
108 )
109 .child(
110 div()
111 .truncate()
112 .text_size(px(TEXT_SIZE))
113 .text_color(theme::text_muted())
114 .child(recap.date_line.clone()),
115 ),
116 )
117 .child(
118 h_flex()
119 .pt(px(2.))
120 .gap(px(4.))
121 .child(
122 plain_button(format!("recap-share-{index}"), share)
123 .w(px(BUTTON_HEIGHT))
124 .hover(|button| button.bg(theme::popup_hover()))
125 .child(symbol("fluent_share", ICON_SIZE, theme::text_soft())),
126 )
127 .child(
128 plain_button(format!("recap-view-{index}"), open)
129 .w(px(VIEW_RECAP_WIDTH))
130 .bg(theme::accent())
131 .hover(|button| button.opacity(0.85))
132 .text_size(px(VIEW_RECAP_SIZE))
133 .font_weight(FontWeight::SEMIBOLD)
134 .text_color(theme::white())
135 .child("View recap"),
136 ),
137 )
138}
139
140fn divider() -> Div {
141 div()
142 .w_full()
143 .py(px(DIVIDER_GAP))
144 .child(div().w_full().h(px(1.)).bg(theme::border_strong()))
145}
146
147fn transcript_chip(index: usize, transcript: RowAction) -> Stateful<Div> {
148 plain_button(format!("recap-transcript-{index}"), transcript)
149 .min_w(px(CHIP_MIN_WIDTH))
150 .px(px(8.))
151 .gap(px(CHIP_ICON_GAP))
152 .border_1()
153 .border_color(theme::border_strong())
154 .bg(theme::bubble_other())
155 .hover(|chip| chip.bg(theme::popup_hover()))
156 .text_size(px(TEXT_SIZE))
157 .font_weight(FontWeight::SEMIBOLD)
158 .text_color(theme::text())
159 .child(symbol(
160 "fluent_document_text",
161 ICON_SIZE,
162 theme::accent_text(),
163 ))
164 .child("Transcript")
165}
166
167fn thumbnail_image(recording: &RecordingCard, directory: &Directory) -> AnyElement {
168 let image = recording
169 .thumbnail
170 .as_ref()
171 .and_then(|thumbnail| directory.image(&thumbnail.url));
172 match image {
173 Some(entry) => img(entry.path.clone())
174 .size_full()
175 .object_fit(ObjectFit::Cover)
176 .into_any_element(),
177 None => h_flex()
178 .size_full()
179 .items_center()
180 .justify_center()
181 .bg(theme::code_surface())
182 .when(recording.duration.is_none(), |tile| {
183 tile.child(symbol("fluent_video", ICON_SIZE, theme::text()))
184 })
185 .into_any_element(),
186 }
187}
188
189fn recording_thumbnail(
190 recording: &RecordingCard,
191 index: usize,
192 directory: &Directory,
193 open: RowAction,
194) -> Div {
195 v_flex()
196 .w(px(THUMB_WIDTH))
197 .flex_none()
198 .child(
199 div()
200 .id(ElementId::Name(format!("recap-recording-{index}").into()))
201 .relative()
202 .w(px(THUMB_WIDTH))
203 .h(px(THUMB_HEIGHT))
204 .rounded(px(THUMB_RADIUS))
205 .overflow_hidden()
206 .cursor_pointer()
207 .hover(|tile| tile.opacity(0.92))
208 .child(thumbnail_image(recording, directory))
209 .children(recording.duration.clone().map(|duration| {
210 div()
211 .absolute()
212 .right(px(BADGE_INSET_RIGHT))
213 .bottom(px(BADGE_INSET_BOTTOM))
214 .px(px(6.))
215 .py(px(1.))
216 .rounded(px(2.))
217 .bg(black().opacity(0.5))
218 .text_size(px(TEXT_SIZE))
219 .line_height(px(16.))
220 .text_color(theme::white())
221 .child(duration)
222 }))
223 .when_some(open, |tile, open| tile.on_click(move |_, _, cx| open(cx))),
224 )
225 .children(recording.expires_in_days.map(|days| {
226 h_flex()
227 .h(px(EXPIRY_LINE))
228 .justify_center()
229 .items_center()
230 .gap(px(EXPIRY_ICON_GAP))
231 .text_size(px(EXPIRY_SIZE))
232 .text_color(theme::text_muted())
233 .child(symbol("fluent_clock", EXPIRY_SIZE, theme::text_muted()))
234 .child(if days == 1 {
235 "Expires in 1 day".to_owned()
236 } else {
237 format!("Expires in {days} days")
238 })
239 }))
240}
241
242fn recap_card(
243 recap: &RecapCard,
244 index: usize,
245 directory: &Directory,
246 actions: RecapActions,
247) -> Div {
248 let RecapActions {
249 view_recap,
250 open_recording,
251 transcript,
252 share,
253 } = actions;
254 v_flex()
255 .mt(px(CARD_TOP))
256 .w_full()
257 .max_w(px(CARD_MAX_WIDTH))
258 .pt(px(CARD_PADDING_TOP))
259 .px(px(CARD_PADDING_X))
260 .rounded(px(CARD_RADIUS))
261 .bg(theme::bubble_other())
262 .shadow(card_shadow())
263 .child(recap_header(recap, index, view_recap, share))
264 .child(divider())
265 .child(
266 h_flex()
267 .w_full()
268 .items_start()
269 .child(
270 v_flex()
271 .flex_1()
272 .min_w_0()
273 .child(
274 div()
275 .text_size(px(TEXT_SIZE))
276 .line_height(px(16.))
277 .font_weight(FontWeight::SEMIBOLD)
278 .text_color(theme::text_soft())
279 .child(CONTENT_LABEL),
280 )
281 .child(
282 h_flex()
283 .mt(px(CONTENT_GAP_TOP))
284 .mb(px(CONTENT_GAP_BOTTOM))
285 .when(recap.recording.transcript, |chips| {
286 chips.child(transcript_chip(index, transcript))
287 }),
288 ),
289 )
290 .child(recording_thumbnail(
291 &recap.recording,
292 index,
293 directory,
294 open_recording,
295 )),
296 )
297}
298
299fn card_shadow() -> Vec<BoxShadow> {
300 vec![
301 BoxShadow {
302 color: hsla(0., 0., 0., 0.24),
303 offset: point(px(0.), px(0.)),
304 blur_radius: px(1.),
305 spread_radius: px(0.),
306 inset: false,
307 },
308 BoxShadow {
309 color: hsla(0., 0., 0., 0.28),
310 offset: point(px(0.), px(2.)),
311 blur_radius: px(2.),
312 spread_radius: px(0.),
313 inset: false,
314 },
315 ]
316}
317
318pub(super) fn notice_line(
319 call: &CallCard,
320 notice: &CallNotice,
321 index: usize,
322 directory: &Directory,
323 actions: RecapActions,
324) -> Div {
325 let (glyph, tint) = notice_icon(call.icon);
326 h_flex()
327 .w_full()
328 .pt(px(ROW_TOP))
329 .items_start()
330 .gap(px(AVATAR_GAP))
331 .child(
332 h_flex()
333 .w(px(AVATAR_SIZE))
334 .h(px(LINE_HEIGHT))
335 .flex_none()
336 .justify_center()
337 .items_center()
338 .child(symbol(glyph, ICON_SIZE, tint)),
339 )
340 .child(
341 v_flex()
342 .flex_1()
343 .min_w_0()
344 .child(
345 div()
346 .text_size(px(TEXT_SIZE))
347 .line_height(px(LINE_HEIGHT))
348 .text_color(theme::text_muted())
349 .child(notice_text(notice)),
350 )
351 .children(
352 call.recap
353 .as_ref()
354 .map(|recap| recap_card(recap, index, directory, actions)),
355 ),
356 )
357}
358
359pub(super) fn notice_row(
360 row: &MessageRow,
361 call: &CallCard,
362 notice: &CallNotice,
363 index: usize,
364 directory: &Directory,
365 actions: RecapActions,
366) -> AnyElement {
367 v_flex()
368 .w_full()
369 .px(px(20.))
370 .children(row.day_header.as_deref().map(day_separator))
371 .when(row.new_marker, |column| column.child(new_marker()))
372 .child(
373 div()
374 .id(ElementId::Name(format!("row-{index}").into()))
375 .w_full()
376 .child(notice_line(call, notice, index, directory, actions)),
377 )
378 .into_any_element()
379}