Events: Distribute user updates to servers.

Fix: Deleting a server now correctly deletes all associated objects.
This commit is contained in:
Paul
2021-07-28 13:40:03 +01:00
parent 7d3ce0c96a
commit 8f6e5be1d4
13 changed files with 142 additions and 201 deletions

View File

@@ -172,6 +172,18 @@ impl ClientboundNotification {
.ok();
});
}
pub fn publish_as_user(self, user: String) {
self.clone().publish(user.clone());
async_std::task::spawn(async move {
if let Ok(server_ids) = User::fetch_server_ids(&user).await {
for server in server_ids {
self.clone().publish(server.clone());
}
}
});
}
}
pub async fn prehandle_hook(notification: &ClientboundNotification) -> Result<()> {

View File

@@ -19,7 +19,7 @@ pub async fn generate_ready(mut user: User) -> Result<ClientboundNotification> {
);
}
let server_ids = user.fetch_server_ids().await?;
let server_ids = User::fetch_server_ids(&user.id).await?;
let mut cursor = get_collection("servers")
.find(
doc! {

View File

@@ -17,8 +17,7 @@ pub async fn generate_subscriptions(user: &User) -> Result<(), String> {
}
}
let server_ids = user
.fetch_server_ids()
let server_ids = User::fetch_server_ids(&user.id)
.await
.map_err(|_| "Failed to fetch memberships.".to_string())?;

View File

@@ -136,7 +136,7 @@ async fn accept(stream: TcpStream) {
}),
clear: None
}
.publish(id);
.publish_as_user(id);
}
}
Err(_) => {
@@ -238,7 +238,7 @@ async fn accept(stream: TcpStream) {
}),
clear: None
}
.publish(id);
.publish_as_user(id);
}
}