Fix Store::remove_connection
not removing guests from projects
This commit is contained in:
parent
7b161b81b5
commit
a828282771
1 changed files with 25 additions and 22 deletions
|
@ -2,7 +2,7 @@ use crate::db::{self, ChannelId, UserId};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use collections::{hash_map::Entry, BTreeMap, HashMap, HashSet};
|
use collections::{hash_map::Entry, BTreeMap, HashMap, HashSet};
|
||||||
use rpc::{proto, ConnectionId, Receipt};
|
use rpc::{proto, ConnectionId, Receipt};
|
||||||
use std::{collections::hash_map, path::PathBuf};
|
use std::{collections::hash_map, mem, path::PathBuf};
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -112,30 +112,25 @@ impl Store {
|
||||||
&mut self,
|
&mut self,
|
||||||
connection_id: ConnectionId,
|
connection_id: ConnectionId,
|
||||||
) -> Result<RemovedConnectionState> {
|
) -> Result<RemovedConnectionState> {
|
||||||
let connection = if let Some(connection) = self.connections.remove(&connection_id) {
|
let connection = self
|
||||||
connection
|
.connections
|
||||||
} else {
|
.get_mut(&connection_id)
|
||||||
return Err(anyhow!("no such connection"))?;
|
.ok_or_else(|| anyhow!("no such connection"))?;
|
||||||
};
|
|
||||||
|
|
||||||
for channel_id in &connection.channels {
|
let user_id = connection.user_id;
|
||||||
if let Some(channel) = self.channels.get_mut(&channel_id) {
|
let connection_projects = mem::take(&mut connection.projects);
|
||||||
channel.connection_ids.remove(&connection_id);
|
let connection_channels = mem::take(&mut connection.channels);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let user_connections = self
|
|
||||||
.connections_by_user_id
|
|
||||||
.get_mut(&connection.user_id)
|
|
||||||
.unwrap();
|
|
||||||
user_connections.remove(&connection_id);
|
|
||||||
if user_connections.is_empty() {
|
|
||||||
self.connections_by_user_id.remove(&connection.user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut result = RemovedConnectionState::default();
|
let mut result = RemovedConnectionState::default();
|
||||||
result.user_id = connection.user_id;
|
result.user_id = user_id;
|
||||||
for project_id in connection.projects.clone() {
|
|
||||||
|
// Leave all channels.
|
||||||
|
for channel_id in connection_channels {
|
||||||
|
self.leave_channel(connection_id, channel_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unregister and leave all projects.
|
||||||
|
for project_id in connection_projects {
|
||||||
if let Ok(project) = self.unregister_project(project_id, connection_id) {
|
if let Ok(project) = self.unregister_project(project_id, connection_id) {
|
||||||
result.hosted_projects.insert(project_id, project);
|
result.hosted_projects.insert(project_id, project);
|
||||||
} else if self.leave_project(connection_id, project_id).is_ok() {
|
} else if self.leave_project(connection_id, project_id).is_ok() {
|
||||||
|
@ -143,6 +138,14 @@ impl Store {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let user_connections = self.connections_by_user_id.get_mut(&user_id).unwrap();
|
||||||
|
user_connections.remove(&connection_id);
|
||||||
|
if user_connections.is_empty() {
|
||||||
|
self.connections_by_user_id.remove(&user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.connections.remove(&connection_id).unwrap();
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue