Move make_initial_presence to presence::send module

This commit is contained in:
xmppftw@kl.netlib.re 2023-12-30 00:21:32 +01:00
parent 2a1b4db8e9
commit 7622721ec6
4 changed files with 25 additions and 13 deletions

View file

@ -26,7 +26,8 @@ pub async fn wait_for_events(agent: &mut Agent) -> Option<Vec<Event>> {
match event { match event {
TokioXmppEvent::Online { resumed: false, .. } => { 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; let _ = agent.client.send_stanza(presence).await;
events.push(Event::Online); events.push(Event::Online);
// TODO: only send this when the ContactList feature is enabled. // TODO: only send this when the ContactList feature is enabled.

View file

@ -10,9 +10,7 @@ use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
pub use tokio_xmpp::parsers; pub use tokio_xmpp::parsers;
use tokio_xmpp::parsers::{ use tokio_xmpp::parsers::{
caps::{compute_disco, hash_caps, Caps},
disco::DiscoInfoResult, disco::DiscoInfoResult,
hashes::Algo,
message::{Body, Message, MessageType}, message::{Body, Message, MessageType},
muc::{user::MucUser, Muc}, muc::{user::MucUser, Muc},
presence::{Presence, Type as PresenceType}, presence::{Presence, Type as PresenceType},
@ -158,16 +156,6 @@ impl Agent {
let _ = self.client.send_stanza(message.into()).await; 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. /// Wait for new events.
/// ///
/// # Returns /// # Returns

View file

@ -5,3 +5,4 @@
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
pub mod receive; pub mod receive;
pub mod send;

22
xmpp/src/presence/send.rs Normal file
View file

@ -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
}