mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
Move make_initial_presence to presence::send module
This commit is contained in:
parent
2a1b4db8e9
commit
7622721ec6
4 changed files with 25 additions and 13 deletions
|
@ -26,7 +26,8 @@ pub async fn wait_for_events(agent: &mut Agent) -> Option<Vec<Event>> {
|
|||
|
||||
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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
pub mod receive;
|
||||
pub mod send;
|
||||
|
|
22
xmpp/src/presence/send.rs
Normal file
22
xmpp/src/presence/send.rs
Normal 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
|
||||
}
|
Loading…
Reference in a new issue