Fix prevention of cross-channel joins
Co-Authored-By: Max <max@zed.dev>
This commit is contained in:
parent
3541dd8a6d
commit
ed76315387
4 changed files with 54 additions and 42 deletions
|
@ -88,7 +88,7 @@ impl std::fmt::Display for Error {
|
||||||
|
|
||||||
impl std::error::Error for Error {}
|
impl std::error::Error for Error {}
|
||||||
|
|
||||||
#[derive(Default, Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub http_port: u16,
|
pub http_port: u16,
|
||||||
pub database_url: String,
|
pub database_url: String,
|
||||||
|
@ -100,7 +100,7 @@ pub struct Config {
|
||||||
pub live_kit_secret: Option<String>,
|
pub live_kit_secret: Option<String>,
|
||||||
pub rust_log: Option<String>,
|
pub rust_log: Option<String>,
|
||||||
pub log_json: Option<bool>,
|
pub log_json: Option<bool>,
|
||||||
pub zed_environment: String,
|
pub zed_environment: Arc<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Deserialize)]
|
#[derive(Default, Deserialize)]
|
||||||
|
|
|
@ -104,6 +104,7 @@ impl<R: RequestMessage> Response<R> {
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct Session {
|
struct Session {
|
||||||
|
zed_environment: Arc<str>,
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
connection_id: ConnectionId,
|
connection_id: ConnectionId,
|
||||||
db: Arc<tokio::sync::Mutex<DbHandle>>,
|
db: Arc<tokio::sync::Mutex<DbHandle>>,
|
||||||
|
@ -609,6 +610,7 @@ impl Server {
|
||||||
user_id,
|
user_id,
|
||||||
connection_id,
|
connection_id,
|
||||||
db: Arc::new(tokio::sync::Mutex::new(DbHandle(this.app_state.db.clone()))),
|
db: Arc::new(tokio::sync::Mutex::new(DbHandle(this.app_state.db.clone()))),
|
||||||
|
zed_environment: this.app_state.config.zed_environment.clone(),
|
||||||
peer: this.peer.clone(),
|
peer: this.peer.clone(),
|
||||||
connection_pool: this.connection_pool.clone(),
|
connection_pool: this.connection_pool.clone(),
|
||||||
live_kit_client: this.app_state.live_kit_client.clone(),
|
live_kit_client: this.app_state.live_kit_client.clone(),
|
||||||
|
@ -999,7 +1001,7 @@ async fn join_room(
|
||||||
room_id,
|
room_id,
|
||||||
session.user_id,
|
session.user_id,
|
||||||
session.connection_id,
|
session.connection_id,
|
||||||
RELEASE_CHANNEL_NAME.as_str(),
|
session.zed_environment.as_ref(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
room_updated(&room.room, &session.peer);
|
room_updated(&room.room, &session.peer);
|
||||||
|
@ -2608,7 +2610,7 @@ async fn join_channel_internal(
|
||||||
channel_id,
|
channel_id,
|
||||||
session.user_id,
|
session.user_id,
|
||||||
session.connection_id,
|
session.connection_id,
|
||||||
RELEASE_CHANNEL_NAME.as_str(),
|
session.zed_environment.as_ref(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
db::{tests::TestDb, NewUserParams, UserId},
|
db::{tests::TestDb, NewUserParams, UserId},
|
||||||
executor::Executor,
|
executor::Executor,
|
||||||
rpc::{Server, CLEANUP_TIMEOUT, RECONNECT_TIMEOUT},
|
rpc::{Server, CLEANUP_TIMEOUT, RECONNECT_TIMEOUT},
|
||||||
AppState,
|
AppState, Config,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use call::ActiveCall;
|
use call::ActiveCall;
|
||||||
|
@ -414,7 +414,19 @@ impl TestServer {
|
||||||
Arc::new(AppState {
|
Arc::new(AppState {
|
||||||
db: test_db.db().clone(),
|
db: test_db.db().clone(),
|
||||||
live_kit_client: Some(Arc::new(fake_server.create_api_client())),
|
live_kit_client: Some(Arc::new(fake_server.create_api_client())),
|
||||||
config: Default::default(),
|
config: Config {
|
||||||
|
http_port: 0,
|
||||||
|
database_url: "".into(),
|
||||||
|
database_max_connections: 0,
|
||||||
|
api_token: "".into(),
|
||||||
|
invite_link_prefix: "".into(),
|
||||||
|
live_kit_server: None,
|
||||||
|
live_kit_key: None,
|
||||||
|
live_kit_secret: None,
|
||||||
|
rust_log: None,
|
||||||
|
log_json: None,
|
||||||
|
zed_environment: "test".into(),
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,12 @@ use futures::{
|
||||||
};
|
};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, canvas, div, impl_actions, point, size, Action, AnyElement, AnyModel, AnyView,
|
actions, canvas, div, impl_actions, point, size, Action, AnyElement, AnyModel, AnyView,
|
||||||
AnyWeakView, AnyWindowHandle, AppContext, AsyncAppContext, AsyncWindowContext, BorrowWindow,
|
AnyWeakView, AppContext, AsyncAppContext, AsyncWindowContext, BorrowWindow, Bounds, Context,
|
||||||
Bounds, Context, Div, DragMoveEvent, Element, Entity, EntityId, EventEmitter, FocusHandle,
|
Div, DragMoveEvent, Element, Entity, EntityId, EventEmitter, FocusHandle, FocusableView,
|
||||||
FocusableView, GlobalPixels, InteractiveElement, IntoElement, KeyContext, LayoutId,
|
GlobalPixels, InteractiveElement, IntoElement, KeyContext, LayoutId, ManagedView, Model,
|
||||||
ManagedView, Model, ModelContext, ParentElement, PathPromptOptions, Pixels, Point, PromptLevel,
|
ModelContext, ParentElement, PathPromptOptions, Pixels, Point, PromptLevel, Render, Size,
|
||||||
Render, Size, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
|
Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView, WindowBounds,
|
||||||
WindowBounds, WindowContext, WindowHandle, WindowOptions,
|
WindowContext, WindowHandle, WindowOptions,
|
||||||
};
|
};
|
||||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ItemSettings, ProjectItem};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
@ -4034,34 +4034,34 @@ pub fn join_channel(
|
||||||
return anyhow::Ok(());
|
return anyhow::Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if requesting_window.is_some() {
|
|
||||||
return anyhow::Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// find an existing workspace to focus and show call controls
|
// find an existing workspace to focus and show call controls
|
||||||
let mut active_window = activate_any_workspace_window(&mut cx);
|
let mut active_window =
|
||||||
|
requesting_window.or_else(|| activate_any_workspace_window(&mut cx));
|
||||||
if active_window.is_none() {
|
if active_window.is_none() {
|
||||||
// no open workspaces, make one to show the error in (blergh)
|
// no open workspaces, make one to show the error in (blergh)
|
||||||
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), requesting_window, cx))?
|
let (window_handle, _) = cx
|
||||||
|
.update(|cx| {
|
||||||
|
Workspace::new_local(vec![], app_state.clone(), requesting_window, cx)
|
||||||
|
})?
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
active_window = Some(window_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
active_window = activate_any_workspace_window(&mut cx);
|
|
||||||
let Some(active_window) = active_window else {
|
|
||||||
return anyhow::Ok(());
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
active_window
|
log::error!("failed to join channel: {}", err);
|
||||||
.update(&mut cx, |_, cx| {
|
if let Some(active_window) = active_window {
|
||||||
cx.prompt(
|
active_window
|
||||||
PromptLevel::Critical,
|
.update(&mut cx, |_, cx| {
|
||||||
&format!("Failed to join channel: {}", err),
|
cx.prompt(
|
||||||
&["Ok"],
|
PromptLevel::Critical,
|
||||||
)
|
&format!("Failed to join channel: {}", err),
|
||||||
})?
|
&["Ok"],
|
||||||
.await
|
)
|
||||||
.ok();
|
})?
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return ok, we showed the error to the user.
|
// return ok, we showed the error to the user.
|
||||||
|
@ -4079,19 +4079,17 @@ pub async fn get_any_active_workspace(
|
||||||
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), None, cx))?
|
cx.update(|cx| Workspace::new_local(vec![], app_state.clone(), None, cx))?
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
activate_any_workspace_window(&mut cx)
|
activate_any_workspace_window(&mut cx).context("could not open zed")
|
||||||
.context("could not open zed")?
|
|
||||||
.downcast::<Workspace>()
|
|
||||||
.context("could not open zed workspace window")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn activate_any_workspace_window(cx: &mut AsyncAppContext) -> Option<AnyWindowHandle> {
|
fn activate_any_workspace_window(cx: &mut AsyncAppContext) -> Option<WindowHandle<Workspace>> {
|
||||||
cx.update(|cx| {
|
cx.update(|cx| {
|
||||||
for window in cx.windows() {
|
for window in cx.windows() {
|
||||||
let is_workspace = window.downcast::<Workspace>().is_some();
|
if let Some(workspace_window) = window.downcast::<Workspace>() {
|
||||||
if is_workspace {
|
workspace_window
|
||||||
window.update(cx, |_, cx| cx.activate_window()).ok();
|
.update(cx, |_, cx| cx.activate_window())
|
||||||
return Some(window);
|
.ok();
|
||||||
|
return Some(workspace_window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue