merged my socket changes

This commit is contained in:
maxwell 2010-06-28 14:52:43 -07:00
commit d9a6bb7ba2
13 changed files with 237 additions and 258 deletions

View file

@ -1,4 +1,6 @@
module ApplicationHelper module ApplicationHelper
require 'lib/common'
include Diaspora::XMLParser
def object_path(object) def object_path(object)
eval("#{object.class.to_s.underscore}_path(object)") eval("#{object.class.to_s.underscore}_path(object)")
end end
@ -7,46 +9,6 @@ module ApplicationHelper
object.attributes.keys object.attributes.keys
end end
def parse_sender_id_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
doc.xpath("/XML/head/sender/email").text.to_s
end
def parse_sender_object_from_xml(xml)
sender_id = parse_sender_id_from_xml(xml)
Friend.where(:email => sender_id).first
end
def parse_body_contents_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
doc.xpath("/XML/posts/post")
end
def parse_objects_from_xml(xml)
objects = []
sender = parse_sender_object_from_xml(xml)
body = parse_body_contents_from_xml(xml)
body.children.each do |post|
begin
object = post.name.camelize.constantize.from_xml post.to_s
object.person = sender if object.is_a? Post
objects << object
rescue
puts "Not a real type: #{object.to_s}"
end
end
objects
end
def store_objects_from_xml(xml)
objects = parse_objects_from_xml(xml)
objects.each do |p|
p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF
#p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
end
end
def mine?(post) def mine?(post)
post.person == User.first post.person == User.first
end end

View file

@ -5,6 +5,7 @@ class Post
include ROXML include ROXML
include Diaspora::Webhooks include Diaspora::Webhooks
xml_accessor :_id
key :person_id, ObjectId key :person_id, ObjectId
belongs_to :person, :class_name => 'Person' belongs_to :person, :class_name => 'Person'

View file

@ -1,4 +1,4 @@
%li.message{:class => ("mine" if mine?(post))} %li.message{:id => post.id, :class => ("mine" if mine?(post))}
%span.from %span.from
= link_to_person post.person = link_to_person post.person
%b wrote a new blog post %b wrote a new blog post

View file

@ -1,4 +1,4 @@
%li.message{:class => ("mine" if mine?(post))} %li.message{:id => post.id, :class => ("mine" if mine?(post))}
%span.from %span.from
= link_to_person post.person = link_to_person post.person
%b shared a link %b shared a link

View file

@ -1,4 +1,6 @@
%li.comment %li.comment{:id => comment.id}
%span.from
= link_to_person comment.person
= comment.text = comment.text
\--- %div.time
= comment.person.real_name = "#{time_ago_in_words(comment.updated_at)} ago"

View file

@ -25,7 +25,6 @@
- if user_signed_in? - if user_signed_in?
:javascript :javascript
$(document).ready(function(){ $(document).ready(function(){
function debug(str){ $("#debug").append("<p>" + str); }; function debug(str){ $("#debug").append("<p>" + str); };
ws = new WebSocket("ws://#{request.host}:8080/"); ws = new WebSocket("ws://#{request.host}:8080/");
@ -34,7 +33,7 @@
if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) { if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) {
$("#stream").prepend($(obj['html']).fadeIn("fast")); $("#stream").prepend($(obj['html']).fadeIn("fast"));
}; };
} };
ws.onclose = function() { debug("socket closed"); }; ws.onclose = function() { debug("socket closed"); };
ws.onopen = function() { ws.onopen = function() {
ws.send(location.pathname); ws.send(location.pathname);
@ -42,11 +41,11 @@
}; };
}); });
%body %body
- flash.each do |name, msg| - flash.each do |name, msg|
= content_tag :div, msg, :id => "flash_#{name}" = content_tag :div, msg, :id => "flash_#{name}"
%header %header
.container
%a#diaspora_text{:href => root_path} %a#diaspora_text{:href => root_path}
%img{:src => '/images/diaspora_white.png'} %img{:src => '/images/diaspora_white.png'}
@ -59,15 +58,17 @@
= link_to "login", new_user_session_path = link_to "login", new_user_session_path
#header_below #header_below
.container
- if user_signed_in? - if user_signed_in?
%h1#user_name %h1#user_name
= link_to User.first.real_name, root_url = link_to User.first.real_name, root_url
%span.description %span.description
= my_latest_message = my_latest_message
%nav .container
%ul.nav #content.span-24.last
.span-3.append-1.last
%ul#stream_filters
%a{ :href => root_path, :title => "Your network stream."} %a{ :href => root_path, :title => "Your network stream."}
%li home %li home
%a{ :href => status_messages_path, :title => "Recent status messages."} %a{ :href => status_messages_path, :title => "Recent status messages."}
@ -78,11 +79,8 @@
%li blogs %li blogs
%a{ :href => friends_path, :title => "Your list of connections with other seeds."} %a{ :href => friends_path, :title => "Your list of connections with other seeds."}
%li friends %li friends
.span-15.append-1.last
#content
#main
= yield = yield
= render "posts/debug" = render "posts/debug"
#friends_list .span-3.last
= render 'friends/sidebar' if user_signed_in? = render 'friends/sidebar' if user_signed_in?

View file

@ -1,4 +1,4 @@
%li.message{:class => ("mine" if mine?(post))} %li.message{:id => post.id, :class => ("mine" if mine?(post))}
%span.from %span.from
= link_to_person post.person = link_to_person post.person
= post.message = post.message

View file

@ -16,10 +16,9 @@ module WebSocket
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>false) do |ws| EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>false) do |ws|
ws.onopen { ws.onopen {
puts ws.request['Cookie']
sid = @channel.subscribe { |msg| ws.send msg } 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) } ws.onclose { @channel.unsubscribe(sid) }
} }
@ -39,6 +38,7 @@ module WebSocket
puts "in failzord " + v .inspect puts "in failzord " + v .inspect
raise "i suck" raise "i suck"
end end
{:class =>object.class.to_s.underscore.pluralize, :html => v} {:class =>object.class.to_s.underscore.pluralize, :html => v}
end end

View file

@ -1,4 +1,47 @@
module Diaspora module Diaspora
module XMLParser
def parse_sender_id_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
doc.xpath("/XML/head/sender/email").text.to_s
end
def parse_sender_object_from_xml(xml)
sender_id = parse_sender_id_from_xml(xml)
Friend.where(:email => sender_id).first
end
def parse_body_contents_from_xml(xml)
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
doc.xpath("/XML/posts/post")
end
def parse_objects_from_xml(xml)
objects = []
sender = parse_sender_object_from_xml(xml)
body = parse_body_contents_from_xml(xml)
body.children.each do |post|
begin
object = post.name.camelize.constantize.from_xml post.to_s
object.person = sender if object.is_a? Post
objects << object
rescue
puts "Not a real type: #{object.to_s}"
end
end
objects
end
def store_objects_from_xml(xml)
objects = parse_objects_from_xml(xml)
objects.each do |p|
p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF
#p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
end
end
end
module Webhooks module Webhooks
def self.included(klass) def self.included(klass)
klass.class_eval do klass.class_eval do

View file

@ -1,5 +1,4 @@
body { body {
font-family: "helvetica", "arial", "sans-serif";
padding: 2em; padding: 2em;
margin: 0; } margin: 0; }
@ -46,82 +45,75 @@ a {
margin: 0; margin: 0;
font-weight: bold; font-weight: bold;
font-size: 12px; font-size: 12px;
background-color: #cc0000; background-color: #cc0000; }
color: white; }
.error_messages p { .error_messages p {
margin: 8px 10px; } margin: 8px 10px; }
.error_messages ul { .error_messages ul {
margin: 0; } margin: 0; }
header { header {
z-index: 10; position: relative;
position: fixed; margin: -2em;
width: 100%; margin-bottom: 0;
margin-top: -2em;
margin-right: -2em;
margin-left: -2em;
height: 30px; height: 30px;
color: white; color: white;
background-color: #1a1a21; background-color: #1a1a21;
border-bottom: 2px solid #f2f8fc; border-bottom: 2px solid white;
padding-top: 5px; } padding-top: 5px; }
header #diaspora_text { header #diaspora_text {
position: fixed; position: absolute;
border: none; border: none;
top: 8px; top: 10px; }
left: 1em; }
header #session_action { header #session_action {
position: fixed; position: absolute;
right: 1em; right: 300px;
font-size: 120%; font-size: 110%;
top: 7px; } top: 7px; }
header #session_action a { header #session_action a {
color: #cccccc; color: #cccccc;
border: none; } border: none; }
ul.nav { #show_filters {
z-index: 100;
position: absolute; position: absolute;
right: 0;
text-align: right; }
#show_filters > a {
border: 1px solid #666666;
padding: 5px; }
ul#stream_filters {
padding: 0; padding: 0;
margin: 0; margin: 0; }
width: 200px; ul#stream_filters li {
top: 100px;
font-size: 130%; }
ul.nav li {
display: block; display: block;
padding: 5px 10px; padding: 5px 0; }
background-color: #f2f8fc; ul#stream_filters li:first-child {
border: 1px solid white; }
ul.nav li:first-child {
border-top-right-radius: 5px; border-top-right-radius: 5px;
border-top-left-radius: 5px; } border-top-left-radius: 5px; }
ul.nav li:last-child { ul#stream_filters li:last-child {
border-bottom-right-radius: 5px; border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px; } border-bottom-left-radius: 5px; }
ul.nav a { ul#stream_filters a {
color: #b1cfe3; } color: #b1cfe3; }
ul#stream_filters a:hover {
color: black; }
#header_below { #header_below {
z-index: 5; margin: 0 -2em;
position: fixed; -webkit-box-shadow: 0 2px 2px -1px #999999;
height: 40px; background-color: #f2f8fc;
width: 100%; border-bottom: 1px solid #7e96a6;
padding: 1em; padding-top: 0.8em;
padding-top: 40px; padding-bottom: 0.4em; }
top: 0;
background-color: rgba(255, 255, 255, 0.9);
margin-left: -2em; }
#header_below img {
position: absolute;
width: 200px;
border-radius: 5px; }
#content { #content {
position: absolute; position: absolute;
left: 250px; top: 94px; }
top: 94px;
width: 60%; #main {
min-width: 500px; width: 100%; }
max-width: 700px; }
ul#stream { ul#stream {
margin: 0; margin: 0;
@ -135,7 +127,6 @@ ul#stream {
li.message { li.message {
line-height: 140%; line-height: 140%;
font-size: 120%;
font-family: "Lucida Grande"; font-family: "Lucida Grande";
color: #999999; } color: #999999; }
li.message span.from { li.message span.from {
@ -146,12 +137,13 @@ li.message {
color: #bababa; color: #bababa;
font-size: 70%; } font-size: 70%; }
.mine { #user_name {
background-color: rgba(202, 237, 204, 0.5); } font-size: 15px;
line-height: 100%; }
h1 { h1 {
position: relative; position: relative;
font-size: 24px; font-size: 18px;
font-weight: bold; font-weight: bold;
line-height: 36px; } line-height: 36px; }
h1 p.description, h1 span.description { h1 p.description, h1 span.description {
@ -160,11 +152,6 @@ h1 {
color: #999999; color: #999999;
padding: 0.1em; } padding: 0.1em; }
.big_number {
font-weight: bold;
font-size: 500%;
line-height: 100%; }
h3 { h3 {
position: relative; position: relative;
font-size: 18px; font-size: 18px;
@ -177,30 +164,39 @@ h3 {
width: 100%; width: 100%;
margin-bottom: 1em; } margin-bottom: 1em; }
#main {
width: 70%;
min-width: 400px;
max-width: 700px;
float: left; }
#friends_list {
float: right;
width: 20%;
min-width: 130px;
padding-left: 10%; }
form { form {
font-size: 130%; font-size: 120%;
margin: 1em; margin: 1em;
margin-left: 0em; } margin-left: 0em; }
form input { form input {
font-size: 150%;
padding: 0.2em; padding: 0.2em;
max-width: 100%; } max-width: 100%; }
#user_name { #user_name {
background-color: rgba(255, 255, 255, 0.5); } text-shadow: 0 1px 0 white; }
#user_name a { #user_name a {
color: black; } color: black; }
#user_name a:hover { #user_name a:hover {
color: #cc1e14; } color: #cc1e14; }
#comment_text {
padding: 3px; }
ul.comment_set {
margin: 0;
margin-top: 1em;
padding: 0;
padding-left: 1em;
list-style: none;
width: 90%; }
ul.comment_set li.comment {
margin-bottom: 0.5em;
background-color: #f2f8fc;
padding: 0.6em;
border-radius: 5px; }
ul.comment_set li.comment .from {
color: #666666;
font-weight: normal; }
ul.comment_set li.comment .from a {
color: #333333;
font-weight: bold; }

View file

@ -1,6 +1,4 @@
body body
:font
:family 'helvetica', 'arial', 'sans-serif'
:padding 2em :padding 2em
:margin 0 :margin 0
a a
@ -50,101 +48,82 @@ a
:weight bold :weight bold
:size 12px :size 12px
:background-color #c00 :background-color #c00
:color #fff
p p
:margin 8px 10px :margin 8px 10px
ul ul
:margin 0 :margin 0
header header
:z-index 10 :position relative
:margin -2em
:position fixed :bottom 0
:width 100%
:margin
:top -2em
:right -2em
:left -2em
:height 30px :height 30px
:color #fff :color #fff
:background :background
:color #1A1A21 :color #1A1A21
:border :border
:bottom 2px solid #F2F8FC :bottom 2px solid #fff
:padding :padding
:top 5px :top 5px
#diaspora_text #diaspora_text
:position fixed :position absolute
:border none :border none
:top 8px :top 10px
:left 1em
#session_action #session_action
:position fixed :position absolute
:right 1em :right 300px
:font :font
:size 120% :size 110%
:top 7px :top 7px
a a
:color #ccc :color #ccc
:border none :border none
#show_filters
ul.nav :z-index 100
:position absolute :position absolute
:right 0
:text-align right
#show_filters > a
:border 1px solid #666
:padding 5px
ul#stream_filters
:padding 0 :padding 0
:margin 0 :margin 0
:width 200px
:top 100px
:font
:size 130%
li li
:display block :display block
:padding 5px 10px :padding 5px 0
:background
:color #F2F8FC
:border 1px solid #fff
&:first-child &:first-child
:border-top-right-radius 5px :border-top-right-radius 5px
:border-top-left-radius 5px :border-top-left-radius 5px
&:last-child &:last-child
:border-bottom-right-radius 5px :border-bottom-right-radius 5px
:border-bottom-left-radius 5px :border-bottom-left-radius 5px
a a
:color #B1CFE3 :color #B1CFE3
a:hover
:color #000
#header_below #header_below
:z-index 5 :margin 0 -2em
:position fixed :-webkit-box-shadow 0 2px 2px -1px #999
:height 40px :background-color #F2F8FC
:width 100% :border
:padding 1em :bottom 1px solid #7E96A6
:top 40px :padding
:top 0 :top 0.8em
:background :bottom 0.4em
:color rgba( 255, 255, 255, 0.9)
:margin
:left -2em
img
:position absolute
:width 200px
:border-radius 5px
#content #content
:position absolute :position absolute
:left 250px
:top 94px :top 94px
:width 60%
:min-width 500px #main
:max-width 700px :width 100%
ul#stream ul#stream
:margin 0 :margin 0
@ -161,7 +140,6 @@ ul#stream
li.message li.message
:line-height 140% :line-height 140%
:font :font
:size 120%
:family 'Lucida Grande' :family 'Lucida Grande'
:color #999 :color #999
@ -177,12 +155,17 @@ li.message
:color #bababa :color #bababa
:font-size 70% :font-size 70%
.mine .mine
:background-color rgba(202, 237, 204, 0.5) //:background-color rgba(202, 237, 204, 0.5)
#user_name
:font
:size 15px
:line-height 100%
h1 h1
:position relative :position relative
:font :font
:size 24px :size 18px
:weight bold :weight bold
:line-height 36px :line-height 36px
@ -193,12 +176,6 @@ h1
:color #999 :color #999
:padding 0.1em :padding 0.1em
.big_number
:font
:weight bold
:size 500%
:line-height 100%
h3 h3
:position relative :position relative
:font :font
@ -215,27 +192,13 @@ h3
:margin :margin
:bottom 1em :bottom 1em
#main
:width 70%
:min-width 400px
:max-width 700px
:float left
#friends_list
:float right
:width 20%
:min-width 130px
:padding-left 10%
form form
:font :font
:size 130% :size 120%
:margin 1em :margin 1em
:margin-left 0em :margin-left 0em
input input
:font
:size 150%
:padding 0.2em :padding 0.2em
:max-width 100% :max-width 100%
@ -244,6 +207,32 @@ form
:color #000 :color #000
&:hover &:hover
:color #CC1E14 :color #CC1E14
:background :text
:color rgba( 255, 255, 255, 0.5) :shadow 0 1px 0 #fff
#comment_text
:padding 3px
ul.comment_set
:margin 0
:top 1em
:padding 0
:left 1em
:list-style none
:width 90%
li.comment
:margin
:bottom 0.5em
:background-color #F2F8FC
:padding 0.6em
:border-radius 5px
.from
:color #666
:font
:weight normal
a
:color #333
:font
:weight bold

View file

@ -15,19 +15,7 @@ describe "parser in application helper" do
store_objects_from_xml(xml) store_objects_from_xml(xml)
StatusMessage.count.should == 0 StatusMessage.count.should == 0
end end
it 'should discard posts where it does not know the type' do
xml = "<XML>
<head>
<sender>
<email>#{Friend.first.email}</email>
</sender>
</head><posts>
<post><status_message>\n <message>Here is another message</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post> <post><not_a_real_type></not_a_real_type></post> <post><status_message>\n <message>HEY DUDE</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
</posts></XML>"
store_objects_from_xml(xml)
Post.count.should == 2
Post.first.person.email.should == Friend.first.email
end
it "should reject xml with no sender" do it "should reject xml with no sender" do
xml = "<XML> xml = "<XML>
<head> <head>
@ -40,6 +28,7 @@ describe "parser in application helper" do
Post.count.should == 0 Post.count.should == 0
end end
it "should reject xml with a sender not in the database" do it "should reject xml with a sender not in the database" do
xml = "<XML> xml = "<XML>
<head> <head>
@ -54,6 +43,7 @@ describe "parser in application helper" do
store_objects_from_xml(xml) store_objects_from_xml(xml)
Post.count.should == 0 Post.count.should == 0
end end
it 'should discard types which are not of type post' do it 'should discard types which are not of type post' do
xml = "<XML> xml = "<XML>
<head> <head>
@ -62,13 +52,11 @@ describe "parser in application helper" do
</sender> </sender>
</head> </head>
<posts> <posts>
<post><status_message>\n <message>Here is another message</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
<post><friend></friend></post> <post><friend></friend></post>
<post><status_message>\n <message>HEY DUDE</message>\n <owner>a@a.com</owner>\n <snippet>a@a.com</snippet>\n <source>a@a.com</source>\n</status_message></post>
</posts></XML>" </posts></XML>"
store_objects_from_xml(xml) store_objects_from_xml(xml)
Post.count.should == 2 Post.count.should == 0
Post.first.person.email.should == Friend.first.email
end end