From f181eb6406ed51220c0b7d8ccf47be14152965d0 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Sun, 18 Jan 2015 22:09:04 +0100 Subject: [PATCH] Switch join action to the new api handler --- lib/Vroom/Constants.pm | 3 ++- public/js/vroom.js | 11 ++++++++--- vroom.pl | 45 ++++++++++++++++++++++----------------------- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/lib/Vroom/Constants.pm b/lib/Vroom/Constants.pm index 60cd824..db4d35c 100644 --- a/lib/Vroom/Constants.pm +++ b/lib/Vroom/Constants.pm @@ -171,7 +171,8 @@ use constant API_ACTIONS => { ping => 1, authenticate => 1, get_room_info => 1, - get_peer_role => 1 + get_peer_role => 1, + join => 1 } }; diff --git a/public/js/vroom.js b/public/js/vroom.js index ee67261..c96f7b0 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -1495,10 +1495,15 @@ function initVroom(room) { // we send it. Not that I like sending this kind of data to the server // but it's needed for email notifications $.ajax({ + url: rootUrl + 'api', data: { - action: 'join', - room: roomName, - name: (peers.local.hasName) ? peers.local.displayName : '' + req: JSON.stringify({ + action: 'join', + param: { + room: roomName, + name: (peers.local.hasName) ? peers.local.displayName : '' + } + }) }, error: function(data) { $.notify(locale.ERROR_OCCURRED, 'error'); diff --git a/vroom.pl b/vroom.pl index 92fd257..9a0fc91 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1541,7 +1541,28 @@ any '/api' => sub { } ); } - + # Notify the backend when we join a room + elsif ($req->{action} eq 'join'){ + my $name = $req->{param}->{name} || ''; + my $subj = sprintf($self->l('s_JOINED_ROOM_s'), ($name eq '') ? $self->l('SOMEONE') : $name, $room); + # Send notifications + my $recipients = $self->get_notification($room); + foreach my $rcpt (keys %{$recipients}){ + my $sent = $self->mail( + to => $recipients->{$rcpt}->{email}, + subject => $subj, + data => $self->render_mail('notification', + room => $room->{name}, + name => $name + ) + ); + } + return $self->render( + json => { + status => 'success' + } + ); + } }; # Catch all route: if nothing else match, it's the name of a room @@ -1681,28 +1702,6 @@ post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub { }, ); } - # New participant joined the room - elsif ($action eq 'join'){ - my $name = $self->param('name') || ''; - my $subj = sprintf($self->l('s_JOINED_ROOM_s'), ($name eq '') ? $self->l('SOMEONE') : $name, $room); - # Send notifications - my $recipients = $self->get_notification($room); - foreach my $rcpt (keys %{$recipients}){ - my $sent = $self->mail( - to => $recipients->{$rcpt}->{email}, - subject => $subj, - data => $self->render_mail('notification', - room => $room, - name => $name - ) - ); - } - return $self->render( - json => { - status => 'success' - } - ); - } # A participant is being promoted to the owner status elsif ($action eq 'promote'){ my $peer = $self->param('peer');