about summary refs log tree commit diff
path: root/app/models/custom_emoji.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/custom_emoji.rb')
-rw-r--r--app/models/custom_emoji.rb8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb
index 7cb03b819..c819288ba 100644
--- a/app/models/custom_emoji.rb
+++ b/app/models/custom_emoji.rb
@@ -18,6 +18,7 @@
 #  visible_in_picker            :boolean          default(TRUE), not null
 #  category_id                  :bigint(8)
 #  image_storage_schema_version :integer
+#  account_id                   :bigint(8)
 #
 
 class CustomEmoji < ApplicationRecord
@@ -32,6 +33,7 @@ class CustomEmoji < ApplicationRecord
   IMAGE_MIME_TYPES = %w(image/png image/gif).freeze
 
   belongs_to :category, class_name: 'CustomEmojiCategory', optional: true
+  belongs_to :account, inverse_of: :custom_emojis, optional: true
   has_one :local_counterpart, -> { where(domain: nil) }, class_name: 'CustomEmoji', primary_key: :shortcode, foreign_key: :shortcode
 
   has_attached_file :image, styles: { static: { format: 'png', convert_options: '-coalesce -strip' } }
@@ -46,6 +48,7 @@ class CustomEmoji < ApplicationRecord
   scope :alphabetic, -> { order(domain: :asc, shortcode: :asc) }
   scope :by_domain_and_subdomains, ->(domain) { where(domain: domain).or(where(arel_table[:domain].matches('%.' + domain))) }
   scope :listed, -> { local.where(disabled: false).where(visible_in_picker: true) }
+  scope :owned_by, ->(account) { where(account: account) }
 
   remotable_attachment :image, LIMIT
 
@@ -61,8 +64,11 @@ class CustomEmoji < ApplicationRecord
     :emoji
   end
 
-  def copy!
+  def copy!(current_account = nil)
     copy = self.class.find_or_initialize_by(domain: nil, shortcode: shortcode)
+    return copy if copy.account_id.present? && copy.account_id != current_account&.id
+
+    copy.account = current_account
     copy.image = image
     copy.tap(&:save!)
   end