# -*-perl-*-
# keitairc/lib/plugins/00unread
# チャネルの未読メッセージ閲覧
# $Id: 00unread,v 1.1 2008/01/09 19:30:34 morimoto Exp $
# $Source: /cvsroot/keitairc/lib/plugins/00unread,v $

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

		::send_message($request, $channel);

		my $buf;
		my $no_message_here_yet;
		if(defined($::ib->name($channel))){
			if(length($::ib->buffer($channel))){
				$buf = ::render_line($::ib->unread($channel), $session_id) ||
					'(未読発言はありません)';
				$buf .= sprintf('<hr /><a accesskey="5" href="../all/%s">[5] 全発言へ</a><br />',
						::uri_escape($channel));
			}else{
				$no_message_here_yet = 1;
			}
		}else{
			$buf = '指定のﾁｬﾈﾙは存在しません';
		}

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

		my $ci = new Keitairc::ClientInfo($request);
		my $view = new Keitairc::View($::cf, $ci);
		return $view->render('unread.html', {
			buf => $buf,
			channel_compact => $::ib->compact_channel_name($::ib->name($channel)),
			channel => ::uri_escape($channel),
			no_message_here_yet => $no_message_here_yet,
			ipod => $ci->is_ipod(),
			     });
	}
};

1;
