mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
WIP
This commit is contained in:
parent
11caba4a4c
commit
2145965749
@ -68,10 +68,11 @@ CREATE TABLE "room_participants" (
|
|||||||
"id" INTEGER PRIMARY KEY,
|
"id" INTEGER PRIMARY KEY,
|
||||||
"room_id" INTEGER NOT NULL REFERENCES rooms (id),
|
"room_id" INTEGER NOT NULL REFERENCES rooms (id),
|
||||||
"user_id" INTEGER NOT NULL REFERENCES users (id),
|
"user_id" INTEGER NOT NULL REFERENCES users (id),
|
||||||
"connection_id" INTEGER,
|
"answering_connection_id" INTEGER,
|
||||||
"location_kind" INTEGER,
|
"location_kind" INTEGER,
|
||||||
"location_project_id" INTEGER REFERENCES projects (id),
|
"location_project_id" INTEGER REFERENCES projects (id),
|
||||||
"initial_project_id" INTEGER REFERENCES projects (id),
|
"initial_project_id" INTEGER REFERENCES projects (id),
|
||||||
"calling_user_id" INTEGER NOT NULL REFERENCES users (id)
|
"calling_user_id" INTEGER NOT NULL REFERENCES users (id)
|
||||||
|
"calling_connection_id" INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
|
CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
|
||||||
|
@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS "room_participants" (
|
|||||||
"location_kind" INTEGER,
|
"location_kind" INTEGER,
|
||||||
"location_project_id" INTEGER REFERENCES projects (id),
|
"location_project_id" INTEGER REFERENCES projects (id),
|
||||||
"initial_project_id" INTEGER REFERENCES projects (id),
|
"initial_project_id" INTEGER REFERENCES projects (id),
|
||||||
"calling_user_id" INTEGER NOT NULL REFERENCES users (id)
|
"calling_user_id" INTEGER NOT NULL REFERENCES users (id),
|
||||||
|
"calling_connection_id" INTEGER NOT NULL
|
||||||
);
|
);
|
||||||
CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
|
CREATE UNIQUE INDEX "index_room_participants_on_user_id" ON "room_participants" ("user_id");
|
||||||
|
|
||||||
|
@ -1342,7 +1342,7 @@ where
|
|||||||
INSERT INTO projects (host_user_id, room_id)
|
INSERT INTO projects (host_user_id, room_id)
|
||||||
VALUES ($1)
|
VALUES ($1)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.bind(room_id)
|
.bind(room_id)
|
||||||
@ -1354,7 +1354,7 @@ where
|
|||||||
sqlx::query(
|
sqlx::query(
|
||||||
"
|
"
|
||||||
INSERT INTO worktrees (id, project_id, root_name)
|
INSERT INTO worktrees (id, project_id, root_name)
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.bind(worktree.id as i32)
|
.bind(worktree.id as i32)
|
||||||
.bind(project_id)
|
.bind(project_id)
|
||||||
@ -1741,15 +1741,6 @@ pub struct Room {
|
|||||||
pub live_kit_room: String,
|
pub live_kit_room: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, FromRow, PartialEq)]
|
|
||||||
pub struct Call {
|
|
||||||
pub room_id: RoomId,
|
|
||||||
pub calling_user_id: UserId,
|
|
||||||
pub called_user_id: UserId,
|
|
||||||
pub answering_connection_id: Option<i32>,
|
|
||||||
pub initial_project_id: Option<ProjectId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
id_type!(ProjectId);
|
id_type!(ProjectId);
|
||||||
#[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)]
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
|
@ -431,12 +431,8 @@ impl Server {
|
|||||||
let mut contacts_to_update = HashSet::default();
|
let mut contacts_to_update = HashSet::default();
|
||||||
let mut room_left = None;
|
let mut room_left = None;
|
||||||
{
|
{
|
||||||
let mut store = self.store().await;
|
let removed_connection = self.store().await.remove_connection(connection_id)?;
|
||||||
|
self.app_state.db.remove_connection(connection_id);
|
||||||
#[cfg(test)]
|
|
||||||
let removed_connection = store.remove_connection(connection_id).unwrap();
|
|
||||||
#[cfg(not(test))]
|
|
||||||
let removed_connection = store.remove_connection(connection_id)?;
|
|
||||||
|
|
||||||
for project in removed_connection.hosted_projects {
|
for project in removed_connection.hosted_projects {
|
||||||
projects_to_unshare.push(project.id);
|
projects_to_unshare.push(project.id);
|
||||||
|
@ -72,16 +72,6 @@ pub struct Worktree {
|
|||||||
|
|
||||||
pub type ReplicaId = u16;
|
pub type ReplicaId = u16;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct RemovedConnectionState<'a> {
|
|
||||||
pub user_id: UserId,
|
|
||||||
pub hosted_projects: Vec<Project>,
|
|
||||||
pub guest_projects: Vec<LeftProject>,
|
|
||||||
pub contact_ids: HashSet<UserId>,
|
|
||||||
pub room: Option<Cow<'a, proto::Room>>,
|
|
||||||
pub canceled_call_connection_ids: Vec<ConnectionId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct LeftProject {
|
pub struct LeftProject {
|
||||||
pub id: ProjectId,
|
pub id: ProjectId,
|
||||||
pub host_user_id: UserId,
|
pub host_user_id: UserId,
|
||||||
@ -129,47 +119,20 @@ impl Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self))]
|
||||||
pub fn remove_connection(
|
pub fn remove_connection(&mut self, connection_id: ConnectionId) -> Result<()> {
|
||||||
&mut self,
|
|
||||||
connection_id: ConnectionId,
|
|
||||||
) -> Result<RemovedConnectionState> {
|
|
||||||
let connection = self
|
let connection = self
|
||||||
.connections
|
.connections
|
||||||
.get_mut(&connection_id)
|
.get_mut(&connection_id)
|
||||||
.ok_or_else(|| anyhow!("no such connection"))?;
|
.ok_or_else(|| anyhow!("no such connection"))?;
|
||||||
|
|
||||||
let user_id = connection.user_id;
|
let user_id = connection.user_id;
|
||||||
|
|
||||||
let mut result = RemovedConnectionState {
|
|
||||||
user_id,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
|
|
||||||
let connected_user = self.connected_users.get(&user_id).unwrap();
|
|
||||||
if let Some(active_call) = connected_user.active_call.as_ref() {
|
|
||||||
let room_id = active_call.room_id;
|
|
||||||
if active_call.connection_id == Some(connection_id) {
|
|
||||||
todo!()
|
|
||||||
// let left_room = self.leave_room(room_id, connection_id)?;
|
|
||||||
// result.hosted_projects = left_room.unshared_projects;
|
|
||||||
// result.guest_projects = left_room.left_projects;
|
|
||||||
// result.room = Some(Cow::Owned(left_room.room.into_owned()));
|
|
||||||
// result.canceled_call_connection_ids = left_room.canceled_call_connection_ids;
|
|
||||||
} else if connected_user.connection_ids.len() == 1 {
|
|
||||||
todo!()
|
|
||||||
// let (room, _) = self.decline_call(room_id, connection_id)?;
|
|
||||||
// result.room = Some(Cow::Owned(room.clone()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let connected_user = self.connected_users.get_mut(&user_id).unwrap();
|
let connected_user = self.connected_users.get_mut(&user_id).unwrap();
|
||||||
connected_user.connection_ids.remove(&connection_id);
|
connected_user.connection_ids.remove(&connection_id);
|
||||||
if connected_user.connection_ids.is_empty() {
|
if connected_user.connection_ids.is_empty() {
|
||||||
self.connected_users.remove(&user_id);
|
self.connected_users.remove(&user_id);
|
||||||
}
|
}
|
||||||
self.connections.remove(&connection_id).unwrap();
|
self.connections.remove(&connection_id).unwrap();
|
||||||
|
Ok(())
|
||||||
Ok(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn user_id_for_connection(&self, connection_id: ConnectionId) -> Result<UserId> {
|
pub fn user_id_for_connection(&self, connection_id: ConnectionId) -> Result<UserId> {
|
||||||
|
Loading…
Reference in New Issue
Block a user