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 {
|
if wait_for_stream_end {
|
||||||
/* Do nothing */
|
/* Do nothing */
|
||||||
} else if event.is_online() {
|
} 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();
|
let presence = make_presence();
|
||||||
tx.start_send(Packet::Stanza(presence)).unwrap();
|
tx.start_send(Packet::Stanza(presence)).unwrap();
|
||||||
|
|
|
@ -145,8 +145,9 @@ impl Stream for Client {
|
||||||
ClientState::Disconnected => Ok(Async::Ready(None)),
|
ClientState::Disconnected => Ok(Async::Ready(None)),
|
||||||
ClientState::Connecting(mut connect) => match connect.poll() {
|
ClientState::Connecting(mut connect) => match connect.poll() {
|
||||||
Ok(Async::Ready(stream)) => {
|
Ok(Async::Ready(stream)) => {
|
||||||
|
let jid = stream.jid.clone();
|
||||||
self.state = ClientState::Connected(stream);
|
self.state = ClientState::Connected(stream);
|
||||||
Ok(Async::Ready(Some(Event::Online)))
|
Ok(Async::Ready(Some(Event::Online(jid))))
|
||||||
}
|
}
|
||||||
Ok(Async::NotReady) => {
|
Ok(Async::NotReady) => {
|
||||||
self.state = ClientState::Connecting(connect);
|
self.state = ClientState::Connecting(connect);
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl Stream for Component {
|
||||||
ComponentState::Connecting(mut connect) => match connect.poll() {
|
ComponentState::Connecting(mut connect) => match connect.poll() {
|
||||||
Ok(Async::Ready(stream)) => {
|
Ok(Async::Ready(stream)) => {
|
||||||
self.state = ComponentState::Connected(stream);
|
self.state = ComponentState::Connected(stream);
|
||||||
Ok(Async::Ready(Some(Event::Online)))
|
Ok(Async::Ready(Some(Event::Online(self.jid.clone()))))
|
||||||
}
|
}
|
||||||
Ok(Async::NotReady) => {
|
Ok(Async::NotReady) => {
|
||||||
self.state = ComponentState::Connecting(connect);
|
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
|
/// High-level event on the Stream implemented by Client and Component
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
/// Stream is connected and initialized
|
/// Stream is connected and initialized
|
||||||
Online,
|
Online(Jid),
|
||||||
/// Stream end
|
/// Stream end
|
||||||
Disconnected,
|
Disconnected,
|
||||||
/// Received stanza/nonza
|
/// Received stanza/nonza
|
||||||
|
@ -15,11 +15,19 @@ impl Event {
|
||||||
/// `Online` event?
|
/// `Online` event?
|
||||||
pub fn is_online(&self) -> bool {
|
pub fn is_online(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Event::Online => true,
|
Event::Online(_) => true,
|
||||||
_ => false,
|
_ => 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?
|
/// `Stanza` event?
|
||||||
pub fn is_stanza(&self, name: &str) -> bool {
|
pub fn is_stanza(&self, name: &str) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
Loading…
Reference in a new issue