This commit is contained in:
Antonio Scandurra 2022-11-11 19:36:20 +01:00
parent 11caba4a4c
commit 2145965749
5 changed files with 10 additions and 59 deletions

View file

@ -68,10 +68,11 @@ CREATE TABLE "room_participants" (
"id" INTEGER PRIMARY KEY,
"room_id" INTEGER NOT NULL REFERENCES rooms (id),
"user_id" INTEGER NOT NULL REFERENCES users (id),
"connection_id" INTEGER,
"answering_connection_id" INTEGER,
"location_kind" INTEGER,
"location_project_id" INTEGER REFERENCES projects (id),
"initial_project_id" INTEGER REFERENCES projects (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");

View file

@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS "room_participants" (
"location_kind" INTEGER,
"location_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");

View file

@ -1342,7 +1342,7 @@ where
INSERT INTO projects (host_user_id, room_id)
VALUES ($1)
RETURNING id
",
",
)
.bind(user_id)
.bind(room_id)
@ -1354,7 +1354,7 @@ where
sqlx::query(
"
INSERT INTO worktrees (id, project_id, root_name)
",
",
)
.bind(worktree.id as i32)
.bind(project_id)
@ -1741,15 +1741,6 @@ pub struct Room {
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);
#[derive(Clone, Debug, Default, FromRow, Serialize, PartialEq)]
pub struct Project {

View file

@ -431,12 +431,8 @@ impl Server {
let mut contacts_to_update = HashSet::default();
let mut room_left = None;
{
let mut store = self.store().await;
#[cfg(test)]
let removed_connection = store.remove_connection(connection_id).unwrap();
#[cfg(not(test))]
let removed_connection = store.remove_connection(connection_id)?;
let removed_connection = self.store().await.remove_connection(connection_id)?;
self.app_state.db.remove_connection(connection_id);
for project in removed_connection.hosted_projects {
projects_to_unshare.push(project.id);

View file

@ -72,16 +72,6 @@ pub struct Worktree {
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 id: ProjectId,
pub host_user_id: UserId,
@ -129,47 +119,20 @@ impl Store {
}
#[instrument(skip(self))]
pub fn remove_connection(
&mut self,
connection_id: ConnectionId,
) -> Result<RemovedConnectionState> {
pub fn remove_connection(&mut self, connection_id: ConnectionId) -> Result<()> {
let connection = self
.connections
.get_mut(&connection_id)
.ok_or_else(|| anyhow!("no such connection"))?;
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();
connected_user.connection_ids.remove(&connection_id);
if connected_user.connection_ids.is_empty() {
self.connected_users.remove(&user_id);
}
self.connections.remove(&connection_id).unwrap();
Ok(result)
Ok(())
}
pub fn user_id_for_connection(&self, connection_id: ConnectionId) -> Result<UserId> {