diff --git a/templates/default/documentation.html.ep b/templates/default/documentation.html.ep index 07c5468..c6ec3ae 100644 --- a/templates/default/documentation.html.ep +++ b/templates/default/documentation.html.ep @@ -108,6 +108,7 @@
  • Protocol::SocketIO::Message
  • Data::Dumper
  • DateTime
  • +
  • Array::Diff
  • The following perl modules are optional @@ -174,7 +175,7 @@ yum install epel-release The following command will install everything required to run VROOM
     yum install git tar wget httpd mod_ssl openssl mariadb-server \\
    -           'perl(DBI)' 'perl(DBD::mysql)' \\
    +           'perl(DBI)' 'perl(DBD::mysql)' 'perl('Array::Diff)' \\
                'perl(Mojolicious)' 'perl(Mojolicious::Plugin::I18N)' 'perl(Mojolicious::Plugin::Mail)' \\
                'perl(Crypt::SaltedHash)' 'perl(Etherpad::API)' 'perl(LWP::Protocol::https)' \\
                'perl(Sesion::Token)' 'perl(Mojolicious::Plugin::Database)' \\
    @@ -715,16 +716,8 @@ systemctl restart vroom.service
    A room is being deleted by a user action - add_email_notification - Add an email to the list of notifications sent when someone joins a room - - - reset_email_notification - Reset the list of email being notified when someone joins a rooms - - - del_email_notification - Remove an email from the list of notifications sent when someone joins a room + email_notification_change + The list of email being notified when someone joins a room has been updated send_invitation diff --git a/vroom.pl b/vroom.pl index f8c3da5..e8d1f4e 100755 --- a/vroom.pl +++ b/vroom.pl @@ -23,6 +23,7 @@ use Protocol::SocketIO::Message; use File::Path qw(make_path); use File::Basename; use DateTime; +use Array::Diff; use Data::Dumper; app->log->level('info'); @@ -654,10 +655,6 @@ helper add_notification => sub { $data->{id}, $email ); - $self->log_event({ - event => 'add_email_notification', - msg => "Adding $email to the notification list for room " . $data->{name} - }); return 1; }; @@ -670,6 +667,26 @@ helper update_email_notifications => sub { if (!$data){ return 0; } + my $old = $self->get_email_notifications($room); + my @old = sort map { $old->{$_}->{email} } keys $old; + my @new = sort @$emails; + # Remove empty email + @new = grep { $_ ne '' } @new; + my $diff = Array::Diff->diff(\@old, \@new); + # Are we changing the list of email ? + if ($diff->count > 0){ + my $msg = "Notification list for room $room has changed\n"; + if (scalar @{$diff->deleted} > 0){ + $msg .= "Emails being removed: " . join (', ', @{$diff->deleted}) . "\n"; + } + if (scalar @{$diff->added} > 0){ + $msg .= "Emails being added: " . join (', ', @{$diff->added}) . "\n"; + } + $self->log_event({ + event => 'email_notification_change', + msg => $msg + }); + } # First, drop all existing notifications my $sth = eval { $self->db->prepare('DELETE FROM `email_notifications` @@ -678,12 +695,8 @@ helper update_email_notifications => sub { $sth->execute( $data->{id}, ); - $self->log_event({ - event => 'reset_email_notification', - msg => 'Resetting email notification list for room ' . $data->{name} - }); # Now, insert new emails - foreach my $email (@$emails){ + foreach my $email (@new){ # Skip empty inputs if ($email eq ''){ next;