BlueGit

ict rusty-teams

Files

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

call_notice.rs

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