diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2865c3476..a77a671d8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,6 @@ module ApplicationHelper + require 'lib/common' + include Diaspora::XMLParser def object_path(object) eval("#{object.class.to_s.underscore}_path(object)") end @@ -7,46 +9,6 @@ module ApplicationHelper object.attributes.keys 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) post.person == User.first end 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/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..3cf43c723 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -1,4 +1,6 @@ -%li.comment - = comment.text - \--- - = comment.person.real_name \ No newline at end of file +%li.comment{:id => comment.id} + %span.from + = link_to_person comment.person + = comment.text + %div.time + = "#{time_ago_in_words(comment.updated_at)} ago" diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index e6b0d14cf..399d69c06 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -24,50 +24,51 @@ - if user_signed_in? :javascript - $(document).ready(function(){ - + $(document).ready(function(){ function debug(str){ $("#debug").append("

" + str); }; ws = new WebSocket("ws://#{request.host}:8080/"); ws.onmessage = function(evt) { 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() { - ws.send(location.pathname); - debug("connected..."); - }; + if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) { + $("#stream").prepend($(obj['html']).fadeIn("fast")); + }; + }; + ws.onclose = function() { debug("socket closed"); }; + ws.onopen = function() { + ws.send(location.pathname); + debug("connected..."); + }; }); %body - - flash.each do |name, msg| = content_tag :div, msg, :id => "flash_#{name}" %header - %a#diaspora_text{:href => root_path} - %img{:src => '/images/diaspora_white.png'} + .container + %a#diaspora_text{:href => root_path} + %img{:src => '/images/diaspora_white.png'} + + #session_action + - if user_signed_in? + =User.first.email + | + = link_to "logout", destroy_user_session_path + - else + = link_to "login", new_user_session_path - #session_action - - if user_signed_in? - =User.first.email - | - = link_to "logout", destroy_user_session_path - - else - = link_to "login", new_user_session_path - #header_below - - - if user_signed_in? - %h1#user_name - = link_to User.first.real_name, root_url - %span.description - = my_latest_message + .container + - if user_signed_in? + %h1#user_name + = link_to User.first.real_name, root_url + %span.description + = my_latest_message - %nav - %ul.nav + .container + #content.span-24.last + .span-3.append-1.last + %ul#stream_filters %a{ :href => root_path, :title => "Your network stream."} %li home %a{ :href => status_messages_path, :title => "Recent status messages."} @@ -78,11 +79,8 @@ %li blogs %a{ :href => friends_path, :title => "Your list of connections with other seeds."} %li friends - - - #content - #main - = yield - = render "posts/debug" - #friends_list - = render 'friends/sidebar' if user_signed_in? + .span-15.append-1.last + = yield + = render "posts/debug" + .span-3.last + = render 'friends/sidebar' if user_signed_in? 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 diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index b55c3e185..b3542cf34 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -16,10 +16,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) } } @@ -39,10 +38,11 @@ module WebSocket puts "in failzord " + v .inspect raise "i suck" end + {: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 diff --git a/lib/common.rb b/lib/common.rb index 36bfcd2fe..99cbb3f50 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -1,4 +1,47 @@ 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 def self.included(klass) klass.class_eval do diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 599de669c..42a32ad8f 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1,5 +1,4 @@ body { - font-family: "helvetica", "arial", "sans-serif"; padding: 2em; margin: 0; } @@ -46,82 +45,75 @@ a { margin: 0; font-weight: bold; font-size: 12px; - background-color: #cc0000; - color: white; } + background-color: #cc0000; } .error_messages p { margin: 8px 10px; } .error_messages ul { margin: 0; } header { - z-index: 10; - position: fixed; - width: 100%; - margin-top: -2em; - margin-right: -2em; - margin-left: -2em; + position: relative; + margin: -2em; + margin-bottom: 0; height: 30px; color: white; background-color: #1a1a21; - border-bottom: 2px solid #f2f8fc; + border-bottom: 2px solid white; padding-top: 5px; } header #diaspora_text { - position: fixed; + position: absolute; border: none; - top: 8px; - left: 1em; } + top: 10px; } header #session_action { - position: fixed; - right: 1em; - font-size: 120%; + position: absolute; + right: 300px; + font-size: 110%; top: 7px; } header #session_action a { color: #cccccc; border: none; } -ul.nav { +#show_filters { + z-index: 100; position: absolute; + right: 0; + text-align: right; } + +#show_filters > a { + border: 1px solid #666666; + padding: 5px; } + +ul#stream_filters { padding: 0; - margin: 0; - width: 200px; - top: 100px; - font-size: 130%; } - ul.nav li { + margin: 0; } + ul#stream_filters li { display: block; - padding: 5px 10px; - background-color: #f2f8fc; - border: 1px solid white; } - ul.nav li:first-child { + padding: 5px 0; } + ul#stream_filters li:first-child { border-top-right-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-left-radius: 5px; } - ul.nav a { + ul#stream_filters a { color: #b1cfe3; } + ul#stream_filters a:hover { + color: black; } #header_below { - z-index: 5; - position: fixed; - height: 40px; - width: 100%; - padding: 1em; - padding-top: 40px; - top: 0; - background-color: rgba(255, 255, 255, 0.9); - margin-left: -2em; } - #header_below img { - position: absolute; - width: 200px; - border-radius: 5px; } + margin: 0 -2em; + -webkit-box-shadow: 0 2px 2px -1px #999999; + background-color: #f2f8fc; + border-bottom: 1px solid #7e96a6; + padding-top: 0.8em; + padding-bottom: 0.4em; } #content { position: absolute; - left: 250px; - top: 94px; - width: 60%; - min-width: 500px; - max-width: 700px; } + top: 94px; } + +#main { + width: 100%; } ul#stream { margin: 0; @@ -135,7 +127,6 @@ ul#stream { li.message { line-height: 140%; - font-size: 120%; font-family: "Lucida Grande"; color: #999999; } li.message span.from { @@ -146,12 +137,13 @@ li.message { color: #bababa; font-size: 70%; } -.mine { - background-color: rgba(202, 237, 204, 0.5); } +#user_name { + font-size: 15px; + line-height: 100%; } h1 { position: relative; - font-size: 24px; + font-size: 18px; font-weight: bold; line-height: 36px; } h1 p.description, h1 span.description { @@ -160,11 +152,6 @@ h1 { color: #999999; padding: 0.1em; } -.big_number { - font-weight: bold; - font-size: 500%; - line-height: 100%; } - h3 { position: relative; font-size: 18px; @@ -177,30 +164,39 @@ h3 { width: 100%; 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 { - font-size: 130%; + font-size: 120%; margin: 1em; margin-left: 0em; } form input { - font-size: 150%; padding: 0.2em; max-width: 100%; } #user_name { - background-color: rgba(255, 255, 255, 0.5); } + text-shadow: 0 1px 0 white; } #user_name a { color: black; } #user_name a:hover { 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; } diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 9e13e0657..7f53a466b 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -1,6 +1,4 @@ body - :font - :family 'helvetica', 'arial', 'sans-serif' :padding 2em :margin 0 a @@ -50,101 +48,82 @@ a :weight bold :size 12px :background-color #c00 - :color #fff p :margin 8px 10px ul :margin 0 header - :z-index 10 - - :position fixed - :width 100% - - :margin - :top -2em - :right -2em - :left -2em - + :position relative + :margin -2em + :bottom 0 :height 30px :color #fff :background :color #1A1A21 :border - :bottom 2px solid #F2F8FC + :bottom 2px solid #fff :padding :top 5px #diaspora_text - :position fixed + :position absolute :border none - :top 8px - :left 1em + :top 10px #session_action - :position fixed - :right 1em + :position absolute + :right 300px :font - :size 120% + :size 110% :top 7px a :color #ccc :border none - -ul.nav +#show_filters + :z-index 100 :position absolute + :right 0 + :text-align right + +#show_filters > a + :border 1px solid #666 + :padding 5px + +ul#stream_filters :padding 0 :margin 0 - :width 200px - :top 100px - :font - :size 130% - li :display block - :padding 5px 10px - :background - :color #F2F8FC - :border 1px solid #fff - - + :padding 5px 0 &:first-child :border-top-right-radius 5px :border-top-left-radius 5px - &:last-child :border-bottom-right-radius 5px :border-bottom-left-radius 5px - a :color #B1CFE3 + a:hover + :color #000 #header_below - :z-index 5 - :position fixed - :height 40px - :width 100% - :padding 1em - :top 40px - :top 0 - :background - :color rgba( 255, 255, 255, 0.9) - :margin - :left -2em - img - :position absolute - :width 200px - :border-radius 5px + :margin 0 -2em + :-webkit-box-shadow 0 2px 2px -1px #999 + :background-color #F2F8FC + :border + :bottom 1px solid #7E96A6 + :padding + :top 0.8em + :bottom 0.4em #content :position absolute - :left 250px :top 94px - :width 60% - :min-width 500px - :max-width 700px + +#main + :width 100% ul#stream :margin 0 @@ -161,7 +140,6 @@ ul#stream li.message :line-height 140% :font - :size 120% :family 'Lucida Grande' :color #999 @@ -177,12 +155,17 @@ li.message :color #bababa :font-size 70% .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 :position relative :font - :size 24px + :size 18px :weight bold :line-height 36px @@ -193,12 +176,6 @@ h1 :color #999 :padding 0.1em -.big_number - :font - :weight bold - :size 500% - :line-height 100% - h3 :position relative :font @@ -214,28 +191,14 @@ h3 :width 100% :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 :font - :size 130% + :size 120% :margin 1em :margin-left 0em input - :font - :size 150% :padding 0.2em :max-width 100% @@ -244,6 +207,32 @@ form :color #000 &:hover :color #CC1E14 - :background - :color rgba( 255, 255, 255, 0.5) - + :text + :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 diff --git a/spec/helpers/parser_spec.rb b/spec/helpers/parser_spec.rb index 40fe5aea5..3cc11f71c 100644 --- a/spec/helpers/parser_spec.rb +++ b/spec/helpers/parser_spec.rb @@ -15,19 +15,7 @@ describe "parser in application helper" do store_objects_from_xml(xml) StatusMessage.count.should == 0 end - it 'should discard posts where it does not know the type' do - xml = " - - - #{Friend.first.email} - - - \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n - " - 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 xml = " @@ -40,6 +28,7 @@ describe "parser in application helper" do Post.count.should == 0 end + it "should reject xml with a sender not in the database" do xml = " @@ -54,6 +43,7 @@ describe "parser in application helper" do store_objects_from_xml(xml) Post.count.should == 0 end + it 'should discard types which are not of type post' do xml = " @@ -62,13 +52,11 @@ describe "parser in application helper" do - \n Here is another message\n a@a.com\n a@a.com\n a@a.com\n - \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " + store_objects_from_xml(xml) - Post.count.should == 2 - Post.first.person.email.should == Friend.first.email + Post.count.should == 0 end