Show guests in fewer places

This commit is contained in:
Conrad Irwin 2024-01-03 14:44:09 -07:00
parent c3402024bc
commit 1930258d39
7 changed files with 100 additions and 26 deletions

View file

@ -172,7 +172,7 @@ impl ChannelView {
cx.notify();
}),
ChannelBufferEvent::ChannelChanged => {
self.editor.update(cx, |editor, cx| {
self.editor.update(cx, |_, cx| {
cx.emit(editor::EditorEvent::TitleChanged);
cx.notify()
});

View file

@ -151,6 +151,9 @@ enum ListEntry {
peer_id: Option<PeerId>,
is_last: bool,
},
GuestCount {
count: usize,
},
IncomingRequest(Arc<User>),
OutgoingRequest(Arc<User>),
ChannelInvite(Arc<Channel>),
@ -380,10 +383,13 @@ impl CollabPanel {
if !self.collapsed_sections.contains(&Section::ActiveCall) {
let room = room.read(cx);
let mut guest_count_ix = 0;
let mut guest_count = if room.read_only() { 1 } else { 0 };
if let Some(channel_id) = room.channel_id() {
self.entries.push(ListEntry::ChannelNotes { channel_id });
self.entries.push(ListEntry::ChannelChat { channel_id })
self.entries.push(ListEntry::ChannelChat { channel_id });
guest_count_ix = self.entries.len();
}
// Populate the active user.
@ -402,7 +408,7 @@ impl CollabPanel {
&Default::default(),
executor.clone(),
));
if !matches.is_empty() {
if !matches.is_empty() && !room.read_only() {
let user_id = user.id;
self.entries.push(ListEntry::CallParticipant {
user,
@ -430,13 +436,21 @@ impl CollabPanel {
// Populate remote participants.
self.match_candidates.clear();
self.match_candidates
.extend(room.remote_participants().iter().map(|(_, participant)| {
StringMatchCandidate {
id: participant.user.id as usize,
string: participant.user.github_login.clone(),
char_bag: participant.user.github_login.chars().collect(),
}
}));
.extend(
room.remote_participants()
.iter()
.filter_map(|(_, participant)| {
if participant.role == proto::ChannelRole::Guest {
guest_count += 1;
return None;
}
Some(StringMatchCandidate {
id: participant.user.id as usize,
string: participant.user.github_login.clone(),
char_bag: participant.user.github_login.chars().collect(),
})
}),
);
let matches = executor.block(match_strings(
&self.match_candidates,
&query,
@ -470,6 +484,10 @@ impl CollabPanel {
});
}
}
if guest_count > 0 {
self.entries
.insert(guest_count_ix, ListEntry::GuestCount { count: guest_count });
}
// Populate pending participants.
self.match_candidates.clear();
@ -959,6 +977,34 @@ impl CollabPanel {
.tooltip(move |cx| Tooltip::text("Open Chat", cx))
}
fn render_guest_count(
&self,
count: usize,
is_selected: bool,
cx: &mut ViewContext<Self>,
) -> impl IntoElement {
// TODO! disable manage_members for guests.
ListItem::new("guest_count")
.selected(is_selected)
.on_click(cx.listener(move |this, _, cx| {
if let Some(channel_id) = ActiveCall::global(cx).read(cx).channel_id(cx) {
this.manage_members(channel_id, cx)
}
}))
.start_slot(
h_stack()
.gap_1()
.child(render_tree_branch(false, cx))
.child(""),
)
.child(Label::new(if count == 1 {
format!("{} guest", count)
} else {
format!("{} guests", count)
}))
.tooltip(move |cx| Tooltip::text("Manage Members", cx))
}
fn has_subchannels(&self, ix: usize) -> bool {
self.entries.get(ix).map_or(false, |entry| {
if let ListEntry::Channel { has_children, .. } = entry {
@ -1180,6 +1226,11 @@ impl CollabPanel {
});
}
}
ListEntry::GuestCount { .. } => {
if let Some(channel_id) = ActiveCall::global(cx).read(cx).channel_id(cx) {
self.manage_members(channel_id, cx)
}
}
ListEntry::Channel { channel, .. } => {
let is_active = maybe!({
let call_channel = ActiveCall::global(cx)
@ -1735,6 +1786,9 @@ impl CollabPanel {
ListEntry::ParticipantScreen { peer_id, is_last } => self
.render_participant_screen(*peer_id, *is_last, is_selected, cx)
.into_any_element(),
ListEntry::GuestCount { count } => self
.render_guest_count(*count, is_selected, cx)
.into_any_element(),
ListEntry::ChannelNotes { channel_id } => self
.render_channel_notes(*channel_id, is_selected, cx)
.into_any_element(),
@ -2504,6 +2558,11 @@ impl PartialEq for ListEntry {
return true;
}
}
ListEntry::GuestCount { .. } => {
if let ListEntry::GuestCount { .. } = other {
return true;
}
}
}
false
}

View file

@ -10,6 +10,7 @@ use gpui::{
};
use project::{Project, RepositoryEntry};
use recent_projects::RecentProjects;
use rpc::proto;
use std::sync::Arc;
use theme::{ActiveTheme, PlayerColors};
use ui::{
@ -173,9 +174,9 @@ impl Render for CollabTitlebarItem {
let is_muted = room.is_muted(cx);
let is_deafened = room.is_deafened().unwrap_or(false);
let is_screen_sharing = room.is_screen_sharing();
let can_publish = room.can_publish();
let read_only = room.read_only();
this.when(is_local && can_publish, |this| {
this.when(is_local && !read_only, |this| {
this.child(
Button::new(
"toggle_sharing",
@ -204,7 +205,7 @@ impl Render for CollabTitlebarItem {
.detach_and_log_err(cx);
}),
)
.when(can_publish, |this| {
.when(!read_only, |this| {
this.child(
IconButton::new(
"mute-microphone",
@ -233,7 +234,7 @@ impl Render for CollabTitlebarItem {
.icon_size(IconSize::Small)
.selected(is_deafened)
.tooltip(move |cx| {
if can_publish {
if !read_only {
Tooltip::with_meta(
"Deafen Audio",
None,
@ -246,7 +247,7 @@ impl Render for CollabTitlebarItem {
})
.on_click(move |_, cx| crate::toggle_deafen(&Default::default(), cx)),
)
.when(can_publish, |this| {
.when(!read_only, |this| {
this.child(
IconButton::new("screen-share", ui::Icon::Screen)
.style(ButtonStyle::Subtle)
@ -420,6 +421,10 @@ impl CollabTitlebarItem {
project_id: Option<u64>,
current_user: &Arc<User>,
) -> Option<FacePile> {
if room.role_for_user(user.id) == Some(proto::ChannelRole::Guest) {
return None;
}
let followers = project_id.map_or(&[] as &[_], |id| room.followers_for(peer_id, id));
let pile = FacePile::default()