link to channel notes (#3167)

Release Notes:

- Add links to channel notes
This commit is contained in:
Conrad Irwin 2023-10-25 15:53:34 +02:00 committed by GitHub
commit 4f859e0253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 22 deletions

View file

@ -35,9 +35,9 @@ use gpui::{
CursorStyle, ModifiersChangedEvent, MouseButton, PathPromptOptions, Platform, PromptLevel, CursorStyle, ModifiersChangedEvent, MouseButton, PathPromptOptions, Platform, PromptLevel,
WindowBounds, WindowOptions, WindowBounds, WindowOptions,
}, },
AnyModelHandle, AnyViewHandle, AnyWeakViewHandle, AnyWindowHandle, AppContext, AsyncAppContext, AnyModelHandle, AnyViewHandle, AnyWeakViewHandle, AppContext, AsyncAppContext, Entity,
Entity, ModelContext, ModelHandle, SizeConstraint, Subscription, Task, View, ViewContext, ModelContext, ModelHandle, SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle,
ViewHandle, WeakViewHandle, WindowContext, WindowHandle, WeakViewHandle, WindowContext, WindowHandle,
}; };
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem}; use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
use itertools::Itertools; use itertools::Itertools;
@ -4299,12 +4299,14 @@ pub fn join_channel(
} }
if let Err(err) = result { if let Err(err) = result {
let prompt = active_window.unwrap().prompt( let prompt = active_window.unwrap().update(&mut cx, |_, cx| {
cx.prompt(
PromptLevel::Critical, PromptLevel::Critical,
&format!("Failed to join channel: {}", err), &format!("Failed to join channel: {}", err),
&["Ok"], &["Ok"],
&mut cx, )
); });
if let Some(mut prompt) = prompt { if let Some(mut prompt) = prompt {
prompt.next().await; prompt.next().await;
} else { } else {
@ -4317,17 +4319,39 @@ pub fn join_channel(
}) })
} }
pub fn activate_any_workspace_window(cx: &mut AsyncAppContext) -> Option<AnyWindowHandle> { pub async fn get_any_active_workspace(
for window in cx.windows() { app_state: Arc<AppState>,
let found = window.update(cx, |cx| { mut cx: AsyncAppContext,
let is_workspace = cx.root_view().clone().downcast::<Workspace>().is_some(); ) -> Result<ViewHandle<Workspace>> {
if is_workspace { // find an existing workspace to focus and show call controls
cx.activate_window(); let active_window = activate_any_workspace_window(&mut cx);
if active_window.is_none() {
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), None, cx))
.await;
} }
is_workspace
}); let Some(active_window) = activate_any_workspace_window(&mut cx) else {
if found == Some(true) { return Err(anyhow!("could not open zed"))?;
return Some(window); };
Ok(active_window)
}
pub fn activate_any_workspace_window(cx: &mut AsyncAppContext) -> Option<ViewHandle<Workspace>> {
for window in cx.windows() {
if let Some(workspace) = window
.update(cx, |cx| {
cx.root_view()
.clone()
.downcast::<Workspace>()
.map(|workspace| {
cx.activate_window();
workspace
})
})
.flatten()
{
return Some(workspace);
} }
} }
None None

View file

@ -7,6 +7,7 @@ use cli::FORCE_CLI_MODE_ENV_VAR_NAME;
use client::{ use client::{
self, Client, TelemetrySettings, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN, self, Client, TelemetrySettings, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN,
}; };
use collab_ui::channel_view::ChannelView;
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use editor::Editor; use editor::Editor;
use futures::StreamExt; use futures::StreamExt;
@ -240,6 +241,20 @@ fn main() {
}) })
.detach_and_log_err(cx) .detach_and_log_err(cx)
} }
Ok(Some(OpenRequest::OpenChannelNotes { channel_id })) => {
triggered_authentication = true;
let app_state = app_state.clone();
let client = client.clone();
cx.spawn(|mut cx| async move {
// ignore errors here, we'll show a generic "not signed in"
let _ = authenticate(client, &cx).await;
let workspace =
workspace::get_any_active_workspace(app_state, cx.clone()).await?;
cx.update(|cx| ChannelView::open(channel_id, workspace, cx))
.await
})
.detach_and_log_err(cx)
}
Ok(None) | Err(_) => cx Ok(None) | Err(_) => cx
.spawn({ .spawn({
let app_state = app_state.clone(); let app_state = app_state.clone();
@ -254,7 +269,9 @@ fn main() {
while let Some(request) = open_rx.next().await { while let Some(request) = open_rx.next().await {
match request { match request {
OpenRequest::Paths { paths } => { OpenRequest::Paths { paths } => {
cx.update(|cx| workspace::open_paths(&paths, &app_state, None, cx)) cx.update(|cx| {
workspace::open_paths(&paths, &app_state.clone(), None, cx)
})
.detach(); .detach();
} }
OpenRequest::CliConnection { connection } => { OpenRequest::CliConnection { connection } => {
@ -266,6 +283,16 @@ fn main() {
workspace::join_channel(channel_id, app_state.clone(), None, cx) workspace::join_channel(channel_id, app_state.clone(), None, cx)
}) })
.detach(), .detach(),
OpenRequest::OpenChannelNotes { channel_id } => {
let app_state = app_state.clone();
if let Ok(workspace) =
workspace::get_any_active_workspace(app_state, cx.clone()).await
{
cx.update(|cx| {
ChannelView::open(channel_id, workspace, cx).detach();
})
}
}
} }
} }
} }

View file

@ -32,6 +32,9 @@ pub enum OpenRequest {
JoinChannel { JoinChannel {
channel_id: u64, channel_id: u64,
}, },
OpenChannelNotes {
channel_id: u64,
},
} }
pub struct OpenListener { pub struct OpenListener {
@ -85,11 +88,15 @@ impl OpenListener {
if let Some(slug) = parts.next() { if let Some(slug) = parts.next() {
if let Some(id_str) = slug.split("-").last() { if let Some(id_str) = slug.split("-").last() {
if let Ok(channel_id) = id_str.parse::<u64>() { if let Ok(channel_id) = id_str.parse::<u64>() {
if Some("notes") == parts.next() {
return Some(OpenRequest::OpenChannelNotes { channel_id });
} else {
return Some(OpenRequest::JoinChannel { channel_id }); return Some(OpenRequest::JoinChannel { channel_id });
} }
} }
} }
} }
}
log::error!("invalid zed url: {}", request_path); log::error!("invalid zed url: {}", request_path);
None None
} }