add jid to Event::Online
breaks the API
This commit is contained in:
parent
16458dedf1
commit
9a5c95694b
4 changed files with 18 additions and 6 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
14
src/event.rs
14
src/event.rs
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue