summaryrefslogtreecommitdiff
path: root/Applications/IRCClient
diff options
context:
space:
mode:
authorBrendan Coles <bcoles@gmail.com>2020-04-02 14:39:25 +0000
committerAndreas Kling <kling@serenityos.org>2020-04-02 21:50:02 +0200
commit40b32039415b48074099ac13982b75bc33b08b26 (patch)
tree8b953316d50623ebc304fd2edd71ff5e4859cde0 /Applications/IRCClient
parent99aab4470a003dc71cb2c05f92a91a59e590cb99 (diff)
downloadserenity-40b32039415b48074099ac13982b75bc33b08b26.zip
IRCClient: Update channel user list when a user joins or quits
Diffstat (limited to 'Applications/IRCClient')
-rw-r--r--Applications/IRCClient/IRCChannel.cpp19
-rw-r--r--Applications/IRCClient/IRCChannel.h1
-rw-r--r--Applications/IRCClient/IRCClient.cpp17
-rw-r--r--Applications/IRCClient/IRCClient.h1
4 files changed, 37 insertions, 1 deletions
diff --git a/Applications/IRCClient/IRCChannel.cpp b/Applications/IRCClient/IRCChannel.cpp
index ae4efb0da6..b151b194fe 100644
--- a/Applications/IRCClient/IRCChannel.cpp
+++ b/Applications/IRCClient/IRCChannel.cpp
@@ -94,8 +94,12 @@ void IRCChannel::say(const String& text)
void IRCChannel::handle_join(const String& nick, const String& hostmask)
{
- if (nick == m_client.nickname())
+ if (nick == m_client.nickname()) {
m_open = true;
+ return;
+ }
+ add_member(nick, (char)0);
+ m_member_model->update();
add_message(String::format("*** %s [%s] has joined %s", nick.characters(), hostmask.characters(), m_name.characters()), Color::MidGreen);
}
@@ -112,6 +116,19 @@ void IRCChannel::handle_part(const String& nick, const String& hostmask)
add_message(String::format("*** %s [%s] has parted from %s", nick.characters(), hostmask.characters(), m_name.characters()), Color::MidGreen);
}
+void IRCChannel::handle_quit(const String& nick, const String& hostmask, const String& message)
+{
+ if (nick == m_client.nickname()) {
+ m_open = false;
+ m_members.clear();
+ m_client.did_part_from_channel({}, *this);
+ } else {
+ remove_member(nick);
+ }
+ m_member_model->update();
+ add_message(String::format("*** %s [%s] has quit (%s)", nick.characters(), hostmask.characters(), message.characters()), Color::MidGreen);
+}
+
void IRCChannel::handle_topic(const String& nick, const String& topic)
{
if (nick.is_null())
diff --git a/Applications/IRCClient/IRCChannel.h b/Applications/IRCClient/IRCChannel.h
index 3bb5a9675f..8bc8e58c06 100644
--- a/Applications/IRCClient/IRCChannel.h
+++ b/Applications/IRCClient/IRCChannel.h
@@ -68,6 +68,7 @@ public:
void handle_join(const String& nick, const String& hostmask);
void handle_part(const String& nick, const String& hostmask);
+ void handle_quit(const String& nick, const String& hostmask, const String& message);
void handle_topic(const String& nick, const String& topic);
IRCWindow& window() { return *m_window; }
diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp
index 2677fc9143..40a3c35748 100644
--- a/Applications/IRCClient/IRCClient.cpp
+++ b/Applications/IRCClient/IRCClient.cpp
@@ -290,6 +290,9 @@ void IRCClient::handle(const Message& msg)
if (msg.command == "PART")
return handle_part(msg);
+ if (msg.command == "QUIT")
+ return handle_quit(msg);
+
if (msg.command == "TOPIC")
return handle_topic(msg);
@@ -545,6 +548,20 @@ void IRCClient::handle_part(const Message& msg)
ensure_channel(channel_name).handle_part(nick, msg.prefix);
}
+void IRCClient::handle_quit(const Message& msg)
+{
+ if (msg.arguments.size() < 1)
+ return;
+ auto prefix_parts = msg.prefix.split('!');
+ if (prefix_parts.size() < 1)
+ return;
+ auto nick = prefix_parts[0];
+ auto& message = msg.arguments[0];
+ for (auto& it : m_channels) {
+ it.value->handle_quit(nick, msg.prefix, message);
+ }
+}
+
void IRCClient::handle_nick(const Message& msg)
{
auto prefix_parts = msg.prefix.split('!');
diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h
index b462f69a91..ec7204ea55 100644
--- a/Applications/IRCClient/IRCClient.h
+++ b/Applications/IRCClient/IRCClient.h
@@ -155,6 +155,7 @@ private:
void process_line(ByteBuffer&&);
void handle_join(const Message&);
void handle_part(const Message&);
+ void handle_quit(const Message&);
void handle_ping(const Message&);
void handle_topic(const Message&);
void handle_rpl_topic(const Message&);