From 293972f716476933df2b665ad755cafe4d29d82d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sat, 23 Sep 2017 01:57:23 +0200 Subject: New API: GET /api/v1/custom_emojis to get a server's custom emojis (#5051) --- app/models/custom_emoji.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models/custom_emoji.rb') diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index f4d3b16a0..aff9f8dfa 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -26,6 +26,8 @@ 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 -- cgit From 3caf0ba92313c71d722b30f77c5c1355601fc7c1 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 27 Sep 2017 04:14:03 +0200 Subject: Fix empty query sent to postgres for custom emojis (#5121) --- app/models/custom_emoji.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'app/models/custom_emoji.rb') diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb index aff9f8dfa..e80c58155 100644 --- a/app/models/custom_emoji.rb +++ b/app/models/custom_emoji.rb @@ -33,7 +33,11 @@ class CustomEmoji < ApplicationRecord 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 -- cgit