forked from lavina/lavina
xmpp: disco-info iq for rooms
This commit is contained in:
parent
6d493d83a3
commit
6bba699d87
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use quick_xml::events::Event;
|
use quick_xml::events::Event;
|
||||||
|
|
||||||
use lavina_core::room::RoomRegistry;
|
use lavina_core::room::{RoomId, RoomRegistry};
|
||||||
use proto_xmpp::bind::{BindResponse, Jid, Name, Server};
|
use proto_xmpp::bind::{BindResponse, Jid, Name, Server};
|
||||||
use proto_xmpp::client::{Iq, IqError, IqErrorType, IqType};
|
use proto_xmpp::client::{Iq, IqError, IqErrorType, IqType};
|
||||||
use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery};
|
use proto_xmpp::disco::{Feature, Identity, InfoQuery, Item, ItemQuery};
|
||||||
|
@ -52,15 +52,29 @@ impl<'a> XmppConnection<'a> {
|
||||||
req.serialize(output);
|
req.serialize(output);
|
||||||
}
|
}
|
||||||
IqClientBody::DiscoInfo(info) => {
|
IqClientBody::DiscoInfo(info) => {
|
||||||
let response = self.disco_info(iq.to.as_ref(), &info);
|
let response = self.disco_info(iq.to.as_ref(), &info).await;
|
||||||
let req = Iq {
|
match response {
|
||||||
from: iq.to,
|
Ok(response) => {
|
||||||
id: iq.id,
|
let req = Iq {
|
||||||
to: None,
|
from: iq.to,
|
||||||
r#type: IqType::Result,
|
id: iq.id,
|
||||||
body: response,
|
to: None,
|
||||||
};
|
r#type: IqType::Result,
|
||||||
req.serialize(output);
|
body: response,
|
||||||
|
};
|
||||||
|
req.serialize(output);
|
||||||
|
}
|
||||||
|
Err(response) => {
|
||||||
|
let req = Iq {
|
||||||
|
from: iq.to,
|
||||||
|
id: iq.id,
|
||||||
|
to: None,
|
||||||
|
r#type: IqType::Error,
|
||||||
|
body: response,
|
||||||
|
};
|
||||||
|
req.serialize(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
IqClientBody::DiscoItem(item) => {
|
IqClientBody::DiscoItem(item) => {
|
||||||
let response = self.disco_items(iq.to.as_ref(), &item, self.rooms).await;
|
let response = self.disco_items(iq.to.as_ref(), &item, self.rooms).await;
|
||||||
|
@ -88,7 +102,7 @@ impl<'a> XmppConnection<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disco_info(&self, to: Option<&Jid>, req: &InfoQuery) -> InfoQuery {
|
async fn disco_info(&self, to: Option<&Jid>, req: &InfoQuery) -> Result<InfoQuery, IqError> {
|
||||||
let identity;
|
let identity;
|
||||||
let feature;
|
let feature;
|
||||||
|
|
||||||
|
@ -126,16 +140,44 @@ impl<'a> XmppConnection<'a> {
|
||||||
Feature::new("http://jabber.org/protocol/muc"),
|
Feature::new("http://jabber.org/protocol/muc"),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Some(Jid {
|
||||||
|
name: Some(room_name),
|
||||||
|
server,
|
||||||
|
resource: None,
|
||||||
|
}) if server.0 == self.hostname_rooms => {
|
||||||
|
let room_id = RoomId::from(room_name.0.clone()).unwrap();
|
||||||
|
let Some(_) = self.rooms.get_room(&room_id).await else {
|
||||||
|
// TODO should return item-not-found
|
||||||
|
// example:
|
||||||
|
// <error type="cancel">
|
||||||
|
// <item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
|
||||||
|
// <text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" xml:lang="en">Conference room does not exist</text>
|
||||||
|
// </error>
|
||||||
|
return Err(IqError {
|
||||||
|
r#type: IqErrorType::Cancel,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
identity = vec![Identity {
|
||||||
|
category: "conference".into(),
|
||||||
|
name: Some(room_id.into_inner().to_string()),
|
||||||
|
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"),
|
||||||
|
]
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
identity = vec![];
|
identity = vec![];
|
||||||
feature = vec![];
|
feature = vec![];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
InfoQuery {
|
Ok(InfoQuery {
|
||||||
node: None,
|
node: None,
|
||||||
identity,
|
identity,
|
||||||
feature,
|
feature,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn disco_items(&self, to: Option<&Jid>, req: &ItemQuery, rooms: &RoomRegistry) -> ItemQuery {
|
async fn disco_items(&self, to: Option<&Jid>, req: &ItemQuery, rooms: &RoomRegistry) -> ItemQuery {
|
||||||
|
|
Loading…
Reference in New Issue