pass in service_type strings instead of objects to deferred_dispatcher.

This commit is contained in:
danielgrippi 2012-01-27 16:05:38 -08:00
parent 67432bfaf4
commit 31bfef9dd2
4 changed files with 7 additions and 6 deletions

View file

@ -51,9 +51,9 @@ class StatusMessagesController < ApplicationController
if @status_message.save if @status_message.save
aspects = current_user.aspects_from_ids(destination_aspect_ids) aspects = current_user.aspects_from_ids(destination_aspect_ids)
current_user.add_to_streams(@status_message, aspects) current_user.add_to_streams(@status_message, aspects)
receiving_services = current_user.services.where(:type => Service.titles(services)) receiving_services = Service.titles(services)
current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :services => receiving_services)
current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :service_types => receiving_services)
if coming_from_profile_page? # if this is a post coming from a profile page if coming_from_profile_page? # if this is a post coming from a profile page
flash[:notice] = successful_mention_message flash[:notice] = successful_mention_message

View file

@ -9,6 +9,7 @@ module Jobs
def self.perform(user_id, object_class_name, object_id, opts) def self.perform(user_id, object_class_name, object_id, opts)
user = User.find(user_id) user = User.find(user_id)
object = object_class_name.constantize.find(object_id) object = object_class_name.constantize.find(object_id)
opts[:services] = user.services.where(:type => opts.delete(:service_types)).all
if opts[:additional_subscribers].present? if opts[:additional_subscribers].present?
opts[:additional_subscribers] = Person.where(:id => opts[:additional_subscribers]) opts[:additional_subscribers] = Person.where(:id => opts[:additional_subscribers])

View file

@ -25,7 +25,7 @@ class Postzord::Dispatcher
# @return [Postzord::Dispatcher] Public or private dispatcher depending on the object's intended audience # @return [Postzord::Dispatcher] Public or private dispatcher depending on the object's intended audience
def self.build(user, object, opts={}) def self.build(user, object, opts={})
unless object.respond_to? :to_diaspora_xml unless object.respond_to? :to_diaspora_xml
raise 'this object does not respond_to? to_diaspora xml. try including Diaspora::Webhooks into your object' raise 'This object does not respond_to? to_diaspora xml. Try including Diaspora::Webhooks into your object'
end end
if self.object_should_be_processed_as_public?(object) if self.object_should_be_processed_as_public?(object)
@ -36,7 +36,6 @@ class Postzord::Dispatcher
end end
def self.defer_build_and_post(user, object, opts={}) def self.defer_build_and_post(user, object, opts={})
opts[:additional_subscribers] ||= []
opts[:additional_subscribers] = [*opts[:additional_subscribers]].map(&:id) opts[:additional_subscribers] = [*opts[:additional_subscribers]].map(&:id)
Resque.enqueue(Jobs::DeferredDispatch, user.id, object.class.to_s, object.id, opts) Resque.enqueue(Jobs::DeferredDispatch, user.id, object.class.to_s, object.id, opts)
end end

View file

@ -68,7 +68,8 @@ describe StatusMessagesController do
alice.services << s1 alice.services << s1
alice.services << Services::Twitter.new alice.services << Services::Twitter.new
status_message_hash[:services] = ['facebook'] status_message_hash[:services] = ['facebook']
alice.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1])) service_types = Service.titles(status_message_hash[:services])
alice.should_receive(:dispatch_post).with(anything(), hash_including(:service_types => service_types))
post :create, status_message_hash post :create, status_message_hash
end end
@ -76,7 +77,7 @@ describe StatusMessagesController do
s1 = Services::Facebook.new s1 = Services::Facebook.new
alice.services << s1 alice.services << s1
status_message_hash[:services] = "facebook" status_message_hash[:services] = "facebook"
alice.should_receive(:dispatch_post).with(anything(), hash_including(:services => [s1])) alice.should_receive(:dispatch_post).with(anything(), hash_including(:service_types => ["Services::Facebook"]))
post :create, status_message_hash post :create, status_message_hash
end end