OSDN Git Service

imported http://mrmt.net/src/keitairc/keitairc r1.9
authormorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sun, 21 Mar 2004 11:03:19 +0000 (11:03 +0000)
committermorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sun, 21 Mar 2004 11:03:19 +0000 (11:03 +0000)
keitairc

index 2a96977..0de76d3 100755 (executable)
--- a/keitairc
+++ b/keitairc
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # keitairc
-# $Id: keitairc,v 1.8 2004-03-21 11:02:59 morimoto Exp $
+# $Id: keitairc,v 1.9 2004-03-21 11:03:19 morimoto Exp $
 #
 # Copyright (c) 2003 Jun Morimoto <morimoto@xantia.citroen.org>
 # This program is covered by the GNU General Public License 2
@@ -8,15 +8,15 @@
 # Depends: libjcode-pm-perl, libpoe-component-irc-perl,
 #   liburi-perl, libwww-perl, libappconfig-perl
 
-my $rcsid = q$Id: keitairc,v 1.8 2004-03-21 11:02:59 morimoto Exp $;
+my $rcsid = q$Id: keitairc,v 1.9 2004-03-21 11:03:19 morimoto Exp $;
 my ($version) = $rcsid =~ m#,v ([0-9.]+)#;
 
 use strict;
 use Jcode;
 use POE;
 use POE::Component::Server::TCP;
-use POE::Component::IRC;
 use POE::Filter::HTTPD;
+use POE::Component::IRC;
 use URI::Escape;
 use HTTP::Response;
 use AppConfig qw(:argcount);
@@ -50,7 +50,10 @@ my %channel_name;
 my %channel_buffer;
 
 # \e$B3F%A%c%M%k$N:G=*%"%/%;%9;~9o!":G?7H/8@;~9o\e(B
-my (%atime, %mtime);
+my %mtime;
+
+# unread lines
+my %unread;
 
 # irc component
 POE::Component::IRC->new('keitairc');
@@ -137,6 +140,10 @@ sub add_message{
     }
 
     $mtime{$channel} = time;
+    $unread{$channel}++;
+    if ($unread{$channel} > $config->web_lines) {
+       $unread{$channel} = $config->web_lines;
+    }
 }
 
 ################################################################
@@ -176,34 +183,30 @@ sub index_page{
 
        $buf .= &label($accesskey);
 
-       unless(defined($channel_buffer{$channel})){
-           $buf .= &compact_channel_name($channel);
-       }else{
-           if($accesskey < 10){
-               $buf .= sprintf('<a accesskey="%1d" href="%s%s">%s</a>',
-                               $accesskey,
-                               $docroot,
-                               uri_escape($channel),
-                               &compact_channel_name($channel));
-           }else{
+            if($accesskey < 10){
+                $buf .= sprintf('<a accesskey="%1d" href="%s%s">%s</a>',
+                                $accesskey,
+                                $docroot,
+                                uri_escape($channel),
+                                &compact_channel_name($channel));
+            }else{
                $buf .= sprintf('<a href="%s%s">%s</a>',
-                               $docroot,
-                               uri_escape($channel),
-                               &compact_channel_name($channel));
-           }
-       }
+                                $docroot,
+                                uri_escape($channel),
+                                &compact_channel_name($channel));
+            }
 
        $accesskey++;
 
-       if($atime{$channel} < $mtime{$channel}){
-           $buf .= '*';
+       if($unread{$channel} > 0){
+           $buf .= sprintf(' (%d)', $unread{$channel});
        }
 
        $buf .= '<br>';
     }
 
     $buf .= qq(<a href="$docroot" accesskey="0"></a>);
-    $buf .= qq( - keitairc $version);
+    $buf .= qq( - keitairc $version +);
 
     $buf;
 }
@@ -317,6 +320,7 @@ sub on_web_request{
 
        $content .= '<a name="1"></a>';
        $content .= '<a accesskey="7" href="#1"></a>';
+       $content .= '<a accesskey="8" href="../"></a>';
 
        $content .= sprintf('<form action="%s%s" method="post">',
                            $docroot, $uri);
@@ -324,6 +328,7 @@ sub on_web_request{
        $content .= '<input type="submit" accesskey="1" value="OK">';
        # $content .= '<input type="submit" accesskey="1" value="&#63920;">';
        $content .= '</form>';
+        $content .= '<a href="../">..back (push 8)</a><BR>';
 
        if(defined($channel_name{$channel})){
            if(defined($channel_buffer{$channel}) &&
@@ -339,7 +344,7 @@ sub on_web_request{
            $content .= "no such channel";
        }
 
-       $atime{$channel} = time;
+        $unread{$channel} = 0;
     }
 
     $content .= '</body></html>';