# Type: Input # Category: Issue # Description: List watched projects and issues # Author: Andriy Lesyuk new Orangutan::Context( response => [ '^(?:What|which) (?:(projects|issues) )?(?:(?:am|do) )?I (?:watch|follow)(?:ing)?\?*!*\.*$', '^(?:(?:Show|list) )?(?:(?:my|the) )?watched (projects|issues)!*\.*$', '^(?:Show )?(?:(?:my|the) )?watch list!*\.*$' ], handler => sub { my ($context, $user, $item, $watch) = @_; my %watched = ( ); if (!defined($watch) || (lc($watch) eq 'projects')) { $watched{'projects'} = [ ]; } if (!defined($watch) || (lc($watch) eq 'issues')) { $watched{'issues'} = [ ]; } if ($main::query->GetWatched($user->GetUserID, defined($watch) ? lc($watch) : undef)) { while (defined(my $item = $main::query->Next)) { if (lc($item->{'watchable_type'}) eq 'project') { push(@{$watched{'projects'}}, $item); } elsif (lc($item->{'watchable_type'}) eq 'issue') { push(@{$watched{'issues'}}, $item); } } } my $message = ''; if ((defined($watched{'projects'}) && (scalar @{$watched{'projects'}} > 0)) && (defined($watched{'issues'}) && (scalar @{$watched{'issues'}} > 0))) { $message = Orangutan::Context::Random( 'You are watching the following', 'Here is your watch list', 'Here is what you watch' ); $message .= ":\n"; } if (defined($watched{'projects'}) && (scalar @{$watched{'projects'}} > 0)) { if (defined($watched{'issues'}) && (scalar @{$watched{'issues'}} > 0)) { $message .= sprintf('Projects (%d)', scalar @{$watched{'projects'}}); $message .= ":\n"; } else { $message .= Orangutan::Context::Random( 'You receive notifications about the following projects', 'You are watching the following projects', 'Projects you watch are' ); $message .= ":\n"; } foreach my $project (@{$watched{'projects'}}) { utf8::decode($project->{'title'}); $message .= ' o '; $message .= $project->{'title'}; $message .= "\n"; } } if (defined($watched{'issues'}) && (scalar @{$watched{'issues'}} > 0)) { if (defined($watched{'projects'}) && (scalar @{$watched{'projects'}} > 0)) { $message .= sprintf('Issues (%d)', scalar @{$watched{'issues'}}); $message .= ":\n"; } else { $message .= Orangutan::Context::Random( 'You receive notifications about changes in the following issues', 'Here are issues you are watching', 'You watch the following issues' ); $message .= ":\n"; } foreach my $issue (@{$watched{'issues'}}) { utf8::decode($issue->{'title'}); $message .= ' o '; $message .= sprintf('#%d: ', $issue->{'watchable_id'}); $message .= $issue->{'title'}; $message .= "\n"; } } $user->SendMessage($message); }, help => { title => 'How can I check what am I watching?', question => '^(?:How )?(?:(?:can|do) I |to )(?:check|see) (?:what|which)(?: (?:project|issue)s?)? '. '(?:(?:do|am) )?I (?:watch|follow)(?:ing)?\?*!*\.*$', answer => "If you want to see the list of projects and/or issues you are watching just ask. ". "To see the list of projects only - specify word \"projects\". ". "To list issues only - specify word \"issues\".\n". "Check samples:\n". " o Which projects do I watch?\n". " o What am I watching?\n". " o List watched issues\n". " o Watch list", weight => 1120 } ); # kate: syntax perl