diff --git a/lib/Convos/Core/Connection/Irc.pm b/lib/Convos/Core/Connection/Irc.pm index 7838813ac..53482be4e 100644 --- a/lib/Convos/Core/Connection/Irc.pm +++ b/lib/Convos/Core/Connection/Irc.pm @@ -136,6 +136,23 @@ sub _connect_args { return $self->SUPER::_connect_args; } +sub _irc_event_cap { + my ($self, $msg) = @_; + $self->_irc_event_fallback($msg); + + if ($msg->{raw_line} =~ m!\s(?:LIST|LS)[^:]+:(.*)!) { + $self->{myinfo}{capabilities}{$_} = true for split /\s/, $1; + my @cap_req; # TODO + $self->_write(@cap_req ? sprintf "CAP REQ :%s\r\n", join ' ', @cap_req : "CAP END\r\n"); + } + elsif ($msg->{raw_line} =~ m!\sACK\s:(.+)!) { + $self->_write("CAP END\r\n"); + } + elsif ($msg->{raw_line} =~ m!\sNAC!) { + $self->_write("CAP END\r\n"); + } +} + sub _irc_event_ctcpreply_rtcz { my ($self, $msg) = @_; my ($nick) = IRC::Utils::parse_user($msg->{prefix}); @@ -1042,6 +1059,7 @@ sub _stream { my $nick = $self->nick; my $user = $url->username || $nick; my $mode = $url->query->param('mode') || 0; + $self->_write("CAP LS\r\n"); $self->_write(sprintf "PASS %s\r\n", $url->password) if length $url->password; $self->_write("NICK $nick\r\n"); $self->_write("USER $user $mode * :https://convos.chat/\r\n"); diff --git a/t/irc-v3-capabilities.t b/t/irc-v3-capabilities.t new file mode 100644 index 000000000..bbe216343 --- /dev/null +++ b/t/irc-v3-capabilities.t @@ -0,0 +1,44 @@ +#!perl +BEGIN { $ENV{CONVOS_SKIP_CONNECT} = 1 } +use lib '.'; +use t::Helper; +use t::Server::Irc; +use Convos::Core; +use Convos::Core::Backend::File; + +my $server = t::Server::Irc->new->start; +my $core = Convos::Core->new; +my $user = $core->user({email => 'superwoman@example.com'}); +$user->save_p->$wait_success; + +note 'external'; +my $connection = $user->connection({name => 'example', protocol => 'irc'}); +$connection->url->userinfo('superwoman:superduper'); +$connection->save_p->$wait_success; + +$server->client($connection)->server_event_ok('_irc_event_cap')->server_event_ok('_irc_event_nick') + ->server_write_ok(":example CAP * LS * :account-notify away-notify chghost extended-join\r\n") + ->server_write_ok(":example CAP * LS :invite-notify multi-prefix sasl userhost-in-names\r\n") + ->client_event_ok('_irc_event_cap')->server_event_ok('_irc_event_cap') + ->server_write_ok( + "example 900 superwoman superwoman!superwoman\@localhost superwoman :You are now logged in as superwoman\r\n" +)->server_write_ok(['welcome.irc'])->client_event_ok('_irc_event_rpl_welcome') + ->process_ok('capabilities handshake'); + +is_deeply $connection->TO_JSON->{me}, + { + nick => 'superman', + capabilities => { + 'account-notify' => true, + 'away-notify' => true, + 'chghost' => true, + 'extended-join' => true, + 'invite-notify' => true, + 'multi-prefix' => true, + 'sasl' => true, + 'userhost-in-names' => true, + }, + }, + 'got capabilities'; + +done_testing;