diff --git a/app/models/photo.rb b/app/models/photo.rb index 76a851012..5c41374e3 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -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? diff --git a/app/models/post.rb b/app/models/post.rb index e7618157d..02582c80a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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). diff --git a/lib/diaspora/shareable.rb b/lib/diaspora/shareable.rb index 28efb8a84..93ac4adf4 100644 --- a/lib/diaspora/shareable.rb +++ b/lib/diaspora/shareable.rb @@ -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