diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index 2d2d656c6a..308516801d 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -9,7 +9,7 @@ IRCAppWindow::IRCAppWindow() : GWindow() , m_client("127.0.0.1", 6667) { - set_title(String::format("IRC Client: %s:%d", m_client.hostname().characters(), m_client.port())); + set_title(String::format("IRC Client: %s@%s:%d", m_client.nickname().characters(), m_client.hostname().characters(), m_client.port())); set_rect(200, 200, 600, 400); setup_client(); setup_widgets(); @@ -25,10 +25,18 @@ void IRCAppWindow::setup_client() m_client.join_channel("#test"); }; + m_client.on_channel_message = [this] (const String& channel_name) { + ensure_window(IRCClientWindow::Channel, channel_name); + }; + m_client.on_join = [this] (const String& channel_name) { ensure_window(IRCClientWindow::Channel, channel_name); }; + m_client.on_query_message = [this] (const String& name) { + ensure_window(IRCClientWindow::Query, name); + }; + m_client.connect(); } diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index 478412cfc1..f27770cc6c 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -253,6 +253,7 @@ void IRCClient::handle_user_input_in_query(const String& query_name, const Strin { if (input.is_empty()) return; + ensure_query(query_name).say(input); } void IRCClient::handle_user_input_in_server(const String& input) @@ -307,7 +308,7 @@ void IRCClient::handle_privmsg(const Message& msg) auto& query = ensure_query(sender_nick); query.add_message(sender_prefix, sender_nick, msg.arguments[1]); if (on_query_message) - on_query_message(target); + on_query_message(sender_nick); } IRCQuery& IRCClient::ensure_query(const String& name) @@ -336,7 +337,7 @@ void IRCClient::handle_ping(const Message& msg) { if (msg.arguments.size() < 0) return; - m_log->add_message(0, "", String::format("Ping? Pong! %s\n", msg.arguments[0].characters())); + m_log->add_message(0, "Server", "Ping? Pong!"); send_pong(msg.arguments[0]); } diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index 04771b722a..7c341db494 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -14,6 +14,7 @@ class GNotifier; class IRCClient { friend class IRCChannel; + friend class IRCQuery; public: IRCClient(const String& address, int port = 6667); ~IRCClient(); diff --git a/Applications/IRCClient/IRCQuery.cpp b/Applications/IRCClient/IRCQuery.cpp index 65ffd3deb1..53e180464e 100644 --- a/Applications/IRCClient/IRCQuery.cpp +++ b/Applications/IRCClient/IRCQuery.cpp @@ -30,3 +30,9 @@ void IRCQuery::add_message(char prefix, const String& name, const String& text) log().add_message(prefix, name, text); dump(); } + +void IRCQuery::say(const String& text) +{ + m_client.send_privmsg(m_name, text); + add_message(' ', m_client.nickname(), text); +} diff --git a/Applications/IRCClient/IRCQuery.h b/Applications/IRCClient/IRCQuery.h index 629c6fbbe3..55da4273ec 100644 --- a/Applications/IRCClient/IRCQuery.h +++ b/Applications/IRCClient/IRCQuery.h @@ -22,6 +22,8 @@ public: const IRCLogBuffer& log() const { return *m_log; } IRCLogBuffer& log() { return *m_log; } + void say(const String&); + private: IRCQuery(IRCClient&, const String& name);