| 1 | use std::cell::{Cell, RefCell}; |
| 2 | use std::collections::{HashMap, HashSet}; |
| 3 | |
| 4 | use chrono::{Local, Utc}; |
| 5 | use gpui_kit::assets::IconName; |
| 6 | use gpui_kit::component::button::{Button, ButtonVariants as _}; |
| 7 | use gpui_kit::component::dialog::DialogFooter; |
| 8 | use gpui_kit::component::menu::{ContextMenuExt as _, DropdownMenu as _, PopupMenu, PopupMenuItem}; |
| 9 | use gpui_kit::component::scroll::ScrollableElement as _; |
| 10 | use gpui_kit::component::{Icon, Sizable as _, WindowExt as _, h_flex, tooltip::Tooltip, v_flex}; |
| 11 | use gpui_kit::prelude::FluentBuilder as _; |
| 12 | use gpui_kit::*; |
| 13 | use store::{ |
| 14 | ChannelNotificationLevel, ChannelNotifications, ChannelRecord, MessageImportance, SidebarTeam, |
| 15 | Store, |
| 16 | }; |
| 17 | use teams_core::team_avatar_key; |
| 18 | |
| 19 | use super::activity_panel::ActivityPanel; |
| 20 | use super::avatar::{spec_avatar, team_avatar, with_presence}; |
| 21 | use super::channel_admin_dialogs::{confirm_delete_channel, open_edit_channel_dialog}; |
| 22 | use super::chat_menu::{ChatMenuTarget, MenuContext, chat_menu}; |
| 23 | use super::create_channel_dialog::open_create_channel_dialog; |
| 24 | use super::last_views::LastViews; |
| 25 | use super::scroll_edge::{scroll_offset, with_top_edge}; |
| 26 | use super::section_dialog::{SectionNameTarget, open_section_name_dialog}; |
| 27 | use super::widgets::{count_badge, icon, menu_icon, page_header, symbol, unread_marker}; |
| 28 | use crate::agents::AgentsPanel; |
| 29 | use crate::app_state::{AppEvent, AppState, QuickView, Selection}; |
| 30 | use crate::channel_menu::{ |
| 31 | ChannelMenuItem, MenuEntry, TeamMenuItem, TeamMenuState, channel_menu_entries, |
| 32 | team_menu_entries, |
| 33 | }; |
| 34 | use crate::chat_actions::TITLE_LIMIT; |
| 35 | use crate::chat_filter::{ChatFilter, filtered_sections, has_no_matches}; |
| 36 | use crate::data::{AvatarState, Directory, is_pending_folder}; |
| 37 | use crate::format; |
| 38 | use crate::i18n::{tr, tr_args}; |
| 39 | use crate::local_previews::LocalPreview; |
| 40 | use crate::notice::truncated; |
| 41 | use crate::sidebar_model::{ |
| 42 | AvatarSpec, ChannelOrderInput, ChatItem, DELETED_CHAT_PREVIEW, EMPTY_FOLDER_HINT, MentionBadge, |
| 43 | NameStyle, NameWeight, Preview, Section, SectionInput, SectionKind, Step, build_sections, |
| 44 | channel_badge, channel_name_style, channel_shown, channel_shows_unread, |
| 45 | older_chats_trigger_resets, step_id, team_badge, team_channel_rows, team_hoisted, |
| 46 | team_name_style, visible_channel_ids, wants_older_chats, |
| 47 | }; |
| 48 | use crate::theme; |
| 49 | use app_ui_kit::layout::SIDEBAR_WIDTH; |
| 50 | use gpui_kit::component::input::InputState; |
| 51 | |
| 52 | pub(crate) mod channel_filter_bar; |
| 53 | pub(crate) mod chat_filter_bar; |
| 54 | |
| 55 | pub const SIDEBAR_SCROLL_DIVIDER: &str = "shell/islands/sidebar/divider-scroll"; |
| 56 | const COLLAPSED_TEAMS_META_KEY: &str = "sidebar_collapsed_teams"; |
| 57 | const ROW_HEIGHT: f32 = 54.; |
| 58 | const ROW_MORE_TOP: f32 = 6.; |
| 59 | const ROW_MORE_RIGHT: f32 = 6.; |
| 60 | const PROPOSAL_DOT_SIZE: f32 = 8.; |
| 61 | const PINNED_CHANNEL_HEIGHT: f32 = 48.; |
| 62 | const SECTION_HEIGHT: f32 = 30.; |
| 63 | const SECTION_GAP: f32 = 4.; |
| 64 | const QUICK_VIEWS_SECTION_ID: &str = "quick-views"; |
| 65 | const QUICK_ROW_HEIGHT: f32 = 32.; |
| 66 | const QUICK_ICON_SIZE: f32 = 18.; |
| 67 | const QUICK_VIEWS: [(QuickView, &str); 3] = [ |
| 68 | (QuickView::Mentions, "alternate_email"), |
| 69 | (QuickView::Drafts, "edit_note"), |
| 70 | (QuickView::Saved, "bookmark"), |
| 71 | ]; |
| 72 | const HINT_HEIGHT: f32 = 26.; |
| 73 | const SEE_MORE_HEIGHT: f32 = 28.; |
| 74 | const FALLBACK_VIEWPORT: f32 = 900.; |
| 75 | const VIEWPORT_MARGIN: f32 = 300.; |
| 76 | const AVATAR_SIZE: f32 = 36.; |
| 77 | const TEAM_ROW_HEIGHT: f32 = 36.; |
| 78 | const CHANNEL_ROW_HEIGHT: f32 = 32.; |
| 79 | const TEAM_ICON_SIZE: f32 = 20.; |
| 80 | const TEAM_ICON_RADIUS: f32 = 4.; |
| 81 | const CHANNEL_INDENT: f32 = 60.; |
| 82 | pub const CHANNEL_ROW_TAG: &str = "sidebar/channel-row"; |
| 83 | pub const SEE_ALL_CHANNELS_TAG: &str = "sidebar/see-all-channels"; |
| 84 | const PRIVATE_MEMBERSHIP: &str = "private"; |
| 85 | const REVEAL_ROW_HEIGHT: f32 = 32.; |
| 86 | const NEW_CHAT_BUTTON_SIZE: f32 = 32.; |
| 87 | const NOTIFICATION_ICON_SIZE: f32 = 13.; |
| 88 | const MENTION_ICON_SIZE: f32 = 15.; |
| 89 | const IMPORTANCE_MARKER_SIZE: f32 = 16.; |
| 90 | |
| 91 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 92 | pub enum SidebarTab { |
| 93 | Activity, |
| 94 | Chats, |
| 95 | Channels, |
| 96 | Calendar, |
| 97 | Calls, |
| 98 | Agents, |
| 99 | /// KVT-fork: Ponos-bord in het hoofdpaneel (`crate::kvt::board_view`). |
| 100 | Ponos, |
| 101 | /// KVT-fork: Asclepius-tickets in het hoofdpaneel (`crate::kvt::tickets_view`). |
| 102 | Asclepius, |
| 103 | } |
| 104 | |
| 105 | impl SidebarTab { |
| 106 | fn title(self) -> String { |
| 107 | match self { |
| 108 | SidebarTab::Activity => tr("rail.activity"), |
| 109 | SidebarTab::Chats => tr("rail.chat"), |
| 110 | SidebarTab::Channels => tr("rail.teams"), |
| 111 | SidebarTab::Calendar => tr("rail.calendar"), |
| 112 | SidebarTab::Calls => tr("rail.calls"), |
| 113 | SidebarTab::Agents => tr("rail.agents"), |
| 114 | SidebarTab::Ponos => tr("kvt.rail.ponos"), |
| 115 | SidebarTab::Asclepius => tr("kvt.rail.asclepius"), |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | pub fn chat_row_selector(chat_id: &str) -> String { |
| 121 | format!("chat-row/{chat_id}") |
| 122 | } |
| 123 | |
| 124 | #[derive(Clone)] |
| 125 | struct DraggedChat { |
| 126 | id: String, |
| 127 | title: String, |
| 128 | } |
| 129 | |
| 130 | struct DragGhost { |
| 131 | title: String, |
| 132 | } |
| 133 | |
| 134 | impl Render for DragGhost { |
| 135 | fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement { |
| 136 | div() |
| 137 | .px(px(12.)) |
| 138 | .py(px(6.)) |
| 139 | .rounded(px(8.)) |
| 140 | .bg(theme::surface_raised()) |
| 141 | .border_1() |
| 142 | .border_color(theme::accent()) |
| 143 | .text_size(px(13.)) |
| 144 | .text_color(theme::text()) |
| 145 | .child(self.title.clone()) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #[derive(Clone)] |
| 150 | struct SectionMenuTarget { |
| 151 | id: String, |
| 152 | name: String, |
| 153 | user_created: bool, |
| 154 | previous_id: Option<String>, |
| 155 | next_id: Option<String>, |
| 156 | movable: bool, |
| 157 | read_only: bool, |
| 158 | } |
| 159 | |
| 160 | fn section_menu_targets( |
| 161 | sections: &[Section], |
| 162 | directory: &Directory, |
| 163 | read_only: bool, |
| 164 | ) -> Vec<SectionMenuTarget> { |
| 165 | let movable_ids: HashSet<&str> = directory |
| 166 | .folders |
| 167 | .iter() |
| 168 | .map(|folder| folder.id.as_str()) |
| 169 | .filter(|folder_id| !is_pending_folder(folder_id)) |
| 170 | .collect(); |
| 171 | let movable = |section: &Section| movable_ids.contains(section.id.as_str()); |
| 172 | sections |
| 173 | .iter() |
| 174 | .enumerate() |
| 175 | .map(|(index, section)| SectionMenuTarget { |
| 176 | id: section.id.clone(), |
| 177 | name: section.name.clone(), |
| 178 | user_created: section.kind == SectionKind::Folder && movable(section), |
| 179 | previous_id: sections[..index] |
| 180 | .iter() |
| 181 | .rev() |
| 182 | .find(|other| movable(other)) |
| 183 | .map(|other| other.id.clone()), |
| 184 | next_id: sections[index + 1..] |
| 185 | .iter() |
| 186 | .find(|other| movable(other)) |
| 187 | .map(|other| other.id.clone()), |
| 188 | movable: movable(section), |
| 189 | read_only, |
| 190 | }) |
| 191 | .collect() |
| 192 | } |
| 193 | |
| 194 | fn drop_target(section: &Section) -> Option<Option<String>> { |
| 195 | if is_pending_folder(§ion.id) { |
| 196 | return None; |
| 197 | } |
| 198 | Some( |
| 199 | matches!(section.kind, SectionKind::Favorites | SectionKind::Folder) |
| 200 | .then(|| section.id.clone()), |
| 201 | ) |
| 202 | } |
| 203 | |
| 204 | fn new_section_item(state: &Entity<AppState>, read_only: bool) -> PopupMenuItem { |
| 205 | let state = state.clone(); |
| 206 | PopupMenuItem::new(tr("sidebar.new_section")) |
| 207 | .icon(menu_icon(IconName::Plus)) |
| 208 | .disabled(read_only) |
| 209 | .on_click(move |_, window, cx| { |
| 210 | open_section_name_dialog(state.clone(), SectionNameTarget::New, window, cx); |
| 211 | }) |
| 212 | } |
| 213 | |
| 214 | fn move_section_item( |
| 215 | state: &Entity<AppState>, |
| 216 | label: String, |
| 217 | glyph: IconName, |
| 218 | folder_id: &str, |
| 219 | target_id: Option<&String>, |
| 220 | read_only: bool, |
| 221 | ) -> PopupMenuItem { |
| 222 | let state = state.clone(); |
| 223 | let folder_id = folder_id.to_owned(); |
| 224 | let target_id = target_id.cloned(); |
| 225 | PopupMenuItem::new(label) |
| 226 | .icon(menu_icon(glyph)) |
| 227 | .disabled(read_only || target_id.is_none()) |
| 228 | .on_click(move |_, _, cx| { |
| 229 | if let Some(target_id) = &target_id { |
| 230 | state.update(cx, |state, cx| { |
| 231 | state.move_section(&folder_id, target_id, cx) |
| 232 | }); |
| 233 | } |
| 234 | }) |
| 235 | } |
| 236 | |
| 237 | fn section_menu( |
| 238 | popup: PopupMenu, |
| 239 | state: &Entity<AppState>, |
| 240 | target: &SectionMenuTarget, |
| 241 | ) -> PopupMenu { |
| 242 | let mut popup = popup; |
| 243 | if target.user_created { |
| 244 | let rename_state = state.clone(); |
| 245 | let rename_target = SectionNameTarget::Rename { |
| 246 | folder_id: target.id.clone(), |
| 247 | name: target.name.clone(), |
| 248 | }; |
| 249 | popup = popup.item( |
| 250 | PopupMenuItem::new(tr("sidebar.rename_section")) |
| 251 | .icon(menu_icon(IconName::Pencil)) |
| 252 | .disabled(target.read_only) |
| 253 | .on_click(move |_, window, cx| { |
| 254 | open_section_name_dialog( |
| 255 | rename_state.clone(), |
| 256 | rename_target.clone(), |
| 257 | window, |
| 258 | cx, |
| 259 | ); |
| 260 | }), |
| 261 | ); |
| 262 | } |
| 263 | if target.movable { |
| 264 | popup = popup |
| 265 | .item(move_section_item( |
| 266 | state, |
| 267 | tr("sidebar.move_up"), |
| 268 | IconName::ArrowUp, |
| 269 | &target.id, |
| 270 | target.previous_id.as_ref(), |
| 271 | target.read_only, |
| 272 | )) |
| 273 | .item(move_section_item( |
| 274 | state, |
| 275 | tr("sidebar.move_down"), |
| 276 | IconName::ArrowDown, |
| 277 | &target.id, |
| 278 | target.next_id.as_ref(), |
| 279 | target.read_only, |
| 280 | )) |
| 281 | .separator(); |
| 282 | } |
| 283 | popup = popup.item(new_section_item(state, target.read_only)); |
| 284 | if target.user_created { |
| 285 | let delete_state = state.clone(); |
| 286 | let (folder_id, name) = (target.id.clone(), target.name.clone()); |
| 287 | popup = popup.separator().item( |
| 288 | PopupMenuItem::element(|_, _| { |
| 289 | div() |
| 290 | .text_color(theme::red_soft()) |
| 291 | .child(tr("sidebar.delete_section")) |
| 292 | }) |
| 293 | .icon(menu_icon(IconName::Trash).text_color(theme::red_soft())) |
| 294 | .disabled(target.read_only) |
| 295 | .on_click(move |_, window, cx| { |
| 296 | confirm_delete_section(&delete_state, &folder_id, &name, window, cx); |
| 297 | }), |
| 298 | ); |
| 299 | } |
| 300 | popup |
| 301 | } |
| 302 | |
| 303 | fn confirm_delete_section( |
| 304 | state: &Entity<AppState>, |
| 305 | folder_id: &str, |
| 306 | name: &str, |
| 307 | window: &mut Window, |
| 308 | cx: &mut App, |
| 309 | ) { |
| 310 | let state = state.clone(); |
| 311 | let folder_id = folder_id.to_owned(); |
| 312 | let mut args = HashMap::new(); |
| 313 | args.insert("name".to_owned(), truncated(name, TITLE_LIMIT)); |
| 314 | let heading = tr_args("sidebar.delete_section_title", &args); |
| 315 | window.open_alert_dialog(cx, move |alert, _, _| { |
| 316 | let state = state.clone(); |
| 317 | let folder_id = folder_id.clone(); |
| 318 | let cancel = Button::new("delete-section-cancel") |
| 319 | .label(tr("common.cancel")) |
| 320 | .on_click(|_, window, cx| window.close_dialog(cx)); |
| 321 | let delete = Button::new("delete-section-confirm") |
| 322 | .label(tr("common.delete")) |
| 323 | .danger() |
| 324 | .on_click(move |_, window, cx| { |
| 325 | state.update(cx, |state, cx| state.delete_section(&folder_id, cx)); |
| 326 | window.close_dialog(cx); |
| 327 | }); |
| 328 | alert |
| 329 | .title(heading.clone()) |
| 330 | .description(tr("sidebar.delete_section_detail")) |
| 331 | .footer(DialogFooter::new().child(cancel).child(delete)) |
| 332 | .on_ok(|_, _, _| false) |
| 333 | }); |
| 334 | } |
| 335 | |
| 336 | pub enum SidebarEvent { |
| 337 | RestoreFocus, |
| 338 | TabChanged, |
| 339 | NewChannelPost, |
| 340 | } |
| 341 | |
| 342 | impl EventEmitter<SidebarEvent> for SidebarView {} |
| 343 | |
| 344 | pub struct SidebarView { |
| 345 | state: Entity<AppState>, |
| 346 | tab: SidebarTab, |
| 347 | activity_panel: Entity<ActivityPanel>, |
| 348 | agents_panel: Option<Entity<AgentsPanel>>, |
| 349 | collapsed_teams: HashSet<String>, |
| 350 | revealed_channel_teams: HashSet<String>, |
| 351 | hidden_teams_open: bool, |
| 352 | chats_scroll: ScrollHandle, |
| 353 | older_chats_trigger_top: Cell<Option<f32>>, |
| 354 | older_chats_seen: Cell<(bool, bool)>, |
| 355 | section_ids: RefCell<Vec<String>>, |
| 356 | channels_scroll: ScrollHandle, |
| 357 | chat_filter: ChatFilter, |
| 358 | filter_box_open: bool, |
| 359 | channel_filter: crate::channel_filter::ChannelFilter, |
| 360 | channel_filter_open: bool, |
| 361 | channel_filter_input: Option<Entity<InputState>>, |
| 362 | channel_filter_subscription: Option<Subscription>, |
| 363 | filter_input: Option<Entity<InputState>>, |
| 364 | filter_subscription: Option<Subscription>, |
| 365 | last_views: LastViews, |
| 366 | _activity_observation: Subscription, |
| 367 | _subscription: Subscription, |
| 368 | _state_observation: Subscription, |
| 369 | _agent_observation: Option<Subscription>, |
| 370 | _runs_observation: Option<Subscription>, |
| 371 | } |
| 372 | |
| 373 | fn preview_text(preview: &Preview) -> Option<(String, bool)> { |
| 374 | match preview { |
| 375 | Preview::Empty => None, |
| 376 | Preview::Deleted => Some((DELETED_CHAT_PREVIEW.to_owned(), true)), |
| 377 | Preview::Event(text) => Some((text.clone(), true)), |
| 378 | Preview::Typing(text) => Some((text.clone(), true)), |
| 379 | Preview::Text { |
| 380 | prefix: Some(prefix), |
| 381 | text, |
| 382 | } => Some((format!("{prefix}: {text}"), false)), |
| 383 | Preview::Text { prefix: None, text } => Some((text.clone(), false)), |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | fn local_preview_row(preview: &LocalPreview, color: Hsla) -> Div { |
| 388 | let row = h_flex() |
| 389 | .flex_1() |
| 390 | .min_w_0() |
| 391 | .overflow_hidden() |
| 392 | .gap(px(4.)) |
| 393 | .items_center() |
| 394 | .text_size(px(12.5)) |
| 395 | .text_color(color); |
| 396 | match preview { |
| 397 | LocalPreview::Draft(text) => row |
| 398 | .child( |
| 399 | div() |
| 400 | .flex_none() |
| 401 | .text_color(theme::accent_text()) |
| 402 | .child(tr("sidebar.draft_prefix")), |
| 403 | ) |
| 404 | .child(div().truncate().child(text.clone())), |
| 405 | LocalPreview::NotSent => row.child( |
| 406 | div() |
| 407 | .flex_none() |
| 408 | .text_color(theme::red_soft()) |
| 409 | .child(tr("sidebar.not_sent")), |
| 410 | ), |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | impl SidebarView { |
| 415 | pub fn new( |
| 416 | state: Entity<AppState>, |
| 417 | activity_panel: Entity<ActivityPanel>, |
| 418 | agents_panel: Option<Entity<AgentsPanel>>, |
| 419 | cx: &mut Context<Self>, |
| 420 | ) -> Self { |
| 421 | let subscription = cx.subscribe(&state, |this, state, event: &AppEvent, cx| { |
| 422 | if matches!(event, AppEvent::Selection) { |
| 423 | if let Some(selection) = &state.read(cx).selection { |
| 424 | this.last_views.remember(selection); |
| 425 | } |
| 426 | if state.read(cx).new_chat { |
| 427 | this.tab = SidebarTab::Chats; |
| 428 | } |
| 429 | this.expand_team_of_selection(cx); |
| 430 | } |
| 431 | if matches!( |
| 432 | event, |
| 433 | AppEvent::Sidebar |
| 434 | | AppEvent::CallHistory |
| 435 | | AppEvent::Selection |
| 436 | | AppEvent::Directory |
| 437 | | AppEvent::Typing |
| 438 | | AppEvent::LocalPreviews |
| 439 | ) { |
| 440 | cx.notify(); |
| 441 | } |
| 442 | }); |
| 443 | let state_observation = cx.observe(&state, |_, _, cx| cx.notify()); |
| 444 | let agent_observation = |
| 445 | crate::agent_api::handle(cx).map(|api| cx.observe(&api, |_, _, cx| cx.notify())); |
| 446 | let runs_observation = crate::agents::runs_handle(cx).map(|runs| { |
| 447 | cx.observe(&runs, |view, _, cx| { |
| 448 | if view.tab == SidebarTab::Agents && !crate::agents::agents_enabled(cx) { |
| 449 | view.open_tab(SidebarTab::Chats, cx); |
| 450 | } |
| 451 | }) |
| 452 | }); |
| 453 | let tab = if state.read(cx).start_on_channels { |
| 454 | SidebarTab::Channels |
| 455 | } else { |
| 456 | SidebarTab::Chats |
| 457 | }; |
| 458 | let collapsed_teams = load_collapsed_teams(&state.read(cx).store); |
| 459 | let activity = activity_panel.read(cx).activity(); |
| 460 | let activity_observation = cx.observe(&activity, |view, _, cx| { |
| 461 | if view |
| 462 | .chat_filter |
| 463 | .has(crate::chat_filter::ChatFilterPill::Mentions) |
| 464 | { |
| 465 | cx.notify(); |
| 466 | } |
| 467 | }); |
| 468 | SidebarView { |
| 469 | state, |
| 470 | tab, |
| 471 | activity_panel, |
| 472 | agents_panel, |
| 473 | collapsed_teams, |
| 474 | revealed_channel_teams: HashSet::new(), |
| 475 | hidden_teams_open: false, |
| 476 | chats_scroll: ScrollHandle::new(), |
| 477 | older_chats_trigger_top: Cell::new(None), |
| 478 | older_chats_seen: Cell::new((false, false)), |
| 479 | section_ids: RefCell::new(Vec::new()), |
| 480 | channels_scroll: ScrollHandle::new(), |
| 481 | chat_filter: ChatFilter::default(), |
| 482 | filter_box_open: false, |
| 483 | channel_filter: Default::default(), |
| 484 | channel_filter_open: false, |
| 485 | channel_filter_input: None, |
| 486 | channel_filter_subscription: None, |
| 487 | filter_input: None, |
| 488 | filter_subscription: None, |
| 489 | last_views: LastViews::default(), |
| 490 | _activity_observation: activity_observation, |
| 491 | _subscription: subscription, |
| 492 | _state_observation: state_observation, |
| 493 | _agent_observation: agent_observation, |
| 494 | _runs_observation: runs_observation, |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | pub fn tab(&self) -> SidebarTab { |
| 499 | self.tab |
| 500 | } |
| 501 | |
| 502 | pub fn show_activity(&mut self, cx: &mut Context<Self>) { |
| 503 | self.open_tab(SidebarTab::Activity, cx); |
| 504 | } |
| 505 | |
| 506 | pub fn show_chats(&mut self, cx: &mut Context<Self>) { |
| 507 | self.open_tab(SidebarTab::Chats, cx); |
| 508 | } |
| 509 | |
| 510 | pub fn show_channels(&mut self, cx: &mut Context<Self>) { |
| 511 | self.open_tab(SidebarTab::Channels, cx); |
| 512 | } |
| 513 | |
| 514 | pub fn show_calls(&mut self, cx: &mut Context<Self>) { |
| 515 | self.open_tab(SidebarTab::Calls, cx); |
| 516 | } |
| 517 | |
| 518 | pub fn show_calendar(&mut self, cx: &mut Context<Self>) { |
| 519 | self.open_tab(SidebarTab::Calendar, cx); |
| 520 | } |
| 521 | |
| 522 | pub fn open_quick_view(&mut self, view: QuickView, cx: &mut Context<Self>) { |
| 523 | self.open_tab(SidebarTab::Chats, cx); |
| 524 | self.state |
| 525 | .update(cx, |state, cx| state.open_quick_view(view, cx)); |
| 526 | } |
| 527 | |
| 528 | pub fn show_agents(&mut self, cx: &mut Context<Self>) { |
| 529 | self.open_tab(SidebarTab::Agents, cx); |
| 530 | } |
| 531 | |
| 532 | pub fn open_tab(&mut self, tab: SidebarTab, cx: &mut Context<Self>) { |
| 533 | if tab == SidebarTab::Agents && !crate::agents::agents_enabled(cx) { |
| 534 | return; |
| 535 | } |
| 536 | if tab == SidebarTab::Calendar && !self.state.read(cx).calendar_available() { |
| 537 | return; |
| 538 | } |
| 539 | let changed = self.tab != tab; |
| 540 | self.tab = tab; |
| 541 | if changed { |
| 542 | if tab != SidebarTab::Calendar { |
| 543 | self.state.update(cx, |state, _| state.close_calendar()); |
| 544 | } |
| 545 | self.restore_last_view(tab, cx); |
| 546 | cx.emit(SidebarEvent::TabChanged); |
| 547 | } |
| 548 | match tab { |
| 549 | SidebarTab::Calls => self.state.update(cx, |state, cx| { |
| 550 | state.refresh_call_history(cx); |
| 551 | state.refresh_calendar(cx); |
| 552 | }), |
| 553 | SidebarTab::Calendar => self.state.update(cx, |state, cx| state.open_calendar(cx)), |
| 554 | SidebarTab::Activity => { |
| 555 | let activity = self.activity_panel.read(cx).activity(); |
| 556 | activity.update(cx, |activity, cx| activity.mark_seen(cx)); |
| 557 | } |
| 558 | SidebarTab::Ponos => crate::kvt::board_opened(cx), |
| 559 | SidebarTab::Asclepius => crate::kvt::tickets_opened(cx), |
| 560 | _ => {} |
| 561 | } |
| 562 | cx.notify(); |
| 563 | } |
| 564 | |
| 565 | fn restore_last_view(&mut self, tab: SidebarTab, cx: &mut Context<Self>) { |
| 566 | let first_channel_id = self.first_channel_id(cx); |
| 567 | let state = self.state.read(cx); |
| 568 | if let Some(current) = &state.selection { |
| 569 | self.last_views.remember(current); |
| 570 | } |
| 571 | let first_chat_id = state.sidebar.chats.first().map(|chat| chat.id.as_str()); |
| 572 | if let Some(selection) = self.last_views.restore( |
| 573 | tab, |
| 574 | state.selection.as_ref(), |
| 575 | first_chat_id, |
| 576 | first_channel_id.as_deref(), |
| 577 | ) { |
| 578 | self.state |
| 579 | .update(cx, |state, cx| state.select(selection, cx)); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | pub fn select_adjacent(&mut self, step: Step, cx: &mut Context<Self>) { |
| 584 | let selection = match self.tab { |
| 585 | SidebarTab::Chats => self |
| 586 | .state |
| 587 | .read(cx) |
| 588 | .adjacent_chat_id(step) |
| 589 | .map(Selection::Chat), |
| 590 | SidebarTab::Channels => self.adjacent_channel_id(step, cx).map(Selection::Channel), |
| 591 | SidebarTab::Activity |
| 592 | | SidebarTab::Calendar |
| 593 | | SidebarTab::Calls |
| 594 | | SidebarTab::Agents |
| 595 | | SidebarTab::Ponos |
| 596 | | SidebarTab::Asclepius => None, |
| 597 | }; |
| 598 | if let Some(selection) = selection { |
| 599 | self.state |
| 600 | .update(cx, |state, cx| state.select(selection, cx)); |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | fn adjacent_channel_id(&self, step: Step, cx: &mut Context<Self>) -> Option<String> { |
| 605 | let state = self.state.read(cx); |
| 606 | let selected_channel = match &state.selection { |
| 607 | Some(Selection::Channel(channel_id)) => Some(channel_id.as_str()), |
| 608 | _ => None, |
| 609 | }; |
| 610 | let input = self.channel_order_input(state, selected_channel); |
| 611 | step_id(&visible_channel_ids(&input), selected_channel, step) |
| 612 | } |
| 613 | |
| 614 | fn first_channel_id(&self, cx: &App) -> Option<String> { |
| 615 | let input = self.channel_order_input(self.state.read(cx), None); |
| 616 | visible_channel_ids(&input) |
| 617 | .first() |
| 618 | .map(|id| (*id).to_owned()) |
| 619 | } |
| 620 | |
| 621 | fn channel_order_input<'a>( |
| 622 | &'a self, |
| 623 | state: &'a AppState, |
| 624 | selected_channel: Option<&'a str>, |
| 625 | ) -> ChannelOrderInput<'a> { |
| 626 | ChannelOrderInput { |
| 627 | teams: &state.sidebar.teams, |
| 628 | pinned_ids: &state.directory.pinned_channels, |
| 629 | collapsed_teams: &self.collapsed_teams, |
| 630 | revealed_channel_teams: &self.revealed_channel_teams, |
| 631 | hidden_teams_open: self.hidden_teams_open, |
| 632 | selected_channel, |
| 633 | } |
| 634 | } |
| 635 | |
| 636 | fn expand_team_of_selection(&mut self, cx: &mut Context<Self>) { |
| 637 | let state = self.state.read(cx); |
| 638 | let Some(Selection::Channel(channel_id)) = state.selection.clone() else { |
| 639 | return; |
| 640 | }; |
| 641 | let team_id = state |
| 642 | .sidebar |
| 643 | .teams |
| 644 | .iter() |
| 645 | .find(|entry| { |
| 646 | entry |
| 647 | .channels |
| 648 | .iter() |
| 649 | .any(|channel| channel.id == channel_id) |
| 650 | }) |
| 651 | .map(|entry| entry.team.id.clone()); |
| 652 | if let Some(team_id) = team_id |
| 653 | && self.collapsed_teams.remove(&team_id) |
| 654 | { |
| 655 | save_collapsed_teams(&self.state.read(cx).store, &self.collapsed_teams); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | fn new_chat_button(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 660 | let active = self.state.read(cx).new_chat; |
| 661 | div() |
| 662 | .id("new-chat") |
| 663 | .size(px(NEW_CHAT_BUTTON_SIZE)) |
| 664 | .flex_none() |
| 665 | .flex() |
| 666 | .items_center() |
| 667 | .justify_center() |
| 668 | .rounded(px(8.)) |
| 669 | .bg(theme::surface_raised()) |
| 670 | .cursor_pointer() |
| 671 | .when(active, |button| button.bg(theme::popup_hover())) |
| 672 | .hover(|button| button.bg(theme::popup_hover())) |
| 673 | .tooltip(|window, cx| Tooltip::new(tr("sidebar.new_chat_shortcut")).build(window, cx)) |
| 674 | .child(icon(IconName::Pencil, 16., theme::text_soft())) |
| 675 | .on_click(cx.listener(|this, _, _, cx| { |
| 676 | this.state.update(cx, |state, cx| state.start_new_chat(cx)); |
| 677 | })) |
| 678 | } |
| 679 | |
| 680 | fn chat_list_menu_button(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 681 | let state = self.state.clone(); |
| 682 | let section_ids = self.section_ids.borrow().clone(); |
| 683 | let read_only = self.state.read(cx).mode.read_only; |
| 684 | Button::new("chat-list-more") |
| 685 | .icon(IconName::Ellipsis) |
| 686 | .ghost() |
| 687 | .size(px(NEW_CHAT_BUTTON_SIZE)) |
| 688 | .rounded(px(8.)) |
| 689 | .tooltip(tr("sidebar.more_options")) |
| 690 | .dropdown_menu(move |menu, _, _| { |
| 691 | let (read_state, collapse_state) = (state.clone(), state.clone()); |
| 692 | let section_ids = section_ids.clone(); |
| 693 | menu.item( |
| 694 | PopupMenuItem::new(tr("sidebar.mark_all_read")) |
| 695 | .icon(menu_icon(IconName::CheckCheck)) |
| 696 | .disabled(read_only) |
| 697 | .on_click(move |_, _, cx| { |
| 698 | read_state.update(cx, |state, cx| state.mark_all_chats_read(cx)); |
| 699 | }), |
| 700 | ) |
| 701 | .item( |
| 702 | PopupMenuItem::new(tr("sidebar.collapse_all")) |
| 703 | .icon(menu_icon(IconName::ChevronsDownUp)) |
| 704 | .on_click(move |_, _, cx| { |
| 705 | let ids = section_ids.clone(); |
| 706 | collapse_state |
| 707 | .update(cx, |state, cx| state.collapse_sections(&ids, cx)); |
| 708 | }), |
| 709 | ) |
| 710 | .separator() |
| 711 | .item(new_section_item(&state, read_only)) |
| 712 | }) |
| 713 | } |
| 714 | |
| 715 | fn channel_list_menu_button(&self, cx: &mut Context<Self>) -> impl IntoElement { |
| 716 | let state = self.state.clone(); |
| 717 | let read_only = self.state.read(cx).mode.read_only; |
| 718 | let view = cx.entity().downgrade(); |
| 719 | let team_ids: Vec<String> = self |
| 720 | .state |
| 721 | .read(cx) |
| 722 | .sidebar |
| 723 | .teams |
| 724 | .iter() |
| 725 | .map(|entry| entry.team.id.clone()) |
| 726 | .collect(); |
| 727 | Button::new("channel-list-more") |
| 728 | .icon(IconName::Ellipsis) |
| 729 | .ghost() |
| 730 | .size(px(NEW_CHAT_BUTTON_SIZE)) |
| 731 | .rounded(px(8.)) |
| 732 | .tooltip(tr("sidebar.more_options")) |
| 733 | .dropdown_menu(move |menu, _, _| { |
| 734 | let (state, view, team_ids) = (state.clone(), view.clone(), team_ids.clone()); |
| 735 | menu.item( |
| 736 | PopupMenuItem::new(tr("sidebar.mark_all_read")) |
| 737 | .icon(menu_icon(IconName::CheckCheck)) |
| 738 | .disabled(read_only) |
| 739 | .on_click(move |_, _, cx| { |
| 740 | state.update(cx, |state, cx| state.mark_all_channels_read(cx)); |
| 741 | }), |
| 742 | ) |
| 743 | .item( |
| 744 | PopupMenuItem::new(tr("sidebar.collapse_all")) |
| 745 | .icon(menu_icon(IconName::ChevronsDownUp)) |
| 746 | .on_click(move |_, _, cx| { |
| 747 | let team_ids = team_ids.clone(); |
| 748 | view.update(cx, |this, cx| this.collapse_all_teams(team_ids, cx)) |
| 749 | .ok(); |
| 750 | }), |
| 751 | ) |
| 752 | }) |
| 753 | } |
| 754 | |
| 755 | fn draft_row(&self) -> impl IntoElement { |
| 756 | h_flex() |
| 757 | .id("new-chat-draft") |
| 758 | .mx(px(6.)) |
| 759 | .h(px(ROW_HEIGHT)) |
| 760 | .flex_none() |
| 761 | .px(px(10.)) |
| 762 | .gap(px(12.)) |
| 763 | .items_center() |
| 764 | .rounded(px(8.)) |
| 765 | .bg(theme::surface_raised()) |
| 766 | .child( |
| 767 | div() |
| 768 | .size(px(AVATAR_SIZE)) |
| 769 | .flex_none() |
| 770 | .flex() |
| 771 | .items_center() |
| 772 | .justify_center() |
| 773 | .rounded_full() |
| 774 | .bg(theme::border_strong()) |
| 775 | .child(icon(IconName::Pencil, 16., theme::text())), |
| 776 | ) |
| 777 | .child( |
| 778 | v_flex() |
| 779 | .flex_1() |
| 780 | .min_w_0() |
| 781 | .gap(px(2.)) |
| 782 | .child( |
| 783 | div() |
| 784 | .truncate() |
| 785 | .text_size(px(14.)) |
| 786 | .text_color(theme::text()) |
| 787 | .child(tr("sidebar.new_chat")), |
| 788 | ) |
| 789 | .child( |
| 790 | div() |
| 791 | .truncate() |
| 792 | .text_size(px(12.5)) |
| 793 | .text_color(theme::text_muted()) |
| 794 | .child(tr("sidebar.draft")), |
| 795 | ), |
| 796 | ) |
| 797 | } |
| 798 | |
| 799 | fn section_header( |
| 800 | &self, |
| 801 | section: &Section, |
| 802 | menu: SectionMenuTarget, |
| 803 | cx: &mut Context<Self>, |
| 804 | ) -> impl IntoElement { |
| 805 | let drop_target = drop_target(section); |
| 806 | let toggle_id = section.id.clone(); |
| 807 | let menu_state = self.state.clone(); |
| 808 | h_flex() |
| 809 | .id(SharedString::from(format!("section-{}", section.id))) |
| 810 | .h(px(SECTION_HEIGHT)) |
| 811 | .mt(px(SECTION_GAP)) |
| 812 | .mx(px(6.)) |
| 813 | .px(px(10.)) |
| 814 | .gap(px(6.)) |
| 815 | .items_center() |
| 816 | .rounded(px(6.)) |
| 817 | .cursor_pointer() |
| 818 | .hover(|header| header.bg(theme::row_hover())) |
| 819 | .when_some(drop_target, |header, drop_target| { |
| 820 | header |
| 821 | .drag_over::<DraggedChat>(|style, _, _, _| { |
| 822 | style |
| 823 | .bg(theme::drop_background()) |
| 824 | .border_1() |
| 825 | .border_color(theme::accent()) |
| 826 | }) |
| 827 | .on_drop(cx.listener(move |this, dragged: &DraggedChat, _, cx| { |
| 828 | let target = drop_target.clone(); |
| 829 | this.state.update(cx, |state, cx| { |
| 830 | state.move_chat(&dragged.id, target.as_deref(), cx) |
| 831 | }); |
| 832 | })) |
| 833 | }) |
| 834 | .child(icon( |
| 835 | if section.collapsed { |
| 836 | IconName::ChevronRight |
| 837 | } else { |
| 838 | IconName::ChevronDown |
| 839 | }, |
| 840 | 12., |
| 841 | theme::text_muted(), |
| 842 | )) |
| 843 | .child( |
| 844 | div() |
| 845 | .flex_1() |
| 846 | .min_w_0() |
| 847 | .truncate() |
| 848 | .text_size(px(12.)) |
| 849 | .font_weight(FontWeight::SEMIBOLD) |
| 850 | .text_color(theme::text_soft()) |
| 851 | .child(section.name.clone()), |
| 852 | ) |
| 853 | .when(section.collapsed && section.unread_chats > 0, |header| { |
| 854 | header.child(count_badge(section.unread_chats, false)) |
| 855 | }) |
| 856 | .on_click(cx.listener(move |this, _, _, cx| { |
| 857 | let id = toggle_id.clone(); |
| 858 | this.state |
| 859 | .update(cx, |state, cx| state.toggle_collapsed(&id, cx)); |
| 860 | })) |
| 861 | .context_menu(move |popup, _, _| section_menu(popup, &menu_state, &menu)) |
| 862 | } |
| 863 | |
| 864 | fn quick_views_section(&self, cx: &mut Context<Self>) -> (Div, f32) { |
| 865 | let (collapsed, open_view) = { |
| 866 | let state = self.state.read(cx); |
| 867 | ( |
| 868 | state.collapsed.contains(QUICK_VIEWS_SECTION_ID), |
| 869 | state.quick_view, |
| 870 | ) |
| 871 | }; |
| 872 | let header = h_flex() |
| 873 | .id(QUICK_VIEWS_SECTION_ID) |
| 874 | .h(px(SECTION_HEIGHT)) |
| 875 | .flex_none() |
| 876 | .mt(px(SECTION_GAP)) |
| 877 | .mx(px(6.)) |
| 878 | .px(px(10.)) |
| 879 | .gap(px(6.)) |
| 880 | .items_center() |
| 881 | .rounded(px(6.)) |
| 882 | .cursor_pointer() |
| 883 | .hover(|header| header.bg(theme::row_hover())) |
| 884 | .child(icon( |
| 885 | if collapsed { |
| 886 | IconName::ChevronRight |
| 887 | } else { |
| 888 | IconName::ChevronDown |
| 889 | }, |
| 890 | 12., |
| 891 | theme::text_muted(), |
| 892 | )) |
| 893 | .child( |
| 894 | div() |
| 895 | .flex_1() |
| 896 | .text_size(px(12.)) |
| 897 | .font_weight(FontWeight::SEMIBOLD) |
| 898 | .text_color(theme::text_soft()) |
| 899 | .child(tr("sidebar.quick_views")), |
| 900 | ) |
| 901 | .on_click(cx.listener(|this, _, _, cx| { |
| 902 | this.state.update(cx, |state, cx| { |
| 903 | state.toggle_collapsed(QUICK_VIEWS_SECTION_ID, cx) |
| 904 | }); |
| 905 | })); |
| 906 | let mut section = v_flex().w_full().child(header); |
| 907 | let mut height = SECTION_GAP + SECTION_HEIGHT; |
| 908 | if !collapsed { |
| 909 | for (view, glyph) in QUICK_VIEWS { |
| 910 | section = |
| 911 | section.child(self.quick_view_row(view, glyph, open_view == Some(view), cx)); |
| 912 | height += QUICK_ROW_HEIGHT; |
| 913 | } |
| 914 | } |
| 915 | (section, height) |
| 916 | } |
| 917 | |
| 918 | fn quick_view_row( |
| 919 | &self, |
| 920 | view: QuickView, |
| 921 | glyph: &'static str, |
| 922 | selected: bool, |
| 923 | cx: &mut Context<Self>, |
| 924 | ) -> Stateful<Div> { |
| 925 | h_flex() |
| 926 | .id(SharedString::from(format!("quick-view-{}", view.title()))) |
| 927 | .debug_selector(move || format!("quick-view/{}", view.title())) |
| 928 | .h(px(QUICK_ROW_HEIGHT)) |
| 929 | .flex_none() |
| 930 | .mx(px(6.)) |
| 931 | .px(px(10.)) |
| 932 | .gap(px(10.)) |
| 933 | .items_center() |
| 934 | .rounded(px(8.)) |
| 935 | .cursor_pointer() |
| 936 | .when(selected, |row| row.bg(theme::surface_raised())) |
| 937 | .when(!selected, |row| row.hover(|row| row.bg(theme::row_hover()))) |
| 938 | .child(symbol(glyph, QUICK_ICON_SIZE, theme::text_soft())) |
| 939 | .child( |
| 940 | div() |
| 941 | .text_size(px(13.)) |
| 942 | .text_color(theme::text()) |
| 943 | .child(view.title()), |
| 944 | ) |
| 945 | .on_click(cx.listener(move |this, _, _, cx| { |
| 946 | this.state |
| 947 | .update(cx, |state, cx| state.open_quick_view(view, cx)); |
| 948 | })) |
| 949 | } |
| 950 | |
| 951 | fn see_more_row(&self, section: &Section, cx: &mut Context<Self>) -> impl IntoElement { |
| 952 | let toggle_id = section.id.clone(); |
| 953 | let label = if section.hidden_count > 0 { |
| 954 | let mut args = HashMap::new(); |
| 955 | args.insert("count".to_owned(), section.hidden_count.to_string()); |
| 956 | tr_args("sidebar.see_more", &args) |
| 957 | } else { |
| 958 | tr("sidebar.see_less") |
| 959 | }; |
| 960 | div() |
| 961 | .id(SharedString::from(format!("see-more-{}", section.id))) |
| 962 | .mx(px(6.)) |
| 963 | .pl(px(10. + AVATAR_SIZE + 12.)) |
| 964 | .h(px(SEE_MORE_HEIGHT)) |
| 965 | .flex() |
| 966 | .items_center() |
| 967 | .rounded(px(6.)) |
| 968 | .cursor_pointer() |
| 969 | .text_size(px(12.5)) |
| 970 | .text_color(theme::accent_text()) |
| 971 | .hover(|row| row.bg(theme::row_hover())) |
| 972 | .child(label) |
| 973 | .on_click(cx.listener(move |this, _, _, cx| { |
| 974 | let id = toggle_id.clone(); |
| 975 | this.state |
| 976 | .update(cx, |state, cx| state.toggle_list_expanded(&id, cx)); |
| 977 | })) |
| 978 | } |
| 979 | |
| 980 | fn chat_row( |
| 981 | &self, |
| 982 | item: &ChatItem, |
| 983 | selected: bool, |
| 984 | local_preview: Option<&LocalPreview>, |
| 985 | proposal_agent: Option<&'static str>, |
| 986 | directory: &Directory, |
| 987 | menu: &MenuContext, |
| 988 | ) -> AnyElement { |
| 989 | let ring = if selected { |
| 990 | theme::surface_raised() |
| 991 | } else { |
| 992 | theme::surface() |
| 993 | }; |
| 994 | let unread = item.unread.is_unread(); |
| 995 | let presence = item |
| 996 | .presence_user |
| 997 | .as_deref() |
| 998 | .map(|user_id| directory.presence_of(user_id)); |
| 999 | let avatar = spec_avatar(directory, &item.avatar, AVATAR_SIZE, ring); |
| 1000 | let avatar = match presence { |
| 1001 | Some(kind) => with_presence(avatar, kind, AVATAR_SIZE, ring).into_any_element(), |
| 1002 | None => avatar, |
| 1003 | }; |
| 1004 | let name = div() |
| 1005 | .flex_1() |
| 1006 | .min_w_0() |
| 1007 | .truncate() |
| 1008 | .text_size(px(14.)) |
| 1009 | .font_weight(if unread { |
| 1010 | FontWeight::BOLD |
| 1011 | } else { |
| 1012 | FontWeight::NORMAL |
| 1013 | }) |
| 1014 | .text_color(theme::text()) |
| 1015 | .child(item.title.clone()); |
| 1016 | let row_group = SharedString::from(format!("chat-row-{}", item.id)); |
| 1017 | let time = h_flex() |
| 1018 | .flex_none() |
| 1019 | .gap(px(4.)) |
| 1020 | .items_center() |
| 1021 | .text_size(px(11.)) |
| 1022 | .text_color(if unread { |
| 1023 | theme::accent_text() |
| 1024 | } else { |
| 1025 | theme::text_muted() |
| 1026 | }) |
| 1027 | .group_hover(row_group.clone(), |time| time.invisible()) |
| 1028 | .child(item.time_label.clone()); |
| 1029 | let preview_color = if matches!(item.preview, Preview::Typing(_)) { |
| 1030 | theme::accent_text() |
| 1031 | } else if unread { |
| 1032 | theme::text_strong() |
| 1033 | } else { |
| 1034 | theme::text_muted() |
| 1035 | }; |
| 1036 | let preview = match (proposal_agent, local_preview) { |
| 1037 | (Some(agent), _) => Some( |
| 1038 | h_flex() |
| 1039 | .flex_1() |
| 1040 | .min_w_0() |
| 1041 | .overflow_hidden() |
| 1042 | .text_size(px(12.5)) |
| 1043 | .text_color(theme::accent_text()) |
| 1044 | .child(div().truncate().child(format!("Proposal from {agent}"))), |
| 1045 | ), |
| 1046 | (None, Some(local)) => Some(local_preview_row(local, preview_color)), |
| 1047 | (None, None) => preview_text(&item.preview).map(|(text, italic)| { |
| 1048 | h_flex() |
| 1049 | .flex_1() |
| 1050 | .min_w_0() |
| 1051 | .overflow_hidden() |
| 1052 | .gap(px(4.)) |
| 1053 | .items_center() |
| 1054 | .text_size(px(12.5)) |
| 1055 | .when(italic, |preview| preview.italic()) |
| 1056 | .text_color(preview_color) |
| 1057 | .child(div().truncate().child(text)) |
| 1058 | }), |
| 1059 | }; |
| 1060 | let lines = v_flex() |
| 1061 | .flex_1() |
| 1062 | .min_w_0() |
| 1063 | .gap(px(2.)) |
| 1064 | .child( |
| 1065 | h_flex() |
| 1066 | .gap(px(8.)) |
| 1067 | .items_baseline() |
| 1068 | .child(name) |
| 1069 | .child(time), |
| 1070 | ) |
| 1071 | .child( |
| 1072 | h_flex() |
| 1073 | .h(px(18.)) |
| 1074 | .gap(px(8.)) |
| 1075 | .items_center() |
| 1076 | .child(preview.unwrap_or_else(|| div().flex_1())) |
| 1077 | .children(importance_marker(item.importance)) |
| 1078 | .children(match proposal_agent { |
| 1079 | Some(_) => Some( |
| 1080 | div() |
| 1081 | .size(px(PROPOSAL_DOT_SIZE)) |
| 1082 | .flex_none() |
| 1083 | .rounded_full() |
| 1084 | .bg(theme::accent()) |
| 1085 | .into_any_element(), |
| 1086 | ), |
| 1087 | None => unread_marker(item.unread, item.muted) |
| 1088 | .map(IntoElement::into_any_element), |
| 1089 | }), |
| 1090 | ); |
| 1091 | let state = self.state.clone(); |
| 1092 | let chat_id = item.id.clone(); |
| 1093 | let (warm_state, warm_chat_id) = (self.state.clone(), item.id.clone()); |
| 1094 | let dragged = DraggedChat { |
| 1095 | id: item.id.clone(), |
| 1096 | title: item.title.clone(), |
| 1097 | }; |
| 1098 | let menu_context = menu.clone(); |
| 1099 | let reorder_folder = item |
| 1100 | .folder_id |
| 1101 | .clone() |
| 1102 | .filter(|folder_id| !is_pending_folder(folder_id)); |
| 1103 | let target = ChatMenuTarget { |
| 1104 | id: item.id.clone(), |
| 1105 | title: item.title.clone(), |
| 1106 | folder_id: item.folder_id.clone(), |
| 1107 | unread, |
| 1108 | muted: item.muted, |
| 1109 | is_group: item.is_group, |
| 1110 | member_count: item.member_count, |
| 1111 | }; |
| 1112 | let more_context = menu.clone(); |
| 1113 | let more_target = target.clone(); |
| 1114 | let more_button = div() |
| 1115 | .absolute() |
| 1116 | .top(px(ROW_MORE_TOP)) |
| 1117 | .right(px(ROW_MORE_RIGHT)) |
| 1118 | .invisible() |
| 1119 | .group_hover(row_group.clone(), |button| button.visible()) |
| 1120 | .on_mouse_down(MouseButton::Left, |_, _, cx| cx.stop_propagation()) |
| 1121 | .child( |
| 1122 | Button::new(SharedString::from(format!("chat-more-{}", item.id))) |
| 1123 | .ghost() |
| 1124 | .xsmall() |
| 1125 | .icon(IconName::Ellipsis) |
| 1126 | .tooltip(tr("sidebar.more_options")) |
| 1127 | .dropdown_menu(move |popup, window, cx| { |
| 1128 | chat_menu(popup, window, cx, &more_context, &more_target) |
| 1129 | }), |
| 1130 | ); |
| 1131 | h_flex() |
| 1132 | .id(SharedString::from(format!("chat-{}", item.id))) |
| 1133 | .debug_selector(|| chat_row_selector(&item.id)) |
| 1134 | .group(row_group) |
| 1135 | .relative() |
| 1136 | .mx(px(6.)) |
| 1137 | .h(px(ROW_HEIGHT)) |
| 1138 | .flex_none() |
| 1139 | .px(px(10.)) |
| 1140 | .gap(px(12.)) |
| 1141 | .items_center() |
| 1142 | .rounded(px(8.)) |
| 1143 | .cursor_pointer() |
| 1144 | .when(selected, |row| row.bg(theme::surface_raised())) |
| 1145 | .when(!selected, |row| row.hover(|row| row.bg(theme::row_hover()))) |
| 1146 | .on_drag(dragged, |dragged, _, _, cx| { |
| 1147 | let title = dragged.title.clone(); |
| 1148 | cx.new(|_| DragGhost { title }) |
| 1149 | }) |
| 1150 | .when_some(reorder_folder, |row, folder_id| { |
| 1151 | let (drop_state, target_id) = (self.state.clone(), item.id.clone()); |
| 1152 | row.drag_over::<DraggedChat>(|style, _, _, _| style.bg(theme::drop_background())) |
| 1153 | .on_drop(move |dragged: &DraggedChat, _, cx| { |
| 1154 | drop_state.update(cx, |state, cx| { |
| 1155 | state.drop_chat_on(&dragged.id, &target_id, &folder_id, cx) |
| 1156 | }); |
| 1157 | }) |
| 1158 | }) |
| 1159 | .child(avatar) |
| 1160 | .child(lines) |
| 1161 | .child(more_button) |
| 1162 | .on_hover(move |hovered, _, cx| { |
| 1163 | if *hovered { |
| 1164 | warm_state.update(cx, |state, _| state.warm_chat(&warm_chat_id)); |
| 1165 | } |
| 1166 | }) |
| 1167 | .on_click(move |_, _, cx| { |
| 1168 | let selection = Selection::Chat(chat_id.clone()); |
| 1169 | state.update(cx, |state, cx| state.select(selection, cx)); |
| 1170 | }) |
| 1171 | .context_menu(move |popup, window, cx| { |
| 1172 | chat_menu(popup, window, cx, &menu_context, &target) |
| 1173 | }) |
| 1174 | .into_any_element() |
| 1175 | } |
| 1176 | |
| 1177 | fn chats_body(&self, window_height: f32, cx: &mut Context<Self>) -> AnyElement { |
| 1178 | let proposal_agents = crate::agent_api::pending_agents(cx); |
| 1179 | let (sections, section_menus, menu, local_previews) = { |
| 1180 | let state = self.state.read(cx); |
| 1181 | let now = Utc::now(); |
| 1182 | let offset = app_base::format::Zone::Local; |
| 1183 | let input = SectionInput { |
| 1184 | chats: &state.sidebar.chats, |
| 1185 | directory: &state.directory, |
| 1186 | collapsed: &state.collapsed, |
| 1187 | expanded_lists: &state.expanded_lists, |
| 1188 | typing: &state.typing, |
| 1189 | now, |
| 1190 | offset, |
| 1191 | }; |
| 1192 | let sections = if self.chat_filter.is_active() { |
| 1193 | let mentioned = self.mentioned_chats(cx); |
| 1194 | let selected_id = self.selected_chat_id(cx); |
| 1195 | filtered_sections( |
| 1196 | &input, |
| 1197 | &self.chat_filter, |
| 1198 | &mentioned, |
| 1199 | selected_id.as_deref(), |
| 1200 | ) |
| 1201 | } else { |
| 1202 | build_sections(&input) |
| 1203 | }; |
| 1204 | let menu = MenuContext::new(&self.state, cx); |
| 1205 | let section_menus = |
| 1206 | section_menu_targets(§ions, &state.directory, state.mode.read_only); |
| 1207 | *self.section_ids.borrow_mut() = |
| 1208 | sections.iter().map(|section| section.id.clone()).collect(); |
| 1209 | (sections, section_menus, menu, state.local_previews.clone()) |
| 1210 | }; |
| 1211 | |
| 1212 | let top = -f32::from(scroll_offset(&self.chats_scroll).y); |
| 1213 | let measured: f32 = f32::from(self.chats_scroll.bounds().size.height); |
| 1214 | let height = if measured > 1. { |
| 1215 | measured |
| 1216 | } else { |
| 1217 | window_height.max(FALLBACK_VIEWPORT) |
| 1218 | }; |
| 1219 | let (visible_from, visible_to) = (top - VIEWPORT_MARGIN, top + height + VIEWPORT_MARGIN); |
| 1220 | |
| 1221 | let (selected, drafting) = { |
| 1222 | let state = self.state.read(cx); |
| 1223 | ( |
| 1224 | state |
| 1225 | .selection |
| 1226 | .clone() |
| 1227 | .filter(|_| !state.new_chat && state.quick_view.is_none()), |
| 1228 | state.new_chat, |
| 1229 | ) |
| 1230 | }; |
| 1231 | let mut faces: Vec<String> = Vec::new(); |
| 1232 | let mut presence_users: Vec<String> = Vec::new(); |
| 1233 | let mut y = 0.; |
| 1234 | let mut list = v_flex().w_full().pb(px(12.)); |
| 1235 | let mut skipped_height = 0.; |
| 1236 | let mut others_end = None; |
| 1237 | let directory_state = self.state.clone(); |
| 1238 | if drafting { |
| 1239 | list = list.child(self.draft_row()); |
| 1240 | y += ROW_HEIGHT; |
| 1241 | } |
| 1242 | if !self.chat_filter.is_active() { |
| 1243 | let (quick_views, quick_height) = self.quick_views_section(cx); |
| 1244 | list = list.child(quick_views); |
| 1245 | y += quick_height; |
| 1246 | } |
| 1247 | for (section, section_menu) in sections.iter().zip(section_menus) { |
| 1248 | list = with_spacer(list, &mut skipped_height); |
| 1249 | list = list.child(self.section_header(section, section_menu, cx)); |
| 1250 | y += SECTION_GAP + SECTION_HEIGHT; |
| 1251 | if section.collapsed { |
| 1252 | continue; |
| 1253 | } |
| 1254 | for item in §ion.items { |
| 1255 | let on_screen = y + ROW_HEIGHT >= visible_from && y <= visible_to; |
| 1256 | if on_screen { |
| 1257 | collect_faces(&item.avatar, &mut faces); |
| 1258 | presence_users.extend(item.presence_user.clone()); |
| 1259 | } |
| 1260 | if on_screen { |
| 1261 | list = with_spacer(list, &mut skipped_height); |
| 1262 | let is_selected = selected == Some(Selection::Chat(item.id.clone())); |
| 1263 | let directory = &directory_state.read(cx).directory; |
| 1264 | let local_preview = local_previews.get(&item.id).filter(|_| !is_selected); |
| 1265 | list = list.child(self.chat_row( |
| 1266 | item, |
| 1267 | is_selected, |
| 1268 | local_preview, |
| 1269 | proposal_agents.get(&item.id).copied(), |
| 1270 | directory, |
| 1271 | &menu, |
| 1272 | )); |
| 1273 | } else { |
| 1274 | skipped_height += ROW_HEIGHT; |
| 1275 | } |
| 1276 | y += ROW_HEIGHT; |
| 1277 | } |
| 1278 | if section.kind == SectionKind::Others { |
| 1279 | others_end = Some(y); |
| 1280 | } |
| 1281 | if section.hidden_count > 0 || section.list_expanded { |
| 1282 | list = with_spacer(list, &mut skipped_height); |
| 1283 | list = list.child(self.see_more_row(section, cx)); |
| 1284 | y += SEE_MORE_HEIGHT; |
| 1285 | } |
| 1286 | if section.show_empty_hint { |
| 1287 | list = with_spacer(list, &mut skipped_height); |
| 1288 | list = list.child( |
| 1289 | div() |
| 1290 | .ml(px(16.)) |
| 1291 | .mr(px(16.)) |
| 1292 | .h(px(HINT_HEIGHT)) |
| 1293 | .flex() |
| 1294 | .items_center() |
| 1295 | .text_size(px(12.)) |
| 1296 | .italic() |
| 1297 | .text_color(theme::text_faint()) |
| 1298 | .child(EMPTY_FOLDER_HINT), |
| 1299 | ); |
| 1300 | y += HINT_HEIGHT; |
| 1301 | } |
| 1302 | } |
| 1303 | let (has_older, loading_older) = self.state.read(cx).older_chats(); |
| 1304 | let previous = self.older_chats_seen.replace((has_older, loading_older)); |
| 1305 | if older_chats_trigger_resets(previous, (has_older, loading_older)) { |
| 1306 | self.older_chats_trigger_top.set(None); |
| 1307 | } |
| 1308 | if has_older |
| 1309 | && wants_older_chats( |
| 1310 | others_end, |
| 1311 | top + height, |
| 1312 | top, |
| 1313 | self.older_chats_trigger_top.get(), |
| 1314 | loading_older, |
| 1315 | ) |
| 1316 | { |
| 1317 | self.older_chats_trigger_top.set(Some(top)); |
| 1318 | let state = self.state.clone(); |
| 1319 | cx.defer(move |cx| state.read(cx).request_older_chats()); |
| 1320 | } |
| 1321 | if loading_older { |
| 1322 | list = with_spacer(list, &mut skipped_height); |
| 1323 | list = list.child( |
| 1324 | div() |
| 1325 | .pl(px(16. + AVATAR_SIZE + 12.)) |
| 1326 | .h(px(SEE_MORE_HEIGHT)) |
| 1327 | .flex() |
| 1328 | .items_center() |
| 1329 | .text_size(px(12.5)) |
| 1330 | .italic() |
| 1331 | .text_color(theme::text_faint()) |
| 1332 | .child(tr("sidebar.loading_older")), |
| 1333 | ); |
| 1334 | } |
| 1335 | let selected_chat_id = self.selected_chat_id(cx); |
| 1336 | if self.chat_filter.is_active() && has_no_matches(§ions, selected_chat_id.as_deref()) { |
| 1337 | list = list.child(self.filter_empty_state(cx)); |
| 1338 | } |
| 1339 | list = with_spacer(list, &mut skipped_height); |
| 1340 | self.request_lazy_data(faces, presence_users, cx); |
| 1341 | let scroll_area = div() |
| 1342 | .id("chats-scroll") |
| 1343 | .flex_1() |
| 1344 | .min_h_0() |
| 1345 | .overflow_y_scrollbar() |
| 1346 | .track_scroll(&self.chats_scroll) |
| 1347 | .child(list); |
| 1348 | with_top_edge(scroll_area, &self.chats_scroll, SIDEBAR_SCROLL_DIVIDER).into_any_element() |
| 1349 | } |
| 1350 | |
| 1351 | fn request_lazy_data( |
| 1352 | &self, |
| 1353 | faces: Vec<String>, |
| 1354 | presence_users: Vec<String>, |
| 1355 | cx: &mut Context<Self>, |
| 1356 | ) { |
| 1357 | if faces.is_empty() && presence_users.is_empty() { |
| 1358 | return; |
| 1359 | } |
| 1360 | let state = self.state.clone(); |
| 1361 | cx.defer(move |cx| { |
| 1362 | state.update(cx, |state, cx| { |
| 1363 | state.request_avatars(faces, cx); |
| 1364 | state.request_presence(presence_users, cx); |
| 1365 | }); |
| 1366 | }); |
| 1367 | } |
| 1368 | |
| 1369 | fn channel_row( |
| 1370 | &self, |
| 1371 | channel_id: &str, |
| 1372 | entry: &SidebarTeam, |
| 1373 | channel: &ChannelRecord, |
| 1374 | selected: bool, |
| 1375 | team_photo: Option<&AvatarState>, |
| 1376 | ) -> AnyElement { |
| 1377 | let team = &entry.team; |
| 1378 | let unread = channel_shows_unread(entry, channel); |
| 1379 | let notifications = entry.channel_notifications(channel_id); |
| 1380 | let badge = channel_badge(entry, channel_id); |
| 1381 | let name_style = channel_name_style(unread, true, selected); |
| 1382 | let state = self.state.clone(); |
| 1383 | let menu_state = self.state.clone(); |
| 1384 | let menu_channel_id = channel_id.to_owned(); |
| 1385 | let selection = Selection::Channel(channel_id.to_owned()); |
| 1386 | let time = channel_activity(channel); |
| 1387 | h_flex() |
| 1388 | .id(SharedString::from(format!("pinned-{channel_id}"))) |
| 1389 | .mx(px(6.)) |
| 1390 | .h(px(PINNED_CHANNEL_HEIGHT)) |
| 1391 | .px(px(10.)) |
| 1392 | .gap(px(12.)) |
| 1393 | .items_center() |
| 1394 | .rounded(px(8.)) |
| 1395 | .cursor_pointer() |
| 1396 | .when(selected, |row| row.bg(theme::surface_raised())) |
| 1397 | .when(!selected, |row| row.hover(|row| row.bg(theme::row_hover()))) |
| 1398 | .child(team_avatar(team_photo, &team.name, &team.id, 28., 7.)) |
| 1399 | .child( |
| 1400 | v_flex() |
| 1401 | .flex_1() |
| 1402 | .min_w_0() |
| 1403 | .gap(px(1.)) |
| 1404 | .child( |
| 1405 | h_flex() |
| 1406 | .gap(px(8.)) |
| 1407 | .items_baseline() |
| 1408 | .child( |
| 1409 | div() |
| 1410 | .flex_1() |
| 1411 | .min_w_0() |
| 1412 | .truncate() |
| 1413 | .text_size(px(13.5)) |
| 1414 | .font_weight(name_weight(name_style)) |
| 1415 | .text_color(name_color(name_style)) |
| 1416 | .child(format!("{} / {}", team.name, channel.name)), |
| 1417 | ) |
| 1418 | .children(notification_badge(notifications.level)) |
| 1419 | .child( |
| 1420 | div() |
| 1421 | .flex_none() |
| 1422 | .text_size(px(11.)) |
| 1423 | .text_color(if unread { |
| 1424 | theme::accent_text() |
| 1425 | } else { |
| 1426 | theme::text_muted() |
| 1427 | }) |
| 1428 | .child(time), |
| 1429 | ), |
| 1430 | ) |
| 1431 | .child( |
| 1432 | h_flex() |
| 1433 | .gap(px(8.)) |
| 1434 | .items_center() |
| 1435 | .child( |
| 1436 | div() |
| 1437 | .flex_1() |
| 1438 | .min_w_0() |
| 1439 | .truncate() |
| 1440 | .text_size(px(12.)) |
| 1441 | .text_color(theme::text_muted()) |
| 1442 | .child(team.name.clone()), |
| 1443 | ) |
| 1444 | .children(badge.map(mention_badge)), |
| 1445 | ), |
| 1446 | ) |
| 1447 | .on_click(move |_, _, cx| { |
| 1448 | let selection = selection.clone(); |
| 1449 | state.update(cx, |state, cx| state.select(selection, cx)); |
| 1450 | }) |
| 1451 | .context_menu(move |popup, window, cx| { |
| 1452 | channel_menu( |
| 1453 | popup, |
| 1454 | window, |
| 1455 | cx, |
| 1456 | menu_state.clone(), |
| 1457 | &menu_channel_id, |
| 1458 | notifications, |
| 1459 | ) |
| 1460 | }) |
| 1461 | .into_any_element() |
| 1462 | } |
| 1463 | |
| 1464 | fn plain_header(&self, label: impl Into<SharedString>) -> impl IntoElement { |
| 1465 | div() |
| 1466 | .h(px(SECTION_HEIGHT)) |
| 1467 | .mt(px(SECTION_GAP)) |
| 1468 | .px(px(16.)) |
| 1469 | .flex() |
| 1470 | .items_center() |
| 1471 | .text_size(px(12.)) |
| 1472 | .font_weight(FontWeight::SEMIBOLD) |
| 1473 | .text_color(theme::text_soft()) |
| 1474 | .child(label.into()) |
| 1475 | } |
| 1476 | |
| 1477 | fn team_block( |
| 1478 | &self, |
| 1479 | mut list: Div, |
| 1480 | entry: &SidebarTeam, |
| 1481 | hoisted_only: bool, |
| 1482 | selected: Option<&Selection>, |
| 1483 | team_photo: Option<&AvatarState>, |
| 1484 | cx: &mut Context<Self>, |
| 1485 | ) -> Div { |
| 1486 | let team_id = entry.team.id.clone(); |
| 1487 | let expanded = |
| 1488 | self.channel_filter.is_active() || team_expanded(&team_id, &self.collapsed_teams); |
| 1489 | let name_style = team_name_style(entry, expanded); |
| 1490 | let badge = team_badge(entry, expanded); |
| 1491 | let toggle_id = team_id.clone(); |
| 1492 | let (team_menu_state, team_menu_id) = (self.state.clone(), team_id.clone()); |
| 1493 | let team_menu_flags = TeamMenuState { |
| 1494 | hidden: entry.hidden, |
| 1495 | can_add_channel: entry.rights.add_channel, |
| 1496 | }; |
| 1497 | list = list.child( |
| 1498 | h_flex() |
| 1499 | .id(SharedString::from(format!("team-{team_id}"))) |
| 1500 | .mx(px(6.)) |
| 1501 | .h(px(TEAM_ROW_HEIGHT)) |
| 1502 | .flex_none() |
| 1503 | .px(px(10.)) |
| 1504 | .gap(px(8.)) |
| 1505 | .items_center() |
| 1506 | .rounded(px(8.)) |
| 1507 | .cursor_pointer() |
| 1508 | .hover(|row| row.bg(theme::row_hover())) |
| 1509 | .child(icon( |
| 1510 | if expanded { |
| 1511 | IconName::ChevronDown |
| 1512 | } else { |
| 1513 | IconName::ChevronRight |
| 1514 | }, |
| 1515 | 14., |
| 1516 | theme::text_muted(), |
| 1517 | )) |
| 1518 | .child(team_avatar( |
| 1519 | team_photo, |
| 1520 | &entry.team.name, |
| 1521 | &entry.team.id, |
| 1522 | TEAM_ICON_SIZE, |
| 1523 | TEAM_ICON_RADIUS, |
| 1524 | )) |
| 1525 | .child( |
| 1526 | div() |
| 1527 | .flex_1() |
| 1528 | .min_w_0() |
| 1529 | .truncate() |
| 1530 | .text_size(px(13.5)) |
| 1531 | .font_weight(name_weight(name_style)) |
| 1532 | .text_color(name_color(name_style)) |
| 1533 | .child(entry.team.name.clone()), |
| 1534 | ) |
| 1535 | .children(badge.map(mention_badge)) |
| 1536 | .on_click(cx.listener(move |this, _, _, cx| { |
| 1537 | if !this.collapsed_teams.remove(&toggle_id) { |
| 1538 | this.collapsed_teams.insert(toggle_id.clone()); |
| 1539 | } |
| 1540 | save_collapsed_teams(&this.state.read(cx).store, &this.collapsed_teams); |
| 1541 | cx.notify(); |
| 1542 | })) |
| 1543 | .context_menu(move |popup, _, _| { |
| 1544 | team_menu( |
| 1545 | popup, |
| 1546 | team_menu_state.clone(), |
| 1547 | &team_menu_id, |
| 1548 | team_menu_flags, |
| 1549 | ) |
| 1550 | }), |
| 1551 | ); |
| 1552 | if !expanded { |
| 1553 | return list; |
| 1554 | } |
| 1555 | let is_selected = |
| 1556 | |channel: &ChannelRecord| selected == Some(&Selection::Channel(channel.id.clone())); |
| 1557 | let revealed = self.revealed_channel_teams.contains(&team_id); |
| 1558 | let rows = team_channel_rows(entry, hoisted_only, revealed, is_selected); |
| 1559 | for channel in &rows.shown { |
| 1560 | list = list.child(self.team_channel_row( |
| 1561 | channel, |
| 1562 | is_selected(channel), |
| 1563 | channel_name_style( |
| 1564 | channel_shows_unread(entry, channel), |
| 1565 | channel_shown(entry, &channel.id), |
| 1566 | is_selected(channel), |
| 1567 | ), |
| 1568 | entry.channel_notifications(&channel.id), |
| 1569 | channel_badge(entry, &channel.id), |
| 1570 | )); |
| 1571 | } |
| 1572 | if rows.hidden_count == 0 { |
| 1573 | return list; |
| 1574 | } |
| 1575 | for channel in rows.revealed { |
| 1576 | list = list.child(self.team_channel_row( |
| 1577 | channel, |
| 1578 | false, |
| 1579 | channel_name_style(channel_shows_unread(entry, channel), false, false), |
| 1580 | entry.channel_notifications(&channel.id), |
| 1581 | channel_badge(entry, &channel.id), |
| 1582 | )); |
| 1583 | } |
| 1584 | let toggle_id = team_id.clone(); |
| 1585 | list = list.child(self.see_all_channels_row( |
| 1586 | SharedString::from(format!("hidden-channels-{team_id}")), |
| 1587 | revealed, |
| 1588 | cx.listener(move |this, _, _, cx| { |
| 1589 | if !this.revealed_channel_teams.remove(&toggle_id) { |
| 1590 | this.revealed_channel_teams.insert(toggle_id.clone()); |
| 1591 | } |
| 1592 | cx.notify(); |
| 1593 | }), |
| 1594 | )); |
| 1595 | list |
| 1596 | } |
| 1597 | |
| 1598 | fn see_all_channels_row( |
| 1599 | &self, |
| 1600 | id: SharedString, |
| 1601 | open: bool, |
| 1602 | on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, |
| 1603 | ) -> impl IntoElement { |
| 1604 | h_flex() |
| 1605 | .id(id) |
| 1606 | .debug_selector(|| SEE_ALL_CHANNELS_TAG.into()) |
| 1607 | .mx(px(6.)) |
| 1608 | .h(px(CHANNEL_ROW_HEIGHT)) |
| 1609 | .flex_none() |
| 1610 | .pl(px(CHANNEL_INDENT)) |
| 1611 | .pr(px(10.)) |
| 1612 | .items_center() |
| 1613 | .rounded(px(8.)) |
| 1614 | .cursor_pointer() |
| 1615 | .hover(|row| row.bg(theme::row_hover())) |
| 1616 | .text_size(px(13.5)) |
| 1617 | .text_color(theme::accent_text()) |
| 1618 | .child(if open { |
| 1619 | tr("sidebar.see_fewer_channels") |
| 1620 | } else { |
| 1621 | tr("sidebar.see_all_channels") |
| 1622 | }) |
| 1623 | .on_click(on_click) |
| 1624 | } |
| 1625 | |
| 1626 | fn reveal_row( |
| 1627 | &self, |
| 1628 | id: SharedString, |
| 1629 | label: String, |
| 1630 | open: bool, |
| 1631 | indent: f32, |
| 1632 | on_click: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static, |
| 1633 | ) -> impl IntoElement { |
| 1634 | h_flex() |
| 1635 | .id(id) |
| 1636 | .mx(px(6.)) |
| 1637 | .h(px(REVEAL_ROW_HEIGHT)) |
| 1638 | .flex_none() |
| 1639 | .pl(px(indent)) |
| 1640 | .pr(px(10.)) |
| 1641 | .gap(px(8.)) |
| 1642 | .items_center() |
| 1643 | .rounded(px(8.)) |
| 1644 | .cursor_pointer() |
| 1645 | .hover(|row| row.bg(theme::row_hover())) |
| 1646 | .child(icon( |
| 1647 | if open { |
| 1648 | IconName::ChevronDown |
| 1649 | } else { |
| 1650 | IconName::ChevronRight |
| 1651 | }, |
| 1652 | 12., |
| 1653 | theme::text_faint(), |
| 1654 | )) |
| 1655 | .child( |
| 1656 | div() |
| 1657 | .text_size(px(12.5)) |
| 1658 | .text_color(theme::text_muted()) |
| 1659 | .child(label), |
| 1660 | ) |
| 1661 | .on_click(on_click) |
| 1662 | } |
| 1663 | |
| 1664 | fn team_channel_row( |
| 1665 | &self, |
| 1666 | channel: &ChannelRecord, |
| 1667 | is_selected: bool, |
| 1668 | name_style: NameStyle, |
| 1669 | notifications: ChannelNotifications, |
| 1670 | badge: Option<MentionBadge>, |
| 1671 | ) -> impl IntoElement { |
| 1672 | let state = self.state.clone(); |
| 1673 | let menu_state = self.state.clone(); |
| 1674 | let menu_channel_id = channel.id.clone(); |
| 1675 | let selection = Selection::Channel(channel.id.clone()); |
| 1676 | h_flex() |
| 1677 | .id(SharedString::from(format!("channel-{}", channel.id))) |
| 1678 | .debug_selector(|| CHANNEL_ROW_TAG.into()) |
| 1679 | .mx(px(6.)) |
| 1680 | .h(px(CHANNEL_ROW_HEIGHT)) |
| 1681 | .flex_none() |
| 1682 | .pl(px(CHANNEL_INDENT)) |
| 1683 | .pr(px(10.)) |
| 1684 | .gap(px(8.)) |
| 1685 | .items_center() |
| 1686 | .rounded(px(8.)) |
| 1687 | .cursor_pointer() |
| 1688 | .when(is_selected, |row| row.bg(theme::surface_raised())) |
| 1689 | .when(!is_selected, |row| { |
| 1690 | row.hover(|row| row.bg(theme::row_hover())) |
| 1691 | }) |
| 1692 | .child( |
| 1693 | h_flex() |
| 1694 | .flex_1() |
| 1695 | .min_w_0() |
| 1696 | .gap(px(4.)) |
| 1697 | .items_center() |
| 1698 | .child( |
| 1699 | div() |
| 1700 | .min_w_0() |
| 1701 | .truncate() |
| 1702 | .text_size(px(13.5)) |
| 1703 | .font_weight(name_weight(name_style)) |
| 1704 | .text_color(name_color(name_style)) |
| 1705 | .child(channel.name.clone()), |
| 1706 | ) |
| 1707 | .when(is_private_channel(channel), |name| { |
| 1708 | name.child(div().flex_none().child(symbol( |
| 1709 | "lock", |
| 1710 | 14., |
| 1711 | theme::text_muted(), |
| 1712 | ))) |
| 1713 | }), |
| 1714 | ) |
| 1715 | .children(notification_badge(notifications.level)) |
| 1716 | .child( |
| 1717 | div() |
| 1718 | .flex_none() |
| 1719 | .text_size(px(11.)) |
| 1720 | .text_color(theme::text_muted()) |
| 1721 | .child(channel_activity(channel)), |
| 1722 | ) |
| 1723 | .children(badge.map(mention_badge)) |
| 1724 | .on_click(move |_, _, cx| { |
| 1725 | let selection = selection.clone(); |
| 1726 | state.update(cx, |state, cx| state.select(selection, cx)); |
| 1727 | }) |
| 1728 | .context_menu(move |popup, window, cx| { |
| 1729 | channel_menu( |
| 1730 | popup, |
| 1731 | window, |
| 1732 | cx, |
| 1733 | menu_state.clone(), |
| 1734 | &menu_channel_id, |
| 1735 | notifications, |
| 1736 | ) |
| 1737 | }) |
| 1738 | } |
| 1739 | |
| 1740 | fn collapse_all_teams(&mut self, team_ids: Vec<String>, cx: &mut Context<Self>) { |
| 1741 | self.collapsed_teams.extend(team_ids); |
| 1742 | save_collapsed_teams(&self.state.read(cx).store, &self.collapsed_teams); |
| 1743 | cx.notify(); |
| 1744 | } |
| 1745 | |
| 1746 | fn channels_body(&self, cx: &mut Context<Self>) -> AnyElement { |
| 1747 | let (sidebar, pinned_ids, selected, team_photos) = { |
| 1748 | let state = self.state.read(cx); |
| 1749 | let team_photos: HashMap<String, AvatarState> = state |
| 1750 | .sidebar |
| 1751 | .teams |
| 1752 | .iter() |
| 1753 | .filter_map(|entry| { |
| 1754 | let photo = state.directory.avatar(&team_avatar_key(&entry.team.id))?; |
| 1755 | Some((entry.team.id.clone(), photo.clone())) |
| 1756 | }) |
| 1757 | .collect(); |
| 1758 | ( |
| 1759 | state.sidebar.clone(), |
| 1760 | state.directory.pinned_channels.clone(), |
| 1761 | state.selection.clone().filter(|_| !state.new_chat), |
| 1762 | team_photos, |
| 1763 | ) |
| 1764 | }; |
| 1765 | let filtering = self.channel_filter.is_active(); |
| 1766 | let mut sidebar = sidebar; |
| 1767 | let pinned_ids = if filtering { |
| 1768 | sidebar.teams = self.channel_filter.apply(&sidebar.teams); |
| 1769 | Vec::new() |
| 1770 | } else { |
| 1771 | pinned_ids |
| 1772 | }; |
| 1773 | let team_keys = sidebar |
| 1774 | .teams |
| 1775 | .iter() |
| 1776 | .map(|entry| team_avatar_key(&entry.team.id)) |
| 1777 | .collect(); |
| 1778 | let mut list = v_flex().w_full().pb(px(12.)); |
| 1779 | let pinned: Vec<(&SidebarTeam, &ChannelRecord)> = pinned_ids |
| 1780 | .iter() |
| 1781 | .filter_map(|id| { |
| 1782 | sidebar.teams.iter().find_map(|entry| { |
| 1783 | entry |
| 1784 | .channels |
| 1785 | .iter() |
| 1786 | .find(|channel| &channel.id == id) |
| 1787 | .map(|channel| (entry, channel)) |
| 1788 | }) |
| 1789 | }) |
| 1790 | .collect(); |
| 1791 | if !pinned.is_empty() { |
| 1792 | list = list.child(self.plain_header(tr("sidebar.pinned"))); |
| 1793 | for (entry, channel) in pinned { |
| 1794 | let is_selected = selected == Some(Selection::Channel(channel.id.clone())); |
| 1795 | list = list.child(self.channel_row( |
| 1796 | &channel.id, |
| 1797 | entry, |
| 1798 | channel, |
| 1799 | is_selected, |
| 1800 | team_photos.get(&entry.team.id), |
| 1801 | )); |
| 1802 | } |
| 1803 | } |
| 1804 | list = list.child(self.plain_header(tr("sidebar.teams"))); |
| 1805 | let hidden_teams: Vec<&SidebarTeam> = |
| 1806 | sidebar.teams.iter().filter(|entry| entry.hidden).collect(); |
| 1807 | for entry in sidebar |
| 1808 | .teams |
| 1809 | .iter() |
| 1810 | .filter(|entry| !entry.hidden || team_hoisted(entry)) |
| 1811 | { |
| 1812 | let team_photo = team_photos.get(&entry.team.id); |
| 1813 | list = self.team_block(list, entry, entry.hidden, selected.as_ref(), team_photo, cx); |
| 1814 | } |
| 1815 | if !hidden_teams.is_empty() { |
| 1816 | let holds_selection = hidden_teams |
| 1817 | .iter() |
| 1818 | .any(|entry| team_holds(entry, selected.as_ref())); |
| 1819 | let open = self.hidden_teams_open || holds_selection; |
| 1820 | list = list.child(self.reveal_row( |
| 1821 | "hidden-teams".into(), |
| 1822 | format!("{} ({})", tr("sidebar.hidden_teams"), hidden_teams.len()), |
| 1823 | open, |
| 1824 | 10., |
| 1825 | cx.listener(|this, _, _, cx| { |
| 1826 | this.hidden_teams_open = !this.hidden_teams_open; |
| 1827 | cx.notify(); |
| 1828 | }), |
| 1829 | )); |
| 1830 | if open { |
| 1831 | for entry in hidden_teams { |
| 1832 | let team_photo = team_photos.get(&entry.team.id); |
| 1833 | list = self.team_block(list, entry, false, selected.as_ref(), team_photo, cx); |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | self.request_lazy_data(team_keys, Vec::new(), cx); |
| 1838 | let scroll_area = div() |
| 1839 | .id("channels-scroll") |
| 1840 | .flex_1() |
| 1841 | .min_h_0() |
| 1842 | .overflow_y_scrollbar() |
| 1843 | .track_scroll(&self.channels_scroll) |
| 1844 | .child(list); |
| 1845 | with_top_edge(scroll_area, &self.channels_scroll, SIDEBAR_SCROLL_DIVIDER).into_any_element() |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | fn name_weight(style: NameStyle) -> FontWeight { |
| 1850 | match style.weight { |
| 1851 | NameWeight::Regular => FontWeight::NORMAL, |
| 1852 | NameWeight::Semibold => FontWeight::SEMIBOLD, |
| 1853 | NameWeight::Bold => FontWeight::BOLD, |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | fn name_color(style: NameStyle) -> Hsla { |
| 1858 | if style.highlighted { |
| 1859 | theme::text() |
| 1860 | } else { |
| 1861 | theme::text_muted() |
| 1862 | } |
| 1863 | } |
| 1864 | |
| 1865 | /// Teams chat list: red Important / AlertUrgent glyph while the last unread message is marked. |
| 1866 | fn importance_marker(importance: MessageImportance) -> Option<Icon> { |
| 1867 | let name = match importance { |
| 1868 | MessageImportance::Normal => return None, |
| 1869 | MessageImportance::High => "priority_high", |
| 1870 | MessageImportance::Urgent => "notification_important_fill", |
| 1871 | }; |
| 1872 | Some(symbol(name, IMPORTANCE_MARKER_SIZE, theme::red())) |
| 1873 | } |
| 1874 | |
| 1875 | fn mention_badge(badge: MentionBadge) -> AnyElement { |
| 1876 | match badge { |
| 1877 | MentionBadge::Count(count) => count_badge(count, false).into_any_element(), |
| 1878 | MentionBadge::Channel => { |
| 1879 | icon(IconName::Hash, MENTION_ICON_SIZE, theme::accent_text()).into_any_element() |
| 1880 | } |
| 1881 | MentionBadge::Team => { |
| 1882 | icon(IconName::Users, MENTION_ICON_SIZE, theme::accent_text()).into_any_element() |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | fn notification_badge(level: ChannelNotificationLevel) -> Option<impl IntoElement> { |
| 1888 | let name = match level { |
| 1889 | ChannelNotificationLevel::BannerAndFeed => IconName::Bell, |
| 1890 | ChannelNotificationLevel::Off => IconName::BellOff, |
| 1891 | ChannelNotificationLevel::Feed => return None, |
| 1892 | }; |
| 1893 | Some(icon(name, NOTIFICATION_ICON_SIZE, theme::text_muted())) |
| 1894 | } |
| 1895 | |
| 1896 | pub(crate) fn channel_menu( |
| 1897 | popup: PopupMenu, |
| 1898 | window: &mut Window, |
| 1899 | cx: &mut Context<PopupMenu>, |
| 1900 | state: Entity<AppState>, |
| 1901 | channel_id: &str, |
| 1902 | notifications: ChannelNotifications, |
| 1903 | ) -> PopupMenu { |
| 1904 | let menu_state = state.read(cx).channel_menu_state(channel_id); |
| 1905 | let mut popup = popup; |
| 1906 | for entry in channel_menu_entries(menu_state) { |
| 1907 | let item = match entry { |
| 1908 | MenuEntry::Separator => { |
| 1909 | popup = popup.separator(); |
| 1910 | continue; |
| 1911 | } |
| 1912 | MenuEntry::Item(ChannelMenuItem::Notifications) => { |
| 1913 | popup = notifications_submenu(popup, window, cx, &state, channel_id, notifications); |
| 1914 | continue; |
| 1915 | } |
| 1916 | MenuEntry::Item(item) => item, |
| 1917 | }; |
| 1918 | let (action_state, action_id) = (state.clone(), channel_id.to_owned()); |
| 1919 | popup = popup.item( |
| 1920 | PopupMenuItem::new(item.label()) |
| 1921 | .icon(menu_icon(channel_menu_icon(item))) |
| 1922 | .disabled(menu_state.disables(item)) |
| 1923 | .on_click(move |_, window, cx| { |
| 1924 | match item { |
| 1925 | ChannelMenuItem::EditChannel => { |
| 1926 | open_edit_channel_dialog(action_state.clone(), &action_id, window, cx); |
| 1927 | return; |
| 1928 | } |
| 1929 | ChannelMenuItem::DeleteChannel => { |
| 1930 | confirm_delete_channel(action_state.clone(), &action_id, window, cx); |
| 1931 | return; |
| 1932 | } |
| 1933 | _ => {} |
| 1934 | } |
| 1935 | action_state.update(cx, |state, cx| match item { |
| 1936 | ChannelMenuItem::Pin => state.set_channel_pinned(&action_id, true, cx), |
| 1937 | ChannelMenuItem::Unpin => state.set_channel_pinned(&action_id, false, cx), |
| 1938 | ChannelMenuItem::Show => state.set_channel_shown(&action_id, true, cx), |
| 1939 | ChannelMenuItem::Hide => state.set_channel_shown(&action_id, false, cx), |
| 1940 | ChannelMenuItem::ManageChannel => { |
| 1941 | state.manage_channel_in_browser(&action_id, cx) |
| 1942 | } |
| 1943 | ChannelMenuItem::CopyLink => state.copy_channel_link(&action_id, cx), |
| 1944 | ChannelMenuItem::Notifications |
| 1945 | | ChannelMenuItem::EditChannel |
| 1946 | | ChannelMenuItem::DeleteChannel => {} |
| 1947 | }); |
| 1948 | }), |
| 1949 | ); |
| 1950 | } |
| 1951 | popup |
| 1952 | } |
| 1953 | |
| 1954 | fn channel_menu_icon(item: ChannelMenuItem) -> IconName { |
| 1955 | match item { |
| 1956 | ChannelMenuItem::Notifications => IconName::Bell, |
| 1957 | ChannelMenuItem::Pin => IconName::Pin, |
| 1958 | ChannelMenuItem::Unpin => IconName::PinOff, |
| 1959 | ChannelMenuItem::Show => IconName::Eye, |
| 1960 | ChannelMenuItem::Hide => IconName::EyeOff, |
| 1961 | ChannelMenuItem::EditChannel => IconName::Pencil, |
| 1962 | ChannelMenuItem::ManageChannel => IconName::Settings, |
| 1963 | ChannelMenuItem::CopyLink => IconName::Link, |
| 1964 | ChannelMenuItem::DeleteChannel => IconName::Trash, |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | fn team_menu( |
| 1969 | popup: PopupMenu, |
| 1970 | state: Entity<AppState>, |
| 1971 | team_id: &str, |
| 1972 | flags: TeamMenuState, |
| 1973 | ) -> PopupMenu { |
| 1974 | let mut popup = popup; |
| 1975 | for entry in team_menu_entries(flags) { |
| 1976 | let MenuEntry::Item(item) = entry else { |
| 1977 | popup = popup.separator(); |
| 1978 | continue; |
| 1979 | }; |
| 1980 | let (action_state, action_id) = (state.clone(), team_id.to_owned()); |
| 1981 | popup = popup.item( |
| 1982 | PopupMenuItem::new(item.label()) |
| 1983 | .icon(menu_icon(match item { |
| 1984 | TeamMenuItem::AddChannel => IconName::Plus, |
| 1985 | TeamMenuItem::Show => IconName::Eye, |
| 1986 | TeamMenuItem::Hide => IconName::EyeOff, |
| 1987 | TeamMenuItem::ManageTeam => IconName::Settings, |
| 1988 | TeamMenuItem::CopyLink => IconName::Link, |
| 1989 | })) |
| 1990 | .on_click(move |_, window, cx| { |
| 1991 | if item == TeamMenuItem::AddChannel { |
| 1992 | open_create_channel_dialog(action_state.clone(), &action_id, window, cx); |
| 1993 | return; |
| 1994 | } |
| 1995 | action_state.update(cx, |state, cx| match item { |
| 1996 | TeamMenuItem::AddChannel => {} |
| 1997 | TeamMenuItem::Show => state.set_team_shown(&action_id, true, cx), |
| 1998 | TeamMenuItem::Hide => state.set_team_shown(&action_id, false, cx), |
| 1999 | TeamMenuItem::ManageTeam => state.open_manage_team(&action_id, cx), |
| 2000 | TeamMenuItem::CopyLink => state.copy_team_link(&action_id, cx), |
| 2001 | }); |
| 2002 | }), |
| 2003 | ); |
| 2004 | } |
| 2005 | popup |
| 2006 | } |
| 2007 | |
| 2008 | fn notifications_submenu( |
| 2009 | popup: PopupMenu, |
| 2010 | window: &mut Window, |
| 2011 | cx: &mut Context<PopupMenu>, |
| 2012 | state: &Entity<AppState>, |
| 2013 | channel_id: &str, |
| 2014 | notifications: ChannelNotifications, |
| 2015 | ) -> PopupMenu { |
| 2016 | let (state, channel_id) = (state.clone(), channel_id.to_owned()); |
| 2017 | popup.submenu_with_icon( |
| 2018 | Some(menu_icon(IconName::Bell)), |
| 2019 | tr("sidebar.notifications"), |
| 2020 | window, |
| 2021 | cx, |
| 2022 | move |submenu, _, _| { |
| 2023 | let level_item = |label: String, level: ChannelNotificationLevel| { |
| 2024 | let (state, channel_id) = (state.clone(), channel_id.clone()); |
| 2025 | PopupMenuItem::new(label) |
| 2026 | .checked(notifications.level == level) |
| 2027 | .on_click(move |_, _, cx| { |
| 2028 | let changed = ChannelNotifications { |
| 2029 | level, |
| 2030 | include_replies: notifications.include_replies |
| 2031 | && level != ChannelNotificationLevel::Off, |
| 2032 | }; |
| 2033 | state.update(cx, |state, cx| { |
| 2034 | state.set_channel_notifications(&channel_id, changed, cx) |
| 2035 | }); |
| 2036 | }) |
| 2037 | }; |
| 2038 | let (replies_state, replies_id) = (state.clone(), channel_id.clone()); |
| 2039 | submenu |
| 2040 | .item(level_item( |
| 2041 | tr("sidebar.notify_banner_activity"), |
| 2042 | ChannelNotificationLevel::BannerAndFeed, |
| 2043 | )) |
| 2044 | .item(level_item( |
| 2045 | tr("sidebar.notify_activity_only"), |
| 2046 | ChannelNotificationLevel::Feed, |
| 2047 | )) |
| 2048 | .item(level_item( |
| 2049 | tr("sidebar.notify_off"), |
| 2050 | ChannelNotificationLevel::Off, |
| 2051 | )) |
| 2052 | .separator() |
| 2053 | .item( |
| 2054 | PopupMenuItem::new(tr("sidebar.include_thread_replies")) |
| 2055 | .checked(notifications.include_replies) |
| 2056 | .disabled(notifications.level == ChannelNotificationLevel::Off) |
| 2057 | .on_click(move |_, _, cx| { |
| 2058 | let changed = ChannelNotifications { |
| 2059 | level: notifications.level, |
| 2060 | include_replies: !notifications.include_replies, |
| 2061 | }; |
| 2062 | replies_state.update(cx, |state, cx| { |
| 2063 | state.set_channel_notifications(&replies_id, changed, cx) |
| 2064 | }); |
| 2065 | }), |
| 2066 | ) |
| 2067 | }, |
| 2068 | ) |
| 2069 | } |
| 2070 | |
| 2071 | fn team_expanded(team_id: &str, collapsed_teams: &HashSet<String>) -> bool { |
| 2072 | !collapsed_teams.contains(team_id) |
| 2073 | } |
| 2074 | |
| 2075 | fn load_collapsed_teams(store: &Store) -> HashSet<String> { |
| 2076 | store |
| 2077 | .meta(COLLAPSED_TEAMS_META_KEY) |
| 2078 | .ok() |
| 2079 | .flatten() |
| 2080 | .map(|value| parse_collapsed_teams(&value)) |
| 2081 | .unwrap_or_default() |
| 2082 | } |
| 2083 | |
| 2084 | fn save_collapsed_teams(store: &Store, collapsed_teams: &HashSet<String>) { |
| 2085 | let _ = store.set_meta( |
| 2086 | COLLAPSED_TEAMS_META_KEY, |
| 2087 | &serialize_collapsed_teams(collapsed_teams), |
| 2088 | ); |
| 2089 | } |
| 2090 | |
| 2091 | fn serialize_collapsed_teams(collapsed_teams: &HashSet<String>) -> String { |
| 2092 | let mut team_ids: Vec<&String> = collapsed_teams.iter().collect(); |
| 2093 | team_ids.sort_unstable(); |
| 2094 | serde_json::to_string(&team_ids).unwrap_or_default() |
| 2095 | } |
| 2096 | |
| 2097 | fn parse_collapsed_teams(value: &str) -> HashSet<String> { |
| 2098 | serde_json::from_str(value).unwrap_or_default() |
| 2099 | } |
| 2100 | |
| 2101 | fn team_holds(entry: &SidebarTeam, selected: Option<&Selection>) -> bool { |
| 2102 | entry |
| 2103 | .channels |
| 2104 | .iter() |
| 2105 | .any(|channel| selected == Some(&Selection::Channel(channel.id.clone()))) |
| 2106 | } |
| 2107 | |
| 2108 | fn is_private_channel(channel: &ChannelRecord) -> bool { |
| 2109 | channel |
| 2110 | .membership_type |
| 2111 | .as_deref() |
| 2112 | .is_some_and(|membership| membership.eq_ignore_ascii_case(PRIVATE_MEMBERSHIP)) |
| 2113 | } |
| 2114 | |
| 2115 | fn channel_activity(channel: &ChannelRecord) -> String { |
| 2116 | channel |
| 2117 | .last_message_at |
| 2118 | .map(|time| { |
| 2119 | format::channel_time_label( |
| 2120 | time, |
| 2121 | Local::now().date_naive(), |
| 2122 | app_base::format::Zone::Local, |
| 2123 | ) |
| 2124 | }) |
| 2125 | .unwrap_or_default() |
| 2126 | } |
| 2127 | |
| 2128 | fn collect_faces(spec: &AvatarSpec, faces: &mut Vec<String>) { |
| 2129 | match spec { |
| 2130 | AvatarSpec::Single(face) | AvatarSpec::Bot(face) => faces.extend(face.user_id.clone()), |
| 2131 | AvatarSpec::Pair(first, second) => { |
| 2132 | faces.extend(first.user_id.clone()); |
| 2133 | faces.extend(second.user_id.clone()); |
| 2134 | } |
| 2135 | AvatarSpec::Meeting | AvatarSpec::Muted => {} |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | fn with_spacer(list: Div, skipped_height: &mut f32) -> Div { |
| 2140 | let height = std::mem::take(skipped_height); |
| 2141 | if height > 0. { |
| 2142 | list.child(div().h(px(height)).flex_none()) |
| 2143 | } else { |
| 2144 | list |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | impl Render for SidebarView { |
| 2149 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 2150 | let window_height = f32::from(window.viewport_size().height); |
| 2151 | let body = match self.tab { |
| 2152 | SidebarTab::Activity => self.activity_panel.clone().into_any_element(), |
| 2153 | SidebarTab::Chats => self.chats_body(window_height, cx), |
| 2154 | SidebarTab::Channels => self.channels_body(cx), |
| 2155 | SidebarTab::Agents => match &self.agents_panel { |
| 2156 | Some(panel) => panel.clone().into_any_element(), |
| 2157 | None => div().into_any_element(), |
| 2158 | }, |
| 2159 | SidebarTab::Calls |
| 2160 | | SidebarTab::Calendar |
| 2161 | | SidebarTab::Ponos |
| 2162 | | SidebarTab::Asclepius => div().into_any_element(), |
| 2163 | }; |
| 2164 | let header = match self.tab { |
| 2165 | SidebarTab::Chats => Some( |
| 2166 | v_flex() |
| 2167 | .flex_none() |
| 2168 | .child( |
| 2169 | page_header(&self.tab.title()) |
| 2170 | .child(self.chat_list_menu_button(cx)) |
| 2171 | .child(self.filter_toggle_button(cx)) |
| 2172 | .child(self.new_chat_button(cx)), |
| 2173 | ) |
| 2174 | .child(self.filter_bar(cx)), |
| 2175 | ), |
| 2176 | SidebarTab::Channels => Some( |
| 2177 | v_flex() |
| 2178 | .flex_none() |
| 2179 | .child( |
| 2180 | page_header(&self.tab.title()) |
| 2181 | .child(self.channel_list_menu_button(cx)) |
| 2182 | .child(self.channel_filter_button(cx)) |
| 2183 | .child(self.new_channel_items_button(cx)), |
| 2184 | ) |
| 2185 | .child(self.channel_filter_bar(cx)), |
| 2186 | ), |
| 2187 | SidebarTab::Agents => Some(page_header(&self.tab.title())), |
| 2188 | SidebarTab::Activity |
| 2189 | | SidebarTab::Calls |
| 2190 | | SidebarTab::Calendar |
| 2191 | | SidebarTab::Ponos |
| 2192 | | SidebarTab::Asclepius => None, |
| 2193 | }; |
| 2194 | v_flex() |
| 2195 | .debug_selector(|| "shell/islands/sidebar".into()) |
| 2196 | .w(px(SIDEBAR_WIDTH)) |
| 2197 | .h_full() |
| 2198 | .flex_none() |
| 2199 | .bg(theme::surface()) |
| 2200 | .rounded(px(10.)) |
| 2201 | .overflow_hidden() |
| 2202 | .children(header) |
| 2203 | .child(body) |
| 2204 | } |
| 2205 | } |
| 2206 | |
| 2207 | #[cfg(test)] |
| 2208 | mod tests { |
| 2209 | use std::collections::HashSet; |
| 2210 | |
| 2211 | use super::{drop_target, parse_collapsed_teams, serialize_collapsed_teams, team_expanded}; |
| 2212 | use crate::data::PENDING_FOLDER_PREFIX; |
| 2213 | use crate::sidebar_model::{Section, SectionKind}; |
| 2214 | |
| 2215 | fn section(id: &str, kind: SectionKind) -> Section { |
| 2216 | Section { |
| 2217 | id: id.to_owned(), |
| 2218 | name: id.to_owned(), |
| 2219 | kind, |
| 2220 | collapsed: false, |
| 2221 | count: 0, |
| 2222 | unread_chats: 0, |
| 2223 | items: Vec::new(), |
| 2224 | hidden_count: 0, |
| 2225 | list_expanded: false, |
| 2226 | show_empty_hint: false, |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | #[test] |
| 2231 | fn pending_sections_take_no_dropped_chats() { |
| 2232 | let pending = format!("{PENDING_FOLDER_PREFIX}1"); |
| 2233 | assert_eq!(drop_target(§ion(&pending, SectionKind::Folder)), None); |
| 2234 | assert_eq!( |
| 2235 | drop_target(§ion("work", SectionKind::Folder)), |
| 2236 | Some(Some("work".to_owned())) |
| 2237 | ); |
| 2238 | assert_eq!( |
| 2239 | drop_target(§ion("recent", SectionKind::Others)), |
| 2240 | Some(None) |
| 2241 | ); |
| 2242 | } |
| 2243 | |
| 2244 | #[test] |
| 2245 | fn teams_start_expanded() { |
| 2246 | assert!(team_expanded("t1", &HashSet::new())); |
| 2247 | } |
| 2248 | |
| 2249 | #[test] |
| 2250 | fn collapsed_team_stays_closed() { |
| 2251 | let collapsed = HashSet::from(["t1".to_owned()]); |
| 2252 | assert!(!team_expanded("t1", &collapsed)); |
| 2253 | assert!(team_expanded("t2", &collapsed)); |
| 2254 | } |
| 2255 | |
| 2256 | #[test] |
| 2257 | fn collapsed_teams_round_trip_as_json() { |
| 2258 | let collapsed = HashSet::from(["b".to_owned(), "a".to_owned()]); |
| 2259 | let json = serialize_collapsed_teams(&collapsed); |
| 2260 | assert_eq!(json, r#"["a","b"]"#); |
| 2261 | assert_eq!(parse_collapsed_teams(&json), collapsed); |
| 2262 | assert!(parse_collapsed_teams("garbage").is_empty()); |
| 2263 | } |
| 2264 | } |