|
|
@ -575,14 +575,17 @@ 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); |
|
|
|
return undef unless ($data); |
|
|
|
if (!$data){ |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
my $sth = eval { |
|
|
|
my $sth = eval { |
|
|
|
$self->db->prepare('INSERT INTO `email_notifications` |
|
|
|
$self->db->prepare('INSERT INTO `email_notifications` |
|
|
|
(`id`,`email`) |
|
|
|
(`room_id`,`email`) |
|
|
|
VALUES (?,?)'); |
|
|
|
VALUES (?,?)'); |
|
|
|
} || return undef; |
|
|
|
}; |
|
|
|
$sth->execute($data->{id},$email) || return undef; |
|
|
|
$sth->execute($data->{id},$email); |
|
|
|
$self->app->log->debug($self->session('name') . " has added $email to the list of email which will be notified when someone joins room $room"); |
|
|
|
$self->app->log->debug($self->session('name') . |
|
|
|
|
|
|
|
" has added $email to the list of email which will be notified when someone joins room $room"); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -592,16 +595,12 @@ helper get_notification => sub { |
|
|
|
my ($room) = @_; |
|
|
|
my ($room) = @_; |
|
|
|
$room = $self->get_room_by_name($room) || return undef; |
|
|
|
$room = $self->get_room_by_name($room) || return undef; |
|
|
|
my $sth = eval { |
|
|
|
my $sth = eval { |
|
|
|
$self->db->prepare('SELECT `email` |
|
|
|
$self->db->prepare('SELECT `id`,`email` |
|
|
|
FROM `email_notifications` |
|
|
|
FROM `email_notifications` |
|
|
|
WHERE `id`=?'); |
|
|
|
WHERE `room_id`=?'); |
|
|
|
} || return undef; |
|
|
|
}; |
|
|
|
$sth->execute($room->{id}) || return undef; |
|
|
|
$sth->execute($room->{id}); |
|
|
|
my @res; |
|
|
|
return $sth->fetchall_hashref('id'); |
|
|
|
while(my @row = $sth->fetchrow_array){ |
|
|
|
|
|
|
|
push @res, $row[0]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return @res; |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
# Remove an email from notification list |
|
|
|
# Remove an email from notification list |
|
|
@ -609,14 +608,17 @@ helper remove_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); |
|
|
|
return undef unless ($data); |
|
|
|
if (!$data){ |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
my $sth = eval { |
|
|
|
my $sth = eval { |
|
|
|
$self->db->prepare('DELETE FROM `email_notifications` |
|
|
|
$self->db->prepare('DELETE FROM `email_notifications` |
|
|
|
WHERE `id`=? |
|
|
|
WHERE `room_id`=? |
|
|
|
AND `email`=?'); |
|
|
|
AND `email`=?'); |
|
|
|
} || return undef; |
|
|
|
}; |
|
|
|
$sth->execute($data->{id},$email) || return undef; |
|
|
|
$sth->execute($data->{id},$email) || return undef; |
|
|
|
$self->app->log->debug($self->session('name') . " has removed $email from the list of email which are notified when someone joins room $room"); |
|
|
|
$self->app->log->debug($self->session('name') . |
|
|
|
|
|
|
|
" has removed $email from the list of email which are notified when someone joins room $room"); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -1381,8 +1383,6 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub { |
|
|
|
} |
|
|
|
} |
|
|
|
if ($self->session($room)->{role} eq 'owner'){ |
|
|
|
if ($self->session($room)->{role} eq 'owner'){ |
|
|
|
my $i = 0; |
|
|
|
my $i = 0; |
|
|
|
my @email = $self->get_notification($room); |
|
|
|
|
|
|
|
%emailNotif = map { $i => $email[$i++] } @email; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return $self->render( |
|
|
|
return $self->render( |
|
|
|
json => { |
|
|
|
json => { |
|
|
@ -1391,7 +1391,7 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub { |
|
|
|
join_auth => ($data->{join_password}) ? 'yes' : 'no', |
|
|
|
join_auth => ($data->{join_password}) ? 'yes' : 'no', |
|
|
|
locked => ($data->{locked}) ? 'yes' : 'no', |
|
|
|
locked => ($data->{locked}) ? 'yes' : 'no', |
|
|
|
ask_for_name => ($data->{ask_for_name}) ? 'yes' : 'no', |
|
|
|
ask_for_name => ($data->{ask_for_name}) ? 'yes' : 'no', |
|
|
|
notif => Mojo::JSON->new->encode({email => { %emailNotif }}), |
|
|
|
notif => $self->get_notification($room), |
|
|
|
status => 'success' |
|
|
|
status => 'success' |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
@ -1462,9 +1462,10 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub { |
|
|
|
my $name = $self->param('name') || ''; |
|
|
|
my $name = $self->param('name') || ''; |
|
|
|
my $subj = ($name eq '') ? sprintf($self->l('s_JOINED_ROOM_s'), $self->l('SOMEONE'), $room) : sprintf($self->l('s_JOINED_ROOM_s'), $name, $room); |
|
|
|
my $subj = ($name eq '') ? sprintf($self->l('s_JOINED_ROOM_s'), $self->l('SOMEONE'), $room) : sprintf($self->l('s_JOINED_ROOM_s'), $name, $room); |
|
|
|
# Send notifications |
|
|
|
# Send notifications |
|
|
|
foreach my $rcpt ($self->get_notification($room)){ |
|
|
|
my $recipients = $self->get_notification($room); |
|
|
|
|
|
|
|
foreach my $rcpt (keys %{$recipients}){ |
|
|
|
my $sent = $self->mail( |
|
|
|
my $sent = $self->mail( |
|
|
|
to => $rcpt, |
|
|
|
to => $recipients->{$rcpt}->{email}, |
|
|
|
subject => $subj, |
|
|
|
subject => $subj, |
|
|
|
data => $self->render_mail('notification', |
|
|
|
data => $self->render_mail('notification', |
|
|
|
room => $room, |
|
|
|
room => $room, |
|
|
|