Compare commits

...

2 commits

Author SHA1 Message Date
8065fdd8ff
Allow specifying a reason when parting 2023-11-17 10:17:32 +01:00
302ac9b050
cargo fmt 2023-11-17 10:17:20 +01:00

View file

@ -82,7 +82,10 @@ impl Cri {
let command = tokens.next().unwrap();
match command {
"/join" => {
let channel = tokens.next().map(str::to_string).or_else(|| self.message_log.active_channel.clone());
let channel = tokens
.next()
.map(str::to_string)
.or_else(|| self.message_log.active_channel.clone());
if channel.is_none() {
// TODO error message
return;
@ -94,16 +97,21 @@ impl Cri {
return;
}
self
.input_tx
.borrow()
.send(IrcCommand::JOIN(channel.clone(), tokens.next().map(str::to_string), None).into())
.unwrap();
self.input_tx
.borrow()
.send(
IrcCommand::JOIN(channel.clone(), tokens.next().map(str::to_string), None)
.into(),
)
.unwrap();
self.message_log.set_active(Some(channel));
},
}
"/part" => {
let channel = tokens.next().map(str::to_string).or_else(|| self.message_log.active_channel.clone());
let channel = tokens
.next()
.map(str::to_string)
.or_else(|| self.message_log.active_channel.clone());
if channel.is_none() {
// TODO error message
return;
@ -115,17 +123,17 @@ impl Cri {
return;
}
self
.input_tx
.borrow()
.send(
IrcCommand::PART(
channel,
tokens.next().map(str::to_string),
)
.into(),
)
.unwrap();
let reason = tokens.collect::<Vec<_>>().join(" ");
let reason = if reason.is_empty() {
None
} else {
Some(reason)
};
self.input_tx
.borrow()
.send(IrcCommand::PART(channel, reason).into())
.unwrap();
}
"/query" => self
.message_log
@ -182,7 +190,7 @@ impl Application for Cri {
.on_quit(&source_nickname, comment.as_deref());
}
IrcCommand::PRIVMSG(msgtarget, content) => {
IrcCommand::PRIVMSG(msgtarget, content) | IrcCommand::NOTICE(msgtarget, content) => {
let channel = message.response_target().unwrap_or(msgtarget).to_string();
self.message_log
.on_privmsg(&channel, &source_nickname, content);