add event_bus_typed
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
use crate::domain::events::channel::{ChannelCreatedEvent, ChannelDeletedEvent};
|
||||
use crate::domain::events::channel_permission::{
|
||||
ChannelRolePermissionUpdatedEvent, ChannelUserPermissionCreatedEvent,
|
||||
ChannelUserPermissionDeletedEvent, ChannelUserPermissionUpdatedEvent,
|
||||
};
|
||||
use crate::domain::events::role::{RoleUserCreatedEvent, RoleUserDeletedEvent};
|
||||
use crate::domain::events::server::{
|
||||
ServerCreatedEvent, ServerUserCreatedEvent, ServerUserDeletedEvent,
|
||||
};
|
||||
use crate::domain::events::server_permission::{
|
||||
ServerRolePermissionUpdatedEvent, ServerUserPermissionUpdatedEvent,
|
||||
};
|
||||
use crate::domain::events::server_tree::ServerTreeInvalidatedEvent;
|
||||
use crate::models::server;
|
||||
use crate::repositories::Repositories;
|
||||
use crate::services::ServicesContext;
|
||||
use event_bus::EventBus;
|
||||
@@ -60,13 +70,10 @@ pub struct PermissionSyncService {
|
||||
|
||||
impl PermissionSyncService {
|
||||
fn invalidate_tree(event_bus: &Arc<EventBus>, server_id: Uuid, user_ids: Option<Vec<Uuid>>) {
|
||||
event_bus.emit(
|
||||
"server_tree_invalidated",
|
||||
ServerTreeInvalidatedEvent {
|
||||
server_id,
|
||||
user_ids,
|
||||
},
|
||||
);
|
||||
event_bus.emit(ServerTreeInvalidatedEvent {
|
||||
server_id,
|
||||
user_ids,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn new(service_context: Arc<ServicesContext>) -> Self {
|
||||
@@ -83,18 +90,18 @@ impl PermissionSyncService {
|
||||
// Événements Serveur & Membres Serveur
|
||||
// ---------------------------------------------------------------------
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"server_created",
|
||||
event_bus.on_async_with::<ServerCreatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, server: server::Model| async move {
|
||||
Self::sync_server(repositories, server.id).await;
|
||||
move |repositories, event| async move {
|
||||
Self::sync_server(repositories, event.server.id).await;
|
||||
},
|
||||
);
|
||||
|
||||
event_bus.on_async_with(
|
||||
"server_user_created",
|
||||
event_bus.on_async_with::<ServerUserCreatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (server_id, user_id): (Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let server_id = event.server_user.server_id;
|
||||
let user_id = event.server_user.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_user(repositories, user_id, server_id).await;
|
||||
@@ -104,10 +111,11 @@ impl PermissionSyncService {
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"server_user_deleted",
|
||||
event_bus.on_async_with::<ServerUserDeletedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (server_id, user_id): (Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let server_id = event.server_user.server_id;
|
||||
let user_id = event.server_user.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_user(repositories, user_id, server_id).await;
|
||||
@@ -121,10 +129,11 @@ impl PermissionSyncService {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"role_user_created",
|
||||
event_bus.on_async_with::<RoleUserCreatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (_role_id, user_id, server_id): (Uuid, Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let server_id = event.server_id;
|
||||
let user_id = event.role_user.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_user(repositories, user_id, server_id).await;
|
||||
@@ -134,10 +143,11 @@ impl PermissionSyncService {
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"role_user_deleted",
|
||||
event_bus.on_async_with::<RoleUserDeletedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (_role_id, user_id, server_id): (Uuid, Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let server_id = event.server_id;
|
||||
let user_id = event.role_user.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_user(repositories, user_id, server_id).await;
|
||||
@@ -151,10 +161,11 @@ impl PermissionSyncService {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"server_role_permission_updated",
|
||||
event_bus.on_async_with::<ServerRolePermissionUpdatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (role_id, server_id): (Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let role_id = event.role_id;
|
||||
let server_id = event.server_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_role_members(repositories, role_id, server_id).await;
|
||||
@@ -164,10 +175,11 @@ impl PermissionSyncService {
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"server_user_permission_updated",
|
||||
event_bus.on_async_with::<ServerUserPermissionUpdatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (server_id, user_id): (Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let server_id = event.server_id;
|
||||
let user_id = event.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_user(repositories, user_id, server_id).await;
|
||||
@@ -181,10 +193,9 @@ impl PermissionSyncService {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"channel_created",
|
||||
event_bus.on_async_with::<ChannelCreatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, event: ChannelCreatedEvent| {
|
||||
move |repositories, event| {
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
if let Some(server_id) = event.channel.server_id {
|
||||
@@ -196,10 +207,9 @@ impl PermissionSyncService {
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"channel_deleted",
|
||||
event_bus.on_async_with::<ChannelDeletedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, event: ChannelDeletedEvent| {
|
||||
move |repositories, event| {
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
if let Some(server_id) = event.channel.server_id {
|
||||
@@ -211,10 +221,11 @@ impl PermissionSyncService {
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"channel_role_permission_updated",
|
||||
event_bus.on_async_with::<ChannelRolePermissionUpdatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (role_id, server_id): (Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let role_id = event.role_id;
|
||||
let server_id = event.server_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_role_members(repositories, role_id, server_id).await;
|
||||
@@ -224,23 +235,34 @@ impl PermissionSyncService {
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"channel_user_permission_updated",
|
||||
event_bus.on_async_with::<ChannelUserPermissionUpdatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (server_id, user_id): (Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let user_id = event.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
Self::sync_user(repositories, user_id, server_id).await;
|
||||
Self::invalidate_tree(¬ify, server_id, Some(vec![user_id]));
|
||||
if let Some(channel) = repositories
|
||||
.channel
|
||||
.get_by_id(event.channel_id)
|
||||
.await
|
||||
.ok()
|
||||
.flatten()
|
||||
{
|
||||
if let Some(server_id) = channel.server_id {
|
||||
Self::sync_user(repositories, user_id, server_id).await;
|
||||
Self::invalidate_tree(¬ify, server_id, Some(vec![user_id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"channel_user_permission_created",
|
||||
event_bus.on_async_with::<ChannelUserPermissionCreatedEvent, _>(
|
||||
repositories.clone(),
|
||||
move |repositories, (channel_id, user_id, _permissions): (Uuid, Uuid, u64)| {
|
||||
move |repositories, event| {
|
||||
let channel_id = event.permission.channel_id;
|
||||
let user_id = event.permission.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
if let Some(channel) = repositories
|
||||
@@ -260,10 +282,11 @@ impl PermissionSyncService {
|
||||
);
|
||||
|
||||
let notify = event_bus.clone();
|
||||
event_bus.on_async_with(
|
||||
"channel_user_permission_deleted",
|
||||
event_bus.on_async_with::<ChannelUserPermissionDeletedEvent, _>(
|
||||
repositories,
|
||||
move |repositories, (channel_id, user_id): (Uuid, Uuid)| {
|
||||
move |repositories, event| {
|
||||
let channel_id = event.permission.channel_id;
|
||||
let user_id = event.permission.user_id;
|
||||
let notify = notify.clone();
|
||||
async move {
|
||||
if let Some(channel) = repositories
|
||||
|
||||
Reference in New Issue
Block a user