forked from lavina/lavina
remove unused struct
This commit is contained in:
parent
3e1bb53c1b
commit
71d7323534
|
@ -162,44 +162,8 @@ impl Features {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum FromClient {
|
||||
Message(Message),
|
||||
}
|
||||
impl FromClient {
|
||||
pub async fn parse(
|
||||
reader: &mut NsReader<impl AsyncBufRead + Unpin>,
|
||||
buf: &mut Vec<u8>,
|
||||
) -> Result<FromClient> {
|
||||
let incoming = skip_text!(reader, buf);
|
||||
let start = if let Event::Start(ref bytes) = incoming {
|
||||
bytes
|
||||
} else {
|
||||
return Err(ffail!("Unexpected XML event: {incoming:?}"));
|
||||
};
|
||||
let (ns, name) = reader.resolve_element(start.name());
|
||||
if name.as_ref() == b"message" {
|
||||
let mut parser = Message::parse().consume(ns, &incoming);
|
||||
let result = loop {
|
||||
match parser {
|
||||
Continuation::Final(res) => break res,
|
||||
Continuation::Continue(next) => {
|
||||
let (ns, event) = reader.read_resolved_event_into_async(buf).await.unwrap();
|
||||
parser = next.consume(ns, &event);
|
||||
}
|
||||
}
|
||||
}?;
|
||||
Ok(FromClient::Message(result))
|
||||
} else {
|
||||
Err(ffail!("Unknown XML tag: {name:?}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::protos::xmpp::client::MessageType;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
|
@ -233,24 +197,4 @@ mod test {
|
|||
input.write_xml(&mut writer).await.unwrap();
|
||||
assert_eq!(std::str::from_utf8(&output).unwrap(), expected);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn client_message() {
|
||||
let input = r#"<message id="aacea" type="chat" to="nikita@vlnv.dev"><subject>daa</subject><body>bbb</body></message>"#;
|
||||
let mut reader = NsReader::from_reader(input.as_bytes());
|
||||
let mut buf = vec![];
|
||||
let res = FromClient::parse(&mut reader, &mut buf).await.unwrap();
|
||||
assert_eq!(
|
||||
res,
|
||||
FromClient::Message(Message {
|
||||
from: None,
|
||||
id: Some("aacea".to_string()),
|
||||
r#type: MessageType::Chat,
|
||||
to: Some("nikita@vlnv.dev".to_string()),
|
||||
lang: None,
|
||||
subject: Some("daa".to_string()),
|
||||
body: "bbb".to_string(),
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue