Commit ae05d4e9 authored by Benjamin Neff's avatar Benjamin Neff

use Diaspora::Federation::Dispatcher everywhere

parent b0942bc2
......@@ -45,7 +45,7 @@ class ConversationsController < ApplicationController
@response = {}
if person_ids.present? && @conversation.save
Postzord::Dispatcher.build(current_user, @conversation).post
Diaspora::Federation::Dispatcher.defer_dispatch(current_user, @conversation)
@response[:success] = true
@response[:message] = I18n.t('conversations.create.sent')
@response[:conversation_id] = @conversation.id
......
......@@ -17,7 +17,7 @@ class MessagesController < ApplicationController
if message.save
logger.info "event=create type=comment user=#{current_user.diaspora_handle} status=success " \
"message=#{message.id} chars=#{params[:message][:text].length}"
Postzord::Dispatcher.build(current_user, message).post
Diaspora::Federation::Dispatcher.defer_dispatch(current_user, message)
else
flash[:error] = I18n.t('conversations.new_conversation.fail')
end
......
......@@ -25,18 +25,14 @@ class AccountDeletion < ActiveRecord::Base
end
def perform!
self.dispatch if person.local?
AccountDeleter.new(self.diaspora_handle).perform!
Diaspora::Federation::Dispatcher.build(person.owner, self).dispatch if person.local?
AccountDeleter.new(diaspora_handle).perform!
end
def subscribers
person.owner.contact_people.remote | Person.who_have_reshared_a_users_posts(person.owner).remote
end
def dispatch
Postzord::Dispatcher.build(person.owner, self).post
end
def public?
true
end
......
......@@ -242,7 +242,7 @@ class User < ActiveRecord::Base
def dispatch_post(post, opts={})
logger.info "user:#{id} dispatching #{post.class}:#{post.guid}"
Postzord::Dispatcher.defer_build_and_post(self, post, opts)
Diaspora::Federation::Dispatcher.defer_dispatch(self, post, opts)
end
def update_post(post, post_hash={})
......@@ -459,10 +459,10 @@ class User < ActiveRecord::Base
conversation = sender.build_conversation(
participant_ids: [sender.person.id, person.id],
subject: AppConfig.settings.welcome_message.subject.get,
message: {text: AppConfig.settings.welcome_message.text.get % {username: username}})
if conversation.save
Postzord::Dispatcher.build(sender, conversation).post
end
message: {text: AppConfig.settings.welcome_message.text.get % {username: username}}
)
Diaspora::Federation::Dispatcher.build(sender, conversation).dispatch if conversation.save
end
def encryption_key
......
......@@ -25,7 +25,7 @@ module User::SocialActions
build_post(:reshare, :root_guid => target.guid).tap do |reshare|
reshare.save!
update_or_create_participation!(target)
Postzord::Dispatcher.defer_build_and_post(self, reshare)
Diaspora::Federation::Dispatcher.defer_dispatch(self, reshare)
end
end
......
......@@ -13,7 +13,7 @@ module Federated
if relayable.save!
logger.info "user:#{@user.id} dispatching #{relayable.class}:#{relayable.guid}"
add_root_author(relayable)
Postzord::Dispatcher.defer_build_and_post(@user, relayable, @dispatcher_opts)
Diaspora::Federation::Dispatcher.defer_dispatch(@user, relayable, @dispatcher_opts)
relayable
end
end
......
......@@ -153,9 +153,7 @@ describe ConversationsController, :type => :controller do
}
)
p = Postzord::Dispatcher.build(alice, cnv)
allow(p.class).to receive(:new).and_return(p)
expect(p).to receive(:post)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
post :create, @hash
end
end
......
......@@ -16,9 +16,10 @@ describe "adds root author on reshare" do
end
it "calls add_root_author" do
allow(Postzord::Dispatcher).to receive(:defer_build_and_post).and_return(true)
allow(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).and_return(true)
allow(@generator).to receive(:build).and_return(@relayable)
allow(@relayable).to receive(:save!).and_return(true)
allow(@relayable).to receive(:new_record?).and_return(false)
expect(@generator).to receive(:add_root_author)
@generator.create!
end
......
......@@ -4,46 +4,42 @@
require "spec_helper"
describe AccountDeletion, :type => :model do
let(:account_deletion_new) { AccountDeletion.new(person: alice.person) }
let(:account_deletion_create) { AccountDeletion.create(person: alice.person) }
describe AccountDeletion, type: :model do
let(:account_deletion) { AccountDeletion.new(person: alice.person) }
it "assigns the diaspora_handle from the person object" do
expect(account_deletion_new.diaspora_handle).to eq(alice.person.diaspora_handle)
expect(account_deletion.diaspora_handle).to eq(alice.person.diaspora_handle)
end
it "fires a job after creation"do
it "fires a job after creation" do
expect(Workers::DeleteAccount).to receive(:perform_async).with(anything)
account_deletion_create
AccountDeletion.create(person: alice.person)
end
describe "#perform!" do
it "creates a deleter" do
expect(AccountDeleter).to receive(:new).with(alice.person.diaspora_handle).and_return(double(perform!: true))
account_deletion_new.perform!
account_deletion.perform!
end
it "dispatches the account deletion if the user exists" do
expect(account_deletion_new).to receive(:dispatch)
account_deletion_new.perform!
dispatcher = double
expect(Diaspora::Federation::Dispatcher::Public).to receive(:new).and_return(dispatcher)
expect(dispatcher).to receive(:dispatch)
account_deletion.perform!
end
it "does not dispatch an account deletion for non-local people" do
deletion = AccountDeletion.new(person: remote_raphael)
expect(deletion).not_to receive(:dispatch)
expect(Diaspora::Federation::Dispatcher).not_to receive(:build)
deletion.perform!
end
it "marks an AccountDeletion as completed when successful" do
account_deletion_create.perform!
expect(account_deletion_create.reload.completed_at).not_to be_nil
end
end
describe "#dispatch" do
it "creates a public postzord" do
expect(Postzord::Dispatcher::Public).to receive(:new).and_return(double.as_null_object)
account_deletion_new.dispatch
deletion = AccountDeletion.create(person: alice.person)
deletion.perform!
expect(deletion.reload.completed_at).not_to be_nil
end
end
......@@ -51,7 +47,7 @@ describe AccountDeletion, :type => :model do
it "includes all remote contacts" do
alice.share_with(remote_raphael, alice.aspects.first)
expect(account_deletion_new.subscribers).to eq([remote_raphael])
expect(account_deletion.subscribers).to eq([remote_raphael])
end
it "includes remote resharers" do
......@@ -59,7 +55,7 @@ describe AccountDeletion, :type => :model do
FactoryGirl.create(:reshare, author: remote_raphael, root: status_message)
FactoryGirl.create(:reshare, author: local_luke.person, root: status_message)
expect(account_deletion_new.subscribers).to eq([remote_raphael])
expect(account_deletion.subscribers).to eq([remote_raphael])
end
end
end
......@@ -51,7 +51,7 @@ describe Message, :type => :model do
msg_hash = {:author => @local_luke.person, :text => 'yo', :conversation => @local_parent}
@object_by_parent_author = Message.create(msg_hash.dup)
Postzord::Dispatcher.build(@local_luke, @object_by_parent_author).post
Diaspora::Federation::Dispatcher.build(@local_luke, @object_by_parent_author).dispatch
msg_hash[:author] = @local_leia.person
@object_by_recipient = Message.create(msg_hash.dup)
......@@ -61,7 +61,7 @@ describe Message, :type => :model do
msg_hash[:author] = @local_luke.person
msg_hash[:conversation] = @remote_parent
@object_on_remote_parent = Message.create(msg_hash)
Postzord::Dispatcher.build(@local_luke, @object_on_remote_parent).post
Diaspora::Federation::Dispatcher.build(@local_luke, @object_on_remote_parent).dispatch
end
let(:build_object) { Message.new(:author => @alice.person, :text => "ohai!", :conversation => @conversation) }
......
......@@ -23,7 +23,7 @@ describe User::SocialActions, :type => :model do
it "federates" do
allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Postzord::Dispatcher).to receive(:defer_build_and_post)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
alice.comment!(@status, "omg")
end
end
......@@ -41,7 +41,7 @@ describe User::SocialActions, :type => :model do
it "federates" do
#participation and like
allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Postzord::Dispatcher).to receive(:defer_build_and_post)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
alice.like!(@status)
end
end
......@@ -62,7 +62,7 @@ describe User::SocialActions, :type => :model do
it "federates" do
#participation and like
expect(Postzord::Dispatcher).to receive(:defer_build_and_post).twice
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch).twice
alice.like!(@status)
end
......@@ -95,7 +95,7 @@ describe User::SocialActions, :type => :model do
it "federates" do
allow_any_instance_of(Participation::Generator).to receive(:create!)
expect(Postzord::Dispatcher).to receive(:defer_build_and_post)
expect(Diaspora::Federation::Dispatcher).to receive(:defer_dispatch)
alice.participate_in_poll!(@status, @answer)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment