use Irssi;
use vars qw($VERSION %IRSSI);
use Data::Dumper;

$VERSION = "0.1";
%IRSSI = (
	authors		=> 'Tom Wesley',
	contact		=> 'tom@tomaw.net',
	name		=> 'activity_skip',
	description	=> 'Skips activity bar on certain messages',
	license		=> 'as-is',
	modules		=> '',
	sbitems		=> '',
);

my (%actcheck);

sub change {
	my ($window, $oldwindow) = @_;
	return unless $$window{refnum} > 1;
#Irssi::print("window change: Changed $$window{refnum} from $actcheck{$$window{refnum}} to 0");
	$actcheck{$$window{refnum}} = 0;
}

sub check_act {
	my ($window, $hilight) = @_;
	return unless $$window{refnum} > 1;
#Irssi::print("activity: Changed $$window{refnum} from $actcheck{$$window{refnum}} to $hilight");
	$actcheck{$$window{refnum}} = $hilight;
}

sub check {
	my ($window, $fg, $bg, $flags, $text, $text_dest) = @_;
	return unless $$window{refnum} > 1;
	my ($regexp) = Irssi::settings_get_str('actskip_regexp');
	if ($window && $text =~ /$regexp/ && $actcheck{$$window{refnum}} eq 0)
	{
#Irssi::print("activity: $$window{refnum} Text: $text regex: $regexp state: $actcheck{$$window{refnum}}");
		Irssi::signal_emit('window dehilight', $window);
	} else {
#Irssi::print("activity: $$window{refnum} Text: $text regex: $regexp state: $actcheck{$$window{refnum}}");
#if ($text =~ /$regexp/){
#Irssi::print("MATCH!");
#}
	}
}

Irssi::signal_add_first('gui print text', 'check');
Irssi::signal_add('window activity', 'check_act');
Irssi::signal_add('window changed', 'change');

Irssi::settings_add_str($IRSSI{name}, 'actskip_regexp', '');
