about summary refs log tree commit diff
path: root/app/models/custom_emoji.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-10-05 23:42:05 +0200
committerGitHub <noreply@github.com>2017-10-05 23:42:05 +0200
commit49cc0eb3e7d1521079e33a60216df46679082547 (patch)
treee7c7879d07d9a5a6258c14b4e2d49b8c07d5d9fa /app/models/custom_emoji.rb
parentb9c76e2edbc372e1b472f6ba480631b79fe24722 (diff)
Improve admin UI for custom emojis, add copy/disable/enable (#5231)
Diffstat (limited to 'app/models/custom_emoji.rb')
-rw-r--r--app/models/custom_emoji.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/app/models/custom_emoji.rb b/app/models/custom_emoji.rb
index 9e9be5e12..258b50c82 100644
--- a/app/models/custom_emoji.rb
+++ b/app/models/custom_emoji.rb
@@ -12,6 +12,7 @@
 #  image_updated_at   :datetime
 #  created_at         :datetime         not null
 #  updated_at         :datetime         not null
+#  disabled           :boolean          default(FALSE), not null
 #
 
 class CustomEmoji < ApplicationRecord
@@ -26,10 +27,16 @@ 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) }
+  scope :local,      -> { where(domain: nil) }
+  scope :remote,     -> { where.not(domain: nil) }
+  scope :alphabetic, -> { order(domain: :asc, shortcode: :asc) }
 
   include Remotable
 
+  def local?
+    domain.nil?
+  end
+
   class << self
     def from_text(text, domain)
       return [] if text.blank?
@@ -38,7 +45,7 @@ class CustomEmoji < ApplicationRecord
 
       return [] if shortcodes.empty?
 
-      where(shortcode: shortcodes, domain: domain)
+      where(shortcode: shortcodes, domain: domain, disabled: false)
     end
   end
 end