Events: Distribute user updates to servers.
Fix: Deleting a server now correctly deletes all associated objects.
This commit is contained in:
@@ -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<()> {
|
||||
|
||||
@@ -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! {
|
||||
|
||||
@@ -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())?;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user