Handle email notifications in the new config menu

master
Daniel Berteaud 10 years ago
parent cdc4d71e68
commit b65ad2c63e
  1. 7
      public/js/vroom.js
  2. 34
      vroom.pl

@ -546,12 +546,17 @@ function initVroom(room) {
if (countPeers() > 1){ if (countPeers() > 1){
$('.threePeersEl').show(500); $('.threePeersEl').show(500);
} }
// Reset the list of email displayed, so first remove evry input field but the first one
// We keep it so we can clone it again
$('.email-list').find('.email-entry:not(:first)').remove(); $('.email-list').find('.email-entry:not(:first)').remove();
$.each(data.notif, function(index, obj){ $.each(data.notif, function(index, obj){
addNotifiedEmail(obj.email); addNotifiedEmail(obj.email);
addEmailInputField(obj.email); addEmailInputField(obj.email);
}); });
$('.email-list').find('.email-entry:first').remove(); // Now, remove the first one if the list is not empty
if (data.notif.length > 0){
$('.email-list').find('.email-entry:first').remove();
}
} }
// We're are not owner of the room // We're are not owner of the room
else{ else{

@ -620,7 +620,7 @@ helper add_notification => sub {
my $self = shift; my $self = shift;
my ($room,$email) = @_; my ($room,$email) = @_;
my $data = $self->get_room_by_name($room); my $data = $self->get_room_by_name($room);
if (!$data){ if (!$data || !$self->valid_email($email)){
return 0; return 0;
} }
my $sth = eval { my $sth = eval {
@ -632,8 +632,34 @@ helper add_notification => sub {
$data->{id}, $data->{id},
$email $email
); );
$self->app->log->debug($self->session('name') . return 1;
" has added $email to the list of email which will be notified when someone joins room $room"); };
# Update the list of notified email for a room in one go
# Take the room and an array ref of emails
helper update_email_notifications => sub {
my $self = shift;
my ($room,$emails) = @_;
my $data = $self->get_room_by_name($room);
if (!$data){
return 0;
}
# First, drop all existing notifications
my $sth = eval {
$self->db->prepare('DELETE FROM `email_notifications`
WHERE `room_id`=?');
};
$sth->execute(
$data->{id},
);
# Now, insert new emails
foreach my $email (@$emails){
# Skip empty inputs
if ($email eq ''){
next;
}
$self->add_notification($room,$email) || return 0;
}
return 1; return 1;
}; };
@ -1348,7 +1374,7 @@ any '/api' => sub {
$room->{$pass} = Crypt::SaltedHash->new(algorithm => 'SHA-256')->add($req->{param}->{$pass})->generate; $room->{$pass} = Crypt::SaltedHash->new(algorithm => 'SHA-256')->add($req->{param}->{$pass})->generate;
} }
} }
if ($self->modify_room($room)){ if ($self->modify_room($room) && $self->update_email_notifications($room->{name},$req->{param}->{emails})){
return $self->render( return $self->render(
json => { json => {
status => 'success', status => 'success',

Loading…
Cancel
Save