diff options
author | dakkar <dakkar@thenautilus.net> | 2016-12-27 16:34:27 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2016-12-27 16:34:27 +0000 |
commit | c6ffe49bff0a41046d4dd64d1f293f925b0f37e1 (patch) | |
tree | 54dc94688787f810d921ddd0df0188797d492909 | |
parent | list & show moderation queue contents (diff) | |
download | Sietima-c6ffe49bff0a41046d4dd64d1f293f925b0f37e1.tar.gz Sietima-c6ffe49bff0a41046d4dd64d1f293f925b0f37e1.tar.bz2 Sietima-c6ffe49bff0a41046d4dd64d1f293f925b0f37e1.zip |
mailstore: retrieve_ids_by_tags
-rw-r--r-- | lib/Sietima/MailStore.pm | 2 | ||||
-rw-r--r-- | lib/Sietima/MailStore/FS.pm | 12 | ||||
-rw-r--r-- | t/lib/Test/Sietima/MailStore.pm | 9 | ||||
-rw-r--r-- | t/tests/sietima/mailstore.t | 30 |
4 files changed, 51 insertions, 2 deletions
diff --git a/lib/Sietima/MailStore.pm b/lib/Sietima/MailStore.pm index d26d475..009580d 100644 --- a/lib/Sietima/MailStore.pm +++ b/lib/Sietima/MailStore.pm @@ -2,6 +2,6 @@ package Sietima::MailStore; use Moo::Role; use Sietima::Policy; -requires 'store','retrieve_by_tags','retrieve_by_id','remove','clear'; +requires 'store','retrieve_ids_by_tags','retrieve_by_tags','retrieve_by_id','remove','clear'; 1; diff --git a/lib/Sietima/MailStore/FS.pm b/lib/Sietima/MailStore/FS.pm index a45b433..6f872c1 100644 --- a/lib/Sietima/MailStore/FS.pm +++ b/lib/Sietima/MailStore/FS.pm @@ -58,7 +58,7 @@ sub _tagged_by($self,$tag) { return $tag_file->lines({chomp=>1}); } -sub retrieve_by_tags($self,@tags) { +sub retrieve_ids_by_tags($self,@tags) { state $check = compile(Object,slurpy ArrayRef[Str]);$check->(@_); my %msgs; @@ -74,6 +74,16 @@ sub retrieve_by_tags($self,@tags) { my @ret; for my $id (keys %msgs) { next unless $msgs{$id} == @tags; + push @ret, $id; + } + return \@ret; +} + +sub retrieve_by_tags($self,@tags) { + state $check = compile(Object,slurpy ArrayRef[Str]);$check->(@_); + + my @ret; + for my $id ($self->retrieve_ids_by_tags(@tags)->@*) { push @ret, { id => $id, mail => $self->retrieve_by_id($id), diff --git a/t/lib/Test/Sietima/MailStore.pm b/t/lib/Test/Sietima/MailStore.pm index 030e5fc..64c7b41 100644 --- a/t/lib/Test/Sietima/MailStore.pm +++ b/t/lib/Test/Sietima/MailStore.pm @@ -25,6 +25,15 @@ sub store ($self,$mail,@tags) { return $id; } +sub retrieve_ids_by_tags ($self,@tags){ + my @ret; + for my $m (values $self->_mails->%*) { + next unless all { $m->{tags}{$_} } @tags; + push @ret, $m->{id}; + } + return \@ret; +} + sub retrieve_by_tags ($self,@tags){ my @ret; for my $m (values $self->_mails->%*) { diff --git a/t/tests/sietima/mailstore.t b/t/tests/sietima/mailstore.t index b7991a5..c03fc1c 100644 --- a/t/tests/sietima/mailstore.t +++ b/t/tests/sietima/mailstore.t @@ -81,6 +81,36 @@ sub test_store($store) { ); }; + subtest 'retrieving ids by tag' => sub { + my $tag1 = $store->retrieve_ids_by_tags('tag1'); + is( + $tag1, + bag { item $stored_id{1}; item $stored_id{3}; end }, + 'tag1 should have ids 1 & 3', + ); + + my $tag2 = $store->retrieve_ids_by_tags('tag2'); + is( + $tag2, + bag { item $stored_id{1}; item $stored_id{2}; end }, + 'tag1 should have ids 1 & 2', + ); + + my $tag12 = $store->retrieve_ids_by_tags('tag2','tag1'); + is( + $tag12, + bag { item $stored_id{1}; end }, + 'tag1+tag2 should have id 1', + ); + + my $tag_all = $store->retrieve_ids_by_tags(); + is( + $tag_all, + bag { item $stored_id{1}; item $stored_id{2}; item $stored_id{3}; end }, + 'no tags should retrieve all ids', + ); + }; + subtest 'removing' => sub { $store->remove($stored_id{2}); is( |