comments should only be dispatched out to remote people from owner. for local people on the same pod, the comment has already been verified by the comment's authority (post owner).

This commit is contained in:
danielvincent 2010-11-28 14:20:27 -05:00
parent e05c113e27
commit 05174436c0
4 changed files with 45 additions and 4 deletions

View file

@ -304,7 +304,17 @@ class User
#push DOWNSTREAM (to original audience)
Rails.logger.info "event=dispatch_comment direction=downstream user=#{self.diaspora_handle} comment=#{comment.id}"
aspects = aspects_with_post(comment.post_id)
push_to_people(comment, people_in_aspects(aspects))
#just socket to local users, as the comment has already
#been associated and saved by post owner
# (we'll push to all of their aspects for now, the comment won't
# show up via js where corresponding posts are not present)
people_in_aspects(aspects, :type => 'local').each do |person|
comment.socket_to_uid(person.owner_id, :aspect_ids => 'all')
end
#push to remote people
push_to_people(comment, people_in_aspects(aspects, :type => 'remote'))
elsif owns? comment
#push UPSTREAM (to poster)

View file

@ -58,9 +58,17 @@ module Diaspora
Person.all(:id.in => person_ids)
end
def people_in_aspects(aspects)
def people_in_aspects(aspects, opts={})
person_ids = contacts_in_aspects(aspects).collect{|contact| contact.person_id}
Person.all(:id.in => person_ids)
people = Person.all(:id.in => person_ids)
if opts[:type] == 'remote'
people.delete_if{ |p| !p.owner_id.blank? }
elsif opts[:type] == 'local'
people.delete_if{ |p| p.owner_id.blank? }
else
people
end
end
def aspect_by_id( id )

View file

@ -18,7 +18,7 @@ var AspectEdit = {
drop: AspectEdit.onDropMove
});
$(".delete").live("click", AspectEdit.deletePerson);
$("#aspect_list").find(".delete").live("click", AspectEdit.deletePerson);
$(".aspect h3").live('focus', AspectEdit.changeName);
},

View file

@ -136,6 +136,29 @@ describe User do
people = user.people_in_aspects([second_aspect])
people.should == [user2.person]
end
it 'should return local/remote people objects for a users contact in each aspect' do
local_user1 = make_user
local_user2 = make_user
remote_user = make_user
asp1 = local_user1.aspects.create(:name => "lol")
asp2 = local_user2.aspects.create(:name => "brb")
asp3 = remote_user.aspects.create(:name => "ttyl")
connect_users(user, first_aspect, local_user1, asp1)
connect_users(user, first_aspect, local_user2, asp2)
connect_users(user, first_aspect, remote_user, asp3)
local_person = remote_user.person
local_person.owner_id = nil
local_person.save
local_person.reload
user.people_in_aspects([first_aspect]).count.should == 4
user.people_in_aspects([first_aspect], :type => 'remote').count.should == 1
user.people_in_aspects([first_aspect], :type => 'local').count.should == 3
end
end
end