Simplify set_peer_role

master
Daniel Berteaud 10 years ago
parent 84cf94b8b5
commit ee6ce99341
  1. 16
      vroom.pl

@ -371,17 +371,17 @@ helper set_peer_role => sub {
AND `r`.`name`=?'); AND `r`.`name`=?');
}; };
if ($@){ if ($@){
return {msg => $@}; return 0;
} }
$sth->execute($data->{peer_id},$data->{name},$data->{room}); $sth->execute($data->{peer_id},$data->{name},$data->{room});
if ($sth->err){ if ($sth->err){
return {msg => "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"}; return 0;
} }
my $num; my $num;
$sth->bind_columns(\$num); $sth->bind_columns(\$num);
$sth->fetch; $sth->fetch;
if ($num > 0){ if ($num > 0){
return {msg => 'ERROR_UNAUTHORIZED'}; return 0;
} }
$sth = eval { $sth = eval {
$self->db->prepare('UPDATE `room_participants` `p` $self->db->prepare('UPDATE `room_participants` `p`
@ -392,7 +392,7 @@ helper set_peer_role => sub {
AND `r`.`name`=?'); AND `r`.`name`=?');
}; };
if ($@){ if ($@){
return {msg => $@}; return 0;
} }
$sth->execute( $sth->execute(
$data->{peer_id}, $data->{peer_id},
@ -401,12 +401,12 @@ helper set_peer_role => sub {
$data->{room} $data->{room}
); );
if ($sth->err){ if ($sth->err){
return {msg => "DB Error: " . $sth->errstr . " (code " . $sth->err . ")"}; return 0;
} }
$self->app->log->info("User " . $data->{name} . " (peer id " . $self->app->log->info("User " . $data->{name} . " (peer id " .
$data->{peer_id} . ") has now the " . $data->{peer_id} . ") has now the " .
$data->{role} . " role in room " . $data->{room}); $data->{role} . " role in room " . $data->{room});
return {ok => 1}; return 1;
}; };
# Return the role of a peer, from it's signaling ID # Return the role of a peer, from it's signaling ID
@ -1541,11 +1541,11 @@ post '/*action' => [action => [qw/action admin\/action/]] => sub {
peer_id => $id, peer_id => $id,
role => $self->session($room)->{role} role => $self->session($room)->{role}
}); });
if (!$res->{ok}){ if (!$res){
return $self->render( return $self->render(
json => { json => {
status => 'error', status => 'error',
msg => $self->l($res->{msg}) msg => $self->l('ERROR_OCCURRED')
} }
); );
} }

Loading…
Cancel
Save