BlueGit

ict rusty-teams

Files

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

call_card.rs

call_card.rs 11.7 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::prelude::FluentBuilder as _;
3use gpui_kit::*;
4
5use super::avatar::person_avatar;
6use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
7use super::profile_card::opens_profile;
8use super::widgets::symbol;
9use crate::data::Directory;
10use crate::rows::{CallCard, CallIcon, CallParticipant, MessageRow, RecordingCard};
11use crate::theme;
12
13const SERIES_START_GAP: f32 = 8.;
14const CARD_RADIUS: f32 = 12.;
15const CARD_MIN_WIDTH: f32 = 200.;
16const ICON_CIRCLE: f32 = 30.;
17const ICON_SIZE: f32 = 18.;
18const TITLE_SIZE: f32 = 13.;
19const DETAIL_SIZE: f32 = 11.;
20const JOIN_HEIGHT: f32 = 24.;
21const PARTICIPANT_AVATAR: f32 = 20.;
22const PARTICIPANT_GAP: f32 = 2.;
23const TILE_WIDTH: f32 = 288.;
24const TILE_HEIGHT: f32 = 162.;
25const TILE_RADIUS: f32 = 8.;
26const PLAY_CIRCLE: f32 = 40.;
27const PLAY_GLYPH: f32 = 24.;
28const DURATION_INSET: f32 = 6.;
29const CHIP_HEIGHT: f32 = 26.;
30
31pub struct CallActions {
32 pub call_back: RowAction,
33 pub join: RowAction,
34 pub open_recording: RowAction,
35 pub open_transcript: RowAction,
36}
37
38impl CallActions {
39 pub fn none() -> Self {
40 CallActions {
41 call_back: None,
42 join: None,
43 open_recording: None,
44 open_transcript: None,
45 }
46 }
47}
48
49fn icon_circle(call: &CallCard, own: bool) -> Div {
50 let (fill, glyph, tint) = match call.icon {
51 CallIcon::Missed => (theme::red().opacity(0.2), "call_missed", theme::red_soft()),
52 CallIcon::Call => (circle_fill(own), "call", theme::text()),
53 CallIcon::Video => (circle_fill(own), "videocam", theme::text()),
54 CallIcon::Record => (
55 circle_fill(own),
56 "radio_button_checked",
57 theme::accent_text(),
58 ),
59 CallIcon::RecordStop => (circle_fill(own), "stop_circle", theme::text()),
60 };
61 h_flex()
62 .size(px(ICON_CIRCLE))
63 .flex_none()
64 .items_center()
65 .justify_center()
66 .rounded_full()
67 .bg(fill)
68 .child(symbol(glyph, ICON_SIZE, tint))
69}
70
71fn circle_fill(own: bool) -> Hsla {
72 if own {
73 theme::reaction_on_own()
74 } else {
75 theme::popup()
76 }
77}
78
79fn detail_line(call: &CallCard, index: usize, own: bool, call_back: RowAction) -> Div {
80 let tint = if own {
81 theme::own_meta()
82 } else {
83 theme::text_muted()
84 };
85 h_flex()
86 .gap(px(4.))
87 .items_center()
88 .text_size(px(DETAIL_SIZE))
89 .text_color(tint)
90 .child(call.detail.clone())
91 .when(call.missed, |line| {
92 line.child("\u{b7}").child(
93 div()
94 .id(ElementId::Name(format!("call-back-{index}").into()))
95 .cursor_pointer()
96 .text_color(theme::accent_text())
97 .child("Call back")
98 .when_some(call_back, |link, call_back| {
99 link.on_click(move |_, _, cx| call_back(cx))
100 }),
101 )
102 })
103}
104
105fn join_button(index: usize, join: RowAction) -> Stateful<Div> {
106 h_flex()
107 .id(ElementId::Name(format!("call-join-{index}").into()))
108 .h(px(JOIN_HEIGHT))
109 .px(px(12.))
110 .flex_none()
111 .items_center()
112 .rounded(px(CARD_RADIUS))
113 .bg(theme::accent())
114 .text_color(theme::white())
115 .text_size(px(DETAIL_SIZE + 1.))
116 .font_weight(FontWeight::SEMIBOLD)
117 .cursor_pointer()
118 .hover(|button| button.opacity(0.85))
119 .child("Join")
120 .when_some(join, |button, join| {
121 button.on_click(move |_, _, cx| join(cx))
122 })
123}
124
125fn participant_stack(
126 participants: &[CallParticipant],
127 extra: usize,
128 directory: &Directory,
129 own: bool,
130) -> Option<Div> {
131 if participants.is_empty() {
132 return None;
133 }
134 let tint = if own {
135 theme::own_meta()
136 } else {
137 theme::text_muted()
138 };
139 Some(
140 h_flex()
141 .pt(px(4.))
142 .gap(px(PARTICIPANT_GAP))
143 .items_center()
144 .children(participants.iter().map(|person| {
145 person_avatar(
146 directory,
147 Some(&person.user_id),
148 &person.name,
149 PARTICIPANT_AVATAR,
150 )
151 }))
152 .when(extra > 0, |stack| {
153 stack.child(
154 div()
155 .pl(px(4.))
156 .text_size(px(DETAIL_SIZE))
157 .text_color(tint)
158 .child(format!("+{extra}")),
159 )
160 }),
161 )
162}
163
164fn recording_thumbnail(recording: &RecordingCard, directory: &Directory) -> AnyElement {
165 let image = recording
166 .thumbnail
167 .as_ref()
168 .and_then(|thumbnail| directory.image(&thumbnail.url));
169 match image {
170 Some(entry) => img(entry.path.clone())
171 .size_full()
172 .object_fit(ObjectFit::Cover)
173 .into_any_element(),
174 None => div()
175 .size_full()
176 .bg(theme::code_surface())
177 .into_any_element(),
178 }
179}
180
181fn recording_tile(
182 recording: &RecordingCard,
183 index: usize,
184 directory: &Directory,
185 open_recording: RowAction,
186) -> Stateful<Div> {
187 div()
188 .id(ElementId::Name(format!("call-recording-{index}").into()))
189 .relative()
190 .w(px(TILE_WIDTH))
191 .h(px(TILE_HEIGHT))
192 .flex_none()
193 .rounded(px(TILE_RADIUS))
194 .overflow_hidden()
195 .cursor_pointer()
196 .hover(|tile| tile.opacity(0.92))
197 .child(recording_thumbnail(recording, directory))
198 .child(
199 h_flex()
200 .absolute()
201 .inset_0()
202 .items_center()
203 .justify_center()
204 .child(
205 h_flex()
206 .size(px(PLAY_CIRCLE))
207 .items_center()
208 .justify_center()
209 .rounded_full()
210 .bg(black().opacity(0.55))
211 .child(symbol("play_arrow", PLAY_GLYPH, theme::white())),
212 ),
213 )
214 .children(recording.duration.clone().map(|duration| {
215 div()
216 .absolute()
217 .bottom(px(DURATION_INSET))
218 .right(px(DURATION_INSET))
219 .px(px(6.))
220 .py(px(1.))
221 .rounded(px(4.))
222 .bg(black().opacity(0.65))
223 .text_size(px(DETAIL_SIZE))
224 .font_weight(FontWeight::SEMIBOLD)
225 .text_color(theme::white())
226 .child(duration)
227 }))
228 .when_some(open_recording, |tile, open| {
229 tile.on_click(move |_, _, cx| open(cx))
230 })
231}
232
233fn transcript_chip(index: usize, open_transcript: RowAction) -> Stateful<Div> {
234 h_flex()
235 .id(ElementId::Name(format!("call-transcript-{index}").into()))
236 .h(px(CHIP_HEIGHT))
237 .px(px(10.))
238 .gap(px(6.))
239 .flex_none()
240 .items_center()
241 .rounded(px(6.))
242 .border_1()
243 .border_color(theme::border())
244 .text_size(px(DETAIL_SIZE + 1.))
245 .font_weight(FontWeight::SEMIBOLD)
246 .text_color(theme::text())
247 .cursor_pointer()
248 .hover(|chip| chip.bg(theme::popup_hover()))
249 .child(symbol("description", 15., theme::accent_text()))
250 .child("Transcript")
251 .when_some(open_transcript, |chip, open| {
252 chip.on_click(move |_, _, cx| open(cx))
253 })
254}
255
256fn recording_block(
257 recording: &RecordingCard,
258 index: usize,
259 directory: &Directory,
260 open_recording: RowAction,
261 open_transcript: RowAction,
262) -> Div {
263 v_flex()
264 .pt(px(4.))
265 .gap(px(8.))
266 .child(recording_tile(recording, index, directory, open_recording))
267 .child(
268 h_flex()
269 .w(px(TILE_WIDTH))
270 .gap(px(8.))
271 .items_center()
272 .child(
273 div()
274 .flex_1()
275 .min_w_0()
276 .truncate()
277 .text_size(px(TITLE_SIZE))
278 .font_weight(FontWeight::SEMIBOLD)
279 .text_color(theme::text())
280 .child(recording.title.clone()),
281 )
282 .when(recording.transcript, |line| {
283 line.child(transcript_chip(index, open_transcript))
284 }),
285 )
286}
287
288fn card(
289 call: &CallCard,
290 index: usize,
291 own: bool,
292 actions: CallActions,
293 directory: &Directory,
294) -> Div {
295 let CallActions {
296 call_back,
297 join,
298 open_recording,
299 open_transcript,
300 } = actions;
301 let show_join = call.started && join.is_some();
302 let summary = h_flex()
303 .gap(px(8.))
304 .items_center()
305 .child(icon_circle(call, own))
306 .child(
307 v_flex()
308 .flex_1()
309 .gap(px(2.))
310 .child(
311 div()
312 .text_size(px(TITLE_SIZE))
313 .font_weight(FontWeight::SEMIBOLD)
314 .text_color(if call.missed {
315 theme::red_soft()
316 } else {
317 theme::text()
318 })
319 .child(call.title.clone()),
320 )
321 .child(detail_line(call, index, own, call_back))
322 .children(participant_stack(
323 &call.participants,
324 call.extra_participants,
325 directory,
326 own,
327 )),
328 )
329 .when(show_join, |card| card.child(join_button(index, join)));
330 v_flex()
331 .min_w(px(CARD_MIN_WIDTH))
332 .gap(px(4.))
333 .pt(px(8.))
334 .pr(px(12.))
335 .pb(px(8.))
336 .pl(px(8.))
337 .rounded(px(CARD_RADIUS))
338 .bg(if own {
339 theme::bubble_own()
340 } else {
341 theme::bubble_other()
342 })
343 .child(summary)
344 .children(call.recording.as_ref().map(|recording| {
345 recording_block(recording, index, directory, open_recording, open_transcript)
346 }))
347}
348
349pub(super) fn post_call_card(
350 call: &CallCard,
351 index: usize,
352 actions: CallActions,
353 directory: &Directory,
354) -> Div {
355 h_flex().child(card(call, index, false, actions, directory))
356}
357
358pub(super) fn call_card_row(
359 row: &MessageRow,
360 call: &CallCard,
361 index: usize,
362 directory: &Directory,
363 actions: CallActions,
364) -> AnyElement {
365 let own = row.own;
366 let body = if own {
367 h_flex()
368 .w_full()
369 .justify_end()
370 .child(card(call, index, true, actions, directory))
371 } else {
372 h_flex()
373 .w_full()
374 .gap(px(AVATAR_GAP))
375 .items_start()
376 .child(
377 opens_profile(
378 div().id(ElementId::Name(format!("author-avatar-{index}").into())),
379 row.sender_id.as_deref(),
380 )
381 .w(px(AVATAR_SIZE))
382 .flex_none()
383 .child(person_avatar(
384 directory,
385 row.sender_id.as_deref(),
386 &row.author,
387 AVATAR_SIZE,
388 )),
389 )
390 .child(card(call, index, false, actions, directory))
391 };
392 v_flex()
393 .w_full()
394 .px(px(20.))
395 .children(row.day_header.as_deref().map(day_separator))
396 .when(row.new_marker, |column| column.child(new_marker()))
397 .child(
398 div()
399 .id(ElementId::Name(format!("row-{index}").into()))
400 .w_full()
401 .pt(px(SERIES_START_GAP))
402 .child(body),
403 )
404 .into_any_element()
405}