From 3805c7c9146903e6c23a663793d42cdd506eeae8 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Thu, 21 May 2015 22:55:49 -0400 Subject: [PATCH] Added support for IRCv3.1 extended-join. --- src/client/data/caps.rs | 4 ++++ src/client/data/command.rs | 27 +++++++++++++++++---------- src/client/server/mod.rs | 2 +- src/client/server/utils.rs | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/client/data/caps.rs b/src/client/data/caps.rs index fda05f3..e5b355a 100644 --- a/src/client/data/caps.rs +++ b/src/client/data/caps.rs @@ -10,6 +10,8 @@ pub enum Capability { AccountNotify, /// [away-notify](http://ircv3.net/specs/extensions/away-notify-3.1.html) AwayNotify, + /// [extended-join](http://ircv3.net/specs/extensions/extended-join-3.1.html) + ExtendedJoin, } impl AsRef for Capability { @@ -18,6 +20,7 @@ impl AsRef for Capability { Capability::MultiPrefix => "multi-prefix", Capability::AccountNotify => "account-notify", Capability::AwayNotify => "away-notify", + Capability::ExtendedJoin => "extended-join", } } } @@ -31,5 +34,6 @@ mod test { assert_eq!(MultiPrefix.as_ref(), "multi-prefix"); assert_eq!(AccountNotify.as_ref(), "account-notify"); assert_eq!(AwayNotify.as_ref(), "away-notify"); + assert_eq!(ExtendedJoin.as_ref(), "extended-join"); } } diff --git a/src/client/data/command.rs b/src/client/data/command.rs index 3ba9642..b71c789 100644 --- a/src/client/data/command.rs +++ b/src/client/data/command.rs @@ -31,7 +31,7 @@ pub enum Command { // 3.2 Channel operations /// JOIN chanlist [chankeys] - JOIN(String, Option), + JOIN(String, Option, Option), /// PART chanlist :[comment] PART(String, Option), // MODE is already defined. @@ -152,7 +152,9 @@ pub enum Command { /// ACCOUNT [account name] ACCOUNT(String), // AWAY is already defined as a send-only message. - //AWAY(Option), + // AWAY(Option), + // JOIN is already defined. + // JOIN(String, Option, Option), } impl Into for Command { @@ -175,10 +177,10 @@ impl Into for Command { Command::QUIT(None) => Message::from_owned(None, string("QUIT"), None, None), Command::SQUIT(s, c) => Message::from_owned(None, string("SQUIT"), Some(vec![s]), Some(c)), - Command::JOIN(c, Some(k)) => - Message::from_owned(None, string("JOIN"), Some(vec![c, k]), None), - Command::JOIN(c, None) => - Message::from_owned(None, string("JOIN"), Some(vec![c]), None), + Command::JOIN(c, Some(k), n) => + Message::from_owned(None, string("JOIN"), Some(vec![c, k]), n), + Command::JOIN(c, None, n) => + Message::from_owned(None, string("JOIN"), Some(vec![c]), n), Command::PART(c, Some(m)) => Message::from_owned(None, string("PART"), Some(vec![c]), Some(m)), Command::PART(c, None) => @@ -427,16 +429,21 @@ impl Command { } else if let "JOIN" = &m.command[..] { match m.suffix { Some(ref suffix) => if m.args.len() == 0 { - Command::JOIN(suffix.clone(), None) + Command::JOIN(suffix.clone(), None, None) } else if m.args.len() == 1 { - Command::JOIN(m.args[0].clone(), Some(suffix.clone())) + Command::JOIN(m.args[0].clone(), Some(suffix.clone()), None) + } else if m.args.len() == 2 { + Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), Some(suffix.clone())) } else { return Err(invalid_input()) }, None => if m.args.len() == 1 { - Command::JOIN(m.args[0].clone(), None) + Command::JOIN(m.args[0].clone(), None, None) } else if m.args.len() == 2 { - Command::JOIN(m.args[0].clone(), Some(m.args[1].clone())) + Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), None) + } else if m.args.len() == 3 { + Command::JOIN(m.args[0].clone(), Some(m.args[1].clone()), + Some(m.args[2].clone())) } else { return Err(invalid_input()) } diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index 3750b31..34b2306 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -150,7 +150,7 @@ impl IrcServer { self.config.umodes().to_owned(), None)).unwrap(); } for chan in self.config.channels().into_iter() { - self.send(JOIN(chan.to_owned(), None)).unwrap(); + self.send(JOIN(chan.to_owned(), None, None)).unwrap(); } } else if resp == Response::ERR_NICKNAMEINUSE || resp == Response::ERR_ERRONEOUSNICKNAME { diff --git a/src/client/server/utils.rs b/src/client/server/utils.rs index 922c876..7c18253 100644 --- a/src/client/server/utils.rs +++ b/src/client/server/utils.rs @@ -40,7 +40,7 @@ pub trait ServerExt<'a, T, U>: Server<'a, T, U> { /// Joins the specified channel or chanlist. fn send_join(&self, chanlist: &str) -> Result<()> { - self.send(JOIN(chanlist.to_owned(), None)) + self.send(JOIN(chanlist.to_owned(), None, None)) } /// Attempts to oper up using the specified username and password.