diff --git a/app/models/user.rb b/app/models/user.rb index c19aaf592..e8a03e261 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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) diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 786aa9bda..1cadcc725 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -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 ) diff --git a/public/javascripts/aspect-edit.js b/public/javascripts/aspect-edit.js index a2aea60d2..b07113109 100644 --- a/public/javascripts/aspect-edit.js +++ b/public/javascripts/aspect-edit.js @@ -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); }, diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index 9b19ecca5..a03545736 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -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