BlueGit

ict rusty-teams

Files

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

call_notice.rs

call_notice.rs 12.0 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(
162 "description",
163 ICON_SIZE,
164 theme::accent_text(),
165 ))
166 .child("Transcript")
167}
168
169fn thumbnail_image(recording: &RecordingCard, directory: &Directory) -> AnyElement {
170 let image = recording
171 .thumbnail
172 .as_ref()
173 .and_then(|thumbnail| directory.image(&thumbnail.url));
174 match image {
175 Some(entry) => img(bounded(entry.path.clone()))
176 .size_full()
177 .object_fit(ObjectFit::Cover)
178 .into_any_element(),
179 None => h_flex()
180 .size_full()
181 .items_center()
182 .justify_center()
183 .bg(theme::code_surface())
184 .when(recording.duration.is_none(), |tile| {
185 tile.child(symbol("videocam", ICON_SIZE, theme::text()))
186 })
187 .into_any_element(),
188 }
189}
190
191fn recording_thumbnail(
192 recording: &RecordingCard,
193 index: usize,
194 directory: &Directory,
195 open: RowAction,
196) -> Div {
197 v_flex()
198 .w(px(THUMB_WIDTH))
199 .flex_none()
200 .child(
201 div()
202 .id(ElementId::Name(format!("recap-recording-{index}").into()))
203 .relative()
204 .w(px(THUMB_WIDTH))
205 .h(px(THUMB_HEIGHT))
206 .rounded(px(THUMB_RADIUS))
207 .overflow_hidden()
208 .cursor_pointer()
209 .hover(|tile| tile.opacity(0.92))
210 .child(thumbnail_image(recording, directory))
211 .children(recording.duration.clone().map(|duration| {
212 div()
213 .absolute()
214 .right(px(BADGE_INSET_RIGHT))
215 .bottom(px(BADGE_INSET_BOTTOM))
216 .px(px(6.))
217 .py(px(1.))
218 .rounded(px(2.))
219 .bg(black().opacity(0.5))
220 .text_size(px(TEXT_SIZE))
221 .line_height(px(16.))
222 .text_color(theme::white())
223 .child(duration)
224 }))
225 .when_some(open, |tile, open| tile.on_click(move |_, _, cx| open(cx))),
226 )
227 .children(recording.expires_in_days.map(|days| {
228 h_flex()
229 .h(px(EXPIRY_LINE))
230 .justify_center()
231 .items_center()
232 .gap(px(EXPIRY_ICON_GAP))
233 .text_size(px(EXPIRY_SIZE))
234 .text_color(theme::text_muted())
235 .child(symbol("schedule", EXPIRY_SIZE, theme::text_muted()))
236 .child(if days == 1 {
237 "Expires in 1 day".to_owned()
238 } else {
239 format!("Expires in {days} days")
240 })
241 }))
242}
243
244fn recap_card(
245 recap: &RecapCard,
246 index: usize,
247 directory: &Directory,
248 actions: RecapActions,
249) -> Div {
250 let RecapActions {
251 view_recap,
252 open_recording,
253 transcript,
254 share,
255 } = actions;
256 v_flex()
257 .mt(px(CARD_TOP))
258 .w_full()
259 .max_w(px(CARD_MAX_WIDTH))
260 .pt(px(CARD_PADDING_TOP))
261 .px(px(CARD_PADDING_X))
262 .rounded(px(CARD_RADIUS))
263 .bg(theme::bubble_other())
264 .shadow(card_shadow())
265 .child(recap_header(recap, index, view_recap, share))
266 .child(divider())
267 .child(
268 h_flex()
269 .w_full()
270 .items_start()
271 .child(
272 v_flex()
273 .flex_1()
274 .min_w_0()
275 .child(
276 div()
277 .text_size(px(TEXT_SIZE))
278 .line_height(px(16.))
279 .font_weight(FontWeight::SEMIBOLD)
280 .text_color(theme::text_soft())
281 .child(CONTENT_LABEL),
282 )
283 .child(
284 h_flex()
285 .mt(px(CONTENT_GAP_TOP))
286 .mb(px(CONTENT_GAP_BOTTOM))
287 .when(recap.recording.transcript, |chips| {
288 chips.child(transcript_chip(index, transcript))
289 }),
290 ),
291 )
292 .child(recording_thumbnail(
293 &recap.recording,
294 index,
295 directory,
296 open_recording,
297 )),
298 )
299}
300
301fn card_shadow() -> Vec<BoxShadow> {
302 vec![
303 BoxShadow {
304 color: hsla(0., 0., 0., 0.24),
305 offset: point(px(0.), px(0.)),
306 blur_radius: px(1.),
307 spread_radius: px(0.),
308 inset: false,
309 },
310 BoxShadow {
311 color: hsla(0., 0., 0., 0.28),
312 offset: point(px(0.), px(2.)),
313 blur_radius: px(2.),
314 spread_radius: px(0.),
315 inset: false,
316 },
317 ]
318}
319
320pub(super) fn notice_line(
321 call: &CallCard,
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(&call.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 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, index, directory, actions)),
377 )
378 .into_any_element()
379}