MS DG add participants
This commit is contained in:
parent
dfd1286521
commit
95c206df24
9 changed files with 39 additions and 1 deletions
|
|
@ -22,6 +22,8 @@ module Jobs
|
||||||
|
|
||||||
def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_string)
|
def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_string)
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
|
|
||||||
|
#could be bad here
|
||||||
people = Person.where(:id => person_ids)
|
people = Person.where(:id => person_ids)
|
||||||
|
|
||||||
dispatcher = dispatcher_class_as_string.constantize
|
dispatcher = dispatcher_class_as_string.constantize
|
||||||
|
|
|
||||||
|
|
@ -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'))
|
return if (object.author.diaspora_handle == 'diasporahq@joindiaspora.com' || (object.respond_to?(:relayable?) && object.parent.author.diaspora_handle == 'diasporahq@joindiaspora.com'))
|
||||||
#end hax
|
#end hax
|
||||||
|
|
||||||
|
#this is really terrible
|
||||||
users = User.where(:id => user_ids)
|
users = User.where(:id => user_ids)
|
||||||
person = Person.find_by_id(person_id)
|
person = Person.find_by_id(person_id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,11 @@ module Jobs
|
||||||
@queue = :receive
|
@queue = :receive
|
||||||
|
|
||||||
def self.perform(object_class_string, object_id, recipient_user_ids)
|
def self.perform(object_class_string, object_id, recipient_user_ids)
|
||||||
|
|
||||||
|
|
||||||
object = object_class_string.constantize.find(object_id)
|
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 = Postzord::Receiver::LocalBatch.new(object, recipient_user_ids)
|
||||||
receiver.perform!
|
receiver.perform!
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||||
# licensed under the Affero General Public License version 3 or later. See
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
#
|
|
||||||
class Notification < ActiveRecord::Base
|
class Notification < ActiveRecord::Base
|
||||||
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
require File.join(Rails.root, 'lib/diaspora/web_socket')
|
||||||
include Diaspora::Socketable
|
include Diaspora::Socketable
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ class Person < ActiveRecord::Base
|
||||||
has_many :posts, :foreign_key => :author_id, :dependent => :destroy # This person's own posts
|
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 :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 :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'
|
belongs_to :owner, :class_name => 'User'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,10 @@ module Diaspora
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def particpants
|
||||||
|
self.parent.participants
|
||||||
|
end
|
||||||
|
|
||||||
def receive(user, person=nil)
|
def receive(user, person=nil)
|
||||||
comment_or_like = self.class.where(:guid => self.guid).first || self
|
comment_or_like = self.class.where(:guid => self.guid).first || self
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,21 @@ module Diaspora
|
||||||
end
|
end
|
||||||
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 = []
|
||||||
|
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
|
protected
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ class Postzord::Receiver::LocalBatch < Postzord::Receiver
|
||||||
def initialize(object, recipient_user_ids)
|
def initialize(object, recipient_user_ids)
|
||||||
@object = object
|
@object = object
|
||||||
@recipient_user_ids = recipient_user_ids
|
@recipient_user_ids = recipient_user_ids
|
||||||
|
#this is a nightmare
|
||||||
@users = User.where(:id => @recipient_user_ids)
|
@users = User.where(:id => @recipient_user_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,16 @@ describe Post do
|
||||||
end
|
end
|
||||||
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
|
describe '#comments' do
|
||||||
it 'returns the comments of a post in created_at order' do
|
it 'returns the comments of a post in created_at order' do
|
||||||
post = bob.post :status_message, :text => "hello", :to => 'all'
|
post = bob.post :status_message, :text => "hello", :to => 'all'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue