diff --git a/xmpp/src/event_loop.rs b/xmpp/src/event_loop.rs index 6041b70..73db911 100644 --- a/xmpp/src/event_loop.rs +++ b/xmpp/src/event_loop.rs @@ -26,7 +26,8 @@ pub async fn wait_for_events(agent: &mut Agent) -> Option> { match event { TokioXmppEvent::Online { resumed: false, .. } => { - let presence = Agent::make_initial_presence(&agent.disco, &agent.node).into(); + let presence = + presence::send::make_initial_presence(&agent.disco, &agent.node).into(); let _ = agent.client.send_stanza(presence).await; events.push(Event::Online); // TODO: only send this when the ContactList feature is enabled. diff --git a/xmpp/src/lib.rs b/xmpp/src/lib.rs index d5388fd..a4accc6 100644 --- a/xmpp/src/lib.rs +++ b/xmpp/src/lib.rs @@ -10,9 +10,7 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, RwLock}; pub use tokio_xmpp::parsers; use tokio_xmpp::parsers::{ - caps::{compute_disco, hash_caps, Caps}, disco::DiscoInfoResult, - hashes::Algo, message::{Body, Message, MessageType}, muc::{user::MucUser, Muc}, presence::{Presence, Type as PresenceType}, @@ -158,16 +156,6 @@ impl Agent { let _ = self.client.send_stanza(message.into()).await; } - fn make_initial_presence(disco: &DiscoInfoResult, node: &str) -> Presence { - let caps_data = compute_disco(disco); - let hash = hash_caps(&caps_data, Algo::Sha_1).unwrap(); - let caps = Caps::new(node, hash); - - let mut presence = Presence::new(PresenceType::None); - presence.add_payload(caps); - presence - } - /// Wait for new events. /// /// # Returns diff --git a/xmpp/src/presence/mod.rs b/xmpp/src/presence/mod.rs index ce689d6..f38387b 100644 --- a/xmpp/src/presence/mod.rs +++ b/xmpp/src/presence/mod.rs @@ -5,3 +5,4 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. pub mod receive; +pub mod send; diff --git a/xmpp/src/presence/send.rs b/xmpp/src/presence/send.rs new file mode 100644 index 0000000..4605cec --- /dev/null +++ b/xmpp/src/presence/send.rs @@ -0,0 +1,22 @@ +// Copyright (c) 2023 xmpp-rs contributors. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +use tokio_xmpp::parsers::{ + caps::{compute_disco, hash_caps, Caps}, + disco::DiscoInfoResult, + hashes::Algo, + presence::{Presence, Type as PresenceType}, +}; + +pub(crate) fn make_initial_presence(disco: &DiscoInfoResult, node: &str) -> Presence { + let caps_data = compute_disco(disco); + let hash = hash_caps(&caps_data, Algo::Sha_1).unwrap(); + let caps = Caps::new(node, hash); + + let mut presence = Presence::new(PresenceType::None); + presence.add_payload(caps); + presence +}