From fd5d7c63adfee46243afd0d537cc87f5cdc2789d Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 22 Jun 2010 18:59:11 -0700 Subject: [PATCH] messy application.haml file i know, but now the sockets only update pages which want their data --- Gemfile | 1 + app/views/layouts/application.html.haml | 31 +++++++++++++------------ config/initializers/socket.rb | 6 ++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index 70d2ba306..1ffc83f22 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ end group :development do gem "nifty-generators" + gem "ruby-debug" end group :deployment do diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 4b2ab3880..cd5431126 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,7 +2,7 @@ %html %head %title - = yield(:title) || "Untitled" + = yield(:title) || "diaspora" %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ = stylesheet_link_tag "blueprint/screen", :media => 'screen' @@ -29,13 +29,14 @@ ws = new WebSocket("ws://#{request.host}:8080/"); ws.onmessage = function(evt) { - $("#stream").prepend($(evt.data).fadeIn("fast")); - }; + var obj = jQuery.parseJSON(evt.data); + if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) { + $("#stream").prepend($(obj['html']).fadeIn("fast")); + }; + } ws.onclose = function() { debug("socket closed"); }; ws.onopen = function() { debug("connected..."); - //ws.send("hello server"); - // ws.send("hello again"); }; }); @@ -55,16 +56,16 @@ // wait for the DOM to be loaded // bind 'myForm' and provide a simple callback function - $('#new_status_message').ajaxForm(function() { - alert("Thank you for your comment!"); - }); - $('#new_bookmark').ajaxForm(function() { - alert("Thank you for your comment!"); - }); - - $('#new_blog').ajaxForm(function() { - alert("Thank you for your comment!"); - }); + $('#new_status_message').ajaxForm(function() { + alert("Thank you for your comment!"); + }); + $('#new_bookmark').ajaxForm(function() { + alert("Thank you for your comment!"); + }); + + $('#new_blog').ajaxForm(function() { + alert("Thank you for your comment!"); + }); }); %body diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index c86e8cd28..f02c12f4a 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -29,9 +29,7 @@ module WebSocket } #this should get folded into message queue i think? def self.update_clients(object) - - n = @view.render(:partial => @view.type_partial(object), :locals => {:post => object}) - @channel.push(n) if @channel + n = @view.render(:partial => @view.type_partial(object), :locals => {:post => object}) + @channel.push({:class =>object.class.to_s.underscore.pluralize, :html => n}.to_json) if @channel end - end