Remove repetion of shareable initialization code

parent 2737280f
......@@ -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
......
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