Some more simplification in peer role handling

master
Daniel Berteaud 10 years ago
parent 54f0648d1d
commit 92de57efdb
  1. 16
      vroom.pl

@ -348,8 +348,8 @@ helper set_peer_role => sub {
# Return the role of a peer, take a peer object as arg ($data = { peer_id => XYZ }) # Return the role of a peer, take a peer object as arg ($data = { peer_id => XYZ })
helper get_peer_role => sub { helper get_peer_role => sub {
my $self = shift; my $self = shift;
my ($data) = @_; my ($peer_id) = @_;
return $peers->{$data->{peer_id}}->{role}; return $peers->{$peer_id}->{role};
}; };
# Promote a peer to owner # Promote a peer to owner
@ -1840,14 +1840,14 @@ any '/api' => sub {
); );
} }
if ($self->session('peer_id') && $self->session('peer_id') eq $peer_id){ if ($self->session('peer_id') && $self->session('peer_id') eq $peer_id){
my $api_role = $self->get_key_role($token,$room->{name});
# If we just have been promoted to owner # If we just have been promoted to owner
if ($self->session($room->{name})->{role} ne 'owner' && if ($api_role ne 'owner' &&
$self->get_peer_role({room => $room->{name}, peer_id => $peer_id}) && $self->get_peer_role($peer_id) &&
$self->get_peer_role({room => $room->{name}, peer_id => $peer_id}) eq 'owner'){ $self->get_peer_role($peer_id) eq 'owner'){
$self->session($room->{name})->{role} = 'owner';
$self->associate_key_to_room( $self->associate_key_to_room(
room => $room->{name}, room => $room->{name},
key => $self->session('key'), key => $token,
role => 'owner' role => 'owner'
); );
if (!$res){ if (!$res){
@ -1861,7 +1861,7 @@ any '/api' => sub {
} }
} }
} }
my $role = $self->get_peer_role({room => $room->{name}, peer_id => $peer_id}); my $role = $self->get_peer_role($peer_id);
if (!$role){ if (!$role){
return $self->render( return $self->render(
json => { json => {

Loading…
Cancel
Save