feat(xmpp): improve disco responses

This commit is contained in:
Nikita Vilunov 2023-04-05 22:37:33 +02:00
parent f71d098420
commit 2b54260f0b
2 changed files with 25 additions and 10 deletions

View File

@ -25,7 +25,7 @@ use crate::prelude::*;
use crate::protos::xmpp;
use crate::protos::xmpp::bind::{BindResponse, Jid, Name, Resource, Server};
use crate::protos::xmpp::client::{Iq, Presence};
use crate::protos::xmpp::disco::{Feature, InfoQuery, Item, ItemQuery};
use crate::protos::xmpp::disco::*;
use crate::protos::xmpp::roster::RosterQuery;
use crate::protos::xmpp::session::Session;
use crate::protos::xmpp::stream::*;
@ -314,7 +314,7 @@ fn handle_packet(output: &mut Vec<Event<'static>>, packet: ClientPacket) -> bool
};
response.serialize(output);
false
},
}
proto::ClientPacket::StreamEnd => {
ServerStreamEnd.serialize(output);
true
@ -394,9 +394,16 @@ fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>) {
}
fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery {
let feature = match to {
let identity;
let feature;
match to {
Some("localhost") => {
vec![
identity = vec![Identity {
category: "server".into(),
name: None,
r#type: "im".into(),
}];
feature = vec![
Feature::new("http://jabber.org/protocol/disco#info"),
Feature::new("http://jabber.org/protocol/disco#items"),
Feature::new("iq"),
@ -404,17 +411,25 @@ fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery {
]
}
Some("rooms.localhost") => {
vec![
identity = vec![Identity {
category: "conference".into(),
name: Some("Chat rooms".into()),
r#type: "text".into(),
}];
feature = vec![
Feature::new("http://jabber.org/protocol/disco#info"),
Feature::new("http://jabber.org/protocol/disco#items"),
Feature::new("http://jabber.org/protocol/muc"),
]
}
_ => vec![],
_ => {
identity = vec![];
feature = vec![];
}
};
InfoQuery {
node: None,
identity: vec![],
identity,
feature,
}
}

View File

@ -132,9 +132,9 @@ impl ToXml for InfoQuery {
#[derive(PartialEq, Eq, Debug)]
pub struct Identity {
category: String,
name: Option<String>,
r#type: String,
pub category: String,
pub name: Option<String>,
pub r#type: String,
}
impl FromXml for Identity {