From 3259d858d259f6964548804ebc36d1c7991da92a Mon Sep 17 00:00:00 2001 From: Fernando Brito Date: Wed, 9 Jul 2014 12:01:28 -0300 Subject: [PATCH] Filter callback refresh within user context --- app/assets/javascripts/v_libras/videos/index.js.erb | 7 +++++-- app/views/v_libras/videos/index.haml | 2 ++ lib/api_client/callback_processor.rb | 2 +- lib/api_client/client.rb | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/v_libras/videos/index.js.erb b/app/assets/javascripts/v_libras/videos/index.js.erb index 5ca616b..b54ec96 100644 --- a/app/assets/javascripts/v_libras/videos/index.js.erb +++ b/app/assets/javascripts/v_libras/videos/index.js.erb @@ -9,14 +9,17 @@ $(function() { // bind to a channel event // If video is finished, update window on any case channel.bind('callback_called', function(data) { - window.location = window.location.pathname; + if (data.owner_id === current_user) + window.location = window.location.pathname; }); // The other event will only update the window if #modal-wait is closed channel.bind('video_submitted', function(data) { /* alert("Um vídeo que estava em processamento está disponível. Sua página será atualizada automaticamente.") */ + if (! $('#modal-wait').hasClass('in')) { - window.location = window.location.pathname; + if (data.owner_id === current_user) + window.location = window.location.pathname; } }); }); \ No newline at end of file diff --git a/app/views/v_libras/videos/index.haml b/app/views/v_libras/videos/index.haml index 8ead5eb..8166a47 100644 --- a/app/views/v_libras/videos/index.haml +++ b/app/views/v_libras/videos/index.haml @@ -68,6 +68,8 @@ - content_for :javascript_code do :javascript + current_user = #{current_user.id}; + $(function () { $('#modal-wait').modal(); }) \ No newline at end of file diff --git a/lib/api_client/callback_processor.rb b/lib/api_client/callback_processor.rb index f186a63..8141db5 100644 --- a/lib/api_client/callback_processor.rb +++ b/lib/api_client/callback_processor.rb @@ -14,6 +14,6 @@ class ApiClient::CallbackProcessor end Rails.logger.debug "[VLibras::Callback] Notifying websocket channel" - WebsocketRails[:requests_update].trigger(:callback_called) + WebsocketRails[:requests_update].trigger(:callback_called, { :owner_id => request.owner_id }) end end \ No newline at end of file diff --git a/lib/api_client/client.rb b/lib/api_client/client.rb index 67e2470..5840cd1 100644 --- a/lib/api_client/client.rb +++ b/lib/api_client/client.rb @@ -23,7 +23,7 @@ module ApiClient::Client ensure # FIXME: Running on another thread. Websocket not working :( Delayed::Worker.logger.debug "[VLibras::Request] Sending message to websocket channel" - WebsocketRails[:requests_update].trigger(:video_submitted) + WebsocketRails[:requests_update].trigger(:video_submitted, { :owner_id => request.owner_id }) end -- libgit2 0.21.2