From f53a1ee46d617d5473f3f8e5e196169723e34100 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 11 Sep 2023 13:44:41 -0700 Subject: [PATCH] Put channel call participants back in channel row Open both the channel notes and the channel chat when clicking a channel --- crates/channel/src/channel_store.rs | 42 +++--- crates/collab_ui/src/channel_view.rs | 2 +- crates/collab_ui/src/chat_panel.rs | 35 +++-- crates/collab_ui/src/collab_panel.rs | 217 ++++++++------------------- 4 files changed, 109 insertions(+), 187 deletions(-) diff --git a/crates/channel/src/channel_store.rs b/crates/channel/src/channel_store.rs index bdfc75e814..b90a3fdaeb 100644 --- a/crates/channel/src/channel_store.rs +++ b/crates/channel/src/channel_store.rs @@ -196,10 +196,15 @@ impl ChannelStore { ) } + /// Asynchronously open a given resource associated with a channel. + /// + /// Make sure that the resource is only opened once, even if this method + /// is called multiple times with the same channel id while the first task + /// is still running. fn open_channel_resource( &mut self, channel_id: ChannelId, - map: fn(&mut Self) -> &mut HashMap>, + get_map: fn(&mut Self) -> &mut HashMap>, load: F, cx: &mut ModelContext, ) -> Task>> @@ -207,21 +212,20 @@ impl ChannelStore { F: 'static + FnOnce(Arc, AsyncAppContext) -> Fut, Fut: Future>>, { - // Make sure that a given channel resource is only opened once per - // app instance, even if this method is called multiple times - // with the same channel id while the first task is still running. let task = loop { - match map(self).entry(channel_id) { + match get_map(self).entry(channel_id) { hash_map::Entry::Occupied(e) => match e.get() { - OpenedModelHandle::Open(buffer) => { - if let Some(buffer) = buffer.upgrade(cx) { - break Task::ready(Ok(buffer)).shared(); + OpenedModelHandle::Open(model) => { + if let Some(model) = model.upgrade(cx) { + break Task::ready(Ok(model)).shared(); } else { - map(self).remove(&channel_id); + get_map(self).remove(&channel_id); continue; } } - OpenedModelHandle::Loading(task) => break task.clone(), + OpenedModelHandle::Loading(task) => { + break task.clone(); + } }, hash_map::Entry::Vacant(e) => { let task = cx @@ -235,25 +239,21 @@ impl ChannelStore { load(channel, cx).await.map_err(Arc::new) }) .shared(); + e.insert(OpenedModelHandle::Loading(task.clone())); cx.spawn({ let task = task.clone(); |this, mut cx| async move { let result = task.await; - this.update(&mut cx, |this, cx| match result { - Ok(buffer) => { - cx.observe_release(&buffer, move |this, _, _| { - this.opened_buffers.remove(&channel_id); - }) - .detach(); - map(this).insert( + this.update(&mut cx, |this, _| match result { + Ok(model) => { + get_map(this).insert( channel_id, - OpenedModelHandle::Open(buffer.downgrade()), + OpenedModelHandle::Open(model.downgrade()), ); } - Err(error) => { - log::error!("failed to open channel buffer {error:?}"); - map(this).remove(&channel_id); + Err(_) => { + get_map(this).remove(&channel_id); } }); } diff --git a/crates/collab_ui/src/channel_view.rs b/crates/collab_ui/src/channel_view.rs index e303111bd4..8bcfad68b3 100644 --- a/crates/collab_ui/src/channel_view.rs +++ b/crates/collab_ui/src/channel_view.rs @@ -53,6 +53,7 @@ impl ChannelView { cx.spawn(|mut cx| async move { let channel_buffer = channel_buffer.await?; + let markdown = markdown.await?; channel_buffer.update(&mut cx, |buffer, cx| { buffer.buffer().update(cx, |buffer, cx| { @@ -75,7 +76,6 @@ impl ChannelView { cx: &mut ViewContext, ) -> Self { let buffer = channel_buffer.read(cx).buffer(); - // buffer.update(cx, |buffer, cx| buffer.set_language(language, cx)); let editor = cx.add_view(|cx| Editor::for_buffer(buffer, None, cx)); let _editor_event_subscription = cx.subscribe(&editor, |_, _, e, cx| cx.emit(e.clone())); diff --git a/crates/collab_ui/src/chat_panel.rs b/crates/collab_ui/src/chat_panel.rs index 9985f0d05b..ba0d196e8d 100644 --- a/crates/collab_ui/src/chat_panel.rs +++ b/crates/collab_ui/src/chat_panel.rs @@ -33,7 +33,7 @@ const CHAT_PANEL_KEY: &'static str = "ChatPanel"; pub struct ChatPanel { client: Arc, channel_store: ModelHandle, - active_channel: Option<(ModelHandle, Subscription)>, + active_chat: Option<(ModelHandle, Subscription)>, message_list: ListState, input_editor: ViewHandle, channel_select: ViewHandle