BlueGit

ict rusty-teams

Files

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

call_card.rs

call_card.rs 7.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::call_notice::{RecapActions, notice_row};
7use super::message_row::{AVATAR_GAP, AVATAR_SIZE, RowAction, day_separator, new_marker};
8use super::profile_card::opens_profile;
9use super::widgets::symbol;
10use crate::data::Directory;
11use crate::rows::{CallCard, CallIcon, CallParticipant, MessageRow};
12use crate::theme;
13
14const SERIES_START_GAP: f32 = 8.;
15const CARD_RADIUS: f32 = 12.;
16const CARD_MIN_WIDTH: f32 = 200.;
17const ICON_CIRCLE: f32 = 30.;
18const ICON_SIZE: f32 = 18.;
19const TITLE_SIZE: f32 = 13.;
20const DETAIL_SIZE: f32 = 11.;
21const JOIN_HEIGHT: f32 = 24.;
22const PARTICIPANT_AVATAR: f32 = 20.;
23const PARTICIPANT_GAP: f32 = 2.;
24
25pub struct CallActions {
26 pub call_back: RowAction,
27 pub join: RowAction,
28 pub recap: RecapActions,
29}
30
31impl CallActions {
32 pub fn none() -> Self {
33 CallActions {
34 call_back: None,
35 join: None,
36 recap: RecapActions {
37 view_recap: None,
38 open_recording: None,
39 transcript: None,
40 share: None,
41 },
42 }
43 }
44}
45
46fn icon_circle(call: &CallCard, own: bool) -> Div {
47 let (fill, glyph, tint) = match call.icon {
48 CallIcon::Missed => (theme::red().opacity(0.2), "call_missed", theme::red_soft()),
49 CallIcon::Call => (circle_fill(own), "call", theme::text()),
50 CallIcon::Video => (circle_fill(own), "videocam", theme::text()),
51 CallIcon::Record | CallIcon::Saved => (
52 circle_fill(own),
53 "fluent_record",
54 theme::accent_text(),
55 ),
56 CallIcon::RecordStop => (circle_fill(own), "fluent_record_stop", theme::text()),
57 };
58 h_flex()
59 .size(px(ICON_CIRCLE))
60 .flex_none()
61 .items_center()
62 .justify_center()
63 .rounded_full()
64 .bg(fill)
65 .child(symbol(glyph, ICON_SIZE, tint))
66}
67
68fn circle_fill(own: bool) -> Hsla {
69 if own {
70 theme::reaction_on_own()
71 } else {
72 theme::popup()
73 }
74}
75
76fn detail_line(call: &CallCard, index: usize, own: bool, call_back: RowAction) -> Div {
77 let tint = if own {
78 theme::own_meta()
79 } else {
80 theme::text_muted()
81 };
82 h_flex()
83 .gap(px(4.))
84 .items_center()
85 .text_size(px(DETAIL_SIZE))
86 .text_color(tint)
87 .child(call.detail.clone())
88 .when(call.missed, |line| {
89 line.child("\u{b7}").child(
90 div()
91 .id(ElementId::Name(format!("call-back-{index}").into()))
92 .cursor_pointer()
93 .text_color(theme::accent_text())
94 .child("Call back")
95 .when_some(call_back, |link, call_back| {
96 link.on_click(move |_, _, cx| call_back(cx))
97 }),
98 )
99 })
100}
101
102fn join_button(index: usize, join: RowAction) -> Stateful<Div> {
103 h_flex()
104 .id(ElementId::Name(format!("call-join-{index}").into()))
105 .h(px(JOIN_HEIGHT))
106 .px(px(12.))
107 .flex_none()
108 .items_center()
109 .rounded(px(CARD_RADIUS))
110 .bg(theme::accent())
111 .text_color(theme::white())
112 .text_size(px(DETAIL_SIZE + 1.))
113 .font_weight(FontWeight::SEMIBOLD)
114 .cursor_pointer()
115 .hover(|button| button.opacity(0.85))
116 .child("Join")
117 .when_some(join, |button, join| {
118 button.on_click(move |_, _, cx| join(cx))
119 })
120}
121
122fn participant_stack(
123 participants: &[CallParticipant],
124 extra: usize,
125 directory: &Directory,
126 own: bool,
127) -> Option<Div> {
128 if participants.is_empty() {
129 return None;
130 }
131 let tint = if own {
132 theme::own_meta()
133 } else {
134 theme::text_muted()
135 };
136 Some(
137 h_flex()
138 .pt(px(4.))
139 .gap(px(PARTICIPANT_GAP))
140 .items_center()
141 .children(participants.iter().map(|person| {
142 person_avatar(
143 directory,
144 Some(&person.user_id),
145 &person.name,
146 PARTICIPANT_AVATAR,
147 )
148 }))
149 .when(extra > 0, |stack| {
150 stack.child(
151 div()
152 .pl(px(4.))
153 .text_size(px(DETAIL_SIZE))
154 .text_color(tint)
155 .child(format!("+{extra}")),
156 )
157 }),
158 )
159}
160
161fn card(
162 call: &CallCard,
163 index: usize,
164 own: bool,
165 actions: CallActions,
166 directory: &Directory,
167) -> Div {
168 let CallActions { call_back, join, .. } = actions;
169 let show_join = call.started && join.is_some();
170 let summary = h_flex()
171 .gap(px(8.))
172 .items_center()
173 .child(icon_circle(call, own))
174 .child(
175 v_flex()
176 .flex_1()
177 .gap(px(2.))
178 .child(
179 div()
180 .text_size(px(TITLE_SIZE))
181 .font_weight(FontWeight::SEMIBOLD)
182 .text_color(if call.missed {
183 theme::red_soft()
184 } else {
185 theme::text()
186 })
187 .child(call.title.clone()),
188 )
189 .child(detail_line(call, index, own, call_back))
190 .children(participant_stack(
191 &call.participants,
192 call.extra_participants,
193 directory,
194 own,
195 )),
196 )
197 .when(show_join, |card| card.child(join_button(index, join)));
198 v_flex()
199 .min_w(px(CARD_MIN_WIDTH))
200 .gap(px(4.))
201 .pt(px(8.))
202 .pr(px(12.))
203 .pb(px(8.))
204 .pl(px(8.))
205 .rounded(px(CARD_RADIUS))
206 .bg(if own {
207 theme::bubble_own()
208 } else {
209 theme::bubble_other()
210 })
211 .child(summary)
212}
213
214pub(super) fn post_call_card(
215 call: &CallCard,
216 index: usize,
217 actions: CallActions,
218 directory: &Directory,
219) -> Div {
220 h_flex().child(card(call, index, false, actions, directory))
221}
222
223pub(super) fn call_card_row(
224 row: &MessageRow,
225 call: &CallCard,
226 index: usize,
227 directory: &Directory,
228 actions: CallActions,
229) -> AnyElement {
230 if let Some(notice) = &call.notice {
231 return notice_row(row, call, notice, index, directory, actions.recap);
232 }
233 let own = row.own;
234 let body = if own {
235 h_flex()
236 .w_full()
237 .justify_end()
238 .child(card(call, index, true, actions, directory))
239 } else {
240 h_flex()
241 .w_full()
242 .gap(px(AVATAR_GAP))
243 .items_start()
244 .child(
245 opens_profile(
246 div().id(ElementId::Name(format!("author-avatar-{index}").into())),
247 row.sender_id.as_deref(),
248 )
249 .w(px(AVATAR_SIZE))
250 .flex_none()
251 .child(person_avatar(
252 directory,
253 row.sender_id.as_deref(),
254 &row.author,
255 AVATAR_SIZE,
256 )),
257 )
258 .child(card(call, index, false, actions, directory))
259 };
260 v_flex()
261 .w_full()
262 .px(px(20.))
263 .children(row.day_header.as_deref().map(day_separator))
264 .when(row.new_marker, |column| column.child(new_marker()))
265 .child(
266 div()
267 .id(ElementId::Name(format!("row-{index}").into()))
268 .w_full()
269 .pt(px(SERIES_START_GAP))
270 .child(body),
271 )
272 .into_any_element()
273}