use std::collections::HashMap; use actix::prelude::*; use tracing::info; use crate::server::{actors::webhook::message::WebhookMessage, config::RepoAlias}; #[derive(Default)] pub struct WebhookRouter { repos: HashMap>, } impl WebhookRouter { pub fn new() -> Self { Self::default() } } impl Actor for WebhookRouter { type Context = Context; } impl Handler for WebhookRouter { type Result = (); fn handle(&mut self, msg: WebhookMessage, _ctx: &mut Self::Context) -> Self::Result { let repo_alias = RepoAlias(msg.path().clone()); info!(?repo_alias, "router..."); if let Some(recipient) = self.repos.get(&repo_alias) { info!("Sending to recipient"); recipient.do_send(msg); } } } #[derive(Message)] #[rtype(result = "()")] pub struct AddWebhookRecipient(pub RepoAlias, pub Recipient); impl Handler for WebhookRouter { type Result = (); fn handle(&mut self, msg: AddWebhookRecipient, _ctx: &mut Self::Context) -> Self::Result { self.repos.insert(msg.0, msg.1); } }