Add collaborators to collaborator list, including self user

This commit is contained in:
Julia 2023-01-30 23:55:13 -05:00
parent bf8658067f
commit 99236f1875
2 changed files with 33 additions and 18 deletions

View file

@ -269,20 +269,23 @@ impl CollabTitlebarItem {
match self.collaborator_list_popover.take() {
Some(_) => {}
None => {
let view = cx.add_view(|cx| CollaboratorListPopover::new(cx));
if let Some(workspace) = self.workspace.upgrade(cx) {
let user_store = workspace.read(cx).user_store().clone();
let view = cx.add_view(|cx| CollaboratorListPopover::new(user_store, cx));
cx.subscribe(&view, |this, _, event, cx| {
match event {
collaborator_list_popover::Event::Dismissed => {
this.collaborator_list_popover = None;
cx.subscribe(&view, |this, _, event, cx| {
match event {
collaborator_list_popover::Event::Dismissed => {
this.collaborator_list_popover = None;
}
}
}
cx.notify();
})
.detach();
cx.notify();
})
.detach();
self.collaborator_list_popover = Some(view);
self.collaborator_list_popover = Some(view);
}
}
}
cx.notify();

View file

@ -1,5 +1,6 @@
use call::ActiveCall;
use gpui::{elements::*, Entity, MouseButton, RenderContext, View, ViewContext};
use client::UserStore;
use gpui::{elements::*, Entity, ModelHandle, MouseButton, RenderContext, View, ViewContext};
use settings::Settings;
use crate::collab_titlebar_item::ToggleCollaboratorList;
@ -45,22 +46,33 @@ impl View for CollaboratorListPopover {
}
impl CollaboratorListPopover {
pub fn new(cx: &mut ViewContext<Self>) -> Self {
pub fn new(user_store: ModelHandle<UserStore>, cx: &mut ViewContext<Self>) -> Self {
let active_call = ActiveCall::global(cx);
let collaborator_count = active_call
let mut collaborators = user_store
.read(cx)
.room()
.map_or(0, |room| room.read(cx).remote_participants().len());
.current_user()
.map(|u| u.github_login.clone())
.into_iter()
.collect::<Vec<_>>();
//TODO: What should the canonical sort here look like, consult contacts list implementation
if let Some(room) = active_call.read(cx).room() {
for participant in room.read(cx).remote_participants() {
collaborators.push(participant.1.user.github_login.clone());
}
}
Self {
list_state: ListState::new(
collaborator_count,
collaborators.len(),
Orientation::Top,
0.,
cx,
|_, index, cx| {
move |_, index, cx| {
let theme = &cx.global::<Settings>().theme;
Label::new(
format!("Participant {index}"),
collaborators[index].clone(),
theme.contact_list.contact_username.text.clone(),
)
.boxed()