about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account_filter.rb2
-rw-r--r--app/models/custom_emoji.rb11
-rw-r--r--app/models/custom_emoji_filter.rb34
3 files changed, 45 insertions, 2 deletions
diff --git a/app/models/account_filter.rb b/app/models/account_filter.rb
index 1a8cc5192..189872368 100644
--- a/app/models/account_filter.rb
+++ b/app/models/account_filter.rb
@@ -9,9 +9,11 @@ class AccountFilter
 
   def results
     scope = Account.alphabetic
+
     params.each do |key, value|
       scope.merge!(scope_for(key, value)) if value.present?
     end
+
     scope
   end
 
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
diff --git a/app/models/custom_emoji_filter.rb b/app/models/custom_emoji_filter.rb
new file mode 100644
index 000000000..2d1394a59
--- /dev/null
+++ b/app/models/custom_emoji_filter.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+class CustomEmojiFilter
+  attr_reader :params
+
+  def initialize(params)
+    @params = params
+  end
+
+  def results
+    scope = CustomEmoji.alphabetic
+
+    params.each do |key, value|
+      scope.merge!(scope_for(key, value)) if value.present?
+    end
+
+    scope
+  end
+
+  private
+
+  def scope_for(key, value)
+    case key.to_s
+    when 'local'
+      CustomEmoji.local
+    when 'remote'
+      CustomEmoji.remote
+    when 'by_domain'
+      CustomEmoji.where(domain: value)
+    else
+      raise "Unknown filter: #{key}"
+    end
+  end
+end