tokio-xmpp: @id wasn't correctly added to every stanza

This commit moves the code adding @id to AsyncClient and SimpleClient,
instead of on the lower level send_stanza helper, which seemed to only
be used internally.

Support is also added for Component.

This removes the addition of @id on elements like <auth/> or <bind/>,
which probably weren't required anyway?

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-06-04 19:01:45 +02:00
commit bc73af1e5e
No known key found for this signature in database
GPG key ID: DEDA74AEECA9D0F2
4 changed files with 20 additions and 11 deletions

View file

@ -14,7 +14,7 @@ use crate::stream_start;
use crate::xmpp_codec::{Packet, XMPPCodec};
use crate::Error;
fn make_id() -> String {
pub(crate) fn make_id() -> String {
let id: u64 = thread_rng().gen();
format!("{}", id)
}
@ -78,11 +78,7 @@ impl<S: AsyncRead + AsyncWrite + Unpin> XMPPStream<S> {
impl<S: AsyncRead + AsyncWrite + Unpin> XMPPStream<S> {
/// Convenience method
pub fn send_stanza<E: Into<Element>>(&mut self, e: E) -> Send<Self, Packet> {
let mut el: Element = e.into();
if el.attr("id").is_none() {
el.set_attr("id", make_id());
}
self.send(Packet::Stanza(el))
self.send(Packet::Stanza(e.into()))
}
}