add jid to Event::Online

breaks the API
This commit is contained in:
Astro 2019-10-15 22:02:14 +02:00
parent 16458dedf1
commit 9a5c95694b
4 changed files with 18 additions and 6 deletions

View file

@ -47,7 +47,10 @@ fn main() {
if wait_for_stream_end {
/* Do nothing */
} else if event.is_online() {
println!("Online!");
let jid = event.get_jid()
.map(|jid| format!("{}", jid))
.unwrap_or("unknown".to_owned());
println!("Online at {}", jid);
let presence = make_presence();
tx.start_send(Packet::Stanza(presence)).unwrap();

View file

@ -145,8 +145,9 @@ impl Stream for Client {
ClientState::Disconnected => Ok(Async::Ready(None)),
ClientState::Connecting(mut connect) => match connect.poll() {
Ok(Async::Ready(stream)) => {
let jid = stream.jid.clone();
self.state = ClientState::Connected(stream);
Ok(Async::Ready(Some(Event::Online)))
Ok(Async::Ready(Some(Event::Online(jid))))
}
Ok(Async::NotReady) => {
self.state = ClientState::Connecting(connect);

View file

@ -90,7 +90,7 @@ impl Stream for Component {
ComponentState::Connecting(mut connect) => match connect.poll() {
Ok(Async::Ready(stream)) => {
self.state = ComponentState::Connected(stream);
Ok(Async::Ready(Some(Event::Online)))
Ok(Async::Ready(Some(Event::Online(self.jid.clone()))))
}
Ok(Async::NotReady) => {
self.state = ComponentState::Connecting(connect);

View file

@ -1,10 +1,10 @@
use xmpp_parsers::Element;
use xmpp_parsers::{Element, Jid};
/// High-level event on the Stream implemented by Client and Component
#[derive(Debug)]
pub enum Event {
/// Stream is connected and initialized
Online,
Online(Jid),
/// Stream end
Disconnected,
/// Received stanza/nonza
@ -15,11 +15,19 @@ impl Event {
/// `Online` event?
pub fn is_online(&self) -> bool {
match *self {
Event::Online => true,
Event::Online(_) => true,
_ => false,
}
}
/// Get the server-assigned JID for the `Online` event
pub fn get_jid(&self) -> Option<&Jid> {
match *self {
Event::Online(ref jid) => Some(jid),
_ => None,
}
}
/// `Stanza` event?
pub fn is_stanza(&self, name: &str) -> bool {
match *self {