whatsapp_rust/handlers/
basic.rs1use super::traits::StanzaHandler;
2use crate::client::Client;
3use async_trait::async_trait;
4use std::sync::Arc;
5use wacore_binary::node::Node;
6
7#[derive(Default)]
11pub struct SuccessHandler;
12
13impl SuccessHandler {
14 pub fn new() -> Self {
15 Self
16 }
17}
18
19#[async_trait]
20impl StanzaHandler for SuccessHandler {
21 fn tag(&self) -> &'static str {
22 "success"
23 }
24
25 async fn handle(&self, client: Arc<Client>, node: &Node, _cancelled: &mut bool) -> bool {
26 client.handle_success(node).await;
27 true
28 }
29}
30
31#[derive(Default)]
35pub struct FailureHandler;
36
37impl FailureHandler {
38 pub fn new() -> Self {
39 Self
40 }
41}
42
43#[async_trait]
44impl StanzaHandler for FailureHandler {
45 fn tag(&self) -> &'static str {
46 "failure"
47 }
48
49 async fn handle(&self, client: Arc<Client>, node: &Node, _cancelled: &mut bool) -> bool {
50 client.handle_connect_failure(node).await;
51 true
52 }
53}
54
55#[derive(Default)]
59pub struct StreamErrorHandler;
60
61impl StreamErrorHandler {
62 pub fn new() -> Self {
63 Self
64 }
65}
66
67#[async_trait]
68impl StanzaHandler for StreamErrorHandler {
69 fn tag(&self) -> &'static str {
70 "stream:error"
71 }
72
73 async fn handle(&self, client: Arc<Client>, node: &Node, _cancelled: &mut bool) -> bool {
74 client.handle_stream_error(node).await;
75 true
76 }
77}
78
79#[derive(Default)]
83pub struct AckHandler;
84
85impl AckHandler {
86 pub fn new() -> Self {
87 Self
88 }
89}
90
91#[async_trait]
92impl StanzaHandler for AckHandler {
93 fn tag(&self) -> &'static str {
94 "ack"
95 }
96
97 async fn handle(&self, _client: Arc<Client>, node: &Node, _cancelled: &mut bool) -> bool {
98 use log::info;
99 use wacore::xml::DisplayableNode;
100
101 info!(target: "Client/Recv", "Received ACK node: {}", DisplayableNode(node));
102 true
103 }
104}