about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-02-19 20:18:40 +0100
committerThibaut Girka <thib@sitedethib.com>2019-02-19 20:18:40 +0100
commitff0576cc2b046694dd8960608ce2f40e32a0ab78 (patch)
tree766b37f3f093f3882aba2258ebc2748325edcfcb /app/models
parent896beb16c5318b8ce59867a06545ae6a00ccc84c (diff)
parent8e7fc7ec73c0743df378403ad2e704c9fae70400 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Diffstat (limited to 'app/models')
-rw-r--r--app/models/account_conversation.rb3
-rw-r--r--app/models/domain_block.rb2
-rw-r--r--app/models/instance_filter.rb8
3 files changed, 10 insertions, 3 deletions
diff --git a/app/models/account_conversation.rb b/app/models/account_conversation.rb
index cc6b39279..0c03747e2 100644
--- a/app/models/account_conversation.rb
+++ b/app/models/account_conversation.rb
@@ -30,7 +30,8 @@ class AccountConversation < ApplicationRecord
     if participant_account_ids.empty?
       [account]
     else
-      Account.where(id: participant_account_ids)
+      participants = Account.where(id: participant_account_ids)
+      participants.empty? ? [account] : participants
     end
   end
 
diff --git a/app/models/domain_block.rb b/app/models/domain_block.rb
index 1064ea7c8..069cda367 100644
--- a/app/models/domain_block.rb
+++ b/app/models/domain_block.rb
@@ -24,6 +24,8 @@ class DomainBlock < ApplicationRecord
   has_many :accounts, foreign_key: :domain, primary_key: :domain
   delegate :count, to: :accounts, prefix: true
 
+  scope :matches_domain, ->(value) { where(arel_table[:domain].matches("%#{value}%")) }
+
   def self.blocked?(domain)
     where(domain: domain, severity: :suspend).exists?
   end
diff --git a/app/models/instance_filter.rb b/app/models/instance_filter.rb
index 3483d8cd6..848fff53e 100644
--- a/app/models/instance_filter.rb
+++ b/app/models/instance_filter.rb
@@ -9,9 +9,13 @@ class InstanceFilter
 
   def results
     if params[:limited].present?
-      DomainBlock.order(id: :desc)
+      scope = DomainBlock
+      scope = scope.matches_domain(params[:by_domain]) if params[:by_domain].present?
+      scope.order(id: :desc)
     else
-      Account.remote.by_domain_accounts
+      scope = Account.remote
+      scope = scope.matches_domain(params[:by_domain]) if params[:by_domain].present?
+      scope.by_domain_accounts
     end
   end
 end