tokio-xmpp: Make bound_jid a FullJid
That way we have fewer checks to make in client code.
This commit is contained in:
parent
47c0edc3f6
commit
d848b6efe7
5 changed files with 17 additions and 11 deletions
|
|
@ -7,7 +7,8 @@ Version NEXT:
|
||||||
child elements and attributes.
|
child elements and attributes.
|
||||||
- Add `xmpp_parsers::stream_features::StreamFeatures` to
|
- Add `xmpp_parsers::stream_features::StreamFeatures` to
|
||||||
`tokio_xmpp::event::Online` (!631)
|
`tokio_xmpp::event::Online` (!631)
|
||||||
- `Component.jid` iw now a `BareJid` and not a raw `Jid` (!684)
|
- `Component.jid` is now a `BareJid` and not a raw `Jid` (!684)
|
||||||
|
- `Client.bound_jid` is now a `FullJid` and not a raw `Jid` (!687)
|
||||||
* Added:
|
* Added:
|
||||||
- Expose `client_auth` method to allow manual stream setups for advanced
|
- Expose `client_auth` method to allow manual stream setups for advanced
|
||||||
use cases.
|
use cases.
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@ use std::io;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{mpsc, oneshot, Mutex};
|
use tokio::sync::{mpsc, oneshot, Mutex};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use xmpp_parsers::{jid::Jid, stream_features::StreamFeatures};
|
use xmpp_parsers::{
|
||||||
|
jid::{FullJid, Jid},
|
||||||
|
stream_features::StreamFeatures,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(feature = "direct-tls")]
|
#[cfg(feature = "direct-tls")]
|
||||||
use crate::connect::DirectTlsServerConnector;
|
use crate::connect::DirectTlsServerConnector;
|
||||||
|
|
@ -54,7 +57,7 @@ pub struct Client {
|
||||||
// Client worker task
|
// Client worker task
|
||||||
worker: JoinHandle<stanzastream::StanzaReceiver>,
|
worker: JoinHandle<stanzastream::StanzaReceiver>,
|
||||||
// JID of the logged-in client
|
// JID of the logged-in client
|
||||||
bound_jid: Option<Jid>,
|
bound_jid: Option<FullJid>,
|
||||||
// Stream features of the currently connected stream
|
// Stream features of the currently connected stream
|
||||||
features: Option<StreamFeatures>,
|
features: Option<StreamFeatures>,
|
||||||
// Response tracker for IQs
|
// Response tracker for IQs
|
||||||
|
|
@ -64,7 +67,7 @@ pub struct Client {
|
||||||
impl Client {
|
impl Client {
|
||||||
/// Get the client's bound JID (the one reported by the XMPP
|
/// Get the client's bound JID (the one reported by the XMPP
|
||||||
/// server).
|
/// server).
|
||||||
pub fn bound_jid(&self) -> Option<&Jid> {
|
pub fn bound_jid(&self) -> Option<&FullJid> {
|
||||||
self.bound_jid.as_ref()
|
self.bound_jid.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ use futures::StreamExt;
|
||||||
use futures::{task::Poll, Stream};
|
use futures::{task::Poll, Stream};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
use xmpp_parsers::{jid::Jid, stream_features::StreamFeatures};
|
use xmpp_parsers::{jid::FullJid, stream_features::StreamFeatures};
|
||||||
|
|
||||||
/// Read half of a [`Client`](crate::Client).
|
/// Read half of a [`Client`](crate::Client).
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -22,7 +22,7 @@ impl ClientReceiver {
|
||||||
///
|
///
|
||||||
/// See the documentation of [`Client::bound_jid`](crate::Client::bound_jid) for more
|
/// See the documentation of [`Client::bound_jid`](crate::Client::bound_jid) for more
|
||||||
/// information.
|
/// information.
|
||||||
pub async fn bound_jid(&self) -> Option<Jid> {
|
pub async fn bound_jid(&self) -> Option<FullJid> {
|
||||||
self.0.lock().await.bound_jid.clone()
|
self.0.lock().await.bound_jid.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,8 @@ impl Stream for Client {
|
||||||
..
|
..
|
||||||
} = event
|
} = event
|
||||||
{
|
{
|
||||||
self.bound_jid = Some(bound_jid.clone());
|
// This unwrap() will never fail because the server MUST send us a full JID.
|
||||||
|
self.bound_jid = Some(bound_jid.try_as_full().unwrap().clone());
|
||||||
self.features = Some(features.clone());
|
self.features = Some(features.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use core::ops::ControlFlow;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::sync::oneshot;
|
use tokio::sync::oneshot;
|
||||||
use xmpp_parsers::jid::Jid;
|
use xmpp_parsers::jid::FullJid;
|
||||||
use xmpp_parsers::stream_features::StreamFeatures;
|
use xmpp_parsers::stream_features::StreamFeatures;
|
||||||
|
|
||||||
/// Worker to drive the [`crate::stanzastream`] of a client in the background and continue to
|
/// Worker to drive the [`crate::stanzastream`] of a client in the background and continue to
|
||||||
|
|
@ -25,7 +25,7 @@ pub struct ClientWorker {
|
||||||
// Shutdown signal receiver from frontend
|
// Shutdown signal receiver from frontend
|
||||||
shutdown_rx: oneshot::Receiver<()>,
|
shutdown_rx: oneshot::Receiver<()>,
|
||||||
// JID of the logged-in client
|
// JID of the logged-in client
|
||||||
bound_jid: Option<Jid>,
|
bound_jid: Option<FullJid>,
|
||||||
// Stream features of the currently connected stream
|
// Stream features of the currently connected stream
|
||||||
features: Option<StreamFeatures>,
|
features: Option<StreamFeatures>,
|
||||||
// Response tracker for IQs
|
// Response tracker for IQs
|
||||||
|
|
@ -81,7 +81,8 @@ impl ClientWorker {
|
||||||
bound_jid,
|
bound_jid,
|
||||||
features,
|
features,
|
||||||
}) => {
|
}) => {
|
||||||
self.bound_jid = Some(bound_jid.clone());
|
// This unwrap() will never fail, because the server always uses our own bound JID.
|
||||||
|
self.bound_jid = Some(bound_jid.try_as_full().unwrap().clone());
|
||||||
self.features = Some(features.clone());
|
self.features = Some(features.clone());
|
||||||
self.iq_response_tracker
|
self.iq_response_tracker
|
||||||
.set_account_jid(bound_jid.to_bare());
|
.set_account_jid(bound_jid.to_bare());
|
||||||
|
|
@ -93,7 +94,7 @@ impl ClientWorker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StanzaStreamEvent::Stream(StreamEvent::Resumed) => Event::Online {
|
StanzaStreamEvent::Stream(StreamEvent::Resumed) => Event::Online {
|
||||||
bound_jid: self.bound_jid.as_ref().unwrap().clone(),
|
bound_jid: self.bound_jid.as_ref().unwrap().clone().into(),
|
||||||
features: self.features.as_ref().unwrap().clone(),
|
features: self.features.as_ref().unwrap().clone(),
|
||||||
resumed: true,
|
resumed: true,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue