1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:47:34 +00:00

IRCClient: Update channel user list when a user joins or quits

This commit is contained in:
Brendan Coles 2020-04-02 14:39:25 +00:00 committed by Andreas Kling
parent 99aab4470a
commit 40b3203941
4 changed files with 37 additions and 1 deletions

View file

@ -94,8 +94,12 @@ void IRCChannel::say(const String& text)
void IRCChannel::handle_join(const String& nick, const String& hostmask) void IRCChannel::handle_join(const String& nick, const String& hostmask)
{ {
if (nick == m_client.nickname()) if (nick == m_client.nickname()) {
m_open = true; 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); 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); 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) void IRCChannel::handle_topic(const String& nick, const String& topic)
{ {
if (nick.is_null()) if (nick.is_null())

View file

@ -68,6 +68,7 @@ public:
void handle_join(const String& nick, const String& hostmask); void handle_join(const String& nick, const String& hostmask);
void handle_part(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); void handle_topic(const String& nick, const String& topic);
IRCWindow& window() { return *m_window; } IRCWindow& window() { return *m_window; }

View file

@ -290,6 +290,9 @@ void IRCClient::handle(const Message& msg)
if (msg.command == "PART") if (msg.command == "PART")
return handle_part(msg); return handle_part(msg);
if (msg.command == "QUIT")
return handle_quit(msg);
if (msg.command == "TOPIC") if (msg.command == "TOPIC")
return handle_topic(msg); return handle_topic(msg);
@ -545,6 +548,20 @@ void IRCClient::handle_part(const Message& msg)
ensure_channel(channel_name).handle_part(nick, msg.prefix); 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) void IRCClient::handle_nick(const Message& msg)
{ {
auto prefix_parts = msg.prefix.split('!'); auto prefix_parts = msg.prefix.split('!');

View file

@ -155,6 +155,7 @@ private:
void process_line(ByteBuffer&&); void process_line(ByteBuffer&&);
void handle_join(const Message&); void handle_join(const Message&);
void handle_part(const Message&); void handle_part(const Message&);
void handle_quit(const Message&);
void handle_ping(const Message&); void handle_ping(const Message&);
void handle_topic(const Message&); void handle_topic(const Message&);
void handle_rpl_topic(const Message&); void handle_rpl_topic(const Message&);