Remove repetion of shareable initialization code
This commit is contained in:
parent
2737280fa4
commit
204f58e6a7
3 changed files with 8 additions and 8 deletions
|
|
@ -82,11 +82,7 @@ class Photo < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.diaspora_initialize(params = {})
|
||||
photo = self.new params.to_hash.slice(:text, :pending)
|
||||
photo.author = params[:author]
|
||||
photo.public = params[:public] if params[:public]
|
||||
photo.pending = params[:pending] if params[:pending]
|
||||
|
||||
photo = shareable_initialize(params)
|
||||
photo.random_string = SecureRandom.hex(10)
|
||||
|
||||
if photo.author.local?
|
||||
|
|
|
|||
|
|
@ -133,9 +133,7 @@ class Post < ActiveRecord::Base
|
|||
#############
|
||||
|
||||
def self.diaspora_initialize(params)
|
||||
new(params.to_hash.stringify_keys.slice(*column_names)).tap do |new_post|
|
||||
new_post.author = params[:author]
|
||||
end
|
||||
shareable_initialize(params)
|
||||
end
|
||||
|
||||
# @return Returns true if this Post will accept updates (i.e. updates to the caption of a photo).
|
||||
|
|
|
|||
|
|
@ -57,6 +57,12 @@ module Diaspora
|
|||
user.person.send(table_name).where(pending: false)
|
||||
end
|
||||
|
||||
def self.shareable_initialize(params)
|
||||
new(params.to_hash.stringify_keys.slice(*column_names)).tap do |new_shareable|
|
||||
new_shareable.author = params[:author]
|
||||
end
|
||||
end
|
||||
|
||||
def self.visible_by_user(user)
|
||||
ShareVisibility.arel_table[:user_id].eq(user.id)
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue