diff options
author | Reverite <github@reverite.sh> | 2019-09-18 16:38:31 -0700 |
---|---|---|
committer | Reverite <github@reverite.sh> | 2019-09-18 16:38:31 -0700 |
commit | 73f4af117fc5b5e4ee3337d634f5e589a9353644 (patch) | |
tree | 62b0443573ba5038fd45aa14d4243dfc832c060a /app/models/custom_emoji.rb | |
parent | 849e2bc4ca11892e701835a4696904d78b1ad325 (diff) | |
parent | febcdad2e2c98aee62b55ee21bdf0debf7c6fd6b (diff) |
Merge branch 'glitch' into production
Diffstat (limited to 'app/models/custom_emoji.rb')
-rw-r--r-- | app/models/custom_emoji.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index b21ad9042..0dacaf654 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -40,10 +40,11 @@ class CustomEmoji < ApplicationRecord validates_attachment :image, content_type: { content_type: IMAGE_MIME_TYPES }, presence: true, size: { less_than: LIMIT } validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 } - scope :local, -> { where(domain: nil) } - scope :remote, -> { where.not(domain: nil) } + scope :local, -> { where(domain: nil) } + scope :remote, -> { where.not(domain: nil) } 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) } remotable_attachment :image, LIMIT @@ -59,6 +60,12 @@ class CustomEmoji < ApplicationRecord :emoji end + def copy! + copy = self.class.find_or_initialize_by(domain: nil, shortcode: shortcode) + copy.image = image + copy.tap(&:save!) + end + class << self def from_text(text, domain) return [] if text.blank? |