Remove workspace -> channel dependency

This commit is contained in:
Max Brunsfeld 2023-10-06 14:16:08 -07:00
parent 3412bb75be
commit f8ca86c6a7
12 changed files with 41 additions and 47 deletions

1
Cargo.lock generated
View file

@ -9969,7 +9969,6 @@ dependencies = [
"async-recursion 1.0.5", "async-recursion 1.0.5",
"bincode", "bincode",
"call", "call",
"channel",
"client", "client",
"collections", "collections",
"context_menu", "context_menu",

View file

@ -2,19 +2,21 @@ mod channel_buffer;
mod channel_chat; mod channel_chat;
mod channel_store; mod channel_store;
use client::{Client, UserStore};
use gpui::{AppContext, ModelHandle};
use std::sync::Arc;
pub use channel_buffer::{ChannelBuffer, ChannelBufferEvent, ACKNOWLEDGE_DEBOUNCE_INTERVAL}; pub use channel_buffer::{ChannelBuffer, ChannelBufferEvent, ACKNOWLEDGE_DEBOUNCE_INTERVAL};
pub use channel_chat::{ChannelChat, ChannelChatEvent, ChannelMessage, ChannelMessageId}; pub use channel_chat::{ChannelChat, ChannelChatEvent, ChannelMessage, ChannelMessageId};
pub use channel_store::{ pub use channel_store::{
Channel, ChannelData, ChannelEvent, ChannelId, ChannelMembership, ChannelPath, ChannelStore, Channel, ChannelData, ChannelEvent, ChannelId, ChannelMembership, ChannelPath, ChannelStore,
}; };
use client::Client;
use std::sync::Arc;
#[cfg(test)] #[cfg(test)]
mod channel_store_tests; mod channel_store_tests;
pub fn init(client: &Arc<Client>) { pub fn init(client: &Arc<Client>, user_store: ModelHandle<UserStore>, cx: &mut AppContext) {
channel_store::init(client, user_store, cx);
channel_buffer::init(client); channel_buffer::init(client);
channel_chat::init(client); channel_chat::init(client);
} }

View file

@ -2,6 +2,7 @@ mod channel_index;
use crate::{channel_buffer::ChannelBuffer, channel_chat::ChannelChat}; use crate::{channel_buffer::ChannelBuffer, channel_chat::ChannelChat};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use channel_index::ChannelIndex;
use client::{Client, Subscription, User, UserId, UserStore}; use client::{Client, Subscription, User, UserId, UserStore};
use collections::{hash_map, HashMap, HashSet}; use collections::{hash_map, HashMap, HashSet};
use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt}; use futures::{channel::mpsc, future::Shared, Future, FutureExt, StreamExt};
@ -14,7 +15,11 @@ use serde_derive::{Deserialize, Serialize};
use std::{borrow::Cow, hash::Hash, mem, ops::Deref, sync::Arc, time::Duration}; use std::{borrow::Cow, hash::Hash, mem, ops::Deref, sync::Arc, time::Duration};
use util::ResultExt; use util::ResultExt;
use self::channel_index::ChannelIndex; pub fn init(client: &Arc<Client>, user_store: ModelHandle<UserStore>, cx: &mut AppContext) {
let channel_store =
cx.add_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx));
cx.set_global(channel_store);
}
pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30); pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(30);
@ -71,6 +76,10 @@ enum OpenedModelHandle<E: Entity> {
} }
impl ChannelStore { impl ChannelStore {
pub fn global(cx: &AppContext) -> ModelHandle<Self> {
cx.global::<ModelHandle<Self>>().clone()
}
pub fn new( pub fn new(
client: Arc<Client>, client: Arc<Client>,
user_store: ModelHandle<UserStore>, user_store: ModelHandle<UserStore>,

View file

@ -340,10 +340,10 @@ fn init_test(cx: &mut AppContext) -> ModelHandle<ChannelStore> {
cx.foreground().forbid_parking(); cx.foreground().forbid_parking();
cx.set_global(SettingsStore::test(cx)); cx.set_global(SettingsStore::test(cx));
crate::init(&client);
client::init(&client, cx); client::init(&client, cx);
crate::init(&client, user_store, cx);
cx.add_model(|cx| ChannelStore::new(client, user_store, cx)) ChannelStore::global(cx)
} }
fn update_channels( fn update_channels(

View file

@ -44,6 +44,7 @@ pub struct TestServer {
pub struct TestClient { pub struct TestClient {
pub username: String, pub username: String,
pub app_state: Arc<workspace::AppState>, pub app_state: Arc<workspace::AppState>,
channel_store: ModelHandle<ChannelStore>,
state: RefCell<TestClientState>, state: RefCell<TestClientState>,
} }
@ -206,15 +207,12 @@ impl TestServer {
let fs = FakeFs::new(cx.background()); let fs = FakeFs::new(cx.background());
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http, cx));
let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx)); let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx));
let channel_store =
cx.add_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx));
let mut language_registry = LanguageRegistry::test(); let mut language_registry = LanguageRegistry::test();
language_registry.set_executor(cx.background()); language_registry.set_executor(cx.background());
let app_state = Arc::new(workspace::AppState { let app_state = Arc::new(workspace::AppState {
client: client.clone(), client: client.clone(),
user_store: user_store.clone(), user_store: user_store.clone(),
workspace_store, workspace_store,
channel_store: channel_store.clone(),
languages: Arc::new(language_registry), languages: Arc::new(language_registry),
fs: fs.clone(), fs: fs.clone(),
build_window_options: |_, _, _| Default::default(), build_window_options: |_, _, _| Default::default(),
@ -231,7 +229,7 @@ impl TestServer {
workspace::init(app_state.clone(), cx); workspace::init(app_state.clone(), cx);
audio::init((), cx); audio::init((), cx);
call::init(client.clone(), user_store.clone(), cx); call::init(client.clone(), user_store.clone(), cx);
channel::init(&client); channel::init(&client, user_store, cx);
}); });
client client
@ -242,6 +240,7 @@ impl TestServer {
let client = TestClient { let client = TestClient {
app_state, app_state,
username: name.to_string(), username: name.to_string(),
channel_store: cx.read(ChannelStore::global).clone(),
state: Default::default(), state: Default::default(),
}; };
client.wait_for_current_user(cx).await; client.wait_for_current_user(cx).await;
@ -310,10 +309,9 @@ impl TestServer {
admin: (&TestClient, &mut TestAppContext), admin: (&TestClient, &mut TestAppContext),
members: &mut [(&TestClient, &mut TestAppContext)], members: &mut [(&TestClient, &mut TestAppContext)],
) -> u64 { ) -> u64 {
let (admin_client, admin_cx) = admin; let (_, admin_cx) = admin;
let channel_id = admin_client let channel_id = admin_cx
.app_state .read(ChannelStore::global)
.channel_store
.update(admin_cx, |channel_store, cx| { .update(admin_cx, |channel_store, cx| {
channel_store.create_channel(channel, parent, cx) channel_store.create_channel(channel, parent, cx)
}) })
@ -321,9 +319,8 @@ impl TestServer {
.unwrap(); .unwrap();
for (member_client, member_cx) in members { for (member_client, member_cx) in members {
admin_client admin_cx
.app_state .read(ChannelStore::global)
.channel_store
.update(admin_cx, |channel_store, cx| { .update(admin_cx, |channel_store, cx| {
channel_store.invite_member( channel_store.invite_member(
channel_id, channel_id,
@ -337,9 +334,8 @@ impl TestServer {
admin_cx.foreground().run_until_parked(); admin_cx.foreground().run_until_parked();
member_client member_cx
.app_state .read(ChannelStore::global)
.channel_store
.update(*member_cx, |channels, _| { .update(*member_cx, |channels, _| {
channels.respond_to_channel_invite(channel_id, true) channels.respond_to_channel_invite(channel_id, true)
}) })
@ -447,7 +443,7 @@ impl TestClient {
} }
pub fn channel_store(&self) -> &ModelHandle<ChannelStore> { pub fn channel_store(&self) -> &ModelHandle<ChannelStore> {
&self.app_state.channel_store &self.channel_store
} }
pub fn user_store(&self) -> &ModelHandle<UserStore> { pub fn user_store(&self) -> &ModelHandle<UserStore> {
@ -614,8 +610,8 @@ impl TestClient {
) { ) {
let (other_client, other_cx) = user; let (other_client, other_cx) = user;
self.app_state cx_self
.channel_store .read(ChannelStore::global)
.update(cx_self, |channel_store, cx| { .update(cx_self, |channel_store, cx| {
channel_store.invite_member(channel, other_client.user_id().unwrap(), true, cx) channel_store.invite_member(channel, other_client.user_id().unwrap(), true, cx)
}) })
@ -624,11 +620,10 @@ impl TestClient {
cx_self.foreground().run_until_parked(); cx_self.foreground().run_until_parked();
other_client other_cx
.app_state .read(ChannelStore::global)
.channel_store .update(other_cx, |channel_store, _| {
.update(other_cx, |channels, _| { channel_store.respond_to_channel_invite(channel, true)
channels.respond_to_channel_invite(channel, true)
}) })
.await .await
.unwrap(); .unwrap();

View file

@ -73,7 +73,7 @@ impl ChannelView {
) -> Task<Result<ViewHandle<Self>>> { ) -> Task<Result<ViewHandle<Self>>> {
let workspace = workspace.read(cx); let workspace = workspace.read(cx);
let project = workspace.project().to_owned(); let project = workspace.project().to_owned();
let channel_store = workspace.app_state().channel_store.clone(); let channel_store = ChannelStore::global(cx);
let markdown = workspace let markdown = workspace
.app_state() .app_state()
.languages .languages

View file

@ -81,7 +81,7 @@ impl ChatPanel {
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> ViewHandle<Self> { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> ViewHandle<Self> {
let fs = workspace.app_state().fs.clone(); let fs = workspace.app_state().fs.clone();
let client = workspace.app_state().client.clone(); let client = workspace.app_state().client.clone();
let channel_store = workspace.app_state().channel_store.clone(); let channel_store = ChannelStore::global(cx);
let languages = workspace.app_state().languages.clone(); let languages = workspace.app_state().languages.clone();
let input_editor = cx.add_view(|cx| { let input_editor = cx.add_view(|cx| {

View file

@ -648,7 +648,7 @@ impl CollabPanel {
channel_editing_state: None, channel_editing_state: None,
selection: None, selection: None,
user_store: workspace.user_store().clone(), user_store: workspace.user_store().clone(),
channel_store: workspace.app_state().channel_store.clone(), channel_store: ChannelStore::global(cx),
project: workspace.project().clone(), project: workspace.project().clone(),
subscriptions: Vec::default(), subscriptions: Vec::default(),
match_candidates: Vec::default(), match_candidates: Vec::default(),

View file

@ -22,7 +22,6 @@ test-support = [
db = { path = "../db" } db = { path = "../db" }
call = { path = "../call" } call = { path = "../call" }
client = { path = "../client" } client = { path = "../client" }
channel = { path = "../channel" }
collections = { path = "../collections" } collections = { path = "../collections" }
context_menu = { path = "../context_menu" } context_menu = { path = "../context_menu" }
drag_and_drop = { path = "../drag_and_drop" } drag_and_drop = { path = "../drag_and_drop" }

View file

@ -12,7 +12,6 @@ mod workspace_settings;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use call::ActiveCall; use call::ActiveCall;
use channel::ChannelStore;
use client::{ use client::{
proto::{self, PeerId}, proto::{self, PeerId},
Client, TypedEnvelope, UserStore, Client, TypedEnvelope, UserStore,
@ -450,7 +449,6 @@ pub struct AppState {
pub languages: Arc<LanguageRegistry>, pub languages: Arc<LanguageRegistry>,
pub client: Arc<Client>, pub client: Arc<Client>,
pub user_store: ModelHandle<UserStore>, pub user_store: ModelHandle<UserStore>,
pub channel_store: ModelHandle<ChannelStore>,
pub workspace_store: ModelHandle<WorkspaceStore>, pub workspace_store: ModelHandle<WorkspaceStore>,
pub fs: Arc<dyn fs::Fs>, pub fs: Arc<dyn fs::Fs>,
pub build_window_options: pub build_window_options:
@ -487,8 +485,6 @@ impl AppState {
let http_client = util::http::FakeHttpClient::with_404_response(); let http_client = util::http::FakeHttpClient::with_404_response();
let client = Client::new(http_client.clone(), cx); let client = Client::new(http_client.clone(), cx);
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http_client, cx));
let channel_store =
cx.add_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx));
let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx)); let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx));
theme::init((), cx); theme::init((), cx);
@ -500,7 +496,7 @@ impl AppState {
fs, fs,
languages, languages,
user_store, user_store,
channel_store, // channel_store,
workspace_store, workspace_store,
initialize_workspace: |_, _, _, _| Task::ready(Ok(())), initialize_workspace: |_, _, _, _| Task::ready(Ok(())),
build_window_options: |_, _, _| Default::default(), build_window_options: |_, _, _| Default::default(),
@ -3527,15 +3523,12 @@ impl Workspace {
let client = project.read(cx).client(); let client = project.read(cx).client();
let user_store = project.read(cx).user_store(); let user_store = project.read(cx).user_store();
let channel_store =
cx.add_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx));
let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx)); let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx));
let app_state = Arc::new(AppState { let app_state = Arc::new(AppState {
languages: project.read(cx).languages().clone(), languages: project.read(cx).languages().clone(),
workspace_store, workspace_store,
client, client,
user_store, user_store,
channel_store,
fs: project.read(cx).fs().clone(), fs: project.read(cx).fs().clone(),
build_window_options: |_, _, _| Default::default(), build_window_options: |_, _, _| Default::default(),
initialize_workspace: |_, _, _, _| Task::ready(Ok(())), initialize_workspace: |_, _, _, _| Task::ready(Ok(())),

View file

@ -3,7 +3,6 @@
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use backtrace::Backtrace; use backtrace::Backtrace;
use channel::ChannelStore;
use cli::{ use cli::{
ipc::{self, IpcSender}, ipc::{self, IpcSender},
CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME, CliRequest, CliResponse, IpcHandshake, FORCE_CLI_MODE_ENV_VAR_NAME,
@ -138,8 +137,6 @@ fn main() {
languages::init(languages.clone(), node_runtime.clone(), cx); languages::init(languages.clone(), node_runtime.clone(), cx);
let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx)); let user_store = cx.add_model(|cx| UserStore::new(client.clone(), http.clone(), cx));
let channel_store =
cx.add_model(|cx| ChannelStore::new(client.clone(), user_store.clone(), cx));
let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx)); let workspace_store = cx.add_model(|cx| WorkspaceStore::new(client.clone(), cx));
cx.set_global(client.clone()); cx.set_global(client.clone());
@ -156,7 +153,7 @@ fn main() {
outline::init(cx); outline::init(cx);
project_symbols::init(cx); project_symbols::init(cx);
project_panel::init(Assets, cx); project_panel::init(Assets, cx);
channel::init(&client); channel::init(&client, user_store.clone(), cx);
diagnostics::init(cx); diagnostics::init(cx);
search::init(cx); search::init(cx);
semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx); semantic_index::init(fs.clone(), http.clone(), languages.clone(), cx);
@ -184,7 +181,6 @@ fn main() {
languages, languages,
client: client.clone(), client: client.clone(),
user_store, user_store,
channel_store,
fs, fs,
build_window_options, build_window_options,
initialize_workspace, initialize_workspace,

View file

@ -2424,6 +2424,7 @@ mod tests {
state.build_window_options = build_window_options; state.build_window_options = build_window_options;
theme::init((), cx); theme::init((), cx);
audio::init((), cx); audio::init((), cx);
channel::init(&app_state.client, app_state.user_store.clone(), cx);
call::init(app_state.client.clone(), app_state.user_store.clone(), cx); call::init(app_state.client.clone(), app_state.user_store.clone(), cx);
workspace::init(app_state.clone(), cx); workspace::init(app_state.clone(), cx);
Project::init_settings(cx); Project::init_settings(cx);