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:
commit
5be27f33ec
15 changed files with 63 additions and 65 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
||||
|
|
|
|||
6
app/views/comments/_comments.html.haml
Normal file
6
app/views/comments/_comments.html.haml
Normal 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
|
||||
|
||||
|
|
@ -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'
|
||||
= f.submit 'comment', :class => 'button'
|
||||
|
|
|
|||
|
|
@ -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("<p>" + str); };
|
||||
|
||||
ws = new WebSocket("ws://#{request.host}:8080/");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
};
|
||||
});
|
||||
|
|
@ -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%;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,3 +30,5 @@ end
|
|||
|
||||
Factory.define :post do |p|
|
||||
end
|
||||
|
||||
Factory.define(:comment) {}
|
||||
|
|
@ -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
|
|||
</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_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
|
|||
<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>"
|
||||
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
|
|||
<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>"
|
||||
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
|
|||
<sender>
|
||||
<email>#{Friend.first.email}</email>
|
||||
</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><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>"
|
||||
store_posts_from_xml(xml)
|
||||
</posts></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 = "<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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue