From 60091012bfb2b13325a06b2c0acc497d5753f6eb Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 28 Jun 2010 01:12:21 -0700 Subject: [PATCH 1/4] on client connect, websockets now tell the server where the user is. nothing more --- app/views/layouts/application.html.haml | 11 ++++++----- config/initializers/socket.rb | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index d10b10d2f..e6b0d14cf 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -34,11 +34,12 @@ 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.onclose = function() { debug("socket closed"); }; + ws.onopen = function() { + ws.send(location.pathname); + debug("connected..."); + }; }); %body diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 9e6d7ff59..32debfd65 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -13,11 +13,12 @@ module WebSocket end end - EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws| + EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>false) do |ws| ws.onopen { + sid = @channel.subscribe { |msg| ws.send msg } - ws.onmessage { |msg| @channel.push msg} + ws.onmessage { |msg| @channel.push msg; puts msg} ws.onclose { @channel.unsubscribe(sid) } } @@ -29,10 +30,18 @@ module WebSocket end def self.view_hash(object) - {:class =>object.class.to_s.underscore.pluralize, :html => WebSocket.view_for(object)} + #begin + # puts "I be working hard" + v = WebSocket.view_for(object) + #puts view.inspect + #rescue + # puts "in failzord " + view.inspect + # raise "i suck" + #end + {:class =>object.class.to_s.underscore.pluralize, :html => v} end def self.view_for(object) - @view.render(:partial => @view.type_partial(object), :locals => {:post => object}) + @view.render @view.type_partial(object), :post => object end end \ No newline at end of file From 2b5cf0d265c37e1c6cdbc0d5b782a4338fb722e7 Mon Sep 17 00:00:00 2001 From: maxwell Date: Mon, 28 Jun 2010 10:11:47 -0700 Subject: [PATCH 2/4] my websocket works. wut up --- config/initializers/socket.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 32debfd65..a6e9a6aa1 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -15,10 +15,10 @@ module WebSocket EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>false) do |ws| ws.onopen { - + puts ws.request['Cookie'] sid = @channel.subscribe { |msg| ws.send msg } - ws.onmessage { |msg| @channel.push msg; puts msg} + ws.onmessage { |msg| puts msg}#@channel.push msg; puts msg} ws.onclose { @channel.unsubscribe(sid) } } From 3d76fa26bacef6567ed3526e266f9b466827549e Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 28 Jun 2010 14:28:01 -0400 Subject: [PATCH 3/4] RS IZ testing GUID --- app/models/post.rb | 1 + app/models/status_message.rb | 2 +- config/initializers/socket.rb | 13 +++---------- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 0aba89918..683083b30 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -5,6 +5,7 @@ class Post include ROXML include Diaspora::Webhooks + xml_accessor :_id key :person_id, ObjectId belongs_to :person, :class_name => 'Person' diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 195d5a73e..96c9c689e 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -3,7 +3,7 @@ class StatusMessage < Post xml_name :status_message xml_accessor :message - + key :message, String diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index a6e9a6aa1..de5eb3f3c 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -15,10 +15,9 @@ module WebSocket EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>false) do |ws| ws.onopen { - puts ws.request['Cookie'] sid = @channel.subscribe { |msg| ws.send msg } - ws.onmessage { |msg| puts msg}#@channel.push msg; puts msg} + ws.onmessage { |msg|}#@channel.push msg; puts msg} ws.onclose { @channel.unsubscribe(sid) } } @@ -30,18 +29,12 @@ module WebSocket end def self.view_hash(object) - #begin - # puts "I be working hard" v = WebSocket.view_for(object) - #puts view.inspect - #rescue - # puts "in failzord " + view.inspect - # raise "i suck" - #end + puts v {:class =>object.class.to_s.underscore.pluralize, :html => v} end def self.view_for(object) @view.render @view.type_partial(object), :post => object end -end \ No newline at end of file +end From a540f0910957f98b03515f8a049d7426a5324efa Mon Sep 17 00:00:00 2001 From: ilya Date: Mon, 28 Jun 2010 14:46:43 -0400 Subject: [PATCH 4/4] RS, IZ; Added ids to views --- app/views/blogs/_blog.html.haml | 2 +- app/views/bookmarks/_bookmark.html.haml | 2 +- app/views/comments/_comment.html.haml | 4 ++-- app/views/status_messages/_status_message.html.haml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/blogs/_blog.html.haml b/app/views/blogs/_blog.html.haml index 366f5ad85..e0f63e52d 100644 --- a/app/views/blogs/_blog.html.haml +++ b/app/views/blogs/_blog.html.haml @@ -1,4 +1,4 @@ -%li.message{:class => ("mine" if mine?(post))} +%li.message{:id => post.id, :class => ("mine" if mine?(post))} %span.from = link_to_person post.person %b wrote a new blog post diff --git a/app/views/bookmarks/_bookmark.html.haml b/app/views/bookmarks/_bookmark.html.haml index 03fd47c0f..88208a619 100644 --- a/app/views/bookmarks/_bookmark.html.haml +++ b/app/views/bookmarks/_bookmark.html.haml @@ -1,4 +1,4 @@ -%li.message{:class => ("mine" if mine?(post))} +%li.message{:id => post.id, :class => ("mine" if mine?(post))} %span.from = link_to_person post.person %b shared a link diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 9914fcb7a..4591333df 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -1,4 +1,4 @@ -%li.comment +%li.comment{:id => comment.id} = comment.text \--- - = comment.person.real_name \ No newline at end of file + = comment.person.real_name diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index d1c6611c1..a0dc4336b 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -1,4 +1,4 @@ -%li.message{:class => ("mine" if mine?(post))} +%li.message{:id => post.id, :class => ("mine" if mine?(post))} %span.from = link_to_person post.person = post.message