parsers: port Iq to use the derive macros

This commit is contained in:
Jonas Schäfer 2025-04-30 18:07:47 +02:00 committed by Link Mauve
commit dc8c3eac4c
8 changed files with 486 additions and 312 deletions

View file

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use tokio_xmpp::parsers::iq::{Iq, IqType};
use tokio_xmpp::parsers::iq::{Iq, IqHeader, IqPayload};
use crate::{Agent, Event};
@ -14,16 +14,14 @@ pub mod set;
pub async fn handle_iq(agent: &mut Agent, iq: Iq) -> Vec<Event> {
let mut events = vec![];
let from = iq
.from
.clone()
.unwrap_or_else(|| agent.client.bound_jid().unwrap().to_bare().into());
if let IqType::Get(payload) = iq.payload {
get::handle_iq_get(agent, &mut events, from, iq.to, iq.id, payload).await;
} else if let IqType::Result(Some(payload)) = iq.payload {
result::handle_iq_result(agent, &mut events, from, iq.to, iq.id, payload).await;
} else if let IqType::Set(payload) = iq.payload {
set::handle_iq_set(agent, &mut events, from, iq.to, iq.id, payload).await;
let (IqHeader { from, to, id }, data) = iq.split();
let from = from.unwrap_or_else(|| agent.client.bound_jid().unwrap().to_bare().into());
if let IqPayload::Get(payload) = data {
get::handle_iq_get(agent, &mut events, from, to, id, payload).await;
} else if let IqPayload::Result(Some(payload)) = data {
result::handle_iq_result(agent, &mut events, from, to, id, payload).await;
} else if let IqPayload::Set(payload) = data {
set::handle_iq_set(agent, &mut events, from, to, id, payload).await;
}
events
}