Merge branch 'master' of github.com:diaspora/diaspora_rails
This commit is contained in:
commit
f759f5d1b7
10 changed files with 100 additions and 49 deletions
|
|
@ -3,12 +3,12 @@ class Comment
|
||||||
include ROXML
|
include ROXML
|
||||||
include Diaspora::Webhooks
|
include Diaspora::Webhooks
|
||||||
|
|
||||||
|
|
||||||
xml_accessor :text
|
xml_accessor :text
|
||||||
xml_accessor :person, :as => Person
|
xml_accessor :person, :as => Person
|
||||||
xml_accessor :post_id
|
xml_accessor :post_id
|
||||||
|
|
||||||
key :text, String
|
key :text, String
|
||||||
key :target, String
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
key :post_id, ObjectId
|
key :post_id, ObjectId
|
||||||
|
|
@ -17,11 +17,25 @@ class Comment
|
||||||
key :person_id, ObjectId
|
key :person_id, ObjectId
|
||||||
belongs_to :person, :class_name => "Person"
|
belongs_to :person, :class_name => "Person"
|
||||||
|
|
||||||
|
after_save :send_friends_comments_on_my_posts
|
||||||
|
after_save :send_to_view
|
||||||
|
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
(self.message == other.message) && (self.person.email == other.person.email)
|
(self.message == other.message) && (self.person.email == other.person.email)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def send_friends_comments_on_my_posts
|
||||||
|
if (User.first.mine?(self.post) && self.person.is_a?(Friend))
|
||||||
|
self.push_to(self.post.friends_with_permissions)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def send_to_view
|
||||||
|
WebSocket.update_clients(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
%li.comment{:id => comment.id}
|
%li.comment{:id => post.id}
|
||||||
%span.from
|
%span.from
|
||||||
= link_to_person comment.person
|
= link_to_person post.person
|
||||||
= auto_link comment.text
|
= auto_link post.text
|
||||||
%div.time
|
%div.time
|
||||||
= "#{time_ago_in_words(comment.updated_at)} ago"
|
= "#{time_ago_in_words(post.updated_at)} ago"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
%div.comments
|
%div.comments
|
||||||
%ul.comment_set
|
%ul.comment_set{:id => post.id}
|
||||||
- for comment in post.comments
|
- for comment in post.comments
|
||||||
= render "comments/comment", :comment => comment
|
= render 'comments/comment', :post => comment
|
||||||
%li.comment
|
%li.comment
|
||||||
= render "comments/new_comment", :post => post
|
= render 'comments/new_comment', :post => post
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,20 @@
|
||||||
ws.onmessage = function(evt) {
|
ws.onmessage = function(evt) {
|
||||||
var obj = jQuery.parseJSON(evt.data);
|
var obj = jQuery.parseJSON(evt.data);
|
||||||
debug("got a " + obj['class']);
|
debug("got a " + obj['class']);
|
||||||
if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) {
|
|
||||||
|
|
||||||
|
function onPageOne() {
|
||||||
|
var c = document.location.search.charAt(document.location.search.length-1);
|
||||||
|
return ((c =='') || (c== '1'))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (obj['class']=="comments"){
|
||||||
|
var post_id = obj['post_id']
|
||||||
|
$('#'+ obj['post_id'] + ' .comment_set li:last' ).before(
|
||||||
|
$(obj['html']).fadeIn("fast", function(){})
|
||||||
|
)
|
||||||
|
}else if(((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) && onPageOne()) {
|
||||||
$("#stream").prepend(
|
$("#stream").prepend(
|
||||||
$(obj['html']).fadeIn("fast", function(){
|
$(obj['html']).fadeIn("fast", function(){
|
||||||
$("#stream label:first").inFieldLabels();
|
$("#stream label:first").inFieldLabels();
|
||||||
|
|
@ -24,4 +37,4 @@
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
ws.send(location.pathname);
|
ws.send(location.pathname);
|
||||||
debug("connected...");
|
debug("connected...");
|
||||||
};});
|
};});
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
|
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
|
||||||
= javascript_include_tag 'jquery142', 'rails', 'view', 'publisher'
|
= javascript_include_tag 'jquery142', 'rails', 'view', 'publisher'
|
||||||
= javascript_include_tag 'tiny_mce/tiny_mce.js','jquery.infieldlabel'
|
= javascript_include_tag 'tiny_mce/tiny_mce.js','jquery.infieldlabel'
|
||||||
= render "js/google_a_js"
|
= render 'js/google_a_js'
|
||||||
= render "js/websocket_js"
|
= render 'js/websocket_js'
|
||||||
|
|
||||||
= csrf_meta_tag
|
= csrf_meta_tag
|
||||||
= yield(:head)
|
= yield(:head)
|
||||||
|
|
|
||||||
|
|
@ -69,10 +69,12 @@ module Diaspora
|
||||||
|
|
||||||
|
|
||||||
def push_to(recipients)
|
def push_to(recipients)
|
||||||
recipients.map!{|x| x = x.url + "receive/"}
|
unless recipients.empty?
|
||||||
xml = self.class.build_xml_for([self])
|
recipients.map!{|x| x = x.url + "receive/"}
|
||||||
@@queue.add_post_request( recipients, xml )
|
xml = self.class.build_xml_for([self])
|
||||||
@@queue.process
|
@@queue.add_post_request( recipients, xml )
|
||||||
|
@@queue.process
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,22 @@ module SocketRenderer
|
||||||
puts e.message
|
puts e.message
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
{:class =>object.class.to_s.underscore.pluralize, :html => v}
|
|
||||||
|
{:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.view_for(object)
|
def self.view_for(object)
|
||||||
|
puts object.inspect
|
||||||
|
puts @view.type_partial(object)
|
||||||
|
|
||||||
@view.render @view.type_partial(object), :post => object
|
@view.render @view.type_partial(object), :post => object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.obj_id(object)
|
||||||
|
if object.is_a? Post
|
||||||
|
object.id
|
||||||
|
else
|
||||||
|
object.post.id
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ describe Diaspora do
|
||||||
describe Webhooks do
|
describe Webhooks do
|
||||||
before do
|
before do
|
||||||
@user = Factory.create(:user, :email => "bob@aol.com")
|
@user = Factory.create(:user, :email => "bob@aol.com")
|
||||||
|
@friend = Factory.create(:friend)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "header" do
|
describe "header" do
|
||||||
|
|
@ -53,9 +54,7 @@ describe Diaspora do
|
||||||
Factory.create(:friend, :url => "http://www.alice.com/")
|
Factory.create(:friend, :url => "http://www.alice.com/")
|
||||||
Factory.create(:friend, :url => "http://www.jane.com/")
|
Factory.create(:friend, :url => "http://www.jane.com/")
|
||||||
|
|
||||||
@post.friends_with_permissions.should include("http://www.bob.com/receive/")
|
@post.friends_with_permissions.should == Friend.all
|
||||||
@post.friends_with_permissions.should include("http://www.alice.com/receive/")
|
|
||||||
@post.friends_with_permissions.should include("http://www.jane.com/receive/")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should send an owners post to their friends" do
|
it "should send an owners post to their friends" do
|
||||||
|
|
@ -73,7 +72,7 @@ describe Diaspora do
|
||||||
|
|
||||||
it "should ensure one url is created for every friend" do
|
it "should ensure one url is created for every friend" do
|
||||||
5.times {Factory.create(:friend)}
|
5.times {Factory.create(:friend)}
|
||||||
@post.friends_with_permissions.size.should == 5
|
@post.friends_with_permissions.size.should == 6
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should build an xml object containing multiple Post types" do
|
it "should build an xml object containing multiple Post types" do
|
||||||
|
|
|
||||||
|
|
@ -103,20 +103,6 @@ describe "parser in application helper" do
|
||||||
comment.post.should == post
|
comment.post.should == post
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it 'should parse a person out of a post' do
|
|
||||||
@user.comment "foo", :on => @status_messages.first
|
|
||||||
xml = Comment.build_xml_for([Comment.first])
|
|
||||||
puts xml
|
|
||||||
objs = parse_objects_from_xml(xml)
|
|
||||||
|
|
||||||
puts objs.inspect
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -15,21 +15,47 @@ describe Comment do
|
||||||
|
|
||||||
it "should be able to comment on a friend's status" do
|
it "should be able to comment on a friend's status" do
|
||||||
friend = Factory.create :friend
|
friend = Factory.create :friend
|
||||||
status = Factory.create(:status_message, :person => @friend)
|
status = Factory.create(:status_message, :person => friend)
|
||||||
@user.comment "sup dog", :on => status
|
@user.comment "sup dog", :on => status
|
||||||
|
|
||||||
StatusMessage.first.comments.first.text.should == "sup dog"
|
StatusMessage.first.comments.first.text.should == "sup dog"
|
||||||
StatusMessage.first.comments.first.person.should == @user
|
StatusMessage.first.comments.first.person.should == @user
|
||||||
end
|
end
|
||||||
|
it 'should not send out comments when we have no friends' do
|
||||||
|
status = Factory.create(:status_message, :person => @user)
|
||||||
it 'should be able to send a post owner any new comments a user adds' do
|
Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request)
|
||||||
friend = Factory.create(:friend)
|
@user.comment "sup dog", :on => status
|
||||||
status = Factory.create(:status_message, :person => friend)
|
|
||||||
|
|
||||||
Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
|
||||||
@user.comment "yo", :on => status
|
|
||||||
end
|
end
|
||||||
|
describe 'comment propagation' do
|
||||||
|
before do
|
||||||
|
@friend = Factory.create(:friend)
|
||||||
|
@friend_two = Factory.create(:friend)
|
||||||
|
@friend_status = Factory.create(:status_message, :person => @friend)
|
||||||
|
@user_status = Factory.create(:status_message, :person => @user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should send a user's comment on a friend's post to that friend" do
|
||||||
|
Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||||
|
@user.comment "yo", :on => @friend_status
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should send a user comment on his own post to lots of friends' do
|
||||||
|
allowed_urls = @user_status.friends_with_permissions.map!{|x| x = x.url + "receive/"}
|
||||||
|
Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request).with(allowed_urls, anything )
|
||||||
|
@user.comment "yo", :on => @user_status
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should send a comment a friend made on your post to all friends' do
|
||||||
|
Comment.send(:class_variable_get, :@@queue).should_receive(:add_post_request)
|
||||||
|
com = Comment.create(:person => @friend, :text => "balls", :post => @user_status)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not send a comment a friend made on a friend post to anyone' do
|
||||||
|
Comment.send(:class_variable_get, :@@queue).should_not_receive(:add_post_request)
|
||||||
|
com = Comment.create(:person => @friend, :text => "balls", :post => @friend_status)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
Reference in a new issue