Alice
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Alice.pm view on Meta::CPAN
$irc->cl(undef);
$self->remove_irc($name);
}
else {
$irc->removed(1);
$self->disconnect_irc($name);
}
}
}
}
sub announce {
my ($self, $window, $body) = @_;
$self->broadcast({
type => "action",
event => "announce",
body => $body
});
}
sub send_message {
my ($self, $window, $nick, $body) = @_;
my $irc = $self->get_irc($window->network);
my @messages = $window->format_message($nick, $body,
monospaced => $self->is_monospace_nick($nick),
self => $irc->nick eq $nick,
avatar => $irc->nick_avatar($nick) || "",
highlight => $self->is_highlight($irc->nick, $body),
);
if ($messages[0]->{highlight}) {
push @messages, $self->info_window->format_message(
$nick, $body, self => 1, source => $nick);
}
$self->broadcast(@messages);
}
sub send_info {
my ($self, $network, $body, %options) = @_;
return unless $body;
my $message = $self->info_window->format_message($network, $body, %options);
$self->broadcast($message);
}
sub broadcast {
my ($self, @messages) = @_;
return if $self->no_streams or !@messages;
for my $stream (@{$self->streams}) {
$stream->send(\@messages);
}
}
sub ping {
my $self = shift;
return if $self->no_streams;
$_->ping for grep {$_->is_xhr} @{$self->streams};
}
sub update_window {
my ($self, $stream, $window, $max, $min, $limit, $total, $cb) = @_;
my $step = 20;
if ($limit - $total < 20) {
$step = $limit - $total;
}
$window->buffer->messages($max, $min, $step, sub {
my $msgs = shift;
$stream->send([{
window => $window->serialized,
type => "chunk",
range => (@$msgs ? [$msgs->[0]{msgid}, $msgs->[-1]{msgid}] : []),
html => join "", map {$_->{html}} @$msgs,
}]);
$total += $step;
if (@$msgs == $step and $total < $limit) {
$max = $msgs->[0]->{msgid} - 1;
$self->update_window($stream, $window, $max, $min, $limit, $total, $cb);
}
else {
$cb->() if $cb;
return;
}
});
}
sub handle_message {
my ($self, $message) = @_;
if (my $window = $self->get_window($message->{source})) {
my $stream = first {$_->id eq $message->{stream}} @{$self->streams};
return unless $stream;
$message->{msg} = html_to_irc($message->{msg}) if $message->{html};
for my $line (split /\n/, $message->{msg}) {
next unless $line;
my $input = Alice::Request->new(
window => $window,
stream => $stream,
line => $line,
);
$self->irc_command($input);
}
}
}
sub purge_disconnects {
my ($self) = @_;
AE::log debug => "removing broken streams";
$self->streams([grep {!$_->closed} @{$self->streams}]);
}
sub render {
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.034 second using v1.00-cache-2.02-grep-82fe00e-cpan-b63e86051f13 )