Merge branch 'update-deps' into 'master'

Update tokio-xmpp to 1.0.1 and xmpp-parsers to 0.15

See merge request linkmauve/xmpp-rs!3
This commit is contained in:
linkmauve 2019-09-12 19:38:06 +00:00
commit 1d05832616
4 changed files with 16 additions and 14 deletions

View file

@ -11,7 +11,7 @@ license = "MPL-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
tokio-xmpp = "1" tokio-xmpp = "1.0.1"
xmpp-parsers = "0.13" xmpp-parsers = "0.15"
futures = "0.1" futures = "0.1"
tokio = "0.1" tokio = "0.1"

View file

@ -8,7 +8,7 @@ use futures::prelude::*;
use std::env::args; use std::env::args;
use std::process::exit; use std::process::exit;
use tokio::runtime::current_thread::Runtime; use tokio::runtime::current_thread::Runtime;
use xmpp_parsers::message::MessageType; use xmpp_parsers::{message::MessageType, Jid};
use xmpp::{ClientBuilder, ClientType, ClientFeature, Event}; use xmpp::{ClientBuilder, ClientType, ClientFeature, Event};
fn main() { fn main() {
@ -60,7 +60,7 @@ fn main() {
}, },
Event::RoomJoined(jid) => { Event::RoomJoined(jid) => {
println!("Joined room {}.", 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) => { Event::RoomLeft(jid) => {
println!("Left room {}.", jid); println!("Left room {}.", jid);

View file

@ -6,6 +6,7 @@
use crate::Event; use crate::Event;
use futures::{sync::mpsc, Sink}; use futures::{sync::mpsc, Sink};
use std::convert::TryFrom;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{self, Write}; use std::io::{self, Write};
use tokio_xmpp::Packet; use tokio_xmpp::Packet;
@ -19,7 +20,7 @@ use xmpp_parsers::{
NodeName, NodeName,
}, },
hashes::Hash, hashes::Hash,
Jid, TryFrom, Jid,
}; };
// TODO: Update xmpp-parsers to get this function for free on Hash. // TODO: Update xmpp-parsers to get this function for free on Hash.

View file

@ -9,6 +9,7 @@
use std::str::FromStr; use std::str::FromStr;
use std::rc::Rc; use std::rc::Rc;
use std::cell::RefCell; use std::cell::RefCell;
use std::convert::TryFrom;
use futures::{Future,Stream, Sink, sync::mpsc}; use futures::{Future,Stream, Sink, sync::mpsc};
use tokio_xmpp::{ use tokio_xmpp::{
Client as TokioXmppClient, Client as TokioXmppClient,
@ -38,7 +39,7 @@ use xmpp_parsers::{
}, },
roster::{Roster, Item as RosterItem}, roster::{Roster, Item as RosterItem},
stanza_error::{StanzaError, ErrorType, DefinedCondition}, stanza_error::{StanzaError, ErrorType, DefinedCondition},
Jid, JidParseError, TryFrom, Jid, BareJid, FullJid, JidParseError,
}; };
mod avatar; mod avatar;
@ -84,8 +85,8 @@ pub enum Event {
ContactChanged(RosterItem), ContactChanged(RosterItem),
AvatarRetrieved(Jid, String), AvatarRetrieved(Jid, String),
OpenRoomBookmark(ConferenceBookmark), OpenRoomBookmark(ConferenceBookmark),
RoomJoined(Jid), RoomJoined(BareJid),
RoomLeft(Jid), RoomLeft(BareJid),
} }
#[derive(Default)] #[derive(Default)]
@ -289,7 +290,10 @@ impl ClientBuilder<'_> {
} }
} else if stanza.is("presence", "jabber:client") { } else if stanza.is("presence", "jabber:client") {
let presence = Presence::try_from(stanza).unwrap(); 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() { for payload in presence.payloads.into_iter() {
let muc_user = match MucUser::try_from(payload) { let muc_user = match MucUser::try_from(payload) {
Ok(muc_user) => muc_user, Ok(muc_user) => muc_user,
@ -347,20 +351,17 @@ pub struct Agent {
} }
impl Agent { impl Agent {
pub fn join_room(&mut self, room: Jid, nick: Option<String>, password: Option<String>, pub fn join_room(&mut self, room: BareJid, nick: Option<String>, password: Option<String>,
lang: &str, status: &str) { lang: &str, status: &str) {
let mut muc = Muc::new(); let mut muc = Muc::new();
if let Some(password) = password { if let Some(password) = password {
muc = muc.with_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 nick = nick.unwrap_or_else(|| self.default_nick.borrow().clone());
let room_jid = room.with_resource(nick); let room_jid = room.with_resource(nick);
let mut presence = Presence::new(PresenceType::None) let mut presence = Presence::new(PresenceType::None)
.with_to(Some(room_jid)); .with_to(Some(Jid::Full(room_jid)));
presence.add_payload(muc); presence.add_payload(muc);
presence.set_status(String::from(lang), String::from(status)); presence.set_status(String::from(lang), String::from(status));
let presence = presence.into(); let presence = presence.into();