diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 834b33395..4bf1ade9d 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -9,7 +9,7 @@ class DashboardController < ApplicationController def receive - store_posts_from_xml CGI::unescape(params[:xml]) + store_objects_from_xml CGI::unescape(params[:xml]) render :nothing => true end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 50b8f700b..2865c3476 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -22,27 +22,28 @@ module ApplicationHelper doc.xpath("/XML/posts/post") end - def parse_posts_from_xml(xml) - posts = [] + 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 - posts << object if object.is_a? Post + object.person = sender if object.is_a? Post + objects << object rescue - puts "Not a real type: #{post.to_s}" + puts "Not a real type: #{object.to_s}" end end - posts + objects end - def store_posts_from_xml(xml) - posts = parse_posts_from_xml(xml) + def store_objects_from_xml(xml) + objects = parse_objects_from_xml(xml) - posts.each do |p| - p.save unless p.person.nil? + 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 @@ -66,7 +67,7 @@ module ApplicationHelper when "User" user_path(person) else - "#" + link_to "unknown person", "#" end end diff --git a/app/models/post.rb b/app/models/post.rb index 6a450ebac..0aba89918 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -25,10 +25,6 @@ class Post Post.sort(:created_at.desc).all end - def each - yield self - end - def self.newest(person = nil) return self.last if person.nil? diff --git a/app/views/comments/_comments.html.haml b/app/views/comments/_comments.html.haml new file mode 100644 index 000000000..374f585e5 --- /dev/null +++ b/app/views/comments/_comments.html.haml @@ -0,0 +1,6 @@ +%div.comments + = render "comments/new_comment", :post => post + %ul.comment_set + - for comment in post.comments + = render "comments/comment", :comment => comment + diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index 0480c968f..b377602e3 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -1,7 +1,6 @@ = form_for Comment.new, :remote => true do |f| = f.error_messages %p - /= f.label :message = f.text_field :text, :value => "dislike!" = f.hidden_field :post_id, :value => post.id - = f.submit 'comment', :class => 'button' \ No newline at end of file + = f.submit 'comment', :class => 'button' diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index cc03cceae..1afb41e7b 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,7 +2,7 @@ %html %head %title - = yield(:title) || "diaspora" + = "diaspora" %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ %meta{"http-equiv"=> "X-UA-Compatible", :content =>"chrome=1" } @@ -25,7 +25,6 @@ - if user_signed_in? :javascript $(document).ready(function(){ - function debug(str){ $("#debug").append("

" + str); }; ws = new WebSocket("ws://#{request.host}:8080/"); diff --git a/app/views/status_messages/_status_message.html.haml b/app/views/status_messages/_status_message.html.haml index 83e86f72e..d1c6611c1 100644 --- a/app/views/status_messages/_status_message.html.haml +++ b/app/views/status_messages/_status_message.html.haml @@ -4,12 +4,7 @@ = post.message %div.time = link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post) - %div.comments - %ul.comment_set - - for comment in post.comments - = render "comments/comment", :comment => comment - = render "comments/new_comment", :post => post - + = render "comments/comments", :post => post - if mine?(post) = link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete diff --git a/lib/common.rb b/lib/common.rb index 0d1320361..36bfcd2fe 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -7,7 +7,7 @@ module Diaspora def notify_friends if self.person_id == User.first.id - xml = Post.build_xml_for(self) + xml = Post.build_xml_for([self]) @@queue.add_post_request( friends_with_permissions, CGI::escape(xml) ) @@queue.process end diff --git a/lib/message_handler.rb b/lib/message_handler.rb index 7d75ce08c..6fb15dfbe 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -25,7 +25,7 @@ class MessageHandler case query.type when :post http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body} - http.callback { process} + http.callback {puts query.inspect; process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} diff --git a/public/javascripts/socket.js b/public/javascripts/socket.js deleted file mode 100644 index 7db6c9130..000000000 --- a/public/javascripts/socket.js +++ /dev/null @@ -1,14 +0,0 @@ -$(document).ready(function(){ - function debug(str){ $("#debug").append("

" + str); }; - - ws = new WebSocket("ws://localhost:8080/"); - ws.onmessage = function(evt) { - $("#stream").prepend($(evt.data).fadeIn("fast")); - }; - ws.onclose = function() { debug("socket closed"); }; - ws.onopen = function() { - debug("connected..."); - //ws.send("hello server"); - // ws.send("hello again"); - }; -}); diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index e422bbfaf..c62f3f1b4 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -82,7 +82,7 @@ header { #show_filters { z-index: 100; position: absolute; - left: 630px; + right: 0; text-align: right; } #show_filters > a { @@ -126,10 +126,11 @@ ul#stream_filters { #content { position: absolute; top: 94px; - width: 1000px; } + width: 60%; + min-width: 700px; } #main { - width: 700px; } + width: 100%; } ul#stream { margin: 0; @@ -184,10 +185,9 @@ h3 { #friends_list { position: absolute; - left: 600px; + right: 0; width: 20%; - min-width: 130px; - padding-left: 10%; } + min-width: 130px; } form { font-size: 130%; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index afb209745..f93d35e4a 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -97,7 +97,7 @@ header #show_filters :z-index 100 :position absolute - :left 630px + :right 0 :text-align right #show_filters > a @@ -143,10 +143,11 @@ ul#stream_filters #content :position absolute :top 94px - :width 1000px + :width 60% + :min-width 700px #main - :width 700px + :width 100% ul#stream :margin 0 @@ -219,10 +220,9 @@ h3 #friends_list :position absolute - :left 600px + :right 0 :width 20% :min-width 130px - :padding-left 10% form :font @@ -275,5 +275,3 @@ ul.comment_set :color #333 :font :weight bold - - diff --git a/spec/factories.rb b/spec/factories.rb index 5055b0023..ded4bf247 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -30,3 +30,5 @@ end Factory.define :post do |p| end + +Factory.define(:comment) {} \ No newline at end of file diff --git a/spec/helpers/parser_spec.rb b/spec/helpers/parser_spec.rb index eae4ce7fd..40fe5aea5 100644 --- a/spec/helpers/parser_spec.rb +++ b/spec/helpers/parser_spec.rb @@ -12,7 +12,7 @@ describe "parser in application helper" do status_messages = [] 10.times { status_messages << Factory.build(:status_message, :person => @user)} xml = Post.build_xml_for(status_messages) - store_posts_from_xml(xml) + store_objects_from_xml(xml) StatusMessage.count.should == 0 end it 'should discard posts where it does not know the type' do @@ -24,7 +24,7 @@ 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_posts_from_xml(xml) + store_objects_from_xml(xml) Post.count.should == 2 Post.first.person.email.should == Friend.first.email end @@ -36,7 +36,7 @@ describe "parser in application helper" do \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " - store_posts_from_xml(xml) + store_objects_from_xml(xml) Post.count.should == 0 end @@ -51,7 +51,7 @@ describe "parser in application helper" do \n HEY DUDE\n a@a.com\n a@a.com\n a@a.com\n " - store_posts_from_xml(xml) + store_objects_from_xml(xml) Post.count.should == 0 end it 'should discard types which are not of type post' do @@ -60,12 +60,13 @@ describe "parser in application helper" do #{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_posts_from_xml(xml) + " + store_objects_from_xml(xml) Post.count.should == 2 Post.first.person.email.should == Friend.first.email end @@ -94,10 +95,25 @@ describe "parser in application helper" do end it 'should be able to extract all posts to an array' do - posts = parse_posts_from_xml(@xml) + posts = parse_objects_from_xml(@xml) posts.is_a?(Array).should be true posts.count.should == 10 end + + it 'should be able to correctly handle comments' do + friend = Factory.create(:friend) + post = Factory.create(:status_message) + comment = Factory.build(:comment, :post => post, :person => friend, :text => "Freedom!") + xml = "#{Friend.first.email} + + #{comment.to_xml} + " + objects = parse_objects_from_xml(xml) + comment = objects.first + comment.text.should == "Freedom!" + comment.person.should == friend + comment.post.should == post + end end diff --git a/spec/lib/common_spec.rb b/spec/lib/common_spec.rb index 3b4be323b..8a37fc20a 100644 --- a/spec/lib/common_spec.rb +++ b/spec/lib/common_spec.rb @@ -59,8 +59,8 @@ describe Diaspora do end it "should send an owners post to their friends" do - Post.stub(:build_xml_for).and_return(true) - Post.should_receive(:build_xml_for).and_return true + q = Post.send (:class_variable_get, :@@queue) + q.should_receive :process @post.save end