diff --git a/Cargo.toml b/Cargo.toml index e769b65..a9def97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ license = "MPL-2.0" edition = "2018" [dependencies] -tokio-xmpp = "1" -xmpp-parsers = "0.13" +tokio-xmpp = "1.0.1" +xmpp-parsers = "0.15" futures = "0.1" tokio = "0.1" diff --git a/examples/hello_bot.rs b/examples/hello_bot.rs index e374bf6..dcfd060 100644 --- a/examples/hello_bot.rs +++ b/examples/hello_bot.rs @@ -8,7 +8,7 @@ use futures::prelude::*; use std::env::args; use std::process::exit; use tokio::runtime::current_thread::Runtime; -use xmpp_parsers::message::MessageType; +use xmpp_parsers::{message::MessageType, Jid}; use xmpp::{ClientBuilder, ClientType, ClientFeature, Event}; fn main() { @@ -60,7 +60,7 @@ fn main() { }, Event::RoomJoined(jid) => { println!("Joined room {}.", jid); - agent.send_message(jid.into_bare_jid(), MessageType::Groupchat, "en", "Hello world!"); + agent.send_message(Jid::Bare(jid), MessageType::Groupchat, "en", "Hello world!"); }, Event::RoomLeft(jid) => { println!("Left room {}.", jid); diff --git a/src/avatar.rs b/src/avatar.rs index 56aac06..4c6e588 100644 --- a/src/avatar.rs +++ b/src/avatar.rs @@ -6,6 +6,7 @@ use crate::Event; use futures::{sync::mpsc, Sink}; +use std::convert::TryFrom; use std::fs::{self, File}; use std::io::{self, Write}; use tokio_xmpp::Packet; @@ -19,7 +20,7 @@ use xmpp_parsers::{ NodeName, }, hashes::Hash, - Jid, TryFrom, + Jid, }; // TODO: Update xmpp-parsers to get this function for free on Hash. diff --git a/src/lib.rs b/src/lib.rs index 20fd1ef..a5b6e33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,7 @@ use std::str::FromStr; use std::rc::Rc; use std::cell::RefCell; +use std::convert::TryFrom; use futures::{Future,Stream, Sink, sync::mpsc}; use tokio_xmpp::{ Client as TokioXmppClient, @@ -38,7 +39,7 @@ use xmpp_parsers::{ }, roster::{Roster, Item as RosterItem}, stanza_error::{StanzaError, ErrorType, DefinedCondition}, - Jid, JidParseError, TryFrom, + Jid, BareJid, FullJid, JidParseError, }; mod avatar; @@ -84,8 +85,8 @@ pub enum Event { ContactChanged(RosterItem), AvatarRetrieved(Jid, String), OpenRoomBookmark(ConferenceBookmark), - RoomJoined(Jid), - RoomLeft(Jid), + RoomJoined(BareJid), + RoomLeft(BareJid), } #[derive(Default)] @@ -289,7 +290,10 @@ impl ClientBuilder<'_> { } } else if stanza.is("presence", "jabber:client") { let presence = Presence::try_from(stanza).unwrap(); - let from = presence.from.clone().unwrap(); + let from: BareJid = match presence.from.clone().unwrap() { + Jid::Full(FullJid { node, domain, .. }) => BareJid { node, domain }, + Jid::Bare(bare) => bare, + }; for payload in presence.payloads.into_iter() { let muc_user = match MucUser::try_from(payload) { Ok(muc_user) => muc_user, @@ -347,20 +351,17 @@ pub struct Agent { } impl Agent { - pub fn join_room(&mut self, room: Jid, nick: Option, password: Option, + pub fn join_room(&mut self, room: BareJid, nick: Option, password: Option, lang: &str, status: &str) { let mut muc = Muc::new(); if let Some(password) = password { muc = muc.with_password(password); } - // TODO: change room into a BareJid, which requires an update of jid, which requires an - // update of xmpp-parsers, which requires an update of tokio-xmpp… - assert_eq!(room.resource, None); let nick = nick.unwrap_or_else(|| self.default_nick.borrow().clone()); let room_jid = room.with_resource(nick); let mut presence = Presence::new(PresenceType::None) - .with_to(Some(room_jid)); + .with_to(Some(Jid::Full(room_jid))); presence.add_payload(muc); presence.set_status(String::from(lang), String::from(status)); let presence = presence.into();