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, HostedProjectId};
11use client::{ChannelId, Client, Contact, 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, canvas, div, fill, list, overlay, point, prelude::*, px, AnyElement, AppContext,
18 AsyncWindowContext, Bounds, ClickEvent, ClipboardItem, DismissEvent, Div, EventEmitter,
19 FocusHandle, FocusableView, FontStyle, FontWeight, InteractiveElement, IntoElement, ListOffset,
20 ListState, Model, MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, Render,
21 SharedString, Styled, Subscription, Task, TextStyle, View, ViewContext, VisualContext,
22 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: HostedProjectId,
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, |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_remote_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 .z_index(1)
993 .absolute()
994 .right(px(2.))
995 .top(px(2.))
996 .child(Indicator::dot().color(Color::Info))
997 })),
998 )
999 .child(Label::new("notes"))
1000 .tooltip(move |cx| Tooltip::text("Open Channel Notes", cx))
1001 }
1002
1003 fn render_channel_chat(
1004 &self,
1005 channel_id: ChannelId,
1006 is_selected: bool,
1007 cx: &mut ViewContext<Self>,
1008 ) -> impl IntoElement {
1009 let channel_store = self.channel_store.read(cx);
1010 let has_messages_notification = channel_store.has_new_messages(channel_id);
1011 ListItem::new("channel-chat")
1012 .selected(is_selected)
1013 .on_click(cx.listener(move |this, _, cx| {
1014 this.join_channel_chat(channel_id, cx);
1015 }))
1016 .start_slot(
1017 h_flex()
1018 .relative()
1019 .gap_1()
1020 .child(render_tree_branch(false, false, cx))
1021 .child(IconButton::new(0, IconName::MessageBubbles))
1022 .children(has_messages_notification.then(|| {
1023 div()
1024 .w_1p5()
1025 .z_index(1)
1026 .absolute()
1027 .right(px(2.))
1028 .top(px(4.))
1029 .child(Indicator::dot().color(Color::Info))
1030 })),
1031 )
1032 .child(Label::new("chat"))
1033 .tooltip(move |cx| Tooltip::text("Open Chat", cx))
1034 }
1035
1036 fn render_channel_project(
1037 &self,
1038 id: HostedProjectId,
1039 name: &SharedString,
1040 is_selected: bool,
1041 cx: &mut ViewContext<Self>,
1042 ) -> impl IntoElement {
1043 ListItem::new(ElementId::NamedInteger(
1044 "channel-project".into(),
1045 id.0 as usize,
1046 ))
1047 .indent_level(2)
1048 .indent_step_size(px(20.))
1049 .selected(is_selected)
1050 .on_click(cx.listener(move |_this, _, _cx| {
1051 // todo()
1052 }))
1053 .start_slot(
1054 h_flex()
1055 .relative()
1056 .gap_1()
1057 .child(IconButton::new(0, IconName::FileTree)),
1058 )
1059 .child(Label::new(name.clone()))
1060 .tooltip(move |cx| Tooltip::text("Open Project", cx))
1061 }
1062
1063 fn has_subchannels(&self, ix: usize) -> bool {
1064 self.entries.get(ix).map_or(false, |entry| {
1065 if let ListEntry::Channel { has_children, .. } = entry {
1066 *has_children
1067 } else {
1068 false
1069 }
1070 })
1071 }
1072
1073 fn deploy_participant_context_menu(
1074 &mut self,
1075 position: Point<Pixels>,
1076 user_id: u64,
1077 role: proto::ChannelRole,
1078 cx: &mut ViewContext<Self>,
1079 ) {
1080 let this = cx.view().clone();
1081 if !(role == proto::ChannelRole::Guest
1082 || role == proto::ChannelRole::Talker
1083 || role == proto::ChannelRole::Member)
1084 {
1085 return;
1086 }
1087
1088 let context_menu = ContextMenu::build(cx, |mut context_menu, cx| {
1089 if role == proto::ChannelRole::Guest {
1090 context_menu = context_menu.entry(
1091 "Grant Mic Access",
1092 None,
1093 cx.handler_for(&this, move |_, cx| {
1094 ActiveCall::global(cx)
1095 .update(cx, |call, cx| {
1096 let Some(room) = call.room() else {
1097 return Task::ready(Ok(()));
1098 };
1099 room.update(cx, |room, cx| {
1100 room.set_participant_role(
1101 user_id,
1102 proto::ChannelRole::Talker,
1103 cx,
1104 )
1105 })
1106 })
1107 .detach_and_prompt_err("Failed to grant mic access", cx, |_, _| None)
1108 }),
1109 );
1110 }
1111 if role == proto::ChannelRole::Guest || role == proto::ChannelRole::Talker {
1112 context_menu = context_menu.entry(
1113 "Grant Write Access",
1114 None,
1115 cx.handler_for(&this, move |_, cx| {
1116 ActiveCall::global(cx)
1117 .update(cx, |call, cx| {
1118 let Some(room) = call.room() else {
1119 return Task::ready(Ok(()));
1120 };
1121 room.update(cx, |room, cx| {
1122 room.set_participant_role(
1123 user_id,
1124 proto::ChannelRole::Member,
1125 cx,
1126 )
1127 })
1128 })
1129 .detach_and_prompt_err("Failed to grant write access", cx, |e, _| {
1130 match e.error_code() {
1131 ErrorCode::NeedsCla => Some("This user has not yet signed the CLA at https://zed.dev/cla.".into()),
1132 _ => None,
1133 }
1134 })
1135 }),
1136 );
1137 }
1138 if role == proto::ChannelRole::Member || role == proto::ChannelRole::Talker {
1139 let label = if role == proto::ChannelRole::Talker {
1140 "Mute"
1141 } else {
1142 "Revoke Access"
1143 };
1144 context_menu = context_menu.entry(
1145 label,
1146 None,
1147 cx.handler_for(&this, move |_, cx| {
1148 ActiveCall::global(cx)
1149 .update(cx, |call, cx| {
1150 let Some(room) = call.room() else {
1151 return Task::ready(Ok(()));
1152 };
1153 room.update(cx, |room, cx| {
1154 room.set_participant_role(
1155 user_id,
1156 proto::ChannelRole::Guest,
1157 cx,
1158 )
1159 })
1160 })
1161 .detach_and_prompt_err("Failed to revoke access", cx, |_, _| None)
1162 }),
1163 );
1164 }
1165
1166 context_menu
1167 });
1168
1169 cx.focus_view(&context_menu);
1170 let subscription =
1171 cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
1172 if this.context_menu.as_ref().is_some_and(|context_menu| {
1173 context_menu.0.focus_handle(cx).contains_focused(cx)
1174 }) {
1175 cx.focus_self();
1176 }
1177 this.context_menu.take();
1178 cx.notify();
1179 });
1180 self.context_menu = Some((context_menu, position, subscription));
1181 }
1182
1183 fn deploy_channel_context_menu(
1184 &mut self,
1185 position: Point<Pixels>,
1186 channel_id: ChannelId,
1187 ix: usize,
1188 cx: &mut ViewContext<Self>,
1189 ) {
1190 let clipboard_channel_name = self.channel_clipboard.as_ref().and_then(|clipboard| {
1191 self.channel_store
1192 .read(cx)
1193 .channel_for_id(clipboard.channel_id)
1194 .map(|channel| channel.name.clone())
1195 });
1196 let this = cx.view().clone();
1197
1198 let context_menu = ContextMenu::build(cx, |mut context_menu, cx| {
1199 if self.has_subchannels(ix) {
1200 let expand_action_name = if self.is_channel_collapsed(channel_id) {
1201 "Expand Subchannels"
1202 } else {
1203 "Collapse Subchannels"
1204 };
1205 context_menu = context_menu.entry(
1206 expand_action_name,
1207 None,
1208 cx.handler_for(&this, move |this, cx| {
1209 this.toggle_channel_collapsed(channel_id, cx)
1210 }),
1211 );
1212 }
1213
1214 context_menu = context_menu
1215 .entry(
1216 "Open Notes",
1217 None,
1218 cx.handler_for(&this, move |this, cx| {
1219 this.open_channel_notes(channel_id, cx)
1220 }),
1221 )
1222 .entry(
1223 "Open Chat",
1224 None,
1225 cx.handler_for(&this, move |this, cx| {
1226 this.join_channel_chat(channel_id, cx)
1227 }),
1228 )
1229 .entry(
1230 "Copy Channel Link",
1231 None,
1232 cx.handler_for(&this, move |this, cx| {
1233 this.copy_channel_link(channel_id, cx)
1234 }),
1235 );
1236
1237 let mut has_destructive_actions = false;
1238 if self.channel_store.read(cx).is_channel_admin(channel_id) {
1239 has_destructive_actions = true;
1240 context_menu = context_menu
1241 .separator()
1242 .entry(
1243 "New Subchannel",
1244 None,
1245 cx.handler_for(&this, move |this, cx| this.new_subchannel(channel_id, cx)),
1246 )
1247 .entry(
1248 "Rename",
1249 Some(Box::new(SecondaryConfirm)),
1250 cx.handler_for(&this, move |this, cx| this.rename_channel(channel_id, cx)),
1251 );
1252
1253 if let Some(channel_name) = clipboard_channel_name {
1254 context_menu = context_menu.separator().entry(
1255 format!("Move '#{}' here", channel_name),
1256 None,
1257 cx.handler_for(&this, move |this, cx| {
1258 this.move_channel_on_clipboard(channel_id, cx)
1259 }),
1260 );
1261 }
1262
1263 if self.channel_store.read(cx).is_root_channel(channel_id) {
1264 context_menu = context_menu.separator().entry(
1265 "Manage Members",
1266 None,
1267 cx.handler_for(&this, move |this, cx| this.manage_members(channel_id, cx)),
1268 )
1269 } else {
1270 context_menu = context_menu.entry(
1271 "Move this channel",
1272 None,
1273 cx.handler_for(&this, move |this, cx| {
1274 this.start_move_channel(channel_id, cx)
1275 }),
1276 );
1277 if self.channel_store.read(cx).is_public_channel(channel_id) {
1278 context_menu = context_menu.separator().entry(
1279 "Make Channel Private",
1280 None,
1281 cx.handler_for(&this, move |this, cx| {
1282 this.set_channel_visibility(
1283 channel_id,
1284 ChannelVisibility::Members,
1285 cx,
1286 )
1287 }),
1288 )
1289 } else {
1290 context_menu = context_menu.separator().entry(
1291 "Make Channel Public",
1292 None,
1293 cx.handler_for(&this, move |this, cx| {
1294 this.set_channel_visibility(
1295 channel_id,
1296 ChannelVisibility::Public,
1297 cx,
1298 )
1299 }),
1300 )
1301 }
1302 }
1303
1304 context_menu = context_menu.entry(
1305 "Delete",
1306 None,
1307 cx.handler_for(&this, move |this, cx| this.remove_channel(channel_id, cx)),
1308 );
1309 }
1310
1311 if self.channel_store.read(cx).is_root_channel(channel_id) {
1312 if !has_destructive_actions {
1313 context_menu = context_menu.separator()
1314 }
1315 context_menu = context_menu.entry(
1316 "Leave Channel",
1317 None,
1318 cx.handler_for(&this, move |this, cx| this.leave_channel(channel_id, cx)),
1319 );
1320 }
1321
1322 context_menu
1323 });
1324
1325 cx.focus_view(&context_menu);
1326 let subscription =
1327 cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
1328 if this.context_menu.as_ref().is_some_and(|context_menu| {
1329 context_menu.0.focus_handle(cx).contains_focused(cx)
1330 }) {
1331 cx.focus_self();
1332 }
1333 this.context_menu.take();
1334 cx.notify();
1335 });
1336 self.context_menu = Some((context_menu, position, subscription));
1337
1338 cx.notify();
1339 }
1340
1341 fn deploy_contact_context_menu(
1342 &mut self,
1343 position: Point<Pixels>,
1344 contact: Arc<Contact>,
1345 cx: &mut ViewContext<Self>,
1346 ) {
1347 let this = cx.view().clone();
1348 let in_room = ActiveCall::global(cx).read(cx).room().is_some();
1349
1350 let context_menu = ContextMenu::build(cx, |mut context_menu, _| {
1351 let user_id = contact.user.id;
1352
1353 if contact.online && !contact.busy {
1354 let label = if in_room {
1355 format!("Invite {} to join", contact.user.github_login)
1356 } else {
1357 format!("Call {}", contact.user.github_login)
1358 };
1359 context_menu = context_menu.entry(label, None, {
1360 let this = this.clone();
1361 move |cx| {
1362 this.update(cx, |this, cx| {
1363 this.call(user_id, cx);
1364 });
1365 }
1366 });
1367 }
1368
1369 context_menu.entry("Remove Contact", None, {
1370 let this = this.clone();
1371 move |cx| {
1372 this.update(cx, |this, cx| {
1373 this.remove_contact(contact.user.id, &contact.user.github_login, cx);
1374 });
1375 }
1376 })
1377 });
1378
1379 cx.focus_view(&context_menu);
1380 let subscription =
1381 cx.subscribe(&context_menu, |this, _, _: &DismissEvent, cx| {
1382 if this.context_menu.as_ref().is_some_and(|context_menu| {
1383 context_menu.0.focus_handle(cx).contains_focused(cx)
1384 }) {
1385 cx.focus_self();
1386 }
1387 this.context_menu.take();
1388 cx.notify();
1389 });
1390 self.context_menu = Some((context_menu, position, subscription));
1391
1392 cx.notify();
1393 }
1394
1395 fn cancel(&mut self, _: &Cancel, cx: &mut ViewContext<Self>) {
1396 if self.take_editing_state(cx) {
1397 cx.focus_view(&self.filter_editor);
1398 } else {
1399 self.filter_editor.update(cx, |editor, cx| {
1400 if editor.buffer().read(cx).len(cx) > 0 {
1401 editor.set_text("", cx);
1402 }
1403 });
1404 }
1405
1406 self.update_entries(false, cx);
1407 }
1408
1409 fn select_next(&mut self, _: &SelectNext, cx: &mut ViewContext<Self>) {
1410 let ix = self.selection.map_or(0, |ix| ix + 1);
1411 if ix < self.entries.len() {
1412 self.selection = Some(ix);
1413 }
1414
1415 if let Some(ix) = self.selection {
1416 self.scroll_to_item(ix)
1417 }
1418 cx.notify();
1419 }
1420
1421 fn select_prev(&mut self, _: &SelectPrev, cx: &mut ViewContext<Self>) {
1422 let ix = self.selection.take().unwrap_or(0);
1423 if ix > 0 {
1424 self.selection = Some(ix - 1);
1425 }
1426
1427 if let Some(ix) = self.selection {
1428 self.scroll_to_item(ix)
1429 }
1430 cx.notify();
1431 }
1432
1433 fn confirm(&mut self, _: &Confirm, cx: &mut ViewContext<Self>) {
1434 if self.confirm_channel_edit(cx) {
1435 return;
1436 }
1437
1438 if let Some(selection) = self.selection {
1439 if let Some(entry) = self.entries.get(selection) {
1440 match entry {
1441 ListEntry::Header(section) => match section {
1442 Section::ActiveCall => Self::leave_call(cx),
1443 Section::Channels => self.new_root_channel(cx),
1444 Section::Contacts => self.toggle_contact_finder(cx),
1445 Section::ContactRequests
1446 | Section::Online
1447 | Section::Offline
1448 | Section::ChannelInvites => {
1449 self.toggle_section_expanded(*section, cx);
1450 }
1451 },
1452 ListEntry::Contact { contact, calling } => {
1453 if contact.online && !contact.busy && !calling {
1454 self.call(contact.user.id, cx);
1455 }
1456 }
1457 ListEntry::ParticipantProject {
1458 project_id,
1459 host_user_id,
1460 ..
1461 } => {
1462 if let Some(workspace) = self.workspace.upgrade() {
1463 let app_state = workspace.read(cx).app_state().clone();
1464 workspace::join_remote_project(
1465 *project_id,
1466 *host_user_id,
1467 app_state,
1468 cx,
1469 )
1470 .detach_and_prompt_err(
1471 "Failed to join project",
1472 cx,
1473 |_, _| None,
1474 );
1475 }
1476 }
1477 ListEntry::ParticipantScreen { peer_id, .. } => {
1478 let Some(peer_id) = peer_id else {
1479 return;
1480 };
1481 if let Some(workspace) = self.workspace.upgrade() {
1482 workspace.update(cx, |workspace, cx| {
1483 workspace.open_shared_screen(*peer_id, cx)
1484 });
1485 }
1486 }
1487 ListEntry::Channel { channel, .. } => {
1488 let is_active = maybe!({
1489 let call_channel = ActiveCall::global(cx)
1490 .read(cx)
1491 .room()?
1492 .read(cx)
1493 .channel_id()?;
1494
1495 Some(call_channel == channel.id)
1496 })
1497 .unwrap_or(false);
1498 if is_active {
1499 self.open_channel_notes(channel.id, cx)
1500 } else {
1501 self.join_channel(channel.id, cx)
1502 }
1503 }
1504 ListEntry::ContactPlaceholder => self.toggle_contact_finder(cx),
1505 ListEntry::CallParticipant { user, peer_id, .. } => {
1506 if Some(user) == self.user_store.read(cx).current_user().as_ref() {
1507 Self::leave_call(cx);
1508 } else if let Some(peer_id) = peer_id {
1509 self.workspace
1510 .update(cx, |workspace, cx| workspace.follow(*peer_id, cx))
1511 .ok();
1512 }
1513 }
1514 ListEntry::IncomingRequest(user) => {
1515 self.respond_to_contact_request(user.id, true, cx)
1516 }
1517 ListEntry::ChannelInvite(channel) => {
1518 self.respond_to_channel_invite(channel.id, true, cx)
1519 }
1520 ListEntry::ChannelNotes { channel_id } => {
1521 self.open_channel_notes(*channel_id, cx)
1522 }
1523 ListEntry::ChannelChat { channel_id } => {
1524 self.join_channel_chat(*channel_id, cx)
1525 }
1526 ListEntry::HostedProject {
1527 id: _id,
1528 name: _name,
1529 } => {
1530 // todo()
1531 }
1532
1533 ListEntry::OutgoingRequest(_) => {}
1534 ListEntry::ChannelEditor { .. } => {}
1535 }
1536 }
1537 }
1538 }
1539
1540 fn insert_space(&mut self, _: &InsertSpace, cx: &mut ViewContext<Self>) {
1541 if self.channel_editing_state.is_some() {
1542 self.channel_name_editor.update(cx, |editor, cx| {
1543 editor.insert(" ", cx);
1544 });
1545 }
1546 }
1547
1548 fn confirm_channel_edit(&mut self, cx: &mut ViewContext<CollabPanel>) -> bool {
1549 if let Some(editing_state) = &mut self.channel_editing_state {
1550 match editing_state {
1551 ChannelEditingState::Create {
1552 location,
1553 pending_name,
1554 ..
1555 } => {
1556 if pending_name.is_some() {
1557 return false;
1558 }
1559 let channel_name = self.channel_name_editor.read(cx).text(cx);
1560
1561 *pending_name = Some(channel_name.clone());
1562
1563 self.channel_store
1564 .update(cx, |channel_store, cx| {
1565 channel_store.create_channel(&channel_name, *location, cx)
1566 })
1567 .detach();
1568 cx.notify();
1569 }
1570 ChannelEditingState::Rename {
1571 location,
1572 pending_name,
1573 } => {
1574 if pending_name.is_some() {
1575 return false;
1576 }
1577 let channel_name = self.channel_name_editor.read(cx).text(cx);
1578 *pending_name = Some(channel_name.clone());
1579
1580 self.channel_store
1581 .update(cx, |channel_store, cx| {
1582 channel_store.rename(*location, &channel_name, cx)
1583 })
1584 .detach();
1585 cx.notify();
1586 }
1587 }
1588 cx.focus_self();
1589 true
1590 } else {
1591 false
1592 }
1593 }
1594
1595 fn toggle_section_expanded(&mut self, section: Section, cx: &mut ViewContext<Self>) {
1596 if let Some(ix) = self.collapsed_sections.iter().position(|s| *s == section) {
1597 self.collapsed_sections.remove(ix);
1598 } else {
1599 self.collapsed_sections.push(section);
1600 }
1601 self.update_entries(false, cx);
1602 }
1603
1604 fn collapse_selected_channel(
1605 &mut self,
1606 _: &CollapseSelectedChannel,
1607 cx: &mut ViewContext<Self>,
1608 ) {
1609 let Some(channel_id) = self.selected_channel().map(|channel| channel.id) else {
1610 return;
1611 };
1612
1613 if self.is_channel_collapsed(channel_id) {
1614 return;
1615 }
1616
1617 self.toggle_channel_collapsed(channel_id, cx);
1618 }
1619
1620 fn expand_selected_channel(&mut self, _: &ExpandSelectedChannel, cx: &mut ViewContext<Self>) {
1621 let Some(id) = self.selected_channel().map(|channel| channel.id) else {
1622 return;
1623 };
1624
1625 if !self.is_channel_collapsed(id) {
1626 return;
1627 }
1628
1629 self.toggle_channel_collapsed(id, cx)
1630 }
1631
1632 fn toggle_channel_collapsed(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1633 match self.collapsed_channels.binary_search(&channel_id) {
1634 Ok(ix) => {
1635 self.collapsed_channels.remove(ix);
1636 }
1637 Err(ix) => {
1638 self.collapsed_channels.insert(ix, channel_id);
1639 }
1640 };
1641 self.serialize(cx);
1642 self.update_entries(true, cx);
1643 cx.notify();
1644 cx.focus_self();
1645 }
1646
1647 fn is_channel_collapsed(&self, channel_id: ChannelId) -> bool {
1648 self.collapsed_channels.binary_search(&channel_id).is_ok()
1649 }
1650
1651 fn leave_call(cx: &mut WindowContext) {
1652 ActiveCall::global(cx)
1653 .update(cx, |call, cx| call.hang_up(cx))
1654 .detach_and_prompt_err("Failed to hang up", cx, |_, _| None);
1655 }
1656
1657 fn toggle_contact_finder(&mut self, cx: &mut ViewContext<Self>) {
1658 if let Some(workspace) = self.workspace.upgrade() {
1659 workspace.update(cx, |workspace, cx| {
1660 workspace.toggle_modal(cx, |cx| {
1661 let mut finder = ContactFinder::new(self.user_store.clone(), cx);
1662 finder.set_query(self.filter_editor.read(cx).text(cx), cx);
1663 finder
1664 });
1665 });
1666 }
1667 }
1668
1669 fn new_root_channel(&mut self, cx: &mut ViewContext<Self>) {
1670 self.channel_editing_state = Some(ChannelEditingState::Create {
1671 location: None,
1672 pending_name: None,
1673 });
1674 self.update_entries(false, cx);
1675 self.select_channel_editor();
1676 cx.focus_view(&self.channel_name_editor);
1677 cx.notify();
1678 }
1679
1680 fn select_channel_editor(&mut self) {
1681 self.selection = self.entries.iter().position(|entry| match entry {
1682 ListEntry::ChannelEditor { .. } => true,
1683 _ => false,
1684 });
1685 }
1686
1687 fn new_subchannel(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1688 self.collapsed_channels
1689 .retain(|channel| *channel != channel_id);
1690 self.channel_editing_state = Some(ChannelEditingState::Create {
1691 location: Some(channel_id),
1692 pending_name: None,
1693 });
1694 self.update_entries(false, cx);
1695 self.select_channel_editor();
1696 cx.focus_view(&self.channel_name_editor);
1697 cx.notify();
1698 }
1699
1700 fn manage_members(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1701 self.show_channel_modal(channel_id, channel_modal::Mode::ManageMembers, cx);
1702 }
1703
1704 fn remove_selected_channel(&mut self, _: &Remove, cx: &mut ViewContext<Self>) {
1705 if let Some(channel) = self.selected_channel() {
1706 self.remove_channel(channel.id, cx)
1707 }
1708 }
1709
1710 fn rename_selected_channel(&mut self, _: &SecondaryConfirm, cx: &mut ViewContext<Self>) {
1711 if let Some(channel) = self.selected_channel() {
1712 self.rename_channel(channel.id, cx);
1713 }
1714 }
1715
1716 fn rename_channel(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1717 let channel_store = self.channel_store.read(cx);
1718 if !channel_store.is_channel_admin(channel_id) {
1719 return;
1720 }
1721 if let Some(channel) = channel_store.channel_for_id(channel_id).cloned() {
1722 self.channel_editing_state = Some(ChannelEditingState::Rename {
1723 location: channel_id,
1724 pending_name: None,
1725 });
1726 self.channel_name_editor.update(cx, |editor, cx| {
1727 editor.set_text(channel.name.clone(), cx);
1728 editor.select_all(&Default::default(), cx);
1729 });
1730 cx.focus_view(&self.channel_name_editor);
1731 self.update_entries(false, cx);
1732 self.select_channel_editor();
1733 }
1734 }
1735
1736 fn set_channel_visibility(
1737 &mut self,
1738 channel_id: ChannelId,
1739 visibility: ChannelVisibility,
1740 cx: &mut ViewContext<Self>,
1741 ) {
1742 self.channel_store
1743 .update(cx, |channel_store, cx| {
1744 channel_store.set_channel_visibility(channel_id, visibility, cx)
1745 })
1746 .detach_and_prompt_err("Failed to set channel visibility", cx, |e, _| match e.error_code() {
1747 ErrorCode::BadPublicNesting =>
1748 if e.error_tag("direction") == Some("parent") {
1749 Some("To make a channel public, its parent channel must be public.".to_string())
1750 } else {
1751 Some("To make a channel private, all of its subchannels must be private.".to_string())
1752 },
1753 _ => None
1754 });
1755 }
1756
1757 fn start_move_channel(&mut self, channel_id: ChannelId, _cx: &mut ViewContext<Self>) {
1758 self.channel_clipboard = Some(ChannelMoveClipboard { channel_id });
1759 }
1760
1761 fn start_move_selected_channel(&mut self, _: &StartMoveChannel, cx: &mut ViewContext<Self>) {
1762 if let Some(channel) = self.selected_channel() {
1763 self.start_move_channel(channel.id, cx);
1764 }
1765 }
1766
1767 fn move_channel_on_clipboard(
1768 &mut self,
1769 to_channel_id: ChannelId,
1770 cx: &mut ViewContext<CollabPanel>,
1771 ) {
1772 if let Some(clipboard) = self.channel_clipboard.take() {
1773 self.move_channel(clipboard.channel_id, to_channel_id, cx)
1774 }
1775 }
1776
1777 fn move_channel(&self, channel_id: ChannelId, to: ChannelId, cx: &mut ViewContext<Self>) {
1778 self.channel_store
1779 .update(cx, |channel_store, cx| {
1780 channel_store.move_channel(channel_id, to, cx)
1781 })
1782 .detach_and_prompt_err("Failed to move channel", cx, |e, _| match e.error_code() {
1783 ErrorCode::BadPublicNesting => {
1784 Some("Public channels must have public parents".into())
1785 }
1786 ErrorCode::CircularNesting => Some("You cannot move a channel into itself".into()),
1787 ErrorCode::WrongMoveTarget => {
1788 Some("You cannot move a channel into a different root channel".into())
1789 }
1790 _ => None,
1791 })
1792 }
1793
1794 fn open_channel_notes(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1795 if let Some(workspace) = self.workspace.upgrade() {
1796 ChannelView::open(channel_id, None, workspace, cx).detach();
1797 }
1798 }
1799
1800 fn show_inline_context_menu(&mut self, _: &menu::ShowContextMenu, cx: &mut ViewContext<Self>) {
1801 let Some(bounds) = self
1802 .selection
1803 .and_then(|ix| self.list_state.bounds_for_item(ix))
1804 else {
1805 return;
1806 };
1807
1808 if let Some(channel) = self.selected_channel() {
1809 self.deploy_channel_context_menu(
1810 bounds.center(),
1811 channel.id,
1812 self.selection.unwrap(),
1813 cx,
1814 );
1815 cx.stop_propagation();
1816 return;
1817 };
1818
1819 if let Some(contact) = self.selected_contact() {
1820 self.deploy_contact_context_menu(bounds.center(), contact, cx);
1821 cx.stop_propagation();
1822 return;
1823 };
1824 }
1825
1826 fn selected_channel(&self) -> Option<&Arc<Channel>> {
1827 self.selection
1828 .and_then(|ix| self.entries.get(ix))
1829 .and_then(|entry| match entry {
1830 ListEntry::Channel { channel, .. } => Some(channel),
1831 _ => None,
1832 })
1833 }
1834
1835 fn selected_contact(&self) -> Option<Arc<Contact>> {
1836 self.selection
1837 .and_then(|ix| self.entries.get(ix))
1838 .and_then(|entry| match entry {
1839 ListEntry::Contact { contact, .. } => Some(contact.clone()),
1840 _ => None,
1841 })
1842 }
1843
1844 fn show_channel_modal(
1845 &mut self,
1846 channel_id: ChannelId,
1847 mode: channel_modal::Mode,
1848 cx: &mut ViewContext<Self>,
1849 ) {
1850 let workspace = self.workspace.clone();
1851 let user_store = self.user_store.clone();
1852 let channel_store = self.channel_store.clone();
1853 let members = self.channel_store.update(cx, |channel_store, cx| {
1854 channel_store.get_channel_member_details(channel_id, cx)
1855 });
1856
1857 cx.spawn(|_, mut cx| async move {
1858 let members = members.await?;
1859 workspace.update(&mut cx, |workspace, cx| {
1860 workspace.toggle_modal(cx, |cx| {
1861 ChannelModal::new(
1862 user_store.clone(),
1863 channel_store.clone(),
1864 channel_id,
1865 mode,
1866 members,
1867 cx,
1868 )
1869 });
1870 })
1871 })
1872 .detach();
1873 }
1874
1875 fn leave_channel(&self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1876 let Some(user_id) = self.user_store.read(cx).current_user().map(|u| u.id) else {
1877 return;
1878 };
1879 let Some(channel) = self.channel_store.read(cx).channel_for_id(channel_id) else {
1880 return;
1881 };
1882 let prompt_message = format!("Are you sure you want to leave \"#{}\"?", channel.name);
1883 let answer = cx.prompt(
1884 PromptLevel::Warning,
1885 &prompt_message,
1886 None,
1887 &["Leave", "Cancel"],
1888 );
1889 cx.spawn(|this, mut cx| async move {
1890 if answer.await? != 0 {
1891 return Ok(());
1892 }
1893 this.update(&mut cx, |this, cx| {
1894 this.channel_store.update(cx, |channel_store, cx| {
1895 channel_store.remove_member(channel_id, user_id, cx)
1896 })
1897 })?
1898 .await
1899 })
1900 .detach_and_prompt_err("Failed to leave channel", cx, |_, _| None)
1901 }
1902
1903 fn remove_channel(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1904 let channel_store = self.channel_store.clone();
1905 if let Some(channel) = channel_store.read(cx).channel_for_id(channel_id) {
1906 let prompt_message = format!(
1907 "Are you sure you want to remove the channel \"{}\"?",
1908 channel.name
1909 );
1910 let answer = cx.prompt(
1911 PromptLevel::Warning,
1912 &prompt_message,
1913 None,
1914 &["Remove", "Cancel"],
1915 );
1916 cx.spawn(|this, mut cx| async move {
1917 if answer.await? == 0 {
1918 channel_store
1919 .update(&mut cx, |channels, _| channels.remove_channel(channel_id))?
1920 .await
1921 .notify_async_err(&mut cx);
1922 this.update(&mut cx, |_, cx| cx.focus_self()).ok();
1923 }
1924 anyhow::Ok(())
1925 })
1926 .detach();
1927 }
1928 }
1929
1930 fn remove_contact(&mut self, user_id: u64, github_login: &str, cx: &mut ViewContext<Self>) {
1931 let user_store = self.user_store.clone();
1932 let prompt_message = format!(
1933 "Are you sure you want to remove \"{}\" from your contacts?",
1934 github_login
1935 );
1936 let answer = cx.prompt(
1937 PromptLevel::Warning,
1938 &prompt_message,
1939 None,
1940 &["Remove", "Cancel"],
1941 );
1942 cx.spawn(|_, mut cx| async move {
1943 if answer.await? == 0 {
1944 user_store
1945 .update(&mut cx, |store, cx| store.remove_contact(user_id, cx))?
1946 .await
1947 .notify_async_err(&mut cx);
1948 }
1949 anyhow::Ok(())
1950 })
1951 .detach_and_prompt_err("Failed to remove contact", cx, |_, _| None);
1952 }
1953
1954 fn respond_to_contact_request(
1955 &mut self,
1956 user_id: u64,
1957 accept: bool,
1958 cx: &mut ViewContext<Self>,
1959 ) {
1960 self.user_store
1961 .update(cx, |store, cx| {
1962 store.respond_to_contact_request(user_id, accept, cx)
1963 })
1964 .detach_and_prompt_err("Failed to respond to contact request", cx, |_, _| None);
1965 }
1966
1967 fn respond_to_channel_invite(
1968 &mut self,
1969 channel_id: ChannelId,
1970 accept: bool,
1971 cx: &mut ViewContext<Self>,
1972 ) {
1973 self.channel_store
1974 .update(cx, |store, cx| {
1975 store.respond_to_channel_invite(channel_id, accept, cx)
1976 })
1977 .detach();
1978 }
1979
1980 fn call(&mut self, recipient_user_id: u64, cx: &mut ViewContext<Self>) {
1981 ActiveCall::global(cx)
1982 .update(cx, |call, cx| {
1983 call.invite(recipient_user_id, Some(self.project.clone()), cx)
1984 })
1985 .detach_and_prompt_err("Call failed", cx, |_, _| None);
1986 }
1987
1988 fn join_channel(&self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
1989 let Some(workspace) = self.workspace.upgrade() else {
1990 return;
1991 };
1992 let Some(handle) = cx.window_handle().downcast::<Workspace>() else {
1993 return;
1994 };
1995 workspace::join_channel(
1996 channel_id,
1997 workspace.read(cx).app_state().clone(),
1998 Some(handle),
1999 cx,
2000 )
2001 .detach_and_prompt_err("Failed to join channel", cx, |_, _| None)
2002 }
2003
2004 fn join_channel_chat(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
2005 let Some(workspace) = self.workspace.upgrade() else {
2006 return;
2007 };
2008 cx.window_context().defer(move |cx| {
2009 workspace.update(cx, |workspace, cx| {
2010 if let Some(panel) = workspace.focus_panel::<ChatPanel>(cx) {
2011 panel.update(cx, |panel, cx| {
2012 panel
2013 .select_channel(channel_id, None, cx)
2014 .detach_and_notify_err(cx);
2015 });
2016 }
2017 });
2018 });
2019 }
2020
2021 fn copy_channel_link(&mut self, channel_id: ChannelId, cx: &mut ViewContext<Self>) {
2022 let channel_store = self.channel_store.read(cx);
2023 let Some(channel) = channel_store.channel_for_id(channel_id) else {
2024 return;
2025 };
2026 let item = ClipboardItem::new(channel.link());
2027 cx.write_to_clipboard(item)
2028 }
2029
2030 fn render_signed_out(&mut self, cx: &mut ViewContext<Self>) -> Div {
2031 let collab_blurb = "Work with your team in realtime with collaborative editing, voice, shared notes and more.";
2032
2033 v_flex()
2034 .gap_6()
2035 .p_4()
2036 .child(Label::new(collab_blurb))
2037 .child(
2038 v_flex()
2039 .gap_2()
2040 .child(
2041 Button::new("sign_in", "Sign in")
2042 .icon_color(Color::Muted)
2043 .icon(IconName::Github)
2044 .icon_position(IconPosition::Start)
2045 .style(ButtonStyle::Filled)
2046 .full_width()
2047 .on_click(cx.listener(|this, _, cx| {
2048 let client = this.client.clone();
2049 cx.spawn(|_, mut cx| async move {
2050 client
2051 .authenticate_and_connect(true, &cx)
2052 .await
2053 .notify_async_err(&mut cx);
2054 })
2055 .detach()
2056 })),
2057 )
2058 .child(
2059 div().flex().w_full().items_center().child(
2060 Label::new("Sign in to enable collaboration.")
2061 .color(Color::Muted)
2062 .size(LabelSize::Small),
2063 ),
2064 ),
2065 )
2066 }
2067
2068 fn render_list_entry(&mut self, ix: usize, cx: &mut ViewContext<Self>) -> AnyElement {
2069 let entry = &self.entries[ix];
2070
2071 let is_selected = self.selection == Some(ix);
2072 match entry {
2073 ListEntry::Header(section) => {
2074 let is_collapsed = self.collapsed_sections.contains(section);
2075 self.render_header(*section, is_selected, is_collapsed, cx)
2076 .into_any_element()
2077 }
2078 ListEntry::Contact { contact, calling } => self
2079 .render_contact(contact, *calling, is_selected, cx)
2080 .into_any_element(),
2081 ListEntry::ContactPlaceholder => self
2082 .render_contact_placeholder(is_selected, cx)
2083 .into_any_element(),
2084 ListEntry::IncomingRequest(user) => self
2085 .render_contact_request(user, true, is_selected, cx)
2086 .into_any_element(),
2087 ListEntry::OutgoingRequest(user) => self
2088 .render_contact_request(user, false, is_selected, cx)
2089 .into_any_element(),
2090 ListEntry::Channel {
2091 channel,
2092 depth,
2093 has_children,
2094 } => self
2095 .render_channel(channel, *depth, *has_children, is_selected, ix, cx)
2096 .into_any_element(),
2097 ListEntry::ChannelEditor { depth } => {
2098 self.render_channel_editor(*depth, cx).into_any_element()
2099 }
2100 ListEntry::ChannelInvite(channel) => self
2101 .render_channel_invite(channel, is_selected, cx)
2102 .into_any_element(),
2103 ListEntry::CallParticipant {
2104 user,
2105 peer_id,
2106 is_pending,
2107 role,
2108 } => self
2109 .render_call_participant(user, *peer_id, *is_pending, *role, is_selected, cx)
2110 .into_any_element(),
2111 ListEntry::ParticipantProject {
2112 project_id,
2113 worktree_root_names,
2114 host_user_id,
2115 is_last,
2116 } => self
2117 .render_participant_project(
2118 *project_id,
2119 &worktree_root_names,
2120 *host_user_id,
2121 *is_last,
2122 is_selected,
2123 cx,
2124 )
2125 .into_any_element(),
2126 ListEntry::ParticipantScreen { peer_id, is_last } => self
2127 .render_participant_screen(*peer_id, *is_last, is_selected, cx)
2128 .into_any_element(),
2129 ListEntry::ChannelNotes { channel_id } => self
2130 .render_channel_notes(*channel_id, is_selected, cx)
2131 .into_any_element(),
2132 ListEntry::ChannelChat { channel_id } => self
2133 .render_channel_chat(*channel_id, is_selected, cx)
2134 .into_any_element(),
2135
2136 ListEntry::HostedProject { id, name } => self
2137 .render_channel_project(*id, name, is_selected, cx)
2138 .into_any_element(),
2139 }
2140 }
2141
2142 fn render_signed_in(&mut self, cx: &mut ViewContext<Self>) -> Div {
2143 v_flex()
2144 .size_full()
2145 .child(list(self.list_state.clone()).size_full())
2146 .child(
2147 v_flex()
2148 .child(div().mx_2().border_primary(cx).border_t())
2149 .child(
2150 v_flex()
2151 .p_2()
2152 .child(self.render_filter_input(&self.filter_editor, cx)),
2153 ),
2154 )
2155 }
2156
2157 fn render_filter_input(
2158 &self,
2159 editor: &View<Editor>,
2160 cx: &mut ViewContext<Self>,
2161 ) -> impl IntoElement {
2162 let settings = ThemeSettings::get_global(cx);
2163 let text_style = TextStyle {
2164 color: if editor.read(cx).read_only(cx) {
2165 cx.theme().colors().text_disabled
2166 } else {
2167 cx.theme().colors().text
2168 },
2169 font_family: settings.ui_font.family.clone(),
2170 font_features: settings.ui_font.features,
2171 font_size: rems(0.875).into(),
2172 font_weight: FontWeight::NORMAL,
2173 font_style: FontStyle::Normal,
2174 line_height: relative(1.3),
2175 background_color: None,
2176 underline: None,
2177 strikethrough: None,
2178 white_space: WhiteSpace::Normal,
2179 };
2180
2181 EditorElement::new(
2182 editor,
2183 EditorStyle {
2184 local_player: cx.theme().players().local(),
2185 text: text_style,
2186 ..Default::default()
2187 },
2188 )
2189 }
2190
2191 fn render_header(
2192 &self,
2193 section: Section,
2194 is_selected: bool,
2195 is_collapsed: bool,
2196 cx: &ViewContext<Self>,
2197 ) -> impl IntoElement {
2198 let mut channel_link = None;
2199 let mut channel_tooltip_text = None;
2200 let mut channel_icon = None;
2201
2202 let text = match section {
2203 Section::ActiveCall => {
2204 let channel_name = maybe!({
2205 let channel_id = ActiveCall::global(cx).read(cx).channel_id(cx)?;
2206
2207 let channel = self.channel_store.read(cx).channel_for_id(channel_id)?;
2208
2209 channel_link = Some(channel.link());
2210 (channel_icon, channel_tooltip_text) = match channel.visibility {
2211 proto::ChannelVisibility::Public => {
2212 (Some("icons/public.svg"), Some("Copy public channel link."))
2213 }
2214 proto::ChannelVisibility::Members => {
2215 (Some("icons/hash.svg"), Some("Copy private channel link."))
2216 }
2217 };
2218
2219 Some(channel.name.as_ref())
2220 });
2221
2222 if let Some(name) = channel_name {
2223 SharedString::from(name.to_string())
2224 } else {
2225 SharedString::from("Current Call")
2226 }
2227 }
2228 Section::ContactRequests => SharedString::from("Requests"),
2229 Section::Contacts => SharedString::from("Contacts"),
2230 Section::Channels => SharedString::from("Channels"),
2231 Section::ChannelInvites => SharedString::from("Invites"),
2232 Section::Online => SharedString::from("Online"),
2233 Section::Offline => SharedString::from("Offline"),
2234 };
2235
2236 let button = match section {
2237 Section::ActiveCall => channel_link.map(|channel_link| {
2238 let channel_link_copy = channel_link.clone();
2239 IconButton::new("channel-link", IconName::Copy)
2240 .icon_size(IconSize::Small)
2241 .size(ButtonSize::None)
2242 .visible_on_hover("section-header")
2243 .on_click(move |_, cx| {
2244 let item = ClipboardItem::new(channel_link_copy.clone());
2245 cx.write_to_clipboard(item)
2246 })
2247 .tooltip(|cx| Tooltip::text("Copy channel link", cx))
2248 .into_any_element()
2249 }),
2250 Section::Contacts => Some(
2251 IconButton::new("add-contact", IconName::Plus)
2252 .on_click(cx.listener(|this, _, cx| this.toggle_contact_finder(cx)))
2253 .tooltip(|cx| Tooltip::text("Search for new contact", cx))
2254 .into_any_element(),
2255 ),
2256 Section::Channels => Some(
2257 IconButton::new("add-channel", IconName::Plus)
2258 .on_click(cx.listener(|this, _, cx| this.new_root_channel(cx)))
2259 .tooltip(|cx| Tooltip::text("Create a channel", cx))
2260 .into_any_element(),
2261 ),
2262 _ => None,
2263 };
2264
2265 let can_collapse = match section {
2266 Section::ActiveCall | Section::Channels | Section::Contacts => false,
2267 Section::ChannelInvites
2268 | Section::ContactRequests
2269 | Section::Online
2270 | Section::Offline => true,
2271 };
2272
2273 h_flex().w_full().group("section-header").child(
2274 ListHeader::new(text)
2275 .when(can_collapse, |header| {
2276 header
2277 .toggle(Some(!is_collapsed))
2278 .on_toggle(cx.listener(move |this, _, cx| {
2279 this.toggle_section_expanded(section, cx);
2280 }))
2281 })
2282 .inset(true)
2283 .end_slot::<AnyElement>(button)
2284 .selected(is_selected),
2285 )
2286 }
2287
2288 fn render_contact(
2289 &self,
2290 contact: &Arc<Contact>,
2291 calling: bool,
2292 is_selected: bool,
2293 cx: &mut ViewContext<Self>,
2294 ) -> impl IntoElement {
2295 let online = contact.online;
2296 let busy = contact.busy || calling;
2297 let github_login = SharedString::from(contact.user.github_login.clone());
2298 let item = ListItem::new(github_login.clone())
2299 .indent_level(1)
2300 .indent_step_size(px(20.))
2301 .selected(is_selected)
2302 .child(
2303 h_flex()
2304 .w_full()
2305 .justify_between()
2306 .child(Label::new(github_login.clone()))
2307 .when(calling, |el| {
2308 el.child(Label::new("Calling").color(Color::Muted))
2309 })
2310 .when(!calling, |el| {
2311 el.child(
2312 IconButton::new("contact context menu", IconName::Ellipsis)
2313 .icon_color(Color::Muted)
2314 .visible_on_hover("")
2315 .on_click(cx.listener({
2316 let contact = contact.clone();
2317 move |this, event: &ClickEvent, cx| {
2318 this.deploy_contact_context_menu(
2319 event.down.position,
2320 contact.clone(),
2321 cx,
2322 );
2323 }
2324 })),
2325 )
2326 }),
2327 )
2328 .on_secondary_mouse_down(cx.listener({
2329 let contact = contact.clone();
2330 move |this, event: &MouseDownEvent, cx| {
2331 this.deploy_contact_context_menu(event.position, contact.clone(), cx);
2332 }
2333 }))
2334 .start_slot(
2335 // todo handle contacts with no avatar
2336 Avatar::new(contact.user.avatar_uri.clone())
2337 .indicator::<AvatarAvailabilityIndicator>(if online {
2338 Some(AvatarAvailabilityIndicator::new(match busy {
2339 true => ui::Availability::Busy,
2340 false => ui::Availability::Free,
2341 }))
2342 } else {
2343 None
2344 }),
2345 );
2346
2347 div()
2348 .id(github_login.clone())
2349 .group("")
2350 .child(item)
2351 .tooltip(move |cx| {
2352 let text = if !online {
2353 format!(" {} is offline", &github_login)
2354 } else if busy {
2355 format!(" {} is on a call", &github_login)
2356 } else {
2357 let room = ActiveCall::global(cx).read(cx).room();
2358 if room.is_some() {
2359 format!("Invite {} to join call", &github_login)
2360 } else {
2361 format!("Call {}", &github_login)
2362 }
2363 };
2364 Tooltip::text(text, cx)
2365 })
2366 }
2367
2368 fn render_contact_request(
2369 &self,
2370 user: &Arc<User>,
2371 is_incoming: bool,
2372 is_selected: bool,
2373 cx: &mut ViewContext<Self>,
2374 ) -> impl IntoElement {
2375 let github_login = SharedString::from(user.github_login.clone());
2376 let user_id = user.id;
2377 let is_response_pending = self.user_store.read(cx).is_contact_request_pending(&user);
2378 let color = if is_response_pending {
2379 Color::Muted
2380 } else {
2381 Color::Default
2382 };
2383
2384 let controls = if is_incoming {
2385 vec![
2386 IconButton::new("decline-contact", IconName::Close)
2387 .on_click(cx.listener(move |this, _, cx| {
2388 this.respond_to_contact_request(user_id, false, cx);
2389 }))
2390 .icon_color(color)
2391 .tooltip(|cx| Tooltip::text("Decline invite", cx)),
2392 IconButton::new("accept-contact", IconName::Check)
2393 .on_click(cx.listener(move |this, _, cx| {
2394 this.respond_to_contact_request(user_id, true, cx);
2395 }))
2396 .icon_color(color)
2397 .tooltip(|cx| Tooltip::text("Accept invite", cx)),
2398 ]
2399 } else {
2400 let github_login = github_login.clone();
2401 vec![IconButton::new("remove_contact", IconName::Close)
2402 .on_click(cx.listener(move |this, _, cx| {
2403 this.remove_contact(user_id, &github_login, cx);
2404 }))
2405 .icon_color(color)
2406 .tooltip(|cx| Tooltip::text("Cancel invite", cx))]
2407 };
2408
2409 ListItem::new(github_login.clone())
2410 .indent_level(1)
2411 .indent_step_size(px(20.))
2412 .selected(is_selected)
2413 .child(
2414 h_flex()
2415 .w_full()
2416 .justify_between()
2417 .child(Label::new(github_login.clone()))
2418 .child(h_flex().children(controls)),
2419 )
2420 .start_slot(Avatar::new(user.avatar_uri.clone()))
2421 }
2422
2423 fn render_channel_invite(
2424 &self,
2425 channel: &Arc<Channel>,
2426 is_selected: bool,
2427 cx: &mut ViewContext<Self>,
2428 ) -> ListItem {
2429 let channel_id = channel.id;
2430 let response_is_pending = self
2431 .channel_store
2432 .read(cx)
2433 .has_pending_channel_invite_response(&channel);
2434 let color = if response_is_pending {
2435 Color::Muted
2436 } else {
2437 Color::Default
2438 };
2439
2440 let controls = [
2441 IconButton::new("reject-invite", IconName::Close)
2442 .on_click(cx.listener(move |this, _, cx| {
2443 this.respond_to_channel_invite(channel_id, false, cx);
2444 }))
2445 .icon_color(color)
2446 .tooltip(|cx| Tooltip::text("Decline invite", cx)),
2447 IconButton::new("accept-invite", IconName::Check)
2448 .on_click(cx.listener(move |this, _, cx| {
2449 this.respond_to_channel_invite(channel_id, true, cx);
2450 }))
2451 .icon_color(color)
2452 .tooltip(|cx| Tooltip::text("Accept invite", cx)),
2453 ];
2454
2455 ListItem::new(("channel-invite", channel.id.0 as usize))
2456 .selected(is_selected)
2457 .child(
2458 h_flex()
2459 .w_full()
2460 .justify_between()
2461 .child(Label::new(channel.name.clone()))
2462 .child(h_flex().children(controls)),
2463 )
2464 .start_slot(
2465 Icon::new(IconName::Hash)
2466 .size(IconSize::Small)
2467 .color(Color::Muted),
2468 )
2469 }
2470
2471 fn render_contact_placeholder(
2472 &self,
2473 is_selected: bool,
2474 cx: &mut ViewContext<Self>,
2475 ) -> ListItem {
2476 ListItem::new("contact-placeholder")
2477 .child(Icon::new(IconName::Plus))
2478 .child(Label::new("Add a Contact"))
2479 .selected(is_selected)
2480 .on_click(cx.listener(|this, _, cx| this.toggle_contact_finder(cx)))
2481 }
2482
2483 fn render_channel(
2484 &self,
2485 channel: &Channel,
2486 depth: usize,
2487 has_children: bool,
2488 is_selected: bool,
2489 ix: usize,
2490 cx: &mut ViewContext<Self>,
2491 ) -> impl IntoElement {
2492 let channel_id = channel.id;
2493
2494 let is_active = maybe!({
2495 let call_channel = ActiveCall::global(cx)
2496 .read(cx)
2497 .room()?
2498 .read(cx)
2499 .channel_id()?;
2500 Some(call_channel == channel_id)
2501 })
2502 .unwrap_or(false);
2503 let channel_store = self.channel_store.read(cx);
2504 let is_public = channel_store
2505 .channel_for_id(channel_id)
2506 .map(|channel| channel.visibility)
2507 == Some(proto::ChannelVisibility::Public);
2508 let disclosed =
2509 has_children.then(|| self.collapsed_channels.binary_search(&channel.id).is_err());
2510
2511 let has_messages_notification = channel_store.has_new_messages(channel_id);
2512 let has_notes_notification = channel_store.has_channel_buffer_changed(channel_id);
2513
2514 const FACEPILE_LIMIT: usize = 3;
2515 let participants = self.channel_store.read(cx).channel_participants(channel_id);
2516
2517 let face_pile = if !participants.is_empty() {
2518 let extra_count = participants.len().saturating_sub(FACEPILE_LIMIT);
2519 let result = FacePile::new(
2520 participants
2521 .iter()
2522 .map(|user| Avatar::new(user.avatar_uri.clone()).into_any_element())
2523 .take(FACEPILE_LIMIT)
2524 .chain(if extra_count > 0 {
2525 Some(
2526 div()
2527 .ml_2()
2528 .child(Label::new(format!("+{extra_count}")))
2529 .into_any_element(),
2530 )
2531 } else {
2532 None
2533 })
2534 .collect::<SmallVec<_>>(),
2535 );
2536
2537 Some(result)
2538 } else {
2539 None
2540 };
2541
2542 let width = self.width.unwrap_or(px(240.));
2543 let root_id = channel.root_id();
2544
2545 div()
2546 .h_6()
2547 .id(channel_id.0 as usize)
2548 .group("")
2549 .flex()
2550 .w_full()
2551 .when(!channel.is_root_channel(), |el| {
2552 el.on_drag(channel.clone(), move |channel, cx| {
2553 cx.new_view(|_| DraggedChannelView {
2554 channel: channel.clone(),
2555 width,
2556 })
2557 })
2558 })
2559 .drag_over::<Channel>({
2560 move |style, dragged_channel: &Channel, cx| {
2561 if dragged_channel.root_id() == root_id {
2562 style.bg(cx.theme().colors().ghost_element_hover)
2563 } else {
2564 style
2565 }
2566 }
2567 })
2568 .on_drop(cx.listener(move |this, dragged_channel: &Channel, cx| {
2569 if dragged_channel.root_id() != root_id {
2570 return;
2571 }
2572 this.move_channel(dragged_channel.id, channel_id, cx);
2573 }))
2574 .child(
2575 ListItem::new(channel_id.0 as usize)
2576 // Add one level of depth for the disclosure arrow.
2577 .indent_level(depth + 1)
2578 .indent_step_size(px(20.))
2579 .selected(is_selected || is_active)
2580 .toggle(disclosed)
2581 .on_toggle(
2582 cx.listener(move |this, _, cx| {
2583 this.toggle_channel_collapsed(channel_id, cx)
2584 }),
2585 )
2586 .on_click(cx.listener(move |this, _, cx| {
2587 if is_active {
2588 this.open_channel_notes(channel_id, cx)
2589 } else {
2590 this.join_channel(channel_id, cx)
2591 }
2592 }))
2593 .on_secondary_mouse_down(cx.listener(
2594 move |this, event: &MouseDownEvent, cx| {
2595 this.deploy_channel_context_menu(event.position, channel_id, ix, cx)
2596 },
2597 ))
2598 .start_slot(
2599 div()
2600 .relative()
2601 .child(
2602 Icon::new(if is_public {
2603 IconName::Public
2604 } else {
2605 IconName::Hash
2606 })
2607 .size(IconSize::Small)
2608 .color(Color::Muted),
2609 )
2610 .children(has_notes_notification.then(|| {
2611 div()
2612 .w_1p5()
2613 .z_index(1)
2614 .absolute()
2615 .right(px(-1.))
2616 .top(px(-1.))
2617 .child(Indicator::dot().color(Color::Info))
2618 })),
2619 )
2620 .child(
2621 h_flex()
2622 .id(channel_id.0 as usize)
2623 .child(Label::new(channel.name.clone()))
2624 .children(face_pile.map(|face_pile| face_pile.p_1())),
2625 ),
2626 )
2627 .child(
2628 h_flex()
2629 .absolute()
2630 .right(rems(0.))
2631 .z_index(1)
2632 .h_full()
2633 .child(
2634 h_flex()
2635 .h_full()
2636 .gap_1()
2637 .px_1()
2638 .child(
2639 IconButton::new("channel_chat", IconName::MessageBubbles)
2640 .style(ButtonStyle::Filled)
2641 .shape(ui::IconButtonShape::Square)
2642 .icon_size(IconSize::Small)
2643 .icon_color(if has_messages_notification {
2644 Color::Default
2645 } else {
2646 Color::Muted
2647 })
2648 .on_click(cx.listener(move |this, _, cx| {
2649 this.join_channel_chat(channel_id, cx)
2650 }))
2651 .tooltip(|cx| Tooltip::text("Open channel chat", cx))
2652 .visible_on_hover(""),
2653 )
2654 .child(
2655 IconButton::new("channel_notes", IconName::File)
2656 .style(ButtonStyle::Filled)
2657 .shape(ui::IconButtonShape::Square)
2658 .icon_size(IconSize::Small)
2659 .icon_color(if has_notes_notification {
2660 Color::Default
2661 } else {
2662 Color::Muted
2663 })
2664 .on_click(cx.listener(move |this, _, cx| {
2665 this.open_channel_notes(channel_id, cx)
2666 }))
2667 .tooltip(|cx| Tooltip::text("Open channel notes", cx))
2668 .visible_on_hover(""),
2669 ),
2670 ),
2671 )
2672 .tooltip({
2673 let channel_store = self.channel_store.clone();
2674 move |cx| {
2675 cx.new_view(|_| JoinChannelTooltip {
2676 channel_store: channel_store.clone(),
2677 channel_id,
2678 has_notes_notification,
2679 })
2680 .into()
2681 }
2682 })
2683 }
2684
2685 fn render_channel_editor(&self, depth: usize, _cx: &mut ViewContext<Self>) -> impl IntoElement {
2686 let item = ListItem::new("channel-editor")
2687 .inset(false)
2688 // Add one level of depth for the disclosure arrow.
2689 .indent_level(depth + 1)
2690 .indent_step_size(px(20.))
2691 .start_slot(
2692 Icon::new(IconName::Hash)
2693 .size(IconSize::Small)
2694 .color(Color::Muted),
2695 );
2696
2697 if let Some(pending_name) = self
2698 .channel_editing_state
2699 .as_ref()
2700 .and_then(|state| state.pending_name())
2701 {
2702 item.child(Label::new(pending_name))
2703 } else {
2704 item.child(self.channel_name_editor.clone())
2705 }
2706 }
2707}
2708
2709fn render_tree_branch(is_last: bool, overdraw: bool, cx: &mut WindowContext) -> impl IntoElement {
2710 let rem_size = cx.rem_size();
2711 let line_height = cx.text_style().line_height_in_pixels(rem_size);
2712 let width = rem_size * 1.5;
2713 let thickness = px(1.);
2714 let color = cx.theme().colors().text;
2715
2716 canvas(move |bounds, cx| {
2717 let start_x = (bounds.left() + bounds.right() - thickness) / 2.;
2718 let start_y = (bounds.top() + bounds.bottom() - thickness) / 2.;
2719 let right = bounds.right();
2720 let top = bounds.top();
2721
2722 cx.paint_quad(fill(
2723 Bounds::from_corners(
2724 point(start_x, top),
2725 point(
2726 start_x + thickness,
2727 if is_last {
2728 start_y
2729 } else {
2730 bounds.bottom() + if overdraw { px(1.) } else { px(0.) }
2731 },
2732 ),
2733 ),
2734 color,
2735 ));
2736 cx.paint_quad(fill(
2737 Bounds::from_corners(point(start_x, start_y), point(right, start_y + thickness)),
2738 color,
2739 ));
2740 })
2741 .w(width)
2742 .h(line_height)
2743}
2744
2745impl Render for CollabPanel {
2746 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
2747 v_flex()
2748 .key_context("CollabPanel")
2749 .on_action(cx.listener(CollabPanel::cancel))
2750 .on_action(cx.listener(CollabPanel::select_next))
2751 .on_action(cx.listener(CollabPanel::select_prev))
2752 .on_action(cx.listener(CollabPanel::confirm))
2753 .on_action(cx.listener(CollabPanel::insert_space))
2754 .on_action(cx.listener(CollabPanel::remove_selected_channel))
2755 .on_action(cx.listener(CollabPanel::show_inline_context_menu))
2756 .on_action(cx.listener(CollabPanel::rename_selected_channel))
2757 .on_action(cx.listener(CollabPanel::collapse_selected_channel))
2758 .on_action(cx.listener(CollabPanel::expand_selected_channel))
2759 .on_action(cx.listener(CollabPanel::start_move_selected_channel))
2760 .track_focus(&self.focus_handle)
2761 .size_full()
2762 .child(if self.user_store.read(cx).current_user().is_none() {
2763 self.render_signed_out(cx)
2764 } else {
2765 self.render_signed_in(cx)
2766 })
2767 .children(self.context_menu.as_ref().map(|(menu, position, _)| {
2768 overlay()
2769 .position(*position)
2770 .anchor(gpui::AnchorCorner::TopLeft)
2771 .child(menu.clone())
2772 }))
2773 }
2774}
2775
2776impl EventEmitter<PanelEvent> for CollabPanel {}
2777
2778impl Panel for CollabPanel {
2779 fn position(&self, cx: &gpui::WindowContext) -> DockPosition {
2780 CollaborationPanelSettings::get_global(cx).dock
2781 }
2782
2783 fn position_is_valid(&self, position: DockPosition) -> bool {
2784 matches!(position, DockPosition::Left | DockPosition::Right)
2785 }
2786
2787 fn set_position(&mut self, position: DockPosition, cx: &mut ViewContext<Self>) {
2788 settings::update_settings_file::<CollaborationPanelSettings>(
2789 self.fs.clone(),
2790 cx,
2791 move |settings| settings.dock = Some(position),
2792 );
2793 }
2794
2795 fn size(&self, cx: &gpui::WindowContext) -> Pixels {
2796 self.width
2797 .unwrap_or_else(|| CollaborationPanelSettings::get_global(cx).default_width)
2798 }
2799
2800 fn set_size(&mut self, size: Option<Pixels>, cx: &mut ViewContext<Self>) {
2801 self.width = size;
2802 self.serialize(cx);
2803 cx.notify();
2804 }
2805
2806 fn icon(&self, cx: &gpui::WindowContext) -> Option<ui::IconName> {
2807 CollaborationPanelSettings::get_global(cx)
2808 .button
2809 .then(|| ui::IconName::Collab)
2810 }
2811
2812 fn icon_tooltip(&self, _cx: &WindowContext) -> Option<&'static str> {
2813 Some("Collab Panel")
2814 }
2815
2816 fn toggle_action(&self) -> Box<dyn gpui::Action> {
2817 Box::new(ToggleFocus)
2818 }
2819
2820 fn persistent_name() -> &'static str {
2821 "CollabPanel"
2822 }
2823}
2824
2825impl FocusableView for CollabPanel {
2826 fn focus_handle(&self, cx: &AppContext) -> gpui::FocusHandle {
2827 self.filter_editor.focus_handle(cx).clone()
2828 }
2829}
2830
2831impl PartialEq for ListEntry {
2832 fn eq(&self, other: &Self) -> bool {
2833 match self {
2834 ListEntry::Header(section_1) => {
2835 if let ListEntry::Header(section_2) = other {
2836 return section_1 == section_2;
2837 }
2838 }
2839 ListEntry::CallParticipant { user: user_1, .. } => {
2840 if let ListEntry::CallParticipant { user: user_2, .. } = other {
2841 return user_1.id == user_2.id;
2842 }
2843 }
2844 ListEntry::ParticipantProject {
2845 project_id: project_id_1,
2846 ..
2847 } => {
2848 if let ListEntry::ParticipantProject {
2849 project_id: project_id_2,
2850 ..
2851 } = other
2852 {
2853 return project_id_1 == project_id_2;
2854 }
2855 }
2856 ListEntry::ParticipantScreen {
2857 peer_id: peer_id_1, ..
2858 } => {
2859 if let ListEntry::ParticipantScreen {
2860 peer_id: peer_id_2, ..
2861 } = other
2862 {
2863 return peer_id_1 == peer_id_2;
2864 }
2865 }
2866 ListEntry::Channel {
2867 channel: channel_1, ..
2868 } => {
2869 if let ListEntry::Channel {
2870 channel: channel_2, ..
2871 } = other
2872 {
2873 return channel_1.id == channel_2.id;
2874 }
2875 }
2876 ListEntry::HostedProject { id, .. } => {
2877 if let ListEntry::HostedProject { id: other_id, .. } = other {
2878 return id == other_id;
2879 }
2880 }
2881 ListEntry::ChannelNotes { channel_id } => {
2882 if let ListEntry::ChannelNotes {
2883 channel_id: other_id,
2884 } = other
2885 {
2886 return channel_id == other_id;
2887 }
2888 }
2889 ListEntry::ChannelChat { channel_id } => {
2890 if let ListEntry::ChannelChat {
2891 channel_id: other_id,
2892 } = other
2893 {
2894 return channel_id == other_id;
2895 }
2896 }
2897 ListEntry::ChannelInvite(channel_1) => {
2898 if let ListEntry::ChannelInvite(channel_2) = other {
2899 return channel_1.id == channel_2.id;
2900 }
2901 }
2902 ListEntry::IncomingRequest(user_1) => {
2903 if let ListEntry::IncomingRequest(user_2) = other {
2904 return user_1.id == user_2.id;
2905 }
2906 }
2907 ListEntry::OutgoingRequest(user_1) => {
2908 if let ListEntry::OutgoingRequest(user_2) = other {
2909 return user_1.id == user_2.id;
2910 }
2911 }
2912 ListEntry::Contact {
2913 contact: contact_1, ..
2914 } => {
2915 if let ListEntry::Contact {
2916 contact: contact_2, ..
2917 } = other
2918 {
2919 return contact_1.user.id == contact_2.user.id;
2920 }
2921 }
2922 ListEntry::ChannelEditor { depth } => {
2923 if let ListEntry::ChannelEditor { depth: other_depth } = other {
2924 return depth == other_depth;
2925 }
2926 }
2927 ListEntry::ContactPlaceholder => {
2928 if let ListEntry::ContactPlaceholder = other {
2929 return true;
2930 }
2931 }
2932 }
2933 false
2934 }
2935}
2936
2937struct DraggedChannelView {
2938 channel: Channel,
2939 width: Pixels,
2940}
2941
2942impl Render for DraggedChannelView {
2943 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
2944 let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
2945 h_flex()
2946 .font(ui_font)
2947 .bg(cx.theme().colors().background)
2948 .w(self.width)
2949 .p_1()
2950 .gap_1()
2951 .child(
2952 Icon::new(
2953 if self.channel.visibility == proto::ChannelVisibility::Public {
2954 IconName::Public
2955 } else {
2956 IconName::Hash
2957 },
2958 )
2959 .size(IconSize::Small)
2960 .color(Color::Muted),
2961 )
2962 .child(Label::new(self.channel.name.clone()))
2963 }
2964}
2965
2966struct JoinChannelTooltip {
2967 channel_store: Model<ChannelStore>,
2968 channel_id: ChannelId,
2969 has_notes_notification: bool,
2970}
2971
2972impl Render for JoinChannelTooltip {
2973 fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
2974 tooltip_container(cx, |container, cx| {
2975 let participants = self
2976 .channel_store
2977 .read(cx)
2978 .channel_participants(self.channel_id);
2979
2980 container
2981 .child(Label::new("Join channel"))
2982 .children(self.has_notes_notification.then(|| {
2983 h_flex()
2984 .gap_2()
2985 .child(Indicator::dot().color(Color::Info))
2986 .child(Label::new("Unread notes"))
2987 }))
2988 .children(participants.iter().map(|participant| {
2989 h_flex()
2990 .gap_2()
2991 .child(Avatar::new(participant.avatar_uri.clone()))
2992 .child(Label::new(participant.github_login.clone()))
2993 }))
2994 })
2995 }
2996}