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