From 6e982f0343b508c13a51bd42a545cbf6e301ff01 Mon Sep 17 00:00:00 2001 From: Sijmen Date: Fri, 1 Dec 2023 02:28:23 +0100 Subject: [PATCH] Add /quit command --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/cri.rs | 16 ++++++++++++++++ src/message_log.rs | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 19fabbe..1242e31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/Cargo.toml b/Cargo.toml index 80ab227..2d443a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/src/cri.rs b/src/cri.rs index 6695406..bf70d5c 100644 --- a/src/cri.rs +++ b/src/cri.rs @@ -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, diff --git a/src/message_log.rs b/src/message_log.rs index 7d2b15f..c3c6bd4 100644 --- a/src/message_log.rs +++ b/src/message_log.rs @@ -529,7 +529,7 @@ impl<'a> MessageLog { message_id: Option<&str>, timestamp: &DateTime, ) { - 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; }