Skip to content

Instantly share code, notes, and snippets.

@hirose31
Created August 4, 2008 15:56
Show Gist options
  • Save hirose31/3917 to your computer and use it in GitHub Desktop.
Save hirose31/3917 to your computer and use it in GitHub Desktop.
From 90869fbc8128f41a56d2dd1aa7526e5b36179e43 Mon Sep 17 00:00:00 2001
From: HIROSE Masaaki <hirose31@gmail.com>
Date: Tue, 5 Aug 2008 00:52:36 +0900
Subject: [PATCH] recent page show some channels recent log in mobile mode.
---
lib/App/Mobirc/ConfigLoader.pm | 5 +++--
lib/App/Mobirc/Web/C/Mobile.pm | 19 ++++++++++++++++---
lib/App/Mobirc/Web/Template/Mobile.pm | 32 +++++++++++++++++---------------
3 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/lib/App/Mobirc/ConfigLoader.pm b/lib/App/Mobirc/ConfigLoader.pm
index 3ed2fc4..fd89381 100644
--- a/lib/App/Mobirc/ConfigLoader.pm
+++ b/lib/App/Mobirc/ConfigLoader.pm
@@ -32,8 +32,9 @@ my $schema = {
type => 'map',
required => 1,
mapping => {
- lines => { type => 'int', },
- root => { type => 'str', },
+ lines => { type => 'int', },
+ recent_log_per_page => { type => 'int', },
+ root => { type => 'str', },
},
},
global => {
diff --git a/lib/App/Mobirc/Web/C/Mobile.pm b/lib/App/Mobirc/Web/C/Mobile.pm
index d4024db..4fc8c5b 100644
--- a/lib/App/Mobirc/Web/C/Mobile.pm
+++ b/lib/App/Mobirc/Web/C/Mobile.pm
@@ -25,22 +25,35 @@ sub dispatch_index {
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' => {
- channel => $unread_channels[0],
- has_next_page => (scalar(@unread_channels) >= 2 ? 1 : 0),
+ channels => ¥@target_channels,
+ has_next_page => $has_next_page,
irc_nick => irc_nick,
mobile_agent => $c->req->mobile_agent,
},
);
# reset counter.
- if (my $channel = $unread_channels[0]) {
+ for my $channel (@target_channels) {
$channel->clear_unread;
}
diff --git a/lib/App/Mobirc/Web/Template/Mobile.pm b/lib/App/Mobirc/Web/Template/Mobile.pm
index a135a4b..a4e25e7 100644
--- a/lib/App/Mobirc/Web/Template/Mobile.pm
+++ b/lib/App/Mobirc/Web/Template/Mobile.pm
@@ -144,30 +144,32 @@ template 'mobile/recent' => sub {
my $self = shift;
my %args = validate(
@_ => {
- channel => 1,
+ channels => 1,
has_next_page => 1,
irc_nick => 1,
mobile_agent => 1,
}
);
- my $channel = $args{channel} or die 'missing channel';
show 'wrapper_mobile', $args{mobile_agent}, sub {
- div {
- class is 'ChannelHeader';
- a {
- class is 'ChannelName';
- $channel->name;
- };
- a {
- href is '/mobile/channel?channel=' . $channel->name_urlsafe_encoded();
- 'more...';
+ for my $channel ( @{ $args{channels} } ) {
+ div {
+ class is 'ChannelHeader';
+ a {
+ class is 'ChannelName';
+ $channel->name;
+ };
+ a {
+ href is '/mobile/channel?channel=' . $channel->name_urlsafe_encoded();
+ 'more...';
+ };
};
- };
- for my $message (@{$channel->recent_log}) {
- show '../irc_message', $message, $args{irc_nick};
- br { };
+ for my $message (@{$channel->recent_log}) {
+ show '../irc_message', $message, $args{irc_nick};
+ br { };
+ }
+ hr {};
}
if ($args{has_next_page}) {
--
1.5.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment