package App::Mobirc::Web::C::Mobile; use Moose; use App::Mobirc::Web::C; use App::Mobirc::Util; use URI::Escape qw(uri_escape_utf8); use Encode; use Encode::JP::Mobile; use MIME::Base64::URLSafe qw(urlsafe_b64decode); sub dispatch_index { my ($class, $c) = @_; return render_td( $c, 'mobile/top' => { exists_recent_entries => scalar( grep { $_->unread_lines } server->channels ), mobile_agent => $c->req->mobile_agent, keyword_recent_num => server->keyword_channel->unread_lines(), channels => scalar( server->channels_sorted ), } ); } # recent messages on every channel sub dispatch_recent { my ($class, $c) = @_; my @target_channels; my $log_counter = 0; my $has_next_page = 0; my @unread_channels = grep { $_->unread_lines } context->channels; for my $channel (@unread_channels) { push @target_channels, $channel; $log_counter += $channel->recent_log_count; if ($log_counter >= App::Mobirc->context->{config}->{httpd}->{recent_log_per_page}) { $has_next_page = 1; last; } } my $out = render_td( $c, 'mobile/recent' => { channels => \@target_channels, has_next_page => $has_next_page, irc_nick => irc_nick, mobile_agent => $c->req->mobile_agent, }, ); # reset counter. for my $channel (@target_channels) { $channel->clear_unread; } return $out; } # SHOULD USE http://example.com/ INSTEAD OF http://example.com:portnumber/ # because au phone returns '400 Bad Request' when redrirect to http://example.com:portnumber/ sub dispatch_clear_all_unread { my ($class, $c) = @_; for my $channel (server->channels) { $channel->clear_unread; } $c->res->redirect('/mobile/'); } # topic on every channel sub dispatch_topics { my ($class, $c) = @_; render_td( $c => ( 'mobile/topics' => { mobile_agent => $c->req->mobile_agent, channels => scalar( server->channels ), } ) ); } sub dispatch_keyword { my ($class, $c, ) = @_; my $channel = server->keyword_channel; render_td( $c, 'mobile/keyword' => { mobile_agent => $c->req->mobile_agent, rows => ( $c->req->params->{recent_mode} ? scalar($channel->recent_log) : scalar($channel->message_log) ), irc_nick => irc_nick, }, ); $channel->clear_unread; } sub decode_urlsafe_encoded { my $name = shift; decode_utf8 urlsafe_b64decode($name); } sub dispatch_channel { my ($class, $c, $args, ) = @_; my $channel_name = decode_urlsafe_encoded $c->req->params->{channel}; DEBUG "show channel page: $channel_name"; my $channel = context->get_channel($channel_name); render_td( $c, 'mobile/channel' => { mobile_agent => $c->req->mobile_agent, channel => $channel, recent_mode => $c->req->params->{recent_mode} || undef, message => $c->req->params->{'msg'} || '', channel_page_option => context->run_hook('channel_page_option', $channel, $c) || [], irc_nick => irc_nick, } ); $channel->clear_unread; } sub post_dispatch_channel { my ( $class, $c, $args) = @_; my $channel_name = decode_urlsafe_encoded $c->req->params->{channel}; my $message = $c->req->params->{'msg'}; DEBUG "POST MESSAGE $message"; my $channel = context->get_channel($channel_name); $channel->post_command($message); $c->res->redirect( $c->req->uri->path . "?channel=" . $channel->name_urlsafe_encoded); } 1;