1use crate::{
8 disco,
9 jid::Jid,
10 minidom::Element,
11 muc::room::JoinRoomSettings,
12 parsers::{disco::DiscoInfoResult, ns, private::Query as PrivateXMLQuery, roster::Roster},
13 pubsub, upload, Agent, Event, RoomNick,
14};
15
16pub async fn handle_iq_result(
17 agent: &mut Agent,
18 events: &mut Vec<Event>,
19 from: Jid,
20 _to: Option<Jid>,
21 id: String,
22 payload: Element,
23) {
24 if payload.is("query", ns::ROSTER) && from == agent.client.bound_jid().unwrap().to_bare() {
27 let roster = Roster::try_from(payload).unwrap();
28 for item in roster.items.into_iter() {
29 events.push(Event::ContactAdded(item));
30 }
31 } else if payload.is("pubsub", ns::PUBSUB) {
32 let new_events = pubsub::handle_iq_result(&from, payload, agent).await;
33 events.extend(new_events);
34 } else if payload.is("slot", ns::HTTP_UPLOAD) {
35 let new_events = upload::receive::handle_upload_result(&from, id, payload, agent).await;
36 events.extend(new_events);
37 } else if payload.is("query", ns::PRIVATE) {
38 match PrivateXMLQuery::try_from(payload) {
39 Ok(query) => {
40 for conf in query.storage.conferences {
41 let (jid, room) = conf.into_bookmarks2();
42 agent
43 .join_room(JoinRoomSettings {
44 room: jid,
45 nick: room.nick.map(RoomNick::new),
46 password: room.password,
47 status: None,
48 })
49 .await;
50 }
51 }
52 Err(e) => {
53 panic!("Wrong XEP-0048 v1.0 Bookmark format: {}", e);
54 }
55 }
56 } else if payload.is("query", ns::DISCO_INFO) {
57 match DiscoInfoResult::try_from(payload.clone()) {
58 Ok(disco) => {
59 disco::handle_disco_info_result(agent, disco, from).await;
60 }
61 Err(e) => match e {
62 _ => panic!("Wrong disco#info format: {}", e),
63 },
64 }
65 }
66}