From b3d8ce44a2ed705b41c5d13f44fcd2ea6751eb3c Mon Sep 17 00:00:00 2001 From: Brendan Coles Date: Thu, 2 Apr 2020 07:09:34 +0000 Subject: [PATCH] IRCClient: Use active channel window for part,hop,topic,kick commands The /part, /hop, /topic, /kick commands will now default to the currently active window if no channel name was provided. --- Applications/IRCClient/IRCClient.cpp | 69 ++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 13 deletions(-) diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index bb30436a55..b2006da09d 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -687,32 +687,75 @@ void IRCClient::handle_user_command(const String& input) return; } if (command == "/PART") { - if (parts.size() >= 2) - part_channel(parts[1]); + if (parts.size() >= 2) { + auto channel = parts[1]; + part_channel(channel); + } else { + auto* window = current_window(); + if (!window || window->type() != IRCWindow::Type::Channel) + return; + auto channel = window->channel().name(); + join_channel(channel); + } return; } if (command == "/HOP") { if (parts.size() >= 2) { - part_channel(parts[1]); - join_channel(parts[1]); + auto channel = parts[1]; + part_channel(channel); + join_channel(channel); + } else { + auto* window = current_window(); + if (!window || window->type() != IRCWindow::Type::Channel) + return; + auto channel = window->channel().name(); + part_channel(channel); + join_channel(channel); } return; } if (command == "/TOPIC") { - if (parts.size() < 3) + if (parts.size() < 2) return; - auto channel = parts[1]; - auto topic = input.view().substring_view_starting_after_substring(channel); - send_topic(channel, topic); + + // FIXME: channel name validation should be abstracted away into a validation function + if (parts[1].starts_with("&") || parts[1].starts_with("#") || parts[1].starts_with("+") || parts[1].starts_with("!")) { + if (parts.size() < 3) + return; + auto channel = parts[1]; + auto topic = input.view().substring_view_starting_after_substring(channel); + send_topic(channel, topic); + } else { + auto* window = current_window(); + if (!window || window->type() != IRCWindow::Type::Channel) + return; + auto channel = window->channel().name(); + auto topic = input.view().substring_view_starting_after_substring(parts[0]); + send_topic(channel, topic); + } return; } if (command == "/KICK") { - if (parts.size() < 3) + if (parts.size() < 2) return; - auto channel = parts[1]; - auto nick = parts[2]; - auto reason = input.view().substring_view_starting_after_substring(nick); - send_kick(channel, nick, reason); + + // FIXME: channel name validation should be abstracted away into a validation function + if (parts[1].starts_with("&") || parts[1].starts_with("#") || parts[1].starts_with("+") || parts[1].starts_with("!")) { + if (parts.size() < 3) + return; + auto channel = parts[1]; + auto nick = parts[2]; + auto reason = input.view().substring_view_starting_after_substring(nick); + send_kick(channel, nick, reason); + } else { + auto* window = current_window(); + if (!window || window->type() != IRCWindow::Type::Channel) + return; + auto channel = window->channel().name(); + auto nick = parts[1]; + auto reason = input.view().substring_view_starting_after_substring(nick); + send_kick(channel, nick, reason); + } return; } if (command == "/LIST") {