# -*- mode: perl; coding: utf-8 -*-
# keitairc/lib/plugins/00unread
# チャネルの未読メッセージ閲覧
# $Id: 00unread,v 1.9 2008-07-17 15:35:52 morimoto Exp $
# $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/plugins/00unread,v $

# The line number (1 incremented) and filename below must be
# actual. see perlsyn.
# line 10 "keitairc/lib/plugins/00unread"

$plugin = {
	name => 'unread',
	action_imprementation => sub {
		my ($request, $name, $session_id, $param_string) = @_;
		my $cid = $param_string;
		my $channel = $::ib->cid2name($cid);

		::send_message($request, $channel);

		my $buf;
		if(defined($::ib->cid2name($cid))){
			if(defined($::ib->buffer($cid))){
				$buf = ::render_line($::ib->unread($cid), $session_id, $::cf->reverse_unread);
			}
		}

		$::ib->message_added(0); # clear check flags
		$::ib->clear_unread($cid);

		my $ci = new Keitairc::ClientInfo($request);
		my $view = new Keitairc::View($::cf, $ci);
		return $view->render('unread.html', {
			buf => $buf,
			channel_compact => $::ib->simple_escape(encode($::cf->web_charset(), $::ib->compact_channel_name($cid))),
			cid => $cid,
			stamp => time,
			     });
	}
};

1;
