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.
This commit is contained in:
Brendan Coles 2020-04-02 07:09:34 +00:00 committed by Andreas Kling
parent bb15b37228
commit b3d8ce44a2
Notes: sideshowbarker 2024-07-19 08:00:12 +09:00

View file

@ -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") {