Skip to content

Commit

Permalink
get new ignore system working
Browse files Browse the repository at this point in the history
  • Loading branch information
leedo committed Oct 11, 2011
1 parent fcbe978 commit eb4720a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
16 changes: 7 additions & 9 deletions lib/Alice.pm
Expand Up @@ -466,25 +466,23 @@ sub is_monospace_nick {
}

sub is_ignore {
my ($self, $nick) = @_;
any {$_ eq $nick} $self->config->ignores;
my $self = shift;
return $self->config->is_ignore(@_);
}

sub add_ignore {
my ($self, $nick) = @_;
$self->config->add_ignore($nick);
$self->config->write;
my $self = shift;
return $self->config->add_ignore(@_);
}

sub remove_ignore {
my ($self, $nick) = @_;
$self->config->ignore([ grep {$nick ne $_} $self->config->ignores ]);
$self->config->write;
my $self = shift;
return $self->config->remove_ignore(@_);
}

sub ignores {
my $self = shift;
return $self->config->ignores;
return $self->config->ignores(@_);
}

sub static_url {
Expand Down
44 changes: 40 additions & 4 deletions lib/Alice/Config.pm
Expand Up @@ -81,12 +81,21 @@ has tabsets => (
default => sub {{}},
);

has [qw/ignore highlights order monospace_nicks/]=> (
has [qw/highlights order monospace_nicks/]=> (
is => 'rw',
isa => 'ArrayRef[Str]',
default => sub {[]},
);

has ignore => (
is => 'rw',
isa => 'HashRef[ArrayRef]',
default => sub {
+{ msg => [], 'join' => [], part => [] }
}
);


has servers => (
is => 'rw',
isa => 'HashRef[HashRef]',
Expand Down Expand Up @@ -147,9 +156,6 @@ has enable_logging => (
default => 1,
);

sub ignores {@{$_[0]->ignore}}
sub add_ignore {push @{shift->ignore}, @_}

sub BUILD {
my $self = shift;
$self->load;
Expand All @@ -176,6 +182,12 @@ sub load {
my $body;
aio_load $self->fullpath, $body, sub {
$config = eval $body;

# upgrade ignore to new format
if ($config->{ignore} and ref $config->{ignore} eq "ARRAY") {
$config->{ignore} = {msg => $config->{ignore}};
}

if ($@) {
warn "error loading config: $@\n";
}
Expand Down Expand Up @@ -276,5 +288,29 @@ sub serialized {
};
}

sub ignores {
my ($self, $type) = @_;
$type ||= "msg";
@{$self->ignore->{$type} || []}
}

sub is_ignore {
my ($self, $type, $nick) = @_;
$type ||= "msg";
any {$_ eq $nick} $self->ignores($type);
}

sub add_ignore {
my ($self, $type, $nick) = @_;
push @{$self->ignore->{$type}}, $nick;
$self->write;
}

sub remove_ignore {
my ($self, $type, $nick) = @_;
$self->ignore->{$type} = [ grep {$nick ne $_} $self->ignores($type) ];
$self->write;
}

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit eb4720a

Please sign in to comment.