BlueGit

ict rusty-teams

Files

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

call_notice.rs

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