diff options
author | Ondřej Hruška <ondra@ondrovo.com> | 2017-09-28 09:18:35 +0200 |
---|---|---|
committer | Ondřej Hruška <ondra@ondrovo.com> | 2017-09-28 09:18:35 +0200 |
commit | 83bda6c1a813c5aeb131b18a0500fed0c07fa9c2 (patch) | |
tree | 32f197901b4b16ea7f94de682fee6cdc44686045 /app/models/custom_emoji.rb | |
parent | fcf0d2078ea813e0dd318fa154d620018e7b7bcf (diff) | |
parent | b9f59ebcc68e9da0a7158741a1a2ef3564e1321e (diff) |
Merge commit 'b9f59ebcc68e9da0a7158741a1a2ef3564e1321e' into merging-upstream
Diffstat (limited to 'app/models/custom_emoji.rb')
-rw-r--r-- | app/models/custom_emoji.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index f4d3b16a0..e80c58155 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -26,12 +26,18 @@ class CustomEmoji < ApplicationRecord validates_attachment :image, content_type: { content_type: 'image/png' }, presence: true, size: { in: 0..50.kilobytes } validates :shortcode, uniqueness: { scope: :domain }, format: { with: /\A#{SHORTCODE_RE_FRAGMENT}\z/ }, length: { minimum: 2 } + scope :local, -> { where(domain: nil) } + include Remotable class << self def from_text(text, domain) return [] if text.blank? - shortcodes = text.scan(SCAN_RE).map(&:first) + + shortcodes = text.scan(SCAN_RE).map(&:first).uniq + + return [] if shortcodes.empty? + where(shortcode: shortcodes, domain: domain) end end |