forked from lavina/lavina
feat(xmpp): list muc rooms in disco
This commit is contained in:
parent
c44101d5d0
commit
d0c579863e
|
@ -32,6 +32,9 @@ impl RoomId {
|
|||
pub fn as_bytes(&self) -> &ByteVec {
|
||||
&self.0
|
||||
}
|
||||
pub fn into_bytes(self) -> ByteVec {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Shared datastructure for storing metadata about rooms.
|
||||
|
|
|
@ -179,6 +179,7 @@ async fn handle_socket(
|
|||
&mut reader_buf,
|
||||
&authenticated,
|
||||
&mut connection,
|
||||
&rooms,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -266,6 +267,7 @@ async fn socket_final(
|
|||
reader_buf: &mut Vec<u8>,
|
||||
authenticated: &Authenticated,
|
||||
user_handle: &mut PlayerConnection,
|
||||
rooms: &RoomRegistry,
|
||||
) -> Result<()> {
|
||||
read_xml_header(xml_reader, reader_buf).await?;
|
||||
let _ = ClientStreamStart::parse(xml_reader, reader_buf).await?;
|
||||
|
@ -309,7 +311,7 @@ async fn socket_final(
|
|||
Continuation::Final(res) => {
|
||||
let res = res?;
|
||||
dbg!(&res);
|
||||
let stop = handle_packet(&mut events, res, authenticated, user_handle).await?;
|
||||
let stop = handle_packet(&mut events, res, authenticated, user_handle, rooms).await?;
|
||||
for i in &events {
|
||||
xml_writer.write_event_async(i).await?;
|
||||
}
|
||||
|
@ -375,10 +377,11 @@ async fn handle_packet(
|
|||
packet: ClientPacket,
|
||||
user: &Authenticated,
|
||||
user_handle: &mut PlayerConnection,
|
||||
rooms: &RoomRegistry,
|
||||
) -> Result<bool> {
|
||||
Ok(match packet {
|
||||
proto::ClientPacket::Iq(iq) => {
|
||||
handle_iq(output, iq);
|
||||
handle_iq(output, iq, rooms).await;
|
||||
false
|
||||
}
|
||||
proto::ClientPacket::Message(m) => {
|
||||
|
@ -471,7 +474,7 @@ async fn handle_packet(
|
|||
})
|
||||
}
|
||||
|
||||
fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>) {
|
||||
async fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>, rooms: &RoomRegistry) {
|
||||
match iq.body {
|
||||
proto::IqClientBody::Bind(b) => {
|
||||
let req = Iq {
|
||||
|
@ -519,7 +522,7 @@ fn handle_iq(output: &mut Vec<Event<'static>>, iq: Iq<IqClientBody>) {
|
|||
req.serialize(output);
|
||||
}
|
||||
proto::IqClientBody::DiscoItem(item) => {
|
||||
let response = disco_items(iq.to.as_deref(), &item);
|
||||
let response = disco_items(iq.to.as_deref(), &item, rooms).await;
|
||||
let req = Iq {
|
||||
from: iq.to,
|
||||
id: iq.id,
|
||||
|
@ -583,7 +586,7 @@ fn disco_info(to: Option<&str>, req: &InfoQuery) -> InfoQuery {
|
|||
}
|
||||
}
|
||||
|
||||
fn disco_items(to: Option<&str>, req: &ItemQuery) -> ItemQuery {
|
||||
async fn disco_items(to: Option<&str>, req: &ItemQuery, rooms: &RoomRegistry) -> ItemQuery {
|
||||
let item = match to {
|
||||
Some("localhost") => {
|
||||
vec![Item {
|
||||
|
@ -597,26 +600,19 @@ fn disco_items(to: Option<&str>, req: &ItemQuery) -> ItemQuery {
|
|||
}]
|
||||
}
|
||||
Some("rooms.localhost") => {
|
||||
vec![
|
||||
Item {
|
||||
let room_list = rooms.get_all_rooms().await;
|
||||
room_list
|
||||
.into_iter()
|
||||
.map(|room_info| Item {
|
||||
jid: Jid {
|
||||
name: Some(Name("room1".to_string())),
|
||||
name: Some(Name(String::from_utf8(room_info.id.into_bytes()).unwrap())),
|
||||
server: Server("rooms.localhost".to_string()),
|
||||
resource: None,
|
||||
},
|
||||
name: None,
|
||||
node: None,
|
||||
},
|
||||
Item {
|
||||
jid: Jid {
|
||||
name: Some(Name("room2".to_string())),
|
||||
server: Server("rooms.localhost".to_string()),
|
||||
resource: None,
|
||||
},
|
||||
name: None,
|
||||
node: None,
|
||||
},
|
||||
]
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
_ => vec![],
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue