Merge branch 'master' of github.com:diaspora/diaspora_rails

Conflicts:
	app/views/layouts/application.html.haml
	app/views/status_messages/_status_message.html.haml
This commit is contained in:
danielvincent 2010-06-27 10:32:23 -07:00
commit 5be27f33ec
15 changed files with 63 additions and 65 deletions

View file

@ -9,7 +9,7 @@ class DashboardController < ApplicationController
def receive def receive
store_posts_from_xml CGI::unescape(params[:xml]) store_objects_from_xml CGI::unescape(params[:xml])
render :nothing => true render :nothing => true
end end

View file

@ -22,27 +22,28 @@ module ApplicationHelper
doc.xpath("/XML/posts/post") doc.xpath("/XML/posts/post")
end end
def parse_posts_from_xml(xml) def parse_objects_from_xml(xml)
posts = [] objects = []
sender = parse_sender_object_from_xml(xml) sender = parse_sender_object_from_xml(xml)
body = parse_body_contents_from_xml(xml) body = parse_body_contents_from_xml(xml)
body.children.each do |post| body.children.each do |post|
begin begin
object = post.name.camelize.constantize.from_xml post.to_s object = post.name.camelize.constantize.from_xml post.to_s
object.person = sender object.person = sender if object.is_a? Post
posts << object if object.is_a? Post objects << object
rescue rescue
puts "Not a real type: #{post.to_s}" puts "Not a real type: #{object.to_s}"
end end
end end
posts objects
end end
def store_posts_from_xml(xml) def store_objects_from_xml(xml)
posts = parse_posts_from_xml(xml) objects = parse_objects_from_xml(xml)
posts.each do |p| objects.each do |p|
p.save unless p.person.nil? 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 end
@ -66,7 +67,7 @@ module ApplicationHelper
when "User" when "User"
user_path(person) user_path(person)
else else
"#" link_to "unknown person", "#"
end end
end end

View file

@ -25,10 +25,6 @@ class Post
Post.sort(:created_at.desc).all Post.sort(:created_at.desc).all
end end
def each
yield self
end
def self.newest(person = nil) def self.newest(person = nil)
return self.last if person.nil? return self.last if person.nil?

View file

@ -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

View file

@ -1,7 +1,6 @@
= form_for Comment.new, :remote => true do |f| = form_for Comment.new, :remote => true do |f|
= f.error_messages = f.error_messages
%p %p
/= f.label :message
= f.text_field :text, :value => "dislike!" = f.text_field :text, :value => "dislike!"
= f.hidden_field :post_id, :value => post.id = f.hidden_field :post_id, :value => post.id
= f.submit 'comment', :class => 'button' = f.submit 'comment', :class => 'button'

View file

@ -2,7 +2,7 @@
%html %html
%head %head
%title %title
= yield(:title) || "diaspora" = "diaspora"
%meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/ %meta{"http-equiv"=>"Content-Type", :content=>"text/html; charset=utf-8"}/
%meta{"http-equiv"=> "X-UA-Compatible", :content =>"chrome=1" } %meta{"http-equiv"=> "X-UA-Compatible", :content =>"chrome=1" }
@ -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/");

View file

@ -4,12 +4,7 @@
= post.message = post.message
%div.time %div.time
= link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post) = link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post)
%div.comments = render "comments/comments", :post => post
%ul.comment_set
- for comment in post.comments
= render "comments/comment", :comment => comment
= render "comments/new_comment", :post => post
- if mine?(post) - if mine?(post)
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete = link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete

View file

@ -7,7 +7,7 @@ module Diaspora
def notify_friends def notify_friends
if self.person_id == User.first.id 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.add_post_request( friends_with_permissions, CGI::escape(xml) )
@@queue.process @@queue.process
end end

View file

@ -25,7 +25,7 @@ class MessageHandler
case query.type case query.type
when :post when :post
http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body} http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body}
http.callback { process} http.callback {puts query.inspect; process}
when :get when :get
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
http.callback {send_to_seed(query, http.response); process} http.callback {send_to_seed(query, http.response); process}

View file

@ -1,14 +0,0 @@
$(document).ready(function(){
function debug(str){ $("#debug").append("<p>" + 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");
};
});

View file

@ -82,7 +82,7 @@ header {
#show_filters { #show_filters {
z-index: 100; z-index: 100;
position: absolute; position: absolute;
left: 630px; right: 0;
text-align: right; } text-align: right; }
#show_filters > a { #show_filters > a {
@ -126,10 +126,11 @@ ul#stream_filters {
#content { #content {
position: absolute; position: absolute;
top: 94px; top: 94px;
width: 1000px; } width: 60%;
min-width: 700px; }
#main { #main {
width: 700px; } width: 100%; }
ul#stream { ul#stream {
margin: 0; margin: 0;
@ -184,10 +185,9 @@ h3 {
#friends_list { #friends_list {
position: absolute; position: absolute;
left: 600px; right: 0;
width: 20%; width: 20%;
min-width: 130px; min-width: 130px; }
padding-left: 10%; }
form { form {
font-size: 130%; font-size: 130%;

View file

@ -97,7 +97,7 @@ header
#show_filters #show_filters
:z-index 100 :z-index 100
:position absolute :position absolute
:left 630px :right 0
:text-align right :text-align right
#show_filters > a #show_filters > a
@ -143,10 +143,11 @@ ul#stream_filters
#content #content
:position absolute :position absolute
:top 94px :top 94px
:width 1000px :width 60%
:min-width 700px
#main #main
:width 700px :width 100%
ul#stream ul#stream
:margin 0 :margin 0
@ -219,10 +220,9 @@ h3
#friends_list #friends_list
:position absolute :position absolute
:left 600px :right 0
:width 20% :width 20%
:min-width 130px :min-width 130px
:padding-left 10%
form form
:font :font
@ -275,5 +275,3 @@ ul.comment_set
:color #333 :color #333
:font :font
:weight bold :weight bold

View file

@ -30,3 +30,5 @@ end
Factory.define :post do |p| Factory.define :post do |p|
end end
Factory.define(:comment) {}

View file

@ -12,7 +12,7 @@ describe "parser in application helper" do
status_messages = [] status_messages = []
10.times { status_messages << Factory.build(:status_message, :person => @user)} 10.times { status_messages << Factory.build(:status_message, :person => @user)}
xml = Post.build_xml_for(status_messages) xml = Post.build_xml_for(status_messages)
store_posts_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 it 'should discard posts where it does not know the type' do
@ -24,7 +24,7 @@ describe "parser in application helper" do
</head><posts> </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> <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>" </posts></XML>"
store_posts_from_xml(xml) store_objects_from_xml(xml)
Post.count.should == 2 Post.count.should == 2
Post.first.person.email.should == Friend.first.email Post.first.person.email.should == Friend.first.email
end end
@ -36,7 +36,7 @@ describe "parser in application helper" do
<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> <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_posts_from_xml(xml) store_objects_from_xml(xml)
Post.count.should == 0 Post.count.should == 0
end end
@ -51,7 +51,7 @@ describe "parser in application helper" do
<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> <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_posts_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
@ -60,12 +60,13 @@ describe "parser in application helper" do
<sender> <sender>
<email>#{Friend.first.email}</email> <email>#{Friend.first.email}</email>
</sender> </sender>
</head><posts> </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><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> <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_posts_from_xml(xml) store_objects_from_xml(xml)
Post.count.should == 2 Post.count.should == 2
Post.first.person.email.should == Friend.first.email Post.first.person.email.should == Friend.first.email
end end
@ -94,11 +95,26 @@ describe "parser in application helper" do
end end
it 'should be able to extract all posts to an array' do 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.is_a?(Array).should be true
posts.count.should == 10 posts.count.should == 10
end 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 = "<XML><head><sender><email>#{Friend.first.email}</email></sender></head>
<posts>
<post>#{comment.to_xml}</post>
</posts></XML>"
objects = parse_objects_from_xml(xml)
comment = objects.first
comment.text.should == "Freedom!"
comment.person.should == friend
comment.post.should == post
end
end end
end end

View file

@ -59,8 +59,8 @@ describe Diaspora do
end end
it "should send an owners post to their friends" do it "should send an owners post to their friends" do
Post.stub(:build_xml_for).and_return(true) q = Post.send (:class_variable_get, :@@queue)
Post.should_receive(:build_xml_for).and_return true q.should_receive :process
@post.save @post.save
end end