parsers/xmpp: MUC bookmarks have nickname typed as ResourcePart
This commit is contained in:
parent
8c033a3fa0
commit
c16456f381
10 changed files with 65 additions and 28 deletions
|
|
@ -11,7 +11,7 @@ use tokio::sync::RwLock;
|
|||
pub use tokio_xmpp::parsers;
|
||||
use tokio_xmpp::parsers::{disco::DiscoInfoResult, message::MessageType};
|
||||
pub use tokio_xmpp::{
|
||||
jid::{BareJid, FullJid, Jid},
|
||||
jid::{BareJid, FullJid, Jid, ResourcePart},
|
||||
minidom::Element,
|
||||
Client as TokioXmppClient,
|
||||
};
|
||||
|
|
@ -20,16 +20,16 @@ use crate::{event_loop, message, muc, upload, Error, Event, RoomNick};
|
|||
|
||||
pub struct Agent {
|
||||
pub(crate) client: TokioXmppClient,
|
||||
pub(crate) default_nick: Arc<RwLock<String>>,
|
||||
pub(crate) default_nick: Arc<RwLock<ResourcePart>>,
|
||||
pub(crate) lang: Arc<Vec<String>>,
|
||||
pub(crate) disco: DiscoInfoResult,
|
||||
pub(crate) node: String,
|
||||
pub(crate) uploads: Vec<(String, Jid, PathBuf)>,
|
||||
pub(crate) awaiting_disco_bookmarks_type: bool,
|
||||
// Mapping of room->nick
|
||||
pub(crate) rooms_joined: HashMap<BareJid, String>,
|
||||
pub(crate) rooms_joining: HashMap<BareJid, String>,
|
||||
pub(crate) rooms_leaving: HashMap<BareJid, String>,
|
||||
pub(crate) rooms_joined: HashMap<BareJid, ResourcePart>,
|
||||
pub(crate) rooms_joining: HashMap<BareJid, ResourcePart>,
|
||||
pub(crate) rooms_leaving: HashMap<BareJid, ResourcePart>,
|
||||
}
|
||||
|
||||
impl Agent {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use tokio::sync::RwLock;
|
|||
use tokio_xmpp::connect::{DnsConfig, StartTlsServerConnector};
|
||||
use tokio_xmpp::{
|
||||
connect::ServerConnector,
|
||||
jid::{BareJid, Jid},
|
||||
jid::{BareJid, Jid, ResourcePart, ResourceRef},
|
||||
parsers::{
|
||||
disco::{DiscoInfoResult, Feature, Identity},
|
||||
ns,
|
||||
|
|
@ -48,7 +48,7 @@ pub struct ClientBuilder<'a, C: ServerConnector> {
|
|||
password: &'a str,
|
||||
server_connector: C,
|
||||
website: String,
|
||||
default_nick: String,
|
||||
default_nick: ResourcePart,
|
||||
lang: Vec<String>,
|
||||
disco: (ClientType, String),
|
||||
features: Vec<ClientFeature>,
|
||||
|
|
@ -78,7 +78,7 @@ impl<C: ServerConnector> ClientBuilder<'_, C> {
|
|||
password,
|
||||
server_connector,
|
||||
website: String::from("https://gitlab.com/xmpp-rs/tokio-xmpp"),
|
||||
default_nick: String::from("xmpp-rs"),
|
||||
default_nick: ResourcePart::new("xmpp-rs").unwrap().into(),
|
||||
lang: vec![String::from("en")],
|
||||
disco: (ClientType::default(), String::from("tokio-xmpp")),
|
||||
features: vec![],
|
||||
|
|
@ -103,8 +103,8 @@ impl<C: ServerConnector> ClientBuilder<'_, C> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_default_nick(mut self, nick: &str) -> Self {
|
||||
self.default_nick = String::from(nick);
|
||||
pub fn set_default_nick(mut self, nick: impl AsRef<ResourceRef>) -> Self {
|
||||
self.default_nick = nick.as_ref().to_owned();
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ pub type RoomNick = String;
|
|||
/*
|
||||
#[cfg(all(test, any(feature = "starttls-rust", feature = "starttls-native")))]
|
||||
mod tests {
|
||||
use super::jid::BareJid;
|
||||
use super::jid::{BareJid, ResourcePart};
|
||||
use super::{ClientBuilder, ClientFeature, ClientType, Event};
|
||||
use std::str::FromStr;
|
||||
use tokio_xmpp::Client as TokioXmppClient;
|
||||
|
|
@ -52,6 +52,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
async fn test_simple() {
|
||||
let jid = BareJid::from_str("foo@bar").unwrap();
|
||||
let nick = ResourcePart::new("bot").unwrap();
|
||||
|
||||
let client = TokioXmppClient::new(jid.clone(), "meh");
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ mod tests {
|
|||
let client_builder = ClientBuilder::new(jid, "meh")
|
||||
.set_client(ClientType::Bot, "xmpp-rs")
|
||||
.set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
|
||||
.set_default_nick("bot")
|
||||
.set_default_nick(nick)
|
||||
.enable_feature(ClientFeature::ContactList);
|
||||
|
||||
#[cfg(feature = "avatars")]
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use crate::parsers::message::MessageType;
|
||||
use tokio_xmpp::{
|
||||
jid::BareJid,
|
||||
jid::{BareJid, ResourcePart, ResourceRef},
|
||||
parsers::{
|
||||
muc::Muc,
|
||||
presence::{Presence, Type as PresenceType},
|
||||
|
|
@ -18,7 +18,7 @@ use crate::Agent;
|
|||
#[derive(Clone, Debug)]
|
||||
pub struct JoinRoomSettings<'a> {
|
||||
pub room: BareJid,
|
||||
pub nick: Option<String>,
|
||||
pub nick: Option<ResourcePart>,
|
||||
pub password: Option<String>,
|
||||
pub status: Option<(&'a str, &'a str)>,
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ impl<'a> JoinRoomSettings<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn with_nick(mut self, nick: impl AsRef<str>) -> Self {
|
||||
pub fn with_nick(mut self, nick: impl AsRef<ResourceRef>) -> Self {
|
||||
self.nick = Some(nick.as_ref().into());
|
||||
self
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ pub async fn join_room<'a>(agent: &mut Agent, settings: JoinRoomSettings<'a>) {
|
|||
agent.default_nick.read().await.clone()
|
||||
};
|
||||
|
||||
let room_jid = room.with_resource_str(&nick).unwrap();
|
||||
let room_jid = room.with_resource(&nick);
|
||||
let mut presence = Presence::new(PresenceType::None).with_to(room_jid);
|
||||
presence.add_payload(muc);
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ pub async fn leave_room<'a>(agent: &mut Agent, settings: LeaveRoomSettings<'a>)
|
|||
error!("Failed to send leave room presence: {}", e);
|
||||
}
|
||||
|
||||
agent.rooms_leaving.insert(room, nickname.to_string());
|
||||
agent.rooms_leaving.insert(room, nickname.clone());
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ pub async fn handle_presence(agent: &mut Agent, presence: Presence) -> Vec<Event
|
|||
PresenceType::None => {
|
||||
// According to https://xmpp.org/extensions/xep-0045.html#enter-pres, no type should be seen as "available".
|
||||
if let Some(nick) = agent.rooms_joining.get(&from) {
|
||||
agent.rooms_joined.insert(from.clone(), nick.to_string());
|
||||
agent.rooms_joined.insert(from.clone(), nick.clone());
|
||||
agent.rooms_joining.remove(&from);
|
||||
} else {
|
||||
warn!("Received self-presence from {} while the room was not marked as joining.", presence.from.unwrap());
|
||||
|
|
|
|||
Loading…
Reference in a new issue