mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 16:10:20 +00:00
IRCClient: Add ability to send query messages.
You can't open a query yet, but if someone starts one with you, you can respond at least.
This commit is contained in:
parent
7e3673f710
commit
08c15be0ca
Notes:
sideshowbarker
2024-07-19 15:02:24 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/08c15be0ca3
5 changed files with 21 additions and 3 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ class GNotifier;
|
|||
|
||||
class IRCClient {
|
||||
friend class IRCChannel;
|
||||
friend class IRCQuery;
|
||||
public:
|
||||
IRCClient(const String& address, int port = 6667);
|
||||
~IRCClient();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue