From b6369741cdf14655310fd98cd59a977fa0f1fccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 11 Sep 2019 16:11:32 +0200 Subject: [PATCH] Update tokio-xmpp to 1.0.1 and xmpp-parsers to 0.15 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- Cargo.toml | 4 ++-- examples/hello_bot.rs | 4 ++-- src/avatar.rs | 3 ++- src/lib.rs | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e769b655..a9def97c 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 e374bf68..dcfd060d 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 56aac06a..4c6e588c 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 20fd1efd..a5b6e337 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();