diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index 044deb470..de333e74d 100644 --- a/app/models/jobs/http_multi.rb +++ b/app/models/jobs/http_multi.rb @@ -22,6 +22,8 @@ module Jobs def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_string) user = User.find(user_id) + + #could be bad here people = Person.where(:id => person_ids) dispatcher = dispatcher_class_as_string.constantize diff --git a/app/models/jobs/notify_local_users.rb b/app/models/jobs/notify_local_users.rb index f75d5418e..791b3f628 100644 --- a/app/models/jobs/notify_local_users.rb +++ b/app/models/jobs/notify_local_users.rb @@ -16,6 +16,7 @@ module Jobs return if (object.author.diaspora_handle == 'diasporahq@joindiaspora.com' || (object.respond_to?(:relayable?) && object.parent.author.diaspora_handle == 'diasporahq@joindiaspora.com')) #end hax + #this is really terrible users = User.where(:id => user_ids) person = Person.find_by_id(person_id) diff --git a/app/models/jobs/receive_local_batch.rb b/app/models/jobs/receive_local_batch.rb index ec8b781a6..8d408c2ef 100644 --- a/app/models/jobs/receive_local_batch.rb +++ b/app/models/jobs/receive_local_batch.rb @@ -11,7 +11,11 @@ module Jobs @queue = :receive def self.perform(object_class_string, object_id, recipient_user_ids) + + object = object_class_string.constantize.find(object_id) + + #recipient user ids could be really bad receiver = Postzord::Receiver::LocalBatch.new(object, recipient_user_ids) receiver.perform! end diff --git a/app/models/notification.rb b/app/models/notification.rb index 40711786a..bd61c7684 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -1,7 +1,7 @@ # Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -# + class Notification < ActiveRecord::Base require File.join(Rails.root, 'lib/diaspora/web_socket') include Diaspora::Socketable diff --git a/app/models/person.rb b/app/models/person.rb index 0d6d40829..4928fbb77 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -30,6 +30,7 @@ class Person < ActiveRecord::Base has_many :posts, :foreign_key => :author_id, :dependent => :destroy # This person's own posts has_many :photos, :foreign_key => :author_id, :dependent => :destroy # This person's own photos has_many :comments, :foreign_key => :author_id, :dependent => :destroy # This person's own comments + has_many :likes, :foreign_key => :author_id, :dependent => :destroy # This person's own likes belongs_to :owner, :class_name => 'User' diff --git a/lib/diaspora/relayable.rb b/lib/diaspora/relayable.rb index 18f62bff4..b7d9a7aa5 100644 --- a/lib/diaspora/relayable.rb +++ b/lib/diaspora/relayable.rb @@ -46,6 +46,10 @@ module Diaspora end end + def particpants + self.parent.participants + end + def receive(user, person=nil) comment_or_like = self.class.where(:guid => self.guid).first || self diff --git a/lib/diaspora/shareable.rb b/lib/diaspora/shareable.rb index 1ba5746ef..b7acf69e6 100644 --- a/lib/diaspora/shareable.rb +++ b/lib/diaspora/shareable.rb @@ -107,6 +107,21 @@ module Diaspora end end + # @return [Array] The list of participants to this shareable + def participants + @participants ||= lambda do + share_type = self.class.base_class.to_s + people = [] + if self.respond_to? :comments + people += Person.joins(:comments).where(:comments => {:commentable_id => self.id, :commentable_type => share_type}).all + end + + if self.respond_to? :likes + people += Person.joins(:likes).where(:likes => {:target_id => self.id, :target_type => share_type}).all + end + people + end.call + end protected diff --git a/lib/postzord/receiver/local_batch.rb b/lib/postzord/receiver/local_batch.rb index be91e2c93..24b607968 100644 --- a/lib/postzord/receiver/local_batch.rb +++ b/lib/postzord/receiver/local_batch.rb @@ -9,6 +9,7 @@ class Postzord::Receiver::LocalBatch < Postzord::Receiver def initialize(object, recipient_user_ids) @object = object @recipient_user_ids = recipient_user_ids + #this is a nightmare @users = User.where(:id => @recipient_user_ids) end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 55f9b3430..64c512953 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -195,6 +195,16 @@ describe Post do end end + describe '#participants' do + it 'only returns the people that commented and liked the post' do + status = Factory(:status_message, :author => bob.person, :public => true) + alice.comment('too', :post => status) + eve.like(true, :target => status) + + status.participants.map(&:id).should =~ [alice, eve].map{|x| x.person.id} + end + end + describe '#comments' do it 'returns the comments of a post in created_at order' do post = bob.post :status_message, :text => "hello", :to => 'all'