Add /quit command

This commit is contained in:
Sijmen 2023-12-01 02:28:23 +01:00
parent 22209bd133
commit 6e982f0343
Signed by: vijfhoek
GPG key ID: DAF7821E067D9C48
4 changed files with 34 additions and 1 deletions

16
Cargo.lock generated
View file

@ -482,6 +482,7 @@ dependencies = [
"futures",
"iced",
"irc",
"itertools",
"once_cell",
"regex",
"tokio",
@ -525,6 +526,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "either"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "encoding"
version = "0.2.33"
@ -1248,6 +1255,15 @@ dependencies = [
"tokio-util",
]
[[package]]
name = "itertools"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
dependencies = [
"either",
]
[[package]]
name = "jni-sys"
version = "0.3.0"

View file

@ -11,6 +11,7 @@ color-eyre = "0.6.2"
futures = "0.3.29"
iced = { version = "0.10.0", features = ["tokio"] }
irc = "0.15.0"
itertools = "0.12.0"
once_cell = "1.18.0"
regex = "1.10.2"
tokio = { version = "1.33.0", features = ["full"] }

View file

@ -10,6 +10,7 @@ use iced::{
use irc::proto::{
message::Tag, CapSubCommand, Capability, ChannelExt, Command as IrcCommand, Response,
};
use itertools::Itertools;
use once_cell::sync::Lazy;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
@ -65,6 +66,7 @@ impl Cri {
"/part" | "/p" => self.handle_part_command(&mut tokens),
"/query" | "/q" => self.handle_query_command(&mut tokens),
"/nick" | "/n" => self.handle_nick_command(&mut tokens),
"/quit" => self.handle_quit_command(&mut tokens),
"/list" => self.handle_list_command(),
_ => (),
}
@ -142,6 +144,20 @@ impl Cri {
.unwrap()
}
fn handle_quit_command(&self, tokens: &mut SplitWhitespace<'_>) {
let reason: String = tokens.intersperse(" ").collect();
let reason = if reason.trim().is_empty() {
None
} else {
Some(reason)
};
self.input_tx
.borrow()
.send(IrcCommand::QUIT(reason).into())
.unwrap()
}
fn on_join(
&mut self,
chanlist: &str,

View file

@ -529,7 +529,7 @@ impl<'a> MessageLog {
message_id: Option<&str>,
timestamp: &DateTime<Local>,
) {
let is_active = active_channel_name != Some(channel.channel_name.as_ref().unwrap());
let is_active = active_channel_name != channel.channel_name.as_deref();
if is_active {
channel.unread_events += 1;
}