root/lang/perl/mobirc/trunk/lib/App/Mobirc/HTTPD/C/Ajax.pm @ 12867

Revision 12867, 1.4 kB (checked in by tokuhirom, 6 years ago)

use HTTPx::Dispatcher!

Line 
1package App::Mobirc::HTTPD::C::Ajax;
2use Moose;
3use App::Mobirc::HTTPD::C;
4use App::Mobirc::Util;
5use Encode;
6
7sub dispatch_base {
8    my ($class, $c) = @_;
9
10    render_td(
11        $c,
12        'ajax/base' => (
13            $c->req->mobile_agent,
14            ($c->{config}->{httpd}->{root} || '/'),
15        )
16    );
17}
18
19sub dispatch_channel {
20    my ($class, $c, $args) = @_;
21    my $channel_name = uri_unescape $args->{channel};
22
23    my $channel = server->get_channel($channel_name);
24    render_td(
25        $c,
26        'ajax/channel' => (
27            $channel,
28            irc_nick
29        )
30    );
31    $channel->clear_unread();
32}
33
34sub post_dispatch_channel {
35    my ( $class, $c, $args) = @_;
36    my $channel = uri_unescape $args->{channel};
37
38    my $message = $c->req->parameters->{'msg'};
39    $message = decode( $c->req->mobile_agent->encoding, $message );
40
41    DEBUG "POST MESSAGE $message";
42
43    server->get_channel($channel)->post_command($message);
44
45    $c->res->body('ok');
46}
47
48sub dispatch_menu {
49    my ($class, $c ) = @_;
50
51    render_td(
52        $c,
53        'ajax/menu' => (
54            server,
55            server->keyword_channel->unread_lines,
56        )
57    );
58}
59
60sub dispatch_keyword {
61    my ($class, $c ) = @_;
62
63    render_td(
64        $c,
65        'ajax/keyword' => {
66            logs     => scalar(server->keyword_channel->message_log),
67            irc_nick => irc_nick,
68        }
69    );
70    server->keyword_channel->clear_unread();
71}
72
731;
Note: See TracBrowser for help on using the browser.