use super::traits::StanzaHandler;
use crate::client::Client;
use async_trait::async_trait;
use std::sync::Arc;
use wacore_binary::node::Node;
pub struct UnimplementedHandler {
tags: Vec<&'static str>,
}
impl UnimplementedHandler {
pub fn new(tags: Vec<&'static str>) -> Self {
Self { tags }
}
pub fn for_call() -> Self {
Self::new(vec!["call"])
}
pub fn for_presence() -> Self {
Self::new(vec!["presence"])
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
impl StanzaHandler for UnimplementedHandler {
fn tag(&self) -> &'static str {
if self.tags.len() == 1 {
self.tags[0]
} else {
panic!("UnimplementedHandler with multiple tags should be registered individually")
}
}
async fn handle(&self, client: Arc<Client>, node: Arc<Node>, _cancelled: &mut bool) -> bool {
client.handle_unimplemented(&node.tag).await;
true
}
}