Merge branch 'participants'

This commit is contained in:
Maxwell Salzberg 2011-11-04 18:46:58 -07:00
commit 7417801886
10 changed files with 59 additions and 11 deletions

View file

@ -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

View file

@ -9,17 +9,12 @@ module Jobs
require File.join(Rails.root, 'app/models/notification')
def self.perform(user_ids, object_klass, object_id, person_id)
object = object_klass.constantize.find_by_id(object_id)
#hax
return if (object.author.diaspora_handle == 'diasporahq@joindiaspora.com' || (object.respond_to?(:relayable?) && object.parent.author.diaspora_handle == 'diasporahq@joindiaspora.com'))
#end hax
users = User.where(:id => user_ids)
users = object.participant_users
person = Person.find_by_id(person_id)
users.each{|user| Notification.notify(user, object, person) }
users.each do |user|
Notification.notify(user, object, person)
end
end
end
end

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -46,6 +46,14 @@ module Diaspora
end
end
def particpants
self.parent.participants
end
def participant_users
self.parent.participant_users
end
def receive(user, person=nil)
comment_or_like = self.class.where(:guid => self.guid).first || self

View file

@ -107,6 +107,28 @@ module Diaspora
end
end
# @return [Array<Person>] The list of participants to this shareable
def participants
@participants ||= lambda do
share_type = self.class.base_class.to_s
people = [self.author]
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
def participant_users
@participant_users ||= lambda do
user_ids = participants.map{|x| x.owner_id}.compact
User.where(:id => user_ids)
end.call
end
protected

View file

@ -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

View file

@ -117,5 +117,4 @@ class Stream::Multi < Stream::Base
def ids(query)
Post.connection.select_values(query.for_a_stream(max_time, order).select('posts.id').to_sql)
end
end

View file

@ -195,6 +195,22 @@ describe Post do
end
end
describe '#participants' do
it 'includes the post author' do
status = Factory(:status_message, :author => bob.person, :public => true)
status.participants.map(&:id).should == [bob.person.id]
end
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, bob].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'