1mod channel_modal;
2mod contact_finder;
3
4use self::channel_modal::ChannelModal;
5use crate::{
6 channel_view::ChannelView, chat_panel::ChatPanel, face_pile::FacePile,
7 CollaborationPanelSettings,
8};
9use call::ActiveCall;
10use channel::{Channel, ChannelEvent, ChannelStore};
11use client::{ChannelId, Client, Contact, ProjectId, User, UserStore};
12use contact_finder::ContactFinder;
13use db::kvp::KEY_VALUE_STORE;
14use editor::{Editor, EditorElement, EditorStyle};
15use fuzzy::{match_strings, StringMatchCandidate};
16use gpui::{
17 actions, anchored, canvas, deferred, div, fill, list, point, prelude::*, px, AnyElement,
18 AppContext, AsyncWindowContext, Bounds, ClickEvent, ClipboardItem, DismissEvent, Div,
19 EventEmitter, FocusHandle, FocusableView, FontStyle, FontWeight, InteractiveElement,
20 IntoElement, ListOffset, ListState, Model, MouseDownEvent, ParentElement, Pixels, Point,
21 PromptLevel, Render, SharedString, Styled, Subscription, Task, TextStyle, View, ViewContext,
22 VisualContext, WeakView, WhiteSpace,
23};
24use menu::{Cancel, Confirm, SecondaryConfirm, SelectNext, SelectPrev};
25use project::{Fs, Project};
26use rpc::{
27 proto::{self, ChannelVisibility, PeerId},
28 ErrorCode, ErrorExt,
29};
30use serde_derive::{Deserialize, Serialize};
31use settings::Settings;
32use smallvec::SmallVec;
33use std::{mem, sync::Arc};
34use theme::{ActiveTheme, ThemeSettings};
35use ui::{
36 prelude::*, tooltip_container, Avatar, AvatarAvailabilityIndicator, Button, Color, ContextMenu,
37 Icon, IconButton, IconName, IconSize, Indicator, Label, ListHeader, ListItem, Tooltip,
38};
39use util::{maybe, ResultExt, TryFutureExt};
40use workspace::{
41 dock::{DockPosition, Panel, PanelEvent},
42 notifications::{DetachAndPromptErr, NotifyResultExt, NotifyTaskExt},
43 OpenChannelNotes, Workspace,
44};
45
46actions!(
47 collab_panel,
48 [
49 ToggleFocus,
50 Remove,
51 Secondary,
52 CollapseSelectedChannel,
53 ExpandSelectedChannel,
54 StartMoveChannel,
55 MoveSelected,
56 InsertSpace,
57 ]
58);
59
60#[derive(Debug, Copy, Clone, PartialEq, Eq)]
61struct ChannelMoveClipboard {
62 channel_id: ChannelId,
63}
64
65const COLLABORATION_PANEL_KEY: &str = "CollaborationPanel";
66
67pub fn init(cx: &mut AppContext) {
68 cx.observe_new_views(|workspace: &mut Workspace, _| {
69 workspace.register_action(|workspace, _: &ToggleFocus, cx| {
70 workspace.toggle_panel_focus::<CollabPanel>(cx);
71 });
72 workspace.register_action(|_, _: &OpenChannelNotes, cx| {
73 let channel_id = ActiveCall::global(cx)
74 .read(cx)
75 .room()
76 .and_then(|room| room.read(cx).channel_id());
77
78 if let Some(channel_id) = channel_id {
79 let workspace = cx.view().clone();
80 cx.window_context().defer(move |cx| {
81 ChannelView::open(channel_id, None, workspace, cx).detach_and_log_err(cx)
82 });
83 }
84 });
85 })
86 .detach();
87}
88
89#[derive(Debug)]
90pub enum ChannelEditingState {
91 Create {
92 location: Option<ChannelId>,
93 pending_name: Option<String>,
94 },
95 Rename {
96 location: ChannelId,
97 pending_name: Option<String>,
98 },
99}
100
101impl ChannelEditingState {
102 fn pending_name(&self) -> Option<String> {
103 match self {
104 ChannelEditingState::Create { pending_name, .. } => pending_name.clone(),
105 ChannelEditingState::Rename { pending_name, .. } => pending_name.clone(),
106 }
107 }
108}
109
110pub struct CollabPanel {
111 width: Option<Pixels>,
112 fs: Arc<dyn Fs>,
113 focus_handle: FocusHandle,
114 channel_clipboard: Option<ChannelMoveClipboard>,
115 pending_serialization: Task<Option<()>>,
116 context_menu: Option<(View<ContextMenu>, Point<Pixels>, Subscription)>,
117 list_state: ListState,
118 filter_editor: View<Editor>,
119 channel_name_editor: View<Editor>,
120 channel_editing_state: Option<ChannelEditingState>,
121 entries: Vec<ListEntry>,
122 selection: Option<usize>,
123 channel_store: Model<ChannelStore>,
124 user_store: Model<UserStore>,
125 client: Arc<Client>,
126 project: Model<Project>,
127 match_candidates: Vec<StringMatchCandidate>,
128 subscriptions: Vec<Subscription>,
129 collapsed_sections: Vec<Section>,
130 collapsed_channels: Vec<ChannelId>,
131 workspace: WeakView<Workspace>,
132}
133
134#[derive(Serialize, Deserialize)]
135struct SerializedCollabPanel {
136 width: Option<Pixels>,
137 collapsed_channels: Option<Vec<u64>>,
138}
139
140#[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord)]
141enum Section {
142 ActiveCall,
143 Channels,
144 ChannelInvites,
145 ContactRequests,
146 Contacts,
147 Online,
148 Offline,
149}
150
151#[derive(Clone, Debug)]
152enum ListEntry {
153 Header(Section),
154 CallParticipant {
155 user: Arc<User>,
156 peer_id: Option<PeerId>,
157 is_pending: bool,
158 role: proto::ChannelRole,
159 },
160 ParticipantProject {
161 project_id: u64,
162 worktree_root_names: Vec<String>,
163 host_user_id: u64,
164 is_last: bool,
165 },
166 ParticipantScreen {
167 peer_id: Option<PeerId>,
168 is_last: bool,
169 },
170 IncomingRequest(Arc<User>),
171 OutgoingRequest(Arc<User>),
172 ChannelInvite(Arc<Channel>),
173 Channel {
174 channel: Arc<Channel>,
175 depth: usize,
176 has_children: bool,
177 },
178 ChannelNotes {
179 channel_id: ChannelId,
180 },
181 ChannelChat {
182 channel_id: ChannelId,
183 },
184 ChannelEditor {
185 depth: usize,
186 },
187 HostedProject {
188 id: ProjectId,
189 name: SharedString,
190 },
191 Contact {
192 contact: Arc<Contact>,
193 calling: bool,
194 },
195 ContactPlaceholder,
196}
197
198impl CollabPanel {
199 pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {
200 cx.new_view(|cx| {
201 let filter_editor = cx.new_view(|cx| {
202 let mut editor = Editor::single_line(cx);
203 editor.set_placeholder_text("Filter...", cx);
204 editor
205 });
206
207 cx.subscribe(&filter_editor, |this: &mut Self, _, event, cx| {
208 if let editor::EditorEvent::BufferEdited = event {
209 let query = this.filter_editor.read(cx).text(cx);
210 if !query.is_empty() {
211 this.selection.take();
212 }
213 this.update_entries(true, cx);
214 if !query.is_empty() {
215 this.selection = this
216 .entries
217 .iter()
218 .position(|entry| !matches!(entry, ListEntry::Header(_)));
219 }
220 }
221 })
222 .detach();
223
224 let channel_name_editor = cx.new_view(|cx| Editor::single_line(cx));
225
226 cx.subscribe(&channel_name_editor, |this: &mut Self, _, event, cx| {
227 if let editor::EditorEvent::Blurred = event {
228 if let Some(state) = &this.channel_editing_state {
229 if state.pending_name().is_some() {
230 return;
231 }
232 }
233 this.take_editing_state(cx);
234 this.update_entries(false, cx);
235 cx.notify();
236 }
237 })
238 .detach();
239
240 let view = cx.view().downgrade();
241 let list_state =
242 ListState::new(0, gpui::ListAlignment::Top, px(1000.), move |ix, cx| {
243 if let Some(view) = view.upgrade() {
244 view.update(cx, |view, cx| view.render_list_entry(ix, cx))
245 } else {
246 div().into_any()
247 }
248 });
249
250 let mut this = Self {
251 width: None,
252 focus_handle: cx.focus_handle(),
253 channel_clipboard: None,
254 fs: workspace.app_state().fs.clone(),
255 pending_serialization: Task::ready(None),
256 context_menu: None,
257 list_state,
258 channel_name_editor,
259 filter_editor,
260 entries: Vec::default(),
261 channel_editing_state: None,
262 selection: None,
263 channel_store: ChannelStore::global(cx),
264 user_store: workspace.user_store().clone(),
265 project: workspace.project().clone(),
266 subscriptions: Vec::default(),
267 match_candidates: Vec::default(),
268 collapsed_sections: vec![Section::Offline],
269 collapsed_channels: Vec::default(),
270 workspace: workspace.weak_handle(),
271 client: workspace.app_state().client.clone(),
272 };
273
274 this.update_entries(false, cx);
275
276 let active_call = ActiveCall::global(cx);
277 this.subscriptions
278 .push(cx.observe(&this.user_store, |this, _, cx| {
279 this.update_entries(true, cx)
280 }));
281 this.subscriptions
282 .push(cx.observe(&this.channel_store, move |this, _, cx| {
283 this.update_entries(true, cx)
284 }));
285 this.subscriptions
286 .push(cx.observe(&active_call, |this, _, cx| this.update_entries(true, cx)));
287 this.subscriptions.push(cx.subscribe(
288 &this.channel_store,
289 |this, _channel_store, e, cx| match e {
290 ChannelEvent::ChannelCreated(channel_id)
291 | ChannelEvent::ChannelRenamed(channel_id) => {
292 if this.take_editing_state(cx) {
293 this.update_entries(false, cx);
294 this.selection = this.entries.iter().position(|entry| {
295 if let ListEntry::Channel { channel, .. } = entry {
296 channel.id == *channel_id
297 } else {
298 false
299 }
300 });
301 }
302 }
303 },
304 ));
305
306 this
307 })
308 }
309
310 pub async fn load(
311 workspace: WeakView<Workspace>,
312 mut cx: AsyncWindowContext,
313 ) -> anyhow::Result<View<Self>> {
314 let serialized_panel = cx
315 .background_executor()
316 .spawn(async move { KEY_VALUE_STORE.read_kvp(COLLABORATION_PANEL_KEY) })
317 .await
318 .map_err(|_| anyhow::anyhow!("Failed to read collaboration panel from key value store"))
319 .log_err()
320 .flatten()
321 .map(|panel| serde_json::from_str::<SerializedCollabPanel>(&panel))
322 .transpose()
323 .log_err()
324 .flatten();
325
326 workspace.update(&mut cx, |workspace, cx| {
327 let panel = CollabPanel::new(workspace, cx);
328 if let Some(serialized_panel) = serialized_panel {
329 panel.update(cx, |panel, cx| {
330 panel.width = serialized_panel.width.map(|w| w.round());
331 panel.collapsed_channels = serialized_panel
332 .collapsed_channels
333 .unwrap_or_else(|| Vec::new())
334 .iter()
335 .map(|cid| ChannelId(*cid))
336 .collect();
337 cx.notify();
338 });
339 }
340 panel
341 })
342 }
343
344 fn serialize(&mut self, cx: &mut ViewContext<Self>) {
345 let width = self.width;
346 let collapsed_channels = self.collapsed_channels.clone();
347 self.pending_serialization = cx.background_executor().spawn(
348 async move {
349 KEY_VALUE_STORE
350 .write_kvp(
351 COLLABORATION_PANEL_KEY.into(),
352 serde_json::to_string(&SerializedCollabPanel {
353 width,
354 collapsed_channels: Some(
355 collapsed_channels.iter().map(|cid| cid.0).collect(),
356 ),
357 })?,
358 )
359 .await?;
360 anyhow::Ok(())
361 }
362 .log_err(),
363 );
364 }
365
366 fn scroll_to_item(&mut self, ix: usize) {
367 self.list_state.scroll_to_reveal_item(ix)
368 }
369
370 fn update_entries(&mut self, select_same_item: bool, cx: &mut ViewContext<Self>) {
371 let channel_store = self.channel_store.read(cx);
372 let user_store = self.user_store.read(cx);
373 let query = self.filter_editor.read(cx).text(cx);
374 let executor = cx.background_executor().clone();
375
376 let prev_selected_entry = self.selection.and_then(|ix| self.entries.get(ix).cloned());
377 let old_entries = mem::take(&mut self.entries);
378 let mut scroll_to_top = false;
379
380 if let Some(room) = ActiveCall::global(cx).read(cx).room() {
381 self.entries.push(ListEntry::Header(Section::ActiveCall));
382 if !old_entries
383 .iter()
384 .any(|entry| matches!(entry, ListEntry::Header(Section::ActiveCall)))
385 {
386 scroll_to_top = true;
387 }
388
389 if !self.collapsed_sections.contains(&Section::ActiveCall) {
390 let room = room.read(cx);
391
392 if query.is_empty() {
393 if let Some(channel_id) = room.channel_id() {
394 self.entries.push(ListEntry::ChannelNotes { channel_id });
395 self.entries.push(ListEntry::ChannelChat { channel_id });
396 }
397 }
398
399 // Populate the active user.
400 if let Some(user) = user_store.current_user() {
401 self.match_candidates.clear();
402 self.match_candidates.push(StringMatchCandidate {
403 id: 0,
404 string: user.github_login.clone(),
405 char_bag: user.github_login.chars().collect(),
406 });
407 let matches = executor.block(match_strings(
408 &self.match_candidates,
409 &query,
410 true,
411 usize::MAX,
412 &Default::default(),
413 executor.clone(),
414 ));
415 if !matches.is_empty() {
416 let user_id = user.id;
417 self.entries.push(ListEntry::CallParticipant {
418 user,
419 peer_id: None,
420 is_pending: false,
421 role: room.local_participant().role,
422 });
423 let mut projects = room.local_participant().projects.iter().peekable();
424 while let Some(project) = projects.next() {
425 self.entries.push(ListEntry::ParticipantProject {
426 project_id: project.id,
427 worktree_root_names: project.worktree_root_names.clone(),
428 host_user_id: user_id,
429 is_last: projects.peek().is_none() && !room.is_screen_sharing(),
430 });
431 }
432 if room.is_screen_sharing() {
433 self.entries.push(ListEntry::ParticipantScreen {
434 peer_id: None,
435 is_last: true,
436 });
437 }
438 }
439 }
440
441 // Populate remote participants.
442 self.match_candidates.clear();
443 self.match_candidates
444 .extend(room.remote_participants().values().map(|participant| {
445 StringMatchCandidate {
446 id: participant.user.id as usize,
447 string: participant.user.github_login.clone(),
448 char_bag: participant.user.github_login.chars().collect(),
449 }
450 }));
451 let mut matches = executor.block(match_strings(
452 &self.match_candidates,
453 &query,
454 true,
455 usize::MAX,
456 &Default::default(),
457 executor.clone(),
458 ));
459 matches.sort_by(|a, b| {
460 let a_is_guest = room.role_for_user(a.candidate_id as u64)
461 == Some(proto::ChannelRole::Guest);
462 let b_is_guest = room.role_for_user(b.candidate_id as u64)
463 == Some(proto::ChannelRole::Guest);
464 a_is_guest
465 .cmp(&b_is_guest)
466 .then_with(|| a.string.cmp(&b.string))
467 });
468 for mat in matches {
469 let user_id = mat.candidate_id as u64;
470 let participant = &room.remote_participants()[&user_id];
471 self.entries.push(ListEntry::CallParticipant {
472 user: participant.user.clone(),
473 peer_id: Some(participant.peer_id),
474 is_pending: false,
475 role: participant.role,
476 });
477 let mut projects = participant.projects.iter().peekable();
478 while let Some(project) = projects.next() {
479 self.entries.push(ListEntry::ParticipantProject {
480 project_id: project.id,
481 worktree_root_names: project.worktree_root_names.clone(),
482 host_user_id: participant.user.id,
483 is_last: projects.peek().is_none()
484 && participant.video_tracks.is_empty(),
485 });
486 }
487 if !participant.video_tracks.is_empty() {
488 self.entries.push(ListEntry::ParticipantScreen {
489 peer_id: Some(participant.peer_id),
490 is_last: true,
491 });
492 }
493 }
494
495 // Populate pending participants.
496 self.match_candidates.clear();
497 self.match_candidates
498 .extend(room.pending_participants().iter().enumerate().map(
499 |(id, participant)| StringMatchCandidate {
500 id,
501 string: participant.github_login.clone(),
502 char_bag: participant.github_login.chars().collect(),
503 },
504 ));
505 let matches = executor.block(match_strings(
506 &self.match_candidates,
507 &query,
508 true,
509 usize::MAX,
510 &Default::default(),
511 executor.clone(),
512 ));
513 self.entries
514 .extend(matches.iter().map(|mat| ListEntry::CallParticipant {
515 user: room.pending_participants()[mat.candidate_id].clone(),
516 peer_id: None,
517 is_pending: true,
518 role: proto::ChannelRole::Member,
519 }));
520 }
521 }
522
523 let mut request_entries = Vec::new();
524
525 self.entries.push(ListEntry::Header(Section::Channels));
526
527 if channel_store.channel_count() > 0 || self.channel_editing_state.is_some() {
528 self.match_candidates.clear();
529 self.match_candidates
530 .extend(
531 channel_store
532 .ordered_channels()
533 .enumerate()
534 .map(|(ix, (_, channel))| StringMatchCandidate {
535 id: ix,
536 string: channel.name.clone().into(),
537 char_bag: channel.name.chars().collect(),
538 }),
539 );
540 let matches = executor.block(match_strings(
541 &self.match_candidates,
542 &query,
543 true,
544 usize::MAX,
545 &Default::default(),
546 executor.clone(),
547 ));
548 if let Some(state) = &self.channel_editing_state {
549 if matches!(state, ChannelEditingState::Create { location: None, .. }) {
550 self.entries.push(ListEntry::ChannelEditor { depth: 0 });
551 }
552 }
553 let mut collapse_depth = None;
554 for mat in matches {
555 let channel = channel_store.channel_at_index(mat.candidate_id).unwrap();
556 let depth = channel.parent_path.len();
557
558 if collapse_depth.is_none() && self.is_channel_collapsed(channel.id) {
559 collapse_depth = Some(depth);
560 } else if let Some(collapsed_depth) = collapse_depth {
561 if depth > collapsed_depth {
562 continue;
563 }
564 if self.is_channel_collapsed(channel.id) {
565 collapse_depth = Some(depth);
566 } else {
567 collapse_depth = None;
568 }
569 }
570
571 let hosted_projects = channel_store.projects_for_id(channel.id);
572 let has_children = channel_store
573 .channel_at_index(mat.candidate_id + 1)
574 .map_or(false, |next_channel| {
575 next_channel.parent_path.ends_with(&[channel.id])
576 });
577
578 match &self.channel_editing_state {
579 Some(ChannelEditingState::Create {
580 location: parent_id,
581 ..
582 }) if *parent_id == Some(channel.id) => {
583 self.entries.push(ListEntry::Channel {
584 channel: channel.clone(),
585 depth,
586 has_children: false,
587 });
588 self.entries
589 .push(ListEntry::ChannelEditor { depth: depth + 1 });
590 }
591 Some(ChannelEditingState::Rename {
592 location: parent_id,
593 ..
594 }) if parent_id == &channel.id => {
595 self.entries.push(ListEntry::ChannelEditor { depth });
596 }
597 _ => {
598 self.entries.push(ListEntry::Channel {
599 channel: channel.clone(),
600 depth,
601 has_children,
602 });
603 }
604 }
605
606 for (name, id) in hosted_projects {
607 self.entries.push(ListEntry::HostedProject { id, name });
608 }
609 }
610 }
611
612 let channel_invites = channel_store.channel_invitations();
613 if !channel_invites.is_empty() {
614 self.match_candidates.clear();
615 self.match_candidates
616 .extend(channel_invites.iter().enumerate().map(|(ix, channel)| {
617 StringMatchCandidate {
618 id: ix,
619 string: channel.name.clone().into(),
620 char_bag: channel.name.chars().collect(),
621 }
622 }));
623 let matches = executor.block(match_strings(
624 &self.match_candidates,
625 &query,
626 true,
627 usize::MAX,
628 &Default::default(),
629 executor.clone(),
630 ));
631 request_entries.extend(
632 matches
633 .iter()
634 .map(|mat| ListEntry::ChannelInvite(channel_invites[mat.candidate_id].clone())),
635 );
636
637 if !request_entries.is_empty() {
638 self.entries
639 .push(ListEntry::Header(Section::ChannelInvites));
640 if !self.collapsed_sections.contains(&Section::ChannelInvites) {
641 self.entries.append(&mut request_entries);
642 }
643 }
644 }
645
646 self.entries.push(ListEntry::Header(Section::Contacts));
647
648 request_entries.clear();
649 let incoming = user_store.incoming_contact_requests();
650 if !incoming.is_empty() {
651 self.match_candidates.clear();
652 self.match_candidates
653 .extend(
654 incoming
655 .iter()
656 .enumerate()
657 .map(|(ix, user)| StringMatchCandidate {
658 id: ix,
659 string: user.github_login.clone(),
660 char_bag: user.github_login.chars().collect(),
661 }),
662 );
663 let matches = executor.block(match_strings(
664 &self.match_candidates,
665 &query,
666 true,
667 usize::MAX,
668 &Default::default(),
669 executor.clone(),
670 ));
671 request_entries.extend(
672 matches
673 .iter()
674 .map(|mat| ListEntry::IncomingRequest(incoming[mat.candidate_id].clone())),
675 );
676 }
677
678 let outgoing = user_store.outgoing_contact_requests();
679 if !outgoing.is_empty() {
680 self.match_candidates.clear();
681 self.match_candidates
682 .extend(
683 outgoing
684 .iter()
685 .enumerate()
686 .map(|(ix, user)| StringMatchCandidate {
687 id: ix,
688 string: user.github_login.clone(),
689 char_bag: user.github_login.chars().collect(),
690 }),
691 );
692 let matches = executor.block(match_strings(
693 &self.match_candidates,
694 &query,
695 true,
696 usize::MAX,
697 &Default::default(),
698 executor.clone(),
699 ));
700 request_entries.extend(
701 matches
702 .iter()
703 .map(|mat| ListEntry::OutgoingRequest(outgoing[mat.candidate_id].clone())),
704 );
705 }
706
707 if !request_entries.is_empty() {
708 self.entries
709 .push(ListEntry::Header(Section::ContactRequests));
710 if !self.collapsed_sections.contains(&Section::ContactRequests) {
711 self.entries.append(&mut request_entries);
712 }
713 }
714
715 let contacts = user_store.contacts();
716 if !contacts.is_empty() {
717 self.match_candidates.clear();
718 self.match_candidates
719 .extend(
720 contacts
721 .iter()
722 .enumerate()
723 .map(|(ix, contact)| StringMatchCandidate {
724 id: ix,
725 string: contact.user.github_login.clone(),
726 char_bag: contact.user.github_login.chars().collect(),
727 }),
728 );
729
730 let matches = executor.block(match_strings(
731 &self.match_candidates,
732 &query,
733 true,
734 usize::MAX,
735 &Default::default(),
736 executor.clone(),
737 ));
738
739 let (online_contacts, offline_contacts) = matches
740 .iter()
741 .partition::<Vec<_>, _>(|mat| contacts[mat.candidate_id].online);
742
743 for (matches, section) in [
744 (online_contacts, Section::Online),
745 (offline_contacts, Section::Offline),
746 ] {
747 if !matches.is_empty() {
748 self.entries.push(ListEntry::Header(section));
749 if !self.collapsed_sections.contains(§ion) {
750 let active_call = &ActiveCall::global(cx).read(cx);
751 for mat in matches {
752 let contact = &contacts[mat.candidate_id];
753 self.entries.push(ListEntry::Contact {
754 contact: contact.clone(),
755 calling: active_call.pending_invites().contains(&contact.user.id),
756 });
757 }
758 }
759 }
760 }
761 }
762
763 if incoming.is_empty() && outgoing.is_empty() && contacts.is_empty() {
764 self.entries.push(ListEntry::ContactPlaceholder);
765 }
766
767 if select_same_item {
768 if let Some(prev_selected_entry) = prev_selected_entry {
769 self.selection.take();
770 for (ix, entry) in self.entries.iter().enumerate() {
771 if *entry == prev_selected_entry {
772 self.selection = Some(ix);
773 break;
774 }
775 }
776 }
777 } else {
778 self.selection = self.selection.and_then(|prev_selection| {
779 if self.entries.is_empty() {
780 None
781 } else {
782 Some(prev_selection.min(self.entries.len() - 1))
783 }
784 });
785 }
786
787 let old_scroll_top = self.list_state.logical_scroll_top();
788 self.list_state.reset(self.entries.len());
789
790 if scroll_to_top {
791 self.list_state.scroll_to(ListOffset::default());
792 } else {
793 // Attempt to maintain the same scroll position.
794 if let Some(old_top_entry) = old_entries.get(old_scroll_top.item_ix) {
795 let new_scroll_top = self
796 .entries
797 .iter()
798 .position(|entry| entry == old_top_entry)
799 .map(|item_ix| ListOffset {
800 item_ix,
801 offset_in_item: old_scroll_top.offset_in_item,
802 })
803 .or_else(|| {
804 let entry_after_old_top = old_entries.get(old_scroll_top.item_ix + 1)?;
805 let item_ix = self
806 .entries
807 .iter()
808 .position(|entry| entry == entry_after_old_top)?;
809 Some(ListOffset {
810 item_ix,
811 offset_in_item: Pixels::ZERO,
812 })
813 })
814 .or_else(|| {
815 let entry_before_old_top =
816 old_entries.get(old_scroll_top.item_ix.saturating_sub(1))?;
817 let item_ix = self
818 .entries
819 .iter()
820 .position(|entry| entry == entry_before_old_top)?;
821 Some(ListOffset {
822 item_ix,
823 offset_in_item: Pixels::ZERO,
824 })
825 });
826
827 self.list_state
828 .scroll_to(new_scroll_top.unwrap_or(old_scroll_top));
829 }
830 }
831
832 cx.notify();
833 }
834
835 fn render_call_participant(
836 &self,
837 user: &Arc<User>,
838 peer_id: Option<PeerId>,
839 is_pending: bool,
840 role: proto::ChannelRole,
841 is_selected: bool,
842 cx: &mut ViewContext<Self>,
843 ) -> ListItem {
844 let user_id = user.id;
845 let is_current_user =
846 self.user_store.read(cx).current_user().map(|user| user.id) == Some(user_id);
847 let tooltip = format!("Follow {}", user.github_login);
848
849 let is_call_admin = ActiveCall::global(cx).read(cx).room().is_some_and(|room| {
850 room.read(cx).local_participant().role == proto::ChannelRole::Admin
851 });
852
853 ListItem::new(SharedString::from(user.github_login.clone()))
854 .start_slot(Avatar::new(user.avatar_uri.clone()))
855 .child(Label::new(user.github_login.clone()))
856 .selected(is_selected)
857 .end_slot(if is_pending {
858 Label::new("Calling").color(Color::Muted).into_any_element()
859 } else if is_current_user {
860 IconButton::new("leave-call", IconName::Exit)
861 .style(ButtonStyle::Subtle)
862 .on_click(move |_, cx| Self::leave_call(cx))
863 .tooltip(|cx| Tooltip::text("Leave Call", cx))
864 .into_any_element()
865 } else if role == proto::ChannelRole::Guest {
866 Label::new("Guest").color(Color::Muted).into_any_element()
867 } else if role == proto::ChannelRole::Talker {
868 Label::new("Mic only")
869 .color(Color::Muted)
870 .into_any_element()
871 } else {
872 div().into_any_element()
873 })
874 .when_some(peer_id, |el, peer_id| {
875 if role == proto::ChannelRole::Guest {
876 return el;
877 }
878 el.tooltip(move |cx| Tooltip::text(tooltip.clone(), cx))
879 .on_click(cx.listener(move |this, _, cx| {
880 this.workspace
881 .update(cx, |workspace, cx| workspace.follow(peer_id, cx))
882 .ok();
883 }))
884 })
885 .when(is_call_admin, |el| {
886 el.on_secondary_mouse_down(cx.listener(move |this, event: &MouseDownEvent, cx| {
887 this.deploy_participant_context_menu(event.position, user_id, role, cx)
888 }))
889 })
890 }
891
892 fn render_participant_project(
893 &self,
894 project_id: u64,
895 worktree_root_names: &[String],
896 host_user_id: u64,
897 is_last: bool,
898 is_selected: bool,
899 cx: &mut ViewContext<Self>,
900 ) -> impl IntoElement {
901 let project_name: SharedString = if worktree_root_names.is_empty() {
902 "untitled".to_string()
903 } else {
904 worktree_root_names.join(", ")
905 }
906 .into();
907
908 ListItem::new(project_id as usize)
909 .selected(is_selected)
910 .on_click(cx.listener(move |this, _, cx| {
911 this.workspace
912 .update(cx, |workspace, cx| {
913 let app_state = workspace.app_state().clone();
914 workspace::join_in_room_project(project_id, host_user_id, app_state, cx)
915 .detach_and_prompt_err("Failed to join project", cx, |_, _| None);
916 })
917 .ok();
918 }))
919 .start_slot(
920 h_flex()
921 .gap_1()
922 .child(render_tree_branch(is_last, false, cx))
923 .child(IconButton::new(0, IconName::Folder)),
924 )
925 .child(Label::new(project_name.clone()))
926 .tooltip(move |cx| Tooltip::text(format!("Open {}", project_name), cx))
927 }
928
929 fn render_participant_screen(
930 &self,
931 peer_id: Option<PeerId>,
932 is_last: bool,
933 is_selected: bool,
934 cx: &mut ViewContext<Self>,
935 ) -> impl IntoElement {
936 let id = peer_id.map_or(usize::MAX, |id| id.as_u64() as usize);
937
938 ListItem::new(("screen", id))
939 .selected(is_selected)
940 .start_slot(
941 h_flex()
942 .gap_1()
943 .child(render_tree_branch(is_last, false, cx))
944 .child(IconButton::new(0, IconName::Screen)),
945 )
946 .child(Label::new("Screen"))
947 .when_some(peer_id, |this, _| {
948 this.on_click(cx.listener(move |this, _, cx| {
949 this.workspace
950 .update(cx, |workspace, cx| {
951 workspace.open_shared_screen(peer_id.unwrap(), cx)
952 })
953 .ok();
954 }))
955 .tooltip(move |cx| Tooltip::text("Open shared screen", cx))
956 })
957 }
958
959 fn take_editing_state(&mut self, cx: &mut ViewContext<Self>) -> bool {
960 if let Some(_) = self.channel_editing_state.take() {
961 self.channel_name_editor.update(cx, |editor, cx| {
962 editor.set_text("", cx);
963 });
964 true
965 } else {
966 false
967 }
968 }
969
970 fn render_channel_notes(
971 &self,
972 channel_id: ChannelId,
973 is_selected: bool,
974 cx: &mut ViewContext<Self>,
975 ) -> impl IntoElement {
976 let channel_store = self.channel_store.read(cx);
977 let has_channel_buffer_changed = channel_store.has_channel_buffer_changed(channel_id);
978 ListItem::new("channel-notes")
979 .selected(is_selected)
980 .on_click(cx.listener(move |this, _, cx| {
981 this.open_channel_notes(channel_id, cx);
982 }))
983 .start_slot(
984 h_flex()
985 .relative()
986 .gap_1()
987 .child(render_tree_branch(false, true, cx))
988 .child(IconButton::new(0, IconName::File))
989 .children(has_channel_buffer_changed.then(|| {
990 div()
991 .w_1p5()
992 .absolute()
993 .right(px(2.))
994 .top(px(2.))
995 .child(Indicator::dot().color(Color::Info))
996 })),
997 )
998 .child(Label::new("notes"))
999 .tooltip(move |cx| Tooltip::text("Open Channel Notes", cx))
1000 }
1001
1002 fn render_channel_chat(
1003 &self,
1004 channel_id: ChannelId,
1005 is_selected: bool,
1006 cx: &mut ViewContext<Self>,
1007 ) -> impl IntoElement {
1008 let channel_store = self.channel_store.read(cx);
1009 let has_messages_notification = channel_store.has_new_messages(channel_id);
1010 ListItem::new("channel-chat")
1011 .selected(is_selected)
1012 .on_click(cx.listener(move |this, _, cx| {
1013 this.join_channel_chat(channel_id, cx);
1014 }))
1015 .start_slot(
1016 h_flex()
1017 .relative()
1018 .gap_1()
1019 .child(render_tree_branch(false, false, cx))
1020 .child(IconButton::new(0, IconName::MessageBubbles))
1021 .children(has_messages_notification.then(|| {
1022 div()
1023 .w_1p5()
1024 .absolute()
1025 .right(px(2.))
1026 .top(px(4.))
1027 .child(Indicator::dot().color(Color::Info))
1028 })),
1029 )
1030 .child(Label::new("chat"))
1031 .tooltip(move |cx| Tooltip::text("Open Chat", cx))
1032 }
1033
1034 fn render_channel_project(
1035 &self,
1036 id: ProjectId,
1037 name: &SharedString,
1038 is_selected: bool,
1039 cx: &mut ViewContext<Self>,
1040 ) -> impl IntoElement {
1041 ListItem::new(ElementId::NamedInteger(
1042 "channel-project".into(),
1043 id.0 as usize,
1044 ))
1045 .indent_level(2)
1046 .indent_step_size(px(20.))
1047 .selected(is_selected)
1048 .on_click(cx.listener(move |this, _, cx| {
1049 if let Some(workspace) = this.workspace.upgrade() {
1050 let app_state = workspace.read(cx).app_state().clone();
1051 workspace::join_hosted_project(id, app_state, cx).detach_and_prompt_err(
1052 "Failed to open project",
1053 cx,
1054 |_, _| None,
1055 )
1056 }
1057 }))
1058 .start_slot(
1059 h_flex()
1060 .relative()
1061 .gap_1()
1062 .child(IconButton::new(0, IconName::FileTree)),
1063 )
1064 .child(Label::new(name.clone()))
1065 .tooltip(move |cx| Tooltip::text("Open Project", cx))
1066 }
1067
1068 fn has_subchannels(&self, ix: usize) -> bool {
1069 self.entries.get(ix).map_or(false, |entry| {
1070 if let ListEntry::Channel { has_children, .. } = entry {
1071 *has_children
1072 } else {
1073 false
1074 }
1075 })
1076 }
1077
1078 fn deploy_participant_context_menu(
1079 &mut self,
1080 position: Point<Pixels>,
1081 user_id: u64,
1082 role: proto::ChannelRole,
1083 cx: &mut ViewContext<Self>,
1084 ) {
1085 let this = cx.view().clone();
1086 if !(role == proto::ChannelRole::Guest
1087 || role == proto::ChannelRole::Talker
1088 || role == proto::ChannelRole::Member)
1089 {
1090 return;
1091 }
1092
1093 let context_menu = ContextMenu::build(cx, |mut context_menu, cx| {
1094 if role == proto::ChannelRole::Guest {
1095 context_menu = context_menu.entry(
1096 "Grant Mic Access",
1097 None,
1098 cx.handler_for(&this, move |_, cx| {
1099 ActiveCall::global(cx)
1100 .update(cx, |call, cx| {
1101 let Some(room) = call.room() else {
1102 return Task::ready(Ok(()));
1103 };
1104 room.update(cx, |room, cx| {
1105 room.set_participant_role(
1106 user_id,
1107 proto::ChannelRole::Talker,
1108 cx,
1109 )
1110 })
1111 })
1112 .detach_and_prompt_err("Failed to grant mic access", cx, |_, _| None)
1113 }),
1114 );
1115 }
1116 if role == proto::ChannelRole::Guest || role == proto::ChannelRole::Talker {
1117 context_menu = context_menu.entry(
1118 "Grant Write Access",
1119 None,
1120 cx.handler_for(&this, move |_, cx| {
1121 ActiveCall::global(cx)
1122 .update(cx, |call, cx| {
1123 let Some(room) = call.room() else {
1124 return Task::ready(Ok(()));
1125 };
1126 room.update(cx, |room, cx| {
1127 room.set_participant_role(
1128 user_id,
1129 proto::ChannelRole::Member,
1130 cx,
1131 )
1132 })
1133 })
1134 .detach_and_prompt_err("Failed to grant write access", cx, |e, _| {
1135 match e.error_code() {
1136 ErrorCode::NeedsCla => Some("This user has not yet signed the CLA at https://zed.dev/cla.".into()),
1137 _ => None,
1138 }
1139 })
1140 }),
1141 );
1142 }
1143 if role == proto::ChannelRole::Member || role == proto::ChannelRole::Talker {
1144 let label = if role == proto::ChannelRole::Talker {
1145 "Mute"
1146 } else {
1147 "Revoke Access"
1148 };
1149 context_menu = context_menu.entry(
1150 label,
1151 None,
1152 cx.handler_for(&this, move |_, cx| {
1153 ActiveCall::global(cx)
1154 .update(cx, |call, cx| {
1155 let Some(room) = call.room() else {
1156 return Task::ready(Ok(()));
1157 };
1158 room.update(cx, |room, cx| {
1159 room.set_participant_role(
1160 user_id,
1161 proto::ChannelRole::Guest,
1162 cx,
1163 )
1164 })
1165 })
1166 .detach_and_prompt_err("Failed to revoke access", cx, |_, _| None)
1167 }),
1168 );
1169 }
1170
1171 context_menu
1172 });
1173
1174 cx.focus_view(&context_menu);
1175 let subscription =
1176 cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
1177 if this.context_menu.as_ref().is_some_and(|context_menu| {
1178 context_menu.0.focus_handle(cx).contains_focused(cx)
1179 }) {
1180 cx.focus_self();
1181 }
1182 this.context_menu.take();
1183 cx.notify();
1184 });
1185 self.context_menu = Some((context_menu, position, subscription));
1186 }
1187
1188 fn deploy_channel_context_menu(
1189 &mut self,
1190 position: Point<Pixels>,
1191 channel_id: ChannelId,
1192 ix: usize,
1193 cx: &mut ViewContext<Self>,
1194 ) {
1195 let clipboard_channel_name = self.channel_clipboard.as_ref().and_then(|clipboard| {
1196 self.channel_store
1197 .read(cx)
1198 .channel_for_id(clipboard.channel_id)
1199 .map(|channel| channel.name.clone())
1200 });
1201 let this = cx.view().clone();
1202
1203 let context_menu = ContextMenu::build(cx, |mut context_menu, cx| {
1204 if self.has_subchannels(ix) {
1205 let expand_action_name = if self.is_channel_collapsed(channel_id) {
1206 "Expand Subchannels"
1207 } else {
1208 "Collapse Subchannels"
1209 };
1210 context_menu = context_menu.entry(
1211 expand_action_name,
1212 None,
1213 cx.handler_for(&this, move |this, cx| {
1214 this.toggle_channel_collapsed(channel_id, cx)
1215 }),
1216 );
1217 }
1218
1219 context_menu = context_menu
1220 .entry(
1221 "Open Notes",
1222 None,
1223 cx.handler_for(&this, move |this, cx| {
1224 this.open_channel_notes(channel_id, cx)
1225 }),
1226 )
1227 .entry(
1228 "Open Chat",
1229 None,
1230 cx.handler_for(&this, move |this, cx| {
1231 this.join_channel_chat(channel_id, cx)
1232 }),
1233 )
1234 .entry(
1235 "Copy Channel Link",
1236 None,
1237 cx.handler_for(&this, move |this, cx| {
1238 this.copy_channel_link(channel_id, cx)
1239 }),
1240 );
1241
1242 let mut has_destructive_actions = false;
1243 if self.channel_store.read(cx).is_channel_admin(channel_id) {
1244 has_destructive_actions = true;
1245 context_menu = context_menu
1246 .separator()
1247 .entry(
1248 "New Subchannel",
1249 None,
1250 cx.handler_for(&this, move |this, cx| this.new_subchannel(channel_id, cx)),
1251 )
1252 .entry(
1253 "Rename",
1254 Some(Box::new(SecondaryConfirm)),
1255 cx.handler_for(&this, move |this, cx| this.rename_channel(channel_id, cx)),
1256 );
1257
1258 if let Some(channel_name) = clipboard_channel_name {
1259 context_menu = context_menu.separator().entry(
1260 format!("Move '#{}' here", channel_name),
1261 None,
1262 cx.handler_for(&this, move |this, cx| {
1263 this.move_channel_on_clipboard(channel_id, cx)
1264 }),
1265 );
1266 }
1267
1268 if self.channel_store.read(cx).is_root_channel(channel_id) {
1269 context_menu = context_menu.separator().entry(
1270 "Manage Members",
1271 None,
1272 cx.handler_for(&this, move |this, cx| this.manage_members(channel_id, cx)),
1273 )
1274 } else {
1275 context_menu = context_menu.entry(
1276 "Move this channel",
1277 None,
1278 cx.handler_for(&this, move |this, cx| {
1279 this.start_move_channel(channel_id, cx)
1280 }),
1281 );
1282 if self.channel_store.read(cx).is_public_channel(channel_id) {
1283 context_menu = context_menu.separator().entry(
1284 "Make Channel Private",
1285 None,
1286 cx.handler_for(&this, move |this, cx| {
1287 this.set_channel_visibility(
1288 channel_id,
1289 ChannelVisibility::Members,
1290 cx,
1291 )
1292 }),
1293 )
1294 } else {
1295 context_menu = context_menu.separator().entry(
1296 "Make Channel Public",
1297 None,
1298 cx.handler_for(&this, move |this, cx| {
1299 this.set_channel_visibility(
1300 channel_id,
1301 ChannelVisibility::Public,
1302 cx,
1303 )
1304 }),
1305 )
1306 }
1307 }
1308
1309 context_menu = context_menu.entry(
1310 "Delete",
1311 None,
1312 cx.handler_for(&this, move |this, cx| this.remove_channel(channel_id, cx)),
1313 );
1314 }
1315
1316 if self.channel_store.read(cx).is_root_channel(channel_id) {
1317 if !has_destructive_actions {
1318 context_menu = context_menu.separator()
1319 }
1320 context_menu = context_menu.entry(
1321 "Leave Channel",
1322 None,
1323 cx.handler_for(&this, move |this, cx| this.leave_channel(channel_id, cx)),
1324 );
1325 }
1326
1327 context_menu
1328 });
1329
1330 cx.focus_view(&context_menu);
1331 let subscription =
1332 cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
1333 if this.context_menu.as_ref().is_some_and(|context_menu| {
1334 context_menu.0.focus_handle(cx).contains_focused(cx)
1335 }) {
1336 cx.focus_self();
1337 }
1338 this.context_menu.take();
1339 cx.notify();
1340 });
1341 self.context_menu = Some((context_menu, position, subscription));
1342
1343 cx.notify();
1344 }
1345
1346 fn deploy_contact_context_menu(
1347 &mut self,
1348 position: Point<Pixels>,
1349 contact: Arc<Contact>,
1350 cx: &mut ViewContext<Self>,
1351 ) {
1352 let this = cx.view().clone();
1353 let in_room = ActiveCall::global(cx).read(cx).room().is_some();
1354
1355 let context_menu = ContextMenu::build(cx, |mut context_menu, _| {
1356 let user_id = contact.user.id;
1357
1358 if contact.online && !contact.busy {
1359 let label = if in_room {
1360 format!("Invite {} to join", contact.user.github_login)
1361 } else {
1362 format!("Call {}", contact.user.github_login)
1363 };
1364 context_menu = context_menu.entry(label, None, {
1365 let this = this.clone();
1366 move |cx| {
1367 this.update(cx, |this, cx| {
1368 this.call(user_id, cx);
1369 });
1370 }
1371 });
1372 }
1373
1374 context_menu.entry("Remove Contact", None, {
1375 let this = this.clone();
1376 move |cx| {
1377 this.update(cx, |this, cx| {
1378 this.remove_contact(contact.user.id, &contact.user.github_login, cx);
1379 });
1380 }
1381 })
1382 });
1383
1384 cx.focus_view(&context_menu);
1385 let subscription =
1386 cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
1387 if this.context_menu.as_ref().is_some_and(|context_menu| {
1388 context_menu.0.focus_handle(cx).contains_focused(cx)
1389 }) {
1390 cx.focus_self();
1391 }
1392 this.context_menu.take();
1393 cx.notify();
1394 });
1395 self.context_menu = Some((context_menu, position, subscription));
1396
1397 cx.notify();
1398 }
1399
1400 fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
1401 if self.take_editing_state(cx) {
1402 cx.focus_view(&self.filter_editor);
1403 } else {
1404 self.filter_editor.update(cx, |editor, cx| {
1405 if editor.buffer().read(cx).len(cx) > 0 {
1406 editor.set_text("", cx);
1407 }
1408 });
1409 }
1410
1411 if self.context_menu.is_some() {
1412 self.context_menu.take();
1413 cx.notify();
1414 }
1415
1416 self.update_entries(false, cx);
1417 }
1418
1419 fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
1420 let ix = self.selection.map_or(0, |ix| ix + 1);
1421 if ix < self.entries.len() {
1422 self.selection = Some(ix);
1423 }
1424
1425 if let Some(ix) = self.selection {
1426 self.scroll_to_item(ix)
1427 }
1428 cx.notify();
1429 }
1430
1431 fn select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) {
1432 let ix = self.selection.take().unwrap_or(0);
1433 if ix > 0 {
1434 self.selection = Some(ix - 1);
1435 }
1436
1437 if let Some(ix) = self.selection {
1438 self.scroll_to_item(ix)
1439 }
1440 cx.notify();
1441 }
1442
1443 fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
1444 if self.confirm_channel_edit(cx) {
1445 return;
1446 }
1447
1448 if let Some(selection) = self.selection {
1449 if let Some(entry) = self.entries.get(selection) {
1450 match entry {
1451 ListEntry::Header(section) => match section {
1452 Section::ActiveCall => Self::leave_call(cx),
1453 Section::Channels => self.new_root_channel(cx),
1454 Section::Contacts => self.toggle_contact_finder(cx),
1455 Section::ContactRequests
1456 | Section::Online
1457 | Section::Offline
1458 | Section::ChannelInvites => {
1459 self.toggle_section_expanded(*section, cx);
1460 }
1461 },
1462 ListEntry::Contact { contact, calling } => {
1463 if contact.online && !contact.busy && !calling {
1464 self.call(contact.user.id, cx);
1465 }
1466 }
1467 ListEntry::ParticipantProject {
1468 project_id,
1469 host_user_id,
1470 ..
1471 } => {
1472 if let Some(workspace) = self.workspace.upgrade() {
1473 let app_state = workspace.read(cx).app_state().clone();
1474 workspace::join_in_room_project(
1475 *project_id,
1476 *host_user_id,
1477 app_state,
1478 cx,
1479 )
1480 .detach_and_prompt_err(
1481 "Failed to join project",
1482 cx,
1483 |_, _| None,
1484 );
1485 }
1486 }
1487 ListEntry::ParticipantScreen { peer_id, .. } => {
1488 let Some(peer_id) = peer_id else {
1489 return;
1490 };
1491 if let Some(workspace) = self.workspace.upgrade() {
1492 workspace.update(cx, |workspace, cx| {
1493 workspace.open_shared_screen(*peer_id, cx)
1494 });
1495 }
1496 }
1497 ListEntry::Channel { channel, .. } => {
1498 let is_active = maybe!({
1499 let call_channel = ActiveCall::global(cx)
1500 .read(cx)
1501 .room()?
1502 .read(cx)
1503 .channel_id()?;
1504
1505 Some(call_channel == channel.id)
1506 })
1507 .unwrap_or(false);
1508 if is_active {
1509 self.open_channel_notes(channel.id, cx)
1510 } else {
1511 self.join_channel(channel.id, cx)
1512 }
1513 }
1514 ListEntry::ContactPlaceholder => self.toggle_contact_finder(cx),
1515 ListEntry::CallParticipant { user, peer_id, .. } => {
1516 if Some(user) == self.user_store.read(cx).current_user().as_ref() {
1517 Self::leave_call(cx);
1518 } else if let Some(peer_id) = peer_id {
1519 self.workspace
1520 .update(cx, |workspace, cx| workspace.follow(*peer_id, cx))
1521 .ok();
1522 }
1523 }
1524 ListEntry::IncomingRequest(user) => {
1525 self.respond_to_contact_request(user.id, true, cx)
1526 }
1527 ListEntry::ChannelInvite(channel) => {
1528 self.respond_to_channel_invite(channel.id, true, cx)
1529 }
1530 ListEntry::ChannelNotes { channel_id } => {
1531 self.open_channel_notes(*channel_id, cx)
1532 }
1533 ListEntry::ChannelChat { channel_id } => {
1534 self.join_channel_chat(*channel_id, cx)
1535 }
1536 ListEntry::HostedProject {
1537 id: _id,
1538 name: _name,
1539 } => {
1540 // todo()
1541 }
1542 ListEntry::OutgoingRequest(_) => {}
1543 ListEntry::ChannelEditor { .. } => {}
1544 }
1545 }
1546 }
1547 }
1548
1549 fn insert_space(&mut self, _: &InsertSpace, cx: &mut ViewContext<Self>) {
1550 if self.channel_editing_state.is_some() {
1551 self.channel_name_editor.update(cx, |editor, cx| {
1552 editor.insert(" ", cx);
1553 });
1554 }
1555 }
1556
1557 fn confirm_channel_edit(&mut self, cx: &mut ViewContext<CollabPanel>) -> bool {
1558 if let Some(editing_state) = &mut self.channel_editing_state {
1559 match editing_state {
1560 ChannelEditingState::Create {
1561 location,
1562 pending_name,
1563 ..
1564 } => {
1565 if pending_name.is_some() {
1566 return false;
1567 }
1568 let channel_name = self.channel_name_editor.read(cx).text(cx);
1569
1570 *pending_name = Some(channel_name.clone());
1571
1572 self.channel_store
1573 .update(cx, |channel_store, cx| {
1574 channel_store.create_channel(&channel_name, *location, cx)
1575 })
1576 .detach();
1577 cx.notify();
1578 }
1579 ChannelEditingState::Rename {
1580 location,
1581 pending_name,
1582 } => {
1583 if pending_name.is_some() {
1584 return false;
1585 }
1586 let channel_name = self.channel_name_editor.read(cx).text(cx);
1587 *pending_name = Some(channel_name.clone());
1588
1589 self.channel_store
1590 .update(cx, |channel_store, cx| {
1591 channel_store.rename(*location, &channel_name, cx)
1592 })
1593 .detach();
1594 cx.notify();
1595 }
1596 }
1597 cx.focus_self();
1598 true
1599 } else {
1600 false
1601 }
1602 }
1603
1604 fn toggle_section_expanded(&mut self, section: Section, cx: &mut ViewContext<Self>) {
1605 if let Some(ix) = self.collapsed_sections.iter().position(|s| *s == section) {
1606 self.collapsed_sections.remove(ix);
1607 } else {
1608 self.collapsed_sections.push(section);
1609 }
1610 self.update_entries(false, cx);
1611 }
1612
1613 fn collapse_selected_channel(
1614 &mut self,
1615 _: &CollapseSelectedChannel,
1616 cx: &mut ViewContext<Self>,
1617 ) {
1618 let Some(channel_id) = self.selected_channel().map(|channel| channel.id) else {
1619 return;
1620 };
1621
1622 if self.is_channel_collapsed(channel_id) {
1623 return;
1624 }
1625
1626 self.toggle_channel_collapsed(channel_id, cx);
1627 }
1628
1629 fn expand_selected_channel(&mut self, _: &ExpandSelectedChannel, cx: &mut ViewContext<Self>) {
1630 let Some(id) = self.selected_channel().map(|channel| channel.id) else {
1631 return;
1632 };
1633
1634 if !self.is_channel_collapsed(id) {
1635 return;
1636 }
1637
1638 self.toggle_channel_collapsed(id, cx)
1639 }
1640
1641 fn toggle_channel_collapsed(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1642 match self.collapsed_channels.binary_search(&channel_id) {
1643 Ok(ix) => {
1644 self.collapsed_channels.remove(ix);
1645 }
1646 Err(ix) => {
1647 self.collapsed_channels.insert(ix, channel_id);
1648 }
1649 };
1650 self.serialize(cx);
1651 self.update_entries(true, cx);
1652 cx.notify();
1653 cx.focus_self();
1654 }
1655
1656 fn is_channel_collapsed(&self, channel_id: ChannelId) -> bool {
1657 self.collapsed_channels.binary_search(&channel_id).is_ok()
1658 }
1659
1660 fn leave_call(cx: &mut WindowContext) {
1661 ActiveCall::global(cx)
1662 .update(cx, |call, cx| call.hang_up(cx))
1663 .detach_and_prompt_err("Failed to hang up", cx, |_, _| None);
1664 }
1665
1666 fn toggle_contact_finder(&mut self, cx: &mut ViewContext<Self>) {
1667 if let Some(workspace) = self.workspace.upgrade() {
1668 workspace.update(cx, |workspace, cx| {
1669 workspace.toggle_modal(cx, |cx| {
1670 let mut finder = ContactFinder::new(self.user_store.clone(), cx);
1671 finder.set_query(self.filter_editor.read(cx).text(cx), cx);
1672 finder
1673 });
1674 });
1675 }
1676 }
1677
1678 fn new_root_channel(&mut self, cx: &mut ViewContext<Self>) {
1679 self.channel_editing_state = Some(ChannelEditingState::Create {
1680 location: None,
1681 pending_name: None,
1682 });
1683 self.update_entries(false, cx);
1684 self.select_channel_editor();
1685 cx.focus_view(&self.channel_name_editor);
1686 cx.notify();
1687 }
1688
1689 fn select_channel_editor(&mut self) {
1690 self.selection = self.entries.iter().position(|entry| match entry {
1691 ListEntry::ChannelEditor { .. } => true,
1692 _ => false,
1693 });
1694 }
1695
1696 fn new_subchannel(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1697 self.collapsed_channels
1698 .retain(|channel| *channel != channel_id);
1699 self.channel_editing_state = Some(ChannelEditingState::Create {
1700 location: Some(channel_id),
1701 pending_name: None,
1702 });
1703 self.update_entries(false, cx);
1704 self.select_channel_editor();
1705 cx.focus_view(&self.channel_name_editor);
1706 cx.notify();
1707 }
1708
1709 fn manage_members(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1710 self.show_channel_modal(channel_id, channel_modal::Mode::ManageMembers, cx);
1711 }
1712
1713 fn remove_selected_channel(&mut self, _: &Remove, cx: &mut ViewContext<Self>) {
1714 if let Some(channel) = self.selected_channel() {
1715 self.remove_channel(channel.id, cx)
1716 }
1717 }
1718
1719 fn rename_selected_channel(&mut self, _: &SecondaryConfirm, cx: &mut ViewContext<Self>) {
1720 if let Some(channel) = self.selected_channel() {
1721 self.rename_channel(channel.id, cx);
1722 }
1723 }
1724
1725 fn rename_channel(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1726 let channel_store = self.channel_store.read(cx);
1727 if !channel_store.is_channel_admin(channel_id) {
1728 return;
1729 }
1730 if let Some(channel) = channel_store.channel_for_id(channel_id).cloned() {
1731 self.channel_editing_state = Some(ChannelEditingState::Rename {
1732 location: channel_id,
1733 pending_name: None,
1734 });
1735 self.channel_name_editor.update(cx, |editor, cx| {
1736 editor.set_text(channel.name.clone(), cx);
1737 editor.select_all(&Default::default(), cx);
1738 });
1739 cx.focus_view(&self.channel_name_editor);
1740 self.update_entries(false, cx);
1741 self.select_channel_editor();
1742 }
1743 }
1744
1745 fn set_channel_visibility(
1746 &mut self,
1747 channel_id: ChannelId,
1748 visibility: ChannelVisibility,
1749 cx: &mut ViewContext<Self>,
1750 ) {
1751 self.channel_store
1752 .update(cx, |channel_store, cx| {
1753 channel_store.set_channel_visibility(channel_id, visibility, cx)
1754 })
1755 .detach_and_prompt_err("Failed to set channel visibility", cx, |e, _| match e.error_code() {
1756 ErrorCode::BadPublicNesting =>
1757 if e.error_tag("direction") == Some("parent") {
1758 Some("To make a channel public, its parent channel must be public.".to_string())
1759 } else {
1760 Some("To make a channel private, all of its subchannels must be private.".to_string())
1761 },
1762 _ => None
1763 });
1764 }
1765
1766 fn start_move_channel(&mut self, channel_id: ChannelId, _cx: &mut ViewContext<Self>) {
1767 self.channel_clipboard = Some(ChannelMoveClipboard { channel_id });
1768 }
1769
1770 fn start_move_selected_channel(&mut self, _: &StartMoveChannel, cx: &mut ViewContext<Self>) {
1771 if let Some(channel) = self.selected_channel() {
1772 self.start_move_channel(channel.id, cx);
1773 }
1774 }
1775
1776 fn move_channel_on_clipboard(
1777 &mut self,
1778 to_channel_id: ChannelId,
1779 cx: &mut ViewContext<CollabPanel>,
1780 ) {
1781 if let Some(clipboard) = self.channel_clipboard.take() {
1782 self.move_channel(clipboard.channel_id, to_channel_id, cx)
1783 }
1784 }
1785
1786 fn move_channel(&self, channel_id: ChannelId, to: ChannelId, cx: &mut ViewContext<Self>) {
1787 self.channel_store
1788 .update(cx, |channel_store, cx| {
1789 channel_store.move_channel(channel_id, to, cx)
1790 })
1791 .detach_and_prompt_err("Failed to move channel", cx, |e, _| match e.error_code() {
1792 ErrorCode::BadPublicNesting => {
1793 Some("Public channels must have public parents".into())
1794 }
1795 ErrorCode::CircularNesting => Some("You cannot move a channel into itself".into()),
1796 ErrorCode::WrongMoveTarget => {
1797 Some("You cannot move a channel into a different root channel".into())
1798 }
1799 _ => None,
1800 })
1801 }
1802
1803 fn open_channel_notes(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1804 if let Some(workspace) = self.workspace.upgrade() {
1805 ChannelView::open(channel_id, None, workspace, cx).detach();
1806 }
1807 }
1808
1809 fn show_inline_context_menu(&mut self, _: &menu::SecondaryConfirm, cx: &mut ViewContext<Self>) {
1810 let Some(bounds) = self
1811 .selection
1812 .and_then(|ix| self.list_state.bounds_for_item(ix))
1813 else {
1814 return;
1815 };
1816
1817 if let Some(channel) = self.selected_channel() {
1818 self.deploy_channel_context_menu(
1819 bounds.center(),
1820 channel.id,
1821 self.selection.unwrap(),
1822 cx,
1823 );
1824 cx.stop_propagation();
1825 return;
1826 };
1827
1828 if let Some(contact) = self.selected_contact() {
1829 self.deploy_contact_context_menu(bounds.center(), contact, cx);
1830 cx.stop_propagation();
1831 return;
1832 };
1833 }
1834
1835 fn selected_channel(&self) -> Option<&Arc<Channel>> {
1836 self.selection
1837 .and_then(|ix| self.entries.get(ix))
1838 .and_then(|entry| match entry {
1839 ListEntry::Channel { channel, .. } => Some(channel),
1840 _ => None,
1841 })
1842 }
1843
1844 fn selected_contact(&self) -> Option<Arc<Contact>> {
1845 self.selection
1846 .and_then(|ix| self.entries.get(ix))
1847 .and_then(|entry| match entry {
1848 ListEntry::Contact { contact, .. } => Some(contact.clone()),
1849 _ => None,
1850 })
1851 }
1852
1853 fn show_channel_modal(
1854 &mut self,
1855 channel_id: ChannelId,
1856 mode: channel_modal::Mode,
1857 cx: &mut ViewContext<Self>,
1858 ) {
1859 let workspace = self.workspace.clone();
1860 let user_store = self.user_store.clone();
1861 let channel_store = self.channel_store.clone();
1862 let members = self.channel_store.update(cx, |channel_store, cx| {
1863 channel_store.get_channel_member_details(channel_id, cx)
1864 });
1865
1866 cx.spawn(|_, mut cx| async move {
1867 let members = members.await?;
1868 workspace.update(&mut cx, |workspace, cx| {
1869 workspace.toggle_modal(cx, |cx| {
1870 ChannelModal::new(
1871 user_store.clone(),
1872 channel_store.clone(),
1873 channel_id,
1874 mode,
1875 members,
1876 cx,
1877 )
1878 });
1879 })
1880 })
1881 .detach();
1882 }
1883
1884 fn leave_channel(&self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1885 let Some(user_id) = self.user_store.read(cx).current_user().map(|u| u.id) else {
1886 return;
1887 };
1888 let Some(channel) = self.channel_store.read(cx).channel_for_id(channel_id) else {
1889 return;
1890 };
1891 let prompt_message = format!("Are you sure you want to leave \"#{}\"?", channel.name);
1892 let answer = cx.prompt(
1893 PromptLevel::Warning,
1894 &prompt_message,
1895 None,
1896 &["Leave", "Cancel"],
1897 );
1898 cx.spawn(|this, mut cx| async move {
1899 if answer.await? != 0 {
1900 return Ok(());
1901 }
1902 this.update(&mut cx, |this, cx| {
1903 this.channel_store.update(cx, |channel_store, cx| {
1904 channel_store.remove_member(channel_id, user_id, cx)
1905 })
1906 })?
1907 .await
1908 })
1909 .detach_and_prompt_err("Failed to leave channel", cx, |_, _| None)
1910 }
1911
1912 fn remove_channel(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1913 let channel_store = self.channel_store.clone();
1914 if let Some(channel) = channel_store.read(cx).channel_for_id(channel_id) {
1915 let prompt_message = format!(
1916 "Are you sure you want to remove the channel \"{}\"?",
1917 channel.name
1918 );
1919 let answer = cx.prompt(
1920 PromptLevel::Warning,
1921 &prompt_message,
1922 None,
1923 &["Remove", "Cancel"],
1924 );
1925 cx.spawn(|this, mut cx| async move {
1926 if answer.await? == 0 {
1927 channel_store
1928 .update(&mut cx, |channels, _| channels.remove_channel(channel_id))?
1929 .await
1930 .notify_async_err(&mut cx);
1931 this.update(&mut cx, |_, cx| cx.focus_self()).ok();
1932 }
1933 anyhow::Ok(())
1934 })
1935 .detach();
1936 }
1937 }
1938
1939 fn remove_contact(&mut self, user_id: u64, github_login: &str, cx: &mut ViewContext<Self>) {
1940 let user_store = self.user_store.clone();
1941 let prompt_message = format!(
1942 "Are you sure you want to remove \"{}\" from your contacts?",
1943 github_login
1944 );
1945 let answer = cx.prompt(
1946 PromptLevel::Warning,
1947 &prompt_message,
1948 None,
1949 &["Remove", "Cancel"],
1950 );
1951 cx.spawn(|_, mut cx| async move {
1952 if answer.await? == 0 {
1953 user_store
1954 .update(&mut cx, |store, cx| store.remove_contact(user_id, cx))?
1955 .await
1956 .notify_async_err(&mut cx);
1957 }
1958 anyhow::Ok(())
1959 })
1960 .detach_and_prompt_err("Failed to remove contact", cx, |_, _| None);
1961 }
1962
1963 fn respond_to_contact_request(
1964 &mut self,
1965 user_id: u64,
1966 accept: bool,
1967 cx: &mut ViewContext<Self>,
1968 ) {
1969 self.user_store
1970 .update(cx, |store, cx| {
1971 store.respond_to_contact_request(user_id, accept, cx)
1972 })
1973 .detach_and_prompt_err("Failed to respond to contact request", cx, |_, _| None);
1974 }
1975
1976 fn respond_to_channel_invite(
1977 &mut self,
1978 channel_id: ChannelId,
1979 accept: bool,
1980 cx: &mut ViewContext<Self>,
1981 ) {
1982 self.channel_store
1983 .update(cx, |store, cx| {
1984 store.respond_to_channel_invite(channel_id, accept, cx)
1985 })
1986 .detach();
1987 }
1988
1989 fn call(&mut self, recipient_user_id: u64, cx: &mut ViewContext<Self>) {
1990 ActiveCall::global(cx)
1991 .update(cx, |call, cx| {
1992 call.invite(recipient_user_id, Some(self.project.clone()), cx)
1993 })
1994 .detach_and_prompt_err("Call failed", cx, |_, _| None);
1995 }
1996
1997 fn join_channel(&self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1998 let Some(workspace) = self.workspace.upgrade() else {
1999 return;
2000 };
2001 let Some(handle) = cx.window_handle().downcast::<Workspace>() else {
2002 return;
2003 };
2004 workspace::join_channel(
2005 channel_id,
2006 workspace.read(cx).app_state().clone(),
2007 Some(handle),
2008 cx,
2009 )
2010 .detach_and_prompt_err("Failed to join channel", cx, |_, _| None)
2011 }
2012
2013 fn join_channel_chat(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
2014 let Some(workspace) = self.workspace.upgrade() else {
2015 return;
2016 };
2017 cx.window_context().defer(move |cx| {
2018 workspace.update(cx, |workspace, cx| {
2019 if let Some(panel) = workspace.focus_panel::<ChatPanel>(cx) {
2020 panel.update(cx, |panel, cx| {
2021 panel
2022 .select_channel(channel_id, None, cx)
2023 .detach_and_notify_err(cx);
2024 });
2025 }
2026 });
2027 });
2028 }
2029
2030 fn copy_channel_link(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
2031 let channel_store = self.channel_store.read(cx);
2032 let Some(channel) = channel_store.channel_for_id(channel_id) else {
2033 return;
2034 };
2035 let item = ClipboardItem::new(channel.link(cx));
2036 cx.write_to_clipboard(item)
2037 }
2038
2039 fn render_signed_out(&mut self, cx: &mut ViewContext<Self>) -> Div {
2040 let collab_blurb = "Work with your team in realtime with collaborative editing, voice, shared notes and more.";
2041
2042 v_flex()
2043 .gap_6()
2044 .p_4()
2045 .child(Label::new(collab_blurb))
2046 .child(
2047 v_flex()
2048 .gap_2()
2049 .child(
2050 Button::new("sign_in", "Sign in")
2051 .icon_color(Color::Muted)
2052 .icon(IconName::Github)
2053 .icon_position(IconPosition::Start)
2054 .style(ButtonStyle::Filled)
2055 .full_width()
2056 .on_click(cx.listener(|this, _, cx| {
2057 let client = this.client.clone();
2058 cx.spawn(|_, mut cx| async move {
2059 client
2060 .authenticate_and_connect(true, &cx)
2061 .await
2062 .notify_async_err(&mut cx);
2063 })
2064 .detach()
2065 })),
2066 )
2067 .child(
2068 div().flex().w_full().items_center().child(
2069 Label::new("Sign in to enable collaboration.")
2070 .color(Color::Muted)
2071 .size(LabelSize::Small),
2072 ),
2073 ),
2074 )
2075 }
2076
2077 fn render_list_entry(&mut self, ix: usize, cx: &mut ViewContext<Self>) -> AnyElement {
2078 let entry = &self.entries[ix];
2079
2080 let is_selected = self.selection == Some(ix);
2081 match entry {
2082 ListEntry::Header(section) => {
2083 let is_collapsed = self.collapsed_sections.contains(section);
2084 self.render_header(*section, is_selected, is_collapsed, cx)
2085 .into_any_element()
2086 }
2087 ListEntry::Contact { contact, calling } => self
2088 .render_contact(contact, *calling, is_selected, cx)
2089 .into_any_element(),
2090 ListEntry::ContactPlaceholder => self
2091 .render_contact_placeholder(is_selected, cx)
2092 .into_any_element(),
2093 ListEntry::IncomingRequest(user) => self
2094 .render_contact_request(user, true, is_selected, cx)
2095 .into_any_element(),
2096 ListEntry::OutgoingRequest(user) => self
2097 .render_contact_request(user, false, is_selected, cx)
2098 .into_any_element(),
2099 ListEntry::Channel {
2100 channel,
2101 depth,
2102 has_children,
2103 } => self
2104 .render_channel(channel, *depth, *has_children, is_selected, ix, cx)
2105 .into_any_element(),
2106 ListEntry::ChannelEditor { depth } => {
2107 self.render_channel_editor(*depth, cx).into_any_element()
2108 }
2109 ListEntry::ChannelInvite(channel) => self
2110 .render_channel_invite(channel, is_selected, cx)
2111 .into_any_element(),
2112 ListEntry::CallParticipant {
2113 user,
2114 peer_id,
2115 is_pending,
2116 role,
2117 } => self
2118 .render_call_participant(user, *peer_id, *is_pending, *role, is_selected, cx)
2119 .into_any_element(),
2120 ListEntry::ParticipantProject {
2121 project_id,
2122 worktree_root_names,
2123 host_user_id,
2124 is_last,
2125 } => self
2126 .render_participant_project(
2127 *project_id,
2128 &worktree_root_names,
2129 *host_user_id,
2130 *is_last,
2131 is_selected,
2132 cx,
2133 )
2134 .into_any_element(),
2135 ListEntry::ParticipantScreen { peer_id, is_last } => self
2136 .render_participant_screen(*peer_id, *is_last, is_selected, cx)
2137 .into_any_element(),
2138 ListEntry::ChannelNotes { channel_id } => self
2139 .render_channel_notes(*channel_id, is_selected, cx)
2140 .into_any_element(),
2141 ListEntry::ChannelChat { channel_id } => self
2142 .render_channel_chat(*channel_id, is_selected, cx)
2143 .into_any_element(),
2144
2145 ListEntry::HostedProject { id, name } => self
2146 .render_channel_project(*id, name, is_selected, cx)
2147 .into_any_element(),
2148 }
2149 }
2150
2151 fn render_signed_in(&mut self, cx: &mut ViewContext<Self>) -> Div {
2152 v_flex()
2153 .size_full()
2154 .child(list(self.list_state.clone()).size_full())
2155 .child(
2156 v_flex()
2157 .child(div().mx_2().border_primary(cx).border_t_1())
2158 .child(
2159 v_flex()
2160 .p_2()
2161 .child(self.render_filter_input(&self.filter_editor, cx)),
2162 ),
2163 )
2164 }
2165
2166 fn render_filter_input(
2167 &self,
2168 editor: &View<Editor>,
2169 cx: &mut ViewContext<Self>,
2170 ) -> impl IntoElement {
2171 let settings = ThemeSettings::get_global(cx);
2172 let text_style = TextStyle {
2173 color: if editor.read(cx).read_only(cx) {
2174 cx.theme().colors().text_disabled
2175 } else {
2176 cx.theme().colors().text
2177 },
2178 font_family: settings.ui_font.family.clone(),
2179 font_features: settings.ui_font.features.clone(),
2180 font_size: rems(0.875).into(),
2181 font_weight: FontWeight::NORMAL,
2182 font_style: FontStyle::Normal,
2183 line_height: relative(1.3),
2184 background_color: None,
2185 underline: None,
2186 strikethrough: None,
2187 white_space: WhiteSpace::Normal,
2188 };
2189
2190 EditorElement::new(
2191 editor,
2192 EditorStyle {
2193 local_player: cx.theme().players().local(),
2194 text: text_style,
2195 ..Default::default()
2196 },
2197 )
2198 }
2199
2200 fn render_header(
2201 &self,
2202 section: Section,
2203 is_selected: bool,
2204 is_collapsed: bool,
2205 cx: &ViewContext<Self>,
2206 ) -> impl IntoElement {
2207 let mut channel_link = None;
2208 let mut channel_tooltip_text = None;
2209 let mut channel_icon = None;
2210
2211 let text = match section {
2212 Section::ActiveCall => {
2213 let channel_name = maybe!({
2214 let channel_id = ActiveCall::global(cx).read(cx).channel_id(cx)?;
2215
2216 let channel = self.channel_store.read(cx).channel_for_id(channel_id)?;
2217
2218 channel_link = Some(channel.link(cx));
2219 (channel_icon, channel_tooltip_text) = match channel.visibility {
2220 proto::ChannelVisibility::Public => {
2221 (Some("icons/public.svg"), Some("Copy public channel link."))
2222 }
2223 proto::ChannelVisibility::Members => {
2224 (Some("icons/hash.svg"), Some("Copy private channel link."))
2225 }
2226 };
2227
2228 Some(channel.name.as_ref())
2229 });
2230
2231 if let Some(name) = channel_name {
2232 SharedString::from(name.to_string())
2233 } else {
2234 SharedString::from("Current Call")
2235 }
2236 }
2237 Section::ContactRequests => SharedString::from("Requests"),
2238 Section::Contacts => SharedString::from("Contacts"),
2239 Section::Channels => SharedString::from("Channels"),
2240 Section::ChannelInvites => SharedString::from("Invites"),
2241 Section::Online => SharedString::from("Online"),
2242 Section::Offline => SharedString::from("Offline"),
2243 };
2244
2245 let button = match section {
2246 Section::ActiveCall => channel_link.map(|channel_link| {
2247 let channel_link_copy = channel_link.clone();
2248 IconButton::new("channel-link", IconName::Copy)
2249 .icon_size(IconSize::Small)
2250 .size(ButtonSize::None)
2251 .visible_on_hover("section-header")
2252 .on_click(move |_, cx| {
2253 let item = ClipboardItem::new(channel_link_copy.clone());
2254 cx.write_to_clipboard(item)
2255 })
2256 .tooltip(|cx| Tooltip::text("Copy channel link", cx))
2257 .into_any_element()
2258 }),
2259 Section::Contacts => Some(
2260 IconButton::new("add-contact", IconName::Plus)
2261 .on_click(cx.listener(|this, _, cx| this.toggle_contact_finder(cx)))
2262 .tooltip(|cx| Tooltip::text("Search for new contact", cx))
2263 .into_any_element(),
2264 ),
2265 Section::Channels => Some(
2266 IconButton::new("add-channel", IconName::Plus)
2267 .on_click(cx.listener(|this, _, cx| this.new_root_channel(cx)))
2268 .tooltip(|cx| Tooltip::text("Create a channel", cx))
2269 .into_any_element(),
2270 ),
2271 _ => None,
2272 };
2273
2274 let can_collapse = match section {
2275 Section::ActiveCall | Section::Channels | Section::Contacts => false,
2276 Section::ChannelInvites
2277 | Section::ContactRequests
2278 | Section::Online
2279 | Section::Offline => true,
2280 };
2281
2282 h_flex().w_full().group("section-header").child(
2283 ListHeader::new(text)
2284 .when(can_collapse, |header| {
2285 header
2286 .toggle(Some(!is_collapsed))
2287 .on_toggle(cx.listener(move |this, _, cx| {
2288 this.toggle_section_expanded(section, cx);
2289 }))
2290 })
2291 .inset(true)
2292 .end_slot::<AnyElement>(button)
2293 .selected(is_selected),
2294 )
2295 }
2296
2297 fn render_contact(
2298 &self,
2299 contact: &Arc<Contact>,
2300 calling: bool,
2301 is_selected: bool,
2302 cx: &mut ViewContext<Self>,
2303 ) -> impl IntoElement {
2304 let online = contact.online;
2305 let busy = contact.busy || calling;
2306 let github_login = SharedString::from(contact.user.github_login.clone());
2307 let item = ListItem::new(github_login.clone())
2308 .indent_level(1)
2309 .indent_step_size(px(20.))
2310 .selected(is_selected)
2311 .child(
2312 h_flex()
2313 .w_full()
2314 .justify_between()
2315 .child(Label::new(github_login.clone()))
2316 .when(calling, |el| {
2317 el.child(Label::new("Calling").color(Color::Muted))
2318 })
2319 .when(!calling, |el| {
2320 el.child(
2321 IconButton::new("contact context menu", IconName::Ellipsis)
2322 .icon_color(Color::Muted)
2323 .visible_on_hover("")
2324 .on_click(cx.listener({
2325 let contact = contact.clone();
2326 move |this, event: &ClickEvent, cx| {
2327 this.deploy_contact_context_menu(
2328 event.down.position,
2329 contact.clone(),
2330 cx,
2331 );
2332 }
2333 })),
2334 )
2335 }),
2336 )
2337 .on_secondary_mouse_down(cx.listener({
2338 let contact = contact.clone();
2339 move |this, event: &MouseDownEvent, cx| {
2340 this.deploy_contact_context_menu(event.position, contact.clone(), cx);
2341 }
2342 }))
2343 .start_slot(
2344 // todo handle contacts with no avatar
2345 Avatar::new(contact.user.avatar_uri.clone())
2346 .indicator::<AvatarAvailabilityIndicator>(if online {
2347 Some(AvatarAvailabilityIndicator::new(match busy {
2348 true => ui::Availability::Busy,
2349 false => ui::Availability::Free,
2350 }))
2351 } else {
2352 None
2353 }),
2354 );
2355
2356 div()
2357 .id(github_login.clone())
2358 .group("")
2359 .child(item)
2360 .tooltip(move |cx| {
2361 let text = if !online {
2362 format!(" {} is offline", &github_login)
2363 } else if busy {
2364 format!(" {} is on a call", &github_login)
2365 } else {
2366 let room = ActiveCall::global(cx).read(cx).room();
2367 if room.is_some() {
2368 format!("Invite {} to join call", &github_login)
2369 } else {
2370 format!("Call {}", &github_login)
2371 }
2372 };
2373 Tooltip::text(text, cx)
2374 })
2375 }
2376
2377 fn render_contact_request(
2378 &self,
2379 user: &Arc<User>,
2380 is_incoming: bool,
2381 is_selected: bool,
2382 cx: &mut ViewContext<Self>,
2383 ) -> impl IntoElement {
2384 let github_login = SharedString::from(user.github_login.clone());
2385 let user_id = user.id;
2386 let is_response_pending = self.user_store.read(cx).is_contact_request_pending(&user);
2387 let color = if is_response_pending {
2388 Color::Muted
2389 } else {
2390 Color::Default
2391 };
2392
2393 let controls = if is_incoming {
2394 vec![
2395 IconButton::new("decline-contact", IconName::Close)
2396 .on_click(cx.listener(move |this, _, cx| {
2397 this.respond_to_contact_request(user_id, false, cx);
2398 }))
2399 .icon_color(color)
2400 .tooltip(|cx| Tooltip::text("Decline invite", cx)),
2401 IconButton::new("accept-contact", IconName::Check)
2402 .on_click(cx.listener(move |this, _, cx| {
2403 this.respond_to_contact_request(user_id, true, cx);
2404 }))
2405 .icon_color(color)
2406 .tooltip(|cx| Tooltip::text("Accept invite", cx)),
2407 ]
2408 } else {
2409 let github_login = github_login.clone();
2410 vec![IconButton::new("remove_contact", IconName::Close)
2411 .on_click(cx.listener(move |this, _, cx| {
2412 this.remove_contact(user_id, &github_login, cx);
2413 }))
2414 .icon_color(color)
2415 .tooltip(|cx| Tooltip::text("Cancel invite", cx))]
2416 };
2417
2418 ListItem::new(github_login.clone())
2419 .indent_level(1)
2420 .indent_step_size(px(20.))
2421 .selected(is_selected)
2422 .child(
2423 h_flex()
2424 .w_full()
2425 .justify_between()
2426 .child(Label::new(github_login.clone()))
2427 .child(h_flex().children(controls)),
2428 )
2429 .start_slot(Avatar::new(user.avatar_uri.clone()))
2430 }
2431
2432 fn render_channel_invite(
2433 &self,
2434 channel: &Arc<Channel>,
2435 is_selected: bool,
2436 cx: &mut ViewContext<Self>,
2437 ) -> ListItem {
2438 let channel_id = channel.id;
2439 let response_is_pending = self
2440 .channel_store
2441 .read(cx)
2442 .has_pending_channel_invite_response(&channel);
2443 let color = if response_is_pending {
2444 Color::Muted
2445 } else {
2446 Color::Default
2447 };
2448
2449 let controls = [
2450 IconButton::new("reject-invite", IconName::Close)
2451 .on_click(cx.listener(move |this, _, cx| {
2452 this.respond_to_channel_invite(channel_id, false, cx);
2453 }))
2454 .icon_color(color)
2455 .tooltip(|cx| Tooltip::text("Decline invite", cx)),
2456 IconButton::new("accept-invite", IconName::Check)
2457 .on_click(cx.listener(move |this, _, cx| {
2458 this.respond_to_channel_invite(channel_id, true, cx);
2459 }))
2460 .icon_color(color)
2461 .tooltip(|cx| Tooltip::text("Accept invite", cx)),
2462 ];
2463
2464 ListItem::new(("channel-invite", channel.id.0 as usize))
2465 .selected(is_selected)
2466 .child(
2467 h_flex()
2468 .w_full()
2469 .justify_between()
2470 .child(Label::new(channel.name.clone()))
2471 .child(h_flex().children(controls)),
2472 )
2473 .start_slot(
2474 Icon::new(IconName::Hash)
2475 .size(IconSize::Small)
2476 .color(Color::Muted),
2477 )
2478 }
2479
2480 fn render_contact_placeholder(
2481 &self,
2482 is_selected: bool,
2483 cx: &mut ViewContext<Self>,
2484 ) -> ListItem {
2485 ListItem::new("contact-placeholder")
2486 .child(Icon::new(IconName::Plus))
2487 .child(Label::new("Add a Contact"))
2488 .selected(is_selected)
2489 .on_click(cx.listener(|this, _, cx| this.toggle_contact_finder(cx)))
2490 }
2491
2492 fn render_channel(
2493 &self,
2494 channel: &Channel,
2495 depth: usize,
2496 has_children: bool,
2497 is_selected: bool,
2498 ix: usize,
2499 cx: &mut ViewContext<Self>,
2500 ) -> impl IntoElement {
2501 let channel_id = channel.id;
2502
2503 let is_active = maybe!({
2504 let call_channel = ActiveCall::global(cx)
2505 .read(cx)
2506 .room()?
2507 .read(cx)
2508 .channel_id()?;
2509 Some(call_channel == channel_id)
2510 })
2511 .unwrap_or(false);
2512 let channel_store = self.channel_store.read(cx);
2513 let is_public = channel_store
2514 .channel_for_id(channel_id)
2515 .map(|channel| channel.visibility)
2516 == Some(proto::ChannelVisibility::Public);
2517 let disclosed =
2518 has_children.then(|| self.collapsed_channels.binary_search(&channel.id).is_err());
2519
2520 let has_messages_notification = channel_store.has_new_messages(channel_id);
2521 let has_notes_notification = channel_store.has_channel_buffer_changed(channel_id);
2522
2523 const FACEPILE_LIMIT: usize = 3;
2524 let participants = self.channel_store.read(cx).channel_participants(channel_id);
2525
2526 let face_pile = if participants.is_empty() {
2527 None
2528 } else {
2529 let extra_count = participants.len().saturating_sub(FACEPILE_LIMIT);
2530 let result = FacePile::new(
2531 participants
2532 .iter()
2533 .map(|user| Avatar::new(user.avatar_uri.clone()).into_any_element())
2534 .take(FACEPILE_LIMIT)
2535 .chain(if extra_count > 0 {
2536 Some(
2537 div()
2538 .ml_2()
2539 .child(Label::new(format!("+{extra_count}")))
2540 .into_any_element(),
2541 )
2542 } else {
2543 None
2544 })
2545 .collect::<SmallVec<_>>(),
2546 );
2547
2548 Some(result)
2549 };
2550
2551 let width = self.width.unwrap_or(px(240.));
2552 let root_id = channel.root_id();
2553
2554 div()
2555 .h_6()
2556 .id(channel_id.0 as usize)
2557 .group("")
2558 .flex()
2559 .w_full()
2560 .when(!channel.is_root_channel(), |el| {
2561 el.on_drag(channel.clone(), move |channel, cx| {
2562 cx.new_view(|_| DraggedChannelView {
2563 channel: channel.clone(),
2564 width,
2565 })
2566 })
2567 })
2568 .drag_over::<Channel>({
2569 move |style, dragged_channel: &Channel, cx| {
2570 if dragged_channel.root_id() == root_id {
2571 style.bg(cx.theme().colors().ghost_element_hover)
2572 } else {
2573 style
2574 }
2575 }
2576 })
2577 .on_drop(cx.listener(move |this, dragged_channel: &Channel, cx| {
2578 if dragged_channel.root_id() != root_id {
2579 return;
2580 }
2581 this.move_channel(dragged_channel.id, channel_id, cx);
2582 }))
2583 .child(
2584 ListItem::new(channel_id.0 as usize)
2585 // Add one level of depth for the disclosure arrow.
2586 .indent_level(depth + 1)
2587 .indent_step_size(px(20.))
2588 .selected(is_selected || is_active)
2589 .toggle(disclosed)
2590 .on_toggle(
2591 cx.listener(move |this, _, cx| {
2592 this.toggle_channel_collapsed(channel_id, cx)
2593 }),
2594 )
2595 .on_click(cx.listener(move |this, _, cx| {
2596 if is_active {
2597 this.open_channel_notes(channel_id, cx)
2598 } else {
2599 this.join_channel(channel_id, cx)
2600 }
2601 }))
2602 .on_secondary_mouse_down(cx.listener(
2603 move |this, event: &MouseDownEvent, cx| {
2604 this.deploy_channel_context_menu(event.position, channel_id, ix, cx)
2605 },
2606 ))
2607 .start_slot(
2608 div()
2609 .relative()
2610 .child(
2611 Icon::new(if is_public {
2612 IconName::Public
2613 } else {
2614 IconName::Hash
2615 })
2616 .size(IconSize::Small)
2617 .color(Color::Muted),
2618 )
2619 .children(has_notes_notification.then(|| {
2620 div()
2621 .w_1p5()
2622 .absolute()
2623 .right(px(-1.))
2624 .top(px(-1.))
2625 .child(Indicator::dot().color(Color::Info))
2626 })),
2627 )
2628 .child(
2629 h_flex()
2630 .id(channel_id.0 as usize)
2631 .child(Label::new(channel.name.clone()))
2632 .children(face_pile.map(|face_pile| face_pile.p_1())),
2633 ),
2634 )
2635 .child(
2636 h_flex().absolute().right(rems(0.)).h_full().child(
2637 h_flex()
2638 .h_full()
2639 .gap_1()
2640 .px_1()
2641 .child(
2642 IconButton::new("channel_chat", IconName::MessageBubbles)
2643 .style(ButtonStyle::Filled)
2644 .shape(ui::IconButtonShape::Square)
2645 .icon_size(IconSize::Small)
2646 .icon_color(if has_messages_notification {
2647 Color::Default
2648 } else {
2649 Color::Muted
2650 })
2651 .on_click(cx.listener(move |this, _, cx| {
2652 this.join_channel_chat(channel_id, cx)
2653 }))
2654 .tooltip(|cx| Tooltip::text("Open channel chat", cx))
2655 .visible_on_hover(""),
2656 )
2657 .child(
2658 IconButton::new("channel_notes", IconName::File)
2659 .style(ButtonStyle::Filled)
2660 .shape(ui::IconButtonShape::Square)
2661 .icon_size(IconSize::Small)
2662 .icon_color(if has_notes_notification {
2663 Color::Default
2664 } else {
2665 Color::Muted
2666 })
2667 .on_click(cx.listener(move |this, _, cx| {
2668 this.open_channel_notes(channel_id, cx)
2669 }))
2670 .tooltip(|cx| Tooltip::text("Open channel notes", cx))
2671 .visible_on_hover(""),
2672 ),
2673 ),
2674 )
2675 .tooltip({
2676 let channel_store = self.channel_store.clone();
2677 move |cx| {
2678 cx.new_view(|_| JoinChannelTooltip {
2679 channel_store: channel_store.clone(),
2680 channel_id,
2681 has_notes_notification,
2682 })
2683 .into()
2684 }
2685 })
2686 }
2687
2688 fn render_channel_editor(&self, depth: usize, _cx: &mut ViewContext<Self>) -> impl IntoElement {
2689 let item = ListItem::new("channel-editor")
2690 .inset(false)
2691 // Add one level of depth for the disclosure arrow.
2692 .indent_level(depth + 1)
2693 .indent_step_size(px(20.))
2694 .start_slot(
2695 Icon::new(IconName::Hash)
2696 .size(IconSize::Small)
2697 .color(Color::Muted),
2698 );
2699
2700 if let Some(pending_name) = self
2701 .channel_editing_state
2702 .as_ref()
2703 .and_then(|state| state.pending_name())
2704 {
2705 item.child(Label::new(pending_name))
2706 } else {
2707 item.child(self.channel_name_editor.clone())
2708 }
2709 }
2710}
2711
2712fn render_tree_branch(is_last: bool, overdraw: bool, cx: &mut WindowContext) -> impl IntoElement {
2713 let rem_size = cx.rem_size();
2714 let line_height = cx.text_style().line_height_in_pixels(rem_size);
2715 let width = rem_size * 1.5;
2716 let thickness = px(1.);
2717 let color = cx.theme().colors().text;
2718
2719 canvas(
2720 |_, _| {},
2721 move |bounds, _, cx| {
2722 let start_x = (bounds.left() + bounds.right() - thickness) / 2.;
2723 let start_y = (bounds.top() + bounds.bottom() - thickness) / 2.;
2724 let right = bounds.right();
2725 let top = bounds.top();
2726
2727 cx.paint_quad(fill(
2728 Bounds::from_corners(
2729 point(start_x, top),
2730 point(
2731 start_x + thickness,
2732 if is_last {
2733 start_y
2734 } else {
2735 bounds.bottom() + if overdraw { px(1.) } else { px(0.) }
2736 },
2737 ),
2738 ),
2739 color,
2740 ));
2741 cx.paint_quad(fill(
2742 Bounds::from_corners(point(start_x, start_y), point(right, start_y + thickness)),
2743 color,
2744 ));
2745 },
2746 )
2747 .w(width)
2748 .h(line_height)
2749}
2750
2751impl Render for CollabPanel {
2752 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
2753 v_flex()
2754 .key_context("CollabPanel")
2755 .on_action(cx.listener(CollabPanel::cancel))
2756 .on_action(cx.listener(CollabPanel::select_next))
2757 .on_action(cx.listener(CollabPanel::select_prev))
2758 .on_action(cx.listener(CollabPanel::confirm))
2759 .on_action(cx.listener(CollabPanel::insert_space))
2760 .on_action(cx.listener(CollabPanel::remove_selected_channel))
2761 .on_action(cx.listener(CollabPanel::show_inline_context_menu))
2762 .on_action(cx.listener(CollabPanel::rename_selected_channel))
2763 .on_action(cx.listener(CollabPanel::collapse_selected_channel))
2764 .on_action(cx.listener(CollabPanel::expand_selected_channel))
2765 .on_action(cx.listener(CollabPanel::start_move_selected_channel))
2766 .track_focus(&self.focus_handle)
2767 .size_full()
2768 .child(if self.user_store.read(cx).current_user().is_none() {
2769 self.render_signed_out(cx)
2770 } else {
2771 self.render_signed_in(cx)
2772 })
2773 .children(self.context_menu.as_ref().map(|(menu, position, _)| {
2774 deferred(
2775 anchored()
2776 .position(*position)
2777 .anchor(gpui::AnchorCorner::TopLeft)
2778 .child(menu.clone()),
2779 )
2780 .with_priority(1)
2781 }))
2782 }
2783}
2784
2785impl EventEmitter<PanelEvent> for CollabPanel {}
2786
2787impl Panel for CollabPanel {
2788 fn position(&self, cx: &gpui::WindowContext) -> DockPosition {
2789 CollaborationPanelSettings::get_global(cx).dock
2790 }
2791
2792 fn position_is_valid(&self, position: DockPosition) -> bool {
2793 matches!(position, DockPosition::Left | DockPosition::Right)
2794 }
2795
2796 fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
2797 settings::update_settings_file::<CollaborationPanelSettings>(
2798 self.fs.clone(),
2799 cx,
2800 move |settings| settings.dock = Some(position),
2801 );
2802 }
2803
2804 fn size(&self, cx: &gpui::WindowContext) -> Pixels {
2805 self.width
2806 .unwrap_or_else(|| CollaborationPanelSettings::get_global(cx).default_width)
2807 }
2808
2809 fn set_size(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
2810 self.width = size;
2811 self.serialize(cx);
2812 cx.notify();
2813 }
2814
2815 fn icon(&self, cx: &gpui::WindowContext) -> Option<ui::IconName> {
2816 CollaborationPanelSettings::get_global(cx)
2817 .button
2818 .then(|| ui::IconName::Collab)
2819 }
2820
2821 fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> {
2822 Some("Collab Panel")
2823 }
2824
2825 fn toggle_action(&self) -> Box<dyn gpui::Action> {
2826 Box::new(ToggleFocus)
2827 }
2828
2829 fn persistent_name() -> &'static str {
2830 "CollabPanel"
2831 }
2832}
2833
2834impl FocusableView for CollabPanel {
2835 fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
2836 self.filter_editor.focus_handle(cx).clone()
2837 }
2838}
2839
2840impl PartialEq for ListEntry {
2841 fn eq(&self, other: &Self) -> bool {
2842 match self {
2843 ListEntry::Header(section_1) => {
2844 if let ListEntry::Header(section_2) = other {
2845 return section_1 == section_2;
2846 }
2847 }
2848 ListEntry::CallParticipant { user: user_1, .. } => {
2849 if let ListEntry::CallParticipant { user: user_2, .. } = other {
2850 return user_1.id == user_2.id;
2851 }
2852 }
2853 ListEntry::ParticipantProject {
2854 project_id: project_id_1,
2855 ..
2856 } => {
2857 if let ListEntry::ParticipantProject {
2858 project_id: project_id_2,
2859 ..
2860 } = other
2861 {
2862 return project_id_1 == project_id_2;
2863 }
2864 }
2865 ListEntry::ParticipantScreen {
2866 peer_id: peer_id_1, ..
2867 } => {
2868 if let ListEntry::ParticipantScreen {
2869 peer_id: peer_id_2, ..
2870 } = other
2871 {
2872 return peer_id_1 == peer_id_2;
2873 }
2874 }
2875 ListEntry::Channel {
2876 channel: channel_1, ..
2877 } => {
2878 if let ListEntry::Channel {
2879 channel: channel_2, ..
2880 } = other
2881 {
2882 return channel_1.id == channel_2.id;
2883 }
2884 }
2885 ListEntry::HostedProject { id, .. } => {
2886 if let ListEntry::HostedProject { id: other_id, .. } = other {
2887 return id == other_id;
2888 }
2889 }
2890 ListEntry::ChannelNotes { channel_id } => {
2891 if let ListEntry::ChannelNotes {
2892 channel_id: other_id,
2893 } = other
2894 {
2895 return channel_id == other_id;
2896 }
2897 }
2898 ListEntry::ChannelChat { channel_id } => {
2899 if let ListEntry::ChannelChat {
2900 channel_id: other_id,
2901 } = other
2902 {
2903 return channel_id == other_id;
2904 }
2905 }
2906 ListEntry::ChannelInvite(channel_1) => {
2907 if let ListEntry::ChannelInvite(channel_2) = other {
2908 return channel_1.id == channel_2.id;
2909 }
2910 }
2911 ListEntry::IncomingRequest(user_1) => {
2912 if let ListEntry::IncomingRequest(user_2) = other {
2913 return user_1.id == user_2.id;
2914 }
2915 }
2916 ListEntry::OutgoingRequest(user_1) => {
2917 if let ListEntry::OutgoingRequest(user_2) = other {
2918 return user_1.id == user_2.id;
2919 }
2920 }
2921 ListEntry::Contact {
2922 contact: contact_1, ..
2923 } => {
2924 if let ListEntry::Contact {
2925 contact: contact_2, ..
2926 } = other
2927 {
2928 return contact_1.user.id == contact_2.user.id;
2929 }
2930 }
2931 ListEntry::ChannelEditor { depth } => {
2932 if let ListEntry::ChannelEditor { depth: other_depth } = other {
2933 return depth == other_depth;
2934 }
2935 }
2936 ListEntry::ContactPlaceholder => {
2937 if let ListEntry::ContactPlaceholder = other {
2938 return true;
2939 }
2940 }
2941 }
2942 false
2943 }
2944}
2945
2946struct DraggedChannelView {
2947 channel: Channel,
2948 width: Pixels,
2949}
2950
2951impl Render for DraggedChannelView {
2952 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
2953 let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
2954 h_flex()
2955 .font_family(ui_font)
2956 .bg(cx.theme().colors().background)
2957 .w(self.width)
2958 .p_1()
2959 .gap_1()
2960 .child(
2961 Icon::new(
2962 if self.channel.visibility == proto::ChannelVisibility::Public {
2963 IconName::Public
2964 } else {
2965 IconName::Hash
2966 },
2967 )
2968 .size(IconSize::Small)
2969 .color(Color::Muted),
2970 )
2971 .child(Label::new(self.channel.name.clone()))
2972 }
2973}
2974
2975struct JoinChannelTooltip {
2976 channel_store: Model<ChannelStore>,
2977 channel_id: ChannelId,
2978 #[allow(unused)]
2979 has_notes_notification: bool,
2980}
2981
2982impl Render for JoinChannelTooltip {
2983 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
2984 tooltip_container(cx, |container, cx| {
2985 let participants = self
2986 .channel_store
2987 .read(cx)
2988 .channel_participants(self.channel_id);
2989
2990 container
2991 .child(Label::new("Join channel"))
2992 .children(participants.iter().map(|participant| {
2993 h_flex()
2994 .gap_2()
2995 .child(Avatar::new(participant.avatar_uri.clone()))
2996 .child(Label::new(participant.github_login.clone()))
2997 }))
2998 })
2999 }
3000}