federated generators take a user
This commit is contained in:
parent
a0ca983c57
commit
d6fd5cdb20
4 changed files with 19 additions and 19 deletions
|
|
@ -1,19 +1,19 @@
|
||||||
module User::SocialActions
|
module User::SocialActions
|
||||||
def comment!(post, text, opts={})
|
def comment!(target, text, opts={})
|
||||||
participations.where(:target_id => post).first || participate!(post)
|
participations.where(:target_id => target).first || participate!(target)
|
||||||
Comment::Generator.new(self.person, post, text).create!(opts)
|
Comment::Generator.new(self, target, text).create!(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def participate!(target, opts={})
|
def participate!(target, opts={})
|
||||||
Participation::Generator.new(self.person, target).create!(opts)
|
Participation::Generator.new(self, target).create!(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def like!(target, opts={})
|
def like!(target, opts={})
|
||||||
participations.where(:target_id => target).first || participate!(target)
|
participations.where(:target_id => target).first || participate!(target)
|
||||||
Like::Generator.new(self.person, target).create!(opts)
|
Like::Generator.new(self, target).create!(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_comment(options={})
|
def build_comment(options={})
|
||||||
Comment::Generator.new(self.person, options.delete(:post), options.delete(:text)).build(options)
|
Comment::Generator.new(self, options.delete(:post), options.delete(:text)).build(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
module Federated
|
module Federated
|
||||||
class Generator
|
class Generator
|
||||||
def initialize(person, target)
|
def initialize(user, target)
|
||||||
@person = person
|
@user = user
|
||||||
@target = target
|
@target = target
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(options={})
|
|
||||||
options.merge!(relayable_options)
|
|
||||||
relayable = self.class.federated_class.new(options.merge(:author_id => @person.id))
|
|
||||||
relayable.set_guid
|
|
||||||
relayable.initialize_signatures
|
|
||||||
relayable
|
|
||||||
end
|
|
||||||
|
|
||||||
def create!(options={})
|
def create!(options={})
|
||||||
relayable = build(options)
|
relayable = build(options)
|
||||||
if relayable.save
|
if relayable.save
|
||||||
Postzord::Dispatcher.defer_build_and_post(@person, relayable)
|
Postzord::Dispatcher.defer_build_and_post(@user, relayable)
|
||||||
relayable
|
relayable
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build(options={})
|
||||||
|
options.merge!(relayable_options)
|
||||||
|
relayable = self.class.federated_class.new(options.merge(:author_id => @user.person.id))
|
||||||
|
relayable.set_guid
|
||||||
|
relayable.initialize_signatures
|
||||||
|
relayable
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def relayable_options
|
def relayable_options
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ describe Like do
|
||||||
@object_on_remote_parent = @local_luke.like!(@remote_parent)
|
@object_on_remote_parent = @local_luke.like!(@remote_parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:build_object) { Like::Generator.new(alice.person, @status).build }
|
let(:build_object) { Like::Generator.new(alice, @status).build }
|
||||||
it_should_behave_like 'it is relayable'
|
it_should_behave_like 'it is relayable'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ describe Participation do
|
||||||
@object_on_remote_parent = @local_luke.participate!(@remote_parent)
|
@object_on_remote_parent = @local_luke.participate!(@remote_parent)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:build_object) { Participation::Generator.new(alice.person, @status).build }
|
let(:build_object) { Participation::Generator.new(alice, @status).build }
|
||||||
|
|
||||||
it_should_behave_like 'it is relayable'
|
it_should_behave_like 'it is relayable'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue